diff --git a/app/Http/Controllers/Server/H5/EarningController.php b/app/Http/Controllers/Server/H5/EarningController.php index c2e5fca..5a05a65 100644 --- a/app/Http/Controllers/Server/H5/EarningController.php +++ b/app/Http/Controllers/Server/H5/EarningController.php @@ -683,7 +683,7 @@ class EarningController extends Controller Log::info("转账回调"); $url = config("app.url") . "/util/api/wechatpay/saas/mch/transfer/callback"; $token = $request->bearerToken(); - $header = [ + $headers = [ 'Authorization' => "Bearer " . $token, 'Content-Type' => 'application/json', 'wechatpay-timestamp' => $_SERVER['HTTP_WECHATPAY_TIMESTAMP'] ?? '', @@ -692,12 +692,14 @@ class EarningController extends Controller 'wechatpay-serial' => $_SERVER['HTTP_WECHATPAY_SERIAL'] ?? '', ]; - $data = $request->all(); + $body = file_get_contents('php://input'); + Log::info("请求头", ["headers" => $headers]); + Log::info("请求体", ["body" => $body]); $options = [ RequestOptions::TIMEOUT => 3, RequestOptions::HTTP_ERRORS => false, - RequestOptions::HEADERS => $header, - RequestOptions::QUERY => $data, + RequestOptions::HEADERS => $headers, + RequestOptions::QUERY => $body, ]; $client = new Client(); $response = $client->post($url, $options); @@ -714,11 +716,17 @@ class EarningController extends Controller DB::beginTransaction(); $withdraw = MEarningwithdraws::where("trade_no", $res["data"]["out_bill_no"])->first(); $earning_account = MEarningAccount::where("m_id", $withdraw->m_id)->where("m_user_id", $withdraw->m_user_id)->first(); //修改账号状态 - $earning_account->decrement('frozen_withdraw', $withdraw->value); - $earning_account->increment('withdrawl', $withdraw->value); - $withdraw->update(['status' => 'finished']); - //成功通知 - $this->sendWithdrawNotice($earning_account, $withdraw); + if ($res["data"]["state"] == "SUCCESS") { + $earning_account->decrement('frozen_withdraw', $withdraw->value); + $earning_account->increment('withdrawl', $withdraw->value); + $withdraw->update(['status' => 'finished']); + //成功通知 + $this->sendWithdrawNotice($earning_account, $withdraw); + } else { // 转账失败 + $earning_account->decrement('frozen_withdraw', $withdraw->value); + $earning_account->increment("balance", $withdraw->value); + $withdraw->update(['status' => 'canceled']); + } DB::commit(); } catch (Exception $e) { DB::rollBack();