data = $data; $this->queue = config('queue.names.recharge'); } public function getData() { return $this->data; } public function handle() { $tradeStatus = Arr::get($this->data, 'trade_status'); if ($tradeStatus != 'TRADE_SUCCESS') { return; } if (!isset($this->data['notify_id'])) { Log::error('HandleAgentAlipayResultNotice 没有notify_id', $this->data); return; } $aliNotice = AliAgentNotice::where('notify_id', $this->data['notify_id'])->first(); if ($aliNotice) { Log::error('HandleAgentAlipayResultNotice noticeId_exist', $this->data); return; } $rechargeSn = $this->data['out_trade_no']; $rechargeObj = new CustomerRecharge(); $recharge = $rechargeObj->where('recharge_sn', $rechargeSn)->first(); if (!$recharge) { Log::error('HandleAgentAlipayResultNotice not_found_recharge_sn', [ 'data' => $this->data, 'rechargeSn' => $rechargeSn, ]); return; } $tradeStatus = Arr::get($this->data, 'trade_status', ''); $pay_state = PayState::ERROR; if ($tradeStatus == 'TRADE_SUCCESS') { $pay_state = PayState::SUCCESS; if (!bc_equal(Helps::floatFormat($recharge->pay_money), Helps::floatFormat($this->data['receipt_amount']))) { $pay_state = PayState::UNEQUAL; } } $res = CustomerRecharge::query()->where('id', $recharge->id) ->where('recharge_sn', $rechargeSn) ->whereNotIn('pay_state', [PayState::ERROR,PayState::SUCCESS,PayState::UNEQUAL]) ->update([ 'out_trade_no' => $this->data['trade_no'], 'received_money' => $this->data['receipt_amount'], 'pay_at' => $this->data['gmt_create'], 'pay_state' => $pay_state, ]); if (!$res) { Log::error('HandleAgentAlipayResultNotice recharge_update_fail', [ 'data' => $this->data, 'rechargeSn' => $rechargeSn, 'res' => $res, ]); return; } $aliNotice = new AliAgentNotice(); $aliNotice->notify_id = Arr::get($this->data, 'notify_id', ''); $aliNotice->out_trade_no = Arr::get($this->data, 'out_trade_no', ''); $aliNotice->trade_no = Arr::get($this->data, 'trade_no', ''); $aliNotice->trade_status = $tradeStatus; $aliNotice->receipt_amount = Arr::get($this->data, 'receipt_amount', 0); $aliNotice->buyer_pay_amount = Arr::get($this->data, 'buyer_pay_amount', ''); $aliNotice->total_amount = Arr::get($this->data, 'total_amount', 0); $aliNotice->buyer_id = Arr::get($this->data, 'buyer_id', ''); $aliNotice->auth_app_id = Arr::get($this->data, 'auth_app_id', ''); $aliNotice->app_id = Arr::get($this->data, 'app_id', ''); $aliNotice->seller_email = Arr::get($this->data, 'seller_email', ''); $aliNotice->gmt_create = Arr::get($this->data, 'gmt_create'); $aliNotice->response = $this->data; $aliNotice->save(); if ($pay_state == PayState::SUCCESS) { $recharge = $rechargeObj->where('recharge_sn', $rechargeSn)->first(); CustomerWalletService::recharge($recharge); // 如果有订单,则处理订单支付状态 if ($recharge->order_id > 0) { /** @var OrderService $orderService */ $orderService = app(OrderService::class); $orderService->setOrderPaySuccess($recharge->order); } } } }