ViolationStore.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?php
  2. namespace App\Http\Controllers\Manager\WashConfig;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\Manager\WashConfig\ViolationStore as Request;
  5. use App\Models\Manager\WashConfig\ViolationStore as ViolationStoreModel;
  6. use App\Models\Manager\WashConfig\LowPriceGoodsCompany as LowPriceGoodsCompanyModel;
  7. use App\Models\Manager\WashConfig\ViolationProductCompany as ViolationProductCompanyModel;
  8. use App\Models\Manager\Personnel\Employee as EmployeeModel;
  9. use App\Models\Manager\WashConfig\CompanyCategory as CompanyCategoryModel;
  10. use App\Models\Manager\Citys as CitysModel;
  11. /**
  12. * 数据清洗-违规店铺(公司)配置
  13. * @author 唐远望
  14. * @version 1.0
  15. * @date 2025-12-03
  16. */
  17. class ViolationStore extends Controller
  18. {
  19. /**
  20. * 列表
  21. * @author 唐远望
  22. * @version 1.0
  23. * @date 2025-12-03
  24. *
  25. */
  26. public function list(Request $request, ViolationStoreModel $ViolationStoreModel, EmployeeModel $EmployeeModel, CompanyCategoryModel $CompanyCategoryModel, CitysModel $CitysModel)
  27. {
  28. $request->scene('list')->validate();
  29. $company_id = request('access_token.company_id', '0');
  30. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  31. // 查询条件
  32. $map = [];
  33. $limit = request('limit', config('page_num', 10));
  34. $status = request('status', '');
  35. $start_time = request('start_time', '');
  36. $end_time = request('end_time', '');
  37. $store_name = request('store_name', '');
  38. $company_name = request('company_name', '');
  39. $social_credit_code = request('social_credit_code', '');
  40. $store_type = request('store_type', '');
  41. $category_id = request('category_id', '');
  42. // 时间条件
  43. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  44. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  45. // 其他条件
  46. if (is_numeric($status)) $map[] = ['status', '=', $status];
  47. if ($social_credit_code) $map[] = ['social_credit_code', 'like', "%$social_credit_code%"];
  48. if ($company_name) $map[] = ['company_name', 'like', "%$company_name%"];
  49. if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
  50. if ($store_type) $map[] = ['store_type', '=', $store_type];
  51. if ($category_id) $map[] = ['category_id', '=', $category_id];
  52. // 查询数据
  53. $result = $ViolationStoreModel->query()
  54. ->where($map)
  55. ->orderByDesc('id')
  56. ->paginate($limit)->toarray();
  57. // 分配数据
  58. if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
  59. if (isset($result['data']) && count($result['data']) > 0) {
  60. foreach ($result['data'] as $key => $value) {
  61. $employee_ids = $value['employee_ids'] != '' ? explode(',', $value['employee_ids']) : '';
  62. $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',', $value['platform']) : '';
  63. $result['data'][$key]['employee_ids'] = $employee_ids;
  64. $result['data'][$key]['employee_name'] = $employee_ids ? $EmployeeModel->whereIn('id', $employee_ids)->pluck('name')->toArray() : '';
  65. $result['data'][$key]['category_name'] = $value['category_id'] ? $CompanyCategoryModel->where('id', $value['category_id'])->value('name') : '';
  66. $province_name = $CitysModel->get_city_name($value['province_id']);
  67. $result['data'][$key]['province_name'] = $province_name ?? '';
  68. $city_name = $CitysModel->get_city_name($value['city_id']);
  69. $result['data'][$key]['city_name'] = $city_name ?? '';
  70. }
  71. }
  72. // 加载模板
  73. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  74. }
  75. /**
  76. * 全部
  77. * @author 唐远望
  78. * @version 1.0
  79. * @date 2025-12-08
  80. *
  81. */
  82. public function all(Request $request, ViolationStoreModel $ViolationStoreModel)
  83. {
  84. $request->scene('all')->validate();
  85. $company_id = request('access_token.company_id', '0');
  86. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  87. // 查询条件
  88. $map = [];
  89. $status = request('status', '0');
  90. $start_time = request('start_time', '');
  91. $end_time = request('end_time', '');
  92. $store_name = request('store_name', '');
  93. $company_name = request('company_name', '');
  94. $social_credit_code = request('social_credit_code', '');
  95. $category_id = request('category_id', '');
  96. // 时间条件
  97. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  98. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  99. // 其他条件
  100. if (is_numeric($status)) $map[] = ['status', '=', $status];
  101. if ($social_credit_code) $map[] = ['social_credit_code', 'like', "%$social_credit_code%"];
  102. if ($company_name) $map[] = ['company_name', 'like', "%$company_name%"];
  103. if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
  104. if ($category_id) $map[] = ['category_id', '=', $category_id];
  105. // 查询数据
  106. $result = $ViolationStoreModel->query()
  107. ->where($map)
  108. ->orderByDesc('id')
  109. ->get();
  110. // 分配数据
  111. if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
  112. // 加载模板
  113. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  114. }
  115. /**
  116. * 详情
  117. * @author 唐远望
  118. * @version 1.0
  119. * @date 2025-12-03
  120. */
  121. public function detail(Request $request, ViolationStoreModel $ViolationStoreModel, EmployeeModel $EmployeeModel, CompanyCategoryModel $CompanyCategoryModel, CitysModel $CitysModel)
  122. {
  123. $request->scene('detail')->validate();
  124. $company_id = request('access_token.company_id', '0');
  125. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  126. // 接收参数
  127. $id = request('id', 0);
  128. $map = ['id' => $id];
  129. $data = $ViolationStoreModel->where($map)->first();
  130. if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  131. $employee_ids = $data->employee_ids != '' ? explode(',', $data->employee_ids) : '';
  132. $data->employee_ids = $employee_ids;
  133. $data->employee_name = $employee_ids ? $EmployeeModel->whereIn('id', $employee_ids)->pluck('name')->toArray() : '';
  134. $data->category_name = $data->category_id ? $CompanyCategoryModel->where('id', $data->category_id)->value('name') : '';
  135. $province_name = $CitysModel->get_city_name($data->province_id);
  136. $data->province_name = $province_name ?? '';
  137. $city_name = $CitysModel->get_city_name($data->city_id);
  138. $data->city_name = $city_name ?? '';
  139. $data->platform = isset($data->platform) ? explode(',', $data->platform) : '';
  140. // 加载模板
  141. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
  142. }
  143. /**
  144. * 添加
  145. * @author 唐远望
  146. * @version 1.0
  147. * @date 2025-12-03
  148. *
  149. */
  150. public function add(Request $request, ViolationStoreModel $ViolationStoreModel)
  151. {
  152. $request->scene('add')->validate();
  153. $company_id = request('access_token.company_id', '0');
  154. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  155. // 接收数据
  156. $all_data = request()->all();
  157. $store_scope = request('store_scope', '');
  158. $all_data['store_scope'] = $store_scope; //店铺范围
  159. $employee_ids = request('employee_ids', '');
  160. $all_data['employee_ids'] = $employee_ids;
  161. $category_id = request('category_id', '0');
  162. $all_data['category_id'] = $category_id;
  163. $specify_responsible_person = request('specify_responsible_person', '0');
  164. $all_data['specify_responsible_person'] = $specify_responsible_person;
  165. $area_info = request('area_info', '');
  166. $all_data['area_info'] = $area_info;
  167. $platform = request('platform', '0');
  168. $all_data['platform'] = $platform;
  169. //查询是否存在
  170. $map = ['social_credit_code' => $all_data['social_credit_code']];
  171. $data = $ViolationStoreModel->where($map)->first();
  172. if ($data) return json_send(['code' => 'error', 'msg' => '营业执照记录已存在']);
  173. // 写入数据表
  174. $result = $ViolationStoreModel->addViolationStore($all_data);
  175. // 如果操作失败
  176. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  177. // 记录行为
  178. $admin_id = request('access_token.uid', 0); //用户ID
  179. $table_name = $ViolationStoreModel->getTable();
  180. $notes_type = 1; //操作类型,1添加,2修改,3=删除
  181. $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, [], $all_data, '新增了公司' . $all_data['company_name'] . '信息');
  182. // 告知结果
  183. return json_send(['code' => 'success', 'msg' => '新增成功']);
  184. }
  185. /**
  186. * 修改
  187. * @author 唐远望
  188. * @version 1.0
  189. * @date 2025-12-03
  190. *
  191. */
  192. public function edit(Request $request, ViolationStoreModel $ViolationStoreModel)
  193. {
  194. $request->scene('edit')->validate();
  195. $company_id = request('access_token.company_id', '0');
  196. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  197. // 接收参数
  198. $id = request('id', 0);
  199. // 接收数据
  200. $all_data = request()->all();
  201. $store_scope = request('store_scope', '');
  202. $all_data['store_scope'] = $store_scope;
  203. $employee_ids = request('employee_ids', '');
  204. $all_data['employee_ids'] = $employee_ids;
  205. $category_id = request('category_id', '0');
  206. $all_data['category_id'] = $category_id;
  207. $specify_responsible_person = request('specify_responsible_person', '0');
  208. $all_data['specify_responsible_person'] = $specify_responsible_person;
  209. $area_info = request('area_info', '');
  210. $all_data['area_info'] = $area_info;
  211. $platform = request('platform', '0');
  212. $all_data['platform'] = $platform;
  213. //查询是否存在
  214. $map = ['social_credit_code' => $all_data['social_credit_code']];
  215. $data = $ViolationStoreModel->where($map)->where('id', '!=', $id)->first();
  216. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  217. // 更新数据表
  218. $where = ['id' => $id];
  219. $ViolationStore = $ViolationStoreModel->where($where)->first();
  220. if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  221. $oldData = $ViolationStore->toarray();
  222. $result = $ViolationStoreModel->updateViolationStore($ViolationStore, $all_data);
  223. // 如果操作失败
  224. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  225. // 记录行为
  226. $admin_id = request('access_token.uid', 0); //用户ID
  227. $table_name = $ViolationStoreModel->getTable();
  228. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  229. $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, $oldData, $all_data, '修改了公司' . $oldData['company_name'] . '信息');
  230. // 告知结果
  231. return json_send(['code' => 'success', 'msg' => '修改成功']);
  232. }
  233. /**
  234. * 修改状态
  235. * @author 唐远望
  236. * @version 1.0
  237. * @date 2025-12-03
  238. *
  239. */
  240. public function set_status(Request $request, ViolationStoreModel $ViolationStoreModel)
  241. {
  242. // 验证参数
  243. $request->scene('set_status')->validate();
  244. $company_id = request('access_token.company_id', '0');
  245. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  246. // 接收数据
  247. $id = request('id', 0);
  248. $status = request('status', 0);
  249. // 查询用户
  250. $where = ['id' => $id];
  251. $ViolationStore = $ViolationStoreModel->where($where)->first();
  252. if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  253. // 执行修改
  254. $result = $ViolationStoreModel->changeStatus($ViolationStore, $status);
  255. // 提示新增失败
  256. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  257. // 记录行为
  258. $admin_id = request('access_token.uid', 0); //用户ID
  259. $table_name = $ViolationStoreModel->getTable();
  260. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  261. $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, [], ['status' => $status], '修改了公司' . $ViolationStore->company_name . '状态');
  262. // 告知结果
  263. return json_send(['code' => 'success', 'msg' => '设置成功']);
  264. }
  265. /**
  266. * 删除
  267. * @author 唐远望
  268. * @version 1.0
  269. * @date 2025-12-03
  270. *
  271. */
  272. public function delete(Request $request, ViolationStoreModel $ViolationStoreModel, LowPriceGoodsCompanyModel $LowPriceGoodsCompanyModel, ViolationProductCompanyModel $ViolationProductCompanyModel)
  273. {
  274. // 验证参数
  275. $request->scene('delete')->validate();
  276. $company_id = request('access_token.company_id', '0');
  277. $is_admin = request('access_token.is_admin', '0');
  278. // 接收数据
  279. $id = request('id', 0);
  280. //查询是否已经被使用
  281. $use_low_price_goods_company_log = $LowPriceGoodsCompanyModel->where('company_id', $id)->first();
  282. if ($use_low_price_goods_company_log) {
  283. return json_send(['code' => 'error', 'msg' => '该记录已被使用在低价商品配置中,不能删除']);
  284. }
  285. $use_violation_product_company_log = $ViolationProductCompanyModel->where('company_id', $id)->first();
  286. if ($use_violation_product_company_log) {
  287. return json_send(['code' => 'error', 'msg' => '该记录已被使用在违规商品配置中,不能删除']);
  288. }
  289. // 查询用户
  290. $where = ['id' => $id];
  291. // 执行删除
  292. $ViolationStore = $ViolationStoreModel->where($where)->first();
  293. if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  294. $result = $ViolationStore->delete();
  295. // 提示删除失败
  296. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  297. // 记录行为
  298. $admin_id = request('access_token.uid', 0); //用户ID
  299. $is_admin = request('access_token.is_admin'); //是否管理员操作 0=是1=否
  300. $table_name = $ViolationStoreModel->getTable();
  301. $notes_type = 3; //操作类型,1添加,2修改,3=删除
  302. $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, $ViolationStore->toarray(), [], '删除了公司' . $ViolationStore->company_name . '信息');
  303. // 告知结果
  304. return json_send(['code' => 'success', 'msg' => '删除成功']);
  305. }
  306. }