✨ feat(活动): 添加关注豪礼
This commit is contained in:
@@ -1,40 +1,154 @@
|
||||
import { BIND_PHONE_STATUS } from '../../consts';
|
||||
import { pick } from 'underscore';
|
||||
import { BIND_PHONE_STATUS, SNS_LINK_TYPE } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityBindPhoneRewardType } from '../../db/ActivityBindPhoneReward';
|
||||
import { LinkType } from '../../db/Link';
|
||||
import { UserType } from '../../db/User';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
// 数据库
|
||||
interface BindPhoneDataInDb {
|
||||
interface PageDataInDb {
|
||||
pageIndex: number;
|
||||
pageName: string;
|
||||
type: number;
|
||||
rewards: string;
|
||||
giftCode: string;
|
||||
}
|
||||
|
||||
interface BindPhoneDataInDb {
|
||||
pages: PageDataInDb[];
|
||||
}
|
||||
|
||||
class PageData {
|
||||
pageIndex: number;
|
||||
pageName: string;
|
||||
type: number;
|
||||
|
||||
constructor(pageData: PageDataInDb) {
|
||||
this.pageIndex = pageData.pageIndex;
|
||||
this.pageName = pageData.pageName;
|
||||
this.type = pageData.type;
|
||||
}
|
||||
}
|
||||
|
||||
class WXGroupPage extends PageData {
|
||||
link: string = ''; // 微信群外链
|
||||
qrCodeLink: string = ''; // 微信群二维码
|
||||
|
||||
public setLink(link: LinkType) {
|
||||
this.link = link.link;
|
||||
this.qrCodeLink = link.qrCodeLink;
|
||||
}
|
||||
}
|
||||
|
||||
class BindPhonePage extends PageData {
|
||||
rewards: string; // 绑定手机后能有的奖励
|
||||
status: number = BIND_PHONE_STATUS.WAIT_BIND; // 状态 0-未绑定 1-已绑定 3-已领取
|
||||
|
||||
constructor(pageData: PageDataInDb) {
|
||||
super(pageData);
|
||||
this.rewards = pageData.rewards;
|
||||
}
|
||||
}
|
||||
|
||||
class WXPublicAccountPage extends PageData {
|
||||
qrCodeLink: string; // 公众号二维码
|
||||
rewards: string; // 口令能有的奖励
|
||||
originGiftCode: string; // 加密后的口令
|
||||
giftCode: string; // 加密后的口令
|
||||
status: number = BIND_PHONE_STATUS.WAIT_BIND; // 状态 0-未使用 1-可领取 2-已领取
|
||||
|
||||
constructor(pageData: PageDataInDb) {
|
||||
super(pageData);
|
||||
this.originGiftCode = pageData.giftCode;
|
||||
this.rewards = pageData.rewards;
|
||||
}
|
||||
|
||||
public setLink(link: LinkType) {
|
||||
this.qrCodeLink = link.qrCodeLink;
|
||||
}
|
||||
|
||||
public setEncodeGiftCode(giftCode: string) {
|
||||
this.giftCode = giftCode;
|
||||
}
|
||||
|
||||
public getShowResult() {
|
||||
return pick(this, ['pageIndex', 'pageName', 'type', 'qrCodeLink', 'rewards', 'giftCode', 'status']);
|
||||
}
|
||||
}
|
||||
|
||||
class BBSPage extends PageData {
|
||||
link: string; // 论坛外链
|
||||
|
||||
public setLink(link: LinkType) {
|
||||
this.link = link.link;
|
||||
}
|
||||
}
|
||||
|
||||
// 数据
|
||||
export class BindPhoneData extends ActivityBase {
|
||||
rewards: string;
|
||||
|
||||
status: number = BIND_PHONE_STATUS.WAIT_BIND; // 状态 0-未绑定 1-已绑定可领取 2-已领取
|
||||
wxGroup: WXGroupPage;
|
||||
bindPhone: BindPhonePage;
|
||||
wxPublicAccount: WXPublicAccountPage;
|
||||
bbs: BBSPage;
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
||||
super(activityData, createTime, serverTime);
|
||||
this.initData(activityData.data)
|
||||
this.initData(activityData.data);
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let dataObj: BindPhoneDataInDb = JSON.parse(data);
|
||||
this.rewards = dataObj.rewards;
|
||||
for(let pageData of (dataObj?.pages||[])) {
|
||||
switch(pageData.type) {
|
||||
case SNS_LINK_TYPE.WX_GROUP: {
|
||||
this.wxGroup = new WXGroupPage(pageData); break;
|
||||
}
|
||||
case SNS_LINK_TYPE.BIND_PHONE: {
|
||||
this.bindPhone = new BindPhonePage(pageData); break;
|
||||
}
|
||||
case SNS_LINK_TYPE.WX_PUBLIC_ACCOUNT: {
|
||||
this.wxPublicAccount = new WXPublicAccountPage(pageData); break;
|
||||
}
|
||||
case SNS_LINK_TYPE.BBS: {
|
||||
this.bbs = new BBSPage(pageData); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public setRecord(user: UserType, data: ActivityBindPhoneRewardType) {
|
||||
if(user && user.channelInfo && user.channelInfo.is_phone_bind == 1) this.status = BIND_PHONE_STATUS.HAS_BIND;
|
||||
if(data) this.status = data.status;
|
||||
public setLinks(links: LinkType[]) {
|
||||
for(let link of links) {
|
||||
switch (link.type) {
|
||||
case SNS_LINK_TYPE.WX_GROUP: {
|
||||
this.wxGroup.setLink(link); break;
|
||||
}
|
||||
case SNS_LINK_TYPE.WX_PUBLIC_ACCOUNT: {
|
||||
this.wxPublicAccount.setLink(link); break;
|
||||
}
|
||||
case SNS_LINK_TYPE.BBS: {
|
||||
this.bbs.setLink(link); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public setBindPhoneStatus(user: UserType, data: ActivityBindPhoneRewardType) {
|
||||
if(this.bindPhone) {
|
||||
if(user && user.channelInfo && user.channelInfo.is_phone_bind == 1) this.bindPhone.status = BIND_PHONE_STATUS.HAS_BIND;
|
||||
if(data) this.bindPhone.status = data.status;
|
||||
}
|
||||
}
|
||||
|
||||
public getShowResult() {
|
||||
let pages: (WXGroupPage|BindPhonePage|WXPublicAccountPage|BBSPage)[] = [];
|
||||
if(this.wxGroup) pages.push(this.wxGroup);
|
||||
if(this.bindPhone) pages.push(this.bindPhone);
|
||||
if(this.wxPublicAccount) pages.push(this.wxPublicAccount.getShowResult());
|
||||
if(this.bbs) pages.push(this.bbs);
|
||||
return {
|
||||
...this.getBaseKeys(),
|
||||
rewards: this.rewards,
|
||||
status: this.status,
|
||||
pages
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user