LowPriceGoods.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. /**
  7. * 数据清洗-低价产品配置
  8. * @author 唐远望
  9. * @version 1.0
  10. * @date 2025-12-02
  11. */
  12. class LowPriceGoods extends Controller
  13. {
  14. /**
  15. * 列表
  16. * @author 唐远望
  17. * @version 1.0
  18. * @date 2025-12-02
  19. *
  20. */
  21. public function list(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  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. $product_name = request('product_name', '');
  31. // 时间条件
  32. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  33. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  34. // 其他条件
  35. if ($status) $map[] = ['status', '=', $status];
  36. if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
  37. // 查询数据
  38. $result = $LowPriceGoodsModel->query()
  39. ->where($map)
  40. ->orderByDesc('id')
  41. ->paginate($limit);
  42. // 分配数据
  43. if (!$result) return json_send(['code' => 'error', 'msg' => '暂无数据']);
  44. // 加载模板
  45. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  46. }
  47. /**
  48. * 详情
  49. * @author 唐远望
  50. * @version 1.0
  51. * @date 2025-12-02
  52. */
  53. public function detail(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  54. {
  55. $request->scene('detail')->validate();
  56. // 接收参数
  57. $id = request('id', 0);
  58. $map = ['id' => $id];
  59. $data = $LowPriceGoodsModel->where($map)->first();
  60. if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  61. // 加载模板
  62. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
  63. }
  64. /**
  65. * 添加
  66. * @author 唐远望
  67. * @version 1.0
  68. * @date 2025-12-02
  69. *
  70. */
  71. public function add(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  72. {
  73. $request->scene('add')->validate();
  74. // 接收数据
  75. $all_data = request()->all();
  76. $store_scope = request('store_scope', '');
  77. $all_data['store_scope'] = $store_scope;
  78. //查询是否存在
  79. $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs']];
  80. $data = $LowPriceGoodsModel->where($map)->first();
  81. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  82. // 写入数据表
  83. $result = $LowPriceGoodsModel->addLowProduct($all_data);
  84. // 如果操作失败
  85. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  86. // 告知结果
  87. return json_send(['code' => 'success', 'msg' => '新增成功']);
  88. }
  89. /**
  90. * 修改
  91. * @author 唐远望
  92. * @version 1.0
  93. * @date 2025-12-02
  94. *
  95. */
  96. public function edit(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  97. {
  98. $request->scene('edit')->validate();
  99. // 接收参数
  100. $id = request('id', 0);
  101. // 接收数据
  102. $all_data = request()->all();
  103. $store_scope = request('store_scope','');
  104. $all_data['store_scope'] = $store_scope;
  105. //查询是否存在
  106. $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs']];
  107. $data = $LowPriceGoodsModel->where($map)->where('id', '!=', $id)->first();
  108. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  109. // 更新数据表
  110. $where = ['id' => $id];
  111. $result = $LowPriceGoodsModel->updateLowProduct($where, $all_data);
  112. // 如果操作失败
  113. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  114. // 告知结果
  115. return json_send(['code' => 'success', 'msg' => '修改成功']);
  116. }
  117. /**
  118. * 修改状态
  119. * @author 唐远望
  120. * @version 1.0
  121. * @date 2025-12-02
  122. *
  123. */
  124. public function set_status(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  125. {
  126. // 验证参数
  127. $request->scene('set_status')->validate();
  128. // 接收数据
  129. $id = request('id', 0);
  130. $status = request('status', 0);
  131. // 查询用户
  132. $where = ['id' => $id];
  133. // 执行修改
  134. $result = $LowPriceGoodsModel->changeStatus($where, $status);
  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 delete(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  148. {
  149. // 验证参数
  150. $request->scene('delete')->validate();
  151. // 接收数据
  152. $id = request('id', 0);
  153. // 查询用户
  154. $where = ['id' => $id];
  155. // 执行删除
  156. $result = $LowPriceGoodsModel->deleteLowProduct($where);
  157. // 提示删除失败
  158. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  159. // 告知结果
  160. return json_send(['code' => 'success', 'msg' => '删除成功']);
  161. }
  162. }