StoreVisit.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /**
  16. * 商品浏览分析
  17. * Class StoreOrder
  18. * @package app\admin\model\store
  19. */
  20. class StoreVisit extends ModelBasic
  21. {
  22. use ModelTrait;
  23. /**
  24. * @param $where
  25. * @return array
  26. */
  27. public static function getVisit($date,$class=[]){
  28. $model=new self();
  29. switch ($date){
  30. case null:case 'today':case 'week':case 'year':
  31. if($date==null) $date='month';
  32. $model=$model->whereTime('add_time',$date);
  33. break;
  34. case 'quarter':
  35. list($startTime,$endTime)=User::getMonth('n');
  36. $model = $model->where('add_time','>',$startTime);
  37. $model = $model->where('add_time','<',$endTime);
  38. break;
  39. default:
  40. list($startTime,$endTime)=explode('-',$date);
  41. $model = $model->where('add_time','>',strtotime($startTime));
  42. $model = $model->where('add_time','<',strtotime($endTime));
  43. break;
  44. }
  45. $list=$model->group('type')->field('sum(count) as sum,product_id,cate_id,type,content')->order('sum desc')->limit(0,10)->select()->toArray();
  46. $view=[];
  47. foreach ($list as $key=>$val){
  48. $now_list['name']=$val['type']=='viwe'?'浏览量':'搜索';
  49. $now_list['value']=$val['sum'];
  50. $now_list['class']=isset($class[$key])?$class[$key]:'';
  51. $view[]=$now_list;
  52. }
  53. if(empty($list)){
  54. $view=[['name'=>'暂无数据', 'value'=>100, 'class'=>'']];
  55. }
  56. return $view;
  57. }
  58. }