StoreReply.php 2.9 KB

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