public function createTransOrderForBatch($fields) { $longId = CommonUtil::longId(); //$batchNo = $longId . sprintf('%03s', $fields['channel']) . sprintf('%02s', $fields['gateway']) . mt_rand(100, 999) ; $batchNo = date('ymdHis') . mt_rand(100, 999); $requestData = json_decode($fields['request_data'], true); foreach ($requestData as $field) { if (!in_array($fields['gateway'], $this->_allowTransGateway)) { throw new PayException(ErrorCode::ERR_GATEWAY_FAIL, '该gateway不允许提现'); } $validation = new TransValidator($field); if (!$validation->passes(TransValidator::$transDetailRule)) { throw new PayException(ErrCode::ERR_PARAM, $validation->errors); } if ($fields['gateway'] == PayVars::GATEWAY_YEEPAY) { if (!isset($field['bank_code']) || !isset(PayBankVars::$yeepayBankAlis[$field['bank_code']])) { throw new PayException(ErrCode::ERR_PARAM, '银行编码错误!'); } } $account = AccountBiz::getInstance()->getOrCreateAccount($field['user_id'], $fields['channel']); $primaryId = CommonUtil::LongIdIncrease($longId); $merTransNo = $primaryId; $insertArr[] = ['id' => $primaryId, 'user_id' => $field['user_id'], 'account_id' => $account['id'], 'mer_trans_no' => null !== ($localEnv = \GlobalConfig::getLocalEnv()) ? $merTransNo . $localEnv : $merTransNo, 'batch_no' => $batchNo, 'trans_amount' => $field['trans_amount'], 'create_time' => time(), 'person_name' => $field['user_name'], 'person_account' => $field['user_account'], 'channel' => $fields['channel'], 'gateway' => $fields['gateway'], 'callback_url' => $fields['callback_url'], 'subject' => $fields['subject'], 'body' => isset($field['body']) ? $field['body'] : '', 'mobile_no' => isset($field['mobile']) ? $field['mobile'] : '', 'bank_code' => isset($field['bank_code']) ? $field['bank_code'] : '', 'busi_trans_no' => isset($field['busi_trans_no']) ? $field['busi_trans_no'] : '']; } $trans = new TransModel(); if (true !== $trans->insert($insertArr)) { throw new PayException(ErrCode::ERR_SYSTEM, '数据库保存失败'); } return $batchNo; }
public function getAccount() { self::$userId = \Input::get('user_id', ''); self::$accChannel = ChannelUtil::calculateAccountChannel(\Input::get('channel', 0)); $account = AccountBiz::getInstance()->getAccount(self::$userId, self::$accChannel); if (!$account) { throw new PayException(ErrCode::ERR_ACCOUNT_NO_EXISTS); } return $account; }
public function confirmRefundOrderById($orderId, $data) { $time = time(); $errCode = 0; $errMsg = ''; \DB::beginTransaction(); do { try { $order = RefundModel::find($orderId); if (!$order) { throw new PayException(ErrCode::ERR_ORDER_NO_EXISTS); } elseif ($order->status == RefundModel::STATUS_SUCCESS) { $errCode = 1; break; } if (isset($data['ser_refund_no']) && !empty($data['ser_refund_no'])) { $order->ser_refund_no = $data['ser_refund_no']; } if (isset($data['notify_log'])) { $order->ser_notify_log = $data['notify_log']; } if (isset($data['notify_status'])) { $order->ser_notify_status = $data['notify_status']; } if (isset($data['seller_partner'])) { $order->seller_partner = $data['seller_partner']; } $order->refund_time = $data['refund_time']; $order->ser_notify_time = $data['notify_time']; $order->save(); AccountBiz::getInstance()->updateUserAccount($order->user_id, RefundModel::DEAL_OUT_REFUND, $order->refund_amount, $order->channel); } catch (\Exception $e) { $errCode = 1; } } while (0); if ($errCode == 0) { \DB::commit(); if (true !== BusiNotifyBiz::getInstance()->notifyCallback($order, 'refund')) { \Queue::later(5, '\\Pay\\Service\\Queue\\BusiNotifyQueue', ['id' => $order->id, 'notify_type' => 'refund']); } return true; } else { \DB::rollback(); return false; } }
public function refundConsumeOrderById($orderId, $amount) { $time = time(); $errCode = 0; $errMsg = ''; \DB::beginTransaction(); do { $order = ConsumeModel::find($orderId); if (!$order) { $errCode = ErrCode::ERR_ORDER_NO_EXISTS; throw new PayException($errCode); } elseif ($order->status != ConsumeModel::STATUS_SUCCESS) { $errCode = ErrCode::ERR_ORDER_STATUS; throw new PayException($errCode); } $order->refund_count++; $order->refund_amount += $amount; $order->refund_time = $time; $order->update_time = $time; $order->save(); AccountBiz::getInstance()->updateUserAccount($order->user_id, ConsumeModel::DEAL_IN_REFUND, $amount, $order->channel); } while (0); if ($errCode == 0) { \DB::commit(); return true; } else { \DB::rollback(); return false; } }