LowPriceGoods.php 7.2 KB

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