首页修改,jk8修改,历史记录相关,api权限
This commit is contained in:
@@ -2,19 +2,270 @@
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\model\MoneyLogHistory;
|
||||
use app\admin\model\User;
|
||||
use app\admin\model\UserMoneyLog;
|
||||
use app\common\controller\Backend;
|
||||
use app\admin\model\Bank;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\Request;
|
||||
use Throwable;
|
||||
|
||||
class Dashboard extends Backend
|
||||
{
|
||||
/**
|
||||
* @var object
|
||||
* @phpstan-var Bank
|
||||
*/
|
||||
protected object $bank;
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
$this->bank = new Bank();
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
$rawStart = request()->param('start/s');
|
||||
$start = $rawStart ? strtotime($rawStart) : strtotime('today');
|
||||
$rawEnd = request()->param('end/s');
|
||||
$end = $rawEnd ? strtotime("$rawEnd +1 day") : strtotime('tomorrow');
|
||||
if ($start > $end) {
|
||||
list($start, $end) = [$end, $start];
|
||||
}
|
||||
$bankList = Bank::field([
|
||||
'id', 'bank_name', 'bank_account', 'current_balance', 'safe_alert', 'label_color', 'weigh',
|
||||
// 子查询:入款总额
|
||||
"(SELECT SUM(money/100) FROM ba_user_money_log WHERE bank_id = ba_bank.id AND type = 1 and create_time BETWEEN {$start} AND {$end}) AS total_fund_in",
|
||||
// 子查询:出款总额
|
||||
"(SELECT SUM(money/100) FROM ba_user_money_log WHERE bank_id = ba_bank.id AND type = 2 and create_time BETWEEN {$start} AND {$end}) AS total_fund_out",
|
||||
// 子查询:入款次数
|
||||
"(SELECT COUNT(*) FROM ba_user_money_log WHERE bank_id = ba_bank.id AND type = 1 and create_time BETWEEN {$start} AND {$end}) AS count_fund_in",
|
||||
// 子查询:出款次数
|
||||
"(SELECT COUNT(*) FROM ba_user_money_log WHERE bank_id = ba_bank.id AND type = 2 and create_time BETWEEN {$start} AND {$end}) AS count_fund_out",
|
||||
])
|
||||
->where('status', 1)
|
||||
->order('weigh', 'desc')
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($bankList as &$bank) {
|
||||
$bank['total_fund_in'] = (float)$bank['total_fund_in'];
|
||||
$bank['total_fund_out'] = (float)$bank['total_fund_out'];
|
||||
$bank['count_fund_in'] = (int)$bank['count_fund_in'];
|
||||
$bank['count_fund_out'] = (int)$bank['count_fund_out'];
|
||||
}
|
||||
unset($bank);
|
||||
$customer = Db::name('user_money_log')->field([
|
||||
// 1. 总进款 (type = 1)
|
||||
'ROUND(SUM(CASE WHEN type = 1 THEN money/100 ELSE 0 END), 2) AS total_deposit',
|
||||
// 2. 总出款 (type = 2)
|
||||
'ROUND(SUM(CASE WHEN type = 2 THEN money/100 ELSE 0 END), 2) AS total_withdraw',
|
||||
// 3. 总进款次数 (type = 1 的记录总数)
|
||||
'COUNT(CASE WHEN type = 1 THEN 1 END) AS count_deposit',
|
||||
// 4. 总出款次数 (type = 2 的记录总数)
|
||||
'COUNT(CASE WHEN type = 2 THEN 1 END) AS count_withdraw',
|
||||
// 5. 活跃玩家数 (去重计算有多少个不同的 user_id 产生了流水)
|
||||
'COUNT(DISTINCT user_id) AS active_player',
|
||||
//6. 首次充值
|
||||
'COUNT(CASE WHEN label = 1 THEN 1 END) AS first_deposit',
|
||||
'ROUND(SUM(CASE WHEN label = 2 THEN money/100 ELSE 0 END), 2) AS unclaim_amount',
|
||||
'COUNT(CASE WHEN label = 2 THEN 1 END) AS unclaim_receipt',
|
||||
])
|
||||
->whereBetweenTime('create_time', $start, $end)
|
||||
->whereNull('created_by')
|
||||
->find();
|
||||
$customerData = [
|
||||
'total_deposit' => (float)($customer['total_deposit'] ?? 0),
|
||||
'total_withdraw' => (float)($customer['total_withdraw'] ?? 0),
|
||||
'count_deposit' => (int)($customer['count_deposit'] ?? 0),
|
||||
'count_withdraw' => (int)($customer['count_withdraw'] ?? 0),
|
||||
'active_player' => (int)($customer['active_player'] ?? 0),
|
||||
'first_deposit' => (int)($customer['first_deposit'] ?? 0),
|
||||
'unclaim_amount' => (float)($customer['unclaim_amount'] ?? 0),
|
||||
'unclaim_receipt' => (int)($customer['unclaim_receipt'] ?? 0),
|
||||
];
|
||||
$limit = request()->param('limit/d') ?? 15;
|
||||
$bindFields = [
|
||||
'user' => ['jk_username'],
|
||||
'bank' => ['bank_name'],
|
||||
'admin' => ['id', 'username'],
|
||||
];
|
||||
$transaction = UserMoneyLog::withJoin($bindFields, 'left')
|
||||
->with([
|
||||
'scoreLog' => function($query) {
|
||||
$query->field(['money_log_id', 'game_type', 'score']);
|
||||
}
|
||||
])
|
||||
->whereBetweenTime('user_money_log.create_time', $start, $end)
|
||||
->order('id', 'desc')
|
||||
->paginate($limit);
|
||||
$transactionList = $transaction->items();
|
||||
foreach ($transactionList as &$item) {
|
||||
$item['user_name'] = $item['user']['jk_username'] ?? '';
|
||||
$item['bank_name'] = $item['bank']['bank_name'] ?? '';
|
||||
$item['created_by'] = $item['admin']['username'] ?? 'WEBHOOK';
|
||||
unset($item['user'], $item['bank'], $item['admin']);
|
||||
}
|
||||
unset($item);
|
||||
$transactionTotal = Db::name('user_money_log')->field([
|
||||
// 1. 总进款 (type = 1)
|
||||
'ROUND(SUM(CASE WHEN type = 1 THEN money/100 ELSE 0 END), 2) AS total_fund_in',
|
||||
// 2. 总出款 (type = 2)
|
||||
'ROUND(SUM(CASE WHEN type = 2 THEN money/100 ELSE 0 END), 2) AS total_fund_out',
|
||||
])
|
||||
->whereBetweenTime('create_time', $start, $end)
|
||||
->find();
|
||||
$this->success('', [
|
||||
'remark' => get_route_remark()
|
||||
'bank' => $bankList,
|
||||
'customer' => $customerData,
|
||||
'transaction'=> [
|
||||
'list' => $transactionList,
|
||||
'count' => $transaction->total(),
|
||||
'current_page' => $transaction->currentPage(),
|
||||
'last_page' => $transaction->lastPage(),
|
||||
'total_deposit' => (float)($transactionTotal['total_fund_in'] ?? 0),
|
||||
'total_withdraw' => (float)($transactionTotal['total_fund_out'] ?? 0),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function bankTransact(): void
|
||||
{
|
||||
$data = $this->request->post();
|
||||
if (!$data) {
|
||||
$this->error(__('Parameter %s can not be empty', ['']));
|
||||
}
|
||||
|
||||
$money = isset($data['money']) ? (int)$data['money'] : 0;
|
||||
$bankFromId = isset($data['bank_from']) ? (int)$data['bank_from'] : 0;
|
||||
$bankToId = isset($data['bank_to']) ? (int)$data['bank_to'] : 0;
|
||||
if ($money <= 0) {
|
||||
$this->error(__('转账金额必须大于 0'));
|
||||
}
|
||||
if ($bankFromId === $bankToId) {
|
||||
$this->error(__('转出银行和转入银行不能相同'));
|
||||
}
|
||||
$adminId = $this->auth->getInfo()['id'] ?? null;
|
||||
\think\facade\Db::startTrans();
|
||||
try {
|
||||
$bankFrom = Bank::where('id', $bankFromId)->where('status', 1)->lock(true)->find();
|
||||
if (!$bankFrom) {
|
||||
throw new ValidateException('转出银行账户不存在或已被禁用');
|
||||
}
|
||||
if ($bankFrom->current_balance < $money) {
|
||||
throw new ValidateException("转出银行【{$bankFrom->bank_name}】余额不足");
|
||||
}
|
||||
|
||||
$bankTo = Bank::where('id', $bankToId)->where('status', 1)->lock(true)->find();
|
||||
if (!$bankTo) {
|
||||
throw new ValidateException('转入银行账户不存在或已被禁用');
|
||||
}
|
||||
|
||||
// 5. 更新转出银行账户余额
|
||||
$bankFrom->current_balance -= $money;
|
||||
$bankFrom->save();
|
||||
|
||||
$logFrom = new UserMoneyLog();
|
||||
$logFrom->save([
|
||||
'user_id' => 0,
|
||||
'money' => -$money,
|
||||
'before' => $bankFrom->current_balance + $money,
|
||||
'after' => $bankFrom->current_balance,
|
||||
'type' => 4,
|
||||
'bank_id' => $bankFromId,
|
||||
'created_by' => $adminId,
|
||||
'memo' => $data['remark'],
|
||||
'category' => 2,
|
||||
'create_time' => time()
|
||||
]);
|
||||
|
||||
$bankTo->current_balance += $money;
|
||||
$bankTo->save();
|
||||
|
||||
$logTo = new UserMoneyLog();
|
||||
$logTo->save([
|
||||
'user_id' => 0,
|
||||
'money' => $money,
|
||||
'before' => $bankTo->current_balance - $money,
|
||||
'after' => $bankTo->current_balance,
|
||||
'type' => 3,
|
||||
'bank_id' => $bankToId,
|
||||
'created_by' => $adminId,
|
||||
'memo' => $data['remark'],
|
||||
'category' => 2,
|
||||
'create_time' => time()
|
||||
]);
|
||||
|
||||
\think\facade\Db::commit();
|
||||
$isCommitSuccess = true;
|
||||
} catch (ValidateException $e) {
|
||||
\think\facade\Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
} catch (Throwable $e) {
|
||||
\think\facade\Db::rollback();
|
||||
trace($e->getMessage(), 'error');
|
||||
$this->error(__('No rows were added'));
|
||||
}
|
||||
if ($isCommitSuccess) {
|
||||
$this->success(__('Added successfully'));
|
||||
}
|
||||
}
|
||||
|
||||
public function newTransact(): void
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post();
|
||||
if (!$data) {
|
||||
$this->error(__('Parameter %s can not be empty', ['']));
|
||||
}
|
||||
$result = false;
|
||||
$data = $this->excludeFields($data);
|
||||
|
||||
if ($data['type'] == 2) {
|
||||
$data['money'] = -$data['money'];
|
||||
}
|
||||
$user_id = User::where('jk_username', $data['user_name'])->value('id');
|
||||
if (!$user_id) {
|
||||
$this->error(__("The user can't find it", ['']));
|
||||
}
|
||||
$data['user_id'] = $user_id;
|
||||
$userMoneyLog = new UserMoneyLog();
|
||||
$userMoneyLog->startTrans();
|
||||
try {
|
||||
$data['created_by'] = $this->auth->getInfo()['id'];
|
||||
$result = $userMoneyLog->save($data);
|
||||
$userMoneyLog->commit();
|
||||
} catch (Throwable $e) {
|
||||
$userMoneyLog->rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false) {
|
||||
$this->success(__('Added successfully'));
|
||||
} else {
|
||||
$this->error(__('No rows were added'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function logHistory($id): void
|
||||
{
|
||||
$bindFields = [
|
||||
'admin' => ['id','username'],
|
||||
];
|
||||
$history = MoneyLogHistory::withJoin($bindFields, 'left')
|
||||
->where('money_log_id', $id)
|
||||
->select();
|
||||
if (!empty($history)) {
|
||||
foreach ($history as &$item) {
|
||||
$item['admin_name'] = $item['admin']['username'] ?? '';
|
||||
unset($item['admin']);
|
||||
}
|
||||
unset($item);
|
||||
}
|
||||
$this->success('', $history);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace app\admin\controller\user;
|
||||
|
||||
use app\common\service\Jk8Services;
|
||||
use app\admin\model\MoneyLogHistory;
|
||||
use Throwable;
|
||||
use app\admin\model\User;
|
||||
use app\admin\model\UserMoneyLog;
|
||||
@@ -16,19 +16,17 @@ class MoneyLog extends Backend
|
||||
*/
|
||||
protected object $model;
|
||||
|
||||
protected array $withJoinTable = ['user', 'admin'];
|
||||
protected array $withJoinTable = ['user', 'admin', 'bank'];
|
||||
protected array $withTable = ['scoreLog'];
|
||||
|
||||
// 排除字段
|
||||
protected string|array $preExcludeFields = ['create_time'];
|
||||
|
||||
protected string|array $quickSearchField = ['user.username', 'user.nickname'];
|
||||
protected $jk8Services;
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
$this->jk8Services = app(Jk8Services::class);
|
||||
$this->model = new UserMoneyLog();
|
||||
}
|
||||
|
||||
@@ -88,27 +86,13 @@ class MoneyLog extends Backend
|
||||
$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) {
|
||||
@@ -143,15 +127,49 @@ class MoneyLog extends Backend
|
||||
if (!$row) {
|
||||
$this->error(__('Record not found'));
|
||||
}
|
||||
$user = User::where('id', $row['user_id'])->find();
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
parent::edit();
|
||||
$data = $this->request->post();
|
||||
if (!$data) {
|
||||
$this->error(__('Parameter %s can not be empty', ['']));
|
||||
}
|
||||
|
||||
$result = false;
|
||||
$this->model->startTrans();
|
||||
try {
|
||||
$result = $row->save($data);
|
||||
$this->model->commit();
|
||||
} catch (Throwable $e) {
|
||||
$this->model->rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false) {
|
||||
$this->success(__('Update successful'));
|
||||
} else {
|
||||
$this->error(__('No rows updated'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
$row['username'] = $user['username'];
|
||||
$row['nickname'] = $user['nickname'];
|
||||
$this->success('', [
|
||||
'row' => $row
|
||||
]);
|
||||
}
|
||||
|
||||
public function logHistory($id): void
|
||||
{
|
||||
$bindFields = [
|
||||
'admin' => ['id','username'],
|
||||
];
|
||||
$history = MoneyLogHistory::withJoin($bindFields, 'left')
|
||||
->where('money_log_id', $id)
|
||||
->select();
|
||||
if (!empty($history)) {
|
||||
foreach ($history as &$item) {
|
||||
$item['admin_name'] = $item['admin']['username'] ?? '';
|
||||
unset($item['admin']);
|
||||
}
|
||||
unset($item);
|
||||
}
|
||||
$this->success('', $history);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\Model;
|
||||
use think\model\relation\HasMany;
|
||||
|
||||
/**
|
||||
* Bank
|
||||
@@ -46,4 +47,9 @@ class Bank extends Model
|
||||
{
|
||||
return is_null($value) ? null : (float)$value;
|
||||
}
|
||||
|
||||
public function MoneyLog(): hasMany
|
||||
{
|
||||
return $this->hasMany(UserMoneyLog::class, 'bank_id');
|
||||
}
|
||||
}
|
||||
34
app/admin/model/MoneyLogHistory.php
Normal file
34
app/admin/model/MoneyLogHistory.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\model\relation\HasMany;
|
||||
use Throwable;
|
||||
use think\model;
|
||||
use think\Exception;
|
||||
use think\model\relation\BelongsTo;
|
||||
|
||||
/**
|
||||
* MoneyLogHistory 模型
|
||||
*/
|
||||
class MoneyLogHistory extends model
|
||||
{
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $updateTime = false;
|
||||
|
||||
public static function onBeforeDelete(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function moneyLog(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(UserMoneyLog::class, 'money_log_id');
|
||||
}
|
||||
|
||||
public function admin(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Admin::class, 'created_by');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use app\admin\library\Auth;
|
||||
use think\model\relation\HasMany;
|
||||
use Throwable;
|
||||
use think\model;
|
||||
use think\Exception;
|
||||
use think\model\relation\BelongsTo;
|
||||
|
||||
/**
|
||||
@@ -22,23 +22,29 @@ class UserMoneyLog extends model
|
||||
* 入库前
|
||||
* @throws Throwable
|
||||
*/
|
||||
public static function onBeforeInsert($model): void
|
||||
// public static function onAfterInsert($model): void
|
||||
// {
|
||||
// $new = new MoneyLogHistory();
|
||||
// $new->money_log_id = $model->id;
|
||||
// $new->bank_befter = '';
|
||||
// $new->bank_after = $model->bank->bank_name;
|
||||
// $new->create_time = time();
|
||||
// $new->save();
|
||||
//
|
||||
// }
|
||||
|
||||
public static function onAfterUpdate($model): void
|
||||
{
|
||||
$user = User::where('id', $model->user_id)->lock(true)->find();
|
||||
if (!$user) {
|
||||
throw new Exception("The user can't find it");
|
||||
}
|
||||
if (!$model->memo) {
|
||||
throw new Exception("Change note cannot be blank");
|
||||
}
|
||||
$model->before = $user->money;
|
||||
$history = MoneyLogHistory::where('money_log_id', $model->id)->find();
|
||||
$new = new MoneyLogHistory();
|
||||
$new->money_log_id = $model->id;
|
||||
$new->bank_befter = $history->bank_after ?? '';
|
||||
$new->bank_after = $model->bank->bank_name;
|
||||
$new->created_by = Auth::instance()->getInfo()['id'];
|
||||
$new->create_time = time();
|
||||
$new->save();
|
||||
|
||||
$user->money += $model->money;
|
||||
$user->save();
|
||||
|
||||
$model->after = $user->money;
|
||||
}
|
||||
|
||||
public static function onBeforeDelete(): bool
|
||||
{
|
||||
return false;
|
||||
@@ -88,4 +94,9 @@ class UserMoneyLog extends model
|
||||
{
|
||||
return $this->hasMany(UserScoreLog::class, 'money_log_id');
|
||||
}
|
||||
|
||||
public function bank(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Bank::class, 'bank_id');
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,13 @@ class UserScoreLog extends model
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $updateTime = false;
|
||||
|
||||
const GAME_TYPE_LIST = [
|
||||
1001 => 'Lucky Wheel', // 大转盘
|
||||
1002 => 'Golden Eggs', // 砸金蛋
|
||||
1003 => 'Daily Mission', // 每日任务
|
||||
1004 => 'Plinko Ball', // 普林科弹球
|
||||
];
|
||||
|
||||
public static function onBeforeDelete(): bool
|
||||
{
|
||||
return false;
|
||||
@@ -26,4 +33,17 @@ class UserScoreLog extends model
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function getGameTypeTextAttr($value, $data)
|
||||
{
|
||||
$gameType = $data['game_type'] ?? 0;
|
||||
|
||||
// 如果需要严格的多语言,可以在这里根据 $lang 切换,或者直接配合系统的 lang() 助手函数
|
||||
// 这里我们先直接返回对应的标准国际化名称
|
||||
return self::GAME_TYPE_LIST[$gameType] ?? 'Unknown Game';
|
||||
}
|
||||
|
||||
// 3. 别忘了把获取器追加到模型的可见输出数组里
|
||||
protected $append = ['game_type_text'];
|
||||
|
||||
}
|
||||
35
app/api/controller/External.php
Normal file
35
app/api/controller/External.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use Throwable;
|
||||
use ba\Captcha;
|
||||
use ba\ClickCaptcha;
|
||||
use think\facade\Validate;
|
||||
use app\common\model\User;
|
||||
use app\common\library\Email;
|
||||
use app\common\controller\Frontend;
|
||||
use PHPMailer\PHPMailer\Exception as PHPMailerException;
|
||||
|
||||
class External extends Frontend
|
||||
{
|
||||
protected array $noNeedLogin = ['depositNotify'];
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
public function depositNotify(): void
|
||||
{
|
||||
|
||||
|
||||
try {
|
||||
|
||||
} catch (PHPMailerException) {
|
||||
|
||||
}
|
||||
|
||||
$this->success(__('Mail sent successfully~'));
|
||||
}
|
||||
}
|
||||
18
app/api/route/app.php
Normal file
18
app/api/route/app.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use app\common\middleware\ApiAuth;
|
||||
use think\facade\Route;
|
||||
|
||||
Route::group('external', function () {
|
||||
Route::post('register-notify', 'External/registerNotify');
|
||||
Route::post('deposit-notify', 'External/depositNotify');
|
||||
Route::post('withdrawal-notify', 'External/withdrawalNotify');
|
||||
Route::post('agent-notify', 'External/agentNotify');
|
||||
});
|
||||
|
||||
Route::group('external', function () {
|
||||
// 这里面的所有路由都会经过 ApiAuth 中间件
|
||||
Route::post('test', 'Account/test');
|
||||
Route::post('user-withdraw', 'Withdraw/apply');
|
||||
|
||||
})->middleware(ApiAuth::class);
|
||||
71
app/common/middleware/ApiAuth.php
Normal file
71
app/common/middleware/ApiAuth.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2021 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\common\middleware;
|
||||
|
||||
use app\common\model\Config;
|
||||
use Closure;
|
||||
use think\facade\Cache;
|
||||
use think\exception\HttpException;
|
||||
|
||||
class ApiAuth
|
||||
{
|
||||
protected $apps;
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$this->apps = Config::whereIn('name', ['appKey', 'appSecret'])->column('value', 'name');
|
||||
$params = $request->param();
|
||||
$appKey = $request->header('X-Api-AppKey');
|
||||
$timestamp = $request->header('X-Api-Timestamp');
|
||||
$nonce = $request->header('X-Api-Nonce');
|
||||
$signature = $request->header('X-Api-Signature');
|
||||
|
||||
// 1. 基础检查
|
||||
if (!$signature || !$appKey || !$timestamp || !$nonce) {
|
||||
throw new HttpException(401, '缺少必要的签名参数');
|
||||
}
|
||||
|
||||
// 2. 检查 AppKey 是否合法
|
||||
if ($this->apps['appKey'] != $appKey) {
|
||||
throw new HttpException(401, '无效的 AppKey');
|
||||
}
|
||||
|
||||
// 3. 检查时间戳(防重放攻击,允许 60 秒误差)
|
||||
if (abs(time() - $timestamp) > 60) {
|
||||
// throw new HttpException(401, '请求已超时');
|
||||
}
|
||||
|
||||
// 4. 检查随机字符串
|
||||
$cacheKey = "api_nonce:" . $nonce;
|
||||
if (Cache::has($cacheKey)) {
|
||||
// throw new HttpException(401, '重复请求');
|
||||
}
|
||||
Cache::setex($cacheKey, 60, 1);
|
||||
|
||||
// 5. 验证签名
|
||||
if (!$this->checkSignature($params, $timestamp, $nonce, $signature)) {
|
||||
throw new HttpException(401, '签名验证失败');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
protected function checkSignature($params, $timestamp, $nonce, $signature)
|
||||
{
|
||||
$appSecret = $this->apps['appSecret'];
|
||||
unset($params['/']);
|
||||
ksort($params);
|
||||
$stringToBeSigned = http_build_query($params) . '&app_secret=' . $appSecret . '×tamp=' . $timestamp . '&nonce=' . $nonce;
|
||||
$serverSig = hash('sha256', $stringToBeSigned);
|
||||
return hash_equals($serverSig, $signature);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
return [
|
||||
// 默认缓存驱动
|
||||
'default' => env('cache.driver', 'file'),
|
||||
'default' => env('cache.driver', 'redis'),
|
||||
|
||||
// 缓存连接方式配置
|
||||
'stores' => [
|
||||
@@ -25,5 +25,12 @@ return [
|
||||
'serialize' => [],
|
||||
],
|
||||
// 更多的缓存连接
|
||||
// redis缓存
|
||||
'redis' => [
|
||||
// 驱动方式
|
||||
'type' => 'redis',
|
||||
// 服务器地址
|
||||
'host' => '127.0.0.1',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'domain' => 'https://1xace.n9686b.com/api/v1/index.php/',
|
||||
'access_id' => 23873027,
|
||||
'token' => 'fee0e83b784c61210287168af714bca61f29db688c0fa08e7659c2f7d8b729c2',
|
||||
'domain' => 'https://pms99.as6868.com/api/v1/index.php/',
|
||||
'access_id' => 366068146,
|
||||
'token' => '882311d5b502cb8e28898c402112643d0c693a45432e4406ea7a629a22c5577b',
|
||||
];
|
||||
|
||||
@@ -26,5 +26,6 @@ export default {
|
||||
1002 : 'Golden Eggs',
|
||||
1003 : 'Daily Mission',
|
||||
1004 : 'Plinko Ball'
|
||||
}
|
||||
},
|
||||
'bank_id': 'Bank Account',
|
||||
}
|
||||
|
||||
@@ -26,5 +26,6 @@ export default {
|
||||
1002 : 'Golden Eggs',
|
||||
1003 : 'Daily Mission',
|
||||
1004 : 'Plinko Ball'
|
||||
}
|
||||
},
|
||||
'bank_id': '银行账户',
|
||||
}
|
||||
|
||||
@@ -72,9 +72,8 @@ const baTable = new baTableClass(
|
||||
operatorPlaceholder: t('Fuzzy query'),
|
||||
},
|
||||
{ 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.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.bank_id'), prop: 'bank.bank_name', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
||||
{ label: t('user.moneyLog.Transaction id'), prop: 'transaction_id', align: 'center', operator: 'RANGE' },
|
||||
{
|
||||
label: t('user.moneyLog.Game Ticket'),
|
||||
prop: 'scoreLog',
|
||||
|
||||
@@ -40,31 +40,29 @@
|
||||
disabled: baTable.form.operate == 'Edit'
|
||||
}"
|
||||
/>
|
||||
<el-form-item :label="t('user.moneyLog.User name')">
|
||||
<el-input
|
||||
:model-value="baTable.form.operate == 'Edit' ? baTable.form.items!.username : state.userInfo.username"
|
||||
disabled
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('user.moneyLog.User name')">
|
||||
<el-input
|
||||
:model-value="baTable.form.operate == 'Edit' ? baTable.form.items!.nickname : state.userInfo.nickname"
|
||||
disabled
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('user.moneyLog.Current balance')">
|
||||
<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 :label="t('user.moneyLog.bank_id')" prop="bank_id">
|
||||
<el-select
|
||||
v-model="baTable.form.items!.bank_id"
|
||||
filterable
|
||||
remote
|
||||
:placeholder="t('Please select bank account')"
|
||||
:remote-method="getBankList"
|
||||
:loading="state.bankLoading"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in state.bankOptions"
|
||||
:key="item.id"
|
||||
:label="item.bank_name"
|
||||
:value="item.id"
|
||||
>
|
||||
<div style="display: flex; justify-content: space-between; align-items: center;">
|
||||
<span>{{ item.bank_name }}</span>
|
||||
<span style="color: #a8abb2; font-size: 12px;">{{ item.bank_account }}</span>
|
||||
</div>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<FormItem
|
||||
:label="t('user.moneyLog.type')"
|
||||
@@ -88,21 +86,6 @@
|
||||
@input="changeMoney"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('user.moneyLog.Balance after change')">
|
||||
<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 prop="memo" :label="t('user.moneyLog.remarks')">
|
||||
<el-input
|
||||
@keyup.enter.stop=""
|
||||
@@ -135,12 +118,29 @@ import FormItem from '/@/components/formItem/index.vue'
|
||||
import type { FormItemRule } from 'element-plus'
|
||||
import { buildValidatorData } from '/@/utils/validate'
|
||||
import { useConfig } from '/@/stores/config'
|
||||
|
||||
import createAxios from '/@/utils/axios'
|
||||
const getBankList = (query: string = '') => {
|
||||
state.bankLoading = true
|
||||
createAxios({
|
||||
url: '/admin/Bank/index',
|
||||
method: 'GET',
|
||||
params: {
|
||||
// BuildAdmin 后端标准的搜索与分页格式
|
||||
quickSearch: query,
|
||||
limit: 20
|
||||
}
|
||||
}).then((res) => {
|
||||
// BuildAdmin 列表的标准返回结构是 res.data.list
|
||||
state.bankOptions = res.data.list || []
|
||||
}).finally(() => {
|
||||
state.bankLoading = false
|
||||
})
|
||||
}
|
||||
const config = useConfig()
|
||||
const { t } = useI18n()
|
||||
const baTable = inject('baTable') as baTableClass
|
||||
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
||||
user_id: [buildValidatorData({ name: 'required', message: t('Please select field', { field: t('user.moneyLog.User') }) })],
|
||||
bank_id: [buildValidatorData({ name: 'required', message: t('Please select field', { field: t('user.moneyLog.bank_id') }) })],
|
||||
type: [buildValidatorData({ name: 'required', message: t('Please select field', { field: t('user.moneyLog.type') }) })],
|
||||
money: [
|
||||
buildValidatorData({ name: 'required', title: t('user.moneyLog.Change amount') }),
|
||||
@@ -162,9 +162,13 @@ const formRef = useTemplateRef('formRef')
|
||||
const state: {
|
||||
userInfo: anyObj
|
||||
after: number
|
||||
bankOptions: any[] // 新增:存放银行下拉选项
|
||||
bankLoading: boolean // 新增:下拉框加载状态
|
||||
} = reactive({
|
||||
userInfo: {},
|
||||
after: 0,
|
||||
bankOptions: [], // 初始化
|
||||
bankLoading: false
|
||||
})
|
||||
|
||||
const getAdd = () => {
|
||||
|
||||
@@ -99,13 +99,6 @@
|
||||
:placeholder="t('Please select field', { field: t('user.user.birthday') })"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="baTable.form.operate == 'Edit'" :label="t('user.user.balance')">
|
||||
<el-input v-model="baTable.form.items!.money" readonly>
|
||||
<template #append>
|
||||
<el-button @click="changeAccount('money')">{{ t('user.user.Adjustment balance') }}</el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password" :label="t('user.user.password')">
|
||||
<el-input
|
||||
v-model="baTable.form.items!.password"
|
||||
|
||||
Reference in New Issue
Block a user