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.

62 lines
2.2 KiB

  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Constants\v3\OrderState;
  4. use App\Model\v3\Order;
  5. use App\Model\v3\OrderGoods;
  6. use App\Model\v3\OrderMain;
  7. use \App\Service\v3\Interfaces\OrderStatisticsServiceInterface;
  8. use Hyperf\Utils\ApplicationContext;
  9. class OrderStatisticsService implements OrderStatisticsServiceInterface
  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 countOrder($storeId,$type,$startTime = '',$endTime = '')
  24. {
  25. $childTable = ApplicationContext::getContainer()->get(Order::class)->getTable();
  26. $mainTable = ApplicationContext::getContainer()->get(OrderMain::class)->getTable();
  27. $goodsTable = ApplicationContext::getContainer()->get(OrderGoods::class)->getTable();
  28. $builder = OrderMain::query()
  29. ->join($childTable, ''.$childTable.'.order_main_id', '=', ''.$mainTable.'.global_order_id')
  30. ->join($goodsTable, ''.$goodsTable.'.order_id', '=', ''.$childTable.'.id')
  31. ->where([''.$childTable.'.store_id' => $storeId, ''.$mainTable.'.type' => $type])
  32. ->whereIn(''.$mainTable.'.state', array_merge(OrderState::FINISH, [OrderState::REFUNDED,OrderState::REFUND_REFUSE]))
  33. ->whereIn(''.$goodsTable.'.status', [1,2]);
  34. if ($startTime) {
  35. $builder = $builder->where(''.$mainTable.'.created_at', '>=', $startTime);
  36. }
  37. if ($endTime) {
  38. $builder = $builder->where(''.$mainTable.'.created_at', '<=', $endTime);
  39. }
  40. return $builder->groupBy(''.$mainTable.'.id')->count();
  41. // $builder = Order::join('lanzu_order_main','lanzu_order_main.global_order_id','lanzu_order.order_main_id')
  42. // ->where('lanzu_order.store_id',$storeId);
  43. // if(!empty($startTime) && !empty($endTime)){
  44. // $builder->whereBetween('lanzu_order_main.created_at',[$startTime,$endTime]);
  45. // }
  46. // $count = $builder->whereIn('lanzu_order_main.state', OrderState::FINISH)
  47. // ->where('type',$type)
  48. // ->count();
  49. // return $count;
  50. }
  51. }