提交 5252d731 编写于 作者: D devil

iepay支付优化

上级 d6717189
......@@ -59,14 +59,28 @@ class OrderCurrencyService
* @version 1.0.0
* @date 2020-09-17
* @desc description
* @param [array|int] $order_ids [订单id]
* @param [array|int] $order_value [订单id或者编号]
* @param [string] $order_key [订单主键字段名称(order_id|order_no)(默认order_id)]
* @return [array] [货币数据、参数是多个id则返回二维数组,一个id则返回一维数组]
*/
public static function OrderCurrencyGroupList($order_ids)
public static function OrderCurrencyGroupList($order_value, $order_key = 'order_id')
{
$data = Db::name('OrderCurrency')->where(['order_id'=>$order_ids])->select();
// 是否订单编号
if($order_key == 'order_no')
{
// 数组读取多个id,则读取单个订单id
if(is_array($order_value))
{
$order_value = Db::name('OrderCurrency')->where(['order_no'=>$order_value])->column('id');
} else {
$order_value = Db::name('OrderCurrency')->where(['order_no'=>$order_value])->value('id');
}
}
// 数据处理
$data = Db::name('OrderCurrency')->where(['order_id'=>$order_value])->select();
$result = [];
if(!empty($data) && is_array($order_ids) && count($order_ids) > 1)
if(!empty($data) && is_array($order_value) && count($order_value) > 1)
{
foreach($data as $v)
{
......
......@@ -331,12 +331,37 @@ class IEPayAliPay
return DataReturn($ret, -1);
}
// 退款金额
$refund_price = $params['refund_price'];
// 金额转换
if(isset($this->config['is_reverse_price']) && $this->config['is_reverse_price'] == 1)
{
// 获取订单信息
$log_data = \app\service\PayLogService::PayLogList(['where'=>['log_no'=>$params['order_no']]]);
if($log_data['code'] == 0 && !empty($log_data['data']) && !empty($log_data['data'][0]) && !empty($log_data['data'][0]['business_list']) && count($log_data['data'][0]['business_list']) == 1)
{
switch($log_data['data'][0]['business_type'])
{
// 订单
case \app\service\OrderService::$business_type_name :
// 获取订单汇率
$currency_data = \app\service\OrderCurrencyService::OrderCurrencyGroupList($log_data['data'][0]['business_list'][0]['business_id']);
if(isset($currency_data['currency_rate']) && $currency_data['currency_rate'] > 0)
{
$refund_price /= $currency_data['currency_rate'];
}
break;
}
}
}
// 远程查询支付状态
$parameter = [
'mid' => $this->config['mid'],
'pay_type' => $this->GetPayType($params['client_type']),
'out_trade_no' => $params['order_no'],
'refund_amount' => (int) (($params['refund_price']*1000)/10),
'refund_amount' => (int) ((PriceNumberFormat($refund_price)*1000)/10),
'version' => 'v1',
];
......
......@@ -349,11 +349,50 @@ class IEPayWeixin
$data['buyer_user'] = $data['pay_type']; // 支付平台 - 用户
$data['out_trade_no'] = $data['out_trade_no']; // 本系统发起支付的 - 订单号
$data['subject'] = isset($data['order_status']) ? '状态:'.$data['order_status'] : ''; // 本系统发起支付的 - 商品名称
$data['pay_price'] = $data['total_fee']/100; // 本系统发起支付的 - 总价
$data['pay_price'] = $this->RespondReversePrice($data['out_trade_no'], $data['total_fee']); // 本系统发起支付的 - 总价
return $data;
}
/**
* 金额转换
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-09-23
* @desc description
* @param [string] $out_trade_no [支付日志订单号]
* @param [float] $total_fee [平台返回的支付金额]
*/
private function RespondReversePrice($out_trade_no, $total_fee)
{
$total_fee /= 100;
// 金额转换
if(isset($this->config['is_reverse_price']) && $this->config['is_reverse_price'] == 1)
{
// 获取订单信息
$log_data = \app\service\PayLogService::PayLogList(['where'=>['log_no'=>$out_trade_no]]);
if($log_data['code'] == 0 && !empty($log_data['data']) && !empty($log_data['data'][0]) && !empty($log_data['data'][0]['business_list']) && count($log_data['data'][0]['business_list']) == 1)
{
switch($log_data['data'][0]['business_type'])
{
// 订单
case \app\service\OrderService::$business_type_name :
// 获取订单汇率
$currency_data = \app\service\OrderCurrencyService::OrderCurrencyGroupList($log_data['data'][0]['business_list'][0]['business_id']);
if(isset($currency_data['currency_rate']) && $currency_data['currency_rate'] > 0)
{
$total_fee *= $currency_data['currency_rate'];
}
break;
}
}
}
return PriceNumberFormat($total_fee);
}
/**
* 退款处理
* @author Devil
......@@ -394,12 +433,37 @@ class IEPayWeixin
return DataReturn($ret, -1);
}
// 退款金额
$refund_price = $params['refund_price'];
// 金额转换
if(isset($this->config['is_reverse_price']) && $this->config['is_reverse_price'] == 1)
{
// 获取订单信息
$log_data = \app\service\PayLogService::PayLogList(['where'=>['log_no'=>$params['order_no']]]);
if($log_data['code'] == 0 && !empty($log_data['data']) && !empty($log_data['data'][0]) && !empty($log_data['data'][0]['business_list']) && count($log_data['data'][0]['business_list']) == 1)
{
switch($log_data['data'][0]['business_type'])
{
// 订单
case \app\service\OrderService::$business_type_name :
// 获取订单汇率
$currency_data = \app\service\OrderCurrencyService::OrderCurrencyGroupList($log_data['data'][0]['business_list'][0]['business_id']);
if(isset($currency_data['currency_rate']) && $currency_data['currency_rate'] > 0)
{
$refund_price /= $currency_data['currency_rate'];
}
break;
}
}
}
// 远程查询支付状态
$parameter = [
'mid' => $this->config['mid'],
'pay_type' => $this->GetPayType($params['client_type']),
'out_trade_no' => $params['order_no'],
'refund_amount' => (int) (($params['refund_price']*1000)/10),
'refund_amount' => (int) ((PriceNumberFormat($refund_price)*1000)/10),
'version' => 'v1',
];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册