LiveRoom.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\marketing\live;
  12. use app\controller\admin\AuthController;
  13. use app\services\activity\live\LiveRoomServices;
  14. use think\facade\App;
  15. /**
  16. * 直播间
  17. * Class LiveRoom
  18. * @package app\controller\admin\v1\marketing\live
  19. */
  20. class LiveRoom extends AuthController
  21. {
  22. /**
  23. * LiveRoom constructor.
  24. * @param App $app
  25. * @param LiveRoomServices $services
  26. */
  27. public function __construct(App $app, LiveRoomServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. public function list()
  33. {
  34. $where = $this->request->postMore([
  35. ['kerword', ''],
  36. ['status', '']
  37. ]);
  38. return app('json')->success($this->services->getList($where));
  39. }
  40. public function detail($id)
  41. {
  42. if (!$id)
  43. return app('json')->fail('数据不存在');
  44. return app('json')->success('ok', $this->services->get((int)$id)->toArray());
  45. }
  46. public function add()
  47. {
  48. $data = $this->request->postMore([
  49. ['name', ''],
  50. ['cover_img', ''],
  51. ['share_img', ''],
  52. ['anchor_name', ''],
  53. ['anchor_wechat', ''],
  54. ['phone', ''],
  55. ['start_time', ['', '']],
  56. ['type', 1],
  57. ['screen_type', 1],
  58. ['close_like', 0],
  59. ['close_goods', 0],
  60. ['close_comment', 0],
  61. ['replay_status', 1],
  62. ['sort', 0]
  63. ]);
  64. if (!$data['name']) return app('json')->fail('请输入名称');
  65. if (!$data['cover_img']) return app('json')->fail('请选择背景图');
  66. if (!$data['share_img']) return app('json')->fail('请选择分享图');
  67. if (!$data['anchor_wechat']) return app('json')->fail('请选择主播');
  68. if (!$data['start_time'] || count($data['start_time']) != 2) return app('json')->fail('请选择直播开始、结束时间');
  69. if (!$data['phone'] || !check_phone($data['phone'])) return app('json')->fail('请输入正确手机号');
  70. [$data['start_time'], $data['end_time']] = $data['start_time'];
  71. $this->services->add($data);
  72. return app('json')->success('添加成功');
  73. }
  74. public function addGoods()
  75. {
  76. [$room_id, $goods_ids] = $this->request->postMore([
  77. ['room_id', 0],
  78. ['goods_ids', []]
  79. ], true);
  80. if (!$room_id) return app('json')->fail('请选择直播间');
  81. if (!$goods_ids) return app('json')->fail('请选择商品');
  82. $this->services->exportGoods((int)$room_id, $goods_ids);
  83. return app('json')->success('添加商品成功');
  84. }
  85. public function apply($id)
  86. {
  87. [$status, $msg] = $this->request->postMore([
  88. ['status', ''],
  89. ['msg', '']
  90. ], true);
  91. if (!$id)
  92. return app('json')->fail('数据不存在');
  93. $status = $status == 1 ? 1 : -1;
  94. if ($status == -1 && !$msg)
  95. return app('json')->fail('请输入理由');
  96. $this->services->apply((int)$id, $status, $msg);
  97. return app('json')->success('操作成功');
  98. }
  99. public function setShow($id, $is_show)
  100. {
  101. if (!$id)
  102. return app('json')->fail('数据不存在');
  103. return app('json')->success($this->services->isShow((int)$id, $is_show));
  104. }
  105. public function delete($id)
  106. {
  107. if (!$id)
  108. return app('json')->fail('数据不存在');
  109. $this->services->delete($id);
  110. return app('json')->success('删除成功');
  111. }
  112. public function syncRoom()
  113. {
  114. $this->services->syncRoomStatus();
  115. return app('json')->success('同步成功');
  116. }
  117. }