scene('list')->validate(); // 查询条件 $map = []; $limit = request('limit', config('page_num', 10)); $status = request('status', ''); $start_time = request('start_time', ''); $end_time = request('end_time', ''); $store_name = request('store_name', ''); $company_name = request('company_name', ''); $social_credit_code = request('social_credit_code', ''); $store_type = request('store_type', ''); // 时间条件 if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)]; if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)]; // 其他条件 if (is_numeric($status)) $map[] = ['status', '=', $status]; if ($social_credit_code) $map[] = ['social_credit_code', 'like', "%$social_credit_code%"]; if ($company_name) $map[] = ['company_name', 'like', "%$company_name%"]; if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"]; if ($store_type) $map[] = ['store_type', '=', $store_type]; // 查询数据 $result = $ViolationStoreModel->query() ->where($map) ->orderByDesc('id') ->paginate($limit); // 分配数据 if (!$result) return json_send(['code' => 'error', 'msg' => '暂无数据']); // 加载模板 return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]); } /** * 全部 * @author 唐远望 * @version 1.0 * @date 2025-12-08 * */ public function all(Request $request, ViolationStoreModel $ViolationStoreModel) { $request->scene('all')->validate(); // 查询条件 $map = []; $status = request('status', '0'); $start_time = request('start_time', ''); $end_time = request('end_time', ''); $store_name = request('store_name', ''); $company_name = request('company_name', ''); $social_credit_code = request('social_credit_code', ''); // 时间条件 if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)]; if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)]; // 其他条件 if (is_numeric($status)) $map[] = ['status', '=', $status]; if ($social_credit_code) $map[] = ['social_credit_code', 'like', "%$social_credit_code%"]; if ($company_name) $map[] = ['company_name', 'like', "%$company_name%"]; if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"]; // 查询数据 $result = $ViolationStoreModel->query() ->where($map) ->orderByDesc('id') ->get(); // 分配数据 if (!$result) return json_send(['code' => 'error', 'msg' => '暂无数据']); // 加载模板 return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]); } /** * 详情 * @author 唐远望 * @version 1.0 * @date 2025-12-03 */ public function detail(Request $request, ViolationStoreModel $ViolationStoreModel) { $request->scene('detail')->validate(); // 接收参数 $id = request('id', 0); $map = ['id' => $id]; $data = $ViolationStoreModel->where($map)->first(); if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']); // 加载模板 return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]); } /** * 添加 * @author 唐远望 * @version 1.0 * @date 2025-12-03 * */ public function add(Request $request, ViolationStoreModel $ViolationStoreModel) { $request->scene('add')->validate(); // 接收数据 $all_data = request()->all(); $store_scope = request('store_scope', ''); $all_data['store_scope'] = $store_scope; //查询是否存在 $map = ['social_credit_code' => $all_data['social_credit_code']]; $data = $ViolationStoreModel->where($map)->first(); if ($data) return json_send(['code' => 'error', 'msg' => '营业执照记录已存在']); // 写入数据表 $result = $ViolationStoreModel->addViolationStore($all_data); // 如果操作失败 if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']); // 告知结果 return json_send(['code' => 'success', 'msg' => '新增成功']); } /** * 修改 * @author 唐远望 * @version 1.0 * @date 2025-12-03 * */ public function edit(Request $request, ViolationStoreModel $ViolationStoreModel) { $request->scene('edit')->validate(); // 接收参数 $id = request('id', 0); // 接收数据 $all_data = request()->all(); $store_scope = request('store_scope',''); $all_data['store_scope'] = $store_scope; //查询是否存在 $map = ['social_credit_code' => $all_data['social_credit_code']]; $data = $ViolationStoreModel->where($map)->where('id', '!=', $id)->first(); if ($data) return json_send(['code' => 'error', 'msg' => '营业执照记录已存在']); // 更新数据表 $where = ['id' => $id]; $result = $ViolationStoreModel->updateViolationStore($where, $all_data); // 如果操作失败 if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']); // 告知结果 return json_send(['code' => 'success', 'msg' => '修改成功']); } /** * 修改状态 * @author 唐远望 * @version 1.0 * @date 2025-12-03 * */ public function set_status(Request $request, ViolationStoreModel $ViolationStoreModel) { // 验证参数 $request->scene('set_status')->validate(); // 接收数据 $id = request('id', 0); $status = request('status', 0); // 查询用户 $where = ['id' => $id]; // 执行修改 $result = $ViolationStoreModel->changeStatus($where, $status); // 提示新增失败 if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']); // 告知结果 return json_send(['code' => 'success', 'msg' => '设置成功']); } /** * 删除 * @author 唐远望 * @version 1.0 * @date 2025-12-03 * */ public function delete(Request $request, ViolationStoreModel $ViolationStoreModel) { // 验证参数 $request->scene('delete')->validate(); // 接收数据 $id = request('id', 0); // 查询用户 $where = ['id' => $id]; // 执行删除 $result = $ViolationStoreModel->deleteViolationStore($where); // 提示删除失败 if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']); // 告知结果 return json_send(['code' => 'success', 'msg' => '删除成功']); } }