where('pay_status', 'SUCCESS') // ->where(function ($query) { // $query->whereRaw("JSON_EXTRACT(`pay_extend_json`, '$.notify') IS NULL") // ->orWhereJsonDoesntContain('pay_extend_json->notify', 'success'); // }) // ->get() // ->toArray(); // if (!$payDetails) { // return; // } // // foreach ($payDetails as $payDetail) { // $this->paySuccess($payDetail['pay_id']); // } // } /** * @Desc * @Author Gorden * @Date 2024/8/19 13:33 * * @param Request $request * @return \support\Response */ public function paySuccess(Request $request) { $data = $request->post(); if (is_json($data)) { $data = json_decode($data, true); } _syslog("APP充值","APP充值回调开始",$data,$data,1001); if (!$data['pay_id']) { return json_fail('参数异常'); } try { $result = $this->disposePaySuccess($data['pay_id']); _syslog("APP充值","APP处理完成",$data,$data,1001); return $result; }catch(BusinessException $e){ _syslog("APP充值","APP充值失败",$data,$data,1001); return json_fail("处理失败"); }catch (\Exception $e){ _syslog("APP充值","APP充值失败",$data,$data,1001); return json_fail("处理失败"); } // public function paySuccess($id) // { // if (!$id) { // return json_fail('参数异常'); // } // // $payDetail = PayDetail::find($id); // if ($payDetail->pay_status != 'SUCCESS') { // return json_fail("支付状态异常"); // } } /** * @param $payId * @return \support\Response * @throws BusinessException */ public function disposePaySuccess($payId){ $payDetail = PayDetail::find($payId); if (!$payDetail || $payDetail->pay_status != 'SUCCESS') { throw new BusinessException("支付状态异常"); // return json_fail("支付状态异常"); } $extendJson = []; if (!empty($payDetail->pay_extend_json)) { $extendJson = json_decode($payDetail->pay_extend_json, true); if (isset($extendJson['notify']) && $extendJson['notify'] == 'success') { return json_success('处理完成'); } } Db::beginTransaction(); try { $extendJson['notify'] = 'success'; $payDetail->pay_extend_json = json_encode($extendJson); $payDetail->save(); // 赠送比例 $objectJson = json_decode($payDetail->join_pay_object_json, true); $addedNbr = 0; if (isset($objectJson['order_id'])) { // 对应订单设置已完成 Order::where('order_groupby',$payDetail->join_pay_order_id)->update(['order_status_system'=>'DONE','order_is_complete'=>'Y','order_status_storage'=>'DONE']); $addedNbr = RechargeService::disposeOrder($objectJson['order_id']); // throw new BusinessException("支付数据异常"); // return json_fail(""); } // 赠送金额累加到 账户表 member_account_added $memberAccount = MemberAccount::where('join_account_member_id', $payDetail->join_pay_member_id) ->where('member_account_classify', 'CASH') ->first(); $payAmount = floatval($payDetail->pay_amount); $added = $memberAccount->member_account_added + $payAmount * $addedNbr; $income = $memberAccount->member_account_income + $payAmount; $memberAccount->member_account_added = $added; $memberAccount->member_account_income = $income; $memberAccount->member_account_surplus = $memberAccount->member_account_surplus + $payAmount; $memberAccount->save(); // 根据最新的数据,更新用户等级 $member = Member::find($payDetail->join_pay_member_id); $roleId = RechargeService::disposeRole($payDetail->join_pay_member_id, $payDetail->pay_amount); if ($roleId && $member->join_member_role_id != $roleId) { $member->join_member_role_id = $roleId; $member->save(); // 处理增值套包、组件 RechargeService::disposeAdded($roleId, $payDetail->join_pay_member_id); } Db::commit(); return json_success('success'); } catch (BusinessException $e) { dump($e->getMessage()); Db::rollBack(); throw new BusinessException("处理失败"); // return json_fail('处理失败'); } catch (\Exception $e) { dump($e->getMessage()); Db::rollBack(); throw new BusinessException("处理失败"); // return json_fail('处理失败'); } } }