Merge branch 'main' of 47.107.44.202:xionglijia/18xchat
This commit is contained in:
@@ -93,6 +93,22 @@ export class ShopData extends BaseData {
|
||||
return resultId;
|
||||
}
|
||||
|
||||
/** 获取7天会员的 id */
|
||||
public get7DayMemberId(): number {
|
||||
const ids = this.getMemberIds();
|
||||
const length = ids.length;
|
||||
if (length <= 0) return 0;
|
||||
return ids[0];
|
||||
}
|
||||
|
||||
/** 获取30天会员的 id */
|
||||
public get30DayMemberId(): number {
|
||||
const ids = this.getMemberIds();
|
||||
const length = ids.length;
|
||||
if (length <= 1) return 0;
|
||||
return ids[1];
|
||||
}
|
||||
|
||||
/** 是否是聊天商品,首位数字为 3 */
|
||||
public isChatId(id: number): boolean {
|
||||
const firstDigit = id.toString()[0]; // 取首位字符
|
||||
|
||||
@@ -5,7 +5,7 @@ import { HttpShopService } from "./HttpShopService";
|
||||
import { MockShopService } from "./MockShopService";
|
||||
|
||||
// 模拟开关
|
||||
const USE_MOCK = true;
|
||||
const USE_MOCK = false;
|
||||
|
||||
export class ShopService implements IShopService {
|
||||
private static _I: ShopService | null = null;
|
||||
|
||||
@@ -11,8 +11,10 @@ import { InnerEventCode, InnerMsgCode } from "../../../Main/Config/InnerMsgCode"
|
||||
import { DataManager, DataId } from "../../data/DataManager";
|
||||
import { WalletData } from "../../data/WalletData";
|
||||
import { ShopData } from "../../data/ShopData";
|
||||
import { GirlData } from "../../data/GirlData";
|
||||
import { ShopService } from "db://assets/Scripts/chat18x/network/services/ShopService";
|
||||
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
||||
import GameRootUI from "../../../Main/Common/GameRootUI";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -25,7 +27,6 @@ export class PurchasePanel extends li_BaseView {
|
||||
private vipTime7: Label;
|
||||
private vipPrice30: Label;
|
||||
private vipTime30: Label;
|
||||
private tryBuyId: number;
|
||||
|
||||
@property([PurchasePanelItem])
|
||||
public items: PurchasePanelItem[] = [];
|
||||
@@ -53,26 +54,32 @@ export class PurchasePanel extends li_BaseView {
|
||||
|
||||
bandBtn() {
|
||||
GButton.BandClick(
|
||||
this._nodeTab.BuyVipBtn,
|
||||
this._nodeTab.Buy7DayVipBt,
|
||||
() => {
|
||||
//TODO:购买vip
|
||||
console.log("购买Vip");
|
||||
console.log("购买Vip 7");
|
||||
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
|
||||
const memberId = shopData.get7DayMemberId();
|
||||
this.reqBuyGood(memberId);
|
||||
},
|
||||
this
|
||||
);
|
||||
GButton.BandClick(
|
||||
this._nodeTab.BuyDiamondBtn,
|
||||
this._nodeTab.Buy30DayVipBtn,
|
||||
() => {
|
||||
//TODO:购买钻石
|
||||
console.log("购买钻石,商品id:" + this.tryBuyId);
|
||||
//TODO:购买vip
|
||||
console.log("购买Vip 30");
|
||||
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
|
||||
const memberId = shopData.get30DayMemberId();
|
||||
this.reqBuyGood(memberId);
|
||||
},
|
||||
this
|
||||
);
|
||||
);
|
||||
GButton.BandClick(
|
||||
this._nodeTab.QUIT,
|
||||
this._nodeTab.ReturnBtn,
|
||||
() => {
|
||||
//TODO:购买钻石
|
||||
ViewManager.I.closeView(this.node);
|
||||
this.onClose();
|
||||
GameRootUI.I.showDefaultView();
|
||||
},
|
||||
this
|
||||
);
|
||||
@@ -98,16 +105,12 @@ export class PurchasePanel extends li_BaseView {
|
||||
|
||||
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
|
||||
// VIP会员
|
||||
const memberIds = shopData.getMemberIds();
|
||||
for (let i = 0; i < memberIds.length; i++) {
|
||||
const id = memberIds[i];
|
||||
const price = shopData.getOriginalPriceById(id);
|
||||
if (i === 0) {
|
||||
this.vipPrice7.string = `$ ${price}`;
|
||||
} else if (i === 1) {
|
||||
this.vipPrice30.string = `$ ${price}`;
|
||||
}
|
||||
}
|
||||
const memberId7 = shopData.get7DayMemberId();
|
||||
const price7 = shopData.getOriginalPriceById(memberId7);
|
||||
this.vipPrice7.string = `$ ${price7}`;
|
||||
const memberId30 = shopData.get30DayMemberId();
|
||||
const price30 = shopData.getOriginalPriceById(memberId30);
|
||||
this.vipPrice30.string = `$ ${price30}`;
|
||||
// 充值商品
|
||||
const rechargeIds = shopData.getRechargeIds();
|
||||
for (let index = 0; index < this.items.length; index++) {
|
||||
@@ -118,7 +121,7 @@ export class PurchasePanel extends li_BaseView {
|
||||
}
|
||||
|
||||
setDiamondTag(id: number) {
|
||||
this.tryBuyId = id;
|
||||
this.reqBuyGood(id);
|
||||
}
|
||||
|
||||
getPlayerMerData() {
|
||||
@@ -152,6 +155,27 @@ export class PurchasePanel extends li_BaseView {
|
||||
).replace("${leftTime}", leftTime);
|
||||
}
|
||||
|
||||
// 使用余额购买商品
|
||||
async reqBuyGood(goodId: number) {
|
||||
// 请求购买商品
|
||||
const reqData = {
|
||||
goodId: goodId,
|
||||
girlId: 0,
|
||||
};
|
||||
let res = await ShopService.I.reqBuyGood(reqData);
|
||||
console.log("请求使用余额购买商品的响应数据:", res);
|
||||
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
||||
const resData = res.data;
|
||||
// 保存数据
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
const walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
|
||||
walletData.balance = Number(resData.balance);
|
||||
walletData.vipExpire = Number(resData.vipExpire);
|
||||
// 刷新界面
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
Utils.removeInnerEL(InnerMsgCode.BalanceChange, this, () => {
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ export class ThemePanel extends li_BaseView {
|
||||
uid: Label;
|
||||
itemInst: GirlListItem;
|
||||
content: Node;
|
||||
|
||||
private vipLeftTime: Label;
|
||||
recId: number;
|
||||
recName: Label;
|
||||
recSprite: Sprite;
|
||||
@@ -50,6 +50,7 @@ export class ThemePanel extends li_BaseView {
|
||||
this.uid = this._nodeTab.uid.getComponent(Label);
|
||||
this.recName = this._nodeTab.characterNameText.getComponent(Label);
|
||||
this.recSprite = this._nodeTab.recPicSlot.getComponent(Sprite);
|
||||
this.vipLeftTime = this._nodeTab.vipText.getComponent(Label);
|
||||
|
||||
this.registerListener();
|
||||
this.itemInst = this._nodeTab.ThemeItem.getComponent(ThemeItem);
|
||||
@@ -63,6 +64,7 @@ export class ThemePanel extends li_BaseView {
|
||||
async Show() {
|
||||
//some temp data
|
||||
this.refreshCoinNum();
|
||||
this.refreshVipExpire();
|
||||
const accountData = DataManager.I.getDataById<AccountData>(DataId.Account);
|
||||
this.uid.string = "uid: " + accountData.accId;
|
||||
this.recId = 1;
|
||||
@@ -167,8 +169,10 @@ export class ThemePanel extends li_BaseView {
|
||||
private refreshVipExpire() {
|
||||
const walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
|
||||
const vipExpire = walletData.vipExpire;
|
||||
// TODO
|
||||
|
||||
const leftTime = Utils.formatVipLeftTime(vipExpire);
|
||||
this.vipLeftTime.string = LanguageUtils.getText(
|
||||
"purchasepanel.vip_left"
|
||||
).replace("${leftTime}", leftTime);
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
|
||||
@@ -3,6 +3,8 @@ import { PurchasePanel } from "../ui/panels/PurchasePanel";
|
||||
import { PurchaseConfig } from "../../schema/schema";
|
||||
import { DataManager, DataId } from "../data/DataManager";
|
||||
import { ShopData } from "../data/ShopData";
|
||||
import { GButton } from "db://assets/Scripts/Main/Common/GButton";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("PurchasePanelItem")
|
||||
@@ -17,6 +19,8 @@ export class PurchasePanelItem extends Component {
|
||||
public init(base: PurchasePanel, goodId: number) {
|
||||
this.baseView = base;
|
||||
this.goodId = goodId;
|
||||
|
||||
GButton.BandClick(this.node, this.onClickThis, this);
|
||||
}
|
||||
|
||||
public show() {
|
||||
@@ -27,8 +31,7 @@ export class PurchasePanelItem extends Component {
|
||||
this.price.string = price.toString();
|
||||
}
|
||||
|
||||
onClickThis() {
|
||||
async onClickThis() {
|
||||
this.baseView.setDiamondTag(this.goodId);
|
||||
console.log("点击了");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1746,7 +1746,7 @@
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "text",
|
||||
"_name": "vipText",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_parent": {
|
||||
|
||||
+1
-1
Submodule proto_cs updated: f055100cf0...9ec1d4f077
Reference in New Issue
Block a user