ViolationStore.php 14 KB

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