ViolationStore.php 7.7 KB

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