ViolationStore.php 16 KB

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