ViolationStore.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. /**
  11. * 数据清洗-违规店铺(公司)配置
  12. * @author 唐远望
  13. * @version 1.0
  14. * @date 2025-12-03
  15. */
  16. class ViolationStore extends Controller
  17. {
  18. /**
  19. * 列表
  20. * @author 唐远望
  21. * @version 1.0
  22. * @date 2025-12-03
  23. *
  24. */
  25. public function list(Request $request, ViolationStoreModel $ViolationStoreModel,EmployeeModel $EmployeeModel, CompanyCategoryModel $CompanyCategoryModel)
  26. {
  27. $request->scene('list')->validate();
  28. // 查询条件
  29. $map = [];
  30. $limit = request('limit', config('page_num', 10));
  31. $status = request('status', '');
  32. $start_time = request('start_time', '');
  33. $end_time = request('end_time', '');
  34. $store_name = request('store_name', '');
  35. $company_name = request('company_name', '');
  36. $social_credit_code = request('social_credit_code', '');
  37. $store_type = request('store_type', '');
  38. $category_id = request('category_id', '');
  39. // 时间条件
  40. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  41. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  42. // 其他条件
  43. if (is_numeric($status)) $map[] = ['status', '=', $status];
  44. if ($social_credit_code) $map[] = ['social_credit_code', 'like', "%$social_credit_code%"];
  45. if ($company_name) $map[] = ['company_name', 'like', "%$company_name%"];
  46. if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
  47. if ($store_type) $map[] = ['store_type', '=', $store_type];
  48. if ($category_id) $map[] = ['category_id', '=', $category_id];
  49. // 查询数据
  50. $result = $ViolationStoreModel->query()
  51. ->where($map)
  52. ->orderByDesc('id')
  53. ->paginate($limit)->toarray();
  54. // 分配数据
  55. if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
  56. if (isset($result['data']) && count($result['data']) > 0) {
  57. foreach ($result['data'] as $key => $value) {
  58. $employee_ids = $value['employee_ids'] !='' ? explode(',', $value['employee_ids']) : '';
  59. $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',', $value['platform']) : '';
  60. $result['data'][$key]['employee_ids'] = $employee_ids;
  61. $result['data'][$key]['employee_name'] = $employee_ids ? $EmployeeModel->whereIn('id', $employee_ids)->pluck('name')->toArray() : '';
  62. $result['data'][$key]['category_name'] = $value['category_id'] ? $CompanyCategoryModel->where('id', $value['category_id'])->value('name') : '';
  63. }
  64. }
  65. // 加载模板
  66. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  67. }
  68. /**
  69. * 全部
  70. * @author 唐远望
  71. * @version 1.0
  72. * @date 2025-12-08
  73. *
  74. */
  75. public function all(Request $request, ViolationStoreModel $ViolationStoreModel)
  76. {
  77. $request->scene('all')->validate();
  78. // 查询条件
  79. $map = [];
  80. $status = request('status', '0');
  81. $start_time = request('start_time', '');
  82. $end_time = request('end_time', '');
  83. $store_name = request('store_name', '');
  84. $company_name = request('company_name', '');
  85. $social_credit_code = request('social_credit_code', '');
  86. $category_id = request('category_id', '');
  87. // 时间条件
  88. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  89. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  90. // 其他条件
  91. if (is_numeric($status)) $map[] = ['status', '=', $status];
  92. if ($social_credit_code) $map[] = ['social_credit_code', 'like', "%$social_credit_code%"];
  93. if ($company_name) $map[] = ['company_name', 'like', "%$company_name%"];
  94. if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
  95. if ($category_id) $map[] = ['category_id', '=', $category_id];
  96. // 查询数据
  97. $result = $ViolationStoreModel->query()
  98. ->where($map)
  99. ->orderByDesc('id')
  100. ->get();
  101. // 分配数据
  102. if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
  103. // 加载模板
  104. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  105. }
  106. /**
  107. * 详情
  108. * @author 唐远望
  109. * @version 1.0
  110. * @date 2025-12-03
  111. */
  112. public function detail(Request $request, ViolationStoreModel $ViolationStoreModel,EmployeeModel $EmployeeModel, CompanyCategoryModel $CompanyCategoryModel)
  113. {
  114. $request->scene('detail')->validate();
  115. // 接收参数
  116. $id = request('id', 0);
  117. $map = ['id' => $id];
  118. $data = $ViolationStoreModel->where($map)->first();
  119. if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  120. $employee_ids = $data->employee_ids !='' ? explode(',', $data->employee_ids) : '';
  121. $data->employee_ids = $employee_ids;
  122. $data->employee_name = $employee_ids ? $EmployeeModel->whereIn('id', $employee_ids)->pluck('name')->toArray() : '';
  123. $data->category_name = $data->category_id ? $CompanyCategoryModel->where('id', $data->category_id)->value('name') : '';
  124. // 加载模板
  125. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
  126. }
  127. /**
  128. * 添加
  129. * @author 唐远望
  130. * @version 1.0
  131. * @date 2025-12-03
  132. *
  133. */
  134. public function add(Request $request, ViolationStoreModel $ViolationStoreModel)
  135. {
  136. $request->scene('add')->validate();
  137. // 接收数据
  138. $all_data = request()->all();
  139. $store_scope = request('store_scope', '');
  140. $all_data['store_scope'] = $store_scope;//店铺范围
  141. $employee_ids = request('employee_ids', '');
  142. $all_data['employee_ids'] = $employee_ids;
  143. $category_id = request('category_id', '0');
  144. $all_data['category_id'] = $category_id;
  145. //查询是否存在
  146. $map = ['social_credit_code' => $all_data['social_credit_code']];
  147. $data = $ViolationStoreModel->where($map)->first();
  148. if ($data) return json_send(['code' => 'error', 'msg' => '营业执照记录已存在']);
  149. // 写入数据表
  150. $result = $ViolationStoreModel->addViolationStore($all_data);
  151. // 如果操作失败
  152. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  153. // 告知结果
  154. return json_send(['code' => 'success', 'msg' => '新增成功']);
  155. }
  156. /**
  157. * 修改
  158. * @author 唐远望
  159. * @version 1.0
  160. * @date 2025-12-03
  161. *
  162. */
  163. public function edit(Request $request, ViolationStoreModel $ViolationStoreModel)
  164. {
  165. $request->scene('edit')->validate();
  166. // 接收参数
  167. $id = request('id', 0);
  168. // 接收数据
  169. $all_data = request()->all();
  170. $store_scope = request('store_scope','');
  171. $all_data['store_scope'] = $store_scope;
  172. $employee_ids = request('employee_ids', '');
  173. $all_data['employee_ids'] = $employee_ids;
  174. $category_id = request('category_id', '0');
  175. $all_data['category_id'] = $category_id;
  176. //查询是否存在
  177. $map = ['social_credit_code' => $all_data['social_credit_code']];
  178. $data = $ViolationStoreModel->where($map)->where('id', '!=', $id)->first();
  179. if ($data) return json_send(['code' => 'error', 'msg' => '营业执照记录已存在']);
  180. // 更新数据表
  181. $where = ['id' => $id];
  182. $result = $ViolationStoreModel->updateViolationStore($where, $all_data);
  183. // 如果操作失败
  184. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  185. // 告知结果
  186. return json_send(['code' => 'success', 'msg' => '修改成功']);
  187. }
  188. /**
  189. * 修改状态
  190. * @author 唐远望
  191. * @version 1.0
  192. * @date 2025-12-03
  193. *
  194. */
  195. public function set_status(Request $request, ViolationStoreModel $ViolationStoreModel)
  196. {
  197. // 验证参数
  198. $request->scene('set_status')->validate();
  199. // 接收数据
  200. $id = request('id', 0);
  201. $status = request('status', 0);
  202. // 查询用户
  203. $where = ['id' => $id];
  204. // 执行修改
  205. $result = $ViolationStoreModel->changeStatus($where, $status);
  206. // 提示新增失败
  207. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  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 delete(Request $request, ViolationStoreModel $ViolationStoreModel,LowPriceGoodsCompanyModel $LowPriceGoodsCompanyModel,ViolationProductCompanyModel $ViolationProductCompanyModel)
  219. {
  220. // 验证参数
  221. $request->scene('delete')->validate();
  222. // 接收数据
  223. $id = request('id', 0);
  224. //查询是否已经被使用
  225. if ($id > 0) {
  226. $use_low_price_goods_company_log = $LowPriceGoodsCompanyModel->where('company_id', $id)->first();
  227. if ($use_low_price_goods_company_log) {
  228. return json_send(['code' => 'error', 'msg' => '该记录已被使用在低价商品配置中,不能删除']);
  229. }
  230. $use_violation_product_company_log = $ViolationProductCompanyModel->where('company_id', $id)->first();
  231. if ($use_violation_product_company_log) {
  232. return json_send(['code' => 'error', 'msg' => '该记录已被使用在违规商品配置中,不能删除']);
  233. }
  234. }
  235. // 查询用户
  236. $where = ['id' => $id];
  237. // 执行删除
  238. $result = $ViolationStoreModel->deleteViolationStore($where);
  239. // 提示删除失败
  240. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  241. // 告知结果
  242. return json_send(['code' => 'success', 'msg' => '删除成功']);
  243. }
  244. }