|
@@ -16,13 +16,13 @@ use WeChatPay\Crypto\Rsa;
|
|
|
|
|
|
/**
|
|
|
* 微信支付接口
|
|
|
- *
|
|
|
+ *
|
|
|
* @author JUN
|
|
|
- *
|
|
|
+ *
|
|
|
* */
|
|
|
class WechatTransfer extends Api{
|
|
|
/**
|
|
|
- * 小程序微信支付提现 /api/wechat_pay/transfer
|
|
|
+ * 小程序微信提现 商户转账 /api/wechat_pay/transfer
|
|
|
*
|
|
|
* */
|
|
|
public function transfer(Custom $Custom,CustomAmount $CustomAmount,CustomAmountRecord $CustomAmountRecord)
|
|
@@ -60,7 +60,6 @@ class WechatTransfer extends Api{
|
|
|
$amountUpdate = [
|
|
|
'amount'=>DB::raw('amount-'.$amount),
|
|
|
'use_amount'=>DB::raw('use_amount+'.$amount),
|
|
|
- 'transfer_amount'=>DB::raw('transfer_amount+'.$amount),
|
|
|
'update_time'=>time()
|
|
|
];
|
|
|
$result = $CustomAmount::query()->where(['custom_uid'=>$uid])->update($amountUpdate);
|
|
@@ -81,7 +80,7 @@ class WechatTransfer extends Api{
|
|
|
'pay_type' => 1,
|
|
|
'balance' => $balance,
|
|
|
'description' => '余额提现',
|
|
|
- 'status' => 0,
|
|
|
+ 'status' => 1,
|
|
|
];
|
|
|
//写入余额记录
|
|
|
$recordResult = $CustomAmountRecord->add($data);
|
|
@@ -101,11 +100,11 @@ class WechatTransfer extends Api{
|
|
|
];
|
|
|
return json_send(['code'=>'success','msg'=>'成功','data'=>$list]);
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 小程序微信支付回调 /api/wechat_pay/notify
|
|
|
- *
|
|
|
- * */
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 小程序微信商户转账回调 /api/wechat_pay/notify
|
|
|
+ *
|
|
|
+ * */
|
|
|
public function notify()
|
|
|
{
|
|
|
Log::error('wechat/transfer_notify', '提现转账回调开始');
|
|
@@ -160,13 +159,18 @@ class WechatTransfer extends Api{
|
|
|
// 把解密后的文本转换为PHP Array数组
|
|
|
$inBodyResourceArray = (array)json_decode($inBodyResource, true);
|
|
|
Log::error('wechat/transfer_notify', '打印解密后的结果:' . json_encode($inBodyResourceArray));
|
|
|
- Log::error('wechat/transfer_notify', '参数:' . $inBodyResourceArray['trade_state'] . '订单号' . $inBodyResourceArray['out_trade_no'] . '微信支付号' . $inBodyResourceArray['transaction_id']);
|
|
|
- if ($inBodyResourceArray['trade_state'] == "SUCCESS") {
|
|
|
- $status = 2;
|
|
|
- //更新余额订单状态
|
|
|
+ Log::error('wechat/transfer_notify', '参数:' . $inBodyResourceArray['state'] . '订单号' . $inBodyResourceArray['out_bill_no'] . '微信支付号' . $inBodyResourceArray['transfer_bill_no']);
|
|
|
+ $amountInfo = CustomAmountRecord::query()->where('out_bill_no','=',$inBodyResourceArray['out_bill_no'])->first();
|
|
|
+ if (!$amountInfo) {
|
|
|
+ Log::error('wechat/transfer_notify', '获取余额记录信息失败' . json_encode($amountInfo));
|
|
|
+ return json_send(['code'=>'FAIL']);
|
|
|
+ }
|
|
|
+ if ($inBodyResourceArray['state'] == "SUCCESS") {
|
|
|
+ $transfer_amount = $inBodyResourceArray['transfer_amount']/100;
|
|
|
+ //更新余额记录状态
|
|
|
$data = [
|
|
|
'pay_time' => time(),
|
|
|
- 'status'=>$status,
|
|
|
+ 'status'=>2,
|
|
|
];
|
|
|
$res = CustomAmountRecord::query()->where('out_bill_no','=',$inBodyResourceArray['out_bill_no'])->update($data);
|
|
|
Log::error('wechat/transfer_notify', '更新余额记录,snowflake_id:'.$inBodyResourceArray['out_bill_no'].';'. json_encode($res));
|
|
@@ -174,29 +178,34 @@ class WechatTransfer extends Api{
|
|
|
Log::error('wechat/transfer_notify', '更新余额记录失败' . json_encode($res));
|
|
|
return json_send(['code'=>'FAIL']);
|
|
|
}
|
|
|
+ //更新用户提现成功数额
|
|
|
+ $res = CustomAmount::query()->where('custom_uid','=',$amountInfo['custom_uid'])->update(['transfer_amount'=>DB::raw('transfer_amount+'.$transfer_amount)]);
|
|
|
+ Log::error('wechat/transfer_notify', '更新用户提现成功数额,custom_uid:'.$amountInfo['custom_uid'].';'. json_encode($res));
|
|
|
+ if (!$res) {
|
|
|
+ Log::error('wechat/transfer_notify', '更新余额记录失败' . json_encode($res));
|
|
|
+ return json_send(['code'=>'FAIL']);
|
|
|
+ }
|
|
|
Log::error('wechat/transfer_notify', '支付回调完成 通知返回' . json_encode($data));
|
|
|
- }elseif ($inBodyResourceArray['trade_state'] == "FAIL"){
|
|
|
- $status = 3;
|
|
|
+ }elseif ($inBodyResourceArray['state'] == "FAIL"){
|
|
|
//更新余额订单状态
|
|
|
$data = [
|
|
|
- 'status'=>$status
|
|
|
+ 'status'=>3
|
|
|
];
|
|
|
$res = CustomAmountRecord::query()->where('out_bill_no','=',$inBodyResourceArray['out_bill_no'])->update($data);
|
|
|
- Log::error('wechat/transfer_notify', '更新余额记录,snowflake_id:'.$inBodyResourceArray['out_bill_no'].';'. json_encode($res));
|
|
|
+ Log::error('wechat/transfer_notify', '更新余额记录,out_bill_no:'.$inBodyResourceArray['out_bill_no'].';'. json_encode($res));
|
|
|
if (!$res) {
|
|
|
Log::error('wechat/transfer_notify', '更新余额记录失败' . json_encode($res));
|
|
|
return json_send(['code'=>'FAIL']);
|
|
|
}
|
|
|
- $amountInfo = CustomAmountRecord::query()->where('out_bill_no','=',$inBodyResourceArray['out_bill_no'])->first();
|
|
|
- if ($amountInfo){
|
|
|
- Log::error('wechat/transfer_notify', '获取余额记录信息失败' . json_encode($res));
|
|
|
- return json_send(['code'=>'FAIL']);
|
|
|
- }
|
|
|
//退回余额
|
|
|
- $res = CustomAmount::query()->where('uid','=',$amountInfo['custom_uid'])->increment('amount',$amountInfo['amount']);
|
|
|
- if (!$res){
|
|
|
- Log::error('wechat/transfer_notify', '退回余额失败' . json_encode($amountInfo));
|
|
|
- return json_send(['code'=>'FAIL']);
|
|
|
+ $amountUpdate = [
|
|
|
+ 'amount'=>DB::raw('amount+'.$amountInfo['amount']),
|
|
|
+ 'use_amount'=>DB::raw('use_amount-'.$amountInfo['amount']),
|
|
|
+ 'update_time'=>time()
|
|
|
+ ];
|
|
|
+ $result = CustomAmount::query()->where(['custom_uid'=>$amountInfo['custom_uid']])->update($amountUpdate);
|
|
|
+ if (!$result) {
|
|
|
+ return json_send(['code'=>'error','msg'=>'提现失败退回余额失败','data'=>['error'=>'退回用户余额失败']]);
|
|
|
}
|
|
|
Log::error('wechat/transfer_notify', '回调完成 通知返回' . json_encode($amountInfo));
|
|
|
}
|