Favorite.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\supplier\model\user;
  3. use app\common\model\user\Favorite as FavoriteModel;
  4. /**
  5. * 收藏模型
  6. */
  7. class Favorite extends FavoriteModel
  8. {
  9. /**
  10. * 获取关注店铺的用户
  11. */
  12. public function getUserList($shop_supplier_id, $params)
  13. {
  14. $model = $this;
  15. if(isset($params['search']) && $params['search'] != ''){
  16. $model = $model->where('user.nickName|user.mobile', 'like', '%' . trim($params['search']) . '%');
  17. }
  18. return $model->alias('fav')->field(['fav.*'])->with(['user'])
  19. ->join('user user', 'user.user_id = fav.user_id','left')
  20. ->where('fav.pid', '=', $shop_supplier_id)
  21. ->where('fav.type', '=', 10)
  22. ->paginate($params);
  23. }
  24. /**
  25. * 获取某天的关注用户数
  26. */
  27. public function getUserTotal($day, $shop_supplier_id)
  28. {
  29. $startTime = strtotime($day);
  30. return $this->where('pid', '=', $shop_supplier_id)
  31. ->where('type', '=', 10)
  32. ->where('create_time', '>=', $startTime)
  33. ->where('create_time', '<', $startTime + 86400)
  34. ->count();
  35. }
  36. /**
  37. * 获取某天的店铺关注数
  38. * $endDate不传则默认当天
  39. */
  40. public function getFavData($startDate, $endDate, $type, $shop_supplier_id){
  41. $model = $this;
  42. !is_null($startDate) && $model = $model->where('create_time', '>=', strtotime($startDate));
  43. if(is_null($endDate)){
  44. !is_null($startDate) && $model = $model->where('create_time', '<', strtotime($startDate) + 86400);
  45. }else{
  46. $model = $model->where('create_time', '<', strtotime($endDate) + 86400);
  47. }
  48. return $model->where('shop_supplier_id', '=', $shop_supplier_id)
  49. ->where('type', '=', $type)
  50. ->count();
  51. }
  52. }