优化积分修改时的备注写入

This commit is contained in:
2026-07-27 12:30:23 +08:00
parent c4ec7828bd
commit 881581a8f0
3 changed files with 18 additions and 3 deletions

View File

@@ -36,9 +36,10 @@ class MallPointsLog extends \app\common\model\MallPointsLog
$model->score_value = $scoreValue; $model->score_value = $scoreValue;
$model->before = $before; $model->before = $before;
$model->after = $after; $model->after = $after;
$pointsAbs = abs($scoreValue);
$model->memo = $scoreValue > 0 $model->memo = $scoreValue > 0
? __('Administrator added %s points', [abs($scoreValue)]) ? sprintf(__('Administrator added %s points'), $pointsAbs)
: __('Administrator deducted %s points', [abs($scoreValue)]); : sprintf(__('Administrator deducted %s points'), $pointsAbs);
$userAsset->available_points = $after; $userAsset->available_points = $after;
$userAsset->save(); $userAsset->save();

View File

@@ -1130,7 +1130,7 @@ SQL;
$memoKey = ($row['direction'] ?? '') === 'OUT' $memoKey = ($row['direction'] ?? '') === 'OUT'
? 'Administrator deducted %s points' ? 'Administrator deducted %s points'
: 'Administrator added %s points'; : 'Administrator added %s points';
$memo = __($memoKey, [$row['points'] ?? 0]); $memo = sprintf(__($memoKey), $row['points'] ?? 0);
} }
$list[] = [ $list[] = [
'biz_type' => $row['biz_type'] ?? '', 'biz_type' => $row['biz_type'] ?? '',

View File

@@ -15,4 +15,18 @@ class MallPointsLog extends Model
protected string $pk = 'id'; protected string $pk = 'id';
protected bool $autoWriteTimestamp = true; protected bool $autoWriteTimestamp = true;
protected bool $updateTime = false; protected bool $updateTime = false;
/**
* 展示备注:兼容历史数据未替换的 %s 占位符
*/
public function getMemoAttr($value, $row): string
{
$memo = strval($value ?? '');
if ($memo === '' || !str_contains($memo, '%s')) {
return $memo;
}
$points = abs(intval(is_array($row) ? ($row['score_value'] ?? 0) : ($row->score_value ?? 0)));
return sprintf($memo, $points);
}
} }