ViolationStore.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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\Personnel\Employee as EmployeeModel;
  7. use App\Models\Manager\WashConfig\CompanyCategory as CompanyCategoryModel;
  8. use App\Models\Manager\Citys as CitysModel;
  9. /**
  10. * 数据清洗-违规店铺配置
  11. * @author 唐远望
  12. * @version 1.0
  13. * @date 2025-12-03
  14. */
  15. class ViolationStore extends Controller
  16. {
  17. /**
  18. * 列表
  19. * @author 唐远望
  20. * @version 1.0
  21. * @date 2025-12-03
  22. *
  23. */
  24. public function list(Request $request, ViolationStoreModel $ViolationStoreModel, EmployeeModel $EmployeeModel)
  25. {
  26. $request->scene('list')->validate();
  27. $admin_company_id = request('admin_company_id', '0');
  28. $company_id = request('access_token.company_id', '0');
  29. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  30. // 查询条件
  31. $map = [];
  32. $limit = request('limit', config('page_num', 10));
  33. $status = request('status', '');
  34. $start_time = request('start_time', '');
  35. $end_time = request('end_time', '');
  36. $store_name = request('store_name', '');
  37. $store_type = request('store_type', '');//店铺类型:1=黑名单2=白名单
  38. // 时间条件
  39. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  40. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  41. // 其他条件
  42. if (is_numeric($status)) $map[] = ['status', '=', $status];
  43. if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
  44. if ($store_type) $map[] = ['store_type', '=', $store_type];
  45. // 查询数据
  46. if ($is_admin != 1 && $company_id != 0){
  47. $map[] = ['company_id', '=', $company_id];
  48. }else{
  49. $map[] = ['company_id', '=', $admin_company_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]['city_name'] = $city_name ?? '';
  64. }
  65. }
  66. // 加载模板
  67. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  68. }
  69. /**
  70. * 全部
  71. * @author 唐远望
  72. * @version 1.0
  73. * @date 2025-12-08
  74. *
  75. */
  76. public function all(Request $request, ViolationStoreModel $ViolationStoreModel)
  77. {
  78. $request->scene('all')->validate();
  79. $admin_company_id = request('admin_company_id', '0');
  80. $company_id = request('access_token.company_id', '0');
  81. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  82. // 查询条件
  83. $map = [];
  84. $status = request('status', '0');
  85. $start_time = request('start_time', '');
  86. $end_time = request('end_time', '');
  87. $store_name = request('store_name', '');
  88. $store_type = request('store_type', '');//店铺类型:1=黑名单2=白名单
  89. // 时间条件
  90. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  91. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  92. // 其他条件
  93. if (is_numeric($status)) $map[] = ['status', '=', $status];
  94. if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
  95. if ($store_type) $map[] = ['store_type', '=', $store_type];
  96. // 查询数据
  97. if ($is_admin != 1 && $company_id != 0){
  98. $map[] = ['company_id', '=', $company_id];
  99. }else{
  100. $map[] = ['company_id', '=', $admin_company_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)
  118. {
  119. $request->scene('detail')->validate();
  120. $admin_company_id = request('admin_company_id', '0');
  121. $company_id = request('access_token.company_id', '0');
  122. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  123. // 接收参数
  124. $id = request('id', 0);
  125. $map = ['id' => $id];
  126. if ($is_admin != 1 && $company_id != 0) {
  127. $map['company_id'] = $company_id;
  128. } else {
  129. $map['company_id'] = $admin_company_id;
  130. }
  131. $data = $ViolationStoreModel->where($map)->first();
  132. if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  133. $employee_ids = $data->employee_ids != '' ? explode(',', $data->employee_ids) : '';
  134. $data->employee_ids = $employee_ids;
  135. $data->employee_name = $employee_ids ? $EmployeeModel->whereIn('id', $employee_ids)->pluck('name')->toArray() : '';
  136. $data->platform = isset($data->platform) ? explode(',', $data->platform) : '';
  137. // 加载模板
  138. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
  139. }
  140. /**
  141. * 添加
  142. * @author 唐远望
  143. * @version 1.0
  144. * @date 2025-12-03
  145. *
  146. */
  147. public function add(Request $request, ViolationStoreModel $ViolationStoreModel)
  148. {
  149. $request->scene('add')->validate();
  150. $admin_company_id = request('admin_company_id', '0');
  151. $company_id = request('access_token.company_id', '0');
  152. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  153. // 接收数据
  154. $all_data = request()->all();
  155. $store_scope = request('store_scope', '');
  156. $store_type = request('store_type', '1');//店铺类型:1=黑名单2=白名单
  157. $all_data['store_type'] = $store_type; //店铺类型
  158. $all_data['store_scope'] = $store_scope; //店铺范围
  159. $employee_ids = request('employee_ids', '');
  160. $all_data['employee_ids'] = $employee_ids;
  161. $category_id = request('category_id', '0');
  162. $all_data['category_id'] = $category_id;
  163. $specify_responsible_person = request('specify_responsible_person', '0');
  164. $all_data['specify_responsible_person'] = $specify_responsible_person;
  165. $area_info = request('area_info', '');
  166. $all_data['area_info'] = $area_info;
  167. $platform = request('platform', '0');
  168. $all_data['platform'] = $platform;
  169. //查询是否存在
  170. $map = ['store_name' => $all_data['store_name']];
  171. if ($is_admin != 1 && $company_id != 0) {
  172. $map['company_id'] = $company_id;
  173. $all_data['company_id'] = $company_id;
  174. } else {
  175. $map['company_id'] = $admin_company_id;
  176. $all_data['company_id'] = $admin_company_id;
  177. }
  178. $data = $ViolationStoreModel->where($map)->first();
  179. if ($data) return json_send(['code' => 'error', 'msg' => '营业执照记录已存在']);
  180. // 写入数据表
  181. $result = $ViolationStoreModel->addViolationStore($all_data);
  182. // 如果操作失败
  183. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  184. // 记录行为
  185. $admin_id = request('access_token.uid', 0); //用户ID
  186. $table_name = $ViolationStoreModel->getTable();
  187. $notes_type = 1; //操作类型,1添加,2修改,3=删除
  188. $this->addAdminHistory('清洗配置-店铺管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, [], $all_data, '新增了店铺' . $all_data['store_name'] . '信息');
  189. // 告知结果
  190. return json_send(['code' => 'success', 'msg' => '新增成功']);
  191. }
  192. /**
  193. * 修改
  194. * @author 唐远望
  195. * @version 1.0
  196. * @date 2025-12-03
  197. *
  198. */
  199. public function edit(Request $request, ViolationStoreModel $ViolationStoreModel)
  200. {
  201. $request->scene('edit')->validate();
  202. $admin_company_id = request('admin_company_id', '0');
  203. $company_id = request('access_token.company_id', '0');
  204. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  205. // 接收参数
  206. $id = request('id', 0);
  207. // 接收数据
  208. $all_data = request()->all();
  209. $store_scope = request('store_scope', '');
  210. $store_type = request('store_type', '1');//店铺类型:1=黑名单2=白名单
  211. $all_data['store_type'] = $store_type; //店铺类型
  212. $all_data['store_scope'] = $store_scope;
  213. $employee_ids = request('employee_ids', '');
  214. $all_data['employee_ids'] = $employee_ids;
  215. $category_id = request('category_id', '0');
  216. $all_data['category_id'] = $category_id;
  217. $specify_responsible_person = request('specify_responsible_person', '0');
  218. $all_data['specify_responsible_person'] = $specify_responsible_person;
  219. $area_info = request('area_info', '');
  220. $all_data['area_info'] = $area_info;
  221. $platform = request('platform', '0');
  222. $all_data['platform'] = $platform;
  223. //查询是否存在
  224. $map = ['store_name' => $all_data['store_name']];
  225. if ($is_admin != 1 && $company_id != 0) {
  226. $map['company_id'] = $company_id;
  227. } else {
  228. $map['company_id'] = $admin_company_id;
  229. }
  230. $data = $ViolationStoreModel->where($map)->where('id', '!=', $id)->first();
  231. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  232. // 更新数据表
  233. $where = ['id' => $id];
  234. if ($is_admin != 1 && $company_id != 0) {
  235. $where['company_id'] = $company_id;
  236. } else {
  237. $where['company_id'] = $admin_company_id;
  238. }
  239. $ViolationStore = $ViolationStoreModel->where($where)->first();
  240. if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  241. $oldData = $ViolationStore->toarray();
  242. $all_data['company_id'] = $map['company_id'];
  243. $result = $ViolationStoreModel->updateViolationStore($ViolationStore, $all_data);
  244. // 如果操作失败
  245. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  246. // 记录行为
  247. $admin_id = request('access_token.uid', 0); //用户ID
  248. $table_name = $ViolationStoreModel->getTable();
  249. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  250. $this->addAdminHistory('清洗配置-店铺管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, $oldData, $all_data, '修改了店铺' . $oldData['store_name'] . '信息');
  251. // 告知结果
  252. return json_send(['code' => 'success', 'msg' => '修改成功']);
  253. }
  254. /**
  255. * 修改状态
  256. * @author 唐远望
  257. * @version 1.0
  258. * @date 2025-12-03
  259. *
  260. */
  261. public function set_status(Request $request, ViolationStoreModel $ViolationStoreModel)
  262. {
  263. // 验证参数
  264. $request->scene('set_status')->validate();
  265. $admin_company_id = request('admin_company_id', '0');
  266. $company_id = request('access_token.company_id', '0');
  267. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  268. // 接收数据
  269. $id = request('id', 0);
  270. $status = request('status', 0);
  271. // 查询用户
  272. $where = ['id' => $id];
  273. if ($is_admin != 1 && $company_id != 0) {
  274. $where['company_id'] = $company_id;
  275. } else {
  276. $where['company_id'] = $admin_company_id;
  277. }
  278. $ViolationStore = $ViolationStoreModel->where($where)->first();
  279. if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  280. // 执行修改
  281. $result = $ViolationStoreModel->changeStatus($ViolationStore, $status);
  282. // 提示新增失败
  283. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  284. // 记录行为
  285. $admin_id = request('access_token.uid', 0); //用户ID
  286. $table_name = $ViolationStoreModel->getTable();
  287. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  288. $this->addAdminHistory('清洗配置-店铺管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, [], ['status' => $status], '修改了店铺' . $ViolationStore->store_name . '状态');
  289. // 告知结果
  290. return json_send(['code' => 'success', 'msg' => '设置成功']);
  291. }
  292. /**
  293. * 删除
  294. * @author 唐远望
  295. * @version 1.0
  296. * @date 2025-12-03
  297. *
  298. */
  299. public function delete(Request $request, ViolationStoreModel $ViolationStoreModel)
  300. {
  301. // 验证参数
  302. $request->scene('delete')->validate();
  303. $admin_company_id = request('admin_company_id', '0');
  304. $company_id = request('access_token.company_id', '0');
  305. $is_admin = request('access_token.is_admin', '0');
  306. // 接收数据
  307. $id = request('id', 0);
  308. $company_where = ['company_id' => $id];
  309. if ($is_admin != 1 && $company_id != 0) {
  310. $company_where['company_id'] = $company_id;
  311. } else {
  312. $company_where['company_id'] = $admin_company_id;
  313. }
  314. // 查询用户
  315. $where = ['id' => $id];
  316. if ($is_admin != 1 && $company_id != 0) {
  317. $where['company_id'] = $company_id;
  318. } else {
  319. $where['company_id'] = $admin_company_id;
  320. }
  321. // 执行删除
  322. $ViolationStore = $ViolationStoreModel->where($where)->first();
  323. if (!$ViolationStore) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  324. $result = $ViolationStore->delete();
  325. // 提示删除失败
  326. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  327. // 记录行为
  328. $admin_id = request('access_token.uid', 0); //用户ID
  329. $is_admin = request('access_token.is_admin'); //是否管理员操作 0=是1=否
  330. $table_name = $ViolationStoreModel->getTable();
  331. $notes_type = 3; //操作类型,1添加,2修改,3=删除
  332. $this->addAdminHistory('清洗配置-店铺管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, $ViolationStore->toarray(), [], '删除了店铺' . $ViolationStore->store_name . '信息');
  333. // 告知结果
  334. return json_send(['code' => 'success', 'msg' => '删除成功']);
  335. }
  336. }