Exemple #1
0
 public function alliance($params = array())
 {
     extract($params);
     $alliance = array();
     if (isset($alliance_id) && $alliance_id) {
         $model = Alliance::model()->findByPk($alliance_id);
     } else {
         $model = new Alliance();
         $alliance['type'] = 0;
     }
     if (isset($name) && $name) {
         $alliance['name'] = $name;
     }
     if (isset($center_name) && $center_name) {
         $alliance['center_name'] = $center_name;
     }
     if (isset($image) && $image) {
         $alliance['image'] = $image;
     }
     if (isset($notice) && $notice) {
         $alliance['notice'] = $notice;
     }
     if (isset($user_id) && $user_id) {
         $alliance['leader'] = $user_id;
         $owner_arr = User::model()->loadUserByPk($user_id);
         if ($owner_mobile = $owner_arr['mobile']) {
             $model->attributes = $alliance;
             if ($model->validate() && $model->save()) {
                 $id = $model->getPrimaryKey();
                 Yii::import("application.extensions.Emchat.*");
                 $h = new Easemob();
                 $options['groupname'] = $name;
                 $options['desc'] = isset($notice) && $notice ? $notice : "this is a love group";
                 $options['public'] = true;
                 $options['owner'] = 'ur_' . $owner_mobile;
                 $group = $h->createGroup($options);
                 if ($groupid = $group['data']['groupid']) {
                     $groups = array('name' => $name, 'owner' => 'ur_' . $owner_mobile, 'desc' => isset($notice) && $notice ? $notice : "this is a love group", 'emchat_id' => $groupid, 'alliance_id' => $id);
                     $emchat = new Emchat();
                     $emchat->attributes = $groups;
                     if ($emchat->validate() && $emchat->save()) {
                         $ret = $this->notice('OK', 0, '成功', $groups);
                     } else {
                         $ret = $this->notice('ERR', 307, '操作失败', $emchat->getErrors());
                     }
                 } else {
                     $ret = $this->notice('ERR', 306, '环信数据保存失败', $group);
                 }
             } else {
                 $ret = $this->notice('ERR', 305, '数据保存失败', $model->getErrors());
             }
         } else {
             $ret = $this->notice('ERR', 303, '用户数据不存在', []);
         }
     } else {
         $ret = $this->notice('ERR', 301, '缺少参数', []);
     }
     return $ret;
 }