微信小程序实现连续签到七天

断签之后会从第一天重新开始


<template>
  <view class="content" style="height: 100vh;background: white;">
    <view class="back">
      <view style="position: absolute;bottom: 200rpx;left: 40rpx;width: 90%;">
		  <image :src="headimgUrl" mode="widthFix" style="width: 92rpx;height: 92rpx;border-radius: 50%;float: left;margin-top: -6rpx;margin-right: 14rpx;"></image>
			<view style="float: left;">
				
				<span style="font-size: 32rpx;
				font-weight: bold;
				color: #FFFFFF;">当月连续签到 </span> <span style="font-size: 44rpx;color: #FF7D00;line-height: 40rpx;">{{ days }}</span><span style="font-size: 32rpx;
				font-weight: bold;
				color: #FFFFFF;">天</span>
				        <view style="font-size: 24rpx;
				font-weight: 100;
				color: #FFFFFF;">连续签到七天可获得{{ sevenDay }}积分</view>
			</view>
			 <uni-calendar ref="calendar" class="uni-calendar--hook"
			      :clear-date="true" :date="info.date"
			      :insert="info.insert" 
			      :startDate="info.startDate"
			      :endDate="info.endDate" :range="info.range" @confirm="confirm"  />
      </view>
    
    </view>
    <view class="sign_content">
      <div class="signBox">
        <text style="font-size: 30rpx;
font-weight: bold;
color: #0D052C;">签到得积分,直接当钱花</text>

        <ul class="signBtnBox">
          <li class="signBtnOne" v-for="(item, index) in list" :key="index" :class="{ signed: index + 1 <= Number(days) }">
            <div @click="handleSignIn(index+1, item.code)">
              <p style="line-height: 50rpx;">{{ item.gift_num }}</p>
            <!--  <p v-if="index + 1 <= Number(days)">已签到</p>
              <p v-else>签到</p> -->
              <p style="line-height: 210rpx;font-size: 20rpx;">{{ item.points }}积分</p>
            </div>
          </li>
        </ul>
		<view style="background: linear-gradient(to bottom right, #FF5A23, #FF920D);width: 80%;margin: 0 auto;text-align: center;color: white;font-size: 34rpx;height: 88rpx;line-height: 88rpx;margin-top: 120rpx;border-radius: 40rpx;" @click="handleSignIn1">签到</view>
      </div>
	  
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
		showCalendar: false,
		info: {
			lunar: true,
			range: true,
			insert: false,
			selected: []
		},
      list: [
        { gift_num: "第一天", code: "USER_SIGN_POINT_1", points: null },
        { gift_num: "第二天", code: "USER_SIGN_POINT_2", points: null },
        { gift_num: "第三天", code: "USER_SIGN_POINT_3", points: null },
        { gift_num: "第四天", code: "USER_SIGN_POINT_4", points: null },
        { gift_num: "第五天", code: "USER_SIGN_POINT_5", points: null },
        { gift_num: "第六天", code: "USER_SIGN_POINT_6", points: null },
        { gift_num: "第七天", code: "USER_SIGN_POINT_7", points: null },
      ],
      res: "",
      days: "", // 签到的总天数
      signOK: "",
      headimgUrl: "",
      sevenDay: "",
    };
  },
  onReady() {
  	this.$nextTick(() => {
  		this.showCalendar = true
  	})
  },
  methods: {
	  open() {
	  	this.$refs.calendar.open()
	  },
	 
    async todaySignIn(code) {
      const res = await this.$request.post(
        "user/userSign",
        {
          token: uni.getStorageSync("token").token,
        },
        {
          native: true,
        }
      );
      if (res.data.status == "ok") {
        var data = res.data.data;
        uni.showToast({
          title: "签到成功!",
		  duration:2000
        })
		setTimeout(()=>{
			this.getSignIn()
		},2000)
      } else {
        this.handleSignIn()
      }
    },
	handleSignIn1() {
	    const index = Number(this.days) + 1;
	    if (index <= this.list.length) {
	      const code = this.list[index - 1].code;
	      this.todaySignIn(code);
	    } else {
	      uni.showToast({
	        icon: 'none',
	        title: "明天再来签到吧"
	      })
	    }
	  },
    async qiandao(code, index) {
      const res = await this.$request.post(
        "user/getUserConf",
        {
          token: uni.getStorageSync("token").token,
          code: code,
          type: 1
        },
        {
          native: true,
        }
      );
      if (res.data.status == "ok") {
        var data = res.data.data;
        console.log(data, "签到");
		this.sevenDay = data[0].values
        this.list[index].points = data[0].values;
      }
    },
    // 点击签到
    handleSignIn(index, code) {
      if (index > Number(this.days) + 1) {
        uni.showToast({
          icon: 'none',
          title: "请按顺序签到"
        })
      } else if (index === Number(this.days) + 1) {
        this.todaySignIn(code);
		
      } else {
        uni.showToast({
          icon: 'none',
          title: "明天再来签到吧"
        })
      }
    },
// async getSignIn() {
//   const res = await this.$request.post(
//     "user/getUserSignList",
//     {
//       token: uni.getStorageSync("token").token,
//     },
//     {
//       native: true,
//     }
//   );
//   if (res.data.status == "ok") {
//     var data = res.data.data;
//     this.days = data.sign_num;
//     this.headimgUrl = data.headimgurl;
// 	console.log(this.headimgUrl,'头像')
//     // 更新签到列表数据
//     for (let i = 0; i < this.list.length; i++) {
//       if (i < 7) {	
//         // 前七天的日期都显示原始的第一天、第二天等日期
//         this.list[i].gift_num = `第${i + 1}天`;
//       } else {
//         // 第八天及以后的日期只有在连续签到七天后才显示
//         if (this.days >= 7) {
//           this.list[i].gift_num = `第${i + 1}天`;
//         } else {
//           this.list[i].gift_num = "";
//         }
//       }
//       this.qiandao(this.list[i].code, i);
//     }
//   }
// },
    async getSignIn() {
      const res = await this.$request.post(
        "user/getUserSignList",
        {
          token: uni.getStorageSync("token").token,
        },
        {
          native: true,
        }
      );
      if (res.data.status == "ok") {
        var data = res.data.data;
        this.days = data.sign_num;
        this.headimgUrl = data.headimgUrl;
		 // this.apiDates = data.map(item => item.create_time.split(' ')[0]); // 提取日期字符串中的日期部分
        console.log(data, "签到列表");
		
        for (let i = 0; i < this.list.length; i++) {
          this.qiandao(this.list[i].code, i);
        }
      }
    },
  },
  components: {},
  onShow(){
	  this.getSignIn();
  },
  created() {
    this.getSignIn();
    this.qiandao("USER_SIGN_POINT_7", 6);
  },
};
</script>

<style lang="scss" scoped>
.back {
  width: 100%;
  height: 460rpx;
  background: url("https://-picture.oss-cn-hangzhou.aliyuncs.com/ebk-wap/img-202308240245145778-Group%2034161%403x.png") no-repeat;
  position: relative;
  top: 0;
  .avatar {
    width: 400rpx;
    position: absolute;
    height: 100rpx;
    left: 40rpx;
    top: 20rpx;
    z-index: 9;
  }
  .sign-date {
   
  }
}
.sign_content {
  position: relative;
  top: -150rpx;
  // width: 96%;
  height: 622rpx;
  background: white;
  border-radius: 24rpx;
  padding: 34rpx;
   display: flex;
    justify-content: center; /* 水平居中 */
  .sign_day {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    height: 436rpx;
  }
}
.signBox {
	width: 100%;
  background: white;
  border-radius: 10px;
  margin: 0 auto;
  .tips {
    margin-top: 3%;
    span {
      font-size: 16px;
      letter-spacing: -0.1px;
      line-height: 22px;
      font-weight: 500;
    }
    :nth-of-type(2) {
      color: #fe9300;
      letter-spacing: -0.1px;
    }
  }
  .signBtnBox {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    & > li {
      // cursor: pointer;
      width: 22%;
      height: 172rpx;
      background:url('https://ebk-picture.oss-cn-hangzhou.aliyuncs.com/ebk-wap/img-202308300426108993-Group%2034210%403x.png');
      border-radius: 4px;
	  background-size: 100%;
	  margin-top: 50rpx;
      img {
        margin: 6px 0 0 10px;
      }
      p {
        text-align: center;
        opacity: 0.6;
        font-size: 14px;
        color: #333333;
        letter-spacing: 0;
        font-weight: 500;
      }
    }
	li:nth-child(7){
		 width: 49%;
		  height: 172rpx;
		  color: #333333;
		  background: url('https://ebk-picture.oss-cn-hangzhou.aliyuncs.com/ebk-wap/img-202308300506217750-Group%2034211%403x.png');
		  background-size: cover;
		  background-position: center;
		  border-radius: 4px;
		  margin-top: 50rpx;
		  p{
			  text-align: left;
			  padding-left: 50rpx;
		  }
	}
		
		.signed:nth-child(7){
			background: url('https://ebk-picture.oss-cn-hangzhou.aliyuncs.com/ebk-wap/img-202309070948277933-Group%2034267%403x.png');
			background-size: 100%;
			color: #333333;
			p {
			  opacity: 1 !important;
					color: #333;
			}
		}
    .signed {
      background: url('https://ebk-picture.oss-cn-hangzhou.aliyuncs.com/ebk-wap/img-202308300412527364-Group%2034209%403x.png');
	  background-size: 100%;
      color: #333333;
      p {
        opacity: 1 !important;
		color: #333;
      }
    }
	
  }
}
</style>

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
针对电商平台的用户签到积分系统,可以设计以下的数据库表结构: 1. 用户表(user):记录用户的基本信息,如用户ID、用户名、手机号码等。 | 字段名称 | 类型 | 主键/外键 | 描述 | | ------------- | ------------- | --------- | ---------------------- | | user_id | int | 主键 | 用户ID | | username | varchar(50) | | 用户名 | | phone_number | varchar(20) | | 手机号码 | 2. 签到记录表(checkin_record):记录用户每次签到的时间和签到积分数。 | 字段名称 | 类型 | 主键/外键 | 描述 | | --------------- | ------------- | --------- | ---------------------- | | record_id | int | 主键 | 签到记录ID | | user_id | int | 外键 | 用户ID | | checkin_time | datetime | | 签到时间 | | checkin_points | int | | 签到获得的积分数 | 3. 连续签到记录表(continuous_checkin):记录用户的连续签到情况,包括当前连续签到天数和最长连续签到天数。 | 字段名称 | 类型 | 主键/外键 | 描述 | | ---------------------- | ------------- | --------- | ---------------------- | | continuous_checkin_id | int | 主键 | 连续签到记录ID | | user_id | int | 外键 | 用户ID | | current_days | int | | 当前连续签到天数 | | longest_days | int | | 最长连续签到天数 | 在这里,我们可以通过触发器(trigger)来自动更新用户的连续签到记录。当用户签到时,我们可以在签到记录表中插入一条新的记录,并且根据用户的签到时间和上一次签到时间,来判断是否是连续签到。如果是连续签到,则更新用户的连续签到记录;否则,重置用户的连续签到记录。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值