fix: Alipay: 解决多次退款时, 异步通知每次都返回已退的总金额, 直接录入导致金额累加了.

webht/payment
Lei OT 1 year ago
parent 4a1a0fd6e1
commit 8afa987676

@ -152,6 +152,13 @@ class AlipayTradeService extends CI_Controller
,$buyer
);
} else if ($notify_type == "refund") {
// 查询已退金额总计
$query_all_refunds = $this->Alipay_note_model->search_deal_refund_from_memo(
strval($asyns_resp->data->trade_no),
strval($asyns_resp->data->gmt_refund)
);
$asyns_resp->data->total_refund_fee = strval($asyns_resp->data->refund_fee);
$asyns_resp->data->refund_fee = ($asyns_resp->data->refund_fee)+($query_all_refunds->refunded_fee);
$this->Alipay_note_model->save_alipay(
strval($asyns_resp->data->out_biz_no)
,strval($asyns_resp->data->out_trade_no)
@ -800,6 +807,8 @@ class AlipayTradeService extends CI_Controller
* @param [type] $dealId 必须, 退款请求号.out_biz_no, 或原始交易订单号
* @param [type] $trade_no 必须, 原收款交易号, 和order_id不能同时为空
* @param [type] $order_id 必须, 原收款订单号, 和trade_no不能同时为空
*
* @ignore 只能查询API发起的退款, 后台的退款查不到
*/
public function query_refund($dealId=NULL,$trade_no=NULL, $order_id=NULL)
{
@ -813,7 +822,8 @@ class AlipayTradeService extends CI_Controller
$response = $this->aopclientRequestExecute ($request);
// $response = $response->alipay_trade_fastpay_refund_query_response;
return $this->output->set_content_type('application/json')->set_output(json_encode($response));
return $response;
// return $this->output->set_content_type('application/json')->set_output(json_encode($response));
}
public function get_billfile($date=NULL)
@ -995,7 +1005,7 @@ class AlipayTradeService extends CI_Controller
* @return obj
*/
function check($arr){
$ret = new ArrayObject();
$ret = new stdClass();
$ret->check = false;
$ret->data = NULL;

@ -71,12 +71,42 @@ class Alipay_note_model extends CI_Model {
$search_key = trim($search_key);
if (!empty($search_key)) {
$search_sql.=" AND ( pn.ALI_dealId = '$search_key'
OR pn.ALI_orderId like '%$search_key%' )";
OR pn.ALI_orderId like '%$search_key%'
OR pn.ALI_memo like '%$search_key%'
)";
}
$this->search = $search_sql;
return $this->get_list();
}
/**
* 根据支付交易号查询已退款的总金额
*/
public function search_deal_refund_from_memo($search_key, $time = NULL)
{
$this->init();
$this->orderby = false;
$search_sql = '';
$search_key = trim($search_key);
if (!empty($search_key)) {
$search_sql .= " AND ( pn.ALI_memo like '%$search_key%' ) and pn.ALI_payType = 'refund' AND ALI_acquiringTime < '$time' ";
}
$this->search = $search_sql;
$sql = "SELECT SUM(CAST(pn.ALI_orderAmount AS FLOAT)) refunded_fee
FROM InfoManager.dbo.AlipayLog pn
WHERE 1=1 ";
$this->search ? $sql .= $this->search : false;
$this->orderby ? $sql .= $this->orderby : false;
// log_message('error', $sql);
$query = $this->INFO->query($sql);
if ($query->num_rows() > 0) {
$row = $query->row();
return $row;
} else {
return FALSE;
}
}
public function note_exists($dealId)
{
$this->init();
@ -95,7 +125,7 @@ class Alipay_note_model extends CI_Model {
IF NOT EXISTS(
SELECT TOP 1 1
FROM AlipayLog
WHERE ALI_dealId = '$ALI_dealId'
WHERE ALI_dealId = '$ALI_dealId' AND ALI_orderAmount = '$ALI_orderAmount'
)
";
$sql .= "

Loading…
Cancel
Save