|
|
@@ -28,32 +28,29 @@ class Balance extends Controller
|
|
|
'end_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:start_time'],
|
|
|
'first_name' => ['nullable'],
|
|
|
'is_fancai' => ['nullable', 'integer','in:0,1'],
|
|
|
+ // 用户类型/注册来源:-1 tg用户,0 后台客服账号,1 真实用户,2 虚拟用户
|
|
|
+ 'from' => ['nullable'],
|
|
|
]);
|
|
|
$page = request()->input('page', 1);
|
|
|
$limit = request()->input('limit', 10);
|
|
|
$query = BalanceLog::join('users', 'users.member_id', '=', 'balance_logs.member_id')
|
|
|
->where(BalanceLogService::getWhere($params));
|
|
|
if (!empty($params['is_fancai'])) {
|
|
|
-
|
|
|
$data['change_types'] = ['即充即送','老用户回归','余额宝利息'];
|
|
|
- $query = $query->whereIn('balance_logs.change_type',$data['change_types'])->where('type',2);
|
|
|
-
|
|
|
+ $query = $query->whereIn('balance_logs.change_type', $data['change_types'])
|
|
|
+ ->where('balance_logs.type', 2);
|
|
|
} else {
|
|
|
$data['change_types'] = BalanceLogService::$RW;
|
|
|
}
|
|
|
- $data['total'] = $query->count();
|
|
|
- $totalAmount = '--';
|
|
|
- //如果指定用户和类型,则统计变动金额
|
|
|
- if (isset($params['member_id']) && isset($params['change_type'])) {
|
|
|
- $totalAmount = $query->sum('amount');
|
|
|
- $totalAmount = bcadd($totalAmount, 0, 2);
|
|
|
- }
|
|
|
- $data['total_amount'] =$totalAmount;
|
|
|
- $data['data'] = $query->select("balance_logs.*", "users.first_name","users.admin_note as user_admin_note")->orderByDesc('id')
|
|
|
- ->forPage($page, $limit)->with(['member'])
|
|
|
- ->get()->toArray();
|
|
|
-
|
|
|
-
|
|
|
+ // 统计与列表共用筛选条件;clone 避免 count/sum 影响后续分页查询
|
|
|
+ $data['total'] = (clone $query)->count();
|
|
|
+ $data['total_amount'] = bcadd((clone $query)->sum('balance_logs.amount'), 0, 2);
|
|
|
+ $data['data'] = $query->select("balance_logs.*", "users.first_name", "users.admin_note as user_admin_note", "users.from as user_from")
|
|
|
+ ->orderByDesc('balance_logs.id')
|
|
|
+ ->forPage($page, $limit)
|
|
|
+ ->with(['member'])
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
} catch (ValidationException $e) {
|
|
|
return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
|
|
|
} catch (Exception $e) {
|