/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new User(); $organ = new Organ(); //$profile = new Profile; $this->performAjaxValidation(array($model, $organ)); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; //用户名 $model->UserName = $_POST['User']['UserName']; $organ->attributes = $_POST['organ']; //$model->activkey = $model->encrypting(microtime() . $model->password); //$model->activkey=Yii::app()->controller->module->encrypting(microtime().$model->password); //邮箱 $organ->OrganName = $_POST['Organ']['OrganName']; $organ->Email = $_POST['Organ']['Email']; //机构类型 $organ->Identity = $_POST['Organ']['Identity']; $organ->Type = $_POST['Organ']['Type']; $organ->Phone = $_POST['Organ']['Phone']; //是否激活 默认已经激活 $organ->Status = $_POST['Organ']['Status']; $organ->CreateTime = time(); $organ->LastVisitTime = time(); $organ->Province = $_POST['Organ']['Province']; $organ->City = $_POST['Organ']['City']; $organ->Area = $_POST['Organ']['Area']; $organ->Sort = $_POST['Organ']['Sort']; $organ->Recommend = $_POST['Organ']['Recommend']; if ($model->validate() && $organ->validate()) { if ($organ->save()) { $organID = Yii::app()->jpdb->getLastInsertID(); $model->LastVisitTime = time(); $model->OrganID = $organID; $model->PassWord = $model->encrypting($model->PassWord); $model->verifyPassword = $model->encrypting($model->verifyPassword); $model->IsMain = '1'; //主帐号 //激活码 $model->ActiveKey = $model->encrypting(microtime() . $model->PassWord); $result = Yii::app()->jpdb->createCommand()->insert('{{user}}', array('UserName' => $model->UserName, 'PassWord' => $model->PassWord, 'OrganID' => $model->OrganID, 'LastVisitTime' => $model->LastVisitTime, 'ActiveKey' => $model->ActiveKey, 'IsMain' => $model->IsMain)); //添加到推荐记录里面,现只支持修理厂start if ($_POST['Organ']['Identity'] == 3 && $_POST['Organ']['Recommend']) { $record['RecomTime'] = time(); $record['BeFormalTime'] = 0; $record['MemberStatus'] = 0; $organ_factid = Organ::model()->find('OrganName=:OrganName', array(':OrganName' => $_POST['Organ']['Recommend'])); $record['DealerID'] = $organ_factid ? $organ_factid->ID : ''; $record['ServiceID'] = $organID; $lms = Yii::app()->jpdb->createCommand()->insert('jpd_recommend_record', $record); } //添加到推荐记录里面,现只支持修理厂end if ($result) { $this->redirect(array('admin/admin')); } } } else { $organ->validate(); } } $this->render('create', array('model' => $model, 'organ' => $organ)); }