首页 后端开发 php教程 php+mysql+jquery实现日历签到功能的方法

php+mysql+jquery实现日历签到功能的方法

May 25, 2018 am 11:47 AM
php 功能

本文主要介绍了php+mysql+jquery实现日历签到功能的过程与步骤,具有很好的参考价值

在网站开发过程中我们会经常用到签到功能来奖励用户积分,或者做一些其他活动。这次项目开发过程中做了日历签到,因为没有经验所有走了很多弯路,再次记录过程和步骤。

1.日历签到样式:

2.本次签到只记录本月签到数,想要查询可以写其他页面,查询所有签到记录。(功能有,非常麻烦,古没有做。)

3.前台代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

<include file="Public:menu" />

<style type="text/css"

*{margin:0;padding:0;font:14px/1.8 "Helvetica Neue","microsoft yahei";}

</style>

<p class="ser_bx">

  <p class="ser_bxc">

    <span style="color:#5381B5;">签到记录</span>

    <if condition="$res[&#39;0&#39;][&#39;points&#39;] eq &#39;5&#39;">

      <p class="already btn_center">已签到</p>

    <else />

      <p class="ser_mbx btn_center">立即签到</p>

    </if>

    <p class="already btn_center" style="display:none;">已签到</p>

    <!--<p class="minein">积分 : <span style="color:#b81d25">{$poin.points}</span></p>-->

  </p>

</p>

<p class="check_box">

<p style="width:500px;height:400px;margin:0 auto;">

  <p style="width:300px;height:300px;margin-left:50px;" id="calendar"></p>

</p>

  </p>

<script type="text/javascript">

   $(document).ready(function(){

     $(".ser_mbx").click(function(){

       $.ajax({

        url:"{:U(&#39;Index/Checkin&#39;)}",

          type:&#39;POST&#39;,

        datatype:"json",

        success:function(msg){

          $(".already").show();

          $(".ser_mbx").hide();

       MonthSign();

        }

      });

     });

   });

</script>

 <script type="text/javascript" language="javascript">

  $(document).ready(function(){ 

        MonthSign();

   });

  function MonthSign(){

     //ajax获取日历json数据

     $.ajax({

        url:"{:U(&#39;Index/MonthSign&#39;)}",

          type:&#39;POST&#39;,

        datatype:"json",

        success:function(msg){

          //alert(msg);

          /*var signList=[{"signDay":"10"},{"signDay":"11"},{"signDay":"12"},{"signDay":"13"}];

          */

          calUtil.init(JSON.parse(msg));

        }

      });

  }

 </script>

 <script type="text/javascript">

  var calUtil = {

  //当前日历显示的年份

  showYear:2015,

  //当前日历显示的月份

  showMonth:1,

  //当前日历显示的天数

  showDays:1,

  eventName:"load",

  //初始化日历

  init:function(signList){

    calUtil.setMonthAndDay();

    calUtil.draw(signList);

    calUtil.bindEnvent();

  },

  draw:function(signList){

    //绑定日历

    var str = calUtil.drawCal(calUtil.showYear,calUtil.showMonth,signList);

    $("#calendar").html(str);

    //绑定日历表头

    var calendarName=calUtil.showYear+"年"+calUtil.showMonth+"月";

    $(".calendar_month_span").html(calendarName); 

  },

  //绑定事件

  bindEnvent:function(){

    //绑定上个月事件

    $(".calendar_month_prev").click(function(){

      //ajax获取日历json数据

      /*var signList=[{"signDay":"10"},{"signDay":"11"},{"signDay":"12"},{"signDay":"13"}];

      calUtil.eventName="prev";

      calUtil.init(signList);*/

    });

    //绑定下个月事件

    $(".calendar_month_next").click(function(){

      //ajax获取日历json数据

      /*var signList=[{"signDay":"10"},{"signDay":"11"},{"signDay":"12"},{"signDay":"13"}];

      calUtil.eventName="next";

      calUtil.init(signList);*/

    });

  },

  //获取当前选择的年月

  setMonthAndDay:function(){

    switch(calUtil.eventName)

    {

      case "load":

        var current = new Date();

        calUtil.showYear=current.getFullYear();

        calUtil.showMonth=current.getMonth() + 1;

        break;

      case "prev":

        var nowMonth=$(".calendar_month_span").html().split("年")[1].split("月")[0];

        calUtil.showMonth=parseInt(nowMonth)-1;

        if(calUtil.showMonth==0)

        {

            calUtil.showMonth=12;

            calUtil.showYear-=1;

        }

        break;

      case "next":

        var nowMonth=$(".calendar_month_span").html().split("年")[1].split("月")[0];

        calUtil.showMonth=parseInt(nowMonth)+1;

        if(calUtil.showMonth==13)

        {

            calUtil.showMonth=1;

            calUtil.showYear+=1;

        }

        break;

    }

  },

  getDaysInmonth : function(iMonth, iYear){

   var dPrevDate = new Date(iYear, iMonth, 0);

   return dPrevDate.getDate();

  },

  bulidCal : function(iYear, iMonth) {

   var aMonth = new Array();

   aMonth[0] = new Array(7);

   aMonth[1] = new Array(7);

   aMonth[2] = new Array(7);

   aMonth[3] = new Array(7);

   aMonth[4] = new Array(7);

   aMonth[5] = new Array(7);

   aMonth[6] = new Array(7);

   var dCalDate = new Date(iYear, iMonth - 1, 1);

   var iDayOfFirst = dCalDate.getDay();

   var iDaysInMonth = calUtil.getDaysInmonth(iMonth, iYear);

   var iVarDate = 1;

   var d, w;

   aMonth[0][0] = "日";

   aMonth[0][1] = "一";

   aMonth[0][2] = "二";

   aMonth[0][3] = "三";

   aMonth[0][4] = "四";

   aMonth[0][5] = "五";

   aMonth[0][6] = "六";

   for (d = iDayOfFirst; d < 7; d++) {

    aMonth[1][d] = iVarDate;

    iVarDate++;

   }

   for (w = 2; w < 7; w++) {

    for (d = 0; d < 7; d++) {

     if (iVarDate <= iDaysInMonth) {

      aMonth[w][d] = iVarDate;

      iVarDate++;

     }

    }

   }

   return aMonth;

  },

  ifHasSigned : function(signList,day){

   var signed = false;

   $.each(signList,function(index,item){

    if(item.signDay == day) {

     signed = true;

     return false;

    }

   });

   return signed ;

  },

  drawCal : function(iYear, iMonth ,signList) {

   var myMonth = calUtil.bulidCal(iYear, iMonth);

   var htmls = new Array();

   htmls.push("<p class=&#39;sign_main&#39; id=&#39;sign_layer&#39;>");

   htmls.push("<p class=&#39;sign_succ_calendar_title&#39;>");

   htmls.push("<p class=&#39;calendar_month_span&#39;></p>");

   htmls.push("</p>");

   htmls.push("<p class=&#39;sign&#39; id=&#39;sign_cal&#39;>");

   htmls.push("<table>");

   htmls.push("<tr>");

   htmls.push("<th>" + myMonth[0][0] + "</th>");

   htmls.push("<th>" + myMonth[0][1] + "</th>");

   htmls.push("<th>" + myMonth[0][2] + "</th>");

   htmls.push("<th>" + myMonth[0][3] + "</th>");

   htmls.push("<th>" + myMonth[0][4] + "</th>");

   htmls.push("<th>" + myMonth[0][5] + "</th>");

   htmls.push("<th>" + myMonth[0][6] + "</th>");

   htmls.push("</tr>");

   var d, w;

   for (w = 1; w < 7; w++) {

    htmls.push("<tr>");

    for (d = 0; d < 7; d++) {

     var ifHasSigned = calUtil.ifHasSigned(signList,myMonth[w][d]);

     console.log(ifHasSigned);

     if(ifHasSigned){

      htmls.push("<td class=&#39;on&#39;>" + (!isNaN(myMonth[w][d]) ? myMonth[w][d] : " ") + "</td>");

     } else {

      htmls.push("<td>" + (!isNaN(myMonth[w][d]) ? myMonth[w][d] : " ") + "</td>");

     }

    }

    htmls.push("</tr>");

   }

   htmls.push("</table>");

   htmls.push("</p>");

   htmls.push("</p>");

   return htmls.join(&#39;&#39;);

  }

};

</script>

<include file="Public:footer" />

登录后复制

4.后台代码:查询今天是否签到:

1

2

3

4

5

6

7

8

9

10

11

12

$points = M(&#39;points_log&#39;);

    $userid=session(&#39;user.id&#39;);

    $begintime=date("Y-m-d H:i:s",mktime(0,0,0,date(&#39;m&#39;),date(&#39;d&#39;),date(&#39;Y&#39;)));

    $endtime=date("Y-m-d H:i:s",mktime(0,0,0,date(&#39;m&#39;),date(&#39;d&#39;)+1,date(&#39;Y&#39;))-1);

    $where=array(

        &#39;points&#39;=>&#39;5&#39;,

        &#39;user_id&#39;=>$userid,

        &#39;createtime&#39; => array(array(&#39;gt&#39;,$begintime),array(&#39;lt&#39;,$endtime)),

      );

    $res=$points->where($where)->order("createtime desc")->select();

    //var_dump($res[&#39;0&#39;][&#39;points&#39;]);

    $this->assign(&#39;res&#39;,$res);

登录后复制

5.查询积分:

1

2

3

4

5

6

/*查询积分*/

    $jfen=M(cuser);

    $list=$jfen->where(array(&#39;id&#39;=>$userid))->field(&#39;points&#39;)->find();

    $preg = &#39;/[0]*/&#39;;

    $poin = preg_replace($preg, &#39;&#39;, $list, 1);

    $this->assign(&#39;poin&#39;,$poin);

登录后复制

6.签到写入数据库:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

/*签到*/

    if(IS_AJAX){ 

      $userid=session(&#39;user.id&#39;);

      $type=&#39;签到&#39;;

      $typename=&#39;checkin&#39;;

      $id_status=&#39;up&#39;;

      $date=Date(&#39;Y-m-d H:i:s&#39;);

      $dataList=array(

          &#39;user_id&#39;=>$userid,

          &#39;type&#39;=>$type,

          &#39;typename&#39;=>$typename,

          &#39;id_status&#39;=>$id_status,

          &#39;points&#39;=>&#39;5&#39;,

          &#39;createtime&#39;=>$date,

          &#39;remark&#39;=>&#39;奖励5积分&#39;

          ); 

      $points = M(&#39;points_log&#39;);

      if($points->add($dataList)){

        $log=session(&#39;user.id&#39;);

        $user=M(&#39;cuser&#39;);

        $user->where(array(&#39;id&#39;=>$log))->setInc(&#39;points&#39;,5);

      

      $this->ajaxReturn($status);

    }

登录后复制

7. /*查询本月签到天数,并以json格式返回*/

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

public function MonthSign(){

    $userid=session(&#39;user.id&#39;);

    $points = M(&#39;points_log&#39;);

    $res=$points->where(array(&#39;user_id&#39;=>$userid))->select();

    $sign=&#39;[&#39;;

    foreach($res as $key=>$value){

      $first=explode(&#39; &#39;, $value[&#39;createtime&#39;]);

      $second=explode(&#39;-&#39;, $first[&#39;0&#39;])[&#39;2&#39;];

      if($key==0){

        $sign .= &#39;{"signDay":"&#39;.$second.&#39;"}&#39;;

      }else{

        $sign .= &#39;,{"signDay":"&#39;.$second.&#39;"}&#39;;

      }

    }

    $sign .=&#39;]&#39;;

    $this->ajaxReturn($sign,&#39;json&#39;);

  }

登录后复制

以上就是本文的全部内容,希望对大家的学习有所帮助。


相关推荐:

php+mysql+jquery实现日历签到

基于jquery实现日历签到功能_jquery

javascript - PHP+JS的日历签到怎么实现

以上是php+mysql+jquery实现日历签到功能的方法的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

<🎜>:泡泡胶模拟器无穷大 - 如何获取和使用皇家钥匙
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系统,解释
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆树的耳语 - 如何解锁抓钩
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

Java教程
1664
14
CakePHP 教程
1423
52
Laravel 教程
1321
25
PHP教程
1269
29
C# 教程
1249
24
PHP和Python:比较两种流行的编程语言 PHP和Python:比较两种流行的编程语言 Apr 14, 2025 am 12:13 AM

PHP和Python各有优势,选择依据项目需求。1.PHP适合web开发,尤其快速开发和维护网站。2.Python适用于数据科学、机器学习和人工智能,语法简洁,适合初学者。

PHP行动:现实世界中的示例和应用程序 PHP行动:现实世界中的示例和应用程序 Apr 14, 2025 am 12:19 AM

PHP在电子商务、内容管理系统和API开发中广泛应用。1)电子商务:用于购物车功能和支付处理。2)内容管理系统:用于动态内容生成和用户管理。3)API开发:用于RESTfulAPI开发和API安全性。通过性能优化和最佳实践,PHP应用的效率和可维护性得以提升。

PHP:网络开发的关键语言 PHP:网络开发的关键语言 Apr 13, 2025 am 12:08 AM

PHP是一种广泛应用于服务器端的脚本语言,特别适合web开发。1.PHP可以嵌入HTML,处理HTTP请求和响应,支持多种数据库。2.PHP用于生成动态网页内容,处理表单数据,访问数据库等,具有强大的社区支持和开源资源。3.PHP是解释型语言,执行过程包括词法分析、语法分析、编译和执行。4.PHP可以与MySQL结合用于用户注册系统等高级应用。5.调试PHP时,可使用error_reporting()和var_dump()等函数。6.优化PHP代码可通过缓存机制、优化数据库查询和使用内置函数。7

PHP的持久相关性:它还活着吗? PHP的持久相关性:它还活着吗? Apr 14, 2025 am 12:12 AM

PHP仍然具有活力,其在现代编程领域中依然占据重要地位。1)PHP的简单易学和强大社区支持使其在Web开发中广泛应用;2)其灵活性和稳定性使其在处理Web表单、数据库操作和文件处理等方面表现出色;3)PHP不断进化和优化,适用于初学者和经验丰富的开发者。

PHP与Python:了解差异 PHP与Python:了解差异 Apr 11, 2025 am 12:15 AM

PHP和Python各有优势,选择应基于项目需求。1.PHP适合web开发,语法简单,执行效率高。2.Python适用于数据科学和机器学习,语法简洁,库丰富。

PHP和Python:代码示例和比较 PHP和Python:代码示例和比较 Apr 15, 2025 am 12:07 AM

PHP和Python各有优劣,选择取决于项目需求和个人偏好。1.PHP适合快速开发和维护大型Web应用。2.Python在数据科学和机器学习领域占据主导地位。

PHP与其他语言:比较 PHP与其他语言:比较 Apr 13, 2025 am 12:19 AM

PHP适合web开发,特别是在快速开发和处理动态内容方面表现出色,但不擅长数据科学和企业级应用。与Python相比,PHP在web开发中更具优势,但在数据科学领域不如Python;与Java相比,PHP在企业级应用中表现较差,但在web开发中更灵活;与JavaScript相比,PHP在后端开发中更简洁,但在前端开发中不如JavaScript。

PHP和Python:解释了不同的范例 PHP和Python:解释了不同的范例 Apr 18, 2025 am 12:26 AM

PHP主要是过程式编程,但也支持面向对象编程(OOP);Python支持多种范式,包括OOP、函数式和过程式编程。PHP适合web开发,Python适用于多种应用,如数据分析和机器学习。

See all articles