Example #1
0
 public function getCreatorDetail()
 {
     if (!empty($this->origin) && $this->origin !== IssueUser::HELPDESK) {
         return $this->hasOne(IssueUser::className(), ['_id' => 'creator']);
     }
     return $this->hasOne(HelpDesk::className(), ['_id' => 'creator']);
 }
 private function _createIssueUser($params)
 {
     $issueUser = new IssueUser();
     $issueUser->origin = $params['origin'];
     $issueUser->attributes = $params;
     switch ($params['origin']) {
         case IssueUser::WEIBO:
         case IssueUser::ALIPAY:
         case IssueUser::WECHAT:
             $follower = Yii::$app->weConnect->getFollowerByOriginId($params['openId'], $params['channelId']);
             if (empty($follower)) {
                 throw new InvalidParameterException(['issue' => Yii::t('common', 'parameters_missing')]);
             }
             $issueUser->avatar = $follower['headerImgUrl'];
             $issueUser->openId = $follower['originId'];
             $issueUser->nickname = $follower['nickname'];
             $issueUser->gender = $follower['gender'];
             $issueUser->channelId = $follower['accountId'];
             $issueUser->language = $follower['language'];
             $issueUser->location = ['city' => $follower['city'], 'province' => $follower['province'], 'country' => $follower['country']];
             break;
     }
     if ($issueUser->save()) {
         return $issueUser['_id'];
     }
     return ['errors' => $issueUser->errors];
 }