/** * 用户充值行为 * @param $uid 用户id * @param $money 用户金额 * @return bool * @throws ErrorException */ public static function setBalance($uid, $money) { //判断用户是否存在,用户状态TODO(是否锁定) //用户实名 $res = member::isAuthentic($uid); if ($res) { //用户是否绑卡 $isBinding = Balance::isBinding($uid); if ($isBinding) { ////充值金额限定判断--最小充值额度,最大充值额度,单人每次充值限额 ////易宝充值是按-----分计算 $money = $money * 100; $yeepay = yeepay::payment($uid, $money); if ($yeepay) { return $yeepay; } else { throw new ErrorException('充值接口失败'); } } else { throw new ErrorException('请先绑定银行卡'); } } else { throw new ErrorException('请先实名认证'); } }
public function actionDoresbind() { $uid = yii::$app->user->id; $model = UcenterMember::find()->where(['id' => $uid])->one(); $bandcard = $_POST['bankcard']; $phone = $_POST['phone']; if ($_POST[card_code]) { $card_code = $_POST[card_code]; $province = $_POST[province]; $city = $_POST[city]; $info = sinapay::bindingBankCard($uid, $bandcard, $phone, $province, $city, $card_code); echo json_encode($info); exit; } try { $info = sinapay::bindingBankCard($uid, $bandcard, $phone); echo json_encode($info); exit; } catch (ErrorException $e) { echo $e->getMessage(); exit; } if (isset($_POST['bankcard']) && isset($_POST['phone'])) { $cardno = $_POST['bankcard']; $phone = $_POST['phone']; $info = Balance::bindbankcard2($uid, $cardno, $phone); if ($info) { echo '绑卡成功'; exit; } } }
/** * 用户充值短信确认 * @param $out_trade_no 订单号 * @param $ticket 订单标识 * @param $validate_code 短信验证码 * @return array|mixed */ public static function rechargeComfirm($out_trade_no, $ticket, $validate_code) { $cinfirm = SinaDeposit::find()->where(['out_trade_no' => $out_trade_no, 'ticket' => $ticket, 'status' => SinaDeposit::STATUS_CONFIRM])->one(); if (empty($cinfirm)) { $return = array('errorNum' => '1', 'errorMsg' => '请重新获取验证码', 'data' => null); return $return; } $uid = $cinfirm->uid; $amount = $cinfirm->amount; $customer = Info::find()->where(['member_id' => $uid])->one(); if (!$customer) { $return = array('errorNum' => '1', 'errorMsg' => '网站账户异常', 'data' => null); return $return; } //获取银行卡号 $bank_user = self::isBinding($uid); $bank_account_no = $uid; if (!$bank_user['errorNum']) { $bank_account_no = $bank_user['data']['bank_account_no']; } $sina = new sina(); $pay = $sina->advance_hosting_pay($out_trade_no, $ticket, $validate_code); if ($pay['response_code'] == 'APPLY_SUCCESS') { //支付成功 $cinfirm->status = SinaDeposit::STATUS_PROCESSING; $cinfirm->msg = "处理中"; $cinfirm->validate_code = $validate_code; if ($cinfirm->save()) { // //更新网站的本地账户信息 // $balance = $customer->balance ? $customer->balance : 0 ; // $customer->balance = $amount + $balance; //放入冻结金中 $freeze = $customer->freeze ? $customer->freeze : 0; $customer->freeze = $freeze + $amount; $flag = $customer->save(); if ($flag) { $log = Balance::logSave($uid, $amount, "setBalabce", Log::STATUS_PROCESSING, $bank_account_no, "充值处理中", $out_trade_no); // //更新绑定银行卡金额操作 // self::updatebank($uid,$amount); if ($log) { $return = array('errorNum' => '0', 'errorMsg' => '充值处理中', 'data' => null); return $return; } else { $return = array('errorNum' => '1', 'errorMsg' => '账户记录失败', 'data' => null); return $return; } } else { Balance::logSave($uid, $amount, "setBalabce", Log::STATUS_RECHAR_ERR, $bank_account_no, "更新账户数据失败", $out_trade_no); $return = array('errorNum' => '1', 'errorMsg' => '更新账户数据失败', 'data' => null); return $return; } } } elseif ($pay['response_code'] == 'ADVANCE_TICKET_VALIDATE_FAIL') { $cinfirm->status = SinaDeposit::STATUS_ERROR; $cinfirm->msg = $pay['response_message']; $cinfirm->validate_code = $validate_code; if ($cinfirm->save()) { Balance::logSave($uid, $amount, "setBalabce", Log::STATUS_RECHAR_ERR, $bank_account_no, "验证码超时", $out_trade_no); $return = array('errorNum' => '1', 'errorMsg' => '验证码超时,请重新获取', 'data' => null); return $return; } } else { $cinfirm->status = SinaDeposit::STATUS_ERROR; $cinfirm->msg = $pay['response_message']; $cinfirm->validate_code = $validate_code; if ($cinfirm->save()) { Balance::logSave($uid, $amount, "setBalabce", Log::STATUS_RECHAR_ERR, $bank_account_no, $pay['response_message'], $out_trade_no); $return = array('errorNum' => '1', 'errorMsg' => $pay['response_message'], 'data' => null); return $return; } } }
public function actionBindcard() { $model = UcenterMember::find()->where('id=' . Yii::$app->user->id)->one(); $uid = yii::$app->user->id; $is_bind = sinapay::isBinding($uid); if ($is_bind['errorNum'] == 0) { $result_bind = $is_bind['data']; $logo_bind = self::BankInfos(); } $result = member::isAuthentic($uid); //接收验证码后进行银行卡绑定 try { if (isset($_POST['bankcard']) && isset($_POST['idcard']) && isset($_POST['username']) && isset($_POST['phone']) && isset($_POST['code']) && isset($_POST['ticket']) && isset($_POST['request_no'])) { $valid_code = $_POST['code']; $request_no = $_POST['request_no']; $ticket = $_POST['ticket']; $info = sinapay::bankCardAdvance($request_no, $ticket, $valid_code); if ($info['errorNum'] == 0) { //领取体验金 $rid = Rule::find()->where(['title' => '绑定银行卡', 'status' => 1])->one()->id; $r_money = Rule::find()->where(['title' => '绑定银行卡', 'status' => 1])->one()->money; $model_gold = new Gold(); $model_gold->rid = $rid; $model_gold->money = $r_money; $model_gold->uid = yii::$app->user->id; $model_gold->created_at = strtotime("now"); $model_gold->save(); echo "绑卡成功"; exit; } elseif ($info['errorNum'] != 0) { echo $info['errorMsg']; exit; } } } catch (ErrorException $e) { echo $e->getMessage(); exit; } //发送验证码和请求ID try { if (isset($_POST['bankcard']) && isset($_POST['idcard']) && isset($_POST['username']) && isset($_POST['phone'])) { $cardno = $_POST['bankcard']; $idcardno = $_POST['idcard']; $username = $_POST['username']; $phone = $_POST['phone']; try { $info = sinapay::bindingBankCard($uid, $cardno, $phone); echo json_encode($info); exit; } catch (ErrorException $e) { echo $e->getMessage(); exit; } } } catch (ErrorException $e) { echo $e->getMessage(); exit; } if (isset($_POST['bankcard']) && isset($_POST['phone'])) { $cardno = $_POST['bankcard']; $phone = $_POST['phone']; $info = Balance::bindbankcard2($uid, $cardno, $phone); if ($info) { echo '绑卡成功'; exit; } } $infos_rar = $this->Ucenter(); //用户数据包 return $this->render('bindcard', compact("infos_rar", "result", "result_bind", "model", "logo_bind")); }