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.

190 lines
7.1 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\OrderState;
  4. use App\Constants\v3\OrderType;
  5. use App\Model\v3\OrderMain;
  6. use App\Model\v3\Order;
  7. use App\Service\v3\Interfaces\BadgeServiceInterface;
  8. use App\Service\v3\Interfaces\OrderListServiceInterface;
  9. use Hyperf\Di\Annotation\Inject;
  10. use Hyperf\Utils\ApplicationContext;
  11. class OrderListService implements OrderListServiceInterface
  12. {
  13. /**
  14. * @Inject
  15. * @var BadgeServiceInterface
  16. */
  17. protected $badgeService;
  18. public function do()
  19. {
  20. // TODO: Implement do() method.
  21. }
  22. public function check()
  23. {
  24. // TODO: Implement check() method.
  25. }
  26. public function undo()
  27. {
  28. // TODO: Implement undo() method.
  29. }
  30. public function onlineByUser($userId, $tab, $page=1, $pagesize=10)
  31. {
  32. $builder = OrderMain::query()
  33. ->with(['orderGoods', 'market'])
  34. ->where(['user_id' => $userId, 'type' => OrderType::ONLINE]);
  35. switch ($tab) {
  36. case 'all':
  37. break;
  38. case 'finish':
  39. $builder->whereIn('state', OrderState::FINISH);
  40. break;
  41. case 'unpaid':
  42. $builder->where(['state' => OrderState::UNPAID]);
  43. break;
  44. case 'receiving':
  45. $builder->whereIn('state', OrderState::RECEIVING);
  46. break;
  47. case 'refund':
  48. $builder->whereIn('state', OrderState::REFUND);
  49. break;
  50. }
  51. // 清除badge
  52. $this->badgeService->clearUserOrder($userId, $tab);
  53. $paginate = $builder->orderBy('created_at', 'desc')->paginate($pagesize);
  54. $orders = $paginate->toArray();
  55. return ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data']];
  56. }
  57. public function onlineByStore($storeId, $tab, $page=1, $pagesize=10)
  58. {
  59. // $builder = Order::join('lanzu_order_main','lanzu_order.order_main_id','lanzu_order_main.global_order_id')
  60. // ->select(
  61. // 'lanzu_order.*',
  62. // 'lanzu_order_main.state',
  63. // 'lanzu_order_main.address',
  64. // 'lanzu_order_main.name',
  65. // 'lanzu_order_main.delivery_time_note',
  66. // 'lanzu_order_main.shipping_type',
  67. // 'lanzu_order_main.global_order_id',
  68. // 'lanzu_order_main.lat',
  69. // 'lanzu_order_main.lng'
  70. // )
  71. // ->with('orderGoods')
  72. // ->where('lanzu_order.store_id', $storeId)
  73. // ->where('lanzu_order_main.type',1);
  74. $mainTable = ApplicationContext::getContainer()->get(OrderMain::class)->getTable();
  75. $childTable = ApplicationContext::getContainer()->get(Order::class)->getTable();
  76. $builder = Order::query()
  77. ->select(''.$childTable.'.*')
  78. ->join($mainTable, ''.$childTable.'.order_main_id', '=', ''.$mainTable.'.global_order_id')
  79. ->with(['orderMain', 'orderGoods'])
  80. ->where(['store_id' => $storeId, ''.$mainTable.'.type' => OrderType::ONLINE]);
  81. switch ($tab) {
  82. case 'all':
  83. break;
  84. case 'paid':
  85. $builder->where(''.$mainTable.'.state', OrderState::PAID);
  86. break;
  87. case 'delivery':
  88. $builder->where([''.$mainTable.'.state' => OrderState::DELIVERY]);
  89. break;
  90. case 'finish':
  91. $builder->whereIn(''.$mainTable.'.state', OrderState::FINISH);
  92. break;
  93. case 'refund':
  94. $builder->whereIn(''.$mainTable.'.state', OrderState::REFUND);
  95. break;
  96. }
  97. $paginate = $builder->orderBy(''.$mainTable.'.created_at', 'desc')->paginate($pagesize);
  98. $orders = $paginate->toArray();
  99. // $stateTxet = [
  100. // OrderState::UNPAID => '待付款',
  101. // OrderState::PAID => '待接单',
  102. // OrderState::DELIVERY => '待送达',
  103. // OrderState::COMPLETED => '已完成',
  104. // OrderState::EVALUATED => '已评价',
  105. // OrderState::CANCELED => '已取消',
  106. // OrderState::REJECTION => '已拒单',
  107. // OrderState::REFUNDING => '退款中',
  108. // OrderState::REFUNDED => '已退款',
  109. // OrderState::REFUND_REFUSE => '拒绝退款'
  110. // ];
  111. $res = ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data']];
  112. // foreach ($res['orders'] as &$v){
  113. // switch ($v['shipping_type']) {
  114. // case 1:
  115. // $v['delivery_text'] = '服务站配送';
  116. // break;
  117. // case 2:
  118. // $v['delivery_text'] = '达达配送';
  119. // break;
  120. // }
  121. // $v['state_text'] = $stateTxet[$v['state']];
  122. // }
  123. $this->badgeService->clearStoreOrder($storeId, $tab);
  124. return $res;
  125. }
  126. public function offlineByStore($storeId, $page=1, $pagesize=10 ,$start_time = '',$end_time = '')
  127. {
  128. // $builder = Order::join('lanzu_order_main','lanzu_order.order_main_id','lanzu_order_main.global_order_id')
  129. // ->where('store_id', $storeId)
  130. // ->where('lanzu_order_main.type',4)
  131. // ->with('user');
  132. $mainTable = ApplicationContext::getContainer()->get(OrderMain::class)->getTable();
  133. $childTable = ApplicationContext::getContainer()->get(Order::class)->getTable();
  134. $builder = OrderMain::query()
  135. ->select(''.$mainTable.'.*', ''.$childTable.'.order_num')
  136. ->join($childTable, ''.$childTable.'.order_main_id', '=', ''.$mainTable.'.global_order_id')
  137. ->where([''.$childTable.'.store_id' => $storeId, ''.$mainTable.'.type' => OrderType::OFFLINE])
  138. ->with('user');
  139. // if(!empty($start_time) && !empty($end_time)){
  140. // $builder->whereBetween(''.$mainTable.'.created_at',[strtotime($start_time.' 00:00:00'),strtotime($end_time.' 23:59:59')]);
  141. // }
  142. if (!empty($start_time)) {
  143. $builder->where(''.$mainTable.'.created_at', '>=', strtotime($start_time.' 00:00:00'));
  144. }
  145. if (!empty($end_time)) {
  146. $builder->where(''.$mainTable.'.created_at', '<=', strtotime($end_time.' 23:59:59'));
  147. }
  148. $paginate = $builder->orderBy(''.$mainTable.'.created_at', 'desc')->paginate($pagesize);
  149. $orders = $paginate->toArray();
  150. return ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data']];
  151. }
  152. public function offlineByUser($userId, $page=1, $pagesize=10)
  153. {
  154. $builder = OrderMain::query()
  155. ->with(['orders' => function($query) {
  156. $query->with('store');
  157. }])
  158. ->where(['user_id' => $userId, 'type' => OrderType::OFFLINE])
  159. ->whereIn('state', [OrderState::PAID,OrderState::DELIVERY,OrderState::COMPLETED]);
  160. $paginate = $builder->orderBy('created_at', 'desc')->paginate($pagesize);
  161. $orders = $paginate->toArray();
  162. return ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data']];
  163. }
  164. }