"快付支付", 1 => '环球支付', 2 => "payflash支付", 3 => "trustpay支付", 4 => "创汇支付", 5 => "闪付通支付", 7 => "快付支付(银联扫码)", ]; public static $payMethods = [ 'kuaifu'=>6, 'huanqiu' => 1, 'payflash'=> 2, 'trustpay'=> 3, 'chuanghui'=>4, 'shanfutong'=>5, 'kuaifu2'=>7, ]; /** * @inheritdoc */ public function rules() { return [ [['login', 'amount', 'payType'], 'required'], ['amount', 'match', 'pattern' => '/^([1-9]\d*|[0])(\.\d{1,2})?$/'], ['payType', 'integer'], ['payType', 'in', 'range' => array_keys(self::$payNames)], ['bankCode', 'required', 'when' => function ($model) { /** @var PayForm $model */ return in_array($model->payType, []); }, 'message' => '请选择银行'], ]; } /** * @return bool */ public function outPay() { if (Yii::$app->getUser()->getIsGuest()) { $this->addError('login', '用户未登录'); Yii::$app->getUser()->loginRequired(); return false; } if ($this->validate()) { $data = []; $data['orderSn'] = date('YmdHis').rand(1000,9999); $data['amount'] = $this->amount; $data['login'] = $this->login; $data['payType'] = $this->payType; $data['bankCode'] = $this->bankCode; $data['memberId'] = Yii::$app->getUser()->getId(); $data['notifyUrl'] = Url::to(["/pay/notify/{$this->payType}"], true); $data['returnUrl'] = Url::to(["/pay/return/{$this->payType}"], true); $data['ip'] = Utils::getClientIp(); $api = new PayApi(); $result = $api->outPay($data); if ($result['code'] == 1) { $this->_outPayResult = $result['data']; } else { if (is_array($result['message'])) { $this->addErrors($result['message']); } else { $this->addError('amount', $result['message']); } } } return !$this->hasErrors(); } /** * @return string */ public function getOutPayResult() { return $this->_outPayResult; } /** * @param string $payMethod * @return mixed|null */ public function getPayTypeByMethod($payMethod) { return isset(self::$payMethods[$payMethod]) ? self::$payMethods[$payMethod] : null; } }