ViolationStore.php 8.9 KB

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