| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace addons\ReservationService\api\modules\v1\controllers;
- use addons\ReservationService\common\enums\ReservationServiceEnum;
- use addons\ReservationService\common\services\CommentService;
- use api\controllers\OnAuthController;
- use Yii;
- use yii\helpers\Json;
- class CommentController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['comments-list'];
- /**
- * 技师的评分
- * @return mixed|null
- */
- public function actionIndex()
- {
- $data = Yii::$app->request->get();
- $valid = Yii::$app->services->validate->validate($data, [
- [['limit', 'page', 'service_status'], 'integer'],
- ]);
- if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $service = new CommentService();
- $data['tech_user_id'] = $this->user_id;
- $data['store_id'] = 0;
- $ret = $service->page($this->mall_id, 0, $data);
- if (is_string($ret)) return $this->error($ret);
- // 只有第一页才获取评分
- // if (empty($data['page']) || $data['page'] == 1) {
- $ret['service_rating'] = $service->rating($this->mall_id, $this->user_id);
- // }
- return $this->success('获取成功', $ret);
- }
- public function actionTags()
- {
- $tags = \Yii::$app->services->setting->addons->get($this->mall_id, ReservationServiceEnum::ADDONS_NAME, 'basic.comment_tags');
- return $this->success('获取成功', !empty($tags) ? Json::decode((string) $tags) : []);
- }
- /**
- * 评价列表
- * @return mixed|null
- */
- public function actionList()
- {
- $data = Yii::$app->request->get();
- $valid = Yii::$app->services->validate->validate($data, [
- [['limit', 'page', 'tech_id', 'type'], 'integer'],
- ]);
- if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $service = new CommentService();
- $data['store_id'] = 0;
- $ret = $service->page($this->mall_id, 0, $data);
- if (is_string($ret)) return $this->error($ret);
- // 只有第一页才获取评分
- if (empty($data['page']) || $data['page'] == 1) {
- $ret['service_rating'] = $service->rating($this->mall_id, $this->user_id);
- }
- return $this->success('获取成功', $ret);
- }
- public function actionCommentsList(){
- try {
- $params = \Yii::$app->request->get();
- $res = \Yii::$app->services->validate->validate($params, [
- [['goods_id'], 'required', 'message' => 'goods_id必传'],
- [['limit', 'page', 'type','store_id'], 'safe']
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $params['mall_id']= $this->mall_id;
- if(empty($params['store_id'])){
- $params['store_id']= 0;
- }
- $service = new CommentService();
- $ret = $service->commentsList($params);
- return $this->success('获取成功', $ret);
- }catch (\Exception $e){
- return $this->error($e->getMessage());
- }
- }
- }
|