ViolationStore.php 7.7 KB

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