协议修改

This commit is contained in:
chen wei bo
2025-09-08 19:44:58 +08:00
parent e7cb527ca0
commit d4d3e986b3
17 changed files with 878 additions and 66 deletions
+52 -25
View File
@@ -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;