BroadcastAssistantDao.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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. /**
  16. * 直播间主播
  17. * @author wuhaotian
  18. * @email 442384644@qq.com
  19. * @date 2024/7/13
  20. */
  21. class BroadcastAssistantDao extends BaseDao
  22. {
  23. protected function getModel(): string
  24. {
  25. return BroadcastAssistant::class;
  26. }
  27. /**
  28. * 查询是否存在
  29. * @param int $id
  30. * @param int $merId
  31. * @return bool
  32. * @author wuhaotian
  33. * @email 442384644@qq.com
  34. * @date 2024/7/13
  35. */
  36. public function merExists(int $id, int $merId)
  37. {
  38. return $this->existsWhere([$this->getPk() => $id, 'is_del' => 0, 'mer_id' => $merId]);
  39. }
  40. /**
  41. * 查询所有的主播id
  42. * @param string|null $ids
  43. * @param int $merId
  44. * @return int[]|mixed
  45. * @author wuhaotian
  46. * @email 442384644@qq.com
  47. * @date 2024/7/13
  48. */
  49. public function intersection(?string $ids, int $merId)
  50. {
  51. if (!$ids) return [0];
  52. return $this->getModel()::getDb()->whereIn('assistant_id',$ids)->where('mer_id', $merId)->column('assistant_id');
  53. }
  54. /**
  55. * 查询主播是否存在
  56. * @param $ids
  57. * @param $merId
  58. * @return bool
  59. * @author wuhaotian
  60. * @email 442384644@qq.com
  61. * @date 2024/7/13
  62. */
  63. public function existsAll($ids, $merId)
  64. {
  65. foreach ($ids as $id) {
  66. $has = $this->getModel()::getDb()->where('assistant_id',$id)->where('mer_id',$merId)->count();
  67. if (!$has) throw new ValidateException('ID:'.$id.' 不存在');
  68. }
  69. return true;
  70. }
  71. }