diff --git a/saiadmin-artd/src/views/plugin/dice/api/player_wallet_record/index.ts b/saiadmin-artd/src/views/plugin/dice/api/player_wallet_record/index.ts index aec3c77..04be5e2 100644 --- a/saiadmin-artd/src/views/plugin/dice/api/player_wallet_record/index.ts +++ b/saiadmin-artd/src/views/plugin/dice/api/player_wallet_record/index.ts @@ -80,5 +80,21 @@ export default { url: '/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerWalletBefore', params: { player_id: playerId } }) + }, + + /** + * 管理员钱包操作(加点/扣点):更新玩家平台币并创建流水记录 + * type 3=加点 4=扣点 + */ + adminOperate(params: { + player_id: number + type: 3 | 4 + coin: number + remark?: string + }) { + return request.post({ + url: '/dice/player_wallet_record/DicePlayerWalletRecord/adminOperate', + data: params + }) } } diff --git a/saiadmin-artd/src/views/plugin/dice/player/index/index.vue b/saiadmin-artd/src/views/plugin/dice/player/index/index.vue index 4544597..8f367c5 100644 --- a/saiadmin-artd/src/views/plugin/dice/player/index/index.vue +++ b/saiadmin-artd/src/views/plugin/dice/player/index/index.vue @@ -51,9 +51,16 @@ @change="(v: string | number | boolean) => handleStatusChange(row, v ? 1 : 0)" /> - + @@ -89,6 +103,7 @@ import api from '../../api/player/index' import TableSearch from './modules/table-search.vue' import EditDialog from './modules/edit-dialog.vue' + import WalletOperateDialog from './modules/WalletOperateDialog.vue' // 搜索表单 const searchForm = ref({ @@ -188,4 +203,13 @@ handleSelectionChange, selectedRows } = useSaiAdmin() + + // 钱包操作弹窗(从平台币 tag 点击打开) + const walletDialogVisible = ref(false) + const walletOperatePlayer = ref | null>(null) + + function openWalletOperate(row: Record) { + walletOperatePlayer.value = row + walletDialogVisible.value = true + } diff --git a/saiadmin-artd/src/views/plugin/dice/player/index/modules/WalletOperateDialog.vue b/saiadmin-artd/src/views/plugin/dice/player/index/modules/WalletOperateDialog.vue new file mode 100644 index 0000000..266702e --- /dev/null +++ b/saiadmin-artd/src/views/plugin/dice/player/index/modules/WalletOperateDialog.vue @@ -0,0 +1,172 @@ + + + diff --git a/saiadmin-artd/src/views/plugin/dice/player_wallet_record/index/index.vue b/saiadmin-artd/src/views/plugin/dice/player_wallet_record/index/index.vue index 0ba9da6..ae6226b 100644 --- a/saiadmin-artd/src/views/plugin/dice/player_wallet_record/index/index.vue +++ b/saiadmin-artd/src/views/plugin/dice/player_wallet_record/index/index.vue @@ -102,9 +102,23 @@ getData() } - // 类型展示:0=充值 1=提现 2=购买抽奖次数 - const typeFormatter = (row: Record) => - row.type === 0 ? '充值' : row.type === 1 ? '提现' : row.type === 2 ? '购买抽奖次数' : '-' + // 类型展示:0=充值 1=提现 2=购买抽奖次数 3=管理员加点 4=管理员扣点 + const typeFormatter = (row: Record) => { + const t = row.type + if (t === 0) return '充值' + if (t === 1) return '提现' + if (t === 2) return '购买抽奖次数' + if (t === 3) return '管理员加点' + if (t === 4) return '管理员扣点' + return '-' + } + + // 操作人:关联管理员用户名 + const operatorFormatter = (row: Record) => { + const op = row.operator ?? row.operator_id + if (op && typeof op === 'object' && op.username) return op.username + return row.user_id ?? '-' + } // 用户列展示为 dicePlayer.username(兼容 dice_player) const usernameFormatter = (row: Record) => { @@ -135,6 +149,12 @@ { prop: 'player_id', label: '用户', width: 120, formatter: usernameFormatter }, { prop: 'coin', label: '平台币变化', width: 110 }, { prop: 'type', label: '类型', width: 120, formatter: typeFormatter }, + { + prop: 'user_id', + label: '操作人', + width: 100, + formatter: operatorFormatter + }, { prop: 'wallet_before', label: '钱包操作前', width: 110 }, { prop: 'wallet_after', label: '钱包操作后', width: 110 }, { diff --git a/saiadmin-artd/src/views/plugin/dice/player_wallet_record/index/modules/edit-dialog.vue b/saiadmin-artd/src/views/plugin/dice/player_wallet_record/index/modules/edit-dialog.vue index 14df797..1983cce 100644 --- a/saiadmin-artd/src/views/plugin/dice/player_wallet_record/index/modules/edit-dialog.vue +++ b/saiadmin-artd/src/views/plugin/dice/player_wallet_record/index/modules/edit-dialog.vue @@ -31,6 +31,8 @@ + + diff --git a/saiadmin-artd/src/views/plugin/dice/player_wallet_record/index/modules/table-search.vue b/saiadmin-artd/src/views/plugin/dice/player_wallet_record/index/modules/table-search.vue index 83b723f..5de2f6c 100644 --- a/saiadmin-artd/src/views/plugin/dice/player_wallet_record/index/modules/table-search.vue +++ b/saiadmin-artd/src/views/plugin/dice/player_wallet_record/index/modules/table-search.vue @@ -14,6 +14,8 @@ + + diff --git a/server/app/dice/controller/player_wallet_record/DicePlayerWalletRecordController.php b/server/app/dice/controller/player_wallet_record/DicePlayerWalletRecordController.php index 06697f5..4d98f5e 100644 --- a/server/app/dice/controller/player_wallet_record/DicePlayerWalletRecordController.php +++ b/server/app/dice/controller/player_wallet_record/DicePlayerWalletRecordController.php @@ -13,6 +13,7 @@ use app\dice\model\player\DicePlayer; use plugin\saiadmin\service\Permission; use support\Request; use support\Response; +use Tinywan\Jwt\JwtToken; /** * 玩家钱包流水控制器 @@ -48,6 +49,7 @@ class DicePlayerWalletRecordController extends BaseController $query = $this->logic->search($where); $query->with([ 'dicePlayer', + 'operator', ]); $data = $this->logic->getList($query); return $this->success($data); @@ -106,6 +108,61 @@ class DicePlayerWalletRecordController extends BaseController } } + /** + * 管理员钱包操作(加点/扣点):更新玩家平台币并创建流水记录 + * @param Request $request + * @return Response + */ + #[Permission('玩家钱包流水添加', 'dice:player_wallet_record:index:save')] + public function adminOperate(Request $request): Response + { + $data = $request->post(); + $playerId = $data['player_id'] ?? null; + $type = isset($data['type']) ? (int) $data['type'] : null; + $coin = isset($data['coin']) ? (float) $data['coin'] : null; + + if ($playerId === null || $playerId === '') { + return $this->fail('请选择玩家'); + } + if (!in_array($type, [3, 4], true)) { + return $this->fail('操作类型必须为 3=加点 或 4=扣点'); + } + if ($coin === null || $coin <= 0) { + return $this->fail('平台币变动必须大于 0'); + } + + $data['player_id'] = $playerId; + $data['type'] = $type; + $data['coin'] = $coin; + $data['remark'] = $data['remark'] ?? ''; + + $adminId = null; + $checkAdmin = request()->header('check_admin'); + if (!empty($checkAdmin['id'])) { + $adminId = (int) $checkAdmin['id']; + } + if (($adminId === null || $adminId <= 0)) { + try { + $token = JwtToken::getExtend(); + if (!empty($token['id']) && ($token['plat'] ?? '') === 'saiadmin') { + $adminId = (int) $token['id']; + } + } catch (\Throwable $e) { + // JWT 无效或未携带 + } + } + if ($adminId === null || $adminId <= 0) { + return $this->fail('请先登录'); + } + + try { + $this->logic->adminOperate($data, $adminId); + return $this->success('操作成功'); + } catch (\Throwable $e) { + return $this->fail($e->getMessage()); + } + } + /** * 保存数据 * @param Request $request diff --git a/server/app/dice/logic/player_wallet_record/DicePlayerWalletRecordLogic.php b/server/app/dice/logic/player_wallet_record/DicePlayerWalletRecordLogic.php index fd73327..49f341f 100644 --- a/server/app/dice/logic/player_wallet_record/DicePlayerWalletRecordLogic.php +++ b/server/app/dice/logic/player_wallet_record/DicePlayerWalletRecordLogic.php @@ -8,8 +8,8 @@ namespace app\dice\logic\player_wallet_record; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\exception\ApiException; -use plugin\saiadmin\utils\Helper; use app\dice\model\player_wallet_record\DicePlayerWalletRecord; +use app\dice\model\player\DicePlayer; /** * 玩家钱包流水逻辑层 @@ -35,4 +35,57 @@ class DicePlayerWalletRecordLogic extends BaseLogic return parent::add($data); } + /** + * 管理员钱包操作(加点/扣点):更新玩家平台币并创建流水记录 + * @param array $data player_id, type (3=加点 4=扣点), coin (正数), remark (可选) + * @param int $adminId 当前管理员 id + * @return mixed + * @throws ApiException + */ + public function adminOperate(array $data, int $adminId): mixed + { + $playerId = (int) ($data['player_id'] ?? 0); + $type = (int) ($data['type'] ?? 0); + $coin = (float) ($data['coin'] ?? 0); + + if ($playerId <= 0 || !in_array($type, [3, 4], true)) { + throw new ApiException('参数错误:需要有效的 player_id 和 type(3=加点,4=扣点)'); + } + if ($coin <= 0) { + throw new ApiException('平台币变动必须大于 0'); + } + + $player = DicePlayer::where('id', $playerId)->find(); + if (!$player) { + throw new ApiException('玩家不存在'); + } + + $walletBefore = (float) ($player['coin'] ?? 0); + if ($type === 4 && $walletBefore < $coin) { + throw new ApiException('扣点数量不能大于当前余额'); + } + + $walletAfter = $type === 3 ? $walletBefore + $coin : $walletBefore - $coin; + $remark = trim((string) ($data['remark'] ?? '')); + if ($remark === '') { + $remark = $type === 3 ? '管理员加点' : '管理员扣点'; + } + + DicePlayer::where('id', $playerId)->update(['coin' => $walletAfter]); + + $record = [ + 'player_id' => $playerId, + 'coin' => $type === 3 ? $coin : -$coin, + 'type' => $type, + 'wallet_before' => $walletBefore, + 'wallet_after' => $walletAfter, + 'remark' => $remark, + 'user_id' => $adminId, + 'total_draw_count' => 0, + 'paid_draw_count' => 0, + 'free_draw_count' => 0, + ]; + + return $this->model->create($record); + } } diff --git a/server/app/dice/model/player_wallet_record/DicePlayerWalletRecord.php b/server/app/dice/model/player_wallet_record/DicePlayerWalletRecord.php index f2a7615..1b757d8 100644 --- a/server/app/dice/model/player_wallet_record/DicePlayerWalletRecord.php +++ b/server/app/dice/model/player_wallet_record/DicePlayerWalletRecord.php @@ -8,6 +8,8 @@ namespace app\dice\model\player_wallet_record; use app\dice\model\player\DicePlayer; use plugin\saiadmin\basic\think\BaseModel; +use plugin\saiadmin\app\model\system\SystemUser; +use think\model\relation\BelongsTo; /** * 玩家钱包流水模型 @@ -24,6 +26,7 @@ use plugin\saiadmin\basic\think\BaseModel; * @property $paid_draw_count 购买抽奖次数 * @property $free_draw_count 赠送抽奖次数 * @property $remark 备注 + * @property $user_id 操作管理员id(type 3/4 时记录) * @property $create_time 创建时间 * @property $update_time 修改时间 */ @@ -44,11 +47,19 @@ class DicePlayerWalletRecord extends BaseModel /** * 关联模型 dicePlayer */ - public function dicePlayer(): \think\model\relation\BelongsTo + public function dicePlayer(): BelongsTo { return $this->belongsTo(DicePlayer::class, 'player_id', 'id'); } + /** + * 关联操作管理员(type 3/4 时有值) + */ + public function operator(): BelongsTo + { + return $this->belongsTo(SystemUser::class, 'user_id', 'id'); + } + /** * 类型 搜索 */ diff --git a/server/plugin/saiadmin/basic/BaseController.php b/server/plugin/saiadmin/basic/BaseController.php index 0ddc4a6..7420d7d 100644 --- a/server/plugin/saiadmin/basic/BaseController.php +++ b/server/plugin/saiadmin/basic/BaseController.php @@ -21,14 +21,14 @@ class BaseController extends OpenController protected $adminInfo; /** - * 当前登陆管理员ID + * 当前登陆管理员ID(未登录时为 null) */ - protected int $adminId; + protected ?int $adminId = null; /** - * 当前登陆管理员账号 + * 当前登陆管理员账号(未登录时为空字符串) */ - protected string $adminName; + protected string $adminName = ''; /** * 逻辑层注入