|
@@ -36,6 +36,7 @@ use support\exception\BusinessException;
|
|
|
use support\Redis;
|
|
|
use support\Request;
|
|
|
use support\Response;
|
|
|
+use Yansongda\Pay\Pay;
|
|
|
use function Qiniu\Http\Middleware\compose;
|
|
|
|
|
|
class WholeController extends Curd
|
|
@@ -482,7 +483,7 @@ class WholeController extends Curd
|
|
|
}
|
|
|
$account->member_account_expend = $account->member_account_expend + $params['order_sheet_pay'];
|
|
|
$account->save();
|
|
|
- }else if ($params['pay_category'] == 'WELFARE') { // 福利账户
|
|
|
+ } else if ($params['pay_category'] == 'WELFARE') { // 福利账户
|
|
|
$account = MemberAccount::where('join_account_member_id', $params['join_order_member_id'])
|
|
|
->where('member_account_classify', 'WELFARE')
|
|
|
->where('member_account_status', 'ACTIVED')
|
|
@@ -496,7 +497,7 @@ class WholeController extends Curd
|
|
|
Db::rollBack();
|
|
|
return json_fail('账户余额不足');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$account->member_account_surplus = $account->member_account_surplus - $params['order_sheet_pay'];
|
|
|
$account->member_account_expend = $account->member_account_expend + $params['order_sheet_pay'];
|
|
|
$account->save();
|
|
@@ -694,9 +695,9 @@ class WholeController extends Curd
|
|
|
public function insertPayDetail($params)
|
|
|
{
|
|
|
try {
|
|
|
- if(in_array($params['pay_category'],['WXPAY','ALIPAY'])){
|
|
|
+ if (in_array($params['pay_category'], ['WXPAY', 'ALIPAY'])) {
|
|
|
$payPrepayid = $params['pay_category'];
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$payPrepayid = $params['join_order_member_id'] . '-' . $params['pay_category'];
|
|
|
}
|
|
|
$data = [
|
|
@@ -1207,37 +1208,31 @@ class WholeController extends Curd
|
|
|
$return->order_return_status = 'DONE';
|
|
|
$return->order_return_refund_json = json_encode(['amount' => $amount]);
|
|
|
$return->save();
|
|
|
+ $payType = explode('-', $payDetail->pay_prepayid);
|
|
|
// 区分账户余额支付和在线支付
|
|
|
- if (isset($payJsonResponse['paytype']) && in_array($payJsonResponse['paytype'], ['WXPAY', 'ALIPAY'])) {
|
|
|
- $responseJson = [];
|
|
|
- if (!empty($payDetail->pay_json_response)) {
|
|
|
- $responseJson = json_decode($payDetail->pay_json_response, true);
|
|
|
- if (!isset($responseJson['trxid'])) {
|
|
|
- throw new PayException("支付信息异常");
|
|
|
- }
|
|
|
- }
|
|
|
- $data = [
|
|
|
- 'randomstr' => random_string(32),
|
|
|
- 'reqsn' => $return->join_return_order_id,
|
|
|
- 'oldtrxid' => $responseJson['trxid'],
|
|
|
- 'trxamt' => $amount * 100,
|
|
|
-
|
|
|
+ if ($payDetail->pay_prepayid == 'WXPAY') {
|
|
|
+ // 退款
|
|
|
+ $wxRefundData = [
|
|
|
+ 'type' => 'app',
|
|
|
+ 'out_trade_no' => $order->order_groupby,
|
|
|
+ 'out_refund_no' => $return->orders_return_id,
|
|
|
+ 'total_fee' => $payDetail->pay_amount * 100,
|
|
|
+ 'refund_fee' => $amount * 100,
|
|
|
+ 'refund_desc' => '退款',
|
|
|
];
|
|
|
-
|
|
|
- $tlpay = new Tlpay();
|
|
|
- $res = $tlpay->refund($data);
|
|
|
-
|
|
|
+ $res = Pay::wechat(config('payment.wxpay'))->refund($wxRefundData);
|
|
|
+ file_put_contents(runtime_path('logs/wxpay.log'), $res);
|
|
|
$resArray = json_decode($res, true);
|
|
|
- if (AppUtil::validSign($resArray)) {
|
|
|
- if ($resArray['retcode'] != 'SUCCESS' || $resArray['trxstatus'] != '0000') {
|
|
|
- throw new PayException('退款失败,原因:' . $resArray['errmsg']);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $payType = explode('-', $payDetail->pay_prepayid);
|
|
|
- // 余额支付
|
|
|
- if (isset($payType[1]) && $payType[1] == 'CASH') {
|
|
|
+ } else if ($payDetail->pay_prepayid == 'ALIPAY') {
|
|
|
+ // 退款
|
|
|
+ $alipayRefundData = [
|
|
|
+ 'out_trade_no' => $order->order_groupby,
|
|
|
+ 'refund_amount' => $amount,
|
|
|
+ ];
|
|
|
+ $res = Pay::alipay(config('payment.alipay'))->refund($alipayRefundData);
|
|
|
+ file_put_contents(runtime_path('logs/alipay.log'), $res);
|
|
|
+ $resArray = json_decode($res, true);
|
|
|
+ } else if (isset($payType[1]) && $payType[1] == 'CASH') { // 余额支付
|
|
|
$account = MemberAccount::where('join_account_member_id', $order->join_order_member_id)
|
|
|
->where('member_account_classify', 'CASH')
|
|
|
->first();
|
|
@@ -1254,9 +1249,7 @@ class WholeController extends Curd
|
|
|
$res = json_encode([
|
|
|
'status' => 'SUCCESS'
|
|
|
]);
|
|
|
- }
|
|
|
- // 员工福利支付
|
|
|
- if (isset($payType[1]) && $payType[1] == 'WELFARE') {
|
|
|
+ } else if (isset($payType[1]) && $payType[1] == 'WELFARE') { // 员工福利支付
|
|
|
$account = MemberAccount::where('join_account_member_id', $order->join_order_member_id)
|
|
|
->where('member_account_classify', 'WELFARE')
|
|
|
->first();
|
|
@@ -1273,9 +1266,7 @@ class WholeController extends Curd
|
|
|
$res = json_encode([
|
|
|
'status' => 'SUCCESS'
|
|
|
]);
|
|
|
- }
|
|
|
- // 卡支付
|
|
|
- if (count($payType) == 1 && !in_array($payDetail->pay_prepayid, ['W06', 'A01'])) {
|
|
|
+ } else if (count($payType) == 1 && !in_array($payDetail->pay_prepayid, ['W06', 'A01'])) { // 卡支付
|
|
|
$account = MemberAccount::where('join_account_member_id', $order->join_order_member_id)
|
|
|
->where('member_account_nbr', $payType[0])
|
|
|
->where('member_account_classify', 'CARD')
|
|
@@ -1296,6 +1287,33 @@ class WholeController extends Curd
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+// if (!empty($payDetail->pay_prepayid) && in_array($payDetail->pay_prepayid, ['WXPAY', 'ALIPAY'])) {
|
|
|
+// $responseJson = [];
|
|
|
+// if (!empty($payDetail->pay_json_response)) {
|
|
|
+// $responseJson = json_decode($payDetail->pay_json_response, true);
|
|
|
+// if (!isset($responseJson['trxid'])) {
|
|
|
+// throw new PayException("支付信息异常");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// $data = [
|
|
|
+// 'randomstr' => random_string(32),
|
|
|
+// 'reqsn' => $return->join_return_order_id,
|
|
|
+// 'oldtrxid' => $responseJson['trxid'],
|
|
|
+// 'trxamt' => $amount * 100,
|
|
|
+//
|
|
|
+// ];
|
|
|
+//
|
|
|
+// $tlpay = new Tlpay();
|
|
|
+// $res = $tlpay->refund($data);
|
|
|
+//
|
|
|
+// $resArray = json_decode($res, true);
|
|
|
+// if (AppUtil::validSign($resArray)) {
|
|
|
+// if ($resArray['retcode'] != 'SUCCESS' || $resArray['trxstatus'] != '0000') {
|
|
|
+// throw new PayException('退款失败,原因:' . $resArray['errmsg']);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
// 生成payDetail
|
|
|
$payDetailData = [
|
|
|
'join_pay_member_id' => $order->join_order_member_id,
|