validate([ 'page' => ['nullable', 'integer', 'min:1'], 'limit' => ['nullable', 'integer', 'min:1'], 'member_id' => ['nullable', 'string', 'min:1'], 'change_type' => ['nullable', 'string', 'in:' . implode(',', BalanceLogService::$RW)], 'start_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:end_time'], 'end_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:start_time'], ]); $page = request()->input('page', 1); $limit = request()->input('limit', 10); $query = BalanceLog::where(BalanceLogService::getWhere($params)); $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->orderByDesc('id') ->forPage($page, $limit)->with(['member']) ->get()->toArray(); $data['change_types'] = BalanceLogService::$RW; } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (Exception $e) { return $this->error($e->getCode(),$e->getMessage()); } return $this->success($data); } }