|
@@ -22,30 +22,57 @@ class pay_helper
|
|
|
const CMB_PAYMENT = "cmbpay";
|
|
|
const PUBWX_PAYMENT = "jspay";
|
|
|
|
|
|
- public function __construct() {
|
|
|
+ const virtual_order = 1;
|
|
|
+ const real_order = 2;
|
|
|
+
|
|
|
+ private $mOrderType;
|
|
|
+ private $logic_payment;
|
|
|
+ private $mPaysn;
|
|
|
+
|
|
|
+ public function __construct($paysn)
|
|
|
+ {
|
|
|
+ $this->logic_payment = Logic('payment');
|
|
|
+
|
|
|
+ $order_pay_info = Model('order')->getOrderPayInfo(array('pay_sn' => $paysn),true);
|
|
|
+ if (empty($order_pay_info)) {
|
|
|
+ $this->mOrderType = pay_helper::virtual_order;
|
|
|
+ } else {
|
|
|
+ $this->mOrderType = pay_helper::real_order;
|
|
|
+ }
|
|
|
+ $this->mPaysn = $paysn;
|
|
|
}
|
|
|
|
|
|
static public function pay_types()
|
|
|
{
|
|
|
//支付宝,微信,招商银行,各自的描述语
|
|
|
$types = [];
|
|
|
- $types[] = array("payment" => "wxpay","desc" => "");
|
|
|
- $types[] = array("payment" => "alipay","desc" => "");
|
|
|
- $types[] = array("payment" => "cmbpay","desc" => "");
|
|
|
+ $types[] = ["payment" => "wxpay","desc" => ""];
|
|
|
+ $types[] = ["payment" => "alipay","desc" => ""];
|
|
|
+ $types[] = ["payment" => "cmbpay","desc" => ""];
|
|
|
return $types;
|
|
|
}
|
|
|
|
|
|
- static public function pay_bonus($pay_sn)
|
|
|
+ private function pay_bonus()
|
|
|
{
|
|
|
- $member_info = array('member_id' => $_SESSION['member_id'], 'member_name' => $_SESSION['member_name']);
|
|
|
- $logic_payment = Logic('payment');
|
|
|
- $logic_payment->payPredepositEx($pay_sn,$member_info);
|
|
|
+ $pay_sn = $this->mPaysn;
|
|
|
+ $member_info = array('member_id' => session_helper::memberid(), 'member_name' => session_helper::nickname());
|
|
|
+ $this->logic_payment->payPredepositEx($pay_sn,$member_info);
|
|
|
}
|
|
|
|
|
|
- static public function pay($pay_sn, $payment,$usebonus,&$err)
|
|
|
+ public function pay($payment,$usebonus,&$err)
|
|
|
{
|
|
|
+ if($this->mOrderType == self::real_order) {
|
|
|
+ return $this->real_pay($payment,$usebonus,$err);
|
|
|
+ } else {
|
|
|
+ return $this->virtual_pay($payment,$usebonus,$err);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function real_pay($payment,$usebonus,&$err)
|
|
|
+ {
|
|
|
+ $pay_sn = $this->mPaysn;
|
|
|
if($usebonus) {
|
|
|
- self::pay_bonus($pay_sn);
|
|
|
+ $this->pay_bonus();
|
|
|
}
|
|
|
|
|
|
$logic_payment = Logic('payment');
|
|
@@ -72,52 +99,97 @@ class pay_helper
|
|
|
Log::record("Put order to oms error: pay_sn={$pay_sn},bonus pay.",Log::ERR);
|
|
|
}
|
|
|
}
|
|
|
- $pay_helper = new pay_helper();
|
|
|
- $pay_helper->OnSuccess($pay_sn);
|
|
|
+ $this->OnSuccess();
|
|
|
}
|
|
|
return $output;
|
|
|
}
|
|
|
- else
|
|
|
+ else {
|
|
|
+ return $this->third_pay($payment,$payinfo,$left_cents,$err);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function virtual_pay($payment,$usebonus,&$err)
|
|
|
+ {
|
|
|
+ $order_sn = $this->mPaysn;
|
|
|
+
|
|
|
+ $logic_payment = Logic('payment');
|
|
|
+ $payinfo = $logic_payment->getVrOrderInfo($order_sn, $_SESSION['member_id'],true);
|
|
|
+
|
|
|
+ if(!$payinfo['state']) goto onerror;
|
|
|
+ if ($payinfo['data']['order_state'] != ORDER_STATE_NEW || empty($payinfo['data']['api_pay_amount'])) goto onerror;
|
|
|
+
|
|
|
+ $left_cents = intval(doubleval($payinfo['data']['api_pay_amount']) * 100 + 0.5);
|
|
|
+ if($left_cents == 0)
|
|
|
{
|
|
|
- $pay = null;
|
|
|
- if($payment == "wxpay") {
|
|
|
- $pay = new Pay\wxpay();
|
|
|
- }
|
|
|
- else if($payment == "jspay")
|
|
|
+ $output['need_pay'] = false;
|
|
|
+ $output['tips'] = "已经用红包支付完成";
|
|
|
+
|
|
|
+ $payinfo = self::update_order($order_sn, $pay_sn, 'bonus'); // 更新订单
|
|
|
+ if (isset($payinfo) && $payinfo['state'])
|
|
|
{
|
|
|
- $openid = session_helper::pub_openid();
|
|
|
- Log::record("openid = {$openid}",Log::DEBUG);
|
|
|
- if(empty($openid)) {
|
|
|
- $err = array('code' => errcode::ErrPayment, 'msg' => '微信未授权,不可以进行网页支付.');
|
|
|
- return false;
|
|
|
- }
|
|
|
- else {
|
|
|
- $pay = new Pay\jspay($openid);
|
|
|
+ if(is_pushoms())
|
|
|
+ {
|
|
|
+ $logic_delivery = Logic('delivery');
|
|
|
+ $ret = $logic_delivery->putOrder($pay_sn, $pay_sn);
|
|
|
+ if(empty($ret)) { //todo must add to 定时任务
|
|
|
+ Log::record("Put order to oms error: pay_sn={$pay_sn},bonus pay.",Log::ERR);
|
|
|
+ }
|
|
|
}
|
|
|
+ $pay_helper = new pay_helper();
|
|
|
+ $pay_helper->OnSuccess($pay_sn);
|
|
|
}
|
|
|
- else if($payment == "alipay") {
|
|
|
- $pay = new Pay\alipay();
|
|
|
- }
|
|
|
- else if($payment == "cmbpay") {
|
|
|
- $pay = new Pay\cmbpay();
|
|
|
+ return $output;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return $this->third_pay($payment,$payinfo,$left_cents,$err);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ onerror:
|
|
|
+ $err = array('code' => errcode::ErrPayment, 'msg' => $payinfo['msg']);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function third_pay($payment, $payinfo, $left_cents, &$err)
|
|
|
+ {
|
|
|
+ $pay = null;
|
|
|
+ if($payment == "wxpay") {
|
|
|
+ $pay = new Pay\wxpay();
|
|
|
+ }
|
|
|
+ else if($payment == "jspay")
|
|
|
+ {
|
|
|
+ $openid = session_helper::pub_openid();
|
|
|
+ Log::record("openid = {$openid}",Log::DEBUG);
|
|
|
+ if(empty($openid)) {
|
|
|
+ $err = array('code' => errcode::ErrPayment, 'msg' => '微信未授权,不可以进行网页支付.');
|
|
|
+ return false;
|
|
|
}
|
|
|
else {
|
|
|
- $err = array('code' => errcode::ErrPayment, 'msg' => $payinfo['msg']);
|
|
|
- return false;
|
|
|
+ $pay = new Pay\jspay($openid);
|
|
|
}
|
|
|
+ }
|
|
|
+ else if($payment == "alipay") {
|
|
|
+ $pay = new Pay\alipay();
|
|
|
+ }
|
|
|
+ else if($payment == "cmbpay") {
|
|
|
+ $pay = new Pay\cmbpay();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $err = array('code' => errcode::ErrPayment, 'msg' => $payinfo['msg']);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- $subject = $payinfo['data']['subject'];
|
|
|
- $pay_sn = $payinfo['data']['pay_sn'];
|
|
|
- $order_sn = $payinfo['data']['order_list'][0]['order_sn'];
|
|
|
+ $subject = $payinfo['data']['subject'];
|
|
|
+ $pay_sn = $payinfo['data']['pay_sn'];
|
|
|
+ $order_sn = $payinfo['data']['order_list'][0]['order_sn'];
|
|
|
|
|
|
- $output['need_pay'] = true;
|
|
|
- $output['tips'] = "";
|
|
|
+ $output['need_pay'] = true;
|
|
|
+ $output['tips'] = "";
|
|
|
|
|
|
- $third_param = $pay->gen_pay($pay_sn,$left_cents,$order_sn,$subject);
|
|
|
- $output['param'] = $third_param;
|
|
|
+ $third_param = $pay->gen_pay($pay_sn,$left_cents,$order_sn,$subject);
|
|
|
+ $output['param'] = $third_param;
|
|
|
|
|
|
- return $output;
|
|
|
- }
|
|
|
+ return $output;
|
|
|
}
|
|
|
|
|
|
public static function confirm($pay_sn,&$err,&$amount,&$fcode_state)
|
|
@@ -140,8 +212,9 @@ class pay_helper
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static function check_fee($pay_sn,$total_fee,&$need_pay)
|
|
|
+ public function check_fee($total_fee,&$need_pay)
|
|
|
{
|
|
|
+ $pay_sn = $this->mPaysn;
|
|
|
$logic_payment = Logic('payment');
|
|
|
$result = $logic_payment->getRealOrderInfo($pay_sn,null,true);
|
|
|
|
|
@@ -155,12 +228,17 @@ class pay_helper
|
|
|
return ($need_pay === $total_fee);
|
|
|
}
|
|
|
|
|
|
- static public function paied($pay_sn)
|
|
|
+ public function paied()
|
|
|
{
|
|
|
- $logic_payment = Logic('payment');
|
|
|
- $result = $logic_payment->getRealOrderInfo($pay_sn,null,true);
|
|
|
- if (intval($result['data']['api_pay_state']) != 0) {
|
|
|
- return true;
|
|
|
+ $pay_sn = $this->mPaysn;
|
|
|
+ if($this->mOrderType == self::real_order)
|
|
|
+ {
|
|
|
+ $result = $this->logic_payment->getRealOrderInfo($pay_sn,null,true);
|
|
|
+ if (intval($result['data']['api_pay_state']) != 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return false;
|
|
@@ -203,7 +281,7 @@ class pay_helper
|
|
|
$pay_sn = $result['pay_sn'];
|
|
|
$trade_no = $result['trade_no'];
|
|
|
|
|
|
- $cb_info = self::update_order($pay_sn,$trade_no,$payment);
|
|
|
+ $cb_info = $this->update_order($trade_no,$payment);
|
|
|
if ($cb_info['state'] == false) {
|
|
|
Log::record("update_order fail: pay_sn={$pay_sn},trade_no={$trade_no}", Log::DEBUG);
|
|
|
return false;
|
|
@@ -215,7 +293,7 @@ class pay_helper
|
|
|
$logic_delivery->putOrder($pay_sn, $trade_no);
|
|
|
Log::record("update_order success: pay_sn={$pay_sn}", Log::DEBUG);
|
|
|
}
|
|
|
- $this->OnSuccess($pay_sn);
|
|
|
+ $this->OnSuccess();
|
|
|
|
|
|
return true;
|
|
|
}
|
|
@@ -224,73 +302,66 @@ class pay_helper
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private function gen_payment($payment)
|
|
|
+ public function OnSuccess()
|
|
|
{
|
|
|
- if($payment == "wxpay") {
|
|
|
- return new Pay\wxpay();
|
|
|
- }
|
|
|
- else if($payment == "jspay")
|
|
|
+ $pay_sn = $this->mPaysn;
|
|
|
+ if ($this->mOrderType == self::real_order)
|
|
|
{
|
|
|
- return new Pay\jspay("");
|
|
|
- }
|
|
|
- else if($payment == "alipay") {
|
|
|
- return new Pay\alipay();
|
|
|
- }
|
|
|
- else if($payment == "cmbpay") {
|
|
|
- return new Pay\cmbpay();
|
|
|
+ $logic_payment = Logic('payment');
|
|
|
+ $result = $logic_payment->getRealOrderInfo($pay_sn,null,true);
|
|
|
+
|
|
|
+ if($result['state'] != true) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ QueueClient::push('onAsyncOrderPaied',['pay_sn' => $pay_sn]);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
else {
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- public function OnSuccess($pay_sn)
|
|
|
- {
|
|
|
- $logic_payment = Logic('payment');
|
|
|
- $result = $logic_payment->getRealOrderInfo($pay_sn,null,true);
|
|
|
-
|
|
|
- if($result['state'] != true) {
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- QueueClient::push('onAsyncOrderPaied',['pay_sn' => $pay_sn]);
|
|
|
- return true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static function update_order($paysn, $trade_no, $payment)
|
|
|
+ public function update_order($trade_no, $payment)
|
|
|
{
|
|
|
- $logic_payment = Logic('payment');
|
|
|
- $tmp = explode('|', $paysn);
|
|
|
- $paysn = $tmp[0];
|
|
|
- if (!empty($tmp[1])) {
|
|
|
- $order_type = $tmp[1];
|
|
|
- } else {
|
|
|
- $order_pay_info = Model('order')->getOrderPayInfo(array('pay_sn' => $paysn),true);
|
|
|
- if (empty($order_pay_info)) {
|
|
|
- $order_type = 'v';
|
|
|
- } else {
|
|
|
- $order_type = 'r';
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ($order_type == 'r')
|
|
|
+ $paysn = $this->mPaysn;
|
|
|
+ if ($this->mOrderType == self::real_order)
|
|
|
{
|
|
|
- $result = $logic_payment->getRealOrderInfo($paysn,null,true);
|
|
|
+ $result = $this->logic_payment->getRealOrderInfo($paysn,null,true);
|
|
|
if (intval($result['data']['api_pay_state'])) {
|
|
|
- return array('state' => true);
|
|
|
+ return ['state' => true];
|
|
|
}
|
|
|
$order_list = $result['data']['order_list'];
|
|
|
- $result = $logic_payment->updateRealOrder($paysn, $payment, $order_list, $trade_no);
|
|
|
+ $result = $this->logic_payment->updateRealOrder($paysn, $payment, $order_list, $trade_no);
|
|
|
}
|
|
|
- elseif ($order_type == 'v')
|
|
|
+ else
|
|
|
{
|
|
|
- $result = $logic_payment->getVrOrderInfo($paysn);
|
|
|
+ $result = $this->logic_payment->getVrOrderInfo($paysn);
|
|
|
if ($result['data']['order_state'] != ORDER_STATE_NEW) {
|
|
|
- return array('state' => true);
|
|
|
+ return ['state' => true];
|
|
|
}
|
|
|
- $result = $logic_payment->updateVrOrder($paysn, $payment, $result['data'], $trade_no);
|
|
|
+ $result = $this->logic_payment->updateVrOrder($paysn, $payment, $result['data'], $trade_no);
|
|
|
}
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
+ private function gen_payment($payment)
|
|
|
+ {
|
|
|
+ if($payment == "wxpay") {
|
|
|
+ return new Pay\wxpay();
|
|
|
+ }
|
|
|
+ else if($payment == "jspay")
|
|
|
+ {
|
|
|
+ return new Pay\jspay("");
|
|
|
+ }
|
|
|
+ else if($payment == "alipay") {
|
|
|
+ return new Pay\alipay();
|
|
|
+ }
|
|
|
+ else if($payment == "cmbpay") {
|
|
|
+ return new Pay\cmbpay();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|