ViolationStore.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. $all_data['company_id'] = $company_id;
  193. } else {
  194. $map['company_id'] = $admin_company_id;
  195. $all_data['company_id'] = $admin_company_id;
  196. }
  197. $data = $ViolationStoreModel->where($map)->first();
  198. if ($data) return json_send(['code' => 'error', 'msg' => '营业执照记录已存在']);
  199. // 写入数据表
  200. $result = $ViolationStoreModel->addViolationStore($all_data);
  201. // 如果操作失败
  202. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  203. // 记录行为
  204. $admin_id = request('access_token.uid', 0); //用户ID
  205. $table_name = $ViolationStoreModel->getTable();
  206. $notes_type = 1; //操作类型,1添加,2修改,3=删除
  207. $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, [], $all_data, '新增了公司' . $all_data['company_name'] . '信息');
  208. // 告知结果
  209. return json_send(['code' => 'success', 'msg' => '新增成功']);
  210. }
  211. /**
  212. * 修改
  213. * @author 唐远望
  214. * @version 1.0
  215. * @date 2025-12-03
  216. *
  217. */
  218. public function edit(Request $request, ViolationStoreModel $ViolationStoreModel)
  219. {
  220. $request->scene('edit')->validate();
  221. $admin_company_id = request('admin_company_id', '0');
  222. $company_id = request('access_token.company_id', '0');
  223. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  224. // 接收参数
  225. $id = request('id', 0);
  226. // 接收数据
  227. $all_data = request()->all();
  228. $store_scope = request('store_scope', '');
  229. $all_data['store_scope'] = $store_scope;
  230. $employee_ids = request('employee_ids', '');
  231. $all_data['employee_ids'] = $employee_ids;
  232. $category_id = request('category_id', '0');
  233. $all_data['category_id'] = $category_id;
  234. $specify_responsible_person = request('specify_responsible_person', '0');
  235. $all_data['specify_responsible_person'] = $specify_responsible_person;
  236. $area_info = request('area_info', '');
  237. $all_data['area_info'] = $area_info;
  238. $platform = request('platform', '0');
  239. $all_data['platform'] = $platform;
  240. //查询是否存在
  241. $map = ['social_credit_code' => $all_data['social_credit_code']];
  242. if ($is_admin != 1 && $company_id != 0) {
  243. $map['company_id'] = $company_id;
  244. } else {
  245. $map['company_id'] = $admin_company_id;
  246. }
  247. $data = $ViolationStoreModel->where($map)->where('id', '!=', $id)->first();
  248. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  249. // 更新数据表
  250. $where = ['id' => $id];
  251. if ($is_admin != 1 && $company_id != 0) {
  252. $where['company_id'] = $company_id;
  253. } else {
  254. $where['company_id'] = $admin_company_id;
  255. }
  256. $ViolationStore = $ViolationStoreModel->where($where)->first();
  257. if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  258. $oldData = $ViolationStore->toarray();
  259. $all_data['company_id'] = $company_id;
  260. $result = $ViolationStoreModel->updateViolationStore($ViolationStore, $all_data);
  261. // 如果操作失败
  262. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  263. // 记录行为
  264. $admin_id = request('access_token.uid', 0); //用户ID
  265. $table_name = $ViolationStoreModel->getTable();
  266. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  267. $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, $oldData, $all_data, '修改了公司' . $oldData['company_name'] . '信息');
  268. // 告知结果
  269. return json_send(['code' => 'success', 'msg' => '修改成功']);
  270. }
  271. /**
  272. * 修改状态
  273. * @author 唐远望
  274. * @version 1.0
  275. * @date 2025-12-03
  276. *
  277. */
  278. public function set_status(Request $request, ViolationStoreModel $ViolationStoreModel)
  279. {
  280. // 验证参数
  281. $request->scene('set_status')->validate();
  282. $admin_company_id = request('admin_company_id', '0');
  283. $company_id = request('access_token.company_id', '0');
  284. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  285. // 接收数据
  286. $id = request('id', 0);
  287. $status = request('status', 0);
  288. // 查询用户
  289. $where = ['id' => $id];
  290. if ($is_admin != 1 && $company_id != 0) {
  291. $where['company_id'] = $company_id;
  292. } else {
  293. $where['company_id'] = $admin_company_id;
  294. }
  295. $ViolationStore = $ViolationStoreModel->where($where)->first();
  296. if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  297. // 执行修改
  298. $result = $ViolationStoreModel->changeStatus($ViolationStore, $status);
  299. // 提示新增失败
  300. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  301. // 记录行为
  302. $admin_id = request('access_token.uid', 0); //用户ID
  303. $table_name = $ViolationStoreModel->getTable();
  304. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  305. $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, [], ['status' => $status], '修改了公司' . $ViolationStore->company_name . '状态');
  306. // 告知结果
  307. return json_send(['code' => 'success', 'msg' => '设置成功']);
  308. }
  309. /**
  310. * 删除
  311. * @author 唐远望
  312. * @version 1.0
  313. * @date 2025-12-03
  314. *
  315. */
  316. public function delete(Request $request, ViolationStoreModel $ViolationStoreModel, LowPriceGoodsCompanyModel $LowPriceGoodsCompanyModel, ViolationProductCompanyModel $ViolationProductCompanyModel)
  317. {
  318. // 验证参数
  319. $request->scene('delete')->validate();
  320. $admin_company_id = request('admin_company_id', '0');
  321. $company_id = request('access_token.company_id', '0');
  322. $is_admin = request('access_token.is_admin', '0');
  323. // 接收数据
  324. $id = request('id', 0);
  325. $company_where = ['company_id' => $id];
  326. if ($is_admin != 1 && $company_id != 0) {
  327. $company_where['company_id'] = $company_id;
  328. } else {
  329. $company_where['company_id'] = $admin_company_id;
  330. }
  331. //查询是否已经被使用
  332. $use_low_price_goods_company_log = $LowPriceGoodsCompanyModel->where($company_where)->first();
  333. if ($use_low_price_goods_company_log) {
  334. return json_send(['code' => 'error', 'msg' => '该记录已被使用在低价商品配置中,不能删除']);
  335. }
  336. $use_violation_product_company_log = $ViolationProductCompanyModel->where($company_where)->first();
  337. if ($use_violation_product_company_log) {
  338. return json_send(['code' => 'error', 'msg' => '该记录已被使用在违规商品配置中,不能删除']);
  339. }
  340. // 查询用户
  341. $where = ['id' => $id];
  342. if ($is_admin != 1 && $company_id != 0) {
  343. $where['company_id'] = $company_id;
  344. } else {
  345. $where['company_id'] = $admin_company_id;
  346. }
  347. // 执行删除
  348. $ViolationStore = $ViolationStoreModel->where($where)->first();
  349. if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  350. $result = $ViolationStore->delete();
  351. // 提示删除失败
  352. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  353. // 记录行为
  354. $admin_id = request('access_token.uid', 0); //用户ID
  355. $is_admin = request('access_token.is_admin'); //是否管理员操作 0=是1=否
  356. $table_name = $ViolationStoreModel->getTable();
  357. $notes_type = 3; //操作类型,1添加,2修改,3=删除
  358. $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, $ViolationStore->toarray(), [], '删除了公司' . $ViolationStore->company_name . '信息');
  359. // 告知结果
  360. return json_send(['code' => 'success', 'msg' => '删除成功']);
  361. }
  362. }