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.

93 lines
3.4 KiB

  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Constants\v3\OrderState;
  4. use App\Constants\v3\OrderType;
  5. use App\Constants\v3\SsdbKeys;
  6. use App\Model\v3\Order;
  7. use App\Model\v3\OrderGoods;
  8. use App\Model\v3\OrderMain;
  9. use \App\Service\v3\Interfaces\OrderStatisticsServiceInterface;
  10. use App\TaskWorker\SSDBTask;
  11. use Hyperf\Utils\ApplicationContext;
  12. class OrderStatisticsService implements OrderStatisticsServiceInterface
  13. {
  14. public function do()
  15. {
  16. // TODO: Implement do() method.
  17. }
  18. public function check()
  19. {
  20. // TODO: Implement check() method.
  21. }
  22. public function undo()
  23. {
  24. // TODO: Implement undo() method.
  25. }
  26. public function countOrder($storeId,$type,$startTime = '',$endTime = '')
  27. {
  28. $childTable = ApplicationContext::getContainer()->get(Order::class)->getTable();
  29. $mainTable = ApplicationContext::getContainer()->get(OrderMain::class)->getTable();
  30. $goodsTable = ApplicationContext::getContainer()->get(OrderGoods::class)->getTable();
  31. $builder = OrderMain::query()
  32. ->selectRaw('COUNT(DISTINCT '.$mainTable.'.id) AS count')
  33. ->join($childTable, ''.$childTable.'.order_main_id', '=', ''.$mainTable.'.global_order_id');
  34. if ($type == OrderType::ONLINE) {
  35. $builder = $builder->join($goodsTable, ''.$goodsTable.'.order_id', '=', ''.$childTable.'.id');
  36. }
  37. $builder = $builder->where([''.$childTable.'.store_id' => $storeId, ''.$mainTable.'.type' => $type])
  38. ->where(function ($query) use ($mainTable, $goodsTable, $type) {
  39. $query->where(function ($q) use ($mainTable, $goodsTable, $type) {
  40. $q->whereIn(''.$mainTable.'.state', array_merge(OrderState::FINISH, [OrderState::REFUNDED_DIRECT,OrderState::REFUND_REFUSE]));
  41. if ($type == OrderType::ONLINE) {
  42. $q->whereIn(''.$goodsTable.'.status', [1,2]);
  43. }
  44. })->orWhere(''.$mainTable.'.coupon_money', '>', 0);
  45. });
  46. if ($startTime) {
  47. $builder = $builder->where(''.$mainTable.'.created_at', '>=', $startTime);
  48. }
  49. if ($endTime) {
  50. $builder = $builder->where(''.$mainTable.'.created_at', '<=', $endTime);
  51. }
  52. return $builder->first()->count;
  53. // $builder = Order::join('lanzu_order_main','lanzu_order_main.global_order_id','lanzu_order.order_main_id')
  54. // ->where('lanzu_order.store_id',$storeId);
  55. // if(!empty($startTime) && !empty($endTime)){
  56. // $builder->whereBetween('lanzu_order_main.created_at',[$startTime,$endTime]);
  57. // }
  58. // $count = $builder->whereIn('lanzu_order_main.state', OrderState::FINISH)
  59. // ->where('type',$type)
  60. // ->count();
  61. // return $count;
  62. }
  63. public function setForMarket($marketId)
  64. {
  65. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  66. $incr = $ssdb->exec('incr', SsdbKeys::TODAY_SALES_FOR_MARKET.$marketId);
  67. $expire = strtotime('23:59:59') - time();
  68. $expire = $ssdb->exec('expire', SsdbKeys::TODAY_SALES_FOR_MARKET.$marketId,$expire);
  69. return $incr && $expire;
  70. }
  71. public function getForMarket($marketId)
  72. {
  73. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  74. $count = $ssdb->exec('get', SsdbKeys::TODAY_SALES_FOR_MARKET.$marketId);
  75. return $count;
  76. }
  77. }