协议修改
This commit is contained in:
@@ -61,7 +61,7 @@ export class PurchaseConfig extends BaseConfig {
|
||||
// 获取所有 id
|
||||
let resultId = [];
|
||||
for (let one of allId) {
|
||||
const firstDigit = one.toString()[0];
|
||||
const firstDigit = one.toString()[0]; // 取首位字符
|
||||
if (firstDigit === "2") {
|
||||
resultId.push(one);
|
||||
}
|
||||
@@ -76,7 +76,7 @@ export class PurchaseConfig extends BaseConfig {
|
||||
// 获取所有 id
|
||||
let resultId = [];
|
||||
for (let one of allId) {
|
||||
const firstDigit = one.toString()[0];
|
||||
const firstDigit = one.toString()[0]; // 取首位字符
|
||||
if (firstDigit === "3") {
|
||||
resultId.push(one);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 商品数据
|
||||
* 商城数据
|
||||
*/
|
||||
import { BaseData } from "./BaseData";
|
||||
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
||||
|
||||
export class ShopData extends BaseData {
|
||||
// 商品数据
|
||||
private _goods = new Map<number, proto.cs.IGood>();
|
||||
private _goods = new Map<number, proto.cs.IPurchaseConfig>();
|
||||
// 商品 id
|
||||
private _goodIds: number[] = [];
|
||||
|
||||
@@ -27,17 +27,16 @@ export class ShopData extends BaseData {
|
||||
}
|
||||
|
||||
/** 设置商品数据 */
|
||||
public set goods(res: proto.cs.ICSGetShopRes) {
|
||||
const list = res.Goods ?? [];
|
||||
public set goods(res: proto.cs.ICSGetPurchaseRes) {
|
||||
const list = res.items ?? [];
|
||||
this._goods.clear();
|
||||
this._goodIds = [];
|
||||
for (const g of list) {
|
||||
const vo: proto.cs.IGood = {
|
||||
const vo: proto.cs.IPurchaseConfig = {
|
||||
id: g.id, // 商品 id
|
||||
name: g.name || "", // 商品名字
|
||||
desc: g.desc || "", // 商品描述
|
||||
price: g.price || "0.00", // 商品价格
|
||||
count: g.count || 0, // 商品数量
|
||||
name: g.name, // 商品名字
|
||||
count: g.count, // 商品数量
|
||||
price: g.price, // 商品价格
|
||||
};
|
||||
this._goods.set(vo.id, vo);
|
||||
this._goodIds.push(vo.id);
|
||||
@@ -46,7 +45,7 @@ export class ShopData extends BaseData {
|
||||
}
|
||||
|
||||
/** 获取所有商品数据 */
|
||||
public get goods(): Map<number, proto.cs.IGood> { return this._goods; }
|
||||
public get goods(): Map<number, proto.cs.IPurchaseConfig> { return this._goods; }
|
||||
|
||||
/** 获取所有商品数据的数量 */
|
||||
public get goodsCount(): number { return this._goods ? this._goods.size : 0; }
|
||||
@@ -54,18 +53,53 @@ export class ShopData extends BaseData {
|
||||
/** 获取所有商品 id */
|
||||
public get goodIds(): number[] { return this._goodIds; }
|
||||
|
||||
/** 获取vip商品数据 */
|
||||
public get vipGoods(): proto.cs.IGood[] {
|
||||
return this._goodIds.map(id => this._goods.get(id)!).filter(g => g.id > 2000);
|
||||
/** 获取 充值商品的id数组,首位数字为 1 */
|
||||
private getRechargeIds(): number[] {
|
||||
let allId = this._goodIds;
|
||||
if (!allId) return [];
|
||||
// 获取所有 id
|
||||
let resultId = [];
|
||||
for (let one of allId) {
|
||||
const firstDigit = one.toString()[0]; // 取首位字符
|
||||
if (firstDigit === "1") {
|
||||
resultId.push(one);
|
||||
}
|
||||
}
|
||||
return resultId;
|
||||
}
|
||||
|
||||
/** 获取普通商品数据 */
|
||||
public get normalGoods(): proto.cs.IGood[] {
|
||||
return this._goodIds.map(id => this._goods.get(id)!).filter(g => g.id <= 2000);
|
||||
/** 获取 会员商品的id数组,首位数字为 2 */
|
||||
private getMemberIds(): number[] {
|
||||
let allId = this._goodIds;
|
||||
if (!allId) return [];
|
||||
// 获取所有 id
|
||||
let resultId = [];
|
||||
for (let one of allId) {
|
||||
const firstDigit = one.toString()[0]; // 取首位字符
|
||||
if (firstDigit === "2") {
|
||||
resultId.push(one);
|
||||
}
|
||||
}
|
||||
return resultId;
|
||||
}
|
||||
|
||||
/** 获取 聊天商品的id数组,首位数字为 3 */
|
||||
private getChatIds(): number[] {
|
||||
let allId = this._goodIds;
|
||||
if (!allId) return [];
|
||||
// 获取所有 id
|
||||
let resultId = [];
|
||||
for (let one of allId) {
|
||||
const firstDigit = one.toString()[0]; // 取首位字符
|
||||
if (firstDigit === "3") {
|
||||
resultId.push(one);
|
||||
}
|
||||
}
|
||||
return resultId;
|
||||
}
|
||||
|
||||
/** 根据商品 id 获取商品数据 */
|
||||
private getGoodDataById(id: number): proto.cs.IGood | null {
|
||||
private getGoodDataById(id: number): proto.cs.IPurchaseConfig | null {
|
||||
if (!this._goods) return null;
|
||||
return this._goods.get(id) ?? null;
|
||||
}
|
||||
@@ -77,15 +111,8 @@ export class ShopData extends BaseData {
|
||||
return oneData.name;
|
||||
}
|
||||
|
||||
/** 根据商品 id 获取商品描述 */
|
||||
public getDescById(id: number): string | null {
|
||||
let oneData = this.getGoodDataById(id);
|
||||
if (!oneData) return null;
|
||||
return oneData.desc;
|
||||
}
|
||||
|
||||
/** 根据商品 id 获取商品价格 */
|
||||
public getPriceById(id: number): string | null {
|
||||
public getPriceById(id: number): number | null {
|
||||
let oneData = this.getGoodDataById(id);
|
||||
if (!oneData) return null;
|
||||
return oneData.price;
|
||||
|
||||
@@ -26,8 +26,18 @@ export class ChatService implements IChatService {
|
||||
this.impl = useMock ? new MockChatService() : new HttpChatService();
|
||||
}
|
||||
|
||||
// 对外 API 保持不变
|
||||
public async reqBuyChat(req: proto.cs.ICSBuyChatReq): Promise<ApiResponse<proto.cs.ICSBuyChatRes>> {
|
||||
return this.impl.reqBuyChat(req);
|
||||
// 上报聊天数据
|
||||
public async reqChatMsg(req: proto.cs.ICSChatMsgReq): Promise<ApiResponse<proto.cs.ICSChatMsgRes>> {
|
||||
return this.impl.reqChatMsg(req);
|
||||
}
|
||||
|
||||
// 获取聊天数据
|
||||
public async reqGetChatMsg(req: proto.cs.ICSGetChatMsgReq): Promise<ApiResponse<proto.cs.ICSGetChatMsgRes>> {
|
||||
return this.impl.reqGetChatMsg(req);
|
||||
}
|
||||
|
||||
// 获取技师聊天次数
|
||||
public async reqChatCountData(req: proto.cs.ICSGetChatRemainCountReq): Promise<ApiResponse<proto.cs.ICSGetChatRemainCountRes>> {
|
||||
return this.impl.reqChatCountData(req);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,4 +38,14 @@ export class GirlService implements IGirlService {
|
||||
public async reqGetGirlDetail(req: proto.cs.ICSGetGirlDetailReq): Promise<ApiResponse<proto.cs.ICSGetGirlDetailRes>> {
|
||||
return this.impl.reqGetGirlDetail(req);
|
||||
}
|
||||
|
||||
// 解锁技师
|
||||
public async reqUnlockGirl(req: proto.cs.ICSUnlockGirlReq): Promise<ApiResponse<proto.cs.ICSUnlockGirlRes>> {
|
||||
return this.impl.reqUnlockGirl(req);
|
||||
}
|
||||
|
||||
// 解锁资源
|
||||
public async reqUnlockGirlRes(req: proto.cs.ICSUnlockResourceReq): Promise<ApiResponse<proto.cs.ICSUnlockResourceRes>> {
|
||||
return this.impl.reqUnlockGirlRes(req);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,36 @@ import type { IChatService } from "./IChatService";
|
||||
export class HttpChatService implements IChatService {
|
||||
constructor(private api = ApiClient.I) {}
|
||||
|
||||
// 购买聊天次数
|
||||
async reqBuyChat(req: proto.cs.ICSBuyChatReq): Promise<ApiResponse<proto.cs.ICSBuyChatRes>> {
|
||||
const ep: Endpoint<proto.cs.ICSBuyChatReq, proto.cs.ICSBuyChatRes> = {
|
||||
path: "api/logic/buyChat",
|
||||
// 上报聊天数据
|
||||
async reqChatMsg(req: proto.cs.ICSChatMsgReq): Promise<ApiResponse<proto.cs.ICSChatMsgRes>> {
|
||||
const ep: Endpoint<proto.cs.ICSChatMsgReq, proto.cs.ICSChatMsgRes> = {
|
||||
path: "api/logic/chatMsg",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true,
|
||||
};
|
||||
return this.api.call(ep, req);
|
||||
}
|
||||
|
||||
// 获取聊天数据
|
||||
async reqGetChatMsg(req: proto.cs.ICSGetChatMsgReq): Promise<ApiResponse<proto.cs.ICSGetChatMsgRes>> {
|
||||
const ep: Endpoint<proto.cs.ICSGetChatMsgReq, proto.cs.ICSGetChatMsgRes> = {
|
||||
path: "api/logic/getChatMsg",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true,
|
||||
};
|
||||
return this.api.call(ep, req);
|
||||
}
|
||||
|
||||
// 获取技师聊天次数
|
||||
async reqChatCountData(req: proto.cs.ICSGetChatRemainCountReq): Promise<ApiResponse<proto.cs.ICSGetChatRemainCountRes>> {
|
||||
const ep: Endpoint<proto.cs.ICSGetChatRemainCountReq, proto.cs.ICSGetChatRemainCountRes> = {
|
||||
path: "api/logic/getChatRemainCount",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true,
|
||||
};
|
||||
return this.api.call(ep, req);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,4 +39,26 @@ export class HttpGirlService implements IGirlService {
|
||||
};
|
||||
return this.api.call(epData, req);
|
||||
}
|
||||
|
||||
// 解锁技师
|
||||
async reqUnlockGirl(req: proto.cs.ICSUnlockGirlReq): Promise<ApiResponse<proto.cs.ICSUnlockGirlRes>> {
|
||||
let epData: Endpoint<proto.cs.ICSUnlockGirlReq, proto.cs.ICSUnlockGirlRes> = {
|
||||
path: "api/logic/unlockGirl",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true
|
||||
};
|
||||
return this.api.call(epData, req);
|
||||
}
|
||||
|
||||
// 解锁资源
|
||||
async reqUnlockGirlRes(req: proto.cs.ICSUnlockResourceReq): Promise<ApiResponse<proto.cs.ICSUnlockResourceRes>> {
|
||||
let epData: Endpoint<proto.cs.ICSUnlockResourceReq, proto.cs.ICSUnlockResourceRes> = {
|
||||
path: "api/logic/unlockResource",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true
|
||||
};
|
||||
return this.api.call(epData, req);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,24 @@ export class HttpShopService implements IShopService {
|
||||
constructor(private api = ApiClient.I) {}
|
||||
|
||||
// 获取商品列表
|
||||
async reqShopList(req: proto.cs.ICSGetShopReq): Promise<ApiResponse<proto.cs.ICSGetShopRes>> {
|
||||
const ep: Endpoint<proto.cs.ICSGetShopReq, proto.cs.ICSGetShopRes> = {
|
||||
path: "api/logic/shop",
|
||||
async reqShopList(req: proto.cs.ICSGetPurchaseReq): Promise<ApiResponse<proto.cs.ICSGetPurchaseRes>> {
|
||||
const ep: Endpoint<proto.cs.ICSGetPurchaseReq, proto.cs.ICSGetPurchaseRes> = {
|
||||
path: "api/logic/getPurchase",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true,
|
||||
};
|
||||
return this.api.call(ep, req);
|
||||
}
|
||||
|
||||
// 使用余额购买商品
|
||||
async reqBuyGood(req: proto.cs.ICSBuyGoodReq): Promise<ApiResponse<proto.cs.ICSBuyGoodRes>> {
|
||||
const ep: Endpoint<proto.cs.ICSBuyGoodReq, proto.cs.ICSBuyGoodRes> = {
|
||||
path: "api/logic/buyGood",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true,
|
||||
};
|
||||
return this.api.call(ep, req);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@ import type { ApiResponse } from "../client/types";
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
|
||||
export interface IChatService {
|
||||
// 购买聊天次数
|
||||
reqBuyChat(req: proto.cs.ICSBuyChatReq): Promise<ApiResponse<proto.cs.ICSBuyChatRes>>;
|
||||
// 上报聊天数据
|
||||
reqChatMsg(req: proto.cs.ICSChatMsgReq): Promise<ApiResponse<proto.cs.ICSChatMsgRes>>;
|
||||
// 获取聊天数据
|
||||
reqGetChatMsg(req: proto.cs.ICSGetChatMsgReq): Promise<ApiResponse<proto.cs.ICSGetChatMsgRes>>;
|
||||
// 获取技师聊天次数
|
||||
reqChatCountData(req: proto.cs.ICSGetChatRemainCountReq): Promise<ApiResponse<proto.cs.ICSGetChatRemainCountRes>>;
|
||||
}
|
||||
|
||||
@@ -8,4 +8,8 @@ export interface IGirlService {
|
||||
reqGetGirlList(req: proto.cs.ICSGetGirlListReq): Promise<ApiResponse<proto.cs.ICSGetGirlListRes>>;
|
||||
// 获取技师详细信息
|
||||
reqGetGirlDetail(req: proto.cs.ICSGetGirlDetailReq): Promise<ApiResponse<proto.cs.ICSGetGirlDetailRes>>;
|
||||
// 解锁技师
|
||||
reqUnlockGirl(req: proto.cs.ICSUnlockGirlReq): Promise<ApiResponse<proto.cs.ICSUnlockGirlRes>>;
|
||||
// 解锁资源
|
||||
reqUnlockGirlRes(req: proto.cs.ICSUnlockResourceReq): Promise<ApiResponse<proto.cs.ICSUnlockResourceRes>>;
|
||||
}
|
||||
|
||||
@@ -3,5 +3,7 @@ import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
|
||||
export interface IShopService {
|
||||
// 获取商品列表
|
||||
reqShopList(req: proto.cs.ICSGetShopReq): Promise<ApiResponse<proto.cs.ICSGetShopRes>>;
|
||||
reqShopList(req: proto.cs.ICSGetPurchaseReq): Promise<ApiResponse<proto.cs.ICSGetPurchaseRes>>;
|
||||
// 使用余额购买商品
|
||||
reqBuyGood(req: proto.cs.ICSBuyGoodReq): Promise<ApiResponse<proto.cs.ICSBuyGoodRes>>;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,91 @@
|
||||
import type { ApiResponse } from "../client/types";
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
import type { IChatService } from "./IChatService";
|
||||
import { DataManager, DataId } from "../../data/DataManager";
|
||||
import { GirlData } from "../../data/GirlData";
|
||||
|
||||
export class MockChatService implements IChatService {
|
||||
private delay(ms = 160) { return new Promise<void>(r => setTimeout(r, ms)); }
|
||||
|
||||
// 按你们项目的 ApiResponse 结构调整这里即可
|
||||
private ok<T>(data: T): ApiResponse<T> {
|
||||
return ({ ok: true, data } as unknown) as ApiResponse<T>;
|
||||
return ({ code: proto.cs.EnmRetCode.SUCCESS, data } as unknown) as ApiResponse<T>;
|
||||
}
|
||||
// private err<T = unknown>(message = "mock buyChat error"): ApiResponse<T> {
|
||||
// return ({ ok: false, error: { message } } as unknown) as ApiResponse<T>;
|
||||
// }
|
||||
|
||||
async reqBuyChat(_req: proto.cs.ICSBuyChatReq): Promise<ApiResponse<proto.cs.ICSBuyChatRes>> {
|
||||
// 上报聊天数据
|
||||
async reqChatMsg(req: proto.cs.ICSChatMsgReq): Promise<ApiResponse<proto.cs.ICSChatMsgRes>> {
|
||||
// 延时
|
||||
await this.delay();
|
||||
// CSBuyChatRes 在 proto 中为空消息,这里返回 {}
|
||||
const res: proto.cs.ICSBuyChatRes = {};
|
||||
// 请求数据
|
||||
const reqGirlId = req.girlId;
|
||||
// 数据层的数据
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
const reqGirlCategory = girlData.getGrilCategoryById(reqGirlId);
|
||||
const chatTotalCount = girlData.getChatTotalCount(reqGirlCategory.toString(), reqGirlId);
|
||||
const chatRemainCount = girlData.getChatRemainCount(reqGirlCategory.toString(), reqGirlId);
|
||||
// 计算
|
||||
let resultTotalCount = chatTotalCount + 1;
|
||||
let resultRemainCount = chatRemainCount;
|
||||
if (chatRemainCount > 0) {
|
||||
resultRemainCount = chatRemainCount - 1;
|
||||
}
|
||||
// 返回数据
|
||||
const res: proto.cs.ICSChatMsgRes = {
|
||||
chatRemainCount: resultRemainCount,
|
||||
chatTotalCount: resultTotalCount,
|
||||
};
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
// 获取聊天数据
|
||||
async reqGetChatMsg(req: proto.cs.ICSGetChatMsgReq): Promise<ApiResponse<proto.cs.ICSGetChatMsgRes>> {
|
||||
// 延时
|
||||
await this.delay();
|
||||
// 请求数据
|
||||
const reqGirlId = req.GirlId;
|
||||
const page = req.page;
|
||||
const limit = req.limit;
|
||||
// 数据层的数据
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
const reqGirlCategory = girlData.getGrilCategoryById(reqGirlId);
|
||||
const chatTotalCount = girlData.getChatTotalCount(reqGirlCategory.toString(), reqGirlId);
|
||||
const chatRemainCount = girlData.getChatRemainCount(reqGirlCategory.toString(), reqGirlId);
|
||||
// 模拟一个完整的聊天记录池
|
||||
const allMsgs: proto.cs.IChatMsg[] = [];
|
||||
for (let i = 0; i < 50; i++) {
|
||||
allMsgs.push({
|
||||
msg: `模拟消息 ${i + 1} 来自技师 ${reqGirlId}`,
|
||||
isAi: i % 2 === 0, // 偶数条当成 AI 说的
|
||||
});
|
||||
}
|
||||
// 分页计算
|
||||
const start = (page - 1) * limit;
|
||||
const end = start + limit;
|
||||
const pageMsgs = allMsgs.slice(start, end);
|
||||
// 返回数据
|
||||
const res: proto.cs.ICSGetChatMsgRes = {
|
||||
msgs: pageMsgs,
|
||||
chatRemainCount,
|
||||
chatTotalCount,
|
||||
};
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
// 获取技师聊天次数
|
||||
async reqChatCountData(req: proto.cs.ICSGetChatRemainCountReq): Promise<ApiResponse<proto.cs.ICSGetChatRemainCountRes>> {
|
||||
// 延时
|
||||
await this.delay();
|
||||
// 请求数据
|
||||
const reqGirlId = req.id;
|
||||
// 数据层的数据
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
const reqGirlCategory = girlData.getGrilCategoryById(reqGirlId);
|
||||
const chatTotalCount = girlData.getChatTotalCount(reqGirlCategory.toString(), reqGirlId);
|
||||
const chatRemainCount = girlData.getChatRemainCount(reqGirlCategory.toString(), reqGirlId);
|
||||
// 返回数据
|
||||
const res: proto.cs.ICSGetChatRemainCountRes = {
|
||||
chatRemainCount,
|
||||
chatTotalCount,
|
||||
};
|
||||
return this.ok(res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,12 +226,30 @@ export class MockGirlService implements IGirlService {
|
||||
}
|
||||
|
||||
const star = 3;
|
||||
const chatTotalCount = 10;
|
||||
const chatRemainCount = 10;
|
||||
const chatTotalCount = 20;
|
||||
const chatRemainCount = 20;
|
||||
|
||||
const girlData = this.genGirlData(girlId, briefData, isRelease, star, detail, unlockImageData, unlockVideoData, chatTotalCount, chatRemainCount);
|
||||
// 返回数据
|
||||
const res: proto.cs.ICSGetGirlDetailRes = {girl: girlData};
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
// 解锁技师
|
||||
async reqUnlockGirl(_req: proto.cs.ICSUnlockGirlReq): Promise<ApiResponse<proto.cs.ICSUnlockGirlRes>> {
|
||||
// 延时
|
||||
await this.delay(180);
|
||||
// 返回数据
|
||||
const res: proto.cs.ICSUnlockGirlRes = {};
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
// 解锁资源
|
||||
async reqUnlockGirlRes(_req: proto.cs.ICSUnlockResourceReq): Promise<ApiResponse<proto.cs.ICSUnlockResourceRes>> {
|
||||
// 延时
|
||||
await this.delay(180);
|
||||
// 返回数据
|
||||
const res: proto.cs.ICSUnlockResourceRes = {};
|
||||
return this.ok(res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { ApiResponse } from "../client/types";
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
import type { IShopService } from "./IShopService";
|
||||
import { PurchaseConfig } from "../../config/PurchaseConfig";
|
||||
import { ConfigManager, ConfigId } from "../../manager/ConfigManager";
|
||||
|
||||
export class MockShopService implements IShopService {
|
||||
private delay(ms = 180) { return new Promise<void>(r => setTimeout(r, ms)); }
|
||||
@@ -11,29 +13,44 @@ export class MockShopService implements IShopService {
|
||||
}
|
||||
|
||||
private ok<T>(data: T): ApiResponse<T> {
|
||||
return ({ ok: true, data } as unknown) as ApiResponse<T>;
|
||||
return ({ code: proto.cs.EnmRetCode.SUCCESS, data } as unknown) as ApiResponse<T>;
|
||||
}
|
||||
|
||||
private genGood(id: number, vip = false): proto.cs.IGood {
|
||||
private genGood(id: number, name: string, count: number, price: number): proto.cs.IPurchaseConfig {
|
||||
return {
|
||||
id,
|
||||
name: vip ? `VIP-${id}` : `Diamond Pack ${id}`,
|
||||
desc: vip ? `VIP access for ${this.randInt(24, 168)} hours` : `Diamonds x${this.randInt(60, 2000)}`,
|
||||
price: this.priceUSD(vip ? 4.99 : 0.99, vip ? 49.99 : 29.99),
|
||||
count: vip ? this.randInt(24, 168) : this.randInt(60, 2000), // VIP=小时,普通=数量
|
||||
name,
|
||||
count,
|
||||
price,
|
||||
};
|
||||
}
|
||||
|
||||
// 获取商品列表
|
||||
async reqShopList(_req: proto.cs.ICSGetShopReq): Promise<ApiResponse<proto.cs.ICSGetShopRes>> {
|
||||
async reqShopList(_req: proto.cs.ICSGetPurchaseReq): Promise<ApiResponse<proto.cs.ICSGetPurchaseRes>> {
|
||||
// 延时
|
||||
await this.delay();
|
||||
|
||||
// 普通商品(<=2000)+ VIP 商品(>2000)
|
||||
const normals: proto.cs.IGood[] = Array.from({ length: 5 }, (_, i) => this.genGood(1000 + i, false));
|
||||
const vips: proto.cs.IGood[] = Array.from({ length: 3 }, (_, i) => this.genGood(2001 + i, true));
|
||||
|
||||
// 注意:你的 proto 定义中字段名为 "Goods"(大写 G)
|
||||
const res: proto.cs.ICSGetShopRes = { Goods: [...normals, ...vips] };
|
||||
// 配置数据
|
||||
const configData = ConfigManager.I.getDataById<PurchaseConfig>(ConfigId.Purchase);
|
||||
const allId = configData.getAllId();
|
||||
let goodData: proto.cs.IPurchaseConfig[] = [];
|
||||
for (let id of allId) {
|
||||
let name = configData.getNameById(id);
|
||||
let count = configData.getCountById(id);
|
||||
let price = configData.getPriceById(id);
|
||||
let oneData = this.genGood(id, name, count, price);
|
||||
goodData.push(oneData);
|
||||
}
|
||||
// 返回数据
|
||||
const res: proto.cs.ICSGetPurchaseRes = { items: goodData };
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
// 使用余额购买商品
|
||||
async reqBuyGood(_req: proto.cs.ICSBuyGoodReq): Promise<ApiResponse<proto.cs.ICSBuyGoodRes>> {
|
||||
// 延时
|
||||
await this.delay();
|
||||
// 返回数据
|
||||
const res: proto.cs.ICSBuyGoodRes = {};
|
||||
return this.ok(res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,12 @@ export class ShopService implements IShopService {
|
||||
}
|
||||
|
||||
// 获取商品列表
|
||||
public async reqShopList(req: proto.cs.ICSGetShopReq): Promise<ApiResponse<proto.cs.ICSGetShopRes>> {
|
||||
public async reqShopList(req: proto.cs.ICSGetPurchaseReq): Promise<ApiResponse<proto.cs.ICSGetPurchaseRes>> {
|
||||
return this.impl.reqShopList(req);
|
||||
}
|
||||
|
||||
// 使用余额购买商品
|
||||
public async reqBuyGood(req: proto.cs.ICSBuyGoodReq): Promise<ApiResponse<proto.cs.ICSBuyGoodRes>> {
|
||||
return this.impl.reqBuyGood(req);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user