StoreProductReply.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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\product;
  12. use app\controller\admin\AuthController;
  13. use app\services\product\product\StoreProductReplyCommentServices;
  14. use app\services\product\product\StoreProductReplyServices;
  15. use think\db\exception\DataNotFoundException;
  16. use think\db\exception\DbException;
  17. use think\db\exception\ModelNotFoundException;
  18. use think\facade\App;
  19. /**
  20. * 评论管理 控制器
  21. * Class StoreProductReply
  22. * @package app\controller\admin\v1\store
  23. */
  24. class StoreProductReply extends AuthController
  25. {
  26. /**
  27. * StoreProductReply constructor.
  28. * @param App $app
  29. * @param StoreProductReplyServices $service
  30. */
  31. public function __construct(App $app, StoreProductReplyServices $service)
  32. {
  33. parent::__construct($app);
  34. $this->services = $service;
  35. }
  36. /**
  37. * 显示资源列表
  38. *
  39. * @return \think\Response
  40. */
  41. public function index()
  42. {
  43. $where = $this->request->getMore([
  44. ['is_reply', ''],
  45. ['store_name', ''],
  46. ['account', ''],
  47. ['data', ''],
  48. ['product_id', 0]
  49. ]);
  50. $where['type'] = 0;
  51. $where['relation_id'] = 0;
  52. $list = $this->services->sysPage($where);
  53. return $this->success($list);
  54. }
  55. /**
  56. * 删除评论
  57. * @param $id
  58. * @return mixed
  59. */
  60. public function delete($id)
  61. {
  62. $this->services->del($id);
  63. return $this->success('删除成功!');
  64. }
  65. /**
  66. * 管理员回复评论
  67. * @param $id
  68. * @return mixed
  69. */
  70. public function set_reply($id)
  71. {
  72. [$content] = $this->request->postMore([
  73. ['content', '']
  74. ], true);
  75. $this->services->setReply($id, $content);
  76. return $this->success('回复成功!');
  77. }
  78. /**
  79. * 获取管理员评论
  80. * @param StoreProductReplyCommentServices $services
  81. * @param $id
  82. * @return mixed
  83. */
  84. public function getReply(StoreProductReplyCommentServices $services, $id)
  85. {
  86. if (!$id) {
  87. return $this->fail('缺少参数');
  88. }
  89. $where = ['reply_id' => $id, 'uid' => 0, 'relation_id' => 0];
  90. $commentInfo = $services->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 fictitious_reply()
  103. {
  104. [$product_id] = $this->request->postMore([
  105. ['product_id', 0],
  106. ], true);
  107. return $this->success($this->services->createForm($product_id));
  108. }
  109. /**
  110. * 保存自评
  111. * @return mixed
  112. */
  113. public function save_fictitious_reply()
  114. {
  115. $data = $this->request->postMore([
  116. ['image', ''],
  117. ['nickname', ''],
  118. ['avatar', ''],
  119. ['comment', ''],
  120. ['pics', []],
  121. ['product_score', 0],
  122. ['service_score', 0],
  123. ['product_id', 0],
  124. ['unique', '', '', 'sku_unique'],
  125. ['add_time', 0]
  126. ]);
  127. if (!$data['product_id']) {
  128. $data['product_id'] = $data['image']['product_id'] ?? '';
  129. }
  130. $this->validate(['product_id' => $data['product_id'], 'nickname' => $data['nickname'], 'avatar' => $data['avatar'], 'comment' => $data['comment'], 'product_score' => $data['product_score'], 'service_score' => $data['service_score']], \app\validate\admin\product\StoreProductReplyValidate::class, 'save');
  131. $this->services->saveReply($data);
  132. return $this->success('添加成功!');
  133. }
  134. /**
  135. * 获取评论回复列表
  136. * @param StoreProductReplyCommentServices $services
  137. * @param $id
  138. * @return mixed
  139. * @throws DataNotFoundException
  140. * @throws DbException
  141. * @throws ModelNotFoundException
  142. */
  143. public function getComment(StoreProductReplyCommentServices $services, $id)
  144. {
  145. if (!$id) {
  146. return $this->fail('缺少参数');
  147. }
  148. $time = $this->request->get('time', '');
  149. return $this->success($services->getReplCommenList((int)$id, $time));
  150. }
  151. /**
  152. * 管理员二级回复
  153. * @param StoreProductReplyCommentServices $services
  154. * @param $replyId
  155. * @param $id
  156. * @return mixed
  157. */
  158. public function saveComment(StoreProductReplyCommentServices $services, $replyId, $id)
  159. {
  160. if (!$id) {
  161. return $this->fail('缺少参数');
  162. }
  163. $data = $this->request->postMore([
  164. ['content', ''],
  165. ]);
  166. if (!$data['content']) {
  167. return app('json')->fail('缺少回复内容');
  168. }
  169. $data['reply_id'] = $replyId;
  170. $data['create_time'] = time();
  171. $data['uid'] = 0;
  172. $data['pid'] = $id;
  173. $where = ['uid' => 0, 'pid' => $id, 'reply_id' => $replyId];
  174. if ($services->count($where)) {
  175. $services->update($where, ['content' => $data['content'], 'update_time' => time()]);
  176. } else {
  177. $services->save($data);
  178. }
  179. return $this->success('保存成功');
  180. }
  181. /**
  182. * 删除用户回复
  183. * @param StoreProductReplyCommentServices $services
  184. * @param $id
  185. * @return mixed
  186. */
  187. public function deleteComment(StoreProductReplyCommentServices $services, $id)
  188. {
  189. if (!$id) {
  190. return $this->fail('缺少参数');
  191. }
  192. $services->transaction(function () use ($id, $services) {
  193. $services->delete($id);
  194. $services->delete(['pid' => $id]);
  195. });
  196. return $this->success('删除成功');
  197. }
  198. }