StoreProductReply.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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\merchant\controller\store;
  12. use app\merchant\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\merchant\model\store\StoreProductReply as ProductReplyModel;
  18. use app\merchant\model\store\StoreProduct;
  19. use think\Url;
  20. /**
  21. * 评论管理 控制器
  22. * Class StoreProductReply
  23. * @package app\merchant\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. $where['mer_id'] = $this->merchantId;
  52. return Json::successlayui(ProductReplyModel::storeProductReplyList($where));
  53. }
  54. /**
  55. * @param $id
  56. * @return \think\response\Json|void
  57. */
  58. public function delete($id)
  59. {
  60. if (!$id) return $this->failed('数据不存在');
  61. $data['is_del'] = 1;
  62. if (!ProductReplyModel::edit($data, $id))
  63. return Json::fail(ProductReplyModel::getErrorInfo('删除失败,请稍候再试!'));
  64. else
  65. return Json::successful('删除成功!');
  66. }
  67. /**评论回复
  68. * @param Request $request
  69. */
  70. public function set_reply(Request $request)
  71. {
  72. $data = parent::postMore([
  73. 'id',
  74. 'content',
  75. ], $request);
  76. if (!$data['id']) return Json::fail('参数错误');
  77. if ($data['content'] == '') return Json::fail('请输入回复内容');
  78. $save['merchant_reply_content'] = $data['content'];
  79. $save['merchant_reply_time'] = time();
  80. $save['is_reply'] = 1;
  81. $res = ProductReplyModel::edit($save, $data['id']);
  82. if (!$res)
  83. return Json::fail(ProductReplyModel::getErrorInfo('回复失败,请稍候再试!'));
  84. else
  85. return Json::successful('回复成功!');
  86. }
  87. /**回复加精
  88. * @param int $id
  89. */
  90. public function refining_reply($id = 0)
  91. {
  92. if (!$id) return Json::fail('参数错误');
  93. $save['is_selected'] = 1;
  94. $res = ProductReplyModel::edit($save, $id);
  95. if (!$res)
  96. return Json::fail(ProductReplyModel::getErrorInfo('加精失败,请稍候再试!'));
  97. else
  98. return Json::successful('加精成功!');
  99. }
  100. /**
  101. * 创建虚拟评论
  102. *
  103. * */
  104. public function create_false()
  105. {
  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()->where('mer_id', $this->merchantId)->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. }