public function updateBank($userId) { /** @var $bankCard \common\models\BankCard */ $bankCard = BankCard::findOne(['userId' => $userId]); if (!$bankCard) { $bankCard = new BankCard(); $bankCard->userId = $userId; $bankCard->bankName = $this->bankName; $bankCard->cardNumber = $this->cardNumber; $bankCard->cardName = $this->cardName; $bankCard->save(); } else { $bankCard->bankName = $this->bankName; $bankCard->cardNumber = $this->cardNumber; $bankCard->cardName = $this->cardName; $bankCard->save(); } }
public function recordOne() { if (!$this->userId) { //新添加 $user = new Users(); $user->bitcoin = 0; $user->password = CommonFunctions::encrypt("123456"); //初始密码设置为123456 $user->state = Users::STATE_NORMAL; do { if ($this->role == Users::ROLE_AA) { $recommendCode = CommonFunctions::create2ARecommendCode(); } elseif ($this->role == Users::ROLE_AAA) { $recommendCode = CommonFunctions::create3ARecommendCode(); } elseif ($this->role == Users::ROLE_BIG) { $recommendCode = CommonFunctions::createBigRecommendCode(); } else { throw new Exception("未知的角色类型"); } } while (Users::findUserByRecommendCode($recommendCode)); $user->recommendCode = $recommendCode; $recommendUser = Users::findUserByRecommendCode($this->recommendCode); $user->recommendUserID = $recommendUser['userId']; $user->registerDate = DateFunctions::getCurrentDate(); } else { //已存在 $user = Users::findOne($this->userId); } $user->role = $this->role; $user->departmentId = $this->departmentId; $user->username = $this->username; $user->nickname = $this->nickname; $user->address = $this->address; $user->realname = $this->realname; $user->cellphone = $this->cellphone; $user->email = $this->email; $user->qq = $this->qq; $user->weixin = $this->weixin; if (!$user->save()) { throw new Exception("add-user-form user save error"); } else { /** @var $bankCard \common\models\BankCard */ $bankCard = BankCard::findOne(['userId' => $user->userId]); if (!$bankCard) { //如果没有 $bankCard = new BankCard(); $bankCard->userId = $user->userId; $bankCard->state = BankCard::STATE_DEFAULT; } $bankCard->bankName = $this->bankName; $bankCard->cardNumber = $this->cardNumber; $bankCard->cardName = $this->cardName; $bankCard->save(); } }