validator; } /** * 构建查询条件 */ protected function buildQueryConfig(Request $request, string $scene = 'index'): array { $p = $request->all(); $config = []; $config['model'] = $this->modelClass; switch ($scene) { case 'index': // ====== ====== 排序 ====== ====== $config['order']['id'] = 'desc'; break; case 'show': $config['where']['id'] = $p['id']; break; case 'update': case 'destroy': $config['where']['id'] = $p['id']; break; case 'store': break; } return $config; } public function beforeServiceStore($data, Request $request) { $data['apply_no'] = $this->generateUniqueApplyNo(); $data['submit_files'] = json_encode($data['submit_files']); return $data; } public function beforeServiceUpdate($data, Request $request) { $data['submit_files'] = json_encode($data['submit_files']); return $data; } /** * 生成唯一的付款申请编码 * 格式:PA + 日期 + 6位字母数字组合 * * @return string 唯一编码 */ public function generateUniqueApplyNo() { $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $maxAttempts = 10; // 防止无限循环 $secondChar = 'PA' . date('Ymd'); for ($attempt = 0; $attempt < $maxAttempts; $attempt++) { // 生成后6位随机字符 $suffix = ''; for ($i = 0; $i < 6; $i++) { $suffix .= $chars[rand(0, strlen($chars) - 1)]; } $applyNo = $secondChar . $suffix; // 检查是否已存在 $existing = FinPaymentApply::where('apply_no', $applyNo)->first(); if (!$existing) { return $applyNo; } } // 如果1000次尝试后仍然重复,使用时间戳确保唯一性 $timestamp = substr(time(), -6); return $secondChar . $timestamp; } }