LowPriceGoods.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. $platform = request('platform', '');
  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 ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
  39. if ($platform) $map[] = ['platform', 'like', "%$platform%"];
  40. // 查询数据
  41. $result = $LowPriceGoodsModel->query()
  42. ->where($map)
  43. ->orderByDesc('id')
  44. ->paginate($limit)->toarray();
  45. // 分配数据
  46. if (!$result) return json_send(['code' => 'error', 'msg' => '暂无数据']);
  47. if(isset($result['data']) && count($result['data']) > 0){
  48. foreach ($result['data'] as $key => $value) {
  49. $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',',$value['platform']) : '';
  50. //查询店铺名称
  51. if(trim($value['store_scope']) == ''){
  52. $result['data'][$key]['store_name'] =['全部店铺'];
  53. }else{
  54. $store_scope = explode(',',$value['store_scope']);
  55. $store_name = $ViolationStoreModel->whereIn('id',$store_scope)->pluck('store_name');
  56. $result['data'][$key]['store_name'] = $store_name;
  57. }
  58. }
  59. }
  60. // 加载模板
  61. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  62. }
  63. /**
  64. * 详情
  65. * @author 唐远望
  66. * @version 1.0
  67. * @date 2025-12-02
  68. */
  69. public function detail(Request $request, LowPriceGoodsModel $LowPriceGoodsModel,ViolationStoreModel $ViolationStoreModel)
  70. {
  71. $request->scene('detail')->validate();
  72. // 接收参数
  73. $id = request('id', 0);
  74. $map = ['id' => $id];
  75. $data = $LowPriceGoodsModel->where($map)->first();
  76. if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  77. //查询店铺名称
  78. if(trim($data['store_scope']) == ''){
  79. $data['store_name'] = ['全部店铺'];
  80. }else{
  81. $store_scope = explode(',',$data['store_scope']);
  82. $store_name = $ViolationStoreModel->whereIn('id',$store_scope)->pluck('store_name');
  83. $data['store_name'] = $store_name;
  84. }
  85. $data->platform = isset($data->platform) ? explode(',',$data->platform) : '';
  86. // 加载模板
  87. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
  88. }
  89. /**
  90. * 添加
  91. * @author 唐远望
  92. * @version 1.0
  93. * @date 2025-12-02
  94. *
  95. */
  96. public function add(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  97. {
  98. $request->scene('add')->validate();
  99. // 接收数据
  100. $all_data = request()->all();
  101. $store_scope = request('store_scope', '');
  102. $all_data['store_scope'] = $store_scope;
  103. //查询是否存在
  104. $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs']];
  105. $data = $LowPriceGoodsModel->where($map)->first();
  106. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  107. // 写入数据表
  108. $result = $LowPriceGoodsModel->addLowProduct($all_data);
  109. // 如果操作失败
  110. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  111. // 告知结果
  112. return json_send(['code' => 'success', 'msg' => '新增成功']);
  113. }
  114. /**
  115. * 修改
  116. * @author 唐远望
  117. * @version 1.0
  118. * @date 2025-12-02
  119. *
  120. */
  121. public function edit(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  122. {
  123. $request->scene('edit')->validate();
  124. // 接收参数
  125. $id = request('id', 0);
  126. // 接收数据
  127. $all_data = request()->all();
  128. $store_scope = request('store_scope','');
  129. $all_data['store_scope'] = $store_scope;
  130. //查询是否存在
  131. $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs']];
  132. $data = $LowPriceGoodsModel->where($map)->where('id', '!=', $id)->first();
  133. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  134. // 更新数据表
  135. $where = ['id' => $id];
  136. $result = $LowPriceGoodsModel->updateLowProduct($where, $all_data);
  137. // 如果操作失败
  138. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  139. // 告知结果
  140. return json_send(['code' => 'success', 'msg' => '修改成功']);
  141. }
  142. /**
  143. * 修改状态
  144. * @author 唐远望
  145. * @version 1.0
  146. * @date 2025-12-02
  147. *
  148. */
  149. public function set_status(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  150. {
  151. // 验证参数
  152. $request->scene('set_status')->validate();
  153. // 接收数据
  154. $id = request('id', 0);
  155. $status = request('status', 0);
  156. // 查询用户
  157. $where = ['id' => $id];
  158. // 执行修改
  159. $result = $LowPriceGoodsModel->changeStatus($where, $status);
  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-02
  170. *
  171. */
  172. public function delete(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  173. {
  174. // 验证参数
  175. $request->scene('delete')->validate();
  176. // 接收数据
  177. $id = request('id', 0);
  178. // 查询用户
  179. $where = ['id' => $id];
  180. // 执行删除
  181. $result = $LowPriceGoodsModel->deleteLowProduct($where);
  182. // 提示删除失败
  183. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  184. // 告知结果
  185. return json_send(['code' => 'success', 'msg' => '删除成功']);
  186. }
  187. }