ViolationStore.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 ($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-03
  56. */
  57. public function detail(Request $request, ViolationStoreModel $ViolationStoreModel)
  58. {
  59. $request->scene('detail')->validate();
  60. // 接收参数
  61. $id = request('id', 0);
  62. $map = ['id' => $id];
  63. $data = $ViolationStoreModel->where($map)->first();
  64. if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  65. // 加载模板
  66. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
  67. }
  68. /**
  69. * 添加
  70. * @author 唐远望
  71. * @version 1.0
  72. * @date 2025-12-03
  73. *
  74. */
  75. public function add(Request $request, ViolationStoreModel $ViolationStoreModel)
  76. {
  77. $request->scene('add')->validate();
  78. // 接收数据
  79. $all_data = request()->all();
  80. $store_scope = request('store_scope', '');
  81. $all_data['store_scope'] = $store_scope;
  82. //查询是否存在
  83. $map = ['store_name' => $all_data['store_name'], 'company_name' => $all_data['company_name']];
  84. $data = $ViolationStoreModel->where($map)->first();
  85. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  86. // 写入数据表
  87. $result = $ViolationStoreModel->addViolationStore($all_data);
  88. // 如果操作失败
  89. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  90. // 告知结果
  91. return json_send(['code' => 'success', 'msg' => '新增成功']);
  92. }
  93. /**
  94. * 修改
  95. * @author 唐远望
  96. * @version 1.0
  97. * @date 2025-12-03
  98. *
  99. */
  100. public function edit(Request $request, ViolationStoreModel $ViolationStoreModel)
  101. {
  102. $request->scene('edit')->validate();
  103. // 接收参数
  104. $id = request('id', 0);
  105. // 接收数据
  106. $all_data = request()->all();
  107. $store_scope = request('store_scope','');
  108. $all_data['store_scope'] = $store_scope;
  109. //查询是否存在
  110. $map = ['store_name' => $all_data['store_name'], 'company_name' => $all_data['company_name']];
  111. $data = $ViolationStoreModel->where($map)->where('id', '!=', $id)->first();
  112. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  113. // 更新数据表
  114. $where = ['id' => $id];
  115. $result = $ViolationStoreModel->updateViolationStore($where, $all_data);
  116. // 如果操作失败
  117. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  118. // 告知结果
  119. return json_send(['code' => 'success', 'msg' => '修改成功']);
  120. }
  121. /**
  122. * 修改状态
  123. * @author 唐远望
  124. * @version 1.0
  125. * @date 2025-12-03
  126. *
  127. */
  128. public function set_status(Request $request, ViolationStoreModel $ViolationStoreModel)
  129. {
  130. // 验证参数
  131. $request->scene('set_status')->validate();
  132. // 接收数据
  133. $id = request('id', 0);
  134. $status = request('status', 0);
  135. // 查询用户
  136. $where = ['id' => $id];
  137. // 执行修改
  138. $result = $ViolationStoreModel->changeStatus($where, $status);
  139. // 提示新增失败
  140. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  141. // 告知结果
  142. return json_send(['code' => 'success', 'msg' => '设置成功']);
  143. }
  144. /**
  145. * 删除
  146. * @author 唐远望
  147. * @version 1.0
  148. * @date 2025-12-03
  149. *
  150. */
  151. public function delete(Request $request, ViolationStoreModel $ViolationStoreModel)
  152. {
  153. // 验证参数
  154. $request->scene('delete')->validate();
  155. // 接收数据
  156. $id = request('id', 0);
  157. // 查询用户
  158. $where = ['id' => $id];
  159. // 执行删除
  160. $result = $ViolationStoreModel->deleteViolationStore($where);
  161. // 提示删除失败
  162. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  163. // 告知结果
  164. return json_send(['code' => 'success', 'msg' => '删除成功']);
  165. }
  166. }