123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- declare(strict_types=1);
- namespace App\Model\Arts;
- use App\Master\Framework\Library\Tencent\TencentIm;
- use App\Model\Model;
- class LiveRoomAdminModel extends Model
- {
- /**
- * The table associated with the model.
- *
- * @var ?string
- */
- protected ?string $table = 'live_room_admin';
- protected ?string $dateFormat = 'U';
- public bool $timestamps = false;
- protected int $is_status_search = 0;// 是否使用 1=是 0=否 默认使用 status = 1 筛选
- protected int $is_delete_search = 0;// 是否使用 1=是 0=否 默认使用 is_delete = 0 筛选
- /**
- * 默认查询字段
- *
- * @var array|string[]
- */
- public array $select = [
- '*'
- ];
- /**
- * 添加场控
- * @param int $user_id 主播ID
- * @param string $room_no 房间号
- * @param int $admin_id 场控ID
- * @return bool
- */
- public function add(int $user_id, string $room_no, int $admin_id)
- {
- $model = new LiveRoomModel();
- if (!$room = $model->getDetail(params: ['room_no' => $room_no])) {
- return $this->error('直播间已关闭');
- }
- if ($room['user_id'] != $user_id) {
- return $this->error('未拥有此权限');
- }
- if (!$admin = $this->getDetail(params: ['admin_id' => $admin_id, 'room_no' => $room_no])) {
- // 没有直播间 创建一个
- $insert = [
- 'room_id' => $room['id'],
- 'room_no' => $room_no,
- 'user_id' => $user_id,
- 'admin_id' => $admin_id,
- 'status' => 1,
- 'create_time' => time(),
- ];
- if (!$this->insertGetId($insert)) {
- return $this->error('设置失败');
- }
- } else {
- // 更新状态
- if (!$this->where('id', $admin['id'])->update(['status' => 1,'create_time' => time()])) {
- return $this->error('设置失败');
- }
- }
- // $im = new TencentIm();
- // if (!$im->modify_admin($room_no,im_prefix($user_id))){
- // return $this->error($im->getMessage() ?? '设置失败');
- // }
- return $this->success('成功');
- }
- /**
- * 删除场控
- * @param int $user_id 主播ID
- * @param string $room_no 房间号
- * @param int $admin_id 场控ID
- * @return bool
- */
- public function del(int $user_id, string $room_no, int $admin_id)
- {
- $model = new LiveRoomModel();
- if (!$room = $model->getDetail(params: ['room_no' => $room_no])) {
- return $this->error('直播间已关闭');
- }
- if ($room['user_id'] != $user_id) {
- return $this->error('未拥有此权限');
- }
- if ($admin = $this->getDetail(params: ['admin_id' => $admin_id, 'room_no' => $room_no])) {
- // 更新状态
- if (!$this->where('id', $admin['id'])->update(['status' => 0, 'create_time' => time()])) {
- return $this->error('删除失败');
- }
- }
- // $im = new TencentIm();
- // if (!$im->modify_admin($room_no,im_prefix($user_id),2)){
- // return $this->error($im->getMessage() ?? '设置失败');
- // }
- return $this->success('成功');
- }
- /**
- * 获取场控信息
- * @param $admin_id
- * @param $room_no
- * @return array
- */
- public function getAdmin($admin_id, $room_no)
- {
- $this->setIsStatusSearchValue(1);
- return $this->getDetail(params: [
- 'admin_id' => $admin_id,
- 'room_no' => $room_no,
- ]);
- }
- public function searchRoomNoAttribute($query, $value, array $params): mixed
- {
- if (empty($value)) {
- return $query;
- }
- return $query->where('room_no', $value);
- }
- public function searchAdminIdAttribute($query, $value, array $params): mixed
- {
- if (empty($value)) {
- return $query;
- }
- return $query->where('admin_id', $value);
- }
- public function user()
- {
- return $this->hasOne(UserModel::class, 'id', 'admin_id');
- }
- }
|