LiveroomController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\LiveRoom;
  5. use app\model\LiveAnchor;
  6. class LiveroomController extends Base
  7. {
  8. function index()
  9. {
  10. $weid = weid();
  11. $keyword = input('post.keyword', '', 'serach_in');
  12. $query = LiveRoom::where(['weid' => $weid]);
  13. if (!empty($keyword)) {
  14. $query->where('name', 'like', '%' . $keyword . '%');
  15. }
  16. $res = $query->order('sort asc,id asc')
  17. ->paginate(getpage())
  18. ->toArray();
  19. foreach ($res['data'] as &$vo) {
  20. $vo['anchor'] = LiveAnchor::getAnchor($vo['anchor_id']);
  21. $vo['start_time'] = time_format($vo['start_time']);
  22. }
  23. $data['data'] = $res;
  24. return $this->json($data);
  25. }
  26. function listUpdate()
  27. {
  28. $data = only('id,status,sort');
  29. if (!$data['id']) throw new ValidateException('参数错误');
  30. LiveRoom::update($data);
  31. return $this->json(['msg' => '操作成功']);
  32. }
  33. public function update()
  34. {
  35. $id = $this->request->post('id');
  36. $data = input('post.');
  37. unset($data['create_time']);
  38. $data['end_time'] = strtotime($data['start_time'].' +20 hour');
  39. $data['start_time'] = strtotime($data['start_time']);
  40. if (empty($data['room_id'])) {
  41. $LiveAnchor = LiveAnchor::getAnchor($data['anchor_id']);
  42. $createRoom = [
  43. 'startTime' => $data['start_time'],
  44. 'endTime' => is_string($data['end_time']) ? strtotime($data['end_time']) : $data['end_time'],
  45. 'name' => $data['name'],
  46. 'anchorName' => $LiveAnchor['name'],
  47. 'anchorWechat' => $LiveAnchor['wechat'],
  48. 'screenType' => $data['screen_type'],
  49. 'closeGoods' => $data['close_goods'] == 1 ? 0 : 1,
  50. 'closeLike' => $data['close_like'] == 1 ? 0 : 1,
  51. 'closeComment' => $data['close_comment'] == 1 ? 0 : 1,
  52. 'closeReplay' => $data['replay_status'] == 1 ? 0 : 1,
  53. 'type' => $data['type'],
  54. 'coverImg' => $data['cover_img'],
  55. 'shareImg' => $data['share_img'],
  56. 'closekf' => 1
  57. ];
  58. $createRoomres = Author()::createLiveRoom($createRoom);
  59. if(!empty($createRoomres['roomId'])){
  60. $data['room_id'] = $createRoomres['roomId'];
  61. }else{
  62. throw new ValidateException($createRoomres);
  63. }
  64. }
  65. if (empty($id)) {
  66. $data['weid'] = weid();
  67. try {
  68. $res = LiveRoom::create($data);
  69. if ($res->id && empty($data['sort'])) {
  70. LiveRoom::update(['sort' => $res->id, 'id' => $res->id]);
  71. }
  72. } catch (\Exception $e) {
  73. throw new ValidateException($e->getMessage());
  74. }
  75. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  76. } else {
  77. try {
  78. LiveRoom::update($data);
  79. } catch (\Exception $e) {
  80. throw new ValidateException($e->getMessage());
  81. }
  82. return $this->json(['msg' => '修改成功']);
  83. }
  84. }
  85. function getInfo()
  86. {
  87. $id = $this->request->post('id', '', 'serach_in');
  88. if (!$id) throw new ValidateException('参数错误');
  89. $data = LiveRoom::field('*')->find($id)->toArray();
  90. $data['start_time'] = time_format($data['start_time']);
  91. return $this->json(['data' => $data]);
  92. }
  93. function delete()
  94. {
  95. return $this->del(new LiveRoom());
  96. }
  97. function getField()
  98. {
  99. $data['anchorarray'] = LiveAnchor::getpagearray();
  100. return $this->json(['data' => $data]);
  101. }
  102. }