| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace app\extra\service\saas;
- use app\extra\basic\Service;
- use app\model\saas\SaasOrder;
- use app\model\saas\SaasOrderQrcode;
- use app\model\saas\SaasUserBuy;
- class OrderService extends Service
- {
- /**
- * 列表
- * @param array $param
- */
- public function getList(array $param = [])
- {
- $this->mode = new SaasOrder();
- return $this->searchVal($param,$this->searchFilter($param))->field("*")->with(['detail','shop' => function($query){
- $query->field("shop_id,shop_name");
- }])->paginate([
- "list_rows" => $param['pageSize'],
- "page" => $param['page']
- ]);
- }
- public function getTotal(array $param = []): array
- {
- $this->mode = new SaasOrder();
- $total = ['t0' => 0, 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 't6' => 0, 'ta' => 0];
- $where = [];
- if (!empty($param['shop'])) {
- $where[] = ['shop_id','=',$param['shop']];
- }
- $where[] = ['status',">",0];
- foreach ($this->searchVal($param,$where)->field('create_at,status,count(1) total')->group('status,create_at')->cursor() as $vo)
- {
- [$total["t{$vo['status']}"] += $vo['total'], $total['ta'] += $vo['total']];
- }
- return $total;
- }
- /**
- * 手机端
- * @param array $param
- * @return int[]
- */
- public function getTotalDate(array $param = []): array
- {
- $this->mode = new SaasOrder();
- $commonFilter = [];
- $filter = $this->searchFilter($param);
- // 起止时间
- if (!empty($param['create'])) {
- $times = between_time($param['create']);
- $start = date('Y-m-d',$times['start_time']);
- $end = date('Y-m-d',($times['end_time'] + 86400));
- $commonFilter[] = ['create_at', '>=', $start ];
- $commonFilter[] = ['create_at', '<', $end ];
- }
- $filter = array_merge($filter,$commonFilter);
- $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];
- 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)
- {
- $total["t{$vo['status']}"] += $vo['total'];
- $total['ta'] += $vo['total'];
- $total['tm'] += $vo['money'];
- if ($vo['pay_type'] == 1) {
- $total["p1"] += $vo['total'];
- $total["p1m"] += $vo['money'];
- }
- if ($vo['pay_type'] == 2) {
- $total["p2"] += $vo['total'];
- $total["p2m"] += $vo['money'];
- }
- }
- $filter[] = ['status','=',1];
- $qrcode = (new SaasOrderQrcode)->where($filter)->field("sum(money) as money,count(1) as total")->find();
- $card = (new SaasUserBuy)->where($filter)->field("sum(money) as money,count(1) as total")->find();
- return compact("total",'qrcode','card');
- }
- public function getTotalToday(array $param = []): array
- {
- $this->mode = new SaasOrder();
- $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];
- $where = [];
- if (!empty($param['shop'])) {
- $where[] = ['shop_id','=',$param['shop']];
- }
- 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)
- {
- $total["t{$vo['status']}"] += $vo['total'];
- $total['ta'] += $vo['total'];
- $total['tm'] += $vo['money'];
- if ($vo['pay_type'] == 1) {
- $total["p1"] += $vo['total'];
- $total["p1m"] += $vo['money'];
- }
- if ($vo['pay_type'] == 2) {
- $total["p2"] += $vo['total'];
- $total["p2m"] += $vo['money'];
- }
- }
- return $total;
- }
- protected function searchFilter(array $param = []): array
- {
- $filter = [];
- !empty($param['status']) && $filter[] = ["status", '=', ($param['status']-1)];
- !empty($param['statusGt']) && $filter[] = ["status", '>', ($param['statusGt']-1)];
- !empty($param['orderid']) && $filter[] = ["order_sn", 'like', "%{$param['orderid']}%"];
- !empty($param['shop']) && $filter[] = ["shop_id", '=', $param['shop']];
- return $filter;
- }
- }
|