前端样式未做处理,可将后端数据传至前端进行处理

1.wxml页面

<!--pages/signIn/signIn.wxml-->
<view class='signIn'>
<view class='sign-com'>
<view class='thead'>
<view class='tt'>已连续签到</view>
<view class='mm'><label class='n'>{{signNum}}</label>天</view>
<view class='pp'>连续签到7日后每日得3分</view>
</view>
<view class='modle'>
<view class='mol'>
<view class='mol-line'></view>
<view class='mol-ites'>
<view class="ite {{signNum>=min?'hover':''}}" data-n='{{min}}'>
<label class='n'>+{{min<7?1:3}}</label>
</view>
<view class="ite {{signNum>=min+1?'hover':''}}" data-n='{{min+1}}'>
<label class='n'>+{{min+1<7?1:3}}</label>
</view>
<view class="ite {{signNum>=min+2?'hover':''}}" data-n='{{min+2}}'>
<label class='n'>+{{min+2<7?1:3}}</label>
</view>
<view class="ite {{signNum>=min+3?'hover':''}}" data-n='{{min+3}}'>
<label class='n'>+{{min+3<7?1:3}}</label>
</view>
<view class="ite {{signNum>=min+4?'hover':''}}" data-n='{{min+4}}'>
<label class='n'>+{{min+4<7?1:3}}</label>
</view>
<view class="ite {{signNum>=min+5?'hover':''}}" data-n='{{min+5}}'>
<label class='n'>+{{min+5<7?1:3}}</label>
</view>
<view class="ite {{signNum>=min+6?'hover':''}}" data-n='{{max}}'>
<label class='n'>+{{min+6<7?1:3}}</label>
</view>
</view>
</view>
<view class='moday'>
<label class='dd'>{{min}}天</label>
<label class='dd'>{{min+1}}天</label>
<label class='dd'>{{min+2}}天</label>
<label class='dd'>{{min+3}}天</label>
<label class='dd'>{{min+4}}天</label>
<label class='dd'>{{min+5}}天</label>
<label class='dd'>{{max}}天</label>
</view>
</view>
<view class='the-btn'>
<button type='button' class='btn' bindtap='bindSignIn' data-num="{{signNum}}" disabled='{{signState}}'
data-min="{{min}}" data-max="{{max}}" data-be="{{be}}"
>签到</button>
</view>
</view>
</view>
<view class='explax'>
<view class=''>日期开始:{{min}} </view>
<view class=''>日期结束:{{max}} </view>
<view class=''>签到数:{{signNum}}天</view>
<view class=''>切换周期的倍数:{{be}}</view>
</view>

2wxss

.signIn{ width: 100%; height: auto;}

.sign-com{ width: 100%; height: auto; padding: 0 30rpx; box-sizing: border-box; overflow: hidden; }
.sign-com .thead{ width: 100%; text-align: center; padding: 50rpx 0 35rpx;}
.sign-com .thead .tt{ font-size: 24rpx;}
.sign-com .thead .mm{ margin-top: 10rpx; font-size: 24rpx;}
.sign-com .thead .mm .n{ font-size: 66rpx; margin-right: 25rpx;}
.sign-com .thead .pp{ color: #999; font-size: 24rpx; margin-top: 10rpx;} .sign-com .modle{ width: 100%; height: 100rpx; margin-top: 10rpx; }
.sign-com .modle .mol{ width: 100%; height: 52rpx; position: relative; }
.sign-com .mol-line{ width: 100%; height: 4rpx; background-color: #e6e6e6; position: absolute; left: 0; top: 50%; transform: translateY(-50%);}
.sign-com .mol-ites{ width: 100%; height: 100%;position: absolute;}
.mol-ites .ite{ width: 52rpx; height: 52rpx; border-radius: 50%; border: 1px solid #f5f5f5;
background-color: #fff; box-sizing: border-box; position: absolute; left: 0; top: 0; z-index: 2;}
.mol-ites .ite .n{ width: 44rpx; height: 44rpx; line-height: 44rpx; text-align: center; border-radius: 50%; background-color: #f5f5f5;position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); font-size: 22rpx;}
.mol-ites .ite::after{ content: ""; width: 80rpx; height: 4rpx; background-color: transparent;
position: absolute; left: 52rpx; top: 50%; margin-top: -2rpx; z-index: 2;}
.mol-ites .ite:last-of-type::after{ width: 0;}
.mol-ites .ite:nth-of-type(2){ left: 107rpx;}
.mol-ites .ite:nth-of-type(3){ left: 214rpx;}
.mol-ites .ite:nth-of-type(4){ left: 321rpx;}
.mol-ites .ite:nth-of-type(5){ left: 428rpx;}
.mol-ites .ite:nth-of-type(6){ left: 535rpx;}
.mol-ites .ite:nth-of-type(7){ left: 642rpx;}
.mol-ites .ite.hover{ border-color: #ff614a;}
.mol-ites .ite.hover .n{ background-color: #ff614a; color: #fff;}
.mol-ites .ite.hover::after{ background-color: #ff614a; }
.moday{ width: 100%; height:40rpx; overflow: hidden; position: relative; margin-top:20rpx;}
.moday .dd{ width: 52rpx; height: 40rpx; line-height: 1; text-align: center; font-size: 22rpx;
position: absolute; left: 0; bottom: 0;}
.moday .dd:nth-of-type(2){ left: 107rpx;}
.moday .dd:nth-of-type(3){ left: 214rpx;}
.moday .dd:nth-of-type(4){ left: 321rpx;}
.moday .dd:nth-of-type(5){ left: 428rpx;}
.moday .dd:nth-of-type(6){ left: 535rpx;}
.moday .dd:nth-of-type(7){ left: 642rpx;} .the-btn{ margin: 50rpx 0;}
.the-btn .btn{ background-color: #ff614a; color: #fff;}
.the-btn.signed .btn{ background-color: rgba(153, 153, 153, 0.61); } .explax{ padding: 0 30rpx; font-size: 28rpx; color: #666;}

3:wxjs:

const app = getApp();

Page({

  /**
* 页面的初始数据
*/
data: {
//img_url: config.imgUrl, //图片地址 //签到模块
signNum: 0, //签到数
signState: false, //签到状态
min: 1, //默认值日期第一天1
max: 7, //默认值日期最后一天7
be: 0, //默认倍数
integral: ''
}, //签到
bindSignIn(e) {
// 获取token
var token = wx.getStorageSync('token')
// 用户id
var userid = wx.getStorageSync('userid')
wx.request({
url: 'http://www.yan.com/api/task16/sign', //仅为示例,并非真实的接口地址
data: {
userid: userid
},
header: { token },
method: 'POST',
success(res) {
if (res.data.code == 200) {
wx.showToast({
title: '签到成功',
}) }
if (res.data.code == 500) {
wx.showToast({
title: '网络异常',
}) }
if (res.data.code == 501) {
wx.showToast({
title: '签到失败',
}) } }
}) }, /**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) { }, /**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () { }, /**
* 生命周期函数--监听页面显示
*/
onShow: function () { }, /**
* 生命周期函数--监听页面隐藏
*/
onHide: function () { }, /**
* 生命周期函数--监听页面卸载
*/
onUnload: function () { }, /**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () { }, /**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () { }, /**
* 用户点击右上角分享
*/
onShareAppMessage: function () { }
})

laravel 路由:

Route::group(['namespace' => 'Task', 'middleware' => 'jwt'], function () {
// 签到
Route::post('task16/sign','task16\TaskController@sign');
//积分明细表
Route::post('task16/details','task16\TaskController@details'); });

laravel控制器:

/*
*
* 签到*/
public function sign(Request $request)
{
$userId = $request->input('userid');
$user = WxUserInfo::where('id',$userId)->first();
$day = $user->days;
//获取当前的时间
$yearMonthDay = date('Y-m-d',time());
//开启事务
DB::beginTransaction();
try {
//将用户id 和 当前签到天数添加到表里面
$sign = \App\Models\week3\Sign::create(['userid'=>$userId,'ymd'=>$yearMonthDay]); $signId = $sign->id;
//获取用户上次签到时间
$lastSignDayObj = \App\Models\week3\Sign::select('ymd')->where('userid',$userId)->where('id','<',$signId)->orderBy('id','desc')->limit(1)->first(); //根据上次的签到时间来判断是 断签 ,还是连续签到 ,还是第一次签到
if (empty($lastSignDayObj)){
//不存在 表示第一次签到
$days = 1;
$number = BonusPoints::select('number')->where('day',$days)->first();
if ($number){
$score = $number->number;
//存在
}else{
//不存在
$score = 7;
}
$status = '第一次签到,获得积分'.$score;
}else{
$lastSignDay = $lastSignDayObj->ymd;
//存在 将当前天数的时间戳 和 上次签到的时间戳作比较
$time = strtotime($yearMonthDay) - strtotime($lastSignDay);
if ($time >= 24*3600 && $time < 48*3600){
//表示连续签到 签到天数加一
$days = $day +1;
$number = BonusPoints::select('number')->where('day',$days)->first(); if ($number){
$score = $number->number;
}else{
//不存在
$score = 7;
}
$status = '连续签到'.$days.'天,获得积分'.$score;
}else if ($time >= 48*3600){
//表示断签 和 第一次签到是一样的
$days = 1;
$number = BonusPoints::select('number')->where('day',$days)->first();
if ($number){
$score = $number->number;
//存在
}else{
//不存在
$score = 7;
}
$status = '断签后第一次签到,获得积分'.$score;
}else{
return ['code'=>500,'msg'=>'网路错误'];
}
}
//记录用户的积分明细
SignUser::create(['userid'=>$userId,'score'=>$score,'type'=>1,'fid'=>$signId.'订单号']);
//求用户的积分余额
$scores = SignUser::where('userid',$userId)->sum('score');
//更改用户的连续签到天数 和 积分
WxUserInfo::where('id',$userId)->update(['days'=>$days,'scores'=>$scores]);
//事务提交
DB::commit();
return ['code'=>200,'msg'=>'签到成功','data'=>['score'=>$score,'status'=>$status]];
}catch (\Exception $e){
//事务回滚
DB::rollBack();
return ['code'=>501,'msg'=>'签到失败'];
}
}

相关的模型:用户表

CREATE TABLE `wxuserinfos` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`openid` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`session_key` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`avatarUrl` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '头像',
`nickName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '昵称',
`days` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '签到天数',
`scores` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '积分',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
<?php

namespace App\Models\Task\task15;

use Illuminate\Database\Eloquent\Model;

class WxUserInfo extends Model
{
//
protected $guarded=[];
public $timestamps=false;
protected $table='WxUserInfos';
}

签到记录表

<?php

namespace App\Models\week3;

use Illuminate\Database\Eloquent\Model;

class Sign extends Model
{
//
protected $guarded=[];
public $timestamps=false;
protected $table='sign_records';
}
CREATE TABLE `sign_records` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`userid` int(10) NOT NULL COMMENT '用户id',
`ymd` date NOT NULL COMMENT '签到时间',
`updated_at` datetime DEFAULT NULL,
`created_at` datetime DEFAULT NULL COMMENT '签到具体时间',
PRIMARY KEY (`id`,`userid`,`ymd`),
UNIQUE KEY `唯一` (`userid`,`ymd`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=47 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

签到积分规则表:

<?php

namespace App\Models\week3;

use Illuminate\Database\Eloquent\Model;

class BonusPoints extends Model
{
//
protected $table='sign_rule';
protected $guarded=[];
public $timestamps=false;
}
CREATE TABLE `sign_rule` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`day` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '签到天数',
`number` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '积分',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

积分明细表:

<?php

namespace App\Models\week3;

use Illuminate\Database\Eloquent\Model;

class SignUser extends Model
{
//
public $timestamps=false;
protected $table='sign_detailed';
protected $guarded=[];
}
EATE TABLE `sign_detailed` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`userid` int(11) DEFAULT NULL COMMENT '用户id',
`type` tinyint(4) DEFAULT NULL COMMENT '获取积分的类型',
`fid` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '积分来源',
`score` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '获取到的积分',
`time` datetime DEFAULT NULL COMMENT '时间',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

微信小程序结合laravel完成签到功能的更多相关文章

  1. 记录使用微信小程序的NFC和蓝牙功能读取15693芯片的开发历程

    开发目标: (1) 对于Android手机,直接通过微信小程序调用手机的NFC功能,对15693协议的芯片进行读写操作: (2)对于苹果手机(及没有NFC模块的手机),通过微信小程序的蓝牙功能连接到蓝 ...

  2. 基于微信小程序的用户列表点赞功能

    代码地址如下:http://www.demodashi.com/demo/13997.html 一.前言 (1).适合人群 1.微信小程序开发者 2.前端工程师 3.想入门学习小程序开发的人员 4.想 ...

  3. 微信小程序之换肤的功能

    pc或者移动端实现换肤功能还是比较简单的,大致就是需要换肤的css,还有正常的css:把当前皮肤类型存入本地:然后通过js读取并判断当前应该加载哪套css. 由于微信小程序没有操作wxss的api,所 ...

  4. 微信小程序上传Excel文本文件功能

    问题: 在开发过程中会发现微信小程序有很多功能都还不能满足我们的需求,谁叫客户就是上帝呢,前几天小编遇到了这么个问题,就是用微信小程序上传文件,但是还以为微信带有这个模块,可是查了许久还是没有找到,只 ...

  5. 微信小程序背景音频播放分享功能

    如果正常背景音频播放的话,只能跳转到自己对应的微信小程序,无法分享朋友圈,我们需要设置分享朋友圈,需要调用一个API 音频背景播放 注意:背景播放在锁屏后播放只支持IOS端,安卓端虽然可以播放,但是锁 ...

  6. 微信小程序实现连续扫码功能(uniapp)

    注:本文使用的是 uniapp 语法. 微信小程序提供了扫码API:wx.scanCode,但它只能扫一次码,想要实现连续扫码,需要借用 camera 组件.camera 组件不仅能拍照,还具有扫码功 ...

  7. [转]微信小程序实现图片上传功能

    本文转自:http://blog.csdn.net/feter1992/article/details/77877659 前端: 微信开发者工具 后端:.Net 服务器:阿里云 这里介绍微信小程序如何 ...

  8. 微信小程序实现即时通信聊天功能的实例代码

    项目背景:小程序中实现实时聊天功能 一.服务器域名配置 配置流程 配置参考URL:https://developers.weixin.qq.com/miniprogram/dev/api/api-ne ...

  9. 微信小程序实现图片上传功能

    前端: 微信开发者工具 后端:.Net 服务器:阿里云 这里介绍微信小程序如何实现上传图片到自己的服务器上 前端代码 data: { productInfo: {} }, //添加Banner bin ...

随机推荐

  1. 收集有用的 Javascript 片段

    内容目录 数组 arrayMax arrayMin chunk compact countOccurrences deepFlatten difference distinctValuesOfArra ...

  2. 需求: 使用LinkedList存储一副扑克牌,然后实现洗牌功能。

    import java.util.LinkedList; import java.util.Random; /* 需求: 使用LinkedList存储一副扑克牌,然后实现洗牌功能. */ //扑克类 ...

  3. 分布式消息队列RocketMQ(一)安装与启动

    分布式消息队列RocketMQ 一.RocketMQ简介 RocketMQ(火箭MQ) 出自于阿里,后开源给apache成为apache的顶级开源项目之一,顶住了淘宝10年的 双11压力 是电商产品的 ...

  4. 注解的使用、拦截器使用、AOP切面使用

    Java 自定义注解及使用场景 转载: https://www.jianshu.com/p/a7bedc771204 Java自定义注解一般使用场景为:自定义注解+拦截器或者AOP,使用自定义注解来自 ...

  5. JavaWeb项目根路径问题

    jsp中获取项目根路径: 方法① 最顶部增加代码: <% String path = request.getContextPath(); String basePath = request.ge ...

  6. Postman_JavaScript

    使用语法:JavaScript 结构: 测试工具主要包括三部分 在发起请求之前运行的Pre-request,预处理数据,作用:在发送请求前编辑请求数据,比如用户名或时间戳 对响应后的数据运行的Test ...

  7. 第2章 selenium开发环境的搭建

    前端技术: html:网页的基础,一种标记语言,显示数据: JS:前端脚本语言,解释型语言,在页面中添加交互行为 xml:扩展标记语言,用来传输和存储数据 css:层叠样式表,用来表现HTML或XML ...

  8. Express中使用session

    1.安装express-session npm install express-session --save-dev //注意-g无效 2.app.jsvar session = require('e ...

  9. jquery里的Ajax解析

    现在对Jquery的Ajax进行详细的解析. 顺带,我会在后面把我整理的一整套CSS3,PHP,MYSQL的开发的笔记打包放到百度云,有需要可以直接去百度云下载,这样以后你们开发就可以直接翻笔记不用百 ...

  10. v77.01 鸿蒙内核源码分析(消息封装篇) | 剖析LiteIpc(上)进程通讯内容 | 新的一年祝大家生龙活虎 虎虎生威

    百篇博客分析|本篇为:(消息封装篇) | 剖析LiteIpc进程通讯内容 进程通讯相关篇为: v26.08 鸿蒙内核源码分析(自旋锁) | 当立贞节牌坊的好同志 v27.05 鸿蒙内核源码分析(互斥锁 ...