|
@@ -2,10 +2,12 @@
|
|
|
/**
|
|
|
* 支付行为
|
|
|
*
|
|
|
-
|
|
|
+
|
|
|
*/
|
|
|
defined('InShopNC') or exit('Access Invalid!');
|
|
|
-class paymentLogic {
|
|
|
+
|
|
|
+class paymentLogic
|
|
|
+{
|
|
|
|
|
|
/**
|
|
|
* 取得实物订单所需支付金额等信息
|
|
@@ -13,8 +15,9 @@ class paymentLogic {
|
|
|
* @param int $member_id
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function getRealOrderInfo($pay_sn, $member_id = null) {
|
|
|
-
|
|
|
+ public function getRealOrderInfo($pay_sn, $member_id = null)
|
|
|
+ {
|
|
|
+
|
|
|
//验证订单信息
|
|
|
$model_order = Model('order');
|
|
|
$condition = array();
|
|
@@ -23,11 +26,11 @@ class paymentLogic {
|
|
|
$condition['buyer_id'] = $member_id;
|
|
|
}
|
|
|
$order_pay_info = $model_order->getOrderPayInfo($condition);
|
|
|
- if(empty($order_pay_info)){
|
|
|
- return callback(false,'该支付单不存在');
|
|
|
+ if (empty($order_pay_info)) {
|
|
|
+ return callback(false, '该支付单不存在');
|
|
|
}
|
|
|
|
|
|
- $order_pay_info['subject'] = '实物订单_'.$order_pay_info['pay_sn'];
|
|
|
+ $order_pay_info['subject'] = '实物订单_' . $order_pay_info['pay_sn'];
|
|
|
$order_pay_info['order_type'] = 'real_order';
|
|
|
|
|
|
$condition = array();
|
|
@@ -39,13 +42,61 @@ class paymentLogic {
|
|
|
if (!empty($order_list)) {
|
|
|
foreach ($order_list as $order_info) {
|
|
|
$pay_amount += ncPriceFormat(floatval($order_info['order_amount']) - floatval($order_info['pd_amount']));
|
|
|
- }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $usebonus = $_GET['usebonus'];
|
|
|
+ if (intval($usebonus) === 1) {
|
|
|
+ $pay_amount = $this->getAndUpdateBonus($member_id,$pay_amount);
|
|
|
}
|
|
|
|
|
|
$order_pay_info['api_pay_amount'] = $pay_amount;
|
|
|
$order_pay_info['order_list'] = $order_list;
|
|
|
-
|
|
|
- return callback(true,'',$order_pay_info);
|
|
|
+
|
|
|
+ return callback(true, '', $order_pay_info);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param $user_id 用户ID
|
|
|
+ * @param $pay_amount 需要支付金额
|
|
|
+ * @return value 扣除红包后需要支付金额
|
|
|
+ */
|
|
|
+ public function getAndUpdateBonus($user_id,$pay_amount){
|
|
|
+
|
|
|
+ // 获取所有红包 红包类型为 1 ,user_id = member_id,当前时间小于结束时间(暂时未作为参数)
|
|
|
+ $condition['user_id'] = $user_id;
|
|
|
+ $condition['bonus_type_id'] = 1;
|
|
|
+ $bonus_list = Model()->table("user_bonus")->where($condition)->select();
|
|
|
+
|
|
|
+ $ret_value = 0;
|
|
|
+ if (!empty($bonus_list)) {
|
|
|
+
|
|
|
+ foreach ($bonus_list as $value) {
|
|
|
+ $bonus_value = doubleval($value['bonus_value']); // 红包金额
|
|
|
+
|
|
|
+ // 支付金额大于红包金额-需要继续选择红包
|
|
|
+ if (($pay_amount - $bonus_value) > 0.0000001) {
|
|
|
+
|
|
|
+ $data['bonus_value'] = 0; // 更新为0
|
|
|
+ $ret = Model()->table('user_bonus')->where(array('bonus_id' => $value['bonus_id']))->update($data);
|
|
|
+
|
|
|
+ if($ret){
|
|
|
+ $pay_amount -= $bonus_value;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ $data['bonus_value'] = $bonus_value - $pay_amount;
|
|
|
+ $ret = Model()->table('user_bonus')->where(array('bonus_id' => $value['bonus_id']))->update($data);
|
|
|
+
|
|
|
+ if($ret) {
|
|
|
+ $pay_amount = 0;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $pay_amount;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -54,8 +105,9 @@ class paymentLogic {
|
|
|
* @param int $member_id
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function getVrOrderInfo($order_sn, $member_id = null) {
|
|
|
-
|
|
|
+ public function getVrOrderInfo($order_sn, $member_id = null)
|
|
|
+ {
|
|
|
+
|
|
|
//验证订单信息
|
|
|
$model_order = Model('vr_order');
|
|
|
$condition = array();
|
|
@@ -64,11 +116,11 @@ class paymentLogic {
|
|
|
$condition['buyer_id'] = $member_id;
|
|
|
}
|
|
|
$order_info = $model_order->getOrderInfo($condition);
|
|
|
- if(empty($order_info)){
|
|
|
- return callback(false,'该订单不存在');
|
|
|
+ if (empty($order_info)) {
|
|
|
+ return callback(false, '该订单不存在');
|
|
|
}
|
|
|
|
|
|
- $order_info['subject'] = '虚拟订单_'.$order_sn;
|
|
|
+ $order_info['subject'] = '虚拟订单_' . $order_sn;
|
|
|
$order_info['order_type'] = 'vr_order';
|
|
|
$order_info['pay_sn'] = $order_sn;
|
|
|
|
|
@@ -76,8 +128,8 @@ class paymentLogic {
|
|
|
$pay_amount = ncPriceFormat(floatval($order_info['order_amount']) - floatval($order_info['pd_amount']));
|
|
|
|
|
|
$order_info['api_pay_amount'] = $pay_amount;
|
|
|
-
|
|
|
- return callback(true,'',$order_info);
|
|
|
+
|
|
|
+ return callback(true, '', $order_info);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -86,7 +138,8 @@ class paymentLogic {
|
|
|
* @param int $member_id
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function getPdOrderInfo($pdr_sn, $member_id = null) {
|
|
|
+ public function getPdOrderInfo($pdr_sn, $member_id = null)
|
|
|
+ {
|
|
|
|
|
|
$model_pd = Model('predeposit');
|
|
|
$condition = array();
|
|
@@ -96,47 +149,49 @@ class paymentLogic {
|
|
|
}
|
|
|
|
|
|
$order_info = $model_pd->getPdRechargeInfo($condition);
|
|
|
- if(empty($order_info)){
|
|
|
- return callback(false,'该订单不存在');
|
|
|
+ if (empty($order_info)) {
|
|
|
+ return callback(false, '该订单不存在');
|
|
|
}
|
|
|
|
|
|
- $order_info['subject'] = '预存款充值_'.$order_info['pdr_sn'];
|
|
|
+ $order_info['subject'] = '预存款充值_' . $order_info['pdr_sn'];
|
|
|
$order_info['order_type'] = 'pd_order';
|
|
|
$order_info['pay_sn'] = $order_info['pdr_sn'];
|
|
|
$order_info['api_pay_amount'] = $order_info['pdr_amount'];
|
|
|
- return callback(true,'',$order_info);
|
|
|
+ return callback(true, '', $order_info);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 取得所使用支付方式信息
|
|
|
* @param unknown $payment_code
|
|
|
*/
|
|
|
- public function getPaymentInfo($payment_code) {
|
|
|
- if (in_array($payment_code,array('offline','predeposit')) || empty($payment_code)) {
|
|
|
- return callback(false,'系统不支持选定的支付方式');
|
|
|
+ public function getPaymentInfo($payment_code)
|
|
|
+ {
|
|
|
+ if (in_array($payment_code, array('offline', 'predeposit')) || empty($payment_code)) {
|
|
|
+ return callback(false, '系统不支持选定的支付方式');
|
|
|
}
|
|
|
$model_payment = Model('payment');
|
|
|
$condition = array();
|
|
|
$condition['payment_code'] = $payment_code;
|
|
|
$payment_info = $model_payment->getPaymentOpenInfo($condition);
|
|
|
- if(empty($payment_info)) {
|
|
|
- return callback(false,'系统不支持选定的支付方式');
|
|
|
+ if (empty($payment_info)) {
|
|
|
+ return callback(false, '系统不支持选定的支付方式');
|
|
|
}
|
|
|
|
|
|
- $inc_file = BASE_PATH.DS.'api'.DS.'payment'.DS.$payment_info['payment_code'].DS.$payment_info['payment_code'].'.php';
|
|
|
- if(!file_exists($inc_file)){
|
|
|
- return callback(false,'系统不支持选定的支付方式');
|
|
|
+ $inc_file = BASE_PATH . DS . 'api' . DS . 'payment' . DS . $payment_info['payment_code'] . DS . $payment_info['payment_code'] . '.php';
|
|
|
+ if (!file_exists($inc_file)) {
|
|
|
+ return callback(false, '系统不支持选定的支付方式');
|
|
|
}
|
|
|
require_once($inc_file);
|
|
|
- $payment_info['payment_config'] = unserialize($payment_info['payment_config']);
|
|
|
+ $payment_info['payment_config'] = unserialize($payment_info['payment_config']);
|
|
|
|
|
|
- return callback(true,'',$payment_info);
|
|
|
+ return callback(true, '', $payment_info);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 支付成功后修改实物订单状态
|
|
|
*/
|
|
|
- public function updateRealOrder($out_trade_no, $payment_code, $order_list, $trade_no) {
|
|
|
+ public function updateRealOrder($out_trade_no, $payment_code, $order_list, $trade_no)
|
|
|
+ {
|
|
|
$post['payment_code'] = $payment_code;
|
|
|
$post['trade_no'] = $trade_no;
|
|
|
return Logic('order')->changeOrderReceivePay($order_list, 'system', '系统', $post);
|
|
@@ -145,7 +200,8 @@ class paymentLogic {
|
|
|
/**
|
|
|
* 支付成功后修改虚拟订单状态
|
|
|
*/
|
|
|
- public function updateVrOrder($out_trade_no, $payment_code, $order_info, $trade_no) {
|
|
|
+ public function updateVrOrder($out_trade_no, $payment_code, $order_info, $trade_no)
|
|
|
+ {
|
|
|
$post['payment_code'] = $payment_code;
|
|
|
$post['trade_no'] = $trade_no;
|
|
|
return Logic('vr_order')->changeOrderStatePay($order_info, 'system', $post);
|
|
@@ -159,7 +215,8 @@ class paymentLogic {
|
|
|
* @throws Exception
|
|
|
* @return multitype:unknown
|
|
|
*/
|
|
|
- public function updatePdOrder($out_trade_no,$trade_no,$payment_info,$recharge_info) {
|
|
|
+ public function updatePdOrder($out_trade_no, $trade_no, $payment_info, $recharge_info)
|
|
|
+ {
|
|
|
|
|
|
$condition = array();
|
|
|
$condition['pdr_sn'] = $recharge_info['pdr_sn'];
|
|
@@ -174,12 +231,12 @@ class paymentLogic {
|
|
|
$model_pd = Model('predeposit');
|
|
|
try {
|
|
|
$model_pd->beginTransaction();
|
|
|
- $pdnum=$model_pd->getPdRechargeCount(array('pdr_sn'=>$recharge_info['pdr_sn'],'pdr_payment_state'=>1));
|
|
|
- if (intval($pdnum)>0) {
|
|
|
+ $pdnum = $model_pd->getPdRechargeCount(array('pdr_sn' => $recharge_info['pdr_sn'], 'pdr_payment_state' => 1));
|
|
|
+ if (intval($pdnum) > 0) {
|
|
|
throw new Exception('订单已经处理');
|
|
|
}
|
|
|
//更改充值状态
|
|
|
- $state = $model_pd->editPdRecharge($update,$condition);
|
|
|
+ $state = $model_pd->editPdRecharge($update, $condition);
|
|
|
if (!$state) {
|
|
|
throw new Exception('更新充值状态失败');
|
|
|
}
|
|
@@ -189,13 +246,13 @@ class paymentLogic {
|
|
|
$data['member_name'] = $recharge_info['pdr_member_name'];
|
|
|
$data['amount'] = $recharge_info['pdr_amount'];
|
|
|
$data['pdr_sn'] = $recharge_info['pdr_sn'];
|
|
|
- $model_pd->changePd('recharge',$data);
|
|
|
+ $model_pd->changePd('recharge', $data);
|
|
|
$model_pd->commit();
|
|
|
return callback(true);
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
$model_pd->rollback();
|
|
|
- return callback(false,$e->getMessage());
|
|
|
+ return callback(false, $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|