private function _rechargeNotify($notice) { $errCode = 0; $errMsg = ''; do { $rechargeOrder = RechargeModel::where('mer_recharge_no', $notice['mer_recharge_no'])->first(); if (!$rechargeOrder) { $errCode = 2; $errMsg = '充值订单不存在' . $notice['mer_recharge_no']; break; } $rechargeId = $rechargeOrder['id']; $consumeId = $rechargeOrder['consume_id']; if ($consumeId) { $consumeOrder = ConsumeModel::find($consumeId); } $amount = false; if (isset($notice['amount'])) { $amount = $notice['amount']; } /// 需要更新的其他信息 $moreInfo = ['ser_recharge_no' => $notice['ser_recharge_no'], 'gateway_account' => $notice['gateway_account'], 'seller_partner' => $notice['seller_partner'], 'mer_recharge_no' => $notice['mer_recharge_no'], 'pay_time' => $notice['pay_time'], 'notify_log' => $notice['notify_log']]; try { if ($rechargeOrder['status'] != RechargeModel::STATUS_SUCCESS) { $res = RechargeBiz::getInstance()->confirmRechargeOrderById($rechargeId, $amount, $moreInfo); if (false === $res && empty($consumeOrder)) { $errCode = 3; $errMsg = '确认充值订单失败'; break; } } if (!empty($consumeOrder) && $consumeOrder['status'] != ConsumeModel::STATUS_SUCCESS) { $res = ConsumeBiz::getInstance()->confirmConsumeOrderById($consumeOrder['id']); if (false === $res) { $errCode = 3; $errMsg = '确认消费订单失败'; break; } } } catch (\Exception $e) { $errCode = 99; $errMsg = $e->getMessage(); break; } } while (0); $ret = new \stdClass(); $ret->is_success = $errCode === 0 ? 'T' : 'F'; $ret->code = $errCode; $ret->output = $notice['output']; $ret->error = $errMsg; return $ret; }
public function refundConsumeAndRecharge() { if (!$this->validation->passes(RefundValidator::$refundRule)) { throw new PayException(ErrCode::ERR_PARAM); } $fields = \Input::All(); $ret = ConsumeBiz::getInstance()->cancelConsumeOrder($fields['pay_consume_id'], $fields['user_id'], $fields['refund_amount']); if ($ret['pay_consume_id'] > 0 && $ret['pay_recharge_id'] > 0) { $fields['pay_recharge_id'] = $ret['pay_recharge_id']; $cancelRet = RechargeBiz::getInstance()->cancelRechargeOrder($fields); } return $ret; }
public function fire($job, $data) { $errCode = 0; $rechargeOrder = RechargeModel::find($data['id']); do { if ($rechargeOrder->status == RechargeModel::STATUS_SUCCESS) { $errCode = 1; break; } if (!$rechargeOrder->gateway || !$rechargeOrder->channel) { $errCode = 2; break; } $channel = ChannelUtil::calculateAccountChannel($rechargeOrder->channel); if (false === $channel) { $errCode = 3; break; } $gatewayObj = gatewayUtil::getGatewayObj($rechargeOrder->gateway); if (!$gatewayObj) { $errCode = 4; break; } } while (0); if ($errCode == 0) { $orderData = $rechargeOrder->toArray(); $consumeId = $orderData['consume_id']; $queryParams = array('channel' => $channel, 'gateway' => $orderData['gateway'], 'mer_recharge_no' => $orderData['mer_recharge_no']); $queryResult = $gatewayObj->directQuery($queryParams); if ($queryResult->is_success == 'T' && $queryResult->notify_status == 2) { $realAmount = intval($queryResult->amount); $moreInfo = array('ser_recharge_no' => $queryResult->ser_recharge_no, 'gateway_account' => $queryResult->gateway_account, 'seller_partner' => $queryResult->seller_partner, 'pay_time' => $queryResult->pay_time); $ret = RechargeBiz::getInstance()->confirmRechargeOrderById($orderData['id'], $realAmount, $moreInfo); if ($ret == true && $consumeId > 0) { $ret2 = ConsumeBiz::getInstance()->confirmConsumeOrderById($consumeId); } } if ($rechargeOrder->status == RechargeModel::STATUS_SUCCESS || $rechargeOrder->create_time <= time() - 20 * 60) { $job->delete(); } else { $job->release(60); } } else { $job->delete(); } }
public function directConsume($fields) { $ret = []; if ($this->createConsumeOrder($fields)) { $fields['consume_id'] = $this->_consumeModel->id; $fields['recharge_amount'] = $this->_consumeModel->consume_amount; $rechargeOrder = RechargeBiz::getInstance()->createRechargeOrder($fields); $this->_consumeModel->recharge_id = $rechargeOrder->id; $this->_consumeModel->recharge_amount = $rechargeOrder->recharge_amount; $this->_consumeModel->save(); $rechargeUrl = RechargeBiz::getInstance()->directThirdParty($rechargeOrder); if ($rechargeUrl == false) { throw new PayException(ErrCode::ERR_GATEWAY_FAIL); } $ret = ['pay_gateway_url' => $rechargeUrl, 'user_id' => $this->_consumeModel->user_id, 'pay_consume_id' => $this->_consumeModel->id, 'busi_consume_no' => $this->_consumeModel->busi_consume_no, 'consume_amount' => $this->_consumeModel->consume_amount]; \Queue::later(60 * 10, '\\Pay\\Service\\Queue\\SerAutoConfirmQueue', ['id' => $rechargeOrder['id']]); } return $ret; }
public function directBalance() { $fields = \Input::All(); $ret = RechargeBiz::getInstance()->directBalance($fields); return $ret; }