ViolationProduct.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Http\Controllers\Api\WashConfig;
  3. use App\Http\Controllers\Api\Api;
  4. use App\Http\Requests\Api\WashConfig\ViolationProduct as Request;
  5. use App\Models\Api\WashConfig\ViolationProduct as ViolationProductModel;
  6. /**
  7. * 数据清洗-违规产品配置
  8. * @author 唐远望
  9. * @version 1.0
  10. * @date 2025-12-03
  11. */
  12. class ViolationProduct extends Api
  13. {
  14. /**
  15. * 商品列表
  16. * @author 唐远望
  17. * @version 1.0
  18. * @date 2025-12-03
  19. *
  20. */
  21. public function list(Request $request, ViolationProductModel $ViolationProductModel)
  22. {
  23. $user_info = $this->checkLogin();
  24. if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']);
  25. $request->scene('list')->validate();
  26. $company_id = $user_info['company_id'];
  27. // 查询条件
  28. $map = [];
  29. $map[] = ['company_id', '=', $company_id];
  30. $limit = request('limit', config('page_num', 10));
  31. $status = request('status', '0');
  32. $start_time = request('start_time', '');
  33. $end_time = request('end_time', '');
  34. $product_name = request('product_name', '');
  35. $platform = request('platform', '');
  36. $store_scope = request('store_scope', '');
  37. $company_scope = request('company_scope', '');
  38. // 时间条件
  39. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  40. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  41. // 其他条件
  42. if (is_numeric($status)) $map[] = ['status', '=', $status];
  43. if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
  44. if ($platform) $map[] = ['platform', 'like', "%$platform%"];
  45. if ($store_scope) $map[] = ['store_scope', '=',$store_scope];
  46. if ($company_scope) $map[] = ['company_scope', '=',$company_scope];
  47. // 查询数据
  48. $result = $ViolationProductModel->query()
  49. ->where($map)
  50. ->orderByDesc('id')
  51. ->select(['id','product_name'])
  52. ->distinct('product_name')
  53. ->paginate($limit);
  54. // 分配数据
  55. if (!$result) return json_send(['code' => 'error', 'msg' => '暂无数据']);
  56. // 加载模板
  57. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  58. }
  59. /**
  60. * 规格列表
  61. * @author 唐远望
  62. * @version 1.0
  63. * @date 2025-12-15
  64. *
  65. */
  66. public function spec_list(Request $request, ViolationProductModel $ViolationProductModel)
  67. {
  68. $user_info = $this->checkLogin();
  69. if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']);
  70. $request->scene('spec_list')->validate();
  71. $company_id = $user_info['company_id'];
  72. // 查询条件
  73. $map = [];
  74. $map[] = ['company_id', '=', $company_id];
  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 = $ViolationProductModel->query()
  94. ->where($map)
  95. ->orderByDesc('id')
  96. ->select(['id','product_specs'])
  97. ->distinct('product_specs')
  98. ->paginate($limit);
  99. // 分配数据
  100. if (!$result) return json_send(['code' => 'error', 'msg' => '暂无数据']);
  101. // 加载模板
  102. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  103. }
  104. }