ViolationStore.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. //查询是否存在
  159. $map = ['social_credit_code' => $all_data['social_credit_code']];
  160. $data = $ViolationStoreModel->where($map)->first();
  161. if ($data) return json_send(['code' => 'error', 'msg' => '营业执照记录已存在']);
  162. // 写入数据表
  163. $result = $ViolationStoreModel->addViolationStore($all_data);
  164. // 如果操作失败
  165. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  166. // 记录行为
  167. $admin_id = request('access_token.uid', 0); //用户ID
  168. $table_name = $ViolationStoreModel->getTable();
  169. $notes_type = 1; //操作类型,1添加,2修改,3=删除
  170. $this->addAdminHistory('清洗配置-公司管理', $admin_id, $table_name, $notes_type, [], $all_data, '新增了公司' . $all_data['company_name'] . '信息');
  171. // 告知结果
  172. return json_send(['code' => 'success', 'msg' => '新增成功']);
  173. }
  174. /**
  175. * 修改
  176. * @author 唐远望
  177. * @version 1.0
  178. * @date 2025-12-03
  179. *
  180. */
  181. public function edit(Request $request, ViolationStoreModel $ViolationStoreModel)
  182. {
  183. $request->scene('edit')->validate();
  184. // 接收参数
  185. $id = request('id', 0);
  186. // 接收数据
  187. $all_data = request()->all();
  188. $store_scope = request('store_scope', '');
  189. $all_data['store_scope'] = $store_scope;
  190. $employee_ids = request('employee_ids', '');
  191. $all_data['employee_ids'] = $employee_ids;
  192. $category_id = request('category_id', '0');
  193. $all_data['category_id'] = $category_id;
  194. $specify_responsible_person = request('specify_responsible_person', '0');
  195. $all_data['specify_responsible_person'] = $specify_responsible_person;
  196. $area_info = request('area_info', '');
  197. $all_data['area_info'] = $area_info;
  198. //查询是否存在
  199. $map = ['social_credit_code' => $all_data['social_credit_code']];
  200. $data = $ViolationStoreModel->where($map)->where('id', '!=', $id)->first();
  201. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  202. // 更新数据表
  203. $where = ['id' => $id];
  204. $ViolationStore = $ViolationStoreModel->where($where)->first();
  205. if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  206. $result = $ViolationStoreModel->updateViolationStore($ViolationStore, $all_data);
  207. // 如果操作失败
  208. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  209. // 记录行为
  210. $admin_id = request('access_token.uid', 0); //用户ID
  211. $table_name = $ViolationStoreModel->getTable();
  212. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  213. $this->addAdminHistory('清洗配置-公司管理', $admin_id, $table_name, $notes_type, $ViolationStore->toarray(), $all_data, '修改了公司' . $ViolationStore->company_name . '信息');
  214. // 告知结果
  215. return json_send(['code' => 'success', 'msg' => '修改成功']);
  216. }
  217. /**
  218. * 修改状态
  219. * @author 唐远望
  220. * @version 1.0
  221. * @date 2025-12-03
  222. *
  223. */
  224. public function set_status(Request $request, ViolationStoreModel $ViolationStoreModel)
  225. {
  226. // 验证参数
  227. $request->scene('set_status')->validate();
  228. // 接收数据
  229. $id = request('id', 0);
  230. $status = request('status', 0);
  231. // 查询用户
  232. $where = ['id' => $id];
  233. $ViolationStore = $ViolationStoreModel->where($where)->first();
  234. if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  235. // 执行修改
  236. $result = $ViolationStoreModel->changeStatus($ViolationStore, $status);
  237. // 提示新增失败
  238. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  239. // 记录行为
  240. $admin_id = request('access_token.uid', 0); //用户ID
  241. $table_name = $ViolationStoreModel->getTable();
  242. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  243. $this->addAdminHistory('清洗配置-公司管理', $admin_id, $table_name, $notes_type, [], ['status' => $status], '修改了公司' . $ViolationStore->company_name . '状态');
  244. // 告知结果
  245. return json_send(['code' => 'success', 'msg' => '设置成功']);
  246. }
  247. /**
  248. * 删除
  249. * @author 唐远望
  250. * @version 1.0
  251. * @date 2025-12-03
  252. *
  253. */
  254. public function delete(Request $request, ViolationStoreModel $ViolationStoreModel, LowPriceGoodsCompanyModel $LowPriceGoodsCompanyModel, ViolationProductCompanyModel $ViolationProductCompanyModel)
  255. {
  256. // 验证参数
  257. $request->scene('delete')->validate();
  258. // 接收数据
  259. $id = request('id', 0);
  260. //查询是否已经被使用
  261. $use_low_price_goods_company_log = $LowPriceGoodsCompanyModel->where('company_id', $id)->first();
  262. if ($use_low_price_goods_company_log) {
  263. return json_send(['code' => 'error', 'msg' => '该记录已被使用在低价商品配置中,不能删除']);
  264. }
  265. $use_violation_product_company_log = $ViolationProductCompanyModel->where('company_id', $id)->first();
  266. if ($use_violation_product_company_log) {
  267. return json_send(['code' => 'error', 'msg' => '该记录已被使用在违规商品配置中,不能删除']);
  268. }
  269. // 查询用户
  270. $where = ['id' => $id];
  271. // 执行删除
  272. $ViolationStore = $ViolationStoreModel->where($where)->first();
  273. if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  274. $result = $ViolationStore->delete();
  275. // 提示删除失败
  276. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  277. // 记录行为
  278. $admin_id = request('access_token.uid', 0); //用户ID
  279. $table_name = $ViolationStoreModel->getTable();
  280. $notes_type = 3; //操作类型,1添加,2修改,3=删除
  281. $this->addAdminHistory('清洗配置-公司管理', $admin_id, $table_name, $notes_type, $ViolationStore->toarray(), [], '删除了公司' . $ViolationStore->company_name . '信息');
  282. // 告知结果
  283. return json_send(['code' => 'success', 'msg' => '删除成功']);
  284. }
  285. }