diff --git a/app/admin/controller/Dashboard.php b/app/admin/controller/Dashboard.php index 12a3ddb..32e4ffd 100644 --- a/app/admin/controller/Dashboard.php +++ b/app/admin/controller/Dashboard.php @@ -9,7 +9,6 @@ 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 @@ -171,7 +170,7 @@ class Dashboard extends Backend $logFrom = new UserMoneyLog(); $logFrom->save([ 'user_id' => 0, - 'money' => -$money, + 'money' => $money, 'before' => $bankFrom->current_balance + $money, 'after' => $bankFrom->current_balance, 'type' => 4, @@ -224,9 +223,18 @@ class Dashboard extends Backend $result = false; $data = $this->excludeFields($data); - if ($data['type'] == 2) { - $data['money'] = -$data['money']; + $bank = Bank::where('id', $data['bank_id'])->where('status', 1)->lock(true)->find(); + if (!$bank) { + throw new ValidateException('银行账户不存在或已被禁用'); } + + if (in_array($data['type'], [2,4])) { + $bank->current_balance -= $data['money']; + } else { + $bank->current_balance += $data['money']; + } + $bank->save(); + $user_id = User::where('jk_username', $data['user_name'])->value('id'); if (!$user_id) { $this->error(__("The user can't find it", [''])); diff --git a/app/admin/controller/user/MoneyLog.php b/app/admin/controller/user/MoneyLog.php index 34e8204..ac55286 100644 --- a/app/admin/controller/user/MoneyLog.php +++ b/app/admin/controller/user/MoneyLog.php @@ -7,6 +7,7 @@ use Throwable; use app\admin\model\User; use app\admin\model\UserMoneyLog; use app\common\controller\Backend; +use think\facade\Db; class MoneyLog extends Backend { @@ -78,6 +79,7 @@ class MoneyLog extends Backend */ public function add(int $userId = 0): void { + $this->error(__('No rows were added')); if ($this->request->isPost()) { $data = $this->request->post(); if (!$data) { @@ -172,4 +174,95 @@ class MoneyLog extends Backend } $this->success('', $history); } + + public function annualReport() + { + $year = $this->request->param('year/d', date('Y')); + $timeExpression = "create_time"; + + $list = Db::table('ba_user_money_log') + ->whereRaw("FROM_UNIXTIME({$timeExpression}, '%Y') = ?", [$year]) + ->fieldRaw(" + FROM_UNIXTIME({$timeExpression}, '%c') as month, + + -- 1. DEPOSIT (分转元,保留2位小数) + ROUND(SUM(CASE WHEN type IN (1, 3) THEN money / 100 ELSE 0 END), 2) as deposit_amount, + + -- 2. WITHDRAW (从变更记录看提现通常存正数,这里直接累加,分转元) + ROUND(SUM(CASE WHEN type IN (2, 4) THEN money / 100 ELSE 0 END), 2) as withdraw_amount, + + -- 3. TRANSACTION (DEPOSIT) + COUNT(CASE WHEN type IN (1, 3) THEN id END) as deposit_count, + + -- 4. TRANSACTION (WITHDRAW) + COUNT(CASE WHEN type IN (2, 4) THEN id END) as withdraw_count, + + -- 5. ACTIVE PLAYER (每月去重活跃用户) + COUNT(DISTINCT user_id) as active_player, + + -- 6. FIRST DEPOSIT (首充去重人数) + COUNT(DISTINCT CASE WHEN type = 1 AND label = 1 THEN user_id END) as first_deposit_count, + + -- 7. UNCLAIM RECEIPT (未领单数) + COUNT(CASE WHEN type = 1 AND label = 2 THEN id END) as unclaim_count, + + -- 8. UNCLAIM AMOUNT (未领金额) + ROUND(SUM(CASE WHEN type = 1 AND label = 2 THEN money / 100 ELSE 0 END), 2) as unclaim_amount + ") + ->group("month") + ->select() + ->toArray(); + + $monthsData = []; + foreach ($list as $row) { + $monthsData[intval($row['month'])] = $row; + } + + $rowsSkeleton = [ + 'deposit' => ['name' => 'DEPOSIT', 'is_price' => true], + 'withdraw' => ['name' => 'WITHDRAW', 'is_price' => true], + 'trans_deposit' => ['name' => 'TRANSACTION (DEPOSIT)', 'is_price' => false], + 'trans_withdraw' => ['name' => 'TRANSACTION (WITHDRAW)', 'is_price' => false], + 'active_player' => ['name' => 'ACTIVE PLAYER', 'is_price' => false], + 'first_deposit' => ['name' => 'FIRST DEPOSIT', 'is_price' => false], + 'unclaim_receipt' => ['name' => 'UNCLAIM RECEIPT', 'is_price' => false], + 'unclaim_amount' => ['name' => 'UNCLAIM AMOUNT', 'is_price' => true], + ]; + + $finalReport = []; + + foreach ($rowsSkeleton as $key => $meta) { + $rowData = [ + 'title' => $meta['name'] + ]; + $yearTotal = 0; + + for ($m = 1; $m <= 12; $m++) { + $monthValue = 0; + if (isset($monthsData[$m])) { + $monthValue = match ($key) { + 'deposit' => (float)$monthsData[$m]['deposit_amount'], + 'withdraw' => (float)$monthsData[$m]['withdraw_amount'], + 'trans_deposit' => (int)$monthsData[$m]['deposit_count'], + 'trans_withdraw' => (int)$monthsData[$m]['withdraw_count'], + 'active_player' => (int)$monthsData[$m]['active_player'], + 'first_deposit' => (int)$monthsData[$m]['first_deposit_count'], + 'unclaim_receipt' => (int)$monthsData[$m]['unclaim_count'], + 'unclaim_amount' => (float)$monthsData[$m]['unclaim_amount'], + }; + } + + $rowData['month_' . $m] = $meta['is_price'] ? number_format($monthValue, 2, '.', '') : $monthValue; + $yearTotal += $monthValue; + } + + $rowData['year_total'] = $meta['is_price'] ? number_format($yearTotal, 2, '.', '') : $yearTotal; + $finalReport[] = $rowData; + } + + $this->success('', [ + 'year' => $year, + 'report_table' => $finalReport + ]); + } } \ No newline at end of file diff --git a/web/src/api/backend/user/moneyLog.ts b/web/src/api/backend/user/moneyLog.ts index 013368b..ca64230 100644 --- a/web/src/api/backend/user/moneyLog.ts +++ b/web/src/api/backend/user/moneyLog.ts @@ -19,3 +19,11 @@ export function logHistory(params: { id: number | string }) { params, }) } + +export function annualReport(params: { id: number | string }) { + return createAxios({ + url: url + 'annualReport', + method: 'get', + params, + }) +} diff --git a/web/src/lang/backend/en/user/moneyLog.ts b/web/src/lang/backend/en/user/moneyLog.ts index 7169e6a..24f1007 100644 --- a/web/src/lang/backend/en/user/moneyLog.ts +++ b/web/src/lang/backend/en/user/moneyLog.ts @@ -15,7 +15,7 @@ export default { User: 'User', 'Transaction id': 'Transaction id', 'Created by': 'Created by', - 'type': '类型', + 'type': 'Type', 'type_list': { 1 : 'Deposit', 2 : 'Withdraw', diff --git a/web/src/views/backend/user/moneyLog/annualReport.vue b/web/src/views/backend/user/moneyLog/annualReport.vue new file mode 100644 index 0000000..b19d7b7 --- /dev/null +++ b/web/src/views/backend/user/moneyLog/annualReport.vue @@ -0,0 +1,282 @@ + + + + + + + + {{ state.userInfo.username + '(ID:' + state.userInfo.id + ') ' + t('user.moneyLog.balance') + ':' + state.userInfo.money }} + + + + + + + + + + Transaction edit history is only kept for the most recent 12 months. + Transaction 的编辑历史记录仅保存最近 12 个月。 + + + + + + + + CANCEL + + + + + + + +
Transaction edit history is only kept for the most recent 12 months.
Transaction 的编辑历史记录仅保存最近 12 个月。