scene('list')->validate(); $admin_company_id = request('admin_company_id', '0'); $company_id = request('access_token.company_id', '0'); $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否 // 查询条件 $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', ''); $category_id = request('category_id', ''); // 时间条件 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]; if ($category_id) $map[] = ['category_id', '=', $category_id]; // 查询数据 if ($is_admin != 1 && $company_id != 0){ $map[] = ['company_id', '=', $company_id]; }else{ $map[] = ['company_id', '=', $admin_company_id]; } $result = $ViolationStoreModel->query() ->where($map) ->orderByDesc('id') ->paginate($limit)->toarray(); // 分配数据 if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]); if (isset($result['data']) && count($result['data']) > 0) { foreach ($result['data'] as $key => $value) { $employee_ids = $value['employee_ids'] != '' ? explode(',', $value['employee_ids']) : ''; $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',', $value['platform']) : ''; $result['data'][$key]['employee_ids'] = $employee_ids; $result['data'][$key]['employee_name'] = $employee_ids ? $EmployeeModel->whereIn('id', $employee_ids)->pluck('name')->toArray() : ''; $result['data'][$key]['category_name'] = $value['category_id'] ? $CompanyCategoryModel->where('id', $value['category_id'])->value('name') : ''; $province_name = $CitysModel->get_city_name($value['province_id']); $result['data'][$key]['province_name'] = $province_name ?? ''; $city_name = $CitysModel->get_city_name($value['city_id']); $result['data'][$key]['city_name'] = $city_name ?? ''; } } // 加载模板 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(); $admin_company_id = request('admin_company_id', '0'); $company_id = request('access_token.company_id', '0'); $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否 // 查询条件 $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', ''); $category_id = request('category_id', ''); // 时间条件 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 ($category_id) $map[] = ['category_id', '=', $category_id]; // 查询数据 if ($is_admin != 1 && $company_id != 0){ $map[] = ['company_id', '=', $company_id]; }else{ $map[] = ['company_id', '=', $admin_company_id]; } $result = $ViolationStoreModel->query() ->where($map) ->orderByDesc('id') ->get(); // 分配数据 if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]); // 加载模板 return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]); } /** * 详情 * @author 唐远望 * @version 1.0 * @date 2025-12-03 */ public function detail(Request $request, ViolationStoreModel $ViolationStoreModel, EmployeeModel $EmployeeModel, CompanyCategoryModel $CompanyCategoryModel, CitysModel $CitysModel) { $request->scene('detail')->validate(); $admin_company_id = request('admin_company_id', '0'); $company_id = request('access_token.company_id', '0'); $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否 // 接收参数 $id = request('id', 0); $map = ['id' => $id]; if ($is_admin != 1 && $company_id != 0) { $map['company_id'] = $company_id; } else { $map['company_id'] = $admin_company_id; } $data = $ViolationStoreModel->where($map)->first(); if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']); $employee_ids = $data->employee_ids != '' ? explode(',', $data->employee_ids) : ''; $data->employee_ids = $employee_ids; $data->employee_name = $employee_ids ? $EmployeeModel->whereIn('id', $employee_ids)->pluck('name')->toArray() : ''; $data->category_name = $data->category_id ? $CompanyCategoryModel->where('id', $data->category_id)->value('name') : ''; $province_name = $CitysModel->get_city_name($data->province_id); $data->province_name = $province_name ?? ''; $city_name = $CitysModel->get_city_name($data->city_id); $data->city_name = $city_name ?? ''; $data->platform = isset($data->platform) ? explode(',', $data->platform) : ''; // 加载模板 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(); $admin_company_id = request('admin_company_id', '0'); $company_id = request('access_token.company_id', '0'); $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否 // 接收数据 $all_data = request()->all(); $store_scope = request('store_scope', ''); $all_data['store_scope'] = $store_scope; //店铺范围 $employee_ids = request('employee_ids', ''); $all_data['employee_ids'] = $employee_ids; $category_id = request('category_id', '0'); $all_data['category_id'] = $category_id; $specify_responsible_person = request('specify_responsible_person', '0'); $all_data['specify_responsible_person'] = $specify_responsible_person; $area_info = request('area_info', ''); $all_data['area_info'] = $area_info; $platform = request('platform', '0'); $all_data['platform'] = $platform; //查询是否存在 $map = ['social_credit_code' => $all_data['social_credit_code']]; if ($is_admin != 1 && $company_id != 0) { $map['company_id'] = $company_id; } else { $map['company_id'] = $admin_company_id; } $data = $ViolationStoreModel->where($map)->first(); if ($data) return json_send(['code' => 'error', 'msg' => '营业执照记录已存在']); // 写入数据表 $all_data['company_id'] = $company_id; $result = $ViolationStoreModel->addViolationStore($all_data); // 如果操作失败 if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']); // 记录行为 $admin_id = request('access_token.uid', 0); //用户ID $table_name = $ViolationStoreModel->getTable(); $notes_type = 1; //操作类型,1添加,2修改,3=删除 $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, [], $all_data, '新增了公司' . $all_data['company_name'] . '信息'); // 告知结果 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(); $admin_company_id = request('admin_company_id', '0'); $company_id = request('access_token.company_id', '0'); $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否 // 接收参数 $id = request('id', 0); // 接收数据 $all_data = request()->all(); $store_scope = request('store_scope', ''); $all_data['store_scope'] = $store_scope; $employee_ids = request('employee_ids', ''); $all_data['employee_ids'] = $employee_ids; $category_id = request('category_id', '0'); $all_data['category_id'] = $category_id; $specify_responsible_person = request('specify_responsible_person', '0'); $all_data['specify_responsible_person'] = $specify_responsible_person; $area_info = request('area_info', ''); $all_data['area_info'] = $area_info; $platform = request('platform', '0'); $all_data['platform'] = $platform; //查询是否存在 $map = ['social_credit_code' => $all_data['social_credit_code']]; if ($is_admin != 1 && $company_id != 0) { $map['company_id'] = $company_id; } else { $map['company_id'] = $admin_company_id; } $data = $ViolationStoreModel->where($map)->where('id', '!=', $id)->first(); if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']); // 更新数据表 $where = ['id' => $id]; if ($is_admin != 1 && $company_id != 0) { $where['company_id'] = $company_id; } else { $where['company_id'] = $admin_company_id; } $ViolationStore = $ViolationStoreModel->where($where)->first(); if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']); $oldData = $ViolationStore->toarray(); $all_data['company_id'] = $company_id; $result = $ViolationStoreModel->updateViolationStore($ViolationStore, $all_data); // 如果操作失败 if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']); // 记录行为 $admin_id = request('access_token.uid', 0); //用户ID $table_name = $ViolationStoreModel->getTable(); $notes_type = 2; //操作类型,1添加,2修改,3=删除 $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, $oldData, $all_data, '修改了公司' . $oldData['company_name'] . '信息'); // 告知结果 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(); $admin_company_id = request('admin_company_id', '0'); $company_id = request('access_token.company_id', '0'); $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否 // 接收数据 $id = request('id', 0); $status = request('status', 0); // 查询用户 $where = ['id' => $id]; if ($is_admin != 1 && $company_id != 0) { $where['company_id'] = $company_id; } else { $where['company_id'] = $admin_company_id; } $ViolationStore = $ViolationStoreModel->where($where)->first(); if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']); // 执行修改 $result = $ViolationStoreModel->changeStatus($ViolationStore, $status); // 提示新增失败 if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']); // 记录行为 $admin_id = request('access_token.uid', 0); //用户ID $table_name = $ViolationStoreModel->getTable(); $notes_type = 2; //操作类型,1添加,2修改,3=删除 $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, [], ['status' => $status], '修改了公司' . $ViolationStore->company_name . '状态'); // 告知结果 return json_send(['code' => 'success', 'msg' => '设置成功']); } /** * 删除 * @author 唐远望 * @version 1.0 * @date 2025-12-03 * */ public function delete(Request $request, ViolationStoreModel $ViolationStoreModel, LowPriceGoodsCompanyModel $LowPriceGoodsCompanyModel, ViolationProductCompanyModel $ViolationProductCompanyModel) { // 验证参数 $request->scene('delete')->validate(); $admin_company_id = request('admin_company_id', '0'); $company_id = request('access_token.company_id', '0'); $is_admin = request('access_token.is_admin', '0'); // 接收数据 $id = request('id', 0); $company_where = ['company_id' => $id]; if ($is_admin != 1 && $company_id != 0) { $company_where['company_id'] = $company_id; } else { $company_where['company_id'] = $admin_company_id; } //查询是否已经被使用 $use_low_price_goods_company_log = $LowPriceGoodsCompanyModel->where($company_where)->first(); if ($use_low_price_goods_company_log) { return json_send(['code' => 'error', 'msg' => '该记录已被使用在低价商品配置中,不能删除']); } $use_violation_product_company_log = $ViolationProductCompanyModel->where($company_where)->first(); if ($use_violation_product_company_log) { return json_send(['code' => 'error', 'msg' => '该记录已被使用在违规商品配置中,不能删除']); } // 查询用户 $where = ['id' => $id]; if ($is_admin != 1 && $company_id != 0) { $where['company_id'] = $company_id; } else { $where['company_id'] = $admin_company_id; } // 执行删除 $ViolationStore = $ViolationStoreModel->where($where)->first(); if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']); $result = $ViolationStore->delete(); // 提示删除失败 if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']); // 记录行为 $admin_id = request('access_token.uid', 0); //用户ID $is_admin = request('access_token.is_admin'); //是否管理员操作 0=是1=否 $table_name = $ViolationStoreModel->getTable(); $notes_type = 3; //操作类型,1添加,2修改,3=删除 $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, $ViolationStore->toarray(), [], '删除了公司' . $ViolationStore->company_name . '信息'); // 告知结果 return json_send(['code' => 'success', 'msg' => '删除成功']); } }