canyin-project/ybcy/models/common/Visit.php
2024-11-01 16:07:54 +08:00

72 lines
3.1 KiB
PHP

<?php
namespace app\models\common;
use Yii;
use yii\base\Model;
use yii\db\ActiveRecord;
use yii\db\Expression;
class Visit extends ActiveRecord{
//根据时间获取访客浏览量的折线图数据(每小时)
public function visitDataByHours($uniacid,$startTime,$endTime,$time,$storeId=null){
$query=(new \yii\db\Query())
->select(new Expression("from_unixtime(createdAt,'%H') as hours,count(*)money"))
->from('{{%ybwm_visit_list}}')
->where(['uniacid'=>$uniacid])
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$startTime,':endTime'=>$endTime]);
if($storeId){
$query->andWhere(['in','storeId',$storeId]);
}
$data=$query->groupBy(new Expression("from_unixtime(createdAt,'%H')"))->all();
$data=CreatQuery(1,$data,$time);
return $data;
}
//根据时间获取访客浏览量的折线图数据(每天)
public function visitDataByDay($uniacid,$startTime,$endTime,$type,$time,$storeId=null){
$query=(new \yii\db\Query())
->select(new Expression("from_unixtime(createdAt,'%Y-%m-%d') as hours,count(*)money"))
->from('{{%ybwm_visit_list}}')
->where(['uniacid'=>$uniacid])
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$startTime,':endTime'=>$endTime]);
if($storeId){
$query->andWhere(['in','storeId',$storeId]);
}
$data=$query->groupBy(new Expression("from_unixtime(createdAt,'%Y-%m-%d')"))->all();
$data=CreatQuery($type,$data,$time);
return $data;
}
//根据时间获取访客访客数的折线图数据(每小时)
public function visitUserByHours($uniacid,$startTime,$endTime,$time,$storeId=null){
$query=(new \yii\db\Query())
->select(new Expression("from_unixtime(createdAt,'%H') as hours,count(DISTINCT userId)money"))
->from('{{%ybwm_visit_list}}')
->where(['uniacid'=>$uniacid])
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$startTime,':endTime'=>$endTime]);
if($storeId){
$query->andWhere(['in','storeId',$storeId]);
}
$data=$query->groupBy(new Expression("from_unixtime(createdAt,'%H')"))->all();
$data=CreatQuery(1,$data,$time);
return $data;
}
//根据时间获取访客访客量的折线图数据(每天)
public function visitUserByDay($uniacid,$startTime,$endTime,$type,$time,$storeId=null){
$data=[];
$query=(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])
->andWhere('createdAt>=:starTime AND createdAt<=:endTime',[':starTime'=>$startTime,':endTime'=>$endTime]);
if($storeId){
$query->andWhere(['in','storeId',$storeId]);
}
$data=$query->groupBy(new Expression("from_unixtime(createdAt,'%Y-%m-%d')"))->all();
$data=CreatQuery($type,$data,$time);
return $data;
}
}