活动:支付接口
This commit is contained in:
141
game-server/app/servers/order/handler/orderHandler.ts
Normal file
141
game-server/app/servers/order/handler/orderHandler.ts
Normal file
@@ -0,0 +1,141 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { genCode, resResult } from '../../../pubUtils/util';
|
||||
import { ACTIVITY_TYPE, ORDER_STATE, PAY_TYPE, STATUS } from '../../../consts';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { addReward, stringToRewardParam, useGiftPackage } from '../../../services/giftPackageService';
|
||||
import { dicRMB } from '../../../pubUtils/dictionary/DicRMB';
|
||||
import { UserOrderModel } from '../../../db/UserOrder';
|
||||
import _ = require('underscore');
|
||||
|
||||
export default function (app: Application) {
|
||||
return new orderHandler(app);
|
||||
}
|
||||
|
||||
export class orderHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
/************************订单****************************/
|
||||
|
||||
/**
|
||||
* @description 获取订单号
|
||||
* @param {{productID:string, payType:number }} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof orderHandler
|
||||
*/
|
||||
async applyOrder(msg: { productID: string, payType: number }, session: BackendSession) {
|
||||
const { productID, payType } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
|
||||
if (!productID || !_.isString(productID) || !payType || !_.isNumber(payType)) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
//商品价格信息
|
||||
let productInfo = dicRMB.get(productID)
|
||||
if (!productInfo) {
|
||||
return resResult(STATUS.NO_PRODUCT_ID);
|
||||
}
|
||||
|
||||
let price = productInfo.price;//价格
|
||||
let productType = productInfo.type;//类型
|
||||
let localOrderID = genCode(32);//本地订单号
|
||||
let orderID = '';//平台订单号
|
||||
|
||||
//生成订单号
|
||||
let orderInfo = await UserOrderModel.applyOrder(serverId, roleId, productID, localOrderID, orderID, price, payType);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { orderInfo, productInfo });
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description 查询订单,结算奖励
|
||||
* @param {{ localOrderID: string}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof firstGiftHandler
|
||||
*/
|
||||
async checkOrder(msg: { localOrderID: string }, session: BackendSession) {
|
||||
const { localOrderID } = msg;
|
||||
// const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
const funcs: number[] = session.get('funcs');
|
||||
if (!localOrderID || !_.isString(localOrderID)) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
let orderInfo = await UserOrderModel.findOrder(localOrderID);
|
||||
if (!orderInfo) {
|
||||
return resResult(STATUS.NO_ORDER);
|
||||
}
|
||||
if (orderInfo.state == ORDER_STATE.RESULT_SUCCESS) {
|
||||
return resResult(STATUS.DUPLICATE_ORDER);
|
||||
}
|
||||
|
||||
//商品价格信息
|
||||
let productInfo = dicRMB.get(orderInfo.productID)
|
||||
if (!productInfo) {
|
||||
return resResult(STATUS.NO_PRODUCT_ID);
|
||||
}
|
||||
|
||||
let productType = productInfo.type;//类型
|
||||
let price = orderInfo.price;//下单时的价格
|
||||
let payType = orderInfo.payType;//支付类型
|
||||
let roleId = orderInfo.roleId;//角色
|
||||
|
||||
switch (productType) {
|
||||
case ACTIVITY_TYPE.NEW_PLAYER_LIMIT_PACKAGE:
|
||||
{
|
||||
break;
|
||||
}
|
||||
default:
|
||||
console.log('未知错误类型');
|
||||
return resResult(STATUS.NO_PRODUCT_ID);
|
||||
|
||||
}
|
||||
|
||||
orderInfo = await UserOrderModel.check(roleId, localOrderID);
|
||||
if (!orderInfo) {
|
||||
return resResult(STATUS.DUPLICATE_ORDER);
|
||||
}
|
||||
switch (payType) {
|
||||
case PAY_TYPE.WX:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case PAY_TYPE.ALI:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case PAY_TYPE.APPLE:
|
||||
{
|
||||
break;
|
||||
}
|
||||
default:
|
||||
console.log('未知支付类型');
|
||||
return resResult(STATUS.NO_PAY_TYPE);
|
||||
}
|
||||
|
||||
//订单成功
|
||||
let isSuccess = true;
|
||||
if (isSuccess) {
|
||||
orderInfo = await UserOrderModel.success(roleId, localOrderID);
|
||||
if (orderInfo) {
|
||||
//结算奖励
|
||||
console.log('结算完成', localOrderID)
|
||||
return resResult(STATUS.SUCCESS, Object.assign({}));
|
||||
}
|
||||
} else {
|
||||
let message = '订单校验失败';
|
||||
orderInfo = await UserOrderModel.fail(roleId, localOrderID, message);
|
||||
}
|
||||
|
||||
|
||||
return resResult(STATUS.DUPLICATE_ORDER);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user