VideoComment.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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\store\marketing\video;
  12. use app\controller\store\AuthController;
  13. use app\services\activity\video\VideoCommentServices;
  14. use think\db\exception\DbException;
  15. use think\facade\App;
  16. /**
  17. * 视频评论控制器
  18. * Class VideoComment
  19. * @package app\controller\store\marketing\video
  20. */
  21. class VideoComment extends AuthController
  22. {
  23. /**
  24. * VideoComment constructor.
  25. * @param App $app
  26. * @param VideoCommentServices $service
  27. */
  28. public function __construct(App $app, VideoCommentServices $service)
  29. {
  30. parent::__construct($app);
  31. $this->services = $service;
  32. }
  33. /**
  34. * 显示资源列表
  35. *
  36. * @return \think\Response
  37. */
  38. public function index()
  39. {
  40. $where = $this->request->getMore([
  41. ['is_reply', ''],
  42. ['keyword', ''],
  43. ['data', '', '', 'time'],
  44. ['video_id', 0]
  45. ]);
  46. $where['type'] = 1;
  47. $where['relation_id'] = $this->storeId;
  48. $list = $this->services->sysPage($where);
  49. return $this->success($list);
  50. }
  51. /**
  52. * 获取评论回复列表
  53. * @param $id
  54. * @return mixed
  55. * @throws DbException
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. */
  59. public function getCommentReply($id)
  60. {
  61. if (!$id) {
  62. return $this->fail('缺少参数');
  63. }
  64. $time = $this->request->get('data', '');
  65. return $this->success($this->services->getCommentReplyList((int)$id, ['time' =>$time]));
  66. }
  67. /**
  68. * 管理员回复评论
  69. * @param $id
  70. * @return mixed
  71. */
  72. public function setReply($id)
  73. {
  74. [$content] = $this->request->postMore([
  75. ['content', '']
  76. ], true);
  77. $this->services->setReply($id, $content);
  78. return $this->success('回复成功!');
  79. }
  80. /**
  81. * 获取管理员评论
  82. * @param $id
  83. * @return mixed
  84. */
  85. public function getReply($id)
  86. {
  87. if (!$id) {
  88. return $this->fail('缺少参数');
  89. }
  90. $where = ['pid' => $id, 'uid' => 0];
  91. $commentInfo = $this->dao->get($where);
  92. if ($commentInfo) {
  93. return $this->success($commentInfo->toArray());
  94. } else {
  95. return $this->success(['content' => '']);
  96. }
  97. }
  98. /**
  99. * 创建自评表单
  100. * @return mixed
  101. * @throws \FormBuilder\Exception\FormBuilderException
  102. */
  103. public function fictitiousComment()
  104. {
  105. [$video_id] = $this->request->postMore([
  106. ['video_id', 0],
  107. ], true);
  108. return $this->success($this->services->createForm((int)$video_id, (int)$this->storeId));
  109. }
  110. /**
  111. * 保存自评
  112. * @return mixed
  113. */
  114. public function saveFictitiousComment()
  115. {
  116. $data = $this->request->postMore([
  117. ['video', ''],
  118. ['nickname', ''],
  119. ['avatar', ''],
  120. ['content', ''],
  121. ['video_id', 0],
  122. ['add_time', 0]
  123. ]);
  124. if (!$data['video_id']) {
  125. $data['video_id'] = $data['video']['video_id'] ?? '';
  126. }
  127. $video_id = (int)$data['video_id'];
  128. unset($data['video_id'], $data['video']);
  129. $data['ip'] = $this->request->ip();
  130. $this->services->saveComment(0, $video_id, 0, $data);
  131. return $this->success('添加成功!');
  132. }
  133. /**
  134. * 删除评论
  135. * @param $id
  136. * @return mixed
  137. */
  138. public function delete($id)
  139. {
  140. if (!$id) {
  141. return $this->fail('缺少参数');
  142. }
  143. $this->services->update($id, ['is_del' => 1]);
  144. $this->services->update(['pid' => $id], ['is_del' => 1]);
  145. return $this->success('删除成功');
  146. }
  147. }