LowPriceGoods.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. // 写入数据表
  77. $result = $LowPriceGoodsModel->addLowProduct($all_data);
  78. // 如果操作失败
  79. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  80. // 告知结果
  81. return json_send(['code' => 'success', 'msg' => '新增成功']);
  82. }
  83. /**
  84. * 修改
  85. * @author 唐远望
  86. * @version 1.0
  87. * @date 2025-12-02
  88. *
  89. */
  90. public function edit(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  91. {
  92. $request->scene('edit')->validate();
  93. // 接收参数
  94. $id = request('id', 0);
  95. // 接收数据
  96. $all_data = request()->all();
  97. // 更新数据表
  98. $where = ['id' => $id];
  99. $result = $LowPriceGoodsModel->updateLowProduct($where, $all_data);
  100. // 如果操作失败
  101. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  102. // 告知结果
  103. return json_send(['code' => 'success', 'msg' => '修改成功']);
  104. }
  105. /**
  106. * 修改状态
  107. * @author 唐远望
  108. * @version 1.0
  109. * @date 2025-12-02
  110. *
  111. */
  112. public function set_status(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  113. {
  114. // 验证参数
  115. $request->scene('set_status')->validate();
  116. // 接收数据
  117. $id = request('id', 0);
  118. $status = request('status', 0);
  119. // 查询用户
  120. $where = ['id' => $id];
  121. // 执行修改
  122. $result = $LowPriceGoodsModel->changeStatus($where, $status);
  123. // 提示新增失败
  124. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  125. // 告知结果
  126. return json_send(['code' => 'success', 'msg' => '设置成功']);
  127. }
  128. /**
  129. * 删除
  130. * @author 唐远望
  131. * @version 1.0
  132. * @date 2025-12-02
  133. *
  134. */
  135. public function delete(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  136. {
  137. // 验证参数
  138. $request->scene('delete')->validate();
  139. // 接收数据
  140. $id = request('id', 0);
  141. // 查询用户
  142. $where = ['id' => $id];
  143. // 执行删除
  144. $result = $LowPriceGoodsModel->deleteLowProduct($where);
  145. // 提示删除失败
  146. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  147. // 告知结果
  148. return json_send(['code' => 'success', 'msg' => '删除成功']);
  149. }
  150. }