VideoComment.php 5.0 KB

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