thinkPHP完成每日签到作用的方式

摘要: `id` int(11) unsigned NOT NULL AUTO_INCREMENT,`uid` int(11) unsigned NOT NULL COMMENT 客户id ,`days` tinyint(2) unsigned NOT NULL DEFAULT 0 COMMENT 持续每日签到的天数 ,`is_share` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 是不...

`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `uid` int(11) unsigned NOT NULL COMMENT 客户id , `days` tinyint(2) unsigned NOT NULL DEFAULT 0 COMMENT 持续每日签到的天数 , `is_share` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 是不是共享过 , `is_sign` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 是不是每日签到过 , `stime` int(11) unsigned NOT NULL DEFAULT 0 COMMENT 每日签到的時间 , `atime` int(11) unsigned NOT NULL DEFAULT 0 COMMENT 加上時间 , PRIMARY KEY (`id`), KEY `index_uid` (`uid`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=162 DEFAULT CHARSET=utf8 COMMENT= 每日签到共享表

Controller:

 ?php
namespace Member\Controller;
use Member\Controller\MController;
class IndexController extends MController {
 * 客户管理中心
 * @param
 public function index(){
 $pre = C( DB_PREFIX 
 // 日历目录
 $monthSign = $this- getMonthSign();
 $dayList = $this- showDays($monthSign);
 // 今日每日签到
 $data = $this- todayData();
 if($data[ is_sign ] == 1){
 $this- assign( isSign ,true);
 $this- display();
 * 实行当日每日签到
 * @return json 每日签到取得成功回到 {: 已每日签到 }
 public function sign(){
 $todayData = $this- todayData();
 if($todayData[ is_sign ] == 1){
 $this- successMsg( 已每日签到 
 }else{
 $data = $this- getInsertData($this- uid);
 // 无今日数据信息
 if($todayData == NULL){
 $data[ uid ] = $this- 
 $data[ atime ] = time();
 $id = M( members_sign )- add($data);
 }else{
 $save = M( members_sign )- where( id = {$todayData[ id ]} )- save($data);
 if($id or $save){
 $score = $this- getTodayScores($data[ days 
 // 为该客户加上積分
 addScore($this- uid,$score);
 $this- successMsg( 已每日签到 ,array( score = $score, days = $data[ days ]));
 }else{
 $this- errorMsg( 每日签到不成功,请更新后再试! 
 * 回到每一次每日签到要插进的数据信息
 * @param int $uid 客户id
 * @return array(
 * days = 天数 ,
 * is_sign = 是不是每日签到,用1表明早已每日签到 ,
 * stime = 每日签到時间 ,
 * );
 protected function getInsertData($uid){
 // 昨日的持续每日签到天数
 $start_time = strtotime(date( Y-m-d 0:0:0 ,time()-86400))-1;
 $end_time = strtotime(date( Y-m-d 23:59:59 ,time()-86400))+1;
 $days = M( members_sign )- where( uid = $uid and atime $start_time and atime $end_time )- getField( days 
 if($days){
 $days++;
 if($days 30){
 $days = 1;
 }else{
 $days = 1;
 return array(
 days = $days,
 is_sign = 1,
 stime = time()
 * 客户当日每日签到的数据信息
 * @return array 每日签到信息内容 is_sign,stime 等
 protected function todayData(){
 $time = time();
 $start_stime = strtotime(date( Y-m-d 0:0:0 ,$time))-1;
 $end_stime = strtotime(date( Y-m-d 23:59:59 ,$time))+1;
 return M( members_sign )- field( atime ,true)- where( uid = {$this- uid} and atime $start_stime and atime $end_stime )- find();
 * 積分标准,回到持续每日签到的天数相匹配的積分
 * @param int $days 当日应当得的成绩
 * @return int 積分
 protected function getTodayScores($days){
 if($days == 30){
 return 50;
 }else if($days 19){
 return 8;
 }else if($days 9){
 return 5;
 }else{
 return 3;
 * 显示信息每日签到目录
 * @param array $signDays 某月每日签到的时间 array(1,2,3,4,5,12,13)
 * @param int $year 可选择,年代
 * @param int $month 可选择,月份
 * @return string 时间目录 li 1 /li ....
 protected function showDays($signDays,$year,$month){
 $time = time();
 $year = $year ? $year : date( Y ,$time);
 $month = $month ? $month : date( m ,$time);
 $daysTotal = date( t , mktime(0, 0, 0, $month, 1, $year));
 $now = date( Y-m-d ,$time);
 $str = 
 for ($j = 1; $j = $daysTotal; $j++) {
 $i++;
 $someDay = date( Y-m-d ,strtotime( $year-$month-$j ));
 // 低于今日的时间款式
 if ($someDay = $now){
 // 当日时间款式 tdc = todayColor
 if($someDay == $now){
 // 当日每日签到过的
 if(in_array($j,$signDays)){
 $str .= li > 

(資源库 )

Tag标识:ThinkPHP


联系我们

全国服务热线:4000-399-000 公司邮箱:343111187@qq.com

  工作日 9:00-18:00

关注我们

官网公众号

官网公众号

Copyright?2020 广州凡科互联网科技股份有限公司 版权所有 粤ICP备10235580号 客服热线 18720358503

技术支持:手机网页模板