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 = (float)$query->sum('amount'); $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(intval($e->getCode())); } return $this->success($data); } }