LiveHonouredGuest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\merchant\model\live;
  12. /**
  13. * 直播嘉宾
  14. */
  15. use basic\ModelBasic;
  16. use traits\ModelTrait;
  17. class LiveHonouredGuest extends ModelBasic
  18. {
  19. use ModelTrait;
  20. /*
  21. * 设置where条件
  22. * @param array $where 条件
  23. * */
  24. public static function setWhere($where, $model = null, $alial = '', $join = '')
  25. {
  26. $model = $model === null ? new static() : $model;
  27. if ($alial) {
  28. $model = $model->alias($alial);
  29. $alial .= '.';
  30. }
  31. if ($where['nickname'] != '') $model = $model->where("{$alial}nickname" . ($join ? '|' . $join : ''), 'LIKE', "$where[nickname]");
  32. return $model->where("{$alial}live_id", $where['live_id']);
  33. }
  34. /*
  35. * 获取嘉宾列表
  36. * @param array $where 查询条件
  37. * @return array
  38. * */
  39. public static function getGuestList($where)
  40. {
  41. $data = self::setWhere($where, null, 'a', 'u.nickname')->order('a.sort desc,a.add_time')->join('user u', 'a.uid=u.uid')->field(['a.*', 'u.avatar', 'u.nickname as u_nickname'])
  42. ->page((int)$where['page'], (int)$where['limit'])->select();
  43. $count = self::setWhere($where, null, 'a', 'u.nickname')->join('user u', 'a.uid=u.uid')->count();
  44. $data = count($data) ? $data->toArray() : [];
  45. foreach ($data as &$item) {
  46. $item['nickname'] = $item['nickname'] ?: $item['u_nickname'];
  47. $item['_type_name'] = $item['type'] ? '讲师' : '助教';
  48. }
  49. return compact('data', 'count');
  50. }
  51. }