作者 郭文星

123

... ... @@ -463,4 +463,76 @@ class Service
{
return self::getSdkVersion() === self::SDK_VERSION_V3;
}
/**
* 提交退款订单
* @param array|float $amount 订单金额
* @param array|float $refund_money 退款金额
* @param string $orderid 订单号
* @param string $refund_sn 退款订单号
* @param string $type 支付类型,可选alipay或wechat
* @param string $remark 退款原因
* @param string $notifyurl 通知回调URL
* @param string $returnurl 跳转返回URL
* @param string $method 支付方式
* @return Response|RedirectResponse|Collection
* @throws Exception
*/
public static function submitRefund($amount = null, $refund_money, $orderid, $refund_sn, $type, $remark = null, $notifyurl = null, $returnurl = null, $method = 'miniapp')
{
if (!is_array($amount)) {
$params = [
'amount' => $amount,
'type' => $type,
'notifyurl' => $notifyurl,
'returnurl' => $returnurl,
'method' => $method,
];
} else {
$params = $amount;
}
$type = isset($params['type']) && in_array($params['type'], ['alipay', 'wechat']) ? $params['type'] : 'wechat';
$request = request();
//$notifyurl = isset($params['notifyurl']) ? $params['notifyurl'] : $request->root(true) . '/addons/epay/index/' . $type . 'RfdNotify';
// $returnurl = isset($params['returnurl']) ? $params['returnurl'] : $request->root(true) . '/addons/epay/index/' . $type . 'return/out_trade_no/' . $orderid;
//$notifyurl = $this->request->domain() . '/api/index/refundNotifyx';
$config = Service::getConfig($type);
$config['notify_url'] = $notifyurl;
$config['return_url'] = $returnurl;
$result = null;
//退款参数
$order_data = [
'out_trade_no' => $orderid,//原订单号
];
if ($type == 'wechat') {
//创建支付对象
$pay = Pay::wechat($config);
$total_fee = $amount * 100;
$refund_fee = $refund_money * 100;
$order_data = array_merge($order_data, [
'out_refund_no' => $refund_sn,//退款订单号
'total_fee' => $total_fee,//支付金额
'refund_fee' => $refund_fee,//退款金额
'refund_desc' => $remark,//退款原因
'type' => $method //支付方式
]);
} else {
$pay = Pay::alipay($config);
$order_data = array_merge($order_data, [
'out_request_no' => $refund_sn,//退款订单号
'refund_amount' => $refund_money,
]);
}
$result = $pay->refund($order_data);
//使用重写的Response类、RedirectResponse、Collection类
if ($result instanceof \Symfony\Component\HttpFoundation\RedirectResponse) {
$result = RedirectResponse::create($result->getTargetUrl());
} elseif ($result instanceof \Symfony\Component\HttpFoundation\Response) {
$result = Response::create($result->getContent());
} elseif ($result instanceof \Yansongda\Supports\Collection) {
$result = Collection::make($result->all());
}
return $result;
}
}
... ...
... ... @@ -3,6 +3,7 @@
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
/**
* 订单管理
... ... @@ -73,4 +74,21 @@ class Order extends Backend
return $this->view->fetch();
}
public function refund($id){
//查询订单
$order=Db::name("order")->where("id",$id)->find();
if($order['is_pay']!=1){
$this->error("该订单无法退款");
}
//拼接退款参数
$pay_fee = $order['price'];
$refund_fee = $pay_fee;
$order_sn = $order['order_no'];
$pay_type = 'wechat';
$reason = '订单退款';
$notifyurl = 'https://wyc.tenyes.cn/api/index/refundNotifyx';//退款回调地址
//直接调用退款方法传参即可
$response = \addons\epay\library\Service::submitRefund($pay_fee, $refund_fee, $order_sn, getRefundSn($order['user_id']), $pay_type, $reason, $notifyurl, '', 'miniapp');
print_r($response);return;
}
}
... ...
... ... @@ -530,7 +530,20 @@ if (!function_exists('check_url_allowed')) {
return false;
}
}
/**
* 工单退款
* 生成退款单号
*/
if (!function_exists('getRefundSn')) {
function getRefundSn($user_id)
{
$rand = $user_id < 99999 ? mt_rand(100000, 99999999) : mt_rand(100, 99999);
$order_sn = date('Yhis') . $rand;
$id = str_pad($user_id, (24 - strlen($order_sn)), '0', STR_PAD_BOTH);
return 'R' . $order_sn . $id;
}
}
if (!function_exists('build_suffix_image')) {
/**
* 生成文件后缀图片
... ...
... ... @@ -33,14 +33,43 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'is_pay', title: __('Is_pay'), searchList: {"1":__('Is_pay 1'),"2":__('Is_pay 2'),"3":__('Is_pay 3')}, formatter: Table.api.formatter.normal},
{field: 'user_name', title: __('User_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'driver_name', title: __('Driver_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'pay_time', title: __('Pay_time'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'refund_time', title: __('Refund_time'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'create_time', title: __('Create_time'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'refund_time', title: __('Refund_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'driver.name', title: __('Driver.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'car.license_plate', title: __('Car.license_plate'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'user.username', title: __('User.username'), operate: 'LIKE'},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
buttons:[
{
name: 'ajax',
title: "退款",
text:"退款",
classname: 'btn btn-xs btn-warning btn-magic btn-ajax',
icon: 'fa fa-paper-plane',
confirm: function (row) {
return "确认退款"
},
url: 'order/refund?id={id}',
success: function (data, ret) {
// Layer.alert(ret.msg + ",返回数据:" + JSON.stringify(data));
// 如果需要阻止成功提示,则必须使用return false;
console.log(data, ret);
Layer.alert(ret.msg);
$("#myTabContent .btn-refresh").trigger("click");
return false;
},
error: function (data, ret) {
console.log(data, ret);
Layer.alert(ret.msg);
$("#myTabContent .btn-refresh").trigger("click");
return false;
}
},
]
}]
]
});
... ...
... ... @@ -30,7 +30,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'start_address', title: __('Start_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'end_address', title: __('End_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'price', title: __('Price'), operate:'BETWEEN'},
{field: 'create_time', title: __('Create_time'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
... ...