StoreProductReply.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. namespace app\admin\controller\store;
  3. use app\admin\controller\AuthController;
  4. use app\models\store\StoreOrder;
  5. use crmeb\traits\CurdControllerTrait;
  6. use think\facade\Route as Url;
  7. use app\admin\model\store\StoreProductReply as ProductReplyModel;
  8. use crmeb\services\{
  9. FormBuilder as Form, JsonService as Json, UtilService as Util
  10. };
  11. /**
  12. * 评论管理 控制器
  13. * Class StoreProductReply
  14. * @package app\admin\controller\store
  15. */
  16. class StoreProductReply extends AuthController
  17. {
  18. use CurdControllerTrait;
  19. /**
  20. * 显示资源列表
  21. *
  22. * @return \think\Response
  23. */
  24. public function index()
  25. {
  26. $product_id = input('product_id');
  27. if (!$product_id) $product_id = 0;
  28. $this->assign('is_layui', true);
  29. $this->assign('product_id', (int)$product_id);
  30. return $this->fetch();
  31. }
  32. public function get_product_imaes_list()
  33. {
  34. $where = Util::getMore([
  35. ['page', 1],
  36. ['limit', 10],
  37. ['title', ''],
  38. ['is_reply', ''],
  39. ['product_name', ''],
  40. ['product_id', 0],
  41. ]);
  42. return Json::successful(ProductReplyModel::getProductImaesList($where));
  43. }
  44. public function get_product_reply_list()
  45. {
  46. $where = Util::getMore([
  47. ['limit', 10],
  48. ['title', ''],
  49. ['is_reply', ''],
  50. ['message_page', 1],
  51. ['producr_id', 0],
  52. ['order_id', ''],
  53. ['nickname', ''],
  54. ['score_type', ''],
  55. ]);
  56. return Json::successful(ProductReplyModel::getProductReplyList($where));
  57. }
  58. /**
  59. * @param $id
  60. * @return \think\response\Json|void
  61. */
  62. public function delete($id)
  63. {
  64. if (!$id) return $this->failed('数据不存在');
  65. $data['is_del'] = 1;
  66. if (!ProductReplyModel::edit($data, $id))
  67. return Json::fail(ProductReplyModel::getErrorInfo('删除失败,请稍候再试!'));
  68. else
  69. return Json::successful('删除成功!');
  70. }
  71. public function set_reply()
  72. {
  73. $data = Util::postMore([
  74. 'id',
  75. 'content',
  76. ]);
  77. if (!$data['id']) return Json::fail('参数错误');
  78. if ($data['content'] == '') return Json::fail('请输入回复内容');
  79. $save['merchant_reply_content'] = $data['content'];
  80. $save['merchant_reply_time'] = time();
  81. $save['is_reply'] = 2;
  82. $res = ProductReplyModel::edit($save, $data['id']);
  83. if (!$res)
  84. return Json::fail(ProductReplyModel::getErrorInfo('回复失败,请稍候再试!'));
  85. else
  86. return Json::successful('回复成功!');
  87. }
  88. public function edit_reply()
  89. {
  90. $data = Util::postMore([
  91. 'id',
  92. 'content',
  93. ]);
  94. if (!$data['id']) return Json::fail('参数错误');
  95. if ($data['content'] == '') return Json::fail('请输入回复内容');
  96. $save['merchant_reply_content'] = $data['content'];
  97. $save['merchant_reply_time'] = time();
  98. $save['is_reply'] = 2;
  99. $res = ProductReplyModel::edit($save, $data['id']);
  100. if (!$res)
  101. return Json::fail(ProductReplyModel::getErrorInfo('回复失败,请稍候再试!'));
  102. else
  103. return Json::successful('回复成功!');
  104. }
  105. /**
  106. * 添加虚拟评论表单
  107. * @return string
  108. * @throws \FormBuilder\exception\FormBuilderException
  109. */
  110. public function create()
  111. {
  112. $field = [
  113. Form::frameImageOne('image', '商品', Url::buildUrl('admin/store.StoreProductReply/select', array('fodder' => 'image')))->icon('plus')->width('100%')->height('500px'),
  114. Form::hidden('product_id', 0),
  115. Form::input('nickname', '用户名称')->col(Form::col(24)),
  116. Form::input('comment', '评价文字')->type('textarea'),
  117. Form::number('product_score', '商品分数')->col(8)->value(5)->min(1)->max(5),
  118. Form::number('service_score', '服务分数')->col(8)->value(5)->min(1)->max(5),
  119. Form::frameImageOne('avatar', '用户头像', Url::buildUrl('admin/widget.images/index', array('fodder' => 'avatar')))->icon('image')->width('100%')->height('500px'),
  120. Form::frameImages('pics', '评价图片', Url::buildUrl('admin/widget.images/index', array('fodder' => 'pics')))->maxLength(5)->icon('images')->width('100%')->height('500px')->spin(0)
  121. ];
  122. $form = Form::make_post_form('添加评论', $field, Url::buildUrl('save'), 2);
  123. $this->assign(compact('form'));
  124. return $this->fetch('public/form-builder');
  125. }
  126. /**
  127. * 选择商品
  128. * @param int $id
  129. */
  130. public function select()
  131. {
  132. return $this->fetch();
  133. }
  134. /**
  135. * 保存评论
  136. */
  137. public function save()
  138. {
  139. $data = Util::postMore([
  140. ['nickname', ''],
  141. ['avatar', ''],
  142. ['product_id', ''],
  143. ['product_score', 0],
  144. ['service_score', 0],
  145. ['comment', ''],
  146. ['pics', []],
  147. ]);
  148. if ($data['nickname'] == '') return Json::fail('请填写用户名称');
  149. if ($data['avatar'] == '') return Json::fail('请选择用户头像');
  150. if ($data['product_id'] == '') return Json::fail('请选择商品');
  151. if ($data['comment'] == '') return Json::fail('请填写评价');
  152. if (!count($data['pics'])) return Json::fail('请选择评价图片');
  153. $data['uid'] = 0;
  154. $data['oid'] = 0;
  155. $data['unique'] = uniqid();
  156. $data['reply_type'] = 'product';
  157. $data['add_time'] = time();
  158. $data['pics'] = json_encode($data['pics']);
  159. ProductReplyModel::create($data);
  160. return Json::successful('添加成功!');
  161. }
  162. }