where = []; $params = $this->params; if(isset($params['order_status']) && '' != $params['order_status']){ $this->where[] = ['O.order_status','=',$params['order_status']]; } if (isset($params['order_info']) && $params['order_info'] != '') { $this->where[] = ['O.sn','like','%'.$params['order_info'].'%']; } if (isset($params['user_info']) && $params['user_info'] != '') { $this->where[] = ['U.sn|U.nickname|U.account','like','%'.$params['user_info'].'%']; } if (isset($params['goods_info']) && $params['goods_info'] != '') { $orderIds = OrderGoods::where('goods_name','like','%'.$params['goods_info'].'%')->field('order_id')->select()->toArray(); empty($orderIds) && $orderIds = []; $orderIds = array_column($orderIds,'order_id'); $this->where[] = ['O.id','in',implode(',',$orderIds)]; } if (isset($params['pay_status']) && $params['pay_status'] != '') { $this->where[] = ['O.pay_status','=',$params['pay_status']]; } if (isset($params['start_time']) && $params['start_time'] != '') { $timeType = $params['time_type'] ?? 1; switch ($timeType){ case 1: $this->where[] = ['O.create_time','>=',strtotime($params['start_time'])]; break; case 2: $this->where[] = ['O.pay_time','>=',strtotime($params['start_time'])]; break; case 3: $this->where[] = ['O.true_server_finish_time','>=',strtotime($params['start_time'])]; break; } } if (isset($params['end_time']) && $params['end_time'] != '') { $timeType = $params['time_type'] ?? 1; switch ($timeType){ case 1: $this->where[] = ['O.create_time','<=',strtotime($params['end_time'])]; break; case 2: $this->where[] = ['O.pay_time','<=',strtotime($params['end_time'])]; break; case 3: $this->where[] = ['O.true_server_finish_time','<=',strtotime($params['end_time'])]; break; } } if (isset($params['coach_info']) && $params['coach_info'] != '') { $this->where[] = ['C.name|C.sn','like','%'.$params['coach_info'].'%']; } if(isset($params['pay_way']) && $params['pay_way']){ $this->where[] = ['O.pay_way','=',$params['pay_way']]; } if(isset($params['sn']) && $params['sn']){ $this->where[] = ['O.sn','like','%'.$params['sn'].'%']; } return $this->where; } /** * @notes 订单列表 * @return array * @author ljj * @date 2022/2/10 6:19 下午 */ public function lists(): array { self::setWhere(); $lists = Order::alias('O') ->join('user U','O.user_id = U.id') ->join('coach C','O.coach_id = C.id') ->where($this->where) ->order('O.id desc') ->field('O.id,O.shop_id,O.total_order_amount,O.total_refund_amount,O.order_distance,O.pay_status,O.user_id,O.total_amount,O.coach_id,O.sn,O.order_status,O.appoint_time,O.order_amount,O.create_time') ->append(['order_distance_desc','appoint_time','appoint_date','order_status_desc','take_order_btn','depart_btn','dispatch_btn','arrive_btn','server_start_btn','server_finish_btn','refund_btn','cancel_btn','order_cancel_time']) ->limit($this->limitOffset, $this->limitLength) ->select()->toArray(); if(empty($lists)){ return []; } $orderIds = array_column($lists,'id'); $lists = array_column($lists,null,'id'); $orderGoodsLists = OrderGoods::where(['order_id'=>$orderIds])->select()->toArray(); $coachIds = array_column($lists,'coach_id'); $coachLists = Coach::where(['id'=>$coachIds])->column('sn,name,work_photo,shop_id','id'); $shopIds = array_column($lists,'shop_id'); $shopLists = Shop::where(['id'=>$shopIds])->column('sn,name','id'); $userIds = array_column($lists,'user_id'); $userLists = User::where(['id'=>$userIds])->column('id,sn,nickname,mobile,avatar','id'); foreach ($orderGoodsLists as $orderGoodsList){ $orderGoods = $lists[$orderGoodsList['order_id']]['order_goods'] ?? []; $orderGoods[] = $orderGoodsList; $lists[$orderGoodsList['order_id']]['order_goods'] = $orderGoods; } foreach ($lists as $key => $order){ $lists[$key]['coach_info'] = $coachLists[$order['coach_id']] ?? []; $lists[$key]['coach_info']['work_photo'] = FileService::getFileUrl($lists[$key]['coach_info']['work_photo'] ?? ''); $lists[$key]['shop_info'] = $shopLists[$order['shop_id']] ?? []; $lists[$key]['user_info'] = $userLists[$order['user_id']] ?? []; $lists[$key]['user_info']['avatar'] = FileService::getFileUrl($lists[$key]['user_info']['avatar'] ?? ''); if(!isset($order['address_snap']['house_number'])){ $lists[$key]['address_snap']['house_number'] = ''; } } return array_values($lists); } /** * @notes 订单总数 * @return int * @author ljj * @date 2022/2/10 6:19 下午 */ public function count(): int { return Order::alias('O') ->join('user U','O.user_id = U.id') ->join('coach C','O.coach_id = C.id') ->where($this->where) ->count(); } /** * @notes 订单数据统计 * @return array * @author ljj * @date 2022/2/15 11:07 上午 */ public function extend(): array { if(isset($this->where[0]) && 'O.order_status' == $this->where[0][0]){ unset($this->where[0]); $this->where = array_values($this->where); } $lists = Order::alias('O') ->join('user U','O.user_id = U.id') ->join('coach C','O.coach_id = C.id') ->where($this->where) ->field('O.order_status') ->select(); //全部 $data['all_count'] = 0; //待支付 $data['wait_pay_count'] = 0; //待接单 $data['wait_take_count'] = 0; //待出发 $data['wait_depart_count'] = 0; //已出发 $data['depart_count'] = 0; //已到达 $data['arrive_count'] = 0; //服务中 $data['start_server_count'] = 0; //完成服务 $data['finish_server_count'] = 0; //关闭 $data['close_count'] = 0; $data['pay_way'] = PayConfig::field('id,name,pay_way')->select(); $data['order_status'] = OrderEnum::getOrderStatusDesc(); foreach ($lists as $val) { //全部 $data['all_count'] += 1; switch ($val['order_status']){ //待支付 case OrderEnum::ORDER_STATUS_WAIT_PAY: $data['wait_pay_count']++; break; //待接单 case OrderEnum::ORDER_STATUS_WAIT_RECEIVING: $data['wait_take_count']++; break; //待出发 case OrderEnum::ORDER_STATUS_WAIT_DEPART: $data['wait_depart_count']++; break; //已出发 case OrderEnum::ORDER_STATUS_DEPART: $data['depart_count']++; break; //已达到 case OrderEnum::ORDER_STATUS_ARRIVE: $data['arrive_count']++; break; //服务中 case OrderEnum::ORDER_STATUS_START_SERVER: $data['start_server_count']++; break; //完成服务 case OrderEnum::ORDER_STATUS_SERVER_FINISH: $data['finish_server_count']++; break; //服务关闭 case OrderEnum::ORDER_STATUS_CLOSE: $data['close_count']++; break; } } return $data; } }