diff --git a/webht/third_party/pay/controllers/AlipayTradeService.php b/webht/third_party/pay/controllers/AlipayTradeService.php index b800b331..1b3beed4 100644 --- a/webht/third_party/pay/controllers/AlipayTradeService.php +++ b/webht/third_party/pay/controllers/AlipayTradeService.php @@ -624,7 +624,7 @@ class AlipayTradeService extends CI_Controller $GAI_COLI_SN = isset($advisor_info->COLI_SN) ? $advisor_info->COLI_SN : 0; //CHTAPP订单添加记录前判断是否有记录,以前的APP版本没有交易号,只能拿金额来判断 if (substr($advisor_info->COLI_WebCode, 0, 6) == 'CHTAPP' && strstr($advisor_info->COLI_WebCode, "-") != '-biz') {//只判断前6位字符,CHTAPP-fr CHTAPP-jp等各语种都属于APP订单 - $this->Alipay_model->add_account_info_forAPP( + $is_insert = $this->Alipay_model->add_account_info_forAPP( $GAI_COLI_SN, $advisor_info->COLI_ID, $item->ALI_orderAmount, @@ -638,7 +638,12 @@ class AlipayTradeService extends CI_Controller NULL, $item->ALI_dealId, $ht_memo); + + if ($is_insert) { $this->Alipay_model->insert_biz_order_log($GAI_COLI_SN, 'Refunded'); + $this->payment_model->exec_BIZ_TrainCostAdd($GAI_COLI_SN, $ssje); + } + } else { if (false == $this->Alipay_model->if_biz_gai_exists($item->ALI_dealId) ) { $this->Alipay_model->insert_biz_order_log($GAI_COLI_SN, 'Refunded'); diff --git a/webht/third_party/pay/controllers/PaymentService.php b/webht/third_party/pay/controllers/PaymentService.php index 02949cef..812da87e 100644 --- a/webht/third_party/pay/controllers/PaymentService.php +++ b/webht/third_party/pay/controllers/PaymentService.php @@ -202,7 +202,7 @@ class PaymentService extends CI_Controller { // todo: 检测收/退款是否存在 if (substr($advisor_info->COLI_WebCode, 0, 6) == 'CHTAPP' && strstr($advisor_info->COLI_WebCode, "-") !== '-biz') { /* APP */ - $this->account_model->add_account_info_forAPP( + $is_insert = $this->account_model->add_account_info_forAPP( $COLI_SN, $item->OPN_accountMethod, $advisor_info->COLI_ID, @@ -218,6 +218,9 @@ class PaymentService extends CI_Controller { $item->OPN_transactionId, $ht_memo ); + if ($is_refund === true && $is_insert) { + $this->account_model->exec_BIZ_TrainCostAdd($COLI_SN, $ssje); + } if ($advisor_info->COLI_WebCode == 'CHTAPP' && $advisor_info->COLI_State == 11 && false===$is_refund) { //只修改APP组的订单状态,并且订单进度是我的订单 diff --git a/webht/third_party/pay/models/Alipay_model.php b/webht/third_party/pay/models/Alipay_model.php index fd1fe9e5..799f7550 100644 --- a/webht/third_party/pay/models/Alipay_model.php +++ b/webht/third_party/pay/models/Alipay_model.php @@ -87,10 +87,10 @@ class Alipay_model extends CI_Model { */ public function get_group_accout_info($coli_sn, $pn_txn_id) { // select * from BIZ_GroupAccountInfo where GAI_COLI_SN = 559007281 and GAI_AccreditNo = '91R84932UM059045C' - $info_sql = "select GAI_SN, GAI_State from BIZ_GroupAccountInfo + $info_sql = "select GAI_SN, GAI_State from BIZ_GroupAccountInfo where GAI_COLI_SN = $coli_sn and GAI_AccreditNo = '$pn_txn_id' union - select GAI_SN, GAI_State from GroupAccountInfo + select GAI_SN, GAI_State from GroupAccountInfo where GAI_COLI_SN = $coli_sn and GAI_AccreditNo = '$pn_txn_id'"; $info_query = $this->HT->query($info_sql); @@ -204,8 +204,15 @@ class Alipay_model extends CI_Model { ,DeleteFlag ) VALUES (?,?,15015,?,?,?,?,?,?,?,?,?,?,?,0,0)"; $query = $this->HT->query($sql, array($GAI_COLI_SN, $GAI_SQJE, $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, substr($GAI_AccreditNo,0, 30), $GAI_Memo)); - $insertid = $this->HT->last_id('BIZ_GroupAccountInfo'); - return $query; + // $insertid = $this->HT->last_id('BIZ_GroupAccountInfo'); + // return $query; + return $query->num_rows() > 0; + // affected_rows() doesn't work with the 'sqlsrv' driver in CI2 + // The solution: Upgrade to the latest CodeIgniter 3.0.x version + // $ssql = "SELECT 1 as 'exist' from BIZ_GroupAccountInfo where GAI_AccreditNo=? "; + // $squery = $this->HT->query($ssql, array($GAI_AccreditNo)); + // $ret = $squery->result(); + // return !empty($ret); } //添加收款记录(商务订单) diff --git a/webht/third_party/pay/models/Online_payment_account_model.php b/webht/third_party/pay/models/Online_payment_account_model.php index af998030..f741d35f 100644 --- a/webht/third_party/pay/models/Online_payment_account_model.php +++ b/webht/third_party/pay/models/Online_payment_account_model.php @@ -308,8 +308,15 @@ class Online_payment_account_model extends CI_Model { ,DeleteFlag,LastEditTime ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())"; $query = $this->HT->query($sql, array($GAI_COLI_SN, $GAI_SQJE, $payment_method, $GAI_COLI_SN, $GAI_COLI_ID, $payment_method, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo)); - $insertid = $this->HT->last_id('BIZ_GroupAccountInfo'); - return $query; + // $insertid = $this->HT->last_id('BIZ_GroupAccountInfo'); + // return $query; + return $query->num_rows() > 0; + // affected_rows() doesn't work with the 'sqlsrv' driver in CI2 + // The solution: Upgrade to the latest CodeIgniter 3.0.x version + // $ssql = "SELECT 1 as 'exist' from BIZ_GroupAccountInfo where GAI_AccreditNo=? "; + // $squery = $this->HT->query($ssql, array($GAI_AccreditNo)); + // $ret = $squery->result(); + // return !empty($ret); } //添加收款记录(传统订单) @@ -369,6 +376,17 @@ class Online_payment_account_model extends CI_Model { return $query; } + /** + * QQS: APP组退款之后执行 + * 插入数据到“我的支付” + **/ + public function exec_BIZ_TrainCostAdd($COLI_SN, $ssje) + { + $sql = " EXEC dbo.SP_BIZ_TrainCostAdd $COLI_SN, $ssje "; + $query = $this->HT->query($sql); + return $query; + } + public function save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, $M_RelatedInfo = '', $M_State = 0, $M_AddTime = '', $frominfo = 'paypal msg', $M_Web = 'paypal msg') { $sql = "INSERT INTO Email_AutomaticSend ( diff --git a/webht/third_party/paypal/models/paypal_model.php b/webht/third_party/paypal/models/paypal_model.php index a4d29dbe..98154af4 100644 --- a/webht/third_party/paypal/models/paypal_model.php +++ b/webht/third_party/paypal/models/paypal_model.php @@ -221,8 +221,17 @@ class Paypal_model extends CI_Model { ,DeleteFlag,LastEditTime ) VALUES (?,?,15010,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())"; $query = $this->HT->query($sql, array($GAI_COLI_SN, $GAI_SQJE, $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo,$GAI_API)); - $insertid = $this->HT->last_id('BIZ_GroupAccountInfo'); - return $query; + // $insertid = $this->HT->last_id('BIZ_GroupAccountInfo'); + log_message('error','test:$query ' . __METHOD__ . ': ' . __LINE__ . PHP_EOL . var_export($query->num_rows(), 1)); + return $query->num_rows() > 0; + + // affected_rows() doesn't work with the 'sqlsrv' driver in CI2 + // The solution: Upgrade to the latest CodeIgniter 3.0.x version + // $ssql = "SELECT 1 as 'exist' from BIZ_GroupAccountInfo where GAI_AccreditNo=? "; + // $squery = $this->HT->query($ssql, array($GAI_AccreditNo)); + // $ret = $squery->result(); + // log_message('error','test: empty insert ' . __METHOD__ . ': ' . __LINE__ . PHP_EOL . var_export((!empty($ret)), 1)); + // return !empty($ret); } //添加收款记录(商务订单) @@ -659,6 +668,17 @@ class Paypal_model extends CI_Model { return $query; } + /** + * QQS: APP组退款之后执行 + * 插入数据到“我的支付” + **/ + public function exec_BIZ_TrainCostAdd($COLI_SN, $ssje) + { + $sql = " EXEC dbo.SP_BIZ_TrainCostAdd $COLI_SN, $ssje "; + $query = $this->HT->query($sql); + return $query; + } + /** 写入商务订单操作记录 */ public function insert_biz_order_log($coli_sn, $log_info) {