<?php
|
|
namespace app\operations\model\user;
|
|
use app\common\model\user\Visit as VisitModel;
|
use app\operations\model\supplier\Supplier as SupplierRegionModel;
|
|
/**
|
* 访问记录模型
|
*/
|
class Visit extends VisitModel
|
{
|
// 定义全局的查询范围
|
protected $globalScope = ['status'];
|
public function scopeStatus($query)
|
{
|
$shop_supplier_ids = SupplierRegionModel::getSupplierIdsByUser(session('jjjshop_operations')['user']);
|
if (empty($shop_supplier_ids)){
|
$query->where($query->getTable() . '.shop_supplier_id', -1);
|
}else{
|
$query->where($query->getTable() . '.shop_supplier_id', 'in', $shop_supplier_ids);
|
}
|
}
|
/**
|
* 获取用户统计数量
|
*/
|
public function getVisitData($startDate = null, $endDate = null, $type)
|
{
|
$model = $this;
|
if(!is_null($startDate)){
|
$model = $model->where('create_time', '>=', strtotime($startDate));
|
}
|
if(is_null($endDate)){
|
$model = $model->where('create_time', '<', strtotime($startDate) + 86400);
|
}else{
|
$model = $model->where('create_time', '<', strtotime($endDate) + 86400);
|
}
|
if($type == 'visit_user'){
|
$userIds = $model->distinct(true)->column('visitcode');
|
return count($userIds);
|
}else if($type == 'visit_count'){
|
return $model->count();
|
}
|
return 0;
|
}
|
}
|