AliyunLive.php 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  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\admin\controller\live;
  12. use app\admin\controller\AuthController;
  13. use app\admin\model\live\LiveGoods;
  14. use app\admin\model\live\LiveGift;
  15. use app\admin\model\live\LiveReward;
  16. use app\admin\model\order\StoreOrder as StoreOrderModel;
  17. use app\admin\model\live\LiveBarrage;
  18. use app\admin\model\live\LiveHonouredGuest;
  19. use app\admin\model\live\LiveStudio;
  20. use app\admin\model\live\LiveUser;
  21. use app\admin\model\live\LiveAudit;
  22. use app\admin\model\live\LivePlayback;
  23. use app\admin\model\special\Special as SpecialModel;
  24. use app\admin\model\special\Special;
  25. use app\admin\model\special\SpecialCourse;
  26. use app\admin\model\special\SpecialSubject;
  27. use app\admin\model\special\SpecialTask;
  28. use app\admin\model\system\SystemAdmin;
  29. use app\admin\model\merchant\Merchant;
  30. use app\admin\model\user\User;
  31. use app\wap\model\user\WechatUser;
  32. use service\JsonService as Json;
  33. use service\SystemConfigService;
  34. use service\WechatTemplateService;
  35. use think\Exception;
  36. use service\FormBuilder as Form;
  37. use Api\AliyunLive as ApiAliyunLive;
  38. use think\Session;
  39. use think\Url;
  40. use \GatewayWorker\Lib\Gateway;
  41. use app\admin\model\system\SystemRole as RoleModel;
  42. use app\wap\model\routine\RoutineTemplate;
  43. use app\wap\model\wap\SmsTemplate;
  44. use app\index\controller\PushJob;
  45. /**直播
  46. * Class AliyunLive
  47. * @package app\admin\controller\live
  48. */
  49. class AliyunLive extends AuthController
  50. {
  51. /**
  52. * 阿里云直播句柄
  53. * @var \Api\AliyunLive
  54. */
  55. protected $aliyunLive;
  56. protected function _initialize()
  57. {
  58. parent::_initialize();
  59. $this->aliyunLive = \Api\AliyunLive::instance([
  60. 'AccessKey' => SystemConfigService::get('accessKeyId'),
  61. 'AccessKeySecret' => SystemConfigService::get('accessKeySecret'),
  62. 'OssEndpoint' => SystemConfigService::get('aliyun_live_end_point'),
  63. 'OssBucket' => SystemConfigService::get('aliyun_live_oss_bucket'),
  64. 'appName' => SystemConfigService::get('aliyun_live_appName'),
  65. 'payKey' => SystemConfigService::get('aliyun_live_play_key'),
  66. 'key' => SystemConfigService::get('aliyun_live_push_key'),
  67. 'playLike' => SystemConfigService::get('aliyun_live_playLike'),
  68. 'rtmpLink' => SystemConfigService::get('aliyun_live_rtmpLink'),
  69. ]);
  70. }
  71. /**
  72. * 直播间管理
  73. * */
  74. public function index()
  75. {
  76. $this->assign([
  77. 'special_list' => SpecialModel::where('type', SPECIAL_LIVE)->where(['is_del' => 0])->field(['id', 'title'])->select(),
  78. 'mer_list' => Merchant::getMerchantList(),
  79. 'type' => $this->request->param('type', 1),
  80. ]);
  81. return $this->fetch();
  82. }
  83. /**
  84. * 快速设置直播的某个字段的值
  85. * @param string $field 键值
  86. * @param string $value 值
  87. * @param int $id 直播id
  88. * @return json
  89. * */
  90. public function set_live_value($field = '', $value = '', $id = 0)
  91. {
  92. if (!$field || !$id) return Json::fail('缺少参数');
  93. $value = str_replace('免密', '', $value);
  94. $res = parent::getDataModification('studio', $id, $field, $value);
  95. if ($res)
  96. return Json::successful('修改成功');
  97. else
  98. return Json::fail('修改失败');
  99. }
  100. /**
  101. * 编辑直播间
  102. * */
  103. public function update_live($id = 0)
  104. {
  105. if (!$id) return $this->failed('缺少参数');
  106. $liveInfo = LiveStudio::get($id);
  107. if (!$liveInfo) return $this->failed('未查到直播间信息');
  108. $f[] = Form::input('stream_name', '直播间号:', $liveInfo->getData('stream_name'))->disabled(true);
  109. $f[] = Form::input('live_title', '直播间标题:', $liveInfo->getData('live_title'));
  110. $f[] = Form::frameImageOne('live_image', '直播封面:', Url::build('admin/widget.images/index', array('fodder' => 'live_image')), $liveInfo->getData('live_image'))->icon('image')->width('100%')->height('500px');
  111. $f[] = Form::textarea('live_introduction', '直播间简介:', $liveInfo->getData('live_introduction'));
  112. $f[] = Form::number('online_num', '虚拟在线人数:', $liveInfo->getData('online_num'))->min(0);
  113. $f[] = Form::number('sort', '排序:', $liveInfo->getData('sort'))->min(0);
  114. $f[] = Form::radio('is_remind', '开播提醒:', $liveInfo->getData('is_remind'))->options([
  115. ['value' => 1, 'label' => '是'],
  116. ['value' => 0, 'label' => '否']
  117. ]);
  118. $f[] = Form::number('remind_time', '开播前提醒时间(分):', $liveInfo->getData('remind_time'));
  119. $f[] = Form::radio('is_recording', '自动录制:', $liveInfo->getData('is_recording'))->options([
  120. ['value' => 1, 'label' => '是'],
  121. ['value' => 0, 'label' => '否']
  122. ]);
  123. $f[] = Form::radio('is_playback', '直播回放:', $liveInfo->getData('is_playback'))->options([
  124. ['value' => 1, 'label' => '是'],
  125. ['value' => 0, 'label' => '否']
  126. ]);
  127. $f[] = Form::radio('is_chat', '直播间聊天:', $liveInfo->getData('is_chat'))->options([
  128. ['value' => 1, 'label' => '开启'],
  129. ['value' => 0, 'label' => '关闭']
  130. ]);
  131. $f[] = Form::radio('is_class_chat', '直播间课堂:', $liveInfo->getData('is_class_chat'))->options([
  132. ['value' => 1, 'label' => '开启'],
  133. ['value' => 0, 'label' => '关闭']
  134. ]);
  135. $f[] = Form::radio('is_live_recommend', '直播间推荐:', $liveInfo->getData('is_live_recommend'))->options([
  136. ['value' => 1, 'label' => '开启'],
  137. ['value' => 0, 'label' => '关闭']
  138. ]);
  139. $f[] = Form::radio('is_ranking', '直播间排行:', $liveInfo->getData('is_ranking'))->options([
  140. ['value' => 1, 'label' => '开启'],
  141. ['value' => 0, 'label' => '关闭']
  142. ]);
  143. $form = Form::make_post_form('修改直播间', $f, Url::build('save_live', array('id' => $id)), 2);
  144. $this->assign(compact('form'));
  145. return $this->fetch('public/form-builder');
  146. }
  147. /**
  148. * 修改直播间
  149. * @param int $id
  150. * @return json
  151. * */
  152. public function save_live($id = 0)
  153. {
  154. if (!$id) return Json::fail('缺少参数');
  155. $data = parent::postMore([
  156. ['live_title', ''],
  157. ['live_image', ''],
  158. ['live_introduction', ''],
  159. ['online_num', 0],
  160. ['sort', 0],
  161. ['is_remind', 0],
  162. ['remind_time', 0],
  163. ['is_recording', 0],
  164. ['is_playback', 0],
  165. ['is_chat', 0],
  166. ['is_class_chat', 0],
  167. ['is_live_recommend', 0],
  168. ['is_ranking', 0]
  169. ]);
  170. if (!$data['live_title']) return Json::fail('直播间标题不能为空');
  171. if (!$data['live_introduction']) return Json::fail('直播间简介不能为空');
  172. if ($data['is_remind'] && !$data['remind_time']) return Json::fail('请输入直播前提醒时间!');
  173. if (LiveStudio::edit($data, $id))
  174. return Json::successful('修改成功');
  175. else
  176. return Json::fail('修改失败或者您没有修改内容');
  177. }
  178. /**
  179. * 直播间用户管理
  180. * @param int $id
  181. * */
  182. public function live_user($id = 0)
  183. {
  184. if (!$id) return $this->failed('缺少参数');
  185. $liveInfo = LiveStudio::get($id);
  186. if (!$liveInfo) return $this->failed('未查到直播间');
  187. $this->assign([
  188. 'stream_name' => $liveInfo->stream_name,
  189. 'live_id' => $id
  190. ]);
  191. return $this->fetch();
  192. }
  193. /**
  194. * 获取直播间用户列表
  195. * */
  196. public function get_live_user_list()
  197. {
  198. $where = parent::getMore([
  199. ['live_id', 0],
  200. ['page', 0],
  201. ['limit', 20],
  202. ['nickname', ''],
  203. ['start_time', ''],
  204. ['end_time', ''],
  205. ]);
  206. if (!$where['live_id']) return Json::fail('缺少参数');
  207. return Json::successlayui(LiveUser::getLiveUserList($where));
  208. }
  209. /**
  210. * 设置直播用户
  211. * @param string $field
  212. * @param string $id
  213. * @param string $value
  214. */
  215. public function set_live_user_value($field = '', $id = '', $value = '')
  216. {
  217. if (!$field || !$id) return Json::fail('缺少参数');
  218. $res = parent::getDataModification('live_user', $id, $field, $value);
  219. if ($res)
  220. return Json::successful('修改成功');
  221. else
  222. return Json::fail('修改失败');
  223. }
  224. /**礼物
  225. * @param string $field
  226. * @param string $id
  227. * @param string $value
  228. */
  229. public function set_live_gift_value($field = '', $id = '', $value = '')
  230. {
  231. if (!$field || !$id) return Json::fail('缺少参数');
  232. $res = parent::getDataModification('live_gift', $id, $field, $value);
  233. if ($res)
  234. return Json::successful('修改成功');
  235. else
  236. return Json::fail('修改失败');
  237. }
  238. /**
  239. * 禁止发言
  240. */
  241. public function live_no_speaking($id)
  242. {
  243. if (!$id) return $this->failed('缺少参数');
  244. $liveInfo = LiveUser::get($id);
  245. if (!$liveInfo) return $this->failed('未查到直播间信息');
  246. $f[] = Form::radio('is_ban', '是否禁言', $liveInfo->getData('is_ban'))->options([
  247. ['value' => 1, 'label' => '是'],
  248. ['value' => 0, 'label' => '否'],
  249. ]);
  250. $f[] = Form::number('ban_time', '禁言时间:分');
  251. $form = Form::make_post_form('禁止发言', $f, Url::build('save_no_speaking', array('id' => $id)), 2);
  252. $this->assign(compact('form'));
  253. return $this->fetch('public/form-builder');
  254. }
  255. public function save_no_speaking($id = 0)
  256. {
  257. if (!$id) return Json::fail('缺少参数');
  258. $data = parent::postMore([
  259. ['is_ban', 0],
  260. ['ban_time', 0]
  261. ]);
  262. if ($data['is_ban']) {
  263. $workerman = \think\Config::get('workerman.channel', []);
  264. Gateway::$registerAddress = $workerman['ip'] . ':' . $workerman['port'];
  265. $uid = LiveUser::where('id', $id)->value('uid');
  266. if (Gateway::isUidOnline($uid)) {
  267. Gateway::sendToUid($uid, json_encode([
  268. 'type' => 'ban',
  269. 'value' => 1
  270. ]));
  271. }
  272. }
  273. if ($data['is_ban'] && $data['ban_time'] <= 0) return Json::fail('请输入禁言时间');
  274. $data['ban_time'] = bcadd(time(), bcmul($data['ban_time'], 60, 0), 0);
  275. if (LiveUser::edit($data, $id)) {
  276. return Json::successful('修改成功');
  277. } else {
  278. return Json::fail('修改失败');
  279. }
  280. }
  281. /**
  282. * 禁止进入
  283. */
  284. public function live_no_entry($id)
  285. {
  286. if (!$id) return $this->failed('缺少参数');
  287. $liveInfo = LiveUser::get($id);
  288. if (!$liveInfo) return $this->failed('未查到直播间信息');
  289. $f[] = Form::radio('is_open_ben', '是否禁止进入直播间', $liveInfo->getData('is_open_ben'))->options([
  290. ['value' => 1, 'label' => '是'],
  291. ['value' => 0, 'label' => '否'],
  292. ]);
  293. $f[] = Form::number('open_ben_time', '禁止时间:分');
  294. $form = Form::make_post_form('禁止进入', $f, Url::build('save_no_entry', array('id' => $id)), 2);
  295. $this->assign(compact('form'));
  296. return $this->fetch('public/form-builder');
  297. }
  298. public function save_no_entry($id = 0)
  299. {
  300. if (!$id) return Json::fail('缺少参数');
  301. $data = parent::postMore([
  302. ['is_open_ben', 0],
  303. ['open_ben_time', 0]
  304. ]);
  305. if ($data['is_open_ben'] && $data['open_ben_time'] <= 0) return Json::fail('请输入禁止时间');
  306. $data['open_ben_time'] = bcadd(time(), bcmul($data['open_ben_time'], 60, 0), 0);
  307. if (LiveUser::edit($data, $id)) {
  308. return Json::successful('修改成功');
  309. } else {
  310. return Json::fail('修改失败');
  311. }
  312. }
  313. /**
  314. * 直播间管理
  315. */
  316. public function get_live_list()
  317. {
  318. $where = parent::getMore([
  319. ['stream_name', ''],
  320. ['start_time', ''],
  321. ['end_time', ''],
  322. ['page', 1],
  323. ['limit', 20],
  324. ['special_id', 0],
  325. ]);
  326. return Json::successlayui(LiveStudio::getLiveList($where));
  327. }
  328. /**
  329. * 直播专题列表
  330. * @param int $subject_id
  331. * @return mixed
  332. */
  333. public function special_live()
  334. {
  335. $special_type = $this->request->param("special_type");
  336. if (!$special_type || !is_numeric($special_type)) return $this->failed('专题类型参数缺失');
  337. $subjectlist = SpecialSubject::specialCategoryAll();
  338. $this->assign([
  339. 'type' => 1,
  340. 'special_type' => $special_type,
  341. 'special_title' => SPECIAL_TYPE[$special_type],
  342. 'subject_list' => $subjectlist,
  343. 'mer_list' => Merchant::getMerchantList(),
  344. 'is_live' => 1,
  345. ]);
  346. return $this->fetch();
  347. }
  348. /**
  349. * 获取直播推流地址
  350. * @param int $id
  351. * @throws \think\db\exception\DataNotFoundException
  352. * @throws \think\db\exception\ModelNotFoundException
  353. * @throws \think\exception\DbException
  354. */
  355. public function go_live($id = 0)
  356. {
  357. if (!$id) return Json::fail('缺少参数');
  358. $specialInfo = SpecialModel::get($id);
  359. if (!$specialInfo) return Json::fail('直播专题暂未查到');
  360. if ($specialInfo->type != SPECIAL_LIVE) return Json::fail('此专题不授予直播专题,无法获取推流地址!');
  361. $liveInfo = LiveStudio::where('special_id', $specialInfo->id)->find();
  362. if (!$liveInfo) return Json::fail('没有查到此直播间');
  363. if ($liveInfo->is_del) return Json::fail('直播间已删除无法推流');
  364. $url = $this->aliyunLive->getPushSteam($liveInfo->stream_name);
  365. return Json::successful($url);
  366. }
  367. /**
  368. * 直播消息提醒
  369. * @param int $id
  370. * @throws \think\db\exception\DataNotFoundException
  371. * @throws \think\db\exception\ModelNotFoundException
  372. * @throws \think\exception\DbException
  373. */
  374. public function send_remind($id = 0)
  375. {
  376. if (!$id) return Json::fail('缺少参数');
  377. $specialInfo = SpecialModel::get($id);
  378. if (!$specialInfo) return Json::fail('直播专题暂未查到,无法进行提醒');
  379. $liveInfo = LiveStudio::where('special_id', $specialInfo->id)->find();
  380. if (!$liveInfo) return Json::fail('没有查到此直播间,无法提醒');
  381. if ($liveInfo->is_del) return Json::fail('直播间已删除无法提醒');
  382. $liveInfo = $liveInfo->toArray();
  383. if ($liveInfo['is_reminded'] == 0) {
  384. LiveStudio::where('id', $liveInfo['id'])->update(['is_reminded' => 1]);
  385. }
  386. if ($specialInfo['pay_type'] == 1 && $specialInfo['member_pay_type'] == 1) {
  387. $orderList = StoreOrderModel::where(['cart_id' => $id, 'type' => 0])->column("uid");
  388. } elseif ($specialInfo['pay_type'] == 1 && $specialInfo['member_pay_type'] == 0) {
  389. $order = StoreOrderModel::where(['cart_id' => $id, 'type' => 0])->column("uid");
  390. $user = User::where('is_h5user', 0)->where('level', 1)->column("uid");
  391. $orderList = array_merge($order, $user);
  392. } else {
  393. $orderList = User::where('is_h5user', 0)->column("uid");
  394. }
  395. if (!$orderList) {
  396. return Json::fail('暂无合适用户,无需提醒');
  397. }
  398. $site_url = SystemConfigService::get('site_url');
  399. $orderList = array_unique($orderList);
  400. $data['id'] = $id;
  401. $data['site_url'] = $site_url;
  402. $data['live_title'] = $specialInfo['title'];
  403. $data['start_play_time'] = $liveInfo['start_play_time'];
  404. foreach ($orderList as $k => $v) {
  405. $data['uid'] = $v;
  406. PushJob::actionWithDoPinkJob($data, 'doLiveStudioJob');
  407. }
  408. return Json::successful("发送成功");
  409. }
  410. /**直播审核
  411. * @return mixed
  412. */
  413. public function live_audit()
  414. {
  415. return $this->fetch();
  416. }
  417. /**
  418. * 审核列表
  419. */
  420. public function get_live_audit_list()
  421. {
  422. $where = parent::getMore([
  423. ['page', 1],
  424. ['limit', 20],
  425. ['store_name', ''],
  426. ]);
  427. return Json::successlayui(LiveAudit::liveExamineList($where));
  428. }
  429. /**不通过
  430. * @param $id
  431. * @throws \think\exception\DbException
  432. */
  433. public function fail($id)
  434. {
  435. $fail_msg = parent::postMore([
  436. ['message', ''],
  437. ]);
  438. if (!LiveAudit::be(['id' => $id, 'status' => 0])) return Json::fail('操作记录不存在或状态错误!');
  439. $audit = LiveAudit::get($id);
  440. if (!$audit) return Json::fail('操作记录不存!');
  441. if ($audit->status != 0) return Json::fail('您已审核,请勿重复操作');
  442. LiveAudit::beginTrans();
  443. $res = LiveAudit::changeFail($id, $audit['mer_id'], $fail_msg['message']);
  444. if ($res) {
  445. LiveAudit::commitTrans();
  446. return Json::successful('操作成功!');
  447. } else {
  448. LiveAudit::rollbackTrans();
  449. return Json::fail('操作失败!');
  450. }
  451. }
  452. /**通过
  453. * @param $id
  454. * @throws \think\exception\DbException
  455. */
  456. public function succ($id)
  457. {
  458. if (!LiveAudit::be(['id' => $id, 'status' => 0])) return Json::fail('操作记录不存在或状态错误!');
  459. $audit = LiveAudit::get($id);
  460. if (!$audit) return Json::fail('操作记录不存!');
  461. if ($audit->status != 0) return Json::fail('您已审核,请勿重复操作');
  462. LiveAudit::beginTrans();
  463. $res = LiveAudit::changeSuccess($id, $audit['mer_id']);
  464. if ($res) {
  465. LiveAudit::commitTrans();
  466. return Json::successful('操作成功!');
  467. } else {
  468. LiveAudit::rollbackTrans();
  469. return Json::fail('操作失败!');
  470. }
  471. }
  472. /**
  473. * 获取专题直播列表
  474. */
  475. public function special_list()
  476. {
  477. $where = parent::getMore([
  478. ['subject_id', 0],
  479. ['mer_id', 0],
  480. ['page', 1],
  481. ['limit', 20],
  482. ['store_name', ''],
  483. ['title', ''],
  484. ['start_time', ''],
  485. ['end_time', ''],
  486. ['order', ''],
  487. ['is_show', ''],
  488. ['special_type', 4],
  489. ]);
  490. if (isset($where['special_type'])) {
  491. $where['type'] = $where['special_type'];
  492. }
  493. $special_list = SpecialModel::getSpecialList($where);
  494. return Json::successlayui($special_list);
  495. }
  496. /**
  497. * 删除专题和直播间
  498. * @param int $id
  499. * @throws \think\db\exception\DataNotFoundException
  500. * @throws \think\db\exception\ModelNotFoundException
  501. * @throws \think\exception\DbException
  502. */
  503. public function delete($id = 0)
  504. {
  505. if (!$id) return Json::fail('缺少参数');
  506. $specialInfo = SpecialModel::get($id);
  507. if (!$specialInfo) return Json::fail('查找的专题不存在');
  508. if ($specialInfo->is_del) return Json::fail('专题已经删除');
  509. $liveInfo = LiveStudio::where(['special_id' => $id])->find();
  510. if (!$liveInfo) return Json::fail('删除的专题直播不存在');
  511. if ($liveInfo->is_del) return Json::fail('直播间已删除');
  512. $specialInfo->is_del = 1;
  513. $liveInfo->is_del = 1;
  514. if ($specialInfo->save() && $liveInfo->save()) {
  515. LiveStudio::where(['special_id' => $id])->update(['is_del' => 1]);
  516. return Json::successful('删除成功');
  517. } else {
  518. return Json::fail('删除失败');
  519. }
  520. }
  521. public function recommend($id = 0)
  522. {
  523. if (!$id) return Json::fail('缺少参数');
  524. $specialInfo = SpecialModel::get($id);
  525. if (!$specialInfo) return Json::fail('专题不存在');
  526. Session::set('live_one_id', $id, 'wap');
  527. return Json::successful('推荐成功');
  528. }
  529. /**
  530. * 嘉宾列表
  531. * @param $live_id
  532. * @return mixed
  533. */
  534. public function guest_list($live_id = 0)
  535. {
  536. $this->assign('live_id', $live_id);
  537. return $this->fetch();
  538. }
  539. /**
  540. * 添加嘉宾
  541. * @param int $live_id
  542. * @return mixed|void
  543. * @throws \FormBuilder\exception\FormBuilderException
  544. * @throws \think\db\exception\DataNotFoundException
  545. * @throws \think\db\exception\ModelNotFoundException
  546. * @throws \think\exception\DbException
  547. */
  548. public function user($live_id = 0)
  549. {
  550. $this->assign('live_id', $live_id);
  551. return $this->fetch();
  552. }
  553. /**
  554. * 获取用户列表
  555. */
  556. public function user_list()
  557. {
  558. $where = parent::getMore([
  559. ['page', 1],
  560. ['limit', 20],
  561. ['nickname', ''],
  562. ['status', ''],
  563. ['pay_count', ''],
  564. ['is_promoter', ''],
  565. ['order', ''],
  566. ['data', ''],
  567. ['country', ''],
  568. ['province', ''],
  569. ['city', ''],
  570. ['user_time_type', ''],
  571. ['user_time', ''],
  572. ['sex', ''],
  573. ]);
  574. return Json::successlayui(User::add_get_user_list($where));
  575. }
  576. /**
  577. * 添加嘉宾
  578. * @param int $live_id
  579. */
  580. public function save_guest($uid = 0, $live_id = 0, $type = 0)
  581. {
  582. if (!$live_id) return Json::fail('缺少直播间id');
  583. if (!$uid) return Json::fail('请选择用户');
  584. if ($type === '') return Json::fail('请选择类型');
  585. if ($type && LiveHonouredGuest::be(['live_id' => $live_id, 'type' => 1])) return Json::fail('讲师只能添加一个');
  586. $data['uid'] = $uid;
  587. $data['type'] = $type;
  588. $data['live_id'] = $live_id;
  589. $data['nickname'] = User::where('uid', $uid)->value('nickname');
  590. $data['add_time'] = time();
  591. if (LiveHonouredGuest::set($data))
  592. return Json::successful('添加成功');
  593. else
  594. return Json::fail('添加失败');
  595. }
  596. /**
  597. * 获取嘉宾列表
  598. */
  599. public function get_guest_list()
  600. {
  601. $where = parent::getMore([
  602. ['live_id', 0],
  603. ['nickname', ''],
  604. ['page', 1],
  605. ['limit', 20],
  606. ]);
  607. return Json::successlayui(LiveHonouredGuest::getGuestList($where));
  608. }
  609. /**
  610. * 删除嘉宾
  611. * @param int $id
  612. */
  613. public function del_guest($id = 0)
  614. {
  615. if (!$id) return Json::fail('缺少参数');
  616. if (LiveHonouredGuest::del($id))
  617. return Json::successful('删除成功');
  618. else
  619. return Json::fail('删除失败');
  620. }
  621. /**
  622. * 回放设置和下载列表
  623. * @param int $special_id
  624. * @return mixed|void
  625. * @throws \think\db\exception\DataNotFoundException
  626. * @throws \think\db\exception\ModelNotFoundException
  627. * @throws \think\exception\DbException
  628. */
  629. public function download_list($special_id = 0)
  630. {
  631. if (!$special_id) return $this->failed('缺少参数');
  632. $specialInfo = SpecialModel::get($special_id);
  633. if (!$specialInfo) return $this->failed('查找的专题不存在');
  634. if ($specialInfo->is_del) return $this->failed('专题已经删除');
  635. $liveInfo = LiveStudio::where(['special_id' => $special_id])->find();
  636. if (!$liveInfo) return $this->failed('直播不存在!');
  637. $livePlayBack = LivePlayback::where(['stream_name' => $liveInfo->stream_name, 'is_record' => 1])->find();
  638. $this->assign([
  639. 'stream_name' => $liveInfo->stream_name,
  640. 'record_id' => $livePlayBack ? $livePlayBack->RecordId : 0,
  641. 'is_playback' => 1
  642. ]);
  643. return $this->fetch();
  644. }
  645. /**
  646. * 获取直播间下的录制内容
  647. * @param string $record_id
  648. * @param string $stream_name
  649. * @param string $start_time
  650. * @param string $end_time
  651. * @param int $page
  652. * @param int $limit
  653. */
  654. public function get_live_record()
  655. {
  656. $start_time = $this->request->param('syn_start_time');
  657. $end_time = $this->request->param('syn_end_time');
  658. $stream_name = $this->request->param('stream_name');
  659. $record_id = $this->request->param('record_id');
  660. if (!$stream_name) return Json::fail('缺少直播间id');
  661. $aliyunLive = $this->aliyunLive;
  662. $beginToday = mktime(0, 0, 0, date('m'), date('d') - 3, date('Y'));
  663. if ($start_time && $end_time) {
  664. $start_time = strtotime($start_time);
  665. $end_time = strtotime($end_time);
  666. if ($start_time > $end_time) return Json::fail('开始时间不能大于结束时间');
  667. $time = bcsub($end_time, $start_time, 0) / 86400;
  668. if ($time > 4) return Json::fail('开始和结束的时间不能间隔4天');
  669. }
  670. try {
  671. $res = $aliyunLive->queryLiveRecordFiles(
  672. $stream_name,
  673. $start_time ? ApiAliyunLive::setTimeFormat($start_time) : ApiAliyunLive::setTimeFormat($beginToday),
  674. $end_time ? ApiAliyunLive::setTimeFormat($end_time) : ApiAliyunLive::setTimeFormat(time()),
  675. 1,
  676. 10
  677. );
  678. $data = [];
  679. $count = 0;
  680. if ($res) {
  681. if (isset($res['RecordIndexInfoList']['RecordIndexInfo'])) {
  682. foreach ($res['RecordIndexInfoList']['RecordIndexInfo'] as $item) {
  683. LivePlayback::livePlaybackAdd($item);
  684. $data [] = [
  685. 'StreamName' => $item['StreamName'],
  686. 'RecordId' => $item['RecordId'],
  687. 'playback_record_id' => $record_id,
  688. 'RecordUrl' => $item['RecordUrl'],
  689. 'StartTime' => $item['StartTime'],
  690. 'EndTime' => $item['EndTime'],
  691. ];
  692. }
  693. }
  694. if (isset($res['TotalNum'])) $count = $res['TotalNum'];
  695. return Json::successlayui($count, $data);
  696. } else {
  697. return Json::fail('未拉取到直播回放');
  698. }
  699. } catch (Exception $exception) {
  700. return Json::fail($exception->getMessage());
  701. }
  702. }
  703. /**回放列表
  704. * @param string $stream_name
  705. * @param string $start_time
  706. * @param string $end_time
  707. * @param int $page
  708. * @param int $limit
  709. */
  710. public function get_live_record_list()
  711. {
  712. $where = parent::getMore([
  713. ['page', 1],
  714. ['limit', 20],
  715. ['stream_name', ''],
  716. ['start_time', ''],
  717. ['end_time', ''],
  718. ]);
  719. $data = LivePlayback::getLivePlaybackList($where);
  720. return Json::successlayui($data);
  721. }
  722. /**
  723. * 删除直播回放
  724. */
  725. public function delete_live_playback($id = 0)
  726. {
  727. $res = parent::getDataModification('play_back', $id, 'is_del', 1);
  728. if ($res) {
  729. return Json::successful('删除成功');
  730. } else {
  731. return Json::fail('删除失败');
  732. }
  733. }
  734. /**设置显示
  735. * @param string $is_show
  736. * @param string $id
  737. */
  738. public function set_show($is_show = '', $id = '')
  739. {
  740. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  741. $res = parent::getDataModification('play_back', $id, 'is_show', (int)$is_show);
  742. if ($res) {
  743. return Json::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  744. } else {
  745. return Json::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  746. }
  747. }
  748. /**
  749. * 设置某个字段
  750. * @param int $stream_name
  751. * @param string $field
  752. * @param string $value
  753. */
  754. public function set_playback_value($field = '', $id = 0, $value = '')
  755. {
  756. if (!$id || !$field) return Json::fail('缺少参数');
  757. $res = parent::getDataModification('play_back', $id, $field, $value);
  758. if ($res)
  759. return Json::successful('编辑成功');
  760. else
  761. return Json::fail('编辑失败');
  762. }
  763. /**
  764. * 设置某个字段
  765. * @param int $stream_name
  766. * @param string $field
  767. * @param string $value
  768. */
  769. public function set_value($stream_name = 0, $field = '', $value = '')
  770. {
  771. if (!$stream_name || !$field) return Json::fail('缺少参数');
  772. $res = LiveStudio::where('stream_name', $stream_name)->update([$field => $value]);
  773. if ($res)
  774. return Json::successful('设置成功');
  775. else
  776. return Json::fail('设置失败');
  777. }
  778. public function set_record($stream_name = 0, $record_id = 0, $field = '', $value = '')
  779. {
  780. if (!$stream_name || !$record_id || !$field) return Json::fail('缺少参数');
  781. $res = LivePlayback::where(['stream_name' => $stream_name, 'RecordId' => $record_id])->update([$field => $value]);
  782. if ($value == 1) {
  783. LiveStudio::where(['stream_name' => $stream_name])->update(['playback_record_id' => $record_id, 'is_playback' => 1]);
  784. LivePlayback::where(['stream_name' => $stream_name])->where('RecordId', "neq", $record_id)->update([$field => 0]);
  785. } else {
  786. LiveStudio::where(['stream_name' => $stream_name])->update(['playback_record_id' => "", 'is_playback' => 0]);
  787. }
  788. if ($res)
  789. return Json::successful('设置成功');
  790. else
  791. return Json::fail('设置失败');
  792. }
  793. /**
  794. * 直播回放
  795. * @param string $record_url
  796. * @return mixed|void
  797. */
  798. public function live_record_look($record_url = '')
  799. {
  800. if (!$record_url) return $this->failed('缺少回放地址');
  801. $this->assign('record_url', $record_url);
  802. return $this->fetch();
  803. }
  804. /**
  805. * 下载引导页面
  806. * @param string $record_url
  807. * @return mixed|void
  808. */
  809. public function download($record_url = '')
  810. {
  811. if (!$record_url) return $this->failed('缺少回放地址');
  812. $this->assign('record_url', $record_url);
  813. return $this->fetch();
  814. }
  815. /**
  816. * 评论页面
  817. * @param int $special_id
  818. * @return mixed|void
  819. * @throws \think\db\exception\DataNotFoundException
  820. * @throws \think\db\exception\ModelNotFoundException
  821. * @throws \think\exception\DbException
  822. */
  823. public function comment_list($special_id = 0)
  824. {
  825. if (!$special_id) return $this->failed('缺少参数');
  826. $specialInfo = SpecialModel::get($special_id);
  827. if (!$specialInfo) return $this->failed('查找的专题不存在');
  828. if ($specialInfo->is_del) return $this->failed('专题已经删除');
  829. $liveInfo = LiveStudio::where(['special_id' => $special_id])->find();
  830. if (!$liveInfo) return $this->failed('直播不存在!');
  831. if ($liveInfo->is_del) return $this->failed('直播间已删除!');
  832. $this->assign('live_id', $liveInfo->id);
  833. return $this->fetch();
  834. }
  835. /**
  836. * 获取直播评论列表
  837. */
  838. public function get_live_comment_list()
  839. {
  840. $where = parent::getMore([
  841. ['live_id', 0],
  842. ['page', 1],
  843. ['limit', 20],
  844. ['nickname', ''],
  845. ['start_time', ''],
  846. ['end_time', ''],
  847. ]);
  848. if (!$where['live_id']) return Json::fail('缺少直播间id');
  849. return Json::successlayui(LiveBarrage::getLiveCommentList($where));
  850. }
  851. /**
  852. * 设置评论隐藏显示
  853. *
  854. * @return json
  855. */
  856. public function set_show_comment($is_show = '', $id = '')
  857. {
  858. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  859. $res = LiveBarrage::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  860. if ($res) {
  861. return Json::successful('设置成功');
  862. } else {
  863. return Json::fail('设置失败');
  864. }
  865. }
  866. /**
  867. * 任务关联列表
  868. * @param int $special_id
  869. * @return mixed|void
  870. * @throws \think\db\exception\DataNotFoundException
  871. * @throws \think\db\exception\ModelNotFoundException
  872. * @throws \think\exception\DbException
  873. */
  874. public function relation_task($special_id = 0)
  875. {
  876. $specialInfo = SpecialModel::get($special_id);
  877. if (!$specialInfo) return $this->failed('专题不存在');
  878. $liveInfo = LiveStudio::where('special_id', $special_id)->find();
  879. if (!$liveInfo) return $this->failed('直播间不存在');
  880. if ($liveInfo->is_del) return $this->failed('直播间已删除!');
  881. $this->assign('live_id', $liveInfo->id);
  882. return $this->fetch();
  883. }
  884. /**
  885. * 任务关联列表展示
  886. * @throws Exception
  887. * @throws \think\db\exception\DataNotFoundException
  888. * @throws \think\db\exception\ModelNotFoundException
  889. * @throws \think\exception\DbException
  890. */
  891. public function get_relation_task()
  892. {
  893. $where = parent::getMore([
  894. ['live_id', 0],
  895. ['title', ''],
  896. ['start_time', ''],
  897. ['end_time', ''],
  898. ['page', 1],
  899. ['limit', 20],
  900. ]);
  901. if (!$where['live_id']) return Json::fail('缺少参数');
  902. return Json::successlayui(SpecialTask::getRelationTask($where));
  903. }
  904. /**
  905. * 保存直播任务关联
  906. * @param int $live_id
  907. * @param int $special_id
  908. * @return mixed|void
  909. * @throws \think\db\exception\DataNotFoundException
  910. * @throws \think\db\exception\ModelNotFoundException
  911. * @throws \think\exception\DbException
  912. */
  913. public function save_task($live_id = 0, $special_id = 0)
  914. {
  915. if (!$live_id) return $this->failed('缺少参数');
  916. $liveInfo = LiveStudio::get($live_id);
  917. if (!$liveInfo) return $this->failed('直播间不存在');
  918. if ($special_id) {
  919. $list = SpecialCourse::where('is_show', 1)->where('special_id', $special_id)->field(['id', 'course_name'])->select();
  920. $opens = [];
  921. foreach ($list as $item) {
  922. $opens [] = ['value' => $item['id'], 'label' => $item['course_name']];
  923. }
  924. $f[] = Form::input('special_id', '专题id', $special_id)->disabled(true);
  925. $f[] = Form::input('title', '任务标题', $liveInfo->getData('live_title'));
  926. $f[] = Form::frameImageOne('image', '任务封面图', Url::build('admin/widget.images/index', array('fodder' => 'image')), $liveInfo->getData('live_image'))->icon('image')->width('100%')->height('550px');
  927. $f[] = Form::number('sort', '排序', 0);
  928. $form = Form::make_post_form('关联任务', $f, Url::build('set_task', array('live_id' => $live_id)), 3);
  929. $this->assign(compact('form'));
  930. return $this->fetch('public/form-builder');
  931. } else {
  932. $this->assign('grade_list', SpecialSubject::specialCategoryAll(1));
  933. $this->assign('live_id', $live_id);
  934. return $this->fetch();
  935. }
  936. }
  937. /**
  938. * @param int $grade_id
  939. * @throws \think\db\exception\DataNotFoundException
  940. * @throws \think\db\exception\ModelNotFoundException
  941. * @throws \think\exception\DbException
  942. */
  943. public function get_subject_list($grade_id = 0)
  944. {
  945. if (!$grade_id) return Json::fail('缺少参数');
  946. $subjectlist = SpecialSubject::where(['grade_id' => $grade_id, 'is_show' => 1, 'is_del' => 0])->order('sort desc')->select();
  947. return Json::successful($subjectlist);
  948. }
  949. /**
  950. * @param int $subject_id
  951. * @throws \think\db\exception\DataNotFoundException
  952. * @throws \think\db\exception\ModelNotFoundException
  953. * @throws \think\exception\DbException
  954. */
  955. public function get_special_list($subject_id = false, $live_goods_list = false)
  956. {
  957. $where['is_show'] = 1;
  958. $where['is_del'] = 0;
  959. if ($subject_id) $where['subject_id'] = $subject_id;
  960. if (!$live_goods_list) {
  961. $dataList = $specialList = Special::where($where)->order('sort desc')->select();
  962. } else {
  963. $dataList = array();
  964. $specialList = Special::where($where)->whereIn('type', [1, 2, 3, 5])->order('type desc')->select();
  965. foreach ($specialList as $k => $v) {
  966. $dataList[$k]['value'] = $v['id'];
  967. $dataList[$k]['title'] = SPECIAL_TYPE[$v['type']] . "--" . $v['title'];
  968. }
  969. }
  970. return Json::successful($dataList);
  971. }
  972. public function move_live_admin()
  973. {
  974. $parm = parent::getMore([
  975. 'special_id',
  976. 'admin_id'
  977. ]);
  978. if (!$parm['special_id'] || !$parm['admin_id']) {
  979. Json::fail('缺少参数');
  980. }
  981. $special_info = Special::get(['id' => $parm['special_id']]);
  982. if (!$special_info) Json::fail('直播间不存在');
  983. if ($special_info['admin_id'] == $parm['admin_id']) return Json::successful('转移成功');
  984. $special_info->save(['admin_id' => $parm['admin_id']]);
  985. return Json::successful('转移成功');
  986. }
  987. /**
  988. * 新增直播任务
  989. * @param int $live_id
  990. */
  991. public function set_task($live_id = 0)
  992. {
  993. if (!$live_id) return Json::fail('缺少直播id');
  994. $data = parent::postMore([
  995. ['coures_id', ''],
  996. ['title', ''],
  997. ['image', ''],
  998. ['sort', 0],
  999. ['is_show', 1],
  1000. ['special_id', 0]
  1001. ]);
  1002. if (!$data['special_id']) return Json::fail('关联专题Id缺失');
  1003. if (!$data['title']) return Json::fail('请输入任务标题!');
  1004. if (!$data['image']) return Json::fail('请上传图片');
  1005. $data['add_time'] = time();
  1006. $data['live_id'] = $live_id;
  1007. $special_id = LiveStudio::where('id', $live_id)->value('special_id');
  1008. $data['is_pay'] = SpecialModel::where(['type' => SPECIAL_LIVE, 'id' => $special_id])->value('pay_type');
  1009. if (SpecialTask::set($data))
  1010. return Json::successful('保存成功');
  1011. else
  1012. return Json::fail('保存失败');
  1013. }
  1014. /**直播推荐(课程)
  1015. * @return mixed
  1016. */
  1017. public function live_goods($live_id = 0, $special_id = 0)
  1018. {
  1019. $this->assign(['live_id' => $live_id, 'special_id' => $special_id]);
  1020. return $this->fetch();
  1021. }
  1022. /**添加直播的专题课程推荐
  1023. * @param int $id
  1024. * @param string $ids
  1025. */
  1026. public function add_live_special($special_id = 0, $ids = '', $type = 0)
  1027. {
  1028. if (!$special_id || !$ids) return Json::fail('参数错误');
  1029. $res = LiveGoods::saveLiveGoods($ids, $special_id, $type);
  1030. if ($res)
  1031. return Json::successful('添加成功');
  1032. else
  1033. return Json::fail('添加失败');
  1034. }
  1035. /**直播推荐列表数据
  1036. * @return mixed
  1037. */
  1038. public function live_goods_list($live_id = false)
  1039. {
  1040. $where = parent::getMore([
  1041. ['page', 1],
  1042. ['live_id', 0],
  1043. ['store_name', ""],
  1044. ['limit', 20],
  1045. ['order', ''],
  1046. ['is_show', ''],
  1047. ]);
  1048. if ($live_id) $where['live_id'] = $live_id;
  1049. return Json::successlayui(LiveGoods::getLiveGoodsList($where));
  1050. }
  1051. /**直播推荐(商品)
  1052. * @return mixed
  1053. */
  1054. public function live_store($live_id = 0, $special_id = 0)
  1055. {
  1056. $this->assign(['live_id' => $live_id, 'special_id' => $special_id]);
  1057. return $this->fetch();
  1058. }
  1059. /**直播推荐列表数据
  1060. * @return mixed
  1061. */
  1062. public function live_store_list($live_id = false)
  1063. {
  1064. $where = parent::getMore([
  1065. ['page', 1],
  1066. ['live_id', 0],
  1067. ['store_name', ""],
  1068. ['limit', 20],
  1069. ['order', ''],
  1070. ['is_show', ''],
  1071. ]);
  1072. if ($live_id) $where['live_id'] = $live_id;
  1073. return Json::successlayui(LiveGoods::getLiveStoreProductList($where));
  1074. }
  1075. /**直播打赏
  1076. * @return mixed
  1077. */
  1078. public function live_reward($live_id = 0)
  1079. {
  1080. $gold_info = SystemConfigService::more(['gold_name', 'gold_image']);
  1081. $where['l.is_del'] = 0;
  1082. $live_studio = LiveStudio::alias('l')->where($where)->join('__SPECIAL__ s', 'l.special_id = s.id')->field('l.id,l.live_title')->select();
  1083. $live_studio = $live_studio ? $live_studio->toArray() : [];
  1084. $this->assign("year", getMonth('y'));
  1085. $this->assign("live_studio", json_encode($live_studio));
  1086. $this->assign("gold_info", $gold_info);
  1087. $this->assign("live_id", $live_id);
  1088. return $this->fetch();
  1089. }
  1090. /**礼物管理
  1091. * @return mixed
  1092. */
  1093. public function live_gift()
  1094. {
  1095. $list = LiveGift::liveGiftList();
  1096. $this->assign("list", $list);
  1097. return $this->fetch();
  1098. }
  1099. /**添加礼物
  1100. * @return mixed
  1101. * @throws \FormBuilder\exception\FormBuilderException
  1102. * @throws \think\exception\DbException
  1103. */
  1104. public function create($id = 0)
  1105. {
  1106. if ($id) $gift = LiveGift::get($id);
  1107. $form = Form::create(Url::build('save', ['id' => $id]), [
  1108. Form::input('live_gift_name', '礼物名称', isset($gift) ? $gift->live_gift_name : ''),
  1109. Form::number('live_gift_price', '礼物价格(虚拟货币)', isset($gift) ? $gift->live_gift_price : '')->min(0),
  1110. Form::checkbox('live_gift_num', '赠送数量列表', isset($gift) ? json_decode($gift->live_gift_num) : [])->options([
  1111. ['label' => '1', 'value' => 1],
  1112. ['label' => '5', 'value' => 5],
  1113. ['label' => '10', 'value' => 10],
  1114. ['label' => '20', 'value' => 20],
  1115. ['label' => '66', 'value' => 66],
  1116. ['label' => '99', 'value' => 99],
  1117. ['label' => '520', 'value' => 520],
  1118. ['label' => '999', 'value' => 999],
  1119. ['label' => '1314', 'value' => 1314]
  1120. ]),
  1121. Form::frameImageOne('live_gift_show_img', '图标(100*100px)', Url::build('admin/widget.images/index', array('fodder' => 'live_gift_show_img')), isset($gift) ? $gift->live_gift_show_img : '')->icon('image')->width('70%')->height('500px'),
  1122. Form::number('sort', '排序', isset($gift) ? $gift->sort : 0)->min(0)->max(99999),
  1123. Form::radio('is_show', '状态', isset($gift) ? $gift->is_show : 1)->options([['label' => '显示', 'value' => 1], ['label' => '隐藏', 'value' => 0]])
  1124. ]);
  1125. $form->setMethod('post')->setTitle($id ? '修改礼物' : '添加礼物')->setSuccessScript('parent.layer.close(parent.layer.getFrameIndex(window.name));parent.$(".J_iframe:visible")[0].contentWindow.location.reload()');
  1126. $this->assign(compact('form'));
  1127. return $this->fetch('public/form-builder');
  1128. }
  1129. /**
  1130. * 保存数据
  1131. */
  1132. public function save($id)
  1133. {
  1134. $post = parent::postMore([
  1135. ['live_gift_name', ''],
  1136. ['live_gift_price', 0],
  1137. ['live_gift_num', []],
  1138. ['live_gift_show_img', ''],
  1139. ['is_show', 1],
  1140. ['sort', 0],
  1141. ]);
  1142. if (!$post['live_gift_name']) return Json::fail('请输入礼物名称');
  1143. if (bcsub($post['live_gift_price'], 0, 0) <= 0) return Json::fail('请输入礼物价格');
  1144. if (count($post['live_gift_num']) < 1) return Json::fail('请选择赠送数量列表');
  1145. if (!$post['live_gift_show_img']) return Json::fail('请选择礼物图标');
  1146. $post['live_gift_num'] = json_encode($post['live_gift_num']);
  1147. $post['add_time'] = time();
  1148. if (!$id) {
  1149. $res = LiveGift::set($post);
  1150. if ($res) {
  1151. return Json::successful('添加成功');
  1152. } else {
  1153. return Json::fail('添加失败');
  1154. }
  1155. } else {
  1156. $res = LiveGift::edit($post, $id);
  1157. if ($res) {
  1158. return Json::successful('修改成功');
  1159. } else {
  1160. return Json::fail('修改失败');
  1161. }
  1162. }
  1163. }
  1164. /**礼物是否显示快捷操作
  1165. * @param string $is_show
  1166. * @param string $id
  1167. * @return mixed
  1168. */
  1169. public function set_gift_show($is_show = '', $id = '')
  1170. {
  1171. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  1172. $res = LiveGift::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  1173. if ($res) {
  1174. return Json::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  1175. } else {
  1176. return Json::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  1177. }
  1178. }
  1179. /**
  1180. * 直播礼物列表
  1181. */
  1182. public function live_gift_list()
  1183. {
  1184. return Json::successlayui(LiveGift::liveGiftList());
  1185. }
  1186. /**直播礼物
  1187. * @throws \think\db\exception\DataNotFoundException
  1188. * @throws \think\db\exception\ModelNotFoundException
  1189. * @throws \think\exception\DbException
  1190. */
  1191. public function liveGiftList()
  1192. {
  1193. $data = LiveGift::order('sort DESC,id DESC')->select();
  1194. return Json::successful($data);
  1195. }
  1196. /**直播推荐列表数据
  1197. * @return mixed
  1198. */
  1199. public function live_reward_list()
  1200. {
  1201. $where = parent::getMore([
  1202. ['page', 1],
  1203. ['user_info', ""],
  1204. ['limit', 20],
  1205. ['order', ''],
  1206. ['live_id', 0],
  1207. ['gift_id', 0],
  1208. ['date', 0],
  1209. ]);
  1210. //根据账号身份获取各自的列表数据
  1211. $role_sign = get_login_role();
  1212. if (isset($role_sign['role_sign']) && $role_sign['role_sign'] == "anchor") {
  1213. $where['admin_id'] = get_login_id()['admin_id'];
  1214. }
  1215. return Json::successlayui(LiveReward::getLiveRewardList($where));
  1216. }
  1217. /**
  1218. * 获取头部订单金额等信息
  1219. * return json
  1220. */
  1221. public function getBadge()
  1222. {
  1223. $where = parent::postMore([
  1224. ['page', 1],
  1225. ['user_info', ''],
  1226. ['limit', 20],
  1227. ['order', ''],
  1228. ['live_id', 0],
  1229. ['gift_id', 0],
  1230. ['date', 0],
  1231. ]);
  1232. return Json::successful(LiveReward::getBadge($where));
  1233. }
  1234. }