UserRelationDao.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\common\dao\user;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\user\UserRelation;
  5. use app\common\model\user\UserRelation as model;
  6. /**
  7. * Class UserVisitDao
  8. * @package app\common\dao\user
  9. * @author zfy
  10. * @day 2020/5/27
  11. */
  12. class UserRelationDao extends BaseDao
  13. {
  14. /**
  15. * @return string
  16. * @author zfy
  17. * @day 2020/5/27
  18. */
  19. protected function getModel(): string
  20. {
  21. return model::class;
  22. }
  23. /**
  24. * @param $field
  25. * @param $value
  26. * @param null $type
  27. * @param null $uid
  28. * @return mixed
  29. * @author Qinii
  30. */
  31. public function apiFieldExists($field, $value, $type = null, $uid = null)
  32. {
  33. return $this->getModel()::getDB()->when($uid, function ($query) use ($uid) {
  34. $query->where('uid', $uid);
  35. })->when(!is_null($type), function ($query) use ($type) {
  36. $query->where('type', $type);
  37. })->where($field, $value);
  38. }
  39. /**
  40. * @param $where
  41. * @return mixed
  42. * @author Qinii
  43. */
  44. public function search($where)
  45. {
  46. $query = ($this->getModel()::getDB())
  47. ->when((isset($where['type']) && $where['type'] !== ''), function ($query) use ($where) {
  48. if(in_array($where['type'],[1,2,3,4])){
  49. $query->whereIn('type',[1,2,3,4]);
  50. }else{
  51. $query->where('type',$where['type']);
  52. }
  53. })->when((isset($where['uid']) && $where['uid']), function ($query) use ($where) {
  54. $query->where('uid', $where['uid']);
  55. });
  56. return $query->order('create_time DESC');
  57. }
  58. /**
  59. * @param array $where
  60. * @author Qinii
  61. */
  62. public function destory(array $where)
  63. {
  64. ($this->getModel()::getDB())->where($where)->delete();
  65. }
  66. public function dayLikeStore($day, $merId = null)
  67. {
  68. return getModelTime(UserRelation::getDB()->where('type', 10)->when($merId, function ($query, $merId) {
  69. $query->where('type_id', $merId);
  70. }), $day)->count();
  71. }
  72. public function dateVisitStore($date, $merId = null)
  73. {
  74. return UserRelation::getDB()->where('type', 11)->when($merId, function ($query, $merId) {
  75. $query->where('type_id', $merId);
  76. })->when($date, function ($query, $date) {
  77. getModelTime($query, $date, 'create_time');
  78. })->count();
  79. }
  80. /**
  81. * @param $uid
  82. * @param array $ids
  83. * @return array
  84. * @author zfy
  85. * @day 2020/10/20
  86. */
  87. public function intersectionPayer($uid, array $ids): array
  88. {
  89. return UserRelation::getDB()->where('uid', $uid)->whereIn('type', 12)->whereIn('type_id', $ids)->column('type_id');
  90. }
  91. }