StoreReply.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\controller\api\store\product;
  3. use app\common\repositories\store\order\StoreOrderProductRepository;
  4. use app\validate\api\ProductReplyValidate;
  5. use think\App;
  6. use ln\basic\BaseController;
  7. use app\common\repositories\store\product\ProductReplyRepository as repository;
  8. class StoreReply extends BaseController
  9. {
  10. /**
  11. * @var repository
  12. */
  13. protected $repository;
  14. protected $userInfo;
  15. /**
  16. * StoreProduct constructor.
  17. * @param App $app
  18. * @param repository $repository
  19. */
  20. public function __construct(App $app, repository $repository)
  21. {
  22. parent::__construct($app);
  23. $this->repository = $repository;
  24. $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  25. }
  26. /**
  27. * @Author:Qinii
  28. * @Date: 2020/5/28
  29. * @return mixed
  30. */
  31. public function lst($id)
  32. {
  33. [$page, $limit] = $this->getPage();
  34. $where['type'] = $this->request->param('type');
  35. $where['product_id'] = $id;
  36. return app('json')->success($this->repository->getApiList($where,$page, $limit));
  37. }
  38. public function product($id, StoreOrderProductRepository $orderProductRepository)
  39. {
  40. $orderProduct = $orderProductRepository->userOrderProduct((int)$id, $this->request->uid());
  41. if (!$orderProduct || !$orderProduct->orderInfo)
  42. return app('json')->fail('订单不存在');
  43. if ($orderProduct->is_reply)
  44. return app('json')->fail('该商品已评价');
  45. return app('json')->success($orderProduct->toArray());
  46. }
  47. public function reply($id, ProductReplyValidate $validate)
  48. {
  49. $data = $this->request->params(['comment', 'product_score', 'service_score', 'postage_score', ['pics', []]]);
  50. $validate->check($data);
  51. $user = $this->request->userInfo();
  52. $_name = mb_substr($user['nickname'],0,1).'***';
  53. $name = (strLen($user['nickname']) > 6) ? $_name.mb_substr($user['nickname'],-1,1) : $_name;
  54. $data['uid'] = $this->request->uid();
  55. $data['order_product_id'] = (int)$id;
  56. $data['nickname'] = $name;
  57. $data['avatar'] = $user['avatar'];
  58. $this->repository->reply($data);
  59. return app('json')->success('评价成功');
  60. }
  61. }