LowPriceGoods.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. $company_id = $user_info['company_id'];
  28. // 查询条件
  29. $map = [];
  30. $map[] = ['company_id', '=', $company_id];
  31. $limit = request('limit', config('page_num', 10));
  32. $status = request('status', '0');
  33. $start_time = request('start_time', '');
  34. $end_time = request('end_time', '');
  35. $product_name = request('product_name', '');
  36. $platform = request('platform', '');
  37. $store_scope = request('store_scope', '');
  38. $company_scope = request('company_scope', '');
  39. // 时间条件
  40. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  41. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  42. // 其他条件
  43. if (is_numeric($status)) $map[] = ['status', '=', $status];
  44. if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
  45. if ($platform) $map[] = ['platform', 'like', "%$platform%"];
  46. if ($store_scope) $map[] = ['store_scope', '=', $store_scope];
  47. if ($company_scope) $map[] = ['company_scope', '=', $company_scope];
  48. // 查询数据
  49. $result = $LowPriceGoodsModel->query()
  50. ->where($map)
  51. ->orderByDesc('id')
  52. ->select([
  53. DB::raw('MAX(id) as id'), // 使用 MAX 聚合函数获取最新的 id
  54. 'product_name'
  55. ])
  56. ->groupBy('product_name')
  57. ->paginate($limit);
  58. // 分配数据
  59. if (!$result) return json_send(['code' => 'error', 'msg' => '暂无数据']);
  60. // 加载模板
  61. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  62. }
  63. /**
  64. * 规格列表
  65. * @author 唐远望
  66. * @version 1.0
  67. * @date 2025-12-15
  68. *
  69. */
  70. public function spec_list(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  71. {
  72. $user_info = $this->checkLogin();
  73. if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']);
  74. $request->scene('spec_list')->validate();
  75. $company_id = $user_info['company_id'];
  76. // 查询条件
  77. $map = [];
  78. $map[] = ['company_id', '=', $company_id];
  79. $limit = request('limit', config('page_num', 10));
  80. $status = request('status', '0');
  81. $start_time = request('start_time', '');
  82. $end_time = request('end_time', '');
  83. $product_specs = request('product_specs', '');
  84. $platform = request('platform', '');
  85. $store_scope = request('store_scope', '');
  86. $company_scope = request('company_scope', '');
  87. // 时间条件
  88. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  89. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  90. // 其他条件
  91. if (is_numeric($status)) $map[] = ['status', '=', $status];
  92. if ($product_specs) $map[] = ['product_specs', 'like', "%$product_specs%"];
  93. if ($platform) $map[] = ['platform', 'like', "%$platform%"];
  94. if ($store_scope) $map[] = ['store_scope', '=', $store_scope];
  95. if ($company_scope) $map[] = ['company_scope', '=', $company_scope];
  96. // 查询数据
  97. $result = $LowPriceGoodsModel->query()
  98. ->where($map)
  99. ->orderByDesc('id')
  100. ->select([
  101. DB::raw('MAX(id) as id'), // 使用 MAX 聚合函数获取最新的 id
  102. 'product_specs'
  103. ])
  104. ->groupBy('product_specs')
  105. ->paginate($limit);
  106. // 分配数据
  107. if (!$result) return json_send(['code' => 'error', 'msg' => '暂无数据']);
  108. // 加载模板
  109. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  110. }
  111. }