[色子游戏]玩家-新增玩家钱包操作
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user