You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
zhishifufei_php/application/admin/model/store/StoreVisit.php

66 lines
2.5 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\admin\model\store;
use traits\ModelTrait;
use basic\ModelBasic;
use app\admin\model\user\User;
/**
* 商品浏览分析
* Class StoreVisit
* @package app\admin\model\store
*/
class StoreVisit extends ModelBasic
{
use ModelTrait;
/**
* @param $where
* @return array
*/
public static function getVisit($date, $class = [])
{
$model = new self();
switch ($date) {
case null:
case 'today':
case 'week':
case 'year':
if ($date == null) $date = 'month';
$model = $model->whereTime('add_time', $date);
break;
case 'quarter':
list($startTime, $endTime) = User::getMonth('n');
$model = $model->where('add_time', '>', $startTime);
$model = $model->where('add_time', '<', $endTime);
break;
default:
list($startTime, $endTime) = explode('-', $date);
$model = $model->where('add_time', '>', strtotime($startTime));
$model = $model->where('add_time', '<', strtotime($endTime));
break;
}
$list = $model->group('type')->field('sum(count) as sum,product_id,cate_id,type,content')->order('sum desc')->limit(0, 10)->select()->toArray();
$view = [];
foreach ($list as $key => $val) {
$now_list['name'] = $val['type'] == 'viwe' ? '浏览量' : '搜索';
$now_list['value'] = $val['sum'];
$now_list['class'] = isset($class[$key]) ? $class[$key] : '';
$view[] = $now_list;
}
if (empty($list)) {
$view = [['name' => '暂无数据', 'value' => 100, 'class' => '']];
}
return $view;
}
}