Commit be22f0b1a233f2dd6ce94ad11b96f6e91e9bd8cb
1 parent
cd5f2a51
Exists in
master
and in
3 other branches
X
Showing
9 changed files
with
78 additions
and
31 deletions
Show diff stats
sdk/SDKTools.ts
sdk/shareTools.ts
wxsdk/WXSDK.ts
wxsdk/base/SDKConst.ts
wxsdk/service/DataService.ts
| ... | ... | @@ -518,6 +518,56 @@ export default class DataService { |
| 518 | 518 | // return LocalService.I.getDayAllVideoNum(); |
| 519 | 519 | // } |
| 520 | 520 | |
| 521 | + private timeInterval | |
| 522 | + public updateTodayOnlineTime() { | |
| 523 | + let dot = StorageUtils.I.get("pcsdk_today_online_time_300") || 0; | |
| 524 | + if (dot === 1) { | |
| 525 | + this.setPtm(1) | |
| 526 | + // 定时重启 | |
| 527 | + let expiration = +((this.nextDay() - Date.now()) / 1000).toFixed(0); | |
| 528 | + setTimeout(() => { | |
| 529 | + this.updateTodayOnlineTime(); | |
| 530 | + }, expiration * 1000); | |
| 531 | + return; | |
| 532 | + } else { | |
| 533 | + this.setPtm(0) | |
| 534 | + this.timeInterval = setInterval(this.stayFun.bind(this), 5000); | |
| 535 | + } | |
| 536 | + } | |
| 537 | + private stayFun() { | |
| 538 | + let expiration = +((this.nextDay() - Date.now()) / 1000).toFixed(0); | |
| 539 | + let time = StorageUtils.I.get("pcsdk_today_online_time") || 0; | |
| 540 | + time += 5; | |
| 541 | + StorageUtils.I.set("pcsdk_today_online_time", time, expiration) | |
| 542 | + let dot = StorageUtils.I.get("pcsdk_today_online_time_300") || 0; | |
| 543 | + if (dot === 1) { | |
| 544 | + this.setPtm(1) | |
| 545 | + clearInterval(this.timeInterval); | |
| 546 | + // 定时重启 | |
| 547 | + setTimeout(() => { | |
| 548 | + this.updateTodayOnlineTime(); | |
| 549 | + }, expiration * 1000); | |
| 550 | + return; | |
| 551 | + } | |
| 552 | + // console.log("newUserTime", newUserTime, newUserDot) | |
| 553 | + if (time >= 300 && dot == 0) { | |
| 554 | + StorageUtils.I.set("pcsdk_today_online_time_300", 1, expiration); | |
| 555 | + this.setPtm(1) | |
| 556 | + clearInterval(this.timeInterval); | |
| 557 | + // 定时重启 | |
| 558 | + setTimeout(() => { | |
| 559 | + this.updateTodayOnlineTime(); | |
| 560 | + }, expiration * 1000); | |
| 561 | + } | |
| 562 | + } | |
| 563 | + | |
| 564 | + public nextDay() { | |
| 565 | + var str = new Date(); | |
| 566 | + var str2 = str.getFullYear() + "/" | |
| 567 | + + (str.getMonth() + 1) + "/" + str.getDate(); | |
| 568 | + return new Date(str2).getTime() + 24 * 60 * 60 * 1000 | |
| 569 | + } | |
| 570 | + | |
| 521 | 571 | private static instance: DataService; |
| 522 | 572 | static get I(): DataService { |
| 523 | 573 | return this.instance || (this.instance = new DataService()); | ... | ... |
wxsdk/service/LogService.ts
| ... | ... | @@ -221,7 +221,7 @@ export default class LogService { |
| 221 | 221 | ...this.buildParams() |
| 222 | 222 | }) |
| 223 | 223 | this.checkLogin(fun); |
| 224 | - // 30秒 计时 和 300秒计时 打点 | |
| 224 | + // 30秒 计时 | |
| 225 | 225 | this.startStay() |
| 226 | 226 | } |
| 227 | 227 | |
| ... | ... | @@ -299,16 +299,11 @@ export default class LogService { |
| 299 | 299 | newUserTime++; |
| 300 | 300 | StorageUtils.I.set("newUserTime", newUserTime) |
| 301 | 301 | let newUserDot = StorageUtils.I.get("newUserDot") || 0; |
| 302 | - if (newUserDot === 2) clearInterval(this.stayInterval); | |
| 302 | + if (newUserDot === 1) clearInterval(this.stayInterval); | |
| 303 | 303 | // console.log("newUserTime", newUserTime, newUserDot) |
| 304 | 304 | if (newUserTime >= 30 && newUserDot == 0) { |
| 305 | 305 | StorageUtils.I.set("newUserDot", 1); |
| 306 | 306 | this.loadingFinishStay(30); |
| 307 | - } | |
| 308 | - if (newUserTime >= 300) { | |
| 309 | - StorageUtils.I.set("newUserDot", 2); | |
| 310 | - // this.loadingFinishStay(300);// 300秒计时 | |
| 311 | - this.attributePtm(); | |
| 312 | 307 | clearInterval(this.stayInterval); |
| 313 | 308 | } |
| 314 | 309 | } |
| ... | ... | @@ -327,17 +322,17 @@ export default class LogService { |
| 327 | 322 | * 修改用户属性 ptm 是否累计玩游戏300秒,1是 |
| 328 | 323 | * @returns |
| 329 | 324 | */ |
| 330 | - attributePtm() { | |
| 331 | - let pkv = SDKVersion; | |
| 332 | - let uid = DataService.I.UserId; | |
| 333 | - let token = DataService.I.Token; | |
| 334 | - return SDKApi.attribute({ | |
| 335 | - pkv, | |
| 336 | - uid, | |
| 337 | - token, | |
| 338 | - ptm: 1 | |
| 339 | - }) | |
| 340 | - } | |
| 325 | + // attributePtm() { | |
| 326 | + // let pkv = SDKVersion; | |
| 327 | + // let uid = DataService.I.UserId; | |
| 328 | + // let token = DataService.I.Token; | |
| 329 | + // return SDKApi.attribute({ | |
| 330 | + // pkv, | |
| 331 | + // uid, | |
| 332 | + // token, | |
| 333 | + // ptm: 1 | |
| 334 | + // }) | |
| 335 | + // } | |
| 341 | 336 | |
| 342 | 337 | |
| 343 | 338 | /** | ... | ... |
wxsdk/service/entity/SdkData.ts
| ... | ... | @@ -39,10 +39,10 @@ export default class SdkData { |
| 39 | 39 | public logindays: number; // 登录天数 |
| 40 | 40 | public amount: number; // 充值金额 |
| 41 | 41 | public pon: number; // 用户类型:1微信投放2抖音3自然量0未知 |
| 42 | - public ptm:number; | |
| 42 | + public ptm:number; // 当天是否300s | |
| 43 | 43 | public cule_token: string; // 用户通过广告调起微信小游戏的唯一编码 |
| 44 | - public creative_id: string; //创意ID | |
| 45 | - public advertister_id: string; //广告账户ID | |
| 44 | + public creative_id: string; // 创意ID | |
| 45 | + public advertister_id: string; // 广告账户ID | |
| 46 | 46 | public request_id: string; // 请求下发ID |
| 47 | 47 | |
| 48 | 48 | ... | ... |
wxsdk/utils/StorageUtils.ts
| ... | ... | @@ -26,6 +26,13 @@ export default class StorageUtils { |
| 26 | 26 | return +(new Date().getTime() / 1000).toFixed(0); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | + /** | |
| 30 | + * | |
| 31 | + * @param key | |
| 32 | + * @param value | |
| 33 | + * @param expiration 距离目标(下一天)多少秒 | |
| 34 | + * @returns | |
| 35 | + */ | |
| 29 | 36 | set(key: string, value: Object, expiration = 0) { |
| 30 | 37 | const entity = { |
| 31 | 38 | timestamp: this.timestamp, |
| ... | ... | @@ -58,6 +65,7 @@ export default class StorageUtils { |
| 58 | 65 | // 已过期 |
| 59 | 66 | if (this.__isExpired(entity)) { |
| 60 | 67 | this.remove(key); |
| 68 | + // console.log("过期了",key); | |
| 61 | 69 | return null; |
| 62 | 70 | } else { |
| 63 | 71 | return entity.value; | ... | ... |
wxsdk/wx/WxLogin.ts
| ... | ... | @@ -94,7 +94,7 @@ export default class WxLogin { |
| 94 | 94 | if (data) { |
| 95 | 95 | // 设置登录信息 |
| 96 | 96 | if (data.data) { |
| 97 | - let { channel, uid, firstlogin, token, reftoken, openid, expire, isnew, gameconfig,logindays,amount,pon,ptm } = data.data; | |
| 97 | + let { channel, uid, firstlogin, token, reftoken, openid, expire, isnew, gameconfig,logindays,amount,pon} = data.data; | |
| 98 | 98 | LogService.I.setLogind({ |
| 99 | 99 | channel, |
| 100 | 100 | userId: uid, |
| ... | ... | @@ -106,8 +106,7 @@ export default class WxLogin { |
| 106 | 106 | expire, |
| 107 | 107 | logindays, |
| 108 | 108 | amount, |
| 109 | - pon, | |
| 110 | - ptm | |
| 109 | + pon | |
| 111 | 110 | }); |
| 112 | 111 | OnlineService.I.setData(gameconfig) |
| 113 | 112 | LogService.I.active(); | ... | ... |