Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 public function createRefundOrder($fields)
 {
     $account = AccountBiz::getInstance()->getOrCreateAccount($fields['user_id'], $fields['channel']);
     $refund = new RefundModel();
     $refund->id = CommonUtil::longId();
     $refund->user_id = $fields['user_id'];
     $refund->account_id = $account['id'];
     $refund->channel = $fields['channel'];
     $refund->gateway = $fields['gateway'];
     $refund->recharge_id = $fields['recharge_id'];
     $refund->mer_refund_no = $refund->id . substr(sprintf('%012s', $fields['user_id']), -12);
     if (null !== ($localEnv = \GlobalConfig::getLocalEnv())) {
         $refund->mer_refund_no = substr($refund->mer_refund_no, 0, -strlen($localEnv)) . $localEnv;
     }
     $refund->amount = $fields['refund_amount'];
     $refund->create_time = time();
     $refund->callback_url = $fields['callback_url'];
     $refund->subject = $fields['subject'];
     $refund->body = isset($fields['body']) ? $fields['body'] : '';
     $refund->busi_refund_no = isset($fields['busi_refund_no']) ? $fields['busi_refund_no'] : '';
     $refund->seller_partner = isset($fields['seller_partner']) ? $fields['seller_partner'] : '';
     if (true !== $refund->save()) {
         throw new PayException(ErrCode::ERR_ORDER_CREATE_FAIL);
     }
     return $refund;
 }
Esempio n. 3
0
 public function createRechargeOrder($fields)
 {
     $account = AccountBiz::getInstance()->getOrCreateAccount($fields['user_id'], $fields['channel']);
     $primaryId = $this->_rechargeModel->calculPrimaryId();
     $this->_rechargeModel->id = $primaryId;
     $this->_rechargeModel->user_id = $fields['user_id'];
     $this->_rechargeModel->account_id = $account['id'];
     $this->_rechargeModel->channel = $fields['channel'];
     $this->_rechargeModel->gateway = $fields['gateway'];
     $this->_rechargeModel->mer_recharge_no = $primaryId . substr(sprintf('%012s', $fields['user_id']), -12);
     if (null !== ($localEnv = \GlobalConfig::getLocalEnv())) {
         $this->_rechargeModel->mer_recharge_no = substr($this->_rechargeModel->mer_recharge_no, 0, -strlen($localEnv)) . $localEnv;
     }
     $this->_rechargeModel->recharge_amount = $fields['recharge_amount'];
     $this->_rechargeModel->create_time = time();
     $this->_rechargeModel->return_url = $fields['return_url'];
     $this->_rechargeModel->callback_url = $fields['callback_url'];
     $this->_rechargeModel->subject = $fields['subject'];
     $this->_rechargeModel->expire_time = isset($fields['expire_time']) ? $fields['expire_time'] : 0;
     $this->_rechargeModel->consume_id = isset($fields['consume_id']) ? $fields['consume_id'] : '';
     $this->_rechargeModel->body = isset($fields['body']) ? $fields['body'] : '';
     $this->_rechargeModel->city_id = isset($fields['city_id']) ? $fields['city_id'] : 0;
     $this->_rechargeModel->plat = isset($fields['plat']) ? $fields['plat'] : 1;
     $this->_rechargeModel->plat_ext = isset($fields['plat_ext']) ? $fields['plat_ext'] : '';
     $this->_rechargeModel->mobile_no = isset($fields['mobile']) ? $fields['mobile'] : '';
     $this->_rechargeModel->bank_code = isset($fields['bank_code']) ? $fields['bank_code'] : '';
     $this->_rechargeModel->busi_recharge_no = isset($fields['busi_recharge_no']) ? $fields['busi_recharge_no'] : '';
     $this->_rechargeModel->gateway_account = $fields['gateway'] == PayVars::GATEWAY_WECHAT && isset($fields['open_id']) ? $fields['open_id'] : '';
     if (true !== $this->_rechargeModel->save()) {
         throw new PayException(ErrCode::ERR_ORDER_CREATE_FAIL);
     }
     return $this->_rechargeModel;
 }