StoreVisit.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\store;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use app\admin\model\user\User;
  15. class StoreVisit extends ModelBasic
  16. {
  17. use ModelTrait;
  18. /**
  19. * @param $where
  20. * @return array
  21. */
  22. public static function getVisit($date,$class=[]){
  23. $model=new self();
  24. switch ($date){
  25. case null:case 'today':case 'week':case 'year':
  26. if($date==null) $date='month';
  27. $model=$model->whereTime('add_time',$date);
  28. break;
  29. case 'quarter':
  30. list($startTime,$endTime)=User::getMonth('n');
  31. $model = $model->where('add_time','>',$startTime);
  32. $model = $model->where('add_time','<',$endTime);
  33. break;
  34. default:
  35. list($startTime,$endTime)=explode('-',$date);
  36. $model = $model->where('add_time','>',strtotime($startTime));
  37. $model = $model->where('add_time','<',strtotime($endTime));
  38. break;
  39. }
  40. $list=$model->group('type')->field('sum(count) as sum,product_id,cate_id,type,content')->order('sum desc')->limit(0,10)->select()->toArray();
  41. $view=[];
  42. foreach ($list as $key=>$val){
  43. $now_list['name']=$val['type']=='viwe'?'浏览量':'搜索';
  44. $now_list['value']=$val['sum'];
  45. $now_list['class']=isset($class[$key])?$class[$key]:'';
  46. $view[]=$now_list;
  47. }
  48. if(empty($list)){
  49. $view=[['name'=>'暂无数据', 'value'=>100, 'class'=>'']];
  50. }
  51. return $view;
  52. }
  53. }