UserRelationDao.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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(!is_null($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())
  56. ->when((isset($where['type']) && $where['type'] !== ''), function ($query) use ($where) {
  57. if(in_array($where['type'],[1,2,3,4])){
  58. $query->whereIn('type',[1,2,3,4]);
  59. }else{
  60. $query->where('type',$where['type']);
  61. }
  62. })->when((isset($where['uid']) && $where['uid']), function ($query) use ($where) {
  63. $query->where('uid', $where['uid']);
  64. });
  65. return $query->order('create_time DESC');
  66. }
  67. /**
  68. * @param array $where
  69. * @author Qinii
  70. */
  71. public function destory(array $where)
  72. {
  73. ($this->getModel()::getDB())->where($where)->delete();
  74. }
  75. public function dayLikeStore($day, $merId = null)
  76. {
  77. return getModelTime(UserRelation::getDB()->where('type', 10)->when($merId, function ($query, $merId) {
  78. $query->where('type_id', $merId);
  79. }), $day)->count();
  80. }
  81. public function dateVisitStore($date, $merId = null)
  82. {
  83. return UserRelation::getDB()->where('type', 11)->when($merId, function ($query, $merId) {
  84. $query->where('type_id', $merId);
  85. })->when($date, function ($query, $date) {
  86. getModelTime($query, $date, 'create_time');
  87. })->count();
  88. }
  89. /**
  90. * @param $uid
  91. * @param array $ids
  92. * @return array
  93. * @author xaboy
  94. * @day 2020/10/20
  95. */
  96. public function intersectionPayer($uid, array $ids): array
  97. {
  98. return UserRelation::getDB()->where('uid', $uid)->whereIn('type', 12)->whereIn('type_id', $ids)->column('type_id');
  99. }
  100. public function getUserProductToCommunity(?string $keyword, int $uid)
  101. {
  102. $query = UserRelation::hasWhere('spu', function ($query) use($keyword) {
  103. $query->when($keyword, function ($query) use($keyword) {
  104. $query->whereLike('store_name',"%{$keyword}%");
  105. });
  106. $query->where('status',1);
  107. });
  108. $query->where('uid',$uid);
  109. return $query;
  110. }
  111. }