BroadcastRoom.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace app\controller\merchant\store\broadcast;
  3. use app\common\repositories\store\broadcast\BroadcastRoomGoodsRepository;
  4. use app\common\repositories\store\broadcast\BroadcastRoomRepository;
  5. use app\validate\merchant\BroadcastRoomValidate;
  6. use ln\basic\BaseController;
  7. use think\App;
  8. class BroadcastRoom extends BaseController
  9. {
  10. protected $repository;
  11. public function __construct(App $app, BroadcastRoomRepository $repository)
  12. {
  13. parent::__construct($app);
  14. $this->repository = $repository;
  15. }
  16. public function lst()
  17. {
  18. [$page, $limit] = $this->getPage();
  19. $where = $this->request->params(['keyword', 'status_tag', 'show_tag', 'show_type','live_status','broadcast_room_id']);
  20. return app('json')->success($this->repository->getList($this->request->merId(), $where, $page, $limit));
  21. }
  22. /**
  23. * @param BroadcastRoomGoodsRepository $repository
  24. * @param $id
  25. * @return \think\response\Json
  26. * @author zfy
  27. * @day 2020/8/31
  28. */
  29. public function goodsList(BroadcastRoomGoodsRepository $repository, $id)
  30. {
  31. [$page, $limit] = $this->getPage();
  32. if (!$this->repository->merExists((int)$id, $this->request->merId()))
  33. return app('json')->fail('直播间不存在');
  34. return app('json')->success($repository->getGoodsList($id, $page, $limit));
  35. }
  36. public function detail($id)
  37. {
  38. if (!$this->repository->merExists($id, $this->request->merId()))
  39. return app('json')->fail('数据不存在');
  40. return app('json')->success($this->repository->get($id)->toArray());
  41. }
  42. public function createForm()
  43. {
  44. return app('json')->success(formToData($this->repository->createForm()));
  45. }
  46. public function updateForm($id)
  47. {
  48. if (!$this->repository->merExists($id, $this->request->merId()))
  49. return app('json')->fail('数据不存在');
  50. if (!$this->repository->existsWhere(['broadcast_room_id' => $id, 'status' => [-1, 0]]))
  51. return app('json')->fail('当前直播间不能修改');
  52. return app('json')->success(formToData($this->repository->updateForm(intval($id))));
  53. }
  54. public function create()
  55. {
  56. $this->repository->create($this->request->merId(), $this->checkParams());
  57. return app('json')->success('创建成功');
  58. }
  59. public function update($id)
  60. {
  61. if (!$this->repository->merExists($id, $this->request->merId()))
  62. return app('json')->fail('数据不存在');
  63. if (!$this->repository->existsWhere(['broadcast_room_id' => $id, 'status' => [-1, 0]]))
  64. return app('json')->fail('当前直播间不能修改');
  65. $this->repository->updateRoom($this->request->merId(), $id, $this->checkParams());
  66. return app('json')->success('修改成功');
  67. }
  68. public function checkParams()
  69. {
  70. $validate = app()->make(BroadcastRoomValidate::class);
  71. $data = $this->request->params(['name', 'cover_img', 'share_img', 'anchor_name', 'anchor_wechat', 'phone', 'start_time', 'type', 'screen_type', 'close_like', 'close_goods', 'close_comment', 'replay_status', 'close_share', 'close_kf']);
  72. $validate->check($data);
  73. [$data['start_time'], $data['end_time']] = $data['start_time'];
  74. return $data;
  75. }
  76. public function changeStatus($id)
  77. {
  78. $isShow = $this->request->param('is_show') == 1 ? 1 : 0;
  79. if (!$this->repository->merExists($id, $this->request->merId()))
  80. return app('json')->fail('数据不存在');
  81. $this->repository->isShow($id, $isShow);
  82. return app('json')->success('修改成功');
  83. }
  84. public function mark($id)
  85. {
  86. $mark = (string)$this->request->param('mark');
  87. if (!$this->repository->merExists($id, $this->request->merId()))
  88. return app('json')->fail('数据不存在');
  89. $this->repository->mark($id, $mark);
  90. return app('json')->success('修改成功');
  91. }
  92. public function exportGoods()
  93. {
  94. [$ids, $roomId] = $this->request->params(['ids', 'room_id'], true);
  95. if (!count($ids)) return app('json')->fail('请选择直播商品');
  96. $this->repository->exportGoods($this->request->merId(), (array)$ids, $roomId);
  97. return app('json')->success('导入成功');
  98. }
  99. public function rmExportGoods()
  100. {
  101. [$id, $roomId] = $this->request->params(['id', 'room_id'], true);
  102. $this->repository->rmExportGoods($this->request->merId(), intval($roomId), intval($id));
  103. return app('json')->success('删除成功');
  104. }
  105. public function delete($id)
  106. {
  107. if (!$this->repository->merExists($id, $this->request->merId()))
  108. return app('json')->fail('数据不存在');
  109. $this->repository->merDelete((int)$id);
  110. return app('json')->success('删除成功');
  111. }
  112. }