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.

102 lines
3.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
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\Constants\v3\Store as StoreConstants;
  5. use App\Model\v3\Market;
  6. use App\Model\v3\Store;
  7. use App\Model\v3\Goods;
  8. use App\Service\v3\Interfaces\StoreServiceInterface;
  9. use Hyperf\Utils\ApplicationContext;
  10. class StoreService implements StoreServiceInterface
  11. {
  12. public function do()
  13. {
  14. // TODO: Implement do() method.
  15. }
  16. public function check($storeId)
  17. {
  18. $store = Store::query()->where([
  19. ['id','=',$storeId],
  20. ['is_rest','=',0],
  21. ['status','=',2]
  22. ])
  23. ->select('time1','time2','time3','time4')
  24. ->first();
  25. if(!empty($store)){
  26. $nowTime = time();
  27. $startTime = strtotime(($store->time1));
  28. if(!empty($store->time3) && !empty($store->time4)){
  29. $time4 = strtotime(($store->time4));
  30. $endTime = $time4;
  31. }else{
  32. $time2 = strtotime(($store->time2));
  33. $endTime = $time2;
  34. }
  35. if($nowTime > $startTime && $nowTime < $endTime){
  36. return true;
  37. }
  38. }
  39. return false;
  40. }
  41. public function undo()
  42. {
  43. // TODO: Implement undo() method.
  44. }
  45. public function detail($storeId)
  46. {
  47. return Store::query()
  48. ->with('market')
  49. ->where('id',$storeId)
  50. ->first();
  51. }
  52. public function getList($marketId, $page=1, $pagesize=10)
  53. {
  54. $market = Market::query()->withoutGlobalScope('normal')->find($marketId);
  55. $builder = Store::query();
  56. $paginate = $builder->where('market_id',$marketId)->paginate($pagesize);
  57. $stores = $paginate->toArray();
  58. $market->stores = $stores['data'];
  59. return ['has_more_pages' => $paginate->hasMorePages(), 'market' => $market];
  60. }
  61. public function getListByMarketId($marketId, $page=1, $pagesize=10)
  62. {
  63. $storeTable = ApplicationContext::getContainer()->get(Store::class)->getTable();
  64. $goodsTable = ApplicationContext::getContainer()->get(Goods::class)->getTable();
  65. $builder = Store::query()
  66. ->select(''.$storeTable.'.*')
  67. ->join($goodsTable,''.$storeTable.'.id', '=', ''.$goodsTable.'.store_id')
  68. ->where([''.$goodsTable.'.on_sale' => GoodsConstants::ON_SALE_YES])
  69. ->where([''.$goodsTable.'.market_id' => $marketId])
  70. ->where(function ($query) use ($goodsTable) {
  71. $query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1);
  72. })
  73. ->whereRaw(''.$goodsTable.'.deleted_at IS NULL')
  74. ->where([''.$storeTable.'.market_id' => $marketId, ''.$storeTable.'.is_rest' => StoreConstants::IS_REST_NO]);
  75. $paginate = $builder->groupBy(''.$storeTable.'.id')->orderBy($storeTable.'.is_rest','asc')->orderByDesc($storeTable.'.sales')->paginate($pagesize);
  76. $stores = $paginate->map(function ($item, $key) {
  77. $item->goods;
  78. return $item;
  79. })->all();
  80. return ['has_more_pages' => $paginate->hasMorePages(), 'stores' => $stores];
  81. }
  82. public function updateIsRest($storeId)
  83. {
  84. $store = Store::query()->withoutGlobalScope('normal')->find($storeId);
  85. $isRest = $store->is_rest + 1;
  86. $store->is_rest = $isRest % 2;
  87. return $store->save();
  88. }
  89. }