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.

63 lines
2.4 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
  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\Utils\ApplicationContext;
  8. class ActivityService implements ActivityServiceInterface
  9. {
  10. public function do()
  11. {
  12. // TODO: Implement do() method.
  13. }
  14. public function check()
  15. {
  16. // TODO: Implement check() method.
  17. }
  18. public function undo()
  19. {
  20. // TODO: Implement undo() method.
  21. }
  22. public function allForAppletIndex($type, $marketId)
  23. {
  24. $storeTable = ApplicationContext::getContainer()->get(Store::class)->getTable();
  25. $goodsTable = ApplicationContext::getContainer()->get(GoodsActivity::class)->getTable();
  26. $builder = GoodsActivity::query()
  27. ->join($storeTable, ''.$storeTable.'.id', '=', ''.$goodsTable.'.store_id')
  28. ->with(['store'])
  29. ->where([''.$goodsTable.'.type' => $type])
  30. ->where(function ($query) use ($marketId, $goodsTable) {
  31. $query->whereJsonContains(''.$goodsTable.'.market_ids', [(string)$marketId])
  32. ->orWhereJsonLength(''.$goodsTable.'.market_ids', '=', 0);
  33. })
  34. ->where([''.$goodsTable.'.on_sale' => GoodsConstants::ON_SALE_YES])
  35. ->where(function ($query) use ($goodsTable) {
  36. $query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1);
  37. })
  38. ->whereRaw(''.$goodsTable.'.deleted_at IS NULL')
  39. ->where([''.$storeTable.'.market_id' => $marketId])
  40. ->where([''.$storeTable.'.is_open' => \App\Constants\v3\Store::IS_OPEN_YES])
  41. ->where([''.$storeTable.'.is_rest' => \App\Constants\v3\Store::IS_REST_NO])
  42. ->where('time1', '<=', date('H:i'))
  43. ->where(function ($query) {
  44. $query->where('time2', '>=', date('H:i'))
  45. ->orWhere('time4', '>=', date('H:i'));
  46. })
  47. ->where(''.$goodsTable.'.expire_time', '>', time());
  48. return $builder->select(''.$goodsTable.'.*')->addSelect(''.$goodsTable.'.sales as total_sales')
  49. ->orderBy(''.$goodsTable.'.sort', 'DESC')
  50. ->orderBy(''.$goodsTable.'.expire_time', 'ASC')
  51. ->orderBy(''.$goodsTable.'.created_at', 'DESC')
  52. ->get()->toArray();
  53. }
  54. }