BroadcastAssistantDao.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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\store\broadcast;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\broadcast\BroadcastAssistant;
  14. use think\exception\ValidateException;
  15. class BroadcastAssistantDao extends BaseDao
  16. {
  17. protected function getModel(): string
  18. {
  19. return BroadcastAssistant::class;
  20. }
  21. public function merExists(int $id, int $merId)
  22. {
  23. return $this->existsWhere([$this->getPk() => $id, 'is_del' => 0, 'mer_id' => $merId]);
  24. }
  25. public function intersection(?string $ids, int $merId)
  26. {
  27. if (!$ids) return [0];
  28. return $this->getModel()::getDb()->whereIn('assistant_id',$ids)->where('mer_id', $merId)->column('assistant_id');
  29. }
  30. public function existsAll($ids, $merId)
  31. {
  32. foreach ($ids as $id) {
  33. $has = $this->getModel()::getDb()->where('assistant_id',$id)->where('mer_id',$merId)->count();
  34. if (!$has) throw new ValidateException('ID:'.$id.' 不存在');
  35. }
  36. return true;
  37. }
  38. }