You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
5.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Constants\v3\Goods as GoodsConstants;
  4. use App\Model\v3\GoodsActivity;
  5. use App\Model\v3\Store;
  6. use App\Service\v3\Interfaces\ActivityServiceInterface;
  7. use Hyperf\Redis\Redis;
  8. use Hyperf\Utils\ApplicationContext;
  9. class ActivityService implements ActivityServiceInterface
  10. {
  11. public function do()
  12. {
  13. // TODO: Implement do() method.
  14. }
  15. public function check()
  16. {
  17. // TODO: Implement check() method.
  18. }
  19. public function undo()
  20. {
  21. // TODO: Implement undo() method.
  22. }
  23. public function allForAppletIndex($type, $marketId)
  24. {
  25. $storeTable = ApplicationContext::getContainer()->get(Store::class)->getTable();
  26. $goodsTable = ApplicationContext::getContainer()->get(GoodsActivity::class)->getTable();
  27. $builder = GoodsActivity::query()
  28. ->join($storeTable, ''.$storeTable.'.id', '=', ''.$goodsTable.'.store_id')
  29. ->with(['store'])
  30. ->where([''.$goodsTable.'.type' => $type])
  31. ->where(function ($query) use ($marketId, $goodsTable) {
  32. $query->whereJsonContains(''.$goodsTable.'.market_ids', [(string)$marketId])
  33. ->orWhereJsonLength(''.$goodsTable.'.market_ids', '=', 0);
  34. })
  35. ->where([''.$goodsTable.'.on_sale' => GoodsConstants::ON_SALE_YES])
  36. // ->where(function ($query) use ($goodsTable) {
  37. // $query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1);
  38. // })
  39. ->whereRaw(''.$goodsTable.'.deleted_at IS NULL')
  40. ->where([''.$storeTable.'.market_id' => $marketId])
  41. ->where([''.$storeTable.'.is_open' => \App\Constants\v3\Store::IS_OPEN_YES])
  42. ->where([''.$storeTable.'.is_rest' => \App\Constants\v3\Store::IS_REST_NO])
  43. ->where('time1', '<=', date('H:i'))
  44. ->where(function ($query) {
  45. $query->where('time2', '>=', date('H:i'))
  46. ->orWhere('time4', '>=', date('H:i'));
  47. })
  48. ->where(''.$goodsTable.'.expire_time', '>', time());
  49. return $builder->select(''.$goodsTable.'.*')->addSelect(''.$goodsTable.'.sales as total_sales')
  50. ->orderBy(''.$goodsTable.'.sort', 'DESC')
  51. ->orderBy(''.$goodsTable.'.expire_time', 'ASC')
  52. ->orderBy(''.$goodsTable.'.created_at', 'DESC')
  53. ->get()->toArray();
  54. }
  55. public function allSpecialForAppletIndex($marketId)
  56. {
  57. $activity = [
  58. 'type' => '',
  59. 'settings' => '',
  60. 'goods' => []
  61. ];
  62. $redis = ApplicationContext::getContainer()->get(Redis::class);
  63. $activitySettings = $redis->hGetAll('activity_type_setting');
  64. $activity['type'] = $type = $activitySettings['index_activity_type'];
  65. $activity['settings'] = json_decode($activitySettings[$activitySettings['index_activity_type']], true);
  66. $storeTable = ApplicationContext::getContainer()->get(Store::class)->getTable();
  67. $goodsTable = ApplicationContext::getContainer()->get(GoodsActivity::class)->getTable();
  68. $builder = GoodsActivity::query()
  69. ->join($storeTable, ''.$storeTable.'.id', '=', ''.$goodsTable.'.store_id')
  70. ->with(['store'])
  71. ->where([''.$goodsTable.'.type' => $type])
  72. ->where(function ($query) use ($marketId, $goodsTable) {
  73. $query->whereJsonContains(''.$goodsTable.'.market_ids', [(string)$marketId])
  74. ->orWhereJsonLength(''.$goodsTable.'.market_ids', '=', 0);
  75. })
  76. ->where([''.$goodsTable.'.on_sale' => GoodsConstants::ON_SALE_YES])
  77. // ->where(function ($query) use ($goodsTable) {
  78. // $query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1);
  79. // })
  80. ->whereRaw(''.$goodsTable.'.deleted_at IS NULL')
  81. ->where([''.$storeTable.'.market_id' => $marketId])
  82. ->where([''.$storeTable.'.is_open' => \App\Constants\v3\Store::IS_OPEN_YES])
  83. ->where([''.$storeTable.'.is_rest' => \App\Constants\v3\Store::IS_REST_NO])
  84. ->where('time1', '<=', date('H:i'))
  85. ->where(function ($query) {
  86. $query->where('time2', '>=', date('H:i'))
  87. ->orWhere('time4', '>=', date('H:i'));
  88. })
  89. ->where(''.$goodsTable.'.expire_time', '>', time());
  90. $builder = $builder->select(''.$goodsTable.'.*')->addSelect(''.$goodsTable.'.sales as total_sales')
  91. ->orderBy(''.$goodsTable.'.sort', 'DESC')
  92. ->orderBy(''.$goodsTable.'.expire_time', 'ASC')
  93. ->orderBy(''.$goodsTable.'.created_at', 'DESC');
  94. if (isset($activity['settings']['index_num_limit'])&&!empty($activity['settings']['index_num_limit'])) {
  95. $builder = $builder->limit($activity['settings']['index_num_limit']);
  96. }
  97. $activity['goods'] = $builder->get()->toArray();
  98. return $activity;
  99. }
  100. }