Files

41 lines
1.1 KiB
PHP

<?php
namespace app\admin\model\data;
use think\Model;
class Traffic extends Model
{
// 表名
protected $name = 'data_traffic';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = false;
protected $uniacid = false;
public function getTotal($startTime,$endTime){
$where = [];
$where['createtime'] = ['between',[$startTime,$endTime]];
$data = self::where($where)
->field([
"FROM_UNIXTIME(createtime, '%Y-%m-%d') as date", // 转换创建时间为日期
"COUNT(*) as store_pv", // 店铺浏览量,包括所有商品浏览
"COUNT(DISTINCT ip) as store_uv", // 基于IP的店铺访客数
"COUNT(IF(page_type<>'other', 1, NULL)) as product_pv", // 商品浏览量
"COUNT(DISTINCT IF(page_type<>'other', ip, NULL)) as product_uv" // 商品访客数,基于IP
])
->find();
return $data;
}
}