diff --git a/app/admin/controller/mall/PointsLog.php b/app/admin/controller/mall/PointsLog.php index 6eee773..bdab161 100644 --- a/app/admin/controller/mall/PointsLog.php +++ b/app/admin/controller/mall/PointsLog.php @@ -15,7 +15,7 @@ class PointsLog extends Backend protected ?object $model = null; protected array $withJoinTable = ['userAsset', 'admin']; - protected array|string $preExcludeFields = ['id', 'before', 'after', 'memo', 'admin_id', 'create_time']; + protected array|string $preExcludeFields = ['id', 'before', 'after', 'admin_id', 'create_time']; protected array|string $quickSearchField = [ 'userAsset.playx_user_id', 'userAsset.username', diff --git a/app/admin/lang/en/mall/pointslog.php b/app/admin/lang/en/mall/pointslog.php deleted file mode 100644 index 49a3cc0..0000000 --- a/app/admin/lang/en/mall/pointslog.php +++ /dev/null @@ -1,13 +0,0 @@ - 'User asset', - 'Points adjustment' => 'Points adjustment', - 'User asset not found' => 'User asset not found', - 'Points adjustment must be a non-zero integer' => 'Points adjustment must be a non-zero integer', - 'Insufficient available points' => 'Insufficient available points', - 'Administrator added %s points' => 'Administrator added %s points', - 'Administrator deducted %s points' => 'Administrator deducted %s points', - 'Points log cannot be modified' => 'Points log cannot be modified', - 'Points log cannot be deleted' => 'Points log cannot be deleted', -]; diff --git a/app/admin/lang/zh-cn/mall/pointslog.php b/app/admin/lang/zh-cn/mall/pointslog.php deleted file mode 100644 index 202607b..0000000 --- a/app/admin/lang/zh-cn/mall/pointslog.php +++ /dev/null @@ -1,13 +0,0 @@ - '用户资产', - 'Points adjustment' => '调整积分', - 'User asset not found' => '用户资产不存在', - 'Points adjustment must be a non-zero integer' => '调整积分必须为非零整数', - 'Insufficient available points' => '可用积分不足', - 'Administrator added %s points' => '管理员增加积分 %s', - 'Administrator deducted %s points' => '管理员扣除积分 %s', - 'Points log cannot be modified' => '积分流水不允许修改', - 'Points log cannot be deleted' => '积分流水不允许删除', -]; diff --git a/app/admin/model/MallPointsLog.php b/app/admin/model/MallPointsLog.php index e04f224..28cc81f 100644 --- a/app/admin/model/MallPointsLog.php +++ b/app/admin/model/MallPointsLog.php @@ -37,9 +37,19 @@ class MallPointsLog extends \app\common\model\MallPointsLog $model->before = $before; $model->after = $after; $pointsAbs = abs($scoreValue); - $model->memo = $scoreValue > 0 - ? sprintf(__('Administrator added %s points'), $pointsAbs) - : sprintf(__('Administrator deducted %s points'), $pointsAbs); + $memo = trim(strval($model->getData('memo') ?? '')); + if ($memo === '') { + $memo = $scoreValue > 0 + ? sprintf(__('Administrator added %s points'), $pointsAbs) + : sprintf(__('Administrator deducted %s points'), $pointsAbs); + } else { + if (function_exists('mb_substr')) { + $memo = mb_substr($memo, 0, 255); + } else { + $memo = substr($memo, 0, 255); + } + } + $model->memo = $memo; $userAsset->available_points = $after; $userAsset->save(); diff --git a/web/src/views/backend/mall/pointsLog/popupForm.vue b/web/src/views/backend/mall/pointsLog/popupForm.vue index ab31794..96dd921 100644 --- a/web/src/views/backend/mall/pointsLog/popupForm.vue +++ b/web/src/views/backend/mall/pointsLog/popupForm.vue @@ -92,7 +92,7 @@ interface UserAssetInfo { } const config = useConfig() -const { t } = useI18n() +const { t, locale } = useI18n() const injectedBaTable = inject('baTable') if (!injectedBaTable) { throw new Error('baTable is not provided') @@ -132,17 +132,24 @@ const rules: Partial> = reactive({ ], }) +const syncMemoToForm = (scoreValue: number) => { + let memoText = '' + if (scoreValue > 0) { + memoText = t('mall.pointsLog.admin_add_memo', { value: Math.abs(scoreValue) }) + } else if (scoreValue < 0) { + memoText = t('mall.pointsLog.admin_deduct_memo', { value: Math.abs(scoreValue) }) + } + state.memo = memoText + if (baTable.form.items) { + baTable.form.items.memo = memoText + } +} + const changeScore = (value: number | undefined) => { const scoreValue = value ?? 0 const availablePoints = state.userAsset.available_points ?? 0 state.after = availablePoints + scoreValue - if (scoreValue > 0) { - state.memo = t('mall.pointsLog.admin_add_memo', { value: Math.abs(scoreValue) }) - } else if (scoreValue < 0) { - state.memo = t('mall.pointsLog.admin_deduct_memo', { value: Math.abs(scoreValue) }) - } else { - state.memo = '' - } + syncMemoToForm(scoreValue) } const getUserAssetInfo = () => { @@ -151,6 +158,9 @@ const getUserAssetInfo = () => { state.userAsset = {} state.after = 0 state.memo = '' + if (baTable.form.items) { + baTable.form.items.memo = '' + } return } @@ -168,6 +178,12 @@ watch( } } ) + +watch(locale, () => { + if (baTable.form.operate === 'Add') { + changeScore(baTable.form.items?.score_value as number | undefined) + } +})