OrderService.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\extra\service\saas;
  3. use app\extra\basic\Service;
  4. use app\model\saas\SaasOrder;
  5. use app\model\saas\SaasOrderQrcode;
  6. use app\model\saas\SaasUserBuy;
  7. class OrderService extends Service
  8. {
  9. /**
  10. * 列表
  11. * @param array $param
  12. */
  13. public function getList(array $param = [])
  14. {
  15. $this->mode = new SaasOrder();
  16. return $this->searchVal($param,$this->searchFilter($param))->field("*")->with(['detail','shop' => function($query){
  17. $query->field("shop_id,shop_name");
  18. }])->paginate([
  19. "list_rows" => $param['pageSize'],
  20. "page" => $param['page']
  21. ]);
  22. }
  23. public function getTotal(array $param = []): array
  24. {
  25. $this->mode = new SaasOrder();
  26. $total = ['t0' => 0, 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 't6' => 0, 'ta' => 0];
  27. $where = [];
  28. if (!empty($param['shop'])) {
  29. $where[] = ['shop_id','=',$param['shop']];
  30. }
  31. $where[] = ['status',">",0];
  32. foreach ($this->searchVal($param,$where)->field('create_at,status,count(1) total')->group('status,create_at')->cursor() as $vo)
  33. {
  34. [$total["t{$vo['status']}"] += $vo['total'], $total['ta'] += $vo['total']];
  35. }
  36. return $total;
  37. }
  38. /**
  39. * 手机端
  40. * @param array $param
  41. * @return int[]
  42. */
  43. public function getTotalDate(array $param = []): array
  44. {
  45. $this->mode = new SaasOrder();
  46. $commonFilter = [];
  47. $filter = $this->searchFilter($param);
  48. // 起止时间
  49. if (!empty($param['create'])) {
  50. $times = between_time($param['create']);
  51. $start = date('Y-m-d',$times['start_time']);
  52. $end = date('Y-m-d',($times['end_time'] + 86400));
  53. $commonFilter[] = ['create_at', '>=', $start ];
  54. $commonFilter[] = ['create_at', '<', $end ];
  55. }
  56. $filter = array_merge($filter,$commonFilter);
  57. $total = ['ta' => 0,'t0' => 0, 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 't6' => 0, 'tm' => 0, 'p1' => 0, 'p2' => 0, 'p1m' => 0, 'p2m' => 0];
  58. foreach ($this->mode->where($filter)->whereIn("status",[1,2,3])->field('create_at,pay_type,status,sum(discount) as money,count(1) as total')->group('status,create_at,pay_type')->cursor() as $vo)
  59. {
  60. $total["t{$vo['status']}"] += $vo['total'];
  61. $total['ta'] += $vo['total'];
  62. $total['tm'] += $vo['money'];
  63. if ($vo['pay_type'] == 1) {
  64. $total["p1"] += $vo['total'];
  65. $total["p1m"] += $vo['money'];
  66. }
  67. if ($vo['pay_type'] == 2) {
  68. $total["p2"] += $vo['total'];
  69. $total["p2m"] += $vo['money'];
  70. }
  71. }
  72. $filter[] = ['status','=',1];
  73. $qrcode = (new SaasOrderQrcode)->where($filter)->field("sum(money) as money,count(1) as total")->find();
  74. $card = (new SaasUserBuy)->where($filter)->field("sum(money) as money,count(1) as total")->find();
  75. return compact("total",'qrcode','card');
  76. }
  77. public function getTotalToday(array $param = []): array
  78. {
  79. $this->mode = new SaasOrder();
  80. $total = ['ta' => 0,'t0' => 0, 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 't6' => 0, 'tm' => 0, 'p1' => 0, 'p2' => 0, 'p1m' => 0, 'p2m' => 0];
  81. $where = [];
  82. if (!empty($param['shop'])) {
  83. $where[] = ['shop_id','=',$param['shop']];
  84. }
  85. foreach ($this->mode->whereDay("create_at")->where($where)->whereIn("status",[1,2,3])->field('create_at,pay_type,status,sum(discount) as money,count(1) as total')->group('status,create_at,pay_type')->cursor() as $vo)
  86. {
  87. $total["t{$vo['status']}"] += $vo['total'];
  88. $total['ta'] += $vo['total'];
  89. $total['tm'] += $vo['money'];
  90. if ($vo['pay_type'] == 1) {
  91. $total["p1"] += $vo['total'];
  92. $total["p1m"] += $vo['money'];
  93. }
  94. if ($vo['pay_type'] == 2) {
  95. $total["p2"] += $vo['total'];
  96. $total["p2m"] += $vo['money'];
  97. }
  98. }
  99. return $total;
  100. }
  101. protected function searchFilter(array $param = []): array
  102. {
  103. $filter = [];
  104. !empty($param['status']) && $filter[] = ["status", '=', ($param['status']-1)];
  105. !empty($param['statusGt']) && $filter[] = ["status", '>', ($param['statusGt']-1)];
  106. !empty($param['orderid']) && $filter[] = ["order_sn", 'like', "%{$param['orderid']}%"];
  107. !empty($param['shop']) && $filter[] = ["shop_id", '=', $param['shop']];
  108. return $filter;
  109. }
  110. }