UserRelationDao.php 3.1 KB

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