BroadcastRoom.php 5.4 KB

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