优化后台修改玩家信息(钱包等)没有更新缓存的问题
This commit is contained in:
@@ -14,6 +14,7 @@ use support\think\Db;
|
|||||||
use app\api\controller\BaseController;
|
use app\api\controller\BaseController;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
|
use app\api\cache\UserCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 平台 v1 游戏接口
|
* 平台 v1 游戏接口
|
||||||
@@ -297,6 +298,12 @@ class GameController extends BaseController
|
|||||||
return $this->fail('操作失败:' . $e->getMessage(), ReturnCode::SERVER_ERROR);
|
return $this->fail('操作失败:' . $e->getMessage(), ReturnCode::SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 出于安全:删除该玩家相关缓存,后续 API 调用按需重建
|
||||||
|
UserCache::deleteUser($player->id);
|
||||||
|
if ($player->username !== '') {
|
||||||
|
UserCache::deletePlayerByUsername($player->username);
|
||||||
|
}
|
||||||
|
|
||||||
$recordArr = $record->toArray();
|
$recordArr = $record->toArray();
|
||||||
$recordArr['dice_player'] = ['id' => (int) $player->id, 'username' => $player->username ?? '', 'phone' => $player->phone ?? ''];
|
$recordArr['dice_player'] = ['id' => (int) $player->id, 'username' => $player->username ?? '', 'phone' => $player->phone ?? ''];
|
||||||
return $this->success($recordArr);
|
return $this->success($recordArr);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | saiadmin [ saiadmin?????? ]
|
// | saiadmin [ saiadmin快速开发框架 ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: your name
|
// | Author: your name
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
@@ -15,14 +15,16 @@ use app\dice\validate\player\DicePlayerValidate;
|
|||||||
use plugin\saiadmin\service\Permission;
|
use plugin\saiadmin\service\Permission;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
|
use app\api\cache\UserCache;
|
||||||
|
use app\dice\model\player\DicePlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ???-?????
|
* 玩家控制器
|
||||||
*/
|
*/
|
||||||
class DicePlayerController extends BaseController
|
class DicePlayerController extends BaseController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* ????
|
* 构造函数
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -32,11 +34,11 @@ class DicePlayerController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ??????????DiceLotteryPoolConfig.id?name????? lottery_config_id ????
|
* 获取彩金池配置选项(id、name)
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Response ?? [ ['id' => int, 'name' => string], ... ]
|
* @return Response
|
||||||
*/
|
*/
|
||||||
#[Permission('???-????', 'dice:player:index:index')]
|
#[Permission('玩家列表', 'dice:player:index:index')]
|
||||||
public function getLotteryConfigOptions(Request $request): Response
|
public function getLotteryConfigOptions(Request $request): Response
|
||||||
{
|
{
|
||||||
$list = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc')->select();
|
$list = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc')->select();
|
||||||
@@ -47,12 +49,11 @@ class DicePlayerController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ??????????SystemUser.id?username?realname??? admin_id ????
|
* 获取后台管理员选项(id、username、realname)
|
||||||
* ????????????????????????????????
|
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Response ?? [ ['id' => int, 'username' => string, 'realname' => string], ... ]
|
* @return Response
|
||||||
*/
|
*/
|
||||||
#[Permission('???-????', 'dice:player:index:index')]
|
#[Permission('玩家列表', 'dice:player:index:index')]
|
||||||
public function getSystemUserOptions(Request $request): Response
|
public function getSystemUserOptions(Request $request): Response
|
||||||
{
|
{
|
||||||
$query = SystemUser::field('id,username,realname')->where('status', 1)->order('id', 'asc');
|
$query = SystemUser::field('id,username,realname')->where('status', 1)->order('id', 'asc');
|
||||||
@@ -76,11 +77,11 @@ class DicePlayerController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ????
|
* 数据列表
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
#[Permission('???-????', 'dice:player:index:index')]
|
#[Permission('玩家列表', 'dice:player:index:index')]
|
||||||
public function index(Request $request): Response
|
public function index(Request $request): Response
|
||||||
{
|
{
|
||||||
$where = $request->more([
|
$where = $request->more([
|
||||||
@@ -99,54 +100,59 @@ class DicePlayerController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ????
|
* 读取数据
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
#[Permission('???-????', 'dice:player:index:read')]
|
#[Permission('玩家读取', 'dice:player:index:read')]
|
||||||
public function read(Request $request): Response
|
public function read(Request $request): Response
|
||||||
{
|
{
|
||||||
$id = $request->input('id', '');
|
$id = $request->input('id', '');
|
||||||
$model = $this->logic->read($id);
|
$model = $this->logic->read($id);
|
||||||
if (!$model) {
|
if (!$model) {
|
||||||
return $this->fail('??????');
|
return $this->fail('未查找到信息');
|
||||||
}
|
}
|
||||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||||
return $this->fail('????????');
|
return $this->fail('无权限查看该记录');
|
||||||
}
|
}
|
||||||
$data = is_array($model) ? $model : $model->toArray();
|
$data = is_array($model) ? $model : $model->toArray();
|
||||||
return $this->success($data);
|
return $this->success($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ????
|
* 保存数据
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
#[Permission('???-????', 'dice:player:index:save')]
|
#[Permission('玩家添加', 'dice:player:index:save')]
|
||||||
public function save(Request $request): Response
|
public function save(Request $request): Response
|
||||||
{
|
{
|
||||||
$data = $request->post();
|
$data = $request->post();
|
||||||
$this->validate('save', $data);
|
$this->validate('save', $data);
|
||||||
// ?????????????????????
|
// 类型转化
|
||||||
if (empty($data['admin_id']) && isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 0) {
|
if (empty($data['admin_id']) && isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 0) {
|
||||||
$data['admin_id'] = (int) $this->adminInfo['id'];
|
$data['admin_id'] = (int) $this->adminInfo['id'];
|
||||||
}
|
}
|
||||||
$result = $this->logic->add($data);
|
$result = $this->logic->add($data);
|
||||||
if ($result) {
|
if ($result && isset($result['id'])) {
|
||||||
return $this->success('????');
|
// 出于安全:删除该玩家缓存,后续 API 按需重建
|
||||||
} else {
|
UserCache::deleteUser($result['id']);
|
||||||
return $this->fail('????');
|
$player = DicePlayer::find($result['id']);
|
||||||
|
if ($player && $player->username !== '') {
|
||||||
|
UserCache::deletePlayerByUsername($player->username);
|
||||||
|
}
|
||||||
|
return $this->success('添加成功');
|
||||||
}
|
}
|
||||||
|
return $this->fail('添加失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ????
|
* 更新数据
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
#[Permission('???-????', 'dice:player:index:update')]
|
#[Permission('玩家修改', 'dice:player:index:update')]
|
||||||
public function update(Request $request): Response
|
public function update(Request $request): Response
|
||||||
{
|
{
|
||||||
$data = $request->post();
|
$data = $request->post();
|
||||||
@@ -155,55 +161,66 @@ class DicePlayerController extends BaseController
|
|||||||
if ($model) {
|
if ($model) {
|
||||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||||
return $this->fail('????????');
|
return $this->fail('无权限修改该记录');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result = $this->logic->edit($data['id'], $data);
|
$result = $this->logic->edit($data['id'], $data);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $this->success('????');
|
// 出于安全:删除该玩家缓存,后续 API 按需重建
|
||||||
} else {
|
UserCache::deleteUser($data['id']);
|
||||||
return $this->fail('????');
|
$player = DicePlayer::find($data['id']);
|
||||||
|
if ($player && $player->username !== '') {
|
||||||
|
UserCache::deletePlayerByUsername($player->username);
|
||||||
|
}
|
||||||
|
return $this->success('修改成功');
|
||||||
}
|
}
|
||||||
|
return $this->fail('修改失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ?????????????
|
* 更新状态
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
#[Permission('???-????', 'dice:player:index:update')]
|
#[Permission('玩家状态修改', 'dice:player:index:update')]
|
||||||
public function updateStatus(Request $request): Response
|
public function updateStatus(Request $request): Response
|
||||||
{
|
{
|
||||||
$id = $request->input('id');
|
$id = $request->input('id');
|
||||||
$status = $request->input('status');
|
$status = $request->input('status');
|
||||||
if ($id === null || $id === '') {
|
if ($id === null || $id === '') {
|
||||||
return $this->fail('?? id');
|
return $this->fail('缺少参数 id');
|
||||||
}
|
}
|
||||||
if ($status === null || $status === '') {
|
if ($status === null || $status === '') {
|
||||||
return $this->fail('?? status');
|
return $this->fail('缺少参数 status');
|
||||||
}
|
}
|
||||||
$model = $this->logic->read($id);
|
$model = $this->logic->read($id);
|
||||||
if ($model) {
|
if ($model) {
|
||||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||||
return $this->fail('????????');
|
return $this->fail('无权限修改该记录');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->logic->edit($id, ['status' => (int) $status]);
|
$this->logic->edit($id, ['status' => (int) $status]);
|
||||||
return $this->success('????');
|
// 出于安全:删除该玩家缓存,后续 API 按需重建
|
||||||
|
UserCache::deleteUser($id);
|
||||||
|
$player = DicePlayer::find($id);
|
||||||
|
if ($player && $player->username !== '') {
|
||||||
|
UserCache::deletePlayerByUsername($player->username);
|
||||||
|
}
|
||||||
|
return $this->success('修改成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ????
|
* 删除数据
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
#[Permission('???-????', 'dice:player:index:destroy')]
|
#[Permission('玩家删除', 'dice:player:index:destroy')]
|
||||||
public function destroy(Request $request): Response
|
public function destroy(Request $request): Response
|
||||||
{
|
{
|
||||||
$ids = $request->post('ids', '');
|
$ids = $request->post('ids', '');
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
return $this->fail('?????????');
|
return $this->fail('请选择要删除的数据');
|
||||||
}
|
}
|
||||||
$ids = is_array($ids) ? $ids : explode(',', (string) $ids);
|
$ids = is_array($ids) ? $ids : explode(',', (string) $ids);
|
||||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||||
@@ -218,15 +235,22 @@ class DicePlayerController extends BaseController
|
|||||||
}
|
}
|
||||||
$ids = $validIds;
|
$ids = $validIds;
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
return $this->fail('?????????');
|
return $this->fail('无权限删除所选数据');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result = $this->logic->destroy($ids);
|
$result = $this->logic->destroy($ids);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $this->success('????');
|
// 出于安全:删除相关玩家缓存,后续 API 按需重建
|
||||||
} else {
|
foreach ($ids as $id) {
|
||||||
return $this->fail('????');
|
UserCache::deleteUser($id);
|
||||||
|
$player = DicePlayer::find($id);
|
||||||
|
if ($player && $player->username !== '') {
|
||||||
|
UserCache::deletePlayerByUsername($player->username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->success('删除成功');
|
||||||
}
|
}
|
||||||
|
return $this->fail('删除失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use plugin\saiadmin\basic\think\BaseLogic;
|
|||||||
use plugin\saiadmin\exception\ApiException;
|
use plugin\saiadmin\exception\ApiException;
|
||||||
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
|
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
|
||||||
use app\dice\model\player\DicePlayer;
|
use app\dice\model\player\DicePlayer;
|
||||||
|
use app\api\cache\UserCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 玩家钱包流水逻辑层
|
* 玩家钱包流水逻辑层
|
||||||
@@ -73,6 +74,12 @@ class DicePlayerWalletRecordLogic extends BaseLogic
|
|||||||
|
|
||||||
DicePlayer::where('id', $playerId)->update(['coin' => $walletAfter]);
|
DicePlayer::where('id', $playerId)->update(['coin' => $walletAfter]);
|
||||||
|
|
||||||
|
// 出于安全:删除该玩家相关缓存,后续 API 按需重建
|
||||||
|
UserCache::deleteUser($playerId);
|
||||||
|
if (isset($player->username) && $player->username !== '') {
|
||||||
|
UserCache::deletePlayerByUsername($player->username);
|
||||||
|
}
|
||||||
|
|
||||||
$playerAdminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
|
$playerAdminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
|
||||||
$record = [
|
$record = [
|
||||||
'player_id' => $playerId,
|
'player_id' => $playerId,
|
||||||
|
|||||||
Reference in New Issue
Block a user