当前位置:网站首页>Sign in function of Taobao applet

Sign in function of Taobao applet

2022-06-10 02:12:00 weixin_ forty-four million three hundred and eighty-seven thous

    my.getStorage({
      key: gdc.userId + gameName,
      success: function (res) {
        // console.log(!res.data)
        // Determine whether it is the first time to load the game 
        if (!res.data) {
          my.setStorage({
            key: gdc.userId + gameName,
            data: {
              timer: timer,
              list: self.data.list,
              current: 0,
              golds: 0,
              flag: false
            },
            success: function () {
            }
          });
        } else if (res.data != '') {
        // Check in on the eighth day after seven consecutive days , Judge whether to sign in the next day 
          if (res.data.timer - newDateTime < -86400000 || res.data.current == 6) {
            my.getStorage({
              key: gdc.userId + gameName,
              success: function (res) {
                let list = [true, true, true, true, true, true, true]
                my.setStorage({
                  key: gdc.userId + gameName,
                  data: {
                    list: list,
                    current: 0,
                    golds: res.data.golds,
                    timer: timer,
                    flag: false
                  },
                  success: function () {
                    self.setData({
                      list: list,
                      current: 0,
                      golds: res.data.golds,
                      flag: false
                    })
                  }
                });
              },
              fail: function (res) {
                my.alert({ content: res.errorMessage });
              }
            });
          } else {
            self.setData({
              list: res.data.list,
              current: res.data.current,
              golds: res.data.golds,
              flag: false
            })
          }
        }
      },
      fail: function (res) {
        my.alert({ content: res.errorMessage });
      }
    });

Sign in

    report(e) {
      let self = this
      const { gdc = {}, mds = {}, modUtils } = this.props.data;
      //3.26  23.59.59 Time stamp   1616774399999  1616860799999, 1616947199999
      let timer = new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1 // Get the day  23:59:59  Time stamp 
      // Get the current timestamp 
      var newDateTime = Date.parse(new Date())
      my.getStorage({
        key: gdc.userId + gameName,
        success: function (res) {
          if (res.data.timer - newDateTime > 0) {
            // console.log(" On the same day ")
            let list1 = self.data.list[self.data.current] = false
            let list = self.data.list
            if (res.data.flag == false) {
              let golds = res.data.golds + self.data.goldsList[self.data.current]
              my.setStorage({
                key: gdc.userId + gameName,
                data: {
                  list: list,
                  timer: res.data.timer,
                  current: self.data.current,
                  golds: golds,
                  flag: true
                },
                success: function () {
                  self.setData({
                    list: list,
                    golds: golds,
                    flag: true
                  })
                }
              });
            } else {
              let golds = res.data.golds
              my.setStorage({
                key: gdc.userId + gameName,
                data: {
                  list: list,
                  timer: res.data.timer,
                  current: self.data.current,
                  golds: golds,
                  flag: true
                },
                success: function () {
                  self.setData({
                    list: list,
                    golds: golds,
                    flag: true
                  })
                }
              });
            }
          } else if (res.data.timer - newDateTime < 0 && res.data.timer - newDateTime > -86400000) {
            console.log("diertian")
            // No sign in on the first day , Sign in the next day 
            if (self.data.current > 0) {
              if (self.data.current > 6) {
                self.setData({
                  current: 0
                })
              } else {
                self.setData({
                  current: ++self.data.current
                })
              }
            } else if (self.data.current == 0) {
              self.setData({
                current: 0
              })
            }
            let list1 = self.data.list[self.data.current] = false
            let list = self.data.list
            let golds = res.data.golds + self.data.goldsList[self.data.current]
            my.setStorage({
              key: gdc.userId + gameName,
              data: {
                list: list,
                timer: timer,
                current: self.data.current,
                golds: golds
              },
              success: function () {
                self.setData({
                  list: list,
                  golds: golds
                })
              }
            });
          }
        },
        fail: function (res) {
        }
      });
    },
原网站

版权声明
本文为[weixin_ forty-four million three hundred and eighty-seven thous]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091511176368.html