ViolationStore.php 14 KB

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