626 lines
30 KiB
PHP
626 lines
30 KiB
PHP
<?php
|
|
namespace app\controllers\channel;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Yii;
|
|
use yii\web\Controller;
|
|
use app\models\common\Bill;
|
|
use app\models\common\Statistics;
|
|
use app\models\common\Store;
|
|
use app\models\common\StoreBill;
|
|
use app\models\common\Config;
|
|
use yii\db\Expression;
|
|
use app\models\common\Visit;
|
|
class RecordController extends CommonController{
|
|
private $shop_id;
|
|
public function init(){
|
|
parent::init();
|
|
$this->shop_id=$this->storeId?:Store::getMainStore($this->wqData['uniacid'])['id'];
|
|
$this->shop_id=$this->shop_id?:0;
|
|
$request = Yii::$app->request;
|
|
if($request->isPost){
|
|
if(!$this->shop_id){
|
|
return $this->result(3,'无效的门店,请先添加商店');die;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//数据概况 我的账户
|
|
public function actionGetRecordData(){
|
|
$result=axios_request();
|
|
$uniacid=$this->wqData['uniacid'];
|
|
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
|
|
|
|
//可提现余额
|
|
$money=StoreBill::getMerchantMoney($uniacid,$storeId)['money'];
|
|
|
|
//待结算金额
|
|
$waitMoney=StoreBill::getMerchantMoney($uniacid,$storeId)['waitMoney'];
|
|
|
|
//门店总金额
|
|
$allMoney=StoreBill::getMerchantMoney($uniacid,$storeId)['allMoney'];
|
|
|
|
//已提现金额
|
|
$financeMoney=StoreBill::getMerchantMoney($uniacid,$storeId)['financeMoney'];
|
|
|
|
//累计收入
|
|
$cumulative=StoreBill::getMerchantMoney($uniacid,$storeId)['cumulative'];
|
|
$data=array(
|
|
'money'=>$money?:0.00,
|
|
'waitMoney'=>$waitMoney?:0.00,
|
|
'allMoney'=>$allMoney?:0.00,
|
|
'financeMoney'=>$financeMoney?:0.00,
|
|
'cumulative'=>$cumulative?:0.00
|
|
);
|
|
return $this->result(1,'成功',$data);
|
|
}
|
|
|
|
//实时概况
|
|
public function actionRealRecord(){
|
|
$result=axios_request();
|
|
$uniacid=$this->wqData['uniacid'];
|
|
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
|
|
$startTime=strtotime(date('Y-m-d 00:00:00',strtotime($result['startTime'])));
|
|
$endTime=strtotime(date('Y-m-d 23:59:59',strtotime($result['endTime'])));
|
|
|
|
//总营业额;
|
|
$allMoney=(new \yii\db\Query())
|
|
->select('sum(b.boxMoney+b.deliveryMoney+b.originMoney) allMoney')
|
|
->from('{{%ybwm_bill}} as a')
|
|
->join('LEFT JOIN', '{{%ybwm_takeout_order}} as b', 'b.outTradeNo = a.outTradeNo')
|
|
->where('(a.refundMoney=0 or a.refundMoney is null) AND a.uniacid=:uniacid AND a.storeId=:storeId AND a.statisticsAt>=:startTime AND a.statisticsAt<=:endTime AND a.origin=1',
|
|
['startTime'=>$startTime,'endTime'=>$endTime,':uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->one()['allMoney']?:'0.00';
|
|
//用户实付金额
|
|
$payMoney=(new \yii\db\Query())
|
|
->select(['sum(money)money'])
|
|
->from('{{%ybwm_bill}}')
|
|
->where('(refundMoney=0 or refundMoney is null) AND uniacid=:uniacid AND storeId=:storeId AND statisticsAt>=:startTime AND statisticsAt<=:endTime AND origin=1',
|
|
['startTime'=>$startTime,'endTime'=>$endTime,':uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->one()['money']?:'0.00';
|
|
|
|
//预计收入
|
|
$cumulative=StoreBill::getMerchantMoney($uniacid,$storeId,$startTime,$endTime)['cumulative']?:'0.00';
|
|
//付款人数
|
|
$payNum=Statistics::getPayPeople($uniacid,$storeId,$startTime,$endTime)?:'0';
|
|
//有效订单数
|
|
$orderNum=Statistics::getPayNum($uniacid,$storeId,$startTime,$endTime)?:'0';
|
|
//取消/退款订单
|
|
$refundCount=(new \yii\db\Query())
|
|
->from('{{%ybwm_bill}}')
|
|
->where('uniacid=:uniacid',[':uniacid'=>$uniacid])
|
|
->andWhere(['in','origin',Statistics::origin()])
|
|
->andWhere('statisticsAt>=:startTime and statisticsAt<=:endTime',[':startTime'=>$startTime,':endTime'=>$endTime])
|
|
->andWhere('storeId=:storeId',[':storeId'=>$storeId])
|
|
->andWhere('refundAt>0')
|
|
->count()?:'0';
|
|
$refundMoney=(new \yii\db\Query())
|
|
->select('sum(money)money')
|
|
->from('{{%ybwm_bill}}')
|
|
->where('uniacid=:uniacid',[':uniacid'=>$uniacid])
|
|
->andWhere(['in','origin',Statistics::origin()])
|
|
->andWhere('statisticsAt>=:startTime and statisticsAt<=:endTime',[':startTime'=>$startTime,':endTime'=>$endTime])
|
|
->andWhere('storeId=:storeId',[':storeId'=>$storeId])
|
|
->andWhere('refundAt>0')
|
|
->one()['money']?:'0.00';
|
|
//其他订单
|
|
$otherNum=(new \yii\db\Query())->from('{{%ybwm_bill}}')
|
|
->where(['uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->andWhere(['>=','createdAt',$startTime])
|
|
->andWhere(['<=','createdAt',$endTime])
|
|
->andWhere(['<>','origin',Statistics::origin()])
|
|
->count()?:'0';
|
|
//客单价
|
|
$price=bcdiv($payMoney,$orderNum,2);
|
|
//浏览量
|
|
$visitCount=Statistics::getViews($uniacid,$storeId,$startTime,$endTime);
|
|
$visitTotal=Statistics::getViews($uniacid,$storeId);
|
|
$userCount=Statistics::getVisitCount($uniacid,$storeId,$startTime,$endTime);
|
|
$userTotal=Statistics::getVisitCount($uniacid,$storeId);
|
|
//var_dump(date('Y-m-d 00:00:00',$endTime-14*24*60*60));die;
|
|
$beforeStartTime=strtotime(date('Y-m-d 00:00:00',$endTime-14*24*60*60));
|
|
$beforeEndTime=$endTime;
|
|
|
|
//营业额折线图
|
|
$moneyArr= (new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(statisticsAt,'%Y-%m-%d') as hours,sum(money)money"))
|
|
->from('{{%ybwm_bill}}')
|
|
->where(['deleteAt' => 0,'uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->andWhere('statisticsAt>=:starTime AND statisticsAt<=:endTime',[':starTime'=>$beforeStartTime,':endTime'=>$beforeEndTime])
|
|
->andWhere('refundAt=0 or refundAt is null') ->andWhere(['in','origin',Statistics::origin()])
|
|
->groupBy(new Expression("from_unixtime(statisticsAt,'%Y-%m-%d')"))
|
|
->all();
|
|
$moneyArr=dataByTime($moneyArr,$result['endTime']);
|
|
|
|
|
|
//实付折线图
|
|
$payMoneyArr=(new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(statisticsAt,'%Y-%m-%d') as hours,sum(money)money"))
|
|
->from('{{%ybwm_bill}}')
|
|
->where('(refundMoney=0 or refundMoney is null) AND uniacid=:uniacid AND storeId=:storeId AND statisticsAt>=:startTime AND statisticsAt<=:endTime AND deleteAt=0',
|
|
['startTime'=>$beforeStartTime,'endTime'=>$endTime,':uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->andWhere(['in','origin',Statistics::origin()])
|
|
->groupBy(new Expression("from_unixtime(statisticsAt,'%Y-%m-%d')"))
|
|
->all();
|
|
$payMoneyArr=dataByTime($payMoneyArr,$result['endTime']);
|
|
|
|
//有效订单折线图
|
|
$orderNumArr=(new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(statisticsAt,'%Y-%m-%d') as hours,count(*)money"))
|
|
->from('{{%ybwm_bill}}')
|
|
->where('uniacid=:uniacid',[':uniacid'=>$uniacid])
|
|
->andWhere(['in','origin',Statistics::origin()])
|
|
->andWhere('statisticsAt>=:startTime AND statisticsAt<=:endTime',[':startTime'=>$beforeStartTime,':endTime'=>$endTime])
|
|
->andWhere('storeId=:storeId',['storeId'=>$storeId])
|
|
->andWhere('refundAt=0 or refundAt is null')
|
|
->groupBy(new Expression("from_unixtime(statisticsAt,'%Y-%m-%d')"))
|
|
->all();
|
|
$orderNumArr=dataByTime($orderNumArr,$result['endTime']);
|
|
//付款人数折线图
|
|
$payNumArr=(new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(statisticsAt,'%Y-%m-%d') as hours,count(distinct userId) money"))
|
|
->from('{{%ybwm_bill}}')
|
|
->where('uniacid=:uniacid and storeId=:storeId',[':uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->andWhere(['in','origin',Statistics::origin()])
|
|
->andWhere('refundAt=0 or refundAt is null')
|
|
->andWhere('statisticsAt>=:startTime AND statisticsAt<=:endTime',[':startTime'=>$beforeStartTime,':endTime'=>$endTime])
|
|
->groupBy("hours")
|
|
->all();
|
|
$payNumArr=dataByTime($payNumArr,$result['endTime']);
|
|
|
|
//客单价折线图
|
|
$priceArr=(new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(statisticsAt,'%Y-%m-%d') as hours,convert(sum(money)/count(DISTINCT id),decimal(10,2)) money"))
|
|
->from('{{%ybwm_bill}}')
|
|
->where(['deleteAt' => 0,'uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$beforeStartTime,':endTime'=>$beforeEndTime])
|
|
->andWhere(['in','origin',Statistics::origin()])
|
|
->andWhere('refundAt=0 or refundAt is null')
|
|
->groupBy(new Expression("from_unixtime(createdAt,'%Y-%m-%d')"))
|
|
->all();
|
|
$priceArr=dataByTime($priceArr,$result['endTime']);
|
|
|
|
//浏览量折线图
|
|
$visitArr=(new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(createdAt,'%Y-%m-%d') as hours,count(*)money"))
|
|
->from('{{%ybwm_visit_list}}')
|
|
->where(['uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$beforeStartTime,':endTime'=>$beforeEndTime])
|
|
->groupBy(new Expression("from_unixtime(createdAt,'%Y-%m-%d')"))
|
|
->all();
|
|
$visitArr=dataByTime($visitArr,$result['endTime']);
|
|
//访客数折线图
|
|
$userArr=(new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(createdAt,'%Y-%m-%d') as hours,count(DISTINCT userId)money"))
|
|
->from('{{%ybwm_visit_list}}')
|
|
->where(['uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$beforeStartTime,':endTime'=>$beforeEndTime])
|
|
->groupBy(new Expression("from_unixtime(createdAt,'%Y-%m-%d')"))
|
|
->all();
|
|
$userArr=dataByTime($userArr,$result['endTime']);
|
|
//销量排行榜TOP10
|
|
// $sql='select b.name,sum(a.num)num from ims_ybwm_order_goods a
|
|
//left join ims_ybwm_core_goods b on a.goodsId=b.id
|
|
//where a.uniacid=39 and a.storeId=1
|
|
//and orderId in (select id from ims_ybwm_takeout_order where uniacid=39 and storeId=1 and state in (2,3,4,5,6))
|
|
//GROUP BY name order by num desc limit 0,10';
|
|
$moneyTop=(new \yii\db\Query())
|
|
->select('b.name,sum(a.num)num,(sum(a.num)*(a.money))money')
|
|
->from('{{%ybwm_order_goods}} as a')
|
|
->leftJoin('{{%ybwm_core_goods}} as b','a.goodsId=b.id')
|
|
->leftJoin('{{%ybwm_takeout_order}} as c','a.orderId=c.id')
|
|
->where("a.uniacid=$uniacid AND a.storeId=$storeId")
|
|
->andwhere('a.createdAt>=:startTime AND a.createdAt<=:endTime',['startTime'=>$beforeStartTime,'endTime'=>$beforeEndTime])
|
|
->andWhere(['in','state',[2,3,4,5,6,9]])
|
|
->andWhere(['>','b.id',0])
|
|
->groupBy('a.goodsId')
|
|
->orderBy('num desc')
|
|
->limit(10)
|
|
->all();
|
|
|
|
//dd(ddSql($moneyTop));die;
|
|
$payTop=(new \yii\db\Query())
|
|
->select('b.name,(sum(a.num)*(a.money))money,sum(a.num)num')
|
|
->from('{{%ybwm_order_goods}} as a')
|
|
->leftJoin('{{%ybwm_core_goods}} as b','a.goodsId=b.id')
|
|
->leftJoin('{{%ybwm_takeout_order}} as c','a.orderId=c.id')
|
|
->where("a.uniacid=$uniacid AND a.storeId=$storeId")
|
|
->andwhere('a.createdAt>=:startTime AND a.createdAt<=:endTime',['startTime'=>$beforeStartTime,'endTime'=>$beforeEndTime])
|
|
->andWhere(['in','state',[2,3,4,5,6,9]])
|
|
->andWhere(['>','b.id',0])
|
|
->groupBy('a.goodsId')
|
|
->orderBy('money desc')
|
|
->limit(10)
|
|
->all();
|
|
|
|
$data=array(
|
|
'allMoney'=>$allMoney,//营业额
|
|
'moneyArr'=>$moneyArr,//营业额折线图
|
|
'payMoney'=>$payMoney,//用户实付金额
|
|
'cumulative'=>$cumulative,//预计收入
|
|
'payNum'=>$payNum,//付款人数
|
|
'orderNum'=>$orderNum,//有效订单数
|
|
'refundCount'=>$refundCount,//取消/退款订单
|
|
'refundMoney'=>$refundMoney,//退款金额
|
|
'otherNum'=>$otherNum,//其他订单
|
|
'price'=>$price,//客单价
|
|
'payMoneyArr'=>$payMoneyArr,//用户实付金额折线图
|
|
'orderNumArr'=>$orderNumArr,//有效订单数折线图
|
|
'payNumArr'=>$payNumArr,//付款人数折线图
|
|
'priceArr'=>$priceArr,//客单价折线图
|
|
'visitArr'=>$visitArr, //浏览量折线图
|
|
'userArr'=>$userArr,//访客数折线图
|
|
'visitCount'=>$visitCount, //浏览量
|
|
'visitTotal'=>$visitTotal, //全部浏览量
|
|
'userCount'=>$userCount, //访客数
|
|
'userTotal'=>$userTotal, //全部访客数
|
|
'moneyTop'=>$moneyTop,//销量top10
|
|
'payTop'=>$payTop,//支付金额top10
|
|
);
|
|
return $this->result(1,'成功',$data);
|
|
}
|
|
|
|
//实时分析
|
|
public function actionRealAnalysis(){
|
|
$result=axios_request();
|
|
$uniacid=$this->wqData['uniacid'];
|
|
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
|
|
if($result['timeType']==1&&$result['time']){
|
|
//自然日
|
|
$startTime=strtotime(date('Y-m-d 00:00:00',strtotime($result['time'])));
|
|
$endTime=strtotime(date('Y-m-d 23:59:59',strtotime($result['time'])));
|
|
}elseif($result['timeType']==2){
|
|
//自然月
|
|
$startTime=strtotime(date('Y-m-01 00:00:00',strtotime($result['time'])));
|
|
$day=date('t',strtotime($result['time']));
|
|
$endTime=strtotime(date('Y-m-'.$day. ' 23:59:59',strtotime($result['time'])));
|
|
}else{
|
|
$startTime=strtotime(date('Y-m-d 00:00:00',time()));
|
|
$endTime=strtotime(date('Y-m-d 23:59:59',time()));
|
|
}
|
|
|
|
$yesStartTime=$startTime-24*60*60;
|
|
$yesEndTime=$endTime-24*60*60;
|
|
//浏览量
|
|
$visitCount=Statistics::getViews($uniacid,$storeId,$startTime,$endTime);
|
|
$yesVisitCount=Statistics::getViews($uniacid,$storeId,$yesStartTime,$yesEndTime);
|
|
$visitTotal=Statistics::getViews($uniacid,$storeId);
|
|
//访客数
|
|
$user=Statistics::getVisitCount($uniacid,$storeId,$startTime,$endTime);
|
|
$yesUser=Statistics::getVisitCount($uniacid,$storeId,$yesStartTime,$yesEndTime);
|
|
$UserTotal=Statistics::getVisitCount($uniacid,$storeId);
|
|
|
|
//支付金额
|
|
$todayPayMoney=Statistics::getPayMoney($uniacid,$storeId,$startTime,$endTime);
|
|
$yesPayMoney=Statistics::getPayMoney($uniacid,$storeId,$yesStartTime,$yesEndTime);
|
|
$newPayMoney=$todayPayMoney-$yesPayMoney;
|
|
//支付订单数
|
|
$todayPayNum=Statistics::getPayNum($uniacid,$storeId,$startTime,$endTime);
|
|
$yesPayNum=Statistics::getPayNum($uniacid,$storeId,$yesStartTime,$yesEndTime);
|
|
$newPayNum=$todayPayNum-$yesPayNum;
|
|
//支付人数
|
|
$todayUserCount=Statistics::getPayPeople($uniacid,$storeId,$startTime,$endTime);
|
|
$yesUserCount=Statistics::getPayPeople($uniacid,$storeId,$yesStartTime,$yesEndTime);
|
|
$newUserCount=$todayUserCount-$yesUserCount;
|
|
//客单价
|
|
$todayPrice=Statistics::getUnitPrice($uniacid,$storeId,$startTime,$endTime);
|
|
$yesPrice=Statistics::getUnitPrice($uniacid,$storeId,$yesStartTime,$yesEndTime);
|
|
$newPrice=$todayPrice-$yesPrice;
|
|
//下单转化率
|
|
$todayConver=Statistics::getConversion($uniacid,$storeId,$startTime,$endTime);
|
|
$yesConver=Statistics::getConversion($uniacid,$storeId,$yesStartTime,$yesEndTime);
|
|
$newConver=$todayConver-$yesConver;
|
|
//支付金额折线图
|
|
|
|
$payMoneyArr=(new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(createdAt,'%Y-%m-%d') as hours,sum(money)money"))
|
|
->from('{{%ybwm_bill}}')
|
|
->where(['deleteAt' => 0,'uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->andWhere(['>=','createdAt',$startTime])
|
|
->andWhere(['<','createdAt',$endTime])
|
|
->groupBy(new Expression("from_unixtime(createdAt,'%Y-%m-%d')"))
|
|
->orderBy(new Expression("from_unixtime(createdAt,'%Y-%m-%d')"))
|
|
->all();
|
|
$payMoneyArr=CreatQuery(2,$payMoneyArr,$result['time']);
|
|
//支付订单数折线图
|
|
$countArr= (new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(createdAt,'%Y-%m-%d') as hours,count(DISTINCT userId)money"))
|
|
->from('{{%ybwm_bill}}')
|
|
->where(['deleteAt' => 0,'uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$startTime,':endTime'=>$endTime])
|
|
->groupBy(new Expression("from_unixtime(createdAt,'%Y-%m-%d')"))
|
|
->all();
|
|
$countArr=CreatQuery(2,$countArr,$result['time']);
|
|
|
|
//浏览量折线图
|
|
$visitArr=Visit::visitDataByHours($uniacid,$startTime,$endTime,$result['time'],$storeId);
|
|
//访客数折线图
|
|
$userArr=Visit::visitUserByHours($uniacid,$startTime,$endTime,$result['time'],$storeId);
|
|
$data=array(
|
|
'todayPayMoney'=>$todayPayMoney,
|
|
'newPayMoney'=>$newPayMoney,
|
|
'todayPayNum'=>$todayPayNum,
|
|
'newPayNum'=>$newPayNum,
|
|
'dayUserCount'=>$todayUserCount,
|
|
'newUserCount'=>$newUserCount,
|
|
'todayPrice'=>$todayPrice,
|
|
'newPrice'=>$newPrice,
|
|
'todayConver'=>$todayConver,
|
|
'newConver'=>$newConver,
|
|
'payMoneyArr'=>$payMoneyArr,
|
|
'countArr'=>$countArr,
|
|
'visitCount'=>$visitCount,
|
|
'yesVisitCount'=>$yesVisitCount,
|
|
'visitTotal'=>$visitTotal,
|
|
'userCount'=>$user,
|
|
'yesUserCount'=>$yesUser,
|
|
'UserTotal'=>$UserTotal,
|
|
'visitArr'=>$visitArr,
|
|
'userArr'=>$userArr,
|
|
);
|
|
return $this->result(1,'成功',$data);
|
|
}
|
|
//流量分析
|
|
public function actionRealCover(){
|
|
$result=axios_request();
|
|
$uniacid=$this->wqData['uniacid'];
|
|
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
|
|
$startTime=strtotime(date('Y-m-d 00:00:00',strtotime($result['startTime'])));
|
|
$endTime=strtotime(date('Y-m-d 23:59:59',strtotime($result['endTime'])));
|
|
//dd($startTime);dd($endTime);die;
|
|
$yesStartTime=$startTime-24*60*60;
|
|
$yesEndTime=$endTime-24*60*60;
|
|
//访客数
|
|
$userCount=Statistics::getVisitCount($uniacid,$storeId,$startTime,$endTime);
|
|
$wxUserCount=Statistics::getVisitCount($uniacid,$storeId,$startTime,$endTime,2);
|
|
$yesUserCount=Statistics::getVisitCount($uniacid,$storeId,$yesStartTime,$yesEndTime);
|
|
$newUserCount=$userCount-$yesUserCount;
|
|
|
|
//浏览量
|
|
$visitCount=Statistics::getViews($uniacid,$storeId,$startTime,$endTime);
|
|
$yesVisitCount=Statistics::getViews($uniacid,$storeId,$yesStartTime,$yesEndTime);
|
|
$newVisitCount=$visitCount-$yesVisitCount;
|
|
//有效订单数
|
|
$payNum=Statistics::getPayNum($uniacid,$storeId,$startTime,$endTime);
|
|
$yesPayNum=Statistics::getPayNum($uniacid,$storeId,$yesStartTime,$yesEndTime);
|
|
$newPayNum=$payNum-$yesPayNum;
|
|
//付款人数
|
|
$user=Statistics::getPayPeople($uniacid,$storeId,$startTime,$endTime);
|
|
$yesUser=Statistics::getPayPeople($uniacid,$storeId,$yesStartTime,$yesEndTime);
|
|
$newUser=$user-$yesUser;
|
|
//客单价
|
|
$price=Statistics::getUnitPrice($uniacid,$storeId,$startTime,$endTime);
|
|
$yesPrice=Statistics::getUnitPrice($uniacid,$storeId,$yesStartTime,$yesEndTime);
|
|
$newPrice=$price-$yesPrice;
|
|
//下单转换率
|
|
$convers=Statistics::getConversion($uniacid,$storeId,$startTime,$endTime);
|
|
$yesConvers=Statistics::getConversion($uniacid,$storeId,$yesStartTime,$yesEndTime);
|
|
$newConvers=$convers-$yesConvers;
|
|
//跳失率
|
|
$payLv=bcdiv(bcsub($userCount,$user),$userCount);
|
|
$yesPayLv=bcdiv(bcsub($yesUserCount,$yesUser),$yesUserCount);
|
|
$newPayLv=bcsub($payLv,$yesPayLv);
|
|
//总访客数
|
|
$userTotal=Statistics::getVisitCount($uniacid,$storeId);
|
|
//总浏览数
|
|
$visitTotal=Statistics::getViews($uniacid,$storeId);
|
|
$beforeStartTime=$startTime-14*24*60*60;
|
|
$beforeEndTime=$endTime-14*24*60*60;
|
|
$nextTotal=Statistics::getVisitCount($uniacid,$storeId,$beforeStartTime,$beforeEndTime);
|
|
$nextVisitTotal=Statistics::getViews($uniacid,$storeId,$beforeStartTime,$beforeEndTime);
|
|
//访客数折线图
|
|
|
|
$userCountArr=Visit::visitDataByDay($uniacid,$startTime,$endTime,2,$result['time'],$storeId);
|
|
//dd($userCountArr);die;
|
|
//浏览量折线图
|
|
|
|
$browseArr=Visit::visitUserByDay($uniacid,$startTime,$endTime,2,$result['time'],$storeId);
|
|
$data=array(
|
|
'userCount'=>$userCount,
|
|
'wxUserCount'=>$wxUserCount,
|
|
'newUserCount'=>$newUserCount,
|
|
'visitCount'=>$visitCount,
|
|
'newVisitCount'=>$newVisitCount,
|
|
'payNum'=>$payNum,
|
|
'newPayNum'=>$newPayNum,
|
|
'user'=>$user,
|
|
'newUser'=>$newUser,
|
|
'price'=>$price,
|
|
'newPrice'=>$newPrice,
|
|
'convers'=>$convers,
|
|
'newConvers'=>$newConvers,
|
|
'payLv'=>$payLv,
|
|
'newPayLv'=>$newPayLv,
|
|
'userTotal'=>$userTotal,
|
|
'visitTotal'=>$visitTotal,
|
|
'nextTotal'=>$nextTotal,
|
|
'nextVisitTotal'=>$nextVisitTotal,
|
|
'userCountArr'=>$userCountArr,
|
|
'browseArr'=>$browseArr
|
|
);
|
|
//dd($data);die;
|
|
return $this->result(1,'成功',$data);
|
|
}
|
|
|
|
//交易分析 按选择的自然日自然月
|
|
public function actionRealPay(){
|
|
date_default_timezone_set("PRC");
|
|
$result=axios_request();
|
|
$uniacid=$this->wqData['uniacid'];
|
|
$storeId=$result['storeId']?$result['storeId']:$this->shop_id;
|
|
$startTime=strtotime(date('Y-m-d 00:00:00',strtotime($result['startTime'])));
|
|
$endTime=strtotime(date('Y-m-d 23:59:59',strtotime($result['endTime'])));
|
|
$charStartTime=bcsub($endTime,24*60*60);
|
|
//访客数
|
|
$userCount=Statistics::getVisitCount($uniacid,$storeId,$startTime,$endTime);
|
|
//下单人数
|
|
|
|
$orderUser=Statistics::getPayOrderNum($uniacid,$storeId,$startTime,$endTime);
|
|
//下单金额
|
|
$orderMoney=Statistics::getOrderMoney($uniacid,$storeId,$startTime,$endTime);
|
|
//付款人数
|
|
$payUser=Statistics::getPayPeople($uniacid,$storeId,$startTime,$endTime);
|
|
//支付金额
|
|
$payMoney=Statistics::getPayMoney($uniacid,$storeId,$startTime,$endTime);
|
|
//客单价
|
|
$price=Statistics::getUnitPrice($uniacid,$storeId,$startTime,$endTime);
|
|
//付款人数折线图
|
|
$query=(new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(createdAt,'%Y-%m-%d') as hours,count(DISTINCT(userId))money"))
|
|
->from('{{%ybwm_bill}}')
|
|
->where(['uniacid'=>$uniacid])
|
|
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$charStartTime,':endTime'=>$endTime])
|
|
->andWhere(['in','origin',Statistics::origin()])
|
|
->andWhere('refundMoney=0 or refundMoney is null');
|
|
if($storeId){
|
|
$query->andWhere(['in','storeId',$storeId]);
|
|
}
|
|
$payArr=$query->groupBy(new Expression("from_unixtime(createdAt,'%Y-%m-%d')"))->all();
|
|
|
|
$payArr=dataByTime($payArr,$result['endTime']);
|
|
//支付金额折线图
|
|
$query=(new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(createdAt,'%Y-%m-%d') as hours,sum(money)money"))
|
|
->from('{{%ybwm_bill}}')
|
|
->where(['uniacid'=>$uniacid])
|
|
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$charStartTime,':endTime'=>$endTime])
|
|
->andWhere(['in','origin',Statistics::origin()])
|
|
->andWhere('refundMoney=0 or refundMoney is null');
|
|
if($storeId){
|
|
$query->andWhere(['in','storeId',$storeId]);
|
|
}
|
|
$payMoneyArr=$query->groupBy(new Expression("from_unixtime(createdAt,'%Y-%m-%d')"))->all();
|
|
$payMoneyArr=dataByTime($payMoneyArr,$result['endTime']);
|
|
//-------------订单概况
|
|
//外卖订单
|
|
$outCount=(new \yii\db\Query())
|
|
->from('{{%ybwm_takeout_order}}')
|
|
->where(['uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$startTime,':endTime'=>$endTime])
|
|
->andWhere(['<>','deliveryMode',10])
|
|
->andWhere('refundMoney=0 or refundMoney is null')
|
|
->count();
|
|
//自提订单
|
|
$inCount=(new \yii\db\Query())
|
|
->from('{{%ybwm_takeout_order}}')
|
|
->where(['uniacid'=>$uniacid,'deliveryMode'=>10,'storeId'=>$storeId])
|
|
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$startTime,':endTime'=>$endTime])
|
|
->andWhere('refundMoney=0 or refundMoney is null')
|
|
->count();
|
|
//其他订单
|
|
$otherCount=0;
|
|
//退款总金额
|
|
$refundMoney=Statistics::getrefundMoney($uniacid,$storeId,$startTime,$endTime);
|
|
//外卖折线图
|
|
$outArr=(new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(createdAt,'%Y-%m-%d') as hours,sum(money)money"))
|
|
->from('{{%ybwm_takeout_order}}')
|
|
->where(['uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$charStartTime,':endTime'=>$endTime])
|
|
->andWhere(['<>','deliveryMode',10])
|
|
->andWhere('refundMoney=0 or refundMoney is null')
|
|
->groupBy(new Expression("from_unixtime(createdAt,'%Y-%m-%d')"))
|
|
->all();
|
|
$outArr=dataByTime($outArr,$result['endTime']);
|
|
//自提折线图
|
|
$inArr=(new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(createdAt,'%Y-%m-%d') as hours,sum(money)money"))
|
|
->from('{{%ybwm_takeout_order}}')
|
|
->where(['uniacid'=>$uniacid,'deliveryMode'=>10,'storeId'=>$storeId])
|
|
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$charStartTime,':endTime'=>$endTime])
|
|
->andWhere('refundMoney=0 or refundMoney is null')
|
|
->groupBy(new Expression("from_unixtime(createdAt,'%Y-%m-%d')"))
|
|
->all();
|
|
$inArr=dataByTime($inArr,$result['endTime']);
|
|
//支付分析
|
|
$payFX=(new \yii\db\Query())
|
|
->select("money,payMode")
|
|
->from('{{%ybwm_bill}}')
|
|
->where(['uniacid'=>$uniacid])
|
|
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$startTime,':endTime'=>$endTime])
|
|
->andWhere(['in','origin',Statistics::origin()])
|
|
->andWhere('refundMoney=0 or refundMoney is null')
|
|
->all();
|
|
$wxPayMoney=0;
|
|
$wxPayCount=0;
|
|
$balancePayCount=0;
|
|
$balancePayMoney=0;
|
|
foreach ($payFX as $v){
|
|
if($v['payMode']==1){
|
|
$wxPayCount++;
|
|
$wxPayMoney=bcadd($wxPayMoney,$v['money']);
|
|
}
|
|
if($v['payMode']==5){
|
|
$balancePayCount++;
|
|
$balancePayMoney=bcadd($balancePayMoney,$v['money']);
|
|
}
|
|
}
|
|
//退款概况
|
|
$refundCountArr=(new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(statisticsAt,'%Y-%m-%d') as hours,count(*)money"))
|
|
->from('{{%ybwm_bill}}')
|
|
->where(['uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->andWhere('statisticsAt>=:starTime AND statisticsAt<=:endTime',[':starTime'=>$charStartTime,':endTime'=>$endTime])
|
|
->andWhere('refundMoney>0')
|
|
->groupBy(new Expression("from_unixtime(statisticsAt,'%Y-%m-%d')"))
|
|
->all();
|
|
$refundCountArr=dataByTime($refundCountArr,$result['endTime']);
|
|
$refundArr=(new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(statisticsAt,'%Y-%m-%d') as hours,sum(money)money"))
|
|
->from('{{%ybwm_bill}}')
|
|
->where(['uniacid'=>$uniacid,'storeId'=>$storeId])
|
|
->andWhere('statisticsAt>=:starTime AND statisticsAt<=:endTime',[':starTime'=>$charStartTime,':endTime'=>$endTime])
|
|
->andWhere('refundMoney>0')
|
|
->groupBy(new Expression("from_unixtime(statisticsAt,'%Y-%m-%d')"))
|
|
->all();
|
|
$refundArr=dataByTime($refundArr,$result['endTime']);
|
|
|
|
//退款订单数
|
|
$refundCount=(new \yii\db\Query())
|
|
->from('{{%ybwm_bill}}')
|
|
->where('uniacid=:uniacid',[':uniacid'=>$uniacid])
|
|
->andWhere(['in','origin',Statistics::origin()])
|
|
->andWhere('statisticsAt>=:startTime AND statisticsAt<=:endTime',[':startTime'=>$startTime,':endTime'=>$endTime])
|
|
->andWhere('storeId=:storeId',[':storeId'=>$storeId])
|
|
->andWhere('refundAt>0')
|
|
->count();
|
|
|
|
//历史交易
|
|
$orderList=(new \yii\db\Query())
|
|
->select(new Expression("from_unixtime(createdAt,'%Y-%m-%d') as hours,count(*)count,count(DISTINCT(userId))userCount,sum(money)money,sum(refundMoney)refundMoney"))
|
|
->from('{{%ybwm_bill}}')
|
|
->where(['uniacid'=>$uniacid])
|
|
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$startTime,':endTime'=>$endTime])
|
|
->andWhere(['in','origin',Statistics::origin()])
|
|
->groupBy(new Expression("from_unixtime(statisticsAt,'%Y-%m-%d')"))
|
|
->all();
|
|
|
|
$data=array(
|
|
'userCount'=>$userCount,
|
|
'orderUser'=>$orderUser,
|
|
'orderMoney'=>$orderMoney,
|
|
'payUser'=>$payUser,
|
|
'payMoney'=>$payMoney,
|
|
'price'=>$price,
|
|
'payArr'=>$payArr,
|
|
'payMoneyArr'=>$payMoneyArr,
|
|
'outCount'=>$outCount,
|
|
'inCount'=>$inCount,
|
|
'otherCount'=>$otherCount,
|
|
'refundMoney'=>$refundMoney,
|
|
'outArr'=>$outArr,
|
|
'inArr'=>$inArr,
|
|
'wxPayCount'=>$wxPayCount,
|
|
'wxPayMoney'=>$wxPayMoney,
|
|
'balancePayCount'=>$balancePayCount,
|
|
'balancePayMoney'=>$balancePayMoney,
|
|
'refundArr'=>$refundArr,
|
|
'refundCountArr'=>$refundCountArr,
|
|
'refundCount'=>$refundCount,
|
|
'orderList'=>$orderList,
|
|
);
|
|
return $this->result(1,'成功',$data);
|
|
}
|
|
|
|
}
|