CollectData.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace App\Http\Controllers\Manager\Process;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request;
  5. use App\Models\Manager\Process\LowPriceGoods as LowPriceGoodsModel;
  6. use App\Models\Manager\Process\ViolationProduct as ViolationProductModel;
  7. use App\Models\Manager\Process\ViolationStore as ViolationStoreModel;
  8. /**
  9. * 清洗后的数据处理
  10. * @author 唐远望
  11. * @version 1.0
  12. * @date 2026-04-29
  13. */
  14. class CollectData extends Controller
  15. {
  16. /**
  17. * 低价商品清洗数据回填
  18. * @author: 唐远望
  19. * @version: 1.0
  20. * @date: 2026-04-29
  21. */
  22. public function low_price_product_collect_data(LowPriceGoodsModel $LowPriceGoodsModel)
  23. {
  24. //获取非导入的低价商品清洗数据
  25. $map = [];
  26. $map[] = ['process_lowprice_product.source_id', '!=', '0'];
  27. $map[] = ['process_lowprice_product.collection_time', '==', '0'];
  28. $map[] = ['scrape_data.insert_time', '!=', 'null'];
  29. $limit = '10000';
  30. $result = $LowPriceGoodsModel->leftjoin('scrape_data', 'scrape_data.id', '=', 'process_lowprice_product.source_id')
  31. ->where($map)->select(['process_lowprice_product.id', 'scrape_data.insert_time as collect_collection_time'])
  32. ->orderByDesc('id')->paginate($limit)->toarray();
  33. if (!empty($result['data'])) {
  34. foreach ($result['data'] as $key => $value) {
  35. if (empty($value['collect_collection_time'])) {
  36. continue;
  37. }
  38. $update_data['collection_time'] = strtotime($value['collect_collection_time']);
  39. $LowPriceGoodsModel->where('id', $value['id'])->update($update_data);
  40. }
  41. }
  42. return json_send(['code' => 'success', 'msg' => '执行成功', 'data' => count($result['data'])]);
  43. }
  44. /**
  45. * 禁止商品清洗数据回填
  46. * @author: 唐远望
  47. * @version: 1.0
  48. * @date: 2026-04-29
  49. */
  50. public function violation_product_collect_data(ViolationProductModel $ViolationProductModel)
  51. {
  52. //获取非导入的低价商品清洗数据
  53. $map = [];
  54. $map[] = ['process_violation_product.source_id', '!=', '0'];
  55. $map[] = ['process_violation_product.collection_time', '==', '0'];
  56. $map[] = ['scrape_data.insert_time', '!=', 'null'];
  57. $limit = '10000';
  58. $result = $ViolationProductModel->leftjoin('scrape_data', 'scrape_data.id', '=', 'process_violation_product.source_id')
  59. ->where($map)->select(['process_violation_product.id', 'scrape_data.insert_time as collect_collection_time'])
  60. ->orderByDesc('id')->paginate($limit)->toarray();
  61. if (!empty($result['data'])) {
  62. foreach ($result['data'] as $key => $value) {
  63. if (empty($value['collect_collection_time'])) {
  64. continue;
  65. }
  66. $update_data['collection_time'] = strtotime($value['collect_collection_time']);
  67. $ViolationProductModel->where('id', $value['id'])->update($update_data);
  68. }
  69. }
  70. return json_send(['code' => 'success', 'msg' => '执行成功', 'data' => count($result['data'])]);
  71. }
  72. /**
  73. * 违规店铺清洗数据回填
  74. * @author: 唐远望
  75. * @version: 1.0
  76. * @date: 2026-04-29
  77. */
  78. public function violation_store_collect_data(ViolationStoreModel $ViolationStoreModel)
  79. {
  80. //获取非导入的低价商品清洗数据
  81. $map = [];
  82. $map[] = ['process_violation_store.source_id', '!=', '0'];
  83. $map[] = ['process_violation_store.collection_time', '==', '0'];
  84. $map[] = ['scrape_data.insert_time', '!=', 'null'];
  85. $limit = '10000';
  86. $result = $ViolationStoreModel->leftjoin('scrape_data', 'scrape_data.id', '=', 'process_violation_store.source_id')
  87. ->where($map)->select(['process_violation_store.id', 'scrape_data.insert_time as collect_collection_time'])
  88. ->orderByDesc('id')->paginate($limit)->toarray();
  89. if (!empty($result['data'])) {
  90. foreach ($result['data'] as $key => $value) {
  91. if (empty($value['collect_collection_time'])) {
  92. continue;
  93. }
  94. $update_data['collection_time'] = strtotime($value['collect_collection_time']);
  95. $ViolationStoreModel->where('id', $value['id'])->update($update_data);
  96. }
  97. }
  98. return json_send(['code' => 'success', 'msg' => '执行成功', 'data' => count($result['data'])]);
  99. }
  100. }