优化积分修改时的备注写入适配多语言
This commit is contained in:
@@ -15,7 +15,7 @@ class PointsLog extends Backend
|
|||||||
protected ?object $model = null;
|
protected ?object $model = null;
|
||||||
|
|
||||||
protected array $withJoinTable = ['userAsset', 'admin'];
|
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 = [
|
protected array|string $quickSearchField = [
|
||||||
'userAsset.playx_user_id',
|
'userAsset.playx_user_id',
|
||||||
'userAsset.username',
|
'userAsset.username',
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
'User asset' => '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',
|
|
||||||
];
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
'User asset' => '用户资产',
|
|
||||||
'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' => '积分流水不允许删除',
|
|
||||||
];
|
|
||||||
@@ -37,9 +37,19 @@ class MallPointsLog extends \app\common\model\MallPointsLog
|
|||||||
$model->before = $before;
|
$model->before = $before;
|
||||||
$model->after = $after;
|
$model->after = $after;
|
||||||
$pointsAbs = abs($scoreValue);
|
$pointsAbs = abs($scoreValue);
|
||||||
$model->memo = $scoreValue > 0
|
$memo = trim(strval($model->getData('memo') ?? ''));
|
||||||
? sprintf(__('Administrator added %s points'), $pointsAbs)
|
if ($memo === '') {
|
||||||
: sprintf(__('Administrator deducted %s points'), $pointsAbs);
|
$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->available_points = $after;
|
||||||
$userAsset->save();
|
$userAsset->save();
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ interface UserAssetInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const config = useConfig()
|
const config = useConfig()
|
||||||
const { t } = useI18n()
|
const { t, locale } = useI18n()
|
||||||
const injectedBaTable = inject<baTableClass>('baTable')
|
const injectedBaTable = inject<baTableClass>('baTable')
|
||||||
if (!injectedBaTable) {
|
if (!injectedBaTable) {
|
||||||
throw new Error('baTable is not provided')
|
throw new Error('baTable is not provided')
|
||||||
@@ -132,17 +132,24 @@ const rules: Partial<Record<string, FormItemRule[]>> = 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 changeScore = (value: number | undefined) => {
|
||||||
const scoreValue = value ?? 0
|
const scoreValue = value ?? 0
|
||||||
const availablePoints = state.userAsset.available_points ?? 0
|
const availablePoints = state.userAsset.available_points ?? 0
|
||||||
state.after = availablePoints + scoreValue
|
state.after = availablePoints + scoreValue
|
||||||
if (scoreValue > 0) {
|
syncMemoToForm(scoreValue)
|
||||||
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 = ''
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getUserAssetInfo = () => {
|
const getUserAssetInfo = () => {
|
||||||
@@ -151,6 +158,9 @@ const getUserAssetInfo = () => {
|
|||||||
state.userAsset = {}
|
state.userAsset = {}
|
||||||
state.after = 0
|
state.after = 0
|
||||||
state.memo = ''
|
state.memo = ''
|
||||||
|
if (baTable.form.items) {
|
||||||
|
baTable.form.items.memo = ''
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,6 +178,12 @@ watch(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
watch(locale, () => {
|
||||||
|
if (baTable.form.operate === 'Add') {
|
||||||
|
changeScore(baTable.form.items?.score_value as number | undefined)
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss"></style>
|
<style scoped lang="scss"></style>
|
||||||
|
|||||||
Reference in New Issue
Block a user