/** 生成用户 */ public function actionGenerate() { $addUserForm = new AddUserForm(); if ($addUserForm->load(Yii::$app->request->post()) && $addUserForm->validate()) { $addUserForm->recordOne(); CommonFunctions::createAlertMessage("伙伴设置成功", "success"); return $this->redirect(['user-aaa/index']); } if (!CommonFunctions::isExistAlertMessage()) { CommonFunctions::createAlertMessage("伙伴设置失败,参数不全或存在非法字段", "error"); } return $this->redirect(['user-aaa/index']); }
/** * 初始化form,必须使用 * @param null $id 配置该参数则role不启用 * @param null $role 配置该参数则id不启用 * @return AddUserForm * @throws Exception */ public static function initWithIdOrRole($id = null, $role = null) { $form = new AddUserForm(); if ($id) { /** @var $user \common\models\Users*/ $user = Users::findOne($id); /** @var $bank \common\models\bankCard*/ $bank = BankCard::find()->where(['userId' => $id])->one(); if ($bank) { $form->bankName = $bank->bankName; $form->cardNumber = $bank->cardNumber; $form->cardName = $bank->cardName; } $form->role = $user->role; $form->userId = $id; $form->departmentId = $user->departmentId; $form->username = $user->username; $form->nickname = $user->nickname; $form->address = $user->address; $form->realname = $user->realname; $form->cellphone = $user->cellphone; $form->email = $user->email; $form->qq = $user->qq; $form->weixin = $user->weixin; if ($form->role == Users::ROLE_BIG) { //大客户要有推荐码 $form->recommendCode = $user->recommendUser['nickname']; } } else { if ($role) { $form->role = $role; } else { throw new Exception("role do not exit"); } } $form->initRoleName(); return $form; }