validate()) { return $this->getModelError(); } $to_user = ApiHelper::findOneUser($this->to_user_id); if ($to_user == null) { return $this->apiReturnError('教练已离职,无法评论'); } if (!in_array($this->type, [1, 2])) { return $this->apiReturnError('评价类型错误'); } if ($this->type == 1) { if (empty($this->level)) { // return $this->apiReturnError('星级不能为空'); } } $commentModel = Comment::findOne(['user_id' => $this->user_id, 'store_id' => $this->store_id, 'device_id' => $this->device_id]); if ($commentModel == null) { $commentModel = new Comment(); } $data = []; $data['user_id'] = $this->user_id; $data['to_user_id'] = $this->to_user_id; $data['store_id'] = $this->store_id; $data['content'] = $this->content; $data['device_id'] = $this->device_id; $data['type'] = $this->type; $data['created_at'] = time(); if ($this->type == 1) { $data['level'] = $this->level; } $commentModel->attributes = $data; if (!$commentModel->save()) return $this->getModelError($commentModel); return [ 'code' => 0, 'msg' => '成功' ]; } /** * 评价查看 */ public function evaluationList() { if (!$this->store_id) { return $this->apiReturnError('门店ID不能为空'); } if (!$this->device_id) { return $this->apiReturnError('场次ID不能为空'); } // 判断场次 $find = DeviceUniqueBindUser::findOne([ 'id' => $this->device_id, ]); if(empty($find)){ return $this->apiReturnError('场次不存在'); } $list = []; $list = Comment::find()->andWhere([ // 'user_id' => $this->user_id, 'store_id' => $this->store_id, 'device_id' => $this->device_id, ])->select('*')->asArray()->all(); $arr = [ 'xy_data' => [], 'xy_status' => 0, 'jl_status' => 0, 'jl_data' => [], 'sf_status' => 1, # 其他身份 ]; if($find->c_id != intval($this->user_id)){ // 不是教练 $arr['jl_status'] = 1; if($find->uid != intval($this->user_id)){ // 不是学员 $arr['jl_status'] = 1; }else{ $arr['sf_status'] = 2; # 学员身份 } } foreach ($list as $key=>$val){ if($val['type'] == 1){ $arr['xy_data'] = $val; $arr['xy_status'] = 1; }else{ $arr['jl_data'] = $val; $arr['jl_status'] = 1; } } $arr['param'] = ['user_id' => $this->user_id, 'store_id' => $this->store_id, 'device_id' => $this->device_id,$find->c_id]; return $this->apiReturnSuccess('ok', $arr); } }