LowPriceGoods.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace App\Http\Controllers\Api\WashConfig;
  3. use App\Http\Controllers\Api\Api;
  4. use App\Http\Requests\Manager\WashConfig\LowPriceGoods as Request;
  5. use App\Models\Manager\WashConfig\LowPriceGoods as LowPriceGoodsModel;
  6. use Illuminate\Support\Facades\DB;
  7. /**
  8. * 数据清洗-低价产品配置
  9. * @author 唐远望
  10. * @version 1.0
  11. * @date 2025-12-02
  12. */
  13. class LowPriceGoods extends Api
  14. {
  15. /**
  16. * 商品列表
  17. * @author 唐远望
  18. * @version 1.0
  19. * @date 2025-12-02
  20. *
  21. */
  22. public function list(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  23. {
  24. $user_info = $this->checkLogin();
  25. if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']);
  26. $request->scene('list')->validate();
  27. // 查询条件
  28. $map = [];
  29. $limit = request('limit', config('page_num', 10));
  30. $status = request('status', '0');
  31. $start_time = request('start_time', '');
  32. $end_time = request('end_time', '');
  33. $product_name = request('product_name', '');
  34. $platform = request('platform', '');
  35. $store_scope = request('store_scope', '');
  36. $company_scope = request('company_scope', '');
  37. // 时间条件
  38. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  39. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  40. // 其他条件
  41. if (is_numeric($status)) $map[] = ['status', '=', $status];
  42. if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
  43. if ($platform) $map[] = ['platform', 'like', "%$platform%"];
  44. if ($store_scope) $map[] = ['store_scope', '=', $store_scope];
  45. if ($company_scope) $map[] = ['company_scope', '=', $company_scope];
  46. // 查询数据
  47. $result = $LowPriceGoodsModel->query()
  48. ->where($map)
  49. ->orderByDesc('id')
  50. ->select([
  51. DB::raw('MAX(id) as id'), // 使用 MAX 聚合函数获取最新的 id
  52. 'product_name'
  53. ])
  54. ->groupBy('product_name')
  55. ->paginate($limit);
  56. // 分配数据
  57. if (!$result) return json_send(['code' => 'error', 'msg' => '暂无数据']);
  58. // 加载模板
  59. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  60. }
  61. /**
  62. * 规格列表
  63. * @author 唐远望
  64. * @version 1.0
  65. * @date 2025-12-15
  66. *
  67. */
  68. public function spec_list(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  69. {
  70. $user_info = $this->checkLogin();
  71. if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']);
  72. $request->scene('spec_list')->validate();
  73. // 查询条件
  74. $map = [];
  75. $limit = request('limit', config('page_num', 10));
  76. $status = request('status', '0');
  77. $start_time = request('start_time', '');
  78. $end_time = request('end_time', '');
  79. $product_specs = request('product_specs', '');
  80. $platform = request('platform', '');
  81. $store_scope = request('store_scope', '');
  82. $company_scope = request('company_scope', '');
  83. // 时间条件
  84. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  85. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  86. // 其他条件
  87. if (is_numeric($status)) $map[] = ['status', '=', $status];
  88. if ($product_specs) $map[] = ['product_specs', 'like', "%$product_specs%"];
  89. if ($platform) $map[] = ['platform', 'like', "%$platform%"];
  90. if ($store_scope) $map[] = ['store_scope', '=', $store_scope];
  91. if ($company_scope) $map[] = ['company_scope', '=', $company_scope];
  92. // 查询数据
  93. $result = $LowPriceGoodsModel->query()
  94. ->where($map)
  95. ->orderByDesc('id')
  96. ->select([
  97. DB::raw('MAX(id) as id'), // 使用 MAX 聚合函数获取最新的 id
  98. 'product_specs'
  99. ])
  100. ->groupBy('product_specs')
  101. ->paginate($limit);
  102. // 分配数据
  103. if (!$result) return json_send(['code' => 'error', 'msg' => '暂无数据']);
  104. // 加载模板
  105. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  106. }
  107. }