CommentController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace addons\ReservationService\api\modules\v1\controllers;
  3. use addons\ReservationService\common\enums\ReservationServiceEnum;
  4. use addons\ReservationService\common\services\CommentService;
  5. use api\controllers\OnAuthController;
  6. use Yii;
  7. use yii\helpers\Json;
  8. class CommentController extends OnAuthController
  9. {
  10. public $modelClass = '';
  11. /**
  12. * 不用进行登录验证的方法
  13. *
  14. * 例如: ['index', 'update', 'create', 'view', 'delete']
  15. * 默认全部需要验证
  16. *
  17. * @var array
  18. */
  19. protected $authOptional = ['comments-list'];
  20. /**
  21. * 技师的评分
  22. * @return mixed|null
  23. */
  24. public function actionIndex()
  25. {
  26. $data = Yii::$app->request->get();
  27. $valid = Yii::$app->services->validate->validate($data, [
  28. [['limit', 'page', 'service_status'], 'integer'],
  29. ]);
  30. if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  31. $service = new CommentService();
  32. $data['tech_user_id'] = $this->user_id;
  33. $data['store_id'] = 0;
  34. $ret = $service->page($this->mall_id, 0, $data);
  35. if (is_string($ret)) return $this->error($ret);
  36. // 只有第一页才获取评分
  37. // if (empty($data['page']) || $data['page'] == 1) {
  38. $ret['service_rating'] = $service->rating($this->mall_id, $this->user_id);
  39. // }
  40. return $this->success('获取成功', $ret);
  41. }
  42. public function actionTags()
  43. {
  44. $tags = \Yii::$app->services->setting->addons->get($this->mall_id, ReservationServiceEnum::ADDONS_NAME, 'basic.comment_tags');
  45. return $this->success('获取成功', !empty($tags) ? Json::decode((string) $tags) : []);
  46. }
  47. /**
  48. * 评价列表
  49. * @return mixed|null
  50. */
  51. public function actionList()
  52. {
  53. $data = Yii::$app->request->get();
  54. $valid = Yii::$app->services->validate->validate($data, [
  55. [['limit', 'page', 'tech_id', 'type'], 'integer'],
  56. ]);
  57. if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  58. $service = new CommentService();
  59. $data['store_id'] = 0;
  60. $ret = $service->page($this->mall_id, 0, $data);
  61. if (is_string($ret)) return $this->error($ret);
  62. // 只有第一页才获取评分
  63. if (empty($data['page']) || $data['page'] == 1) {
  64. $ret['service_rating'] = $service->rating($this->mall_id, $this->user_id);
  65. }
  66. return $this->success('获取成功', $ret);
  67. }
  68. public function actionCommentsList(){
  69. try {
  70. $params = \Yii::$app->request->get();
  71. $res = \Yii::$app->services->validate->validate($params, [
  72. [['goods_id'], 'required', 'message' => 'goods_id必传'],
  73. [['limit', 'page', 'type','store_id'], 'safe']
  74. ]);
  75. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  76. $params['mall_id']= $this->mall_id;
  77. if(empty($params['store_id'])){
  78. $params['store_id']= 0;
  79. }
  80. $service = new CommentService();
  81. $ret = $service->commentsList($params);
  82. return $this->success('获取成功', $ret);
  83. }catch (\Exception $e){
  84. return $this->error($e->getMessage());
  85. }
  86. }
  87. }