116 lines
3.0 KiB
TypeScript
116 lines
3.0 KiB
TypeScript
/**
|
|
* 商城配置
|
|
*/
|
|
import { BaseConfig } from "./BaseConfig";
|
|
import { ConfigManager } from "../manager/ConfigManager";
|
|
|
|
export class PurchaseConfig extends BaseConfig {
|
|
|
|
public reset(): void {
|
|
|
|
}
|
|
|
|
public clear(): void {
|
|
|
|
}
|
|
|
|
public destroy(): void {
|
|
super.destroy();
|
|
}
|
|
|
|
/**
|
|
* 获取所有配置
|
|
*/
|
|
protected getAllConfig(): any | null {
|
|
return ConfigManager.tables.TbPurchaseConfig;
|
|
}
|
|
|
|
/**
|
|
* 获取所有配置 id,如果存在
|
|
*/
|
|
public getAllId(): any | null {
|
|
let allData = this.getAllConfig();
|
|
if (!allData) return null;
|
|
const dataArr = allData.getDataList();
|
|
let allId = [];
|
|
for (let oneData of dataArr) {
|
|
allId.push(oneData.id);
|
|
}
|
|
return allId;
|
|
}
|
|
|
|
/** 获取 充值商品的id数组,首位数字为 1 */
|
|
public getRechargeIds(): number[] {
|
|
let allId = this.getAllId();
|
|
if (!allId) return [];
|
|
// 获取所有 id
|
|
let resultId = [];
|
|
for (let one of allId) {
|
|
const firstDigit = one.toString()[0]; // 取首位字符
|
|
if (firstDigit === "1") {
|
|
resultId.push(one);
|
|
}
|
|
}
|
|
return resultId;
|
|
}
|
|
|
|
/** 获取 会员商品的id数组,首位数字为 2 */
|
|
public getMemberIds(): number[] {
|
|
let allId = this.getAllId();
|
|
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 */
|
|
public getChatIds(): number[] {
|
|
let allId = this.getAllId();
|
|
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
|
|
*/
|
|
protected getConfigById(id: number): any | null {
|
|
let allData = this.getAllConfig();
|
|
if (!allData) return null;
|
|
return allData.get(id);
|
|
}
|
|
|
|
/** 根据商品 id 获取商品名字 */
|
|
public getNameById(id: number): string | null {
|
|
let oneData = this.getConfigById(id);
|
|
if (!oneData) return null;
|
|
return oneData.name;
|
|
}
|
|
|
|
/** 根据商品 id 获取商品数量 */
|
|
public getCountById(id: number): number | null {
|
|
let oneData = this.getConfigById(id);
|
|
if (!oneData) return null;
|
|
return oneData.count;
|
|
}
|
|
|
|
/** 根据商品 id 获取商品价格 */
|
|
public getPriceById(id: number): number | null {
|
|
let oneData = this.getConfigById(id);
|
|
if (!oneData) return null;
|
|
return oneData.price;
|
|
}
|
|
} |