RelevanceDao.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\system;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\system\Relevance;
  14. use app\common\repositories\system\RelevanceRepository;
  15. class RelevanceDao extends BaseDao
  16. {
  17. protected function getModel(): string
  18. {
  19. return Relevance::class;
  20. }
  21. public function clear(int $id, $type, string $field)
  22. {
  23. if (is_string($type)) $type = [$type];
  24. return $this->getModel()::getDb()->where($field, $id)->whereIn('type', $type)->delete();
  25. }
  26. public function joinUser($where)
  27. {
  28. $query = Relevance::hasWhere('community',function($query) use($where){
  29. $query->where('status',1)->where('is_show',1)->where('is_del',0);
  30. $query->when(isset($where['is_type']) && $where['is_type'] !== '',function($query) use($where){
  31. $query->where('is_type',$where['is_type']);
  32. });
  33. });
  34. $query->where('left_id',$where['uid'])->where('type',RelevanceRepository::TYPE_COMMUNITY_START);
  35. return $query;
  36. }
  37. }