Visit.php 935 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace app\shop\model\user;
  3. use app\common\model\user\Visit as VisitModel;
  4. /**
  5. * 收藏模型
  6. */
  7. class Visit extends VisitModel
  8. {
  9. /**
  10. * 获取用户统计数量
  11. */
  12. public function getVisitData($startDate = null, $endDate = null, $type)
  13. {
  14. $model = $this;
  15. if(!is_null($startDate)){
  16. $model = $model->where('create_time', '>=', strtotime($startDate));
  17. }
  18. if(is_null($endDate)){
  19. $model = $model->where('create_time', '<', strtotime($startDate) + 86400);
  20. }else{
  21. $model = $model->where('create_time', '<', strtotime($endDate) + 86400);
  22. }
  23. if($type == 'visit_user'){
  24. $userIds = $model->distinct(true)->column('visitcode');
  25. return count($userIds);
  26. }else if($type == 'visit_count'){
  27. return $model->count();
  28. }
  29. return 0;
  30. }
  31. }