活动:支付接口

This commit is contained in:
qiaoxin
2021-05-12 15:17:15 +08:00
parent d5d014c2ba
commit 74b57083f7
10 changed files with 374 additions and 75 deletions

View File

@@ -59,4 +59,23 @@ export enum FIRST_GIFT_STATE {
NOT_OPEN = 0, // 未开启
OPEN = 1, // 开启中
CLOSED = 2, //结束
}
}
/**
* 支付类型
*/
export enum PAY_TYPE {
WX = 1, // 微信
ALI = 2, // 阿里
APPLE = 3, // 苹果
}
/**
* 订单状态类型
*/
export enum ORDER_STATE {
APPLY = 1, // 下单成功
CHECK_ORDER = 2, // 触发查询订单
RESULT_SUCCESS = 3, // 订单成功并结算奖励
RESULT_FAIL = 4, // 订单失败
}

View File

@@ -484,6 +484,7 @@ export const FILENAME = {
DIC_GACHA_CONTENT: 'dic_zyz_recruitContent',
DIC_GIFT_PACKAGE: 'dic_zyz_giftPackage',
DIC_RECRUIT: 'dic_zyz_recruit',
DIC_RMB: 'dic_zyz_rmb'
}
export const WAR_RELATE_TABLES = [

View File

@@ -366,6 +366,11 @@ export const STATUS = {
GM_HERO_NOT_FOUND: { code: 60011, simStr: '未找到武将' },
GM_PVP_DEFENSE_NOT_FOUND: { code: 60012, simStr: '该玩家未保存防守阵' },
GM_PVP_DEFENSE_HERO_NOT_FOUND: { code: 60013, simStr: '该守阵没有该武将' },
GM_JSON_FORMAT_ERR: { code: 60005, simStr: 'json格式错误' }
GM_JSON_FORMAT_ERR: { code: 60005, simStr: 'json格式错误' },
// 支付相关状态 70000 - 79999
NO_PRODUCT_ID: { code: 70001, simStr: '无效商品' },
NO_PAY_TYPE: { code: 70002, simStr: '无效支付类型' },
NO_ORDER: { code: 70003, simStr: '没有此订单' },
DUPLICATE_ORDER: { code: 70004, simStr: '订单已经结算' }
}

73
shared/db/UserOrder.ts Normal file
View File

@@ -0,0 +1,73 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { ORDER_STATE } from '../consts';
/**
* 玩家充值订单
*/
@index({ localOrderID: 1 })
export default class UserOrder extends BaseModel {
@prop({ required: true })
serverId: number; // 区号
@prop({ required: true })
roleId: string; // 用户id
@prop({ required: true })
productID: string; // 商品
@prop({ required: true })
orderID: string; // 平台订单号
@prop({ required: true })
localOrderID: string; // 本地订单号
@prop({ required: true })
payType: number; // 支付类型 PAY_TYPE
@prop({ required: true })
price: number; // 价格
@prop({ required: true })
state: number; // 订单状态 ORDER_STATE 3.支付成功并结算
@prop({ required: true })
message: string; // 信息
//校验订单
public static async check(roleId: string, localOrderID: string, message: string = '') {
let result: UserOrderModelType = await UserOrderModel.findOneAndUpdate({ roleId, localOrderID, state: { $ne: ORDER_STATE.RESULT_SUCCESS } },
{ $set: { state: ORDER_STATE.CHECK_ORDER, message } },
{ new: true }).lean(true);
return result;
}
//订单支付失败
public static async fail(roleId: string, localOrderID: string, message: string = '') {
let result: UserOrderModelType = await UserOrderModel.findOneAndUpdate({ roleId, localOrderID, state: { $ne: ORDER_STATE.RESULT_SUCCESS } },
{ $set: { state: ORDER_STATE.RESULT_FAIL, message } },
{ new: true }).lean(true);
return result;
}
//订单支付成功
public static async success(roleId: string, localOrderID: string, message: string = '') {
let result: UserOrderModelType = await UserOrderModel.findOneAndUpdate({ roleId, localOrderID, state: { $ne: ORDER_STATE.RESULT_SUCCESS } },
{ $set: { state: ORDER_STATE.RESULT_SUCCESS, message } },
{ new: true }).lean(true);
return result;
}
//查询订单详情
public static async findOrder(localOrderID: string) {
let result: UserOrderModelType = await UserOrderModel.findOne({ localOrderID }).lean(true);
return result;
}
//新增订单
public static async applyOrder(serverId: number, roleId: string, productID: string, localOrderID: string, orderID: string, price: number, payType: number, message: string = '') {
let result: UserOrderModelType = await UserOrderModel.findOneAndUpdate({ serverId, roleId, productID, localOrderID, orderID, payType },
{ $set: { price, state: ORDER_STATE.APPLY, message } },
{ upsert: true, new: true }).lean(true);
return result;
}
}
export const UserOrderModel = getModelForClass(UserOrder);
export interface UserOrderModelType extends Pick<DocumentType<UserOrder>, keyof UserOrder> { }
export type UserOrderModelTypeParam = Partial<UserOrderModelType>; // 将所有字段变成可选项

View File

@@ -0,0 +1,22 @@
// RMB商品价格表
import { readJsonFile } from '../util';
import { FILENAME } from '../../consts';
export interface DicRMB {
// 商品ID 必须唯一不能相同
readonly productID: string;
// 类型 ACTIVITY_TYPE
readonly type: number;
// 价格
readonly price: number;
// 描述
readonly message: string;
}
const str = readJsonFile(FILENAME.DIC_RMB);
let arr = JSON.parse(str);
export const dicRMB = new Map<string, DicRMB>();
arr.forEach(o => {
dicRMB.set(o.productID, o);
});

View File

@@ -0,0 +1,14 @@
[
{
"productID": "com.bantu.zyz.yb1",
"type": 15,
"price": 6,
"message": "赵云传购买元宝60"
},
{
"productID": "com.bantu.zyz.yb2",
"type": 15,
"price": 12,
"message": "赵云传购买元宝160"
}
]