ViolationStore.php 18 KB

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