Visit.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\supplier\model\user;
  3. use app\common\model\user\Visit as VisitModel;
  4. /**
  5. * 收藏模型
  6. */
  7. class Visit extends VisitModel
  8. {
  9. /**
  10. * 获取某天的访问数
  11. * $endDate不传则默认当天
  12. */
  13. public function getVisitData($startDate, $endDate, $shop_supplier_id){
  14. $model = $this;
  15. !is_null($startDate) && $model = $model->where('create_time', '>=', strtotime($startDate));
  16. if(is_null($endDate)){
  17. !is_null($startDate) && $model = $model->where('create_time', '<', strtotime($startDate) + 86400);
  18. }else{
  19. $model = $model->where('create_time', '<', strtotime($endDate) + 86400);
  20. }
  21. return $model->where('shop_supplier_id', '=', $shop_supplier_id)
  22. ->count();
  23. }
  24. /**
  25. * 获取某天的访客数
  26. * $endDate不传则默认当天
  27. */
  28. public function getVisitUserData($startDate, $endDate, $shop_supplier_id){
  29. $model = $this;
  30. !is_null($startDate) && $model = $model->where('create_time', '>=', strtotime($startDate));
  31. if(is_null($endDate)){
  32. !is_null($startDate) && $model = $model->where('create_time', '<', strtotime($startDate) + 86400);
  33. }else{
  34. $model = $model->where('create_time', '<', strtotime($endDate) + 86400);
  35. }
  36. $userIds = $model->distinct(true)
  37. ->where('shop_supplier_id', '=', $shop_supplier_id)
  38. ->column('visitcode');
  39. return count($userIds);
  40. }
  41. }