[接口]新增玩家-钱包记录,玩家-抽奖记录
This commit is contained in:
@@ -8,6 +8,8 @@ use support\Response;
|
||||
use app\api\cache\UserCache;
|
||||
use app\api\logic\UserLogic;
|
||||
use app\api\util\ReturnCode;
|
||||
use app\dice\model\play_record\DicePlayRecord;
|
||||
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
|
||||
use plugin\saiadmin\basic\OpenController;
|
||||
|
||||
/**
|
||||
@@ -155,4 +157,116 @@ class UserController extends OpenController
|
||||
'username' => $user['username'] ?? '',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家钱包流水
|
||||
* GET /api/user/walletRecord
|
||||
* header: user-token(或 Authorization: Bearer <user-token>)
|
||||
* 参数: page 页码(默认1), limit 每页条数(默认10), create_time_min/create_time_max 创建时间范围(可选)
|
||||
*/
|
||||
public function walletRecord(Request $request): Response
|
||||
{
|
||||
$token = $request->header('user-token');
|
||||
if (empty($token)) {
|
||||
$auth = $request->header('authorization');
|
||||
if ($auth && stripos($auth, 'Bearer ') === 0) {
|
||||
$token = trim(substr($auth, 7));
|
||||
}
|
||||
}
|
||||
if (empty($token)) {
|
||||
return $this->fail('请携带 user-token', ReturnCode::MISSING_TOKEN);
|
||||
}
|
||||
$userId = UserLogic::getUserIdFromToken($token);
|
||||
if ($userId === null) {
|
||||
return $this->fail('user-token 无效或已过期', ReturnCode::TOKEN_TIMEOUT);
|
||||
}
|
||||
|
||||
$page = (int) $request->post('page', 1);
|
||||
$limit = (int) $request->post('limit', 10);
|
||||
if ($page < 1) {
|
||||
$page = 1;
|
||||
}
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = DicePlayerWalletRecord::where('player_id', $userId)->order('id', 'desc');
|
||||
|
||||
$createTimeMin = $request->post('create_time_min', '');
|
||||
$createTimeMax = $request->post('create_time_max', '');
|
||||
if ($createTimeMin !== '' && $createTimeMin !== null) {
|
||||
$query->where('create_time', '>=', $createTimeMin);
|
||||
}
|
||||
if ($createTimeMax !== '' && $createTimeMax !== null) {
|
||||
$query->where('create_time', '<=', $createTimeMax);
|
||||
}
|
||||
|
||||
$total = $query->count();
|
||||
$list = $query->page($page, $limit)->select()->toArray();
|
||||
$totalPage = $limit > 0 ? (int) ceil($total / $limit) : 0;
|
||||
|
||||
return $this->success([
|
||||
'list' => $list,
|
||||
'total_count' => $total,
|
||||
'total_page' => $totalPage,
|
||||
'current_page' => $page,
|
||||
'limit' => $limit,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 游玩记录
|
||||
* GET /api/user/playGameRecord
|
||||
* header: user-token(或 Authorization: Bearer <user-token>)
|
||||
* 参数: page 页码(默认1), limit 每页条数(默认10), create_time_min/create_time_max 创建时间范围(可选)
|
||||
*/
|
||||
public function playGameRecord(Request $request): Response
|
||||
{
|
||||
$token = $request->header('user-token');
|
||||
if (empty($token)) {
|
||||
$auth = $request->header('authorization');
|
||||
if ($auth && stripos($auth, 'Bearer ') === 0) {
|
||||
$token = trim(substr($auth, 7));
|
||||
}
|
||||
}
|
||||
if (empty($token)) {
|
||||
return $this->fail('请携带 user-token', ReturnCode::MISSING_TOKEN);
|
||||
}
|
||||
$userId = UserLogic::getUserIdFromToken($token);
|
||||
if ($userId === null) {
|
||||
return $this->fail('user-token 无效或已过期', ReturnCode::TOKEN_TIMEOUT);
|
||||
}
|
||||
|
||||
$page = (int) $request->post('page', 1);
|
||||
$limit = (int) $request->post('limit', 10);
|
||||
if ($page < 1) {
|
||||
$page = 1;
|
||||
}
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = DicePlayRecord::where('player_id', $userId)->order('id', 'desc');
|
||||
|
||||
$createTimeMin = $request->post('create_time_min', '');
|
||||
$createTimeMax = $request->post('create_time_max', '');
|
||||
if ($createTimeMin !== '' && $createTimeMin !== null) {
|
||||
$query->where('create_time', '>=', $createTimeMin);
|
||||
}
|
||||
if ($createTimeMax !== '' && $createTimeMax !== null) {
|
||||
$query->where('create_time', '<=', $createTimeMax);
|
||||
}
|
||||
|
||||
$total = $query->count();
|
||||
$list = $query->page($page, $limit)->select()->toArray();
|
||||
$totalPage = $limit > 0 ? (int) ceil($total / $limit) : 0;
|
||||
|
||||
return $this->success([
|
||||
'list' => $list,
|
||||
'total_count' => $total,
|
||||
'total_page' => $totalPage,
|
||||
'current_page' => $page,
|
||||
'limit' => $limit,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ Route::group('/api', function () {
|
||||
Route::post('/user/logout', [app\api\controller\UserController::class, 'logout']);
|
||||
Route::get('/user/info', [app\api\controller\UserController::class, 'info']);
|
||||
Route::get('/user/balance', [app\api\controller\UserController::class, 'balance']);
|
||||
Route::get('/user/walletRecord', [app\api\controller\UserController::class, 'walletRecord']);
|
||||
Route::get('/user/playGameRecord', [app\api\controller\UserController::class, 'playGameRecord']);
|
||||
Route::post('/game/buyLotteryTickets', [app\api\controller\GameController::class, 'buyLotteryTickets']);
|
||||
Route::get('/game/lotteryPool', [app\api\controller\GameController::class, 'lotteryPool']);
|
||||
Route::post('/game/playStart', [app\api\controller\GameController::class, 'playStart']);
|
||||
|
||||
Reference in New Issue
Block a user