auth->id; $model = new HotelModel(); $info = $model->getDetail( params: ['user_id' => $user_id], select: ['id','invite_id','user_id','name','image','images','back_rate','address'] ); if (!$info){ return $this->error('未开通门店'); } // 待核销金额 $wait_use = Db::name('bill')->where(['shop_id'=>$info['id'],'table_name'=>'hotel_order','status'=>2])->field('sum(total_amount - back_amount) as money')->find(); // 已核销 $used = Db::name('bill')->where(['shop_id'=>$info['id'],'table_name'=>'hotel_order','status'=>3])->field('sum(total_amount - back_amount) as money')->find(); // 已退款 $refund = Db::name('bill')->where(['shop_id'=>$info['id'],'table_name'=>'hotel_order','status'=>4])->field('sum(total_amount - back_amount) as money')->find(); $statistics = [ 'wait_use' => $wait_use['money'] ?? 0, 'used' => $used['money'] ?? 0, 'refund' => $refund['money'] ?? 0, ]; return $this->success('success',[ 'info' => $info, 'statistics' => $statistics ]); } // 交易统计 public function statistics() { $params = $this->request->param(); $user_id = $this->auth->id; if (empty($params['type'])){ $params['type'] = 1; } $model = new HotelModel(); $info = $model->getDetail( params: ['user_id' => $user_id], select: ['id','invite_id','user_id','name','image','images','back_rate','address'] ); if (!$info){ return $this->error('未开通门店'); } switch ($params['type']){ case 1: // 今天 $createtimeBetween = [ strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59')), ]; break; case 2: // 昨天 $createtimeBetween = [ strtotime(date('Y-m-d 00:00:00', strtotime('-1 day'))), strtotime(date('Y-m-d 23:59:59', strtotime('-1 day'))), ]; break; case 3: // 本月 $createtimeBetween = [ strtotime(date('Y-m-01 00:00:00')), strtotime(date('Y-m-d 23:59:59')), ]; break; default: $createtimeBetween = [ strtotime(date('Y-m-d 00:00:00'),strtotime($params['date'])), strtotime(date('Y-m-d 23:59:59'),strtotime($params['date'])), ]; break; } $wait_use = Db::name('bill') ->where(['shop_id'=>$info['id'],'table_name'=>'hotel_order']) ->whereIn('status',[1,2,3]) ->whereBetween('createtime',$createtimeBetween) ->field('sum(total_amount - back_amount) as money,count(id) as num') ->find(); return $this->success('success',[ 'money' => $wait_use['money'] ?? 0, 'num' => $used['num'] ?? 0, ]); } // 趋势图 public function trend() { $user_id = $this->auth->id; $model = new HotelModel(); $info = $model->getDetail( params: ['user_id' => $user_id], select: ['id','invite_id','user_id','name','image','images','back_rate','address'] ); if (!$info){ return $this->error('未开通门店'); } // 七日数据走势统计 $createtimeBetween = [ strtotime(date('Y-m-d 00:00:00', strtotime('-6 day'))), strtotime(date('Y-m-d 23:59:59')), ]; $dates = []; for ($i = 6; $i >= 0; $i--){ $dates[] = date('Y-m-d', strtotime('-'.$i.' day')); } $wait_use = Db::name('bill') ->field('DATE(FROM_UNIXTIME(createtime)) as order_date,sum(total_amount - back_amount) as money,count(id) as num') ->where(['shop_id'=>$info['id'],'table_name'=>'hotel_order']) ->whereIn('status',[1,2,3]) ->whereBetween('createtime',$createtimeBetween) ->group('order_date') ->order('order_date','asc') ->select(); $num = []; $money = []; foreach ($dates as $key=>$date){ $num[$key] = 0; $money[$key] = '0'; foreach ($wait_use as $k=>$v){ if ($date == $v['order_date']){ $num[$key] = $v['num']; $money[$key] = $v['money']; } } $dates[$key] = date('m/d',strtotime($date)); } return $this->success('success',[ 'money' => $money, 'num' => $num, 'dates' => $dates ]); } }