余额变动修改
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace app\admin\controller\user;
|
namespace app\admin\controller\user;
|
||||||
|
|
||||||
|
use app\common\service\Jk8Services;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use app\admin\model\User;
|
use app\admin\model\User;
|
||||||
use app\admin\model\UserMoneyLog;
|
use app\admin\model\UserMoneyLog;
|
||||||
@@ -15,19 +16,63 @@ class MoneyLog extends Backend
|
|||||||
*/
|
*/
|
||||||
protected object $model;
|
protected object $model;
|
||||||
|
|
||||||
protected array $withJoinTable = ['user'];
|
protected array $withJoinTable = ['user', 'admin'];
|
||||||
|
protected array $withTable = ['scoreLog'];
|
||||||
|
|
||||||
// 排除字段
|
// 排除字段
|
||||||
protected string|array $preExcludeFields = ['create_time'];
|
protected string|array $preExcludeFields = ['create_time'];
|
||||||
|
|
||||||
protected string|array $quickSearchField = ['user.username', 'user.nickname'];
|
protected string|array $quickSearchField = ['user.username', 'user.nickname'];
|
||||||
|
protected $jk8Services;
|
||||||
|
|
||||||
public function initialize(): void
|
public function initialize(): void
|
||||||
{
|
{
|
||||||
parent::initialize();
|
parent::initialize();
|
||||||
|
$this->jk8Services = app(Jk8Services::class);
|
||||||
$this->model = new UserMoneyLog();
|
$this->model = new UserMoneyLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证逻辑
|
||||||
|
*/
|
||||||
|
protected function validateModelData(array $data, string $scene = ''): void
|
||||||
|
{
|
||||||
|
if (!$this->modelValidate) return;
|
||||||
|
|
||||||
|
$validateClass = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
||||||
|
if (class_exists($validateClass)) {
|
||||||
|
$validate = new $validateClass();
|
||||||
|
if ($scene) $validate->scene($scene);
|
||||||
|
$validate->check($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
public function index(): void
|
||||||
|
{
|
||||||
|
if ($this->request->param('select')) {
|
||||||
|
$this->select();
|
||||||
|
}
|
||||||
|
|
||||||
|
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||||
|
$res = $this->model
|
||||||
|
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||||
|
->with($this->withTable)
|
||||||
|
->alias($alias)
|
||||||
|
->where($where)
|
||||||
|
->order($order)
|
||||||
|
->paginate($limit);
|
||||||
|
|
||||||
|
$this->success('', [
|
||||||
|
'list' => $res->items(),
|
||||||
|
'total' => $res->total(),
|
||||||
|
'remark' => get_route_remark(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加
|
* 添加
|
||||||
* @param int $userId
|
* @param int $userId
|
||||||
@@ -36,7 +81,45 @@ class MoneyLog extends Backend
|
|||||||
public function add(int $userId = 0): void
|
public function add(int $userId = 0): void
|
||||||
{
|
{
|
||||||
if ($this->request->isPost()) {
|
if ($this->request->isPost()) {
|
||||||
parent::add();
|
$data = $this->request->post();
|
||||||
|
if (!$data) {
|
||||||
|
$this->error(__('Parameter %s can not be empty', ['']));
|
||||||
|
}
|
||||||
|
$result = false;
|
||||||
|
$data = $this->excludeFields($data);
|
||||||
|
|
||||||
|
$user = User::where('id', $data['user_id'])->find();
|
||||||
|
if ($data['type'] == 2) {
|
||||||
|
$data['money'] = -$data['money'];
|
||||||
|
}
|
||||||
|
if ($user->money + $data['money'] < 0) {
|
||||||
|
$this->error(__('Insufficient Credit'));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 模型验证
|
||||||
|
$this->validateModelData($data, 'add');
|
||||||
|
$transactionId = $this->jk8Services->setScore($user['jk_username'], $data['money']);
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
$this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->model->startTrans();
|
||||||
|
try {
|
||||||
|
$data['transaction_id'] = $transactionId;
|
||||||
|
$data['created_by'] = $this->auth->getInfo()['id'];
|
||||||
|
// $data['type'] = $data['money'] > 0 ? 1 : 2;
|
||||||
|
$result = $this->model->save($data);
|
||||||
|
$this->model->commit();
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
$this->model->rollback();
|
||||||
|
$this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
if ($result !== false) {
|
||||||
|
$this->success(__('Added successfully'));
|
||||||
|
} else {
|
||||||
|
$this->error(__('No rows were added'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = User::where('id', $userId)->find();
|
$user = User::where('id', $userId)->find();
|
||||||
@@ -47,4 +130,28 @@ class MoneyLog extends Backend
|
|||||||
'user' => $user
|
'user' => $user
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
public function edit(): void
|
||||||
|
{
|
||||||
|
$pk = $this->model->getPk();
|
||||||
|
$id = $this->request->param($pk);
|
||||||
|
$row = $this->model->find($id);
|
||||||
|
if (!$row) {
|
||||||
|
$this->error(__('Record not found'));
|
||||||
|
}
|
||||||
|
$user = User::where('id', $row['user_id'])->find();
|
||||||
|
if ($this->request->isPost()) {
|
||||||
|
parent::edit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$row['username'] = $user['username'];
|
||||||
|
$row['nickname'] = $user['nickname'];
|
||||||
|
$this->success('', [
|
||||||
|
'row' => $row
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,8 @@ class User extends Backend
|
|||||||
try {
|
try {
|
||||||
// 模型验证
|
// 模型验证
|
||||||
$this->validateModelData($data, 'add');
|
$this->validateModelData($data, 'add');
|
||||||
$jkId = $this->jk8Services->register($data['username'], $data['nickname'] ?? '', $data['referrer_code'] ?? '');
|
$jkId = $this->jk8Services->register($data['mobile'], $data['nickname'] ?? '', $data['referrer_code'] ?? '');
|
||||||
|
$jkUserName = $this->jk8Services->getAllUsers($jkId);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
$this->error($e->getMessage());
|
$this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -103,6 +104,7 @@ class User extends Backend
|
|||||||
$this->model->startTrans();
|
$this->model->startTrans();
|
||||||
try {
|
try {
|
||||||
$data['jk_user_id'] = $jkId;
|
$data['jk_user_id'] = $jkId;
|
||||||
|
$data['jk_username'] = $jkUserName;
|
||||||
$result = $this->model->save($data);
|
$result = $this->model->save($data);
|
||||||
$this->model->commit();
|
$this->model->commit();
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace app\admin\model;
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use think\model\relation\HasMany;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use think\model;
|
use think\model;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
@@ -77,4 +78,14 @@ class UserMoneyLog extends model
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(User::class, 'user_id');
|
return $this->belongsTo(User::class, 'user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function admin(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Admin::class, 'created_by');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scoreLog(): hasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(UserScoreLog::class, 'money_log_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -56,6 +56,23 @@ class Jk8Services
|
|||||||
return $result['data']['id'];
|
return $result['data']['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户注册
|
||||||
|
* @param int|null $userId
|
||||||
|
* @return string
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function getAllUsers(int $userId = null): string
|
||||||
|
{
|
||||||
|
$params = $this->createParam('/users/getAllUsers', [
|
||||||
|
'id' => $userId,
|
||||||
|
]);
|
||||||
|
$result = doCurl($this->domain, $params);
|
||||||
|
if (($result['status'] ?? '') === 'ERROR') {
|
||||||
|
throw new Exception($result['data']['message'] ?? 'Remote API Error');
|
||||||
|
}
|
||||||
|
return $result['data']['users'][0]['username'] ?? '';
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 获取促销列表
|
* 获取促销列表
|
||||||
* @param string $userId
|
* @param string $userId
|
||||||
@@ -77,19 +94,21 @@ class Jk8Services
|
|||||||
/**
|
/**
|
||||||
* 转账
|
* 转账
|
||||||
* @param string $username
|
* @param string $username
|
||||||
|
* @param float $amount
|
||||||
* @return array|mixed|null
|
* @return array|mixed|null
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function setScore(string $username): mixed
|
public function setScore(string $username, float $amount): mixed
|
||||||
{
|
{
|
||||||
$params = $this->createParam('/member/setScore', [
|
$params = $this->createParam('/member/setScore', [
|
||||||
'username' => $username,
|
'username' => $username,
|
||||||
|
'amount' => $amount
|
||||||
]);
|
]);
|
||||||
$result = doCurl($this->domain, $params);
|
$result = doCurl($this->domain, $params);
|
||||||
if (($result['status'] ?? '') === 'ERROR') {
|
if (($result['status'] ?? '') === 'ERROR') {
|
||||||
throw new Exception($result['data']['message'] ?? 'Remote API Error');
|
throw new Exception($result['data']['message'] ?? 'Remote API Error');
|
||||||
}
|
}
|
||||||
return $result;
|
return $result['data']['transactionId'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,4 +13,18 @@ export default {
|
|||||||
'Balance after change': 'Balance after change',
|
'Balance after change': 'Balance after change',
|
||||||
'Please enter change remarks / description': 'Please enter change remarks/description',
|
'Please enter change remarks / description': 'Please enter change remarks/description',
|
||||||
User: 'User',
|
User: 'User',
|
||||||
|
'Transaction id': 'Transaction id',
|
||||||
|
'Created by': 'Created by',
|
||||||
|
'type': '类型',
|
||||||
|
'type_list': {
|
||||||
|
1 : 'Deposit',
|
||||||
|
2 : 'Withdraw',
|
||||||
|
},
|
||||||
|
'Game Ticket' : 'Game Ticket',
|
||||||
|
'game_type': {
|
||||||
|
1001 : 'Lucky Wheel',
|
||||||
|
1002 : 'Golden Eggs',
|
||||||
|
1003 : 'Daily Mission',
|
||||||
|
1004 : 'Plinko Ball'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export default {
|
|||||||
'User name': 'Username',
|
'User name': 'Username',
|
||||||
nickname: 'Nickname',
|
nickname: 'Nickname',
|
||||||
'jk user id': 'JK8 UserId',
|
'jk user id': 'JK8 UserId',
|
||||||
|
'jk user name': 'JK8 UserName',
|
||||||
'referrer code': 'referrerCode',
|
'referrer code': 'referrerCode',
|
||||||
group: 'Group',
|
group: 'Group',
|
||||||
avatar: 'Avatar',
|
avatar: 'Avatar',
|
||||||
|
|||||||
@@ -13,4 +13,18 @@ export default {
|
|||||||
'Balance after change': '变更后余额',
|
'Balance after change': '变更后余额',
|
||||||
'Please enter change remarks / description': '请输入变更备注/说明',
|
'Please enter change remarks / description': '请输入变更备注/说明',
|
||||||
User: '用户',
|
User: '用户',
|
||||||
|
'Transaction id': '订单号',
|
||||||
|
'Created by': '来源',
|
||||||
|
'type': '类型',
|
||||||
|
'type_list': {
|
||||||
|
1 : '存款',
|
||||||
|
2 : '取款',
|
||||||
|
},
|
||||||
|
'Game Ticket' : '游戏门票',
|
||||||
|
'game_type': {
|
||||||
|
1001 : 'Lucky Wheel',
|
||||||
|
1002 : 'Golden Eggs',
|
||||||
|
1003 : 'Daily Mission',
|
||||||
|
1004 : 'Plinko Ball'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export default {
|
|||||||
'User name': '用户名',
|
'User name': '用户名',
|
||||||
nickname: '昵称',
|
nickname: '昵称',
|
||||||
'jk user id': 'JK8 UserId',
|
'jk user id': 'JK8 UserId',
|
||||||
|
'jk user name': 'JK8 UserName',
|
||||||
'referrer code': '推荐码',
|
'referrer code': '推荐码',
|
||||||
group: '分组',
|
group: '分组',
|
||||||
avatar: '头像',
|
avatar: '头像',
|
||||||
|
|||||||
@@ -36,12 +36,13 @@ import { baTableApi } from '/@/api/common'
|
|||||||
import TableHeader from '/@/components/table/header/index.vue'
|
import TableHeader from '/@/components/table/header/index.vue'
|
||||||
import Table from '/@/components/table/index.vue'
|
import Table from '/@/components/table/index.vue'
|
||||||
import baTableClass from '/@/utils/baTable'
|
import baTableClass from '/@/utils/baTable'
|
||||||
|
import scoreLog from '/@/lang/backend/zh-cn/user/scoreLog'
|
||||||
|
import { defaultOptButtons } from '/@/components/table'
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'user/moneyLog',
|
name: 'user/moneyLog',
|
||||||
})
|
})
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t, tm } = useI18n()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const defalutUser = (route.query.user_id ?? '') as string
|
const defalutUser = (route.query.user_id ?? '') as string
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
@@ -53,8 +54,15 @@ const baTable = new baTableClass(
|
|||||||
{
|
{
|
||||||
column: [
|
column: [
|
||||||
{ type: 'selection', align: 'center', operator: false },
|
{ type: 'selection', align: 'center', operator: false },
|
||||||
{ label: t('Id'), prop: 'id', align: 'center', operator: '=', operatorPlaceholder: t('Id'), width: 70 },
|
{
|
||||||
{ label: t('user.moneyLog.User ID'), prop: 'user_id', align: 'center', width: 70 },
|
label: t('user.moneyLog.Created by'),
|
||||||
|
prop: 'admin.username',
|
||||||
|
align: 'center',
|
||||||
|
width: 70,
|
||||||
|
formatter: (row: TableRow) => {
|
||||||
|
return row.admin?.username || 'web'
|
||||||
|
}
|
||||||
|
},
|
||||||
{ label: t('user.moneyLog.User name'), prop: 'user.username', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
{ label: t('user.moneyLog.User name'), prop: 'user.username', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
||||||
{
|
{
|
||||||
label: t('user.moneyLog.User nickname'),
|
label: t('user.moneyLog.User nickname'),
|
||||||
@@ -66,6 +74,33 @@ const baTable = new baTableClass(
|
|||||||
{ label: t('user.moneyLog.Change balance'), prop: 'money', align: 'center', operator: 'RANGE', sortable: 'custom' },
|
{ label: t('user.moneyLog.Change balance'), prop: 'money', align: 'center', operator: 'RANGE', sortable: 'custom' },
|
||||||
{ label: t('user.moneyLog.Before change'), prop: 'before', align: 'center', operator: 'RANGE', sortable: 'custom' },
|
{ label: t('user.moneyLog.Before change'), prop: 'before', align: 'center', operator: 'RANGE', sortable: 'custom' },
|
||||||
{ label: t('user.moneyLog.After change'), prop: 'after', align: 'center', operator: 'RANGE', sortable: 'custom' },
|
{ label: t('user.moneyLog.After change'), prop: 'after', align: 'center', operator: 'RANGE', sortable: 'custom' },
|
||||||
|
{ label: t('user.moneyLog.Transaction id'), prop: 'transaction_id', align: 'center', operator: 'RANGE', sortable: 'custom' },
|
||||||
|
{
|
||||||
|
label: t('user.moneyLog.Game Ticket'),
|
||||||
|
prop: 'scoreLog',
|
||||||
|
align: 'center',
|
||||||
|
// 使用渲染函数手动构建显示内容
|
||||||
|
formatter: (row: TableRow) => {
|
||||||
|
if (!row.scoreLog || row.scoreLog.length === 0) return '-'
|
||||||
|
return row.scoreLog.map((item: any) => {
|
||||||
|
const gameName = scoreLog.game_type[item.game_type] || item.game_type
|
||||||
|
return `${gameName}: ${item.score}`
|
||||||
|
}).join(' | ')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('user.moneyLog.type'),
|
||||||
|
prop: 'type',
|
||||||
|
align: 'center',
|
||||||
|
operator: 'eq',
|
||||||
|
sortable: false,
|
||||||
|
render: 'tag',
|
||||||
|
custom: {
|
||||||
|
'1': 'success',
|
||||||
|
'2': 'danger',
|
||||||
|
},
|
||||||
|
replaceValue: { ...tm('user.moneyLog.type_list') },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: t('user.moneyLog.remarks'),
|
label: t('user.moneyLog.remarks'),
|
||||||
prop: 'memo',
|
prop: 'memo',
|
||||||
@@ -75,6 +110,7 @@ const baTable = new baTableClass(
|
|||||||
showOverflowTooltip: true,
|
showOverflowTooltip: true,
|
||||||
},
|
},
|
||||||
{ label: t('Create time'), prop: 'create_time', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
|
{ label: t('Create time'), prop: 'create_time', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
|
||||||
|
{ label: t('Operate'), align: 'center', width: '60', render: 'buttons', buttons: defaultOptButtons(['edit']) },
|
||||||
],
|
],
|
||||||
dblClickNotEditColumn: ['all'],
|
dblClickNotEditColumn: ['all'],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -37,27 +37,71 @@
|
|||||||
field: 'nickname_text',
|
field: 'nickname_text',
|
||||||
remoteUrl: '/admin/user.User/index',
|
remoteUrl: '/admin/user.User/index',
|
||||||
onChange: getAdd,
|
onChange: getAdd,
|
||||||
|
disabled: baTable.form.operate == 'Edit'
|
||||||
}"
|
}"
|
||||||
/>
|
/>
|
||||||
<el-form-item :label="t('user.moneyLog.User name')">
|
<el-form-item :label="t('user.moneyLog.User name')">
|
||||||
<el-input v-model="state.userInfo.username" disabled></el-input>
|
<el-input
|
||||||
|
:model-value="baTable.form.operate == 'Edit' ? baTable.form.items!.username : state.userInfo.username"
|
||||||
|
disabled
|
||||||
|
></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="t('user.moneyLog.User nickname')">
|
<el-form-item :label="t('user.moneyLog.User name')">
|
||||||
<el-input v-model="state.userInfo.nickname" disabled></el-input>
|
<el-input
|
||||||
|
:model-value="baTable.form.operate == 'Edit' ? baTable.form.items!.nickname : state.userInfo.nickname"
|
||||||
|
disabled
|
||||||
|
></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="t('user.moneyLog.Current balance')">
|
<el-form-item :label="t('user.moneyLog.Current balance')">
|
||||||
<el-input v-model="state.userInfo.money" disabled type="number"></el-input>
|
<el-input
|
||||||
|
v-if="baTable.form.operate == 'Edit'"
|
||||||
|
v-model="baTable.form.items!.before"
|
||||||
|
type="number"
|
||||||
|
></el-input>
|
||||||
|
|
||||||
|
<el-input
|
||||||
|
v-else
|
||||||
|
v-model="state.userInfo.money"
|
||||||
|
disabled
|
||||||
|
type="number"
|
||||||
|
></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<FormItem
|
||||||
|
:label="t('user.moneyLog.type')"
|
||||||
|
type="select"
|
||||||
|
v-model="baTable.form.items!.type"
|
||||||
|
prop="type"
|
||||||
|
:input-attr="{
|
||||||
|
content: {
|
||||||
|
'1': t('user.moneyLog.type_list.1'),
|
||||||
|
'2': t('user.moneyLog.type_list.2'),
|
||||||
|
},
|
||||||
|
}"
|
||||||
|
:placeholder="t('Please select field', { field: t('user.moneyLog.type') })"
|
||||||
|
@change="(val) => { baTable.form.items!.type = val; }"
|
||||||
|
/>
|
||||||
<el-form-item prop="money" :label="t('user.moneyLog.Change amount')">
|
<el-form-item prop="money" :label="t('user.moneyLog.Change amount')">
|
||||||
<el-input
|
<el-input
|
||||||
@input="changeMoney"
|
|
||||||
v-model="baTable.form.items!.money"
|
v-model="baTable.form.items!.money"
|
||||||
type="number"
|
type="number"
|
||||||
:placeholder="t('user.moneyLog.Please enter the balance change amount')"
|
:placeholder="t('user.moneyLog.Please enter the balance change amount')"
|
||||||
|
@input="changeMoney"
|
||||||
></el-input>
|
></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="t('user.moneyLog.Balance after change')">
|
<el-form-item :label="t('user.moneyLog.Balance after change')">
|
||||||
<el-input v-model="state.after" type="number" disabled></el-input>
|
<el-input
|
||||||
|
v-if="baTable.form.operate == 'Edit'"
|
||||||
|
v-model="baTable.form.items!.after"
|
||||||
|
type="number"
|
||||||
|
></el-input>
|
||||||
|
|
||||||
|
<el-input
|
||||||
|
v-else
|
||||||
|
v-model="state.after"
|
||||||
|
type="number"
|
||||||
|
:placeholder="t('user.moneyLog.Balance after change')"
|
||||||
|
disabled
|
||||||
|
></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="memo" :label="t('user.moneyLog.remarks')">
|
<el-form-item prop="memo" :label="t('user.moneyLog.remarks')">
|
||||||
<el-input
|
<el-input
|
||||||
@@ -83,7 +127,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, inject, watch, useTemplateRef } from 'vue'
|
import { reactive, inject, watch, useTemplateRef, nextTick } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import type baTableClass from '/@/utils/baTable'
|
import type baTableClass from '/@/utils/baTable'
|
||||||
import { add } from '/@/api/backend/user/moneyLog'
|
import { add } from '/@/api/backend/user/moneyLog'
|
||||||
@@ -97,11 +141,12 @@ const { t } = useI18n()
|
|||||||
const baTable = inject('baTable') as baTableClass
|
const baTable = inject('baTable') as baTableClass
|
||||||
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
||||||
user_id: [buildValidatorData({ name: 'required', message: t('Please select field', { field: t('user.moneyLog.User') }) })],
|
user_id: [buildValidatorData({ name: 'required', message: t('Please select field', { field: t('user.moneyLog.User') }) })],
|
||||||
|
type: [buildValidatorData({ name: 'required', message: t('Please select field', { field: t('user.moneyLog.type') }) })],
|
||||||
money: [
|
money: [
|
||||||
buildValidatorData({ name: 'required', title: t('user.moneyLog.Change amount') }),
|
buildValidatorData({ name: 'required', title: t('user.moneyLog.Change amount') }),
|
||||||
{
|
{
|
||||||
validator: (rule: any, val: string, callback: Function) => {
|
validator: (rule: any, val: string, callback: Function) => {
|
||||||
if (!val || parseFloat(val) == 0) {
|
if (!val || (parseFloat(val) <= 0 && baTable.form.operate == 'Add')) {
|
||||||
return callback(new Error(t('Please enter the correct field', { field: t('user.moneyLog.Change amount') })))
|
return callback(new Error(t('Please enter the correct field', { field: t('user.moneyLog.Change amount') })))
|
||||||
}
|
}
|
||||||
return callback()
|
return callback()
|
||||||
@@ -132,13 +177,36 @@ const getAdd = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => [baTable.form.items!.money, baTable.form.items!.type],
|
||||||
|
([newMoney, newType]) => {
|
||||||
|
if (!state.userInfo || Object.keys(state.userInfo).length === 0) {
|
||||||
|
state.after = 0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputAmount = newMoney === '' ? 0 : parseFloat(newMoney as string)
|
||||||
|
const currentMoney = baTable.form.operate == 'Edit'
|
||||||
|
? parseFloat(baTable.form.items!.before)
|
||||||
|
: parseFloat(state.userInfo.money)
|
||||||
|
|
||||||
|
// 核心逻辑判断
|
||||||
|
let result = 0
|
||||||
|
if (newType == 2) {
|
||||||
|
// 类型 2:减法
|
||||||
|
result = currentMoney - inputAmount
|
||||||
|
} else {
|
||||||
|
// 其他(类型 1):加法
|
||||||
|
result = currentMoney + inputAmount
|
||||||
|
}
|
||||||
|
|
||||||
|
state.after = parseFloat(result.toFixed(2))
|
||||||
|
},
|
||||||
|
{ deep: true } // 深度监听
|
||||||
|
)
|
||||||
|
|
||||||
const changeMoney = (value: string) => {
|
const changeMoney = (value: string) => {
|
||||||
if (!state.userInfo || typeof state.userInfo == 'undefined') {
|
|
||||||
state.after = 0
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let newValue = value == '' ? 0 : parseFloat(value)
|
|
||||||
state.after = parseFloat((parseFloat(state.userInfo.money) + newValue).toFixed(2))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 打开表单时刷新用户数据
|
// 打开表单时刷新用户数据
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ const baTable = new baTableClass(
|
|||||||
{ label: t('user.user.User name'), prop: 'username', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
{ label: t('user.user.User name'), prop: 'username', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
||||||
{ label: t('user.user.nickname'), prop: 'nickname', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
{ label: t('user.user.nickname'), prop: 'nickname', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
||||||
{ label: t('user.user.jk user id'), prop: 'jk_user_id', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
{ label: t('user.user.jk user id'), prop: 'jk_user_id', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
||||||
|
{ label: t('user.user.jk user name'), prop: 'jk_username', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
||||||
{ label: t('user.user.referrer code'), prop: 'referrer_code', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query'), width: 120,},
|
{ label: t('user.user.referrer code'), prop: 'referrer_code', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query'), width: 120,},
|
||||||
{
|
{
|
||||||
label: t('user.user.group'),
|
label: t('user.user.group'),
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
v-model="baTable.form.items!.username"
|
v-model="baTable.form.items!.username"
|
||||||
type="string"
|
type="string"
|
||||||
:placeholder="t('Please input field', { field: t('user.user.User name') + '(' + t('user.user.Login account') + ')' })"
|
:placeholder="t('Please input field', { field: t('user.user.User name') + '(' + t('user.user.Login account') + ')' })"
|
||||||
disabled
|
:disabled="baTable.form.operate === 'Edit'"
|
||||||
></el-input>
|
></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="nickname" :label="t('user.user.nickname')">
|
<el-form-item prop="nickname" :label="t('user.user.nickname')">
|
||||||
@@ -42,6 +42,13 @@
|
|||||||
:placeholder="t('Please input field', { field: t('user.user.nickname') })"
|
:placeholder="t('Please input field', { field: t('user.user.nickname') })"
|
||||||
></el-input>
|
></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item prop="mobile" :label="t('user.user.mobile')">
|
||||||
|
<el-input
|
||||||
|
v-model="baTable.form.items!.mobile"
|
||||||
|
type="string"
|
||||||
|
:placeholder="t('Please input field', { field: t('user.user.mobile') })"
|
||||||
|
></el-input>
|
||||||
|
</el-form-item>
|
||||||
<FormItem
|
<FormItem
|
||||||
type="remoteSelect"
|
type="remoteSelect"
|
||||||
:label="t('user.user.group')"
|
:label="t('user.user.group')"
|
||||||
@@ -74,13 +81,6 @@
|
|||||||
:placeholder="t('Please input field', { field: t('user.user.email') })"
|
:placeholder="t('Please input field', { field: t('user.user.email') })"
|
||||||
></el-input>
|
></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="mobile" :label="t('user.user.mobile')">
|
|
||||||
<el-input
|
|
||||||
v-model="baTable.form.items!.mobile"
|
|
||||||
type="string"
|
|
||||||
:placeholder="t('Please input field', { field: t('user.user.mobile') })"
|
|
||||||
></el-input>
|
|
||||||
</el-form-item>
|
|
||||||
<FormItem
|
<FormItem
|
||||||
:label="t('user.user.Gender')"
|
:label="t('user.user.Gender')"
|
||||||
v-model="baTable.form.items!.gender"
|
v-model="baTable.form.items!.gender"
|
||||||
@@ -172,7 +172,7 @@ const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
|||||||
nickname: [buildValidatorData({ name: 'required', title: t('user.user.nickname') })],
|
nickname: [buildValidatorData({ name: 'required', title: t('user.user.nickname') })],
|
||||||
group_id: [buildValidatorData({ name: 'required', message: t('Please select field', { field: t('user.user.group') }) })],
|
group_id: [buildValidatorData({ name: 'required', message: t('Please select field', { field: t('user.user.group') }) })],
|
||||||
email: [buildValidatorData({ name: 'email', title: t('user.user.email') })],
|
email: [buildValidatorData({ name: 'email', title: t('user.user.email') })],
|
||||||
mobile: [buildValidatorData({ name: 'mobile' })],
|
mobile: [buildValidatorData({ name: 'required' })],
|
||||||
password: [
|
password: [
|
||||||
{
|
{
|
||||||
validator: (rule: any, val: string, callback: Function) => {
|
validator: (rule: any, val: string, callback: Function) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user