示例#1
0
 /**
  * 充值提现
  */
 public function actionMoney()
 {
     $user_id = Yii::app()->user->getId();
     $thisuser = Users::model()->findByPk($user_id);
     #获得用户的银行卡
     $thisbank = Bankcard::model()->find("user_id=:user_id", array(":user_id" => $user_id));
     if (!$thisbank) {
         $thisbank = new Bankcard();
     }
     if (isset($_POST['Bankcard'])) {
         if (empty($_POST['Bankcard']['bank_name'])) {
             $_POST['Bankcard']['bank_name'] = "工商银行";
         }
         $thisbank->setAttributes($_POST['Bankcard']);
         //赋值真实姓名
         $thisbank->setAttribute("realname", $thisuser->realname);
         if ($thisbank->validate()) {
             if ($thisbank->isNewRecord) {
                 $thisbank->save();
             } else {
                 $thisbank->update();
             }
         }
         $_REQUEST['tab'] = "tab2";
     }
     $this->render('money', array("thisuser" => $thisuser, "thisbank" => $thisbank));
 }
示例#2
0
 /**
  * 保存用户的银行卡或者更改
  * @param Bankcard $bankCard
  * @param type $user_id
  * @return \Bankcard
  */
 public static function saveBankCard(Bankcard $bankCard, $user_id)
 {
     $_POST['Bankcard']['bank'] = 'xx';
     if (isset($_POST['bank'])) {
         $_POST['Bankcard']['bank'] = $_POST['bank'];
         $bank = Linkage::getValueChina($_POST['bank'], "account_bank");
         if ($bank) {
             $_POST['Bankcard']['bank_name'] = $bank;
         }
     }
     $_POST['Bankcard']['bank_type'] = 'xx';
     if (isset($_POST['bank_type'])) {
         $_POST['Bankcard']['bank_type'] = $_POST['bank_type'];
     }
     $_POST['Bankcard']['area'] = '0';
     if (isset($_POST['province'])) {
         $_POST['Bankcard']['province'] = $_POST['province'];
     }
     if (isset($_POST['city'])) {
         $_POST['Bankcard']['city'] = $_POST['city'];
     }
     $_POST['Bankcard']['user_id'] = $user_id;
     $bankCard->setAttributes($_POST['Bankcard']);
     foreach ((array) $_POST['Bankcard'] as $key => $value) {
         if (trim($value) == '') {
             $bankCard->addError($key, "字段不能为空");
             break;
         }
     }
     if (!$bankCard->getErrors()) {
         $bankCard->setAttribute('addtime', time());
         $bankCard->setAttribute('addip', Yii::app()->request->userHostAddress);
         if ($bankCard->validate()) {
             if ($bankCard->isNewRecord) {
                 $result = $bankCard->save();
             } else {
                 $result = $bankCard->update();
             }
             if (!$result) {
                 $bankCard->addError("realname", "更新失败");
             }
         } else {
             $bankCard->addError("realname", "更新失败");
         }
     }
     return $bankCard;
 }