StoreProductReply.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\store;
  12. use app\admin\controller\AuthController;
  13. use traits\CurdControllerTrait;
  14. use service\JsonService as Json;
  15. use service\UploadService as Upload;
  16. use think\Request;
  17. use app\admin\model\store\StoreProductReply as ProductReplyModel;
  18. use app\admin\model\store\StoreProduct;
  19. use think\Url;
  20. /**
  21. * 评论管理 控制器
  22. * Class StoreProductReply
  23. * @package app\admin\controller\store
  24. */
  25. class StoreProductReply extends AuthController
  26. {
  27. use CurdControllerTrait;
  28. /**
  29. * 显示资源列表
  30. * @return \think\Response
  31. */
  32. public function index($product_id = 0)
  33. {
  34. $this->assign('product_id', $product_id);
  35. return $this->fetch();
  36. }
  37. /**
  38. * 评论列表
  39. */
  40. public function productReplyList()
  41. {
  42. $where = parent::getMore([
  43. ['page', 1],
  44. ['limit', 20],
  45. ['store_name', ''],
  46. ['is_reply', ''],
  47. ['product_id', 0],
  48. ['title', ''],
  49. ['comment', '']
  50. ], $this->request);
  51. return Json::successlayui(ProductReplyModel::storeProductReplyList($where));
  52. }
  53. /**
  54. * @param $id
  55. * @return \think\response\Json|void
  56. */
  57. public function delete($id)
  58. {
  59. if (!$id) return $this->failed('数据不存在');
  60. $data['is_del'] = 1;
  61. if (!ProductReplyModel::edit($data, $id))
  62. return Json::fail(ProductReplyModel::getErrorInfo('删除失败,请稍候再试!'));
  63. else
  64. return Json::successful('删除成功!');
  65. }
  66. /**评论回复
  67. * @param Request $request
  68. */
  69. public function set_reply(Request $request)
  70. {
  71. $data = parent::postMore([
  72. 'id',
  73. 'content',
  74. ], $request);
  75. if (!$data['id']) return Json::fail('参数错误');
  76. if ($data['content'] == '') return Json::fail('请输入回复内容');
  77. $save['merchant_reply_content'] = $data['content'];
  78. $save['merchant_reply_time'] = time();
  79. $save['is_reply'] = 1;
  80. $res = ProductReplyModel::edit($save, $data['id']);
  81. if (!$res)
  82. return Json::fail(ProductReplyModel::getErrorInfo('回复失败,请稍候再试!'));
  83. else
  84. return Json::successful('回复成功!');
  85. }
  86. /**回复加精
  87. * @param int $id
  88. */
  89. public function refining_reply($id = 0)
  90. {
  91. if (!$id) return Json::fail('参数错误');
  92. $save['is_selected'] = 1;
  93. $res = ProductReplyModel::edit($save, $id);
  94. if (!$res)
  95. return Json::fail(ProductReplyModel::getErrorInfo('加精失败,请稍候再试!'));
  96. else
  97. return Json::successful('加精成功!');
  98. }
  99. /**
  100. * 创建虚拟评论
  101. *
  102. * */
  103. public function create_false()
  104. {
  105. $this->assign('list', StoreProduct::PreWhere()->field('id,store_name')->select());
  106. return $this->fetch();
  107. }
  108. /**
  109. * 提交虚拟评论
  110. */
  111. public function save_false()
  112. {
  113. $data = parent::postMore([
  114. ['nickname', 0],
  115. ['avatar', ''],
  116. ['product_id', 0],
  117. ['product_score', 1],
  118. ['service_score', 1],
  119. ['delivery_score', 1],
  120. ['comment', ''],
  121. ['pics', []]
  122. ]);
  123. $data['type'] = 1;
  124. $banner = [];
  125. foreach ($data['pics'] as $item) {
  126. $banner[] = $item['pic'];
  127. }
  128. if (!$data['nickname']) return Json::fail('请输入昵称');
  129. if (!$data['avatar']) return Json::fail('请上传头像');
  130. if (!$data['product_id']) return Json::fail('请选择商品');
  131. if (!$data['comment']) return Json::fail('请编辑评论内容');
  132. $res = ProductReplyModel::helpeFalse($data, $banner);
  133. if ($res === false)
  134. return Json::fail(ProductReplyModel::getErrorInfo());
  135. else
  136. return Json::successful('虚拟评论成功');
  137. }
  138. public function productList()
  139. {
  140. $list = StoreProduct::PreWhere()->field('id,store_name')->select();
  141. return Json::successful($list);
  142. }
  143. /**
  144. * 快速编辑
  145. * @param string $field 字段名
  146. * @param int $id 修改的主键
  147. * @param string value 修改后的值
  148. * @return json
  149. */
  150. public function set_value($field = '', $id = '', $value = '')
  151. {
  152. if (!$field || !$id || $value == '') Json::fail('缺少参数3');
  153. $res = ProductReplyModel::where('id', $id)->update([$field => $value]);
  154. if ($res)
  155. return Json::successful('保存成功');
  156. else
  157. return Json::fail('保存失败');
  158. }
  159. }