WeMall微信商城源码签到插件Sign,用于商城的签到系统,分享了部分比较重要的代码,供技术员学习参考
AdminController.class.php
- find();
- $this->assign("config", $config);
- $record = D(’Addons://Sign/AddonSignRecord’); // 实例化User对象
- $count = $record->count();// 查询满足要求的总记录数
- $Page = new \Think\Page($count, 12);// 实例化分页类 传入总记录数和每页显示的记录数(25)
- $Page->setConfig(’theme’, "
- %FIRST%
- %UP_PAGE%
- %LINK_PAGE%
- %DOWN_PAGE%
- %END%
- %HEADER% %NOW_PAGE%/%TOTAL_PAGE% 页
- ");
- $show = $Page->show();// 分页显示输出
- // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
- $record = $record->limit($Page->firstRow . ’,’ . $Page->listRows)->order("id desc")->relation(true)->select();
- $this->assign("record", $record);// 赋值数据集
- $this->assign(’page’, $show);// 赋值分页输出
- $this->display();
- }
- public function addConfig()
- {
- M("AddonSignConfig")->where(array("id" => "1"))->save($_POST);
- $this->success(’修改成功’, ’Admin/Admin/index/addon/Sign’);
- }
- }
IndexController.class.php
- appUrl = "http://" . I("server.HTTP_HOST");
- }
- public function init()
- {
- return R("App/Common/init");
- }
- public function oauthRegister($wxuser)
- {
- return R("App/Common/oauthRegister", array($wxuser));
- }
- public function index()
- {
- $user = R("App/Public/oauthLogin");
- // $user = M("User")->where(array("uid" => session("userUid")))->find();
- $contact = M("Contact")->where(array("user_id" => $user["id"]))->find();
- if ($contact) {
- $this->assign("contact", $contact);
- }
- $config = M("Config")->find();
- $this->assign("config", $config);
- $this->assign("user", $user);
- $product = M("addonScore")->select();
- $this->assign("product", $product);
- $this->display();
- }
- public function addOrder()
- {
- // $user = M("User")->where(array("uid" => session("userUid")))->find();
- $user = M("User")->where(array("id" => session("userId")))->find();
- $score = floatval($user["score"]) - floatval($_POST["score"]);
- if ($score >= 0) {
- M("User")->where(array("id" => $user["id"]))->save(array("score" => $score));
- } else {
- return;
- }
- $userHas = M("Contact")->where(array("user_id" => session("userId")))->find();
- if ($userHas) {
- $contact ["id"] = $userHas ["id"];
- $contact ["user_id"] = session("userId");
- $contact ["name"] = $_POST ["name"];
- $contact ["phone"] = $_POST ["phone"];
- $contact ["address"] = $_POST ["address"];
- M("Contact")->save($contact);
- } else {
- $contact ["user_id"] = session("userId");
- $contact ["name"] = $_POST ["name"];
- $contact ["city"] = "";
- $contact ["area"] = "";
- $contact ["phone"] = $_POST ["phone"];
- $contact ["address"] = $_POST ["address"];
- M("Contact")->add($contact);
- }
- $userHas = M("Contact")->where(array("user_id" => session("userId")))->find();
- $contact_id = $userHas["id"];
- $data ["user_id"] = session("userId");
- $data ["contact_id"] = $contact_id;
- $data ["orderid"] = date("ymdhis") . mt_rand(1, 9);
- $data ["totalscore"] = $_POST["score"];
- $data ["status"] = 0;
- $data ["note"] = $_POST ["note"];
- $data ["time"] = date("Y-m-d H:i:s");
- $data ["score_id"] = $_POST ["id"];
- $result = M("AddonScoreOrder")->add($data);
- if ($result) {
- $this->ajaxReturn($result);
- }
- }
- public function sign(){
- $today = date("Y-m-d");
- $where["time"] = array("like", $today . "%");
- $where["user_id"] = session("userId");
- $record = D("Addons://Sign/AddonSignRecord")->where($where)->find();
- if ($record) {
- $this->ajaxReturn(array("status" => 0));
- return;
- }
- $user = M("User")->where(array("id" => session("userId")))->find();
- $count = 0;
- do{
- $count++;
- $yesterday = date("Y-m-d", strtotime("-$count day"));
- $where["time"] = array("like", $yesterday . "%");
- $record = D("AddonSignRecord")->where($where)->find();
- } while ($record);
- $continue_sign = $count-1;
- $config = M("AddonSignConfig")->find();
- if ($config) {
- $addScore = floatval($continue_sign) * floatval($config["continue_sign"]) + floatval($config["first_sign"]);
- M("AddonSignRecord")->add(array("user_id" => session("userId"), "score" => $addScore));
- $score = floatval($user["score"]) + $addScore;
- M("User")->where(array("id" => $user["id"]))->save(array("score" => $score));
- $this->ajaxReturn(array("status" => 1, "score" => $addScore));
- }
- }
- }
Index_index.html
- <!DOCTYPE html>
- <html lang="zh-cn">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
- <title>签到系统</title>
- <meta name="format-detection" content="telephone=no, address=no">
- <meta name="apple-mobile-web-app-capable" content="yes">
- <!-- apple devices fullscreen -->
- <meta name="apple-touch-fullscreen" content="yes">
- <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
- <link href="__CSS__/bootstrap.min.css" rel="stylesheet">
- <link href="__CSS__/font-awesome.min.css" rel="stylesheet">
- <link href="__CSS__/animate.css" rel="stylesheet">
- <link href="__CSS__/common.css" rel="stylesheet">
- <link href="__CSS__/sign.css" rel="stylesheet">
- </head>
- <body>
- <div class="container container-fill">
- <div class="pcenter-main">
- <div class="head">
- <div class="pdetail">
- <div class="img-circle"><img src="{$user.avater}"></div>
- <div class="pull-left">
- <span class="name">{$user.username}</span>
- <span class="type">会员ID: {$user.id}</span>
- </div>
- </div>
- <div class="head-nav">
- <a class="head-nav-list">积分<span id="myscore">{$user.score}</span></a>
- <a class="head-nav-list"><span class="pull-center"><span class="btn btn-default" onclick="signIn(this)"
- style="color: #fff;background-color: transparent;border-color: #fff;">今日签到</span></span></a>
- </div>
- </div>
- </div>
- <div class="scroll-container">
- <div class="wrapper">
- <ul class="list-group">
- <volist name="product" id="product">
- <li class="list-group-item">
- <div class="con">
- <div class="list-hd">
- <h5>{$product.name}</h5>
- </div>
- <div class="list-con">
- <img src="__PUBLIC__/Uploads/{$product.image}">
- </div>
- <div class="list-ft">
- <div class="pull-left" style="margin-left: 12px;">积分:<b>{$product.score}</b></div>
- <div class="pull-right btn btn-default" style="margin-right: 12px;"><a
- onclick="doCart(this , '{$product.score}' , '{$product.id}')" style="color: black;">立即兑换</a>
- </div>
- </div>
- </div>
- </li>
- </volist>
- </ul>
- </div>
- </div>
- <div id="cover2" style="display: none; position: fixed; width: 100%; height: 100%;"></div>
- <div class="tc_c2" id="join_box"
- style="left: 0px; bottom: 0px; z-index: 3000; position: fixed; display: none;width: 100%;">
- <div class="join_box_Xq_out" style="max-height: 641px;">
- <div class="tc_c_close">
- <div><img title="关闭" onclick="hidePop(this);" ontouchstart="" src="__IMG__/share_qr_close3.png"></div>
- </div>
- <div class="join_box_Xq">
- <ul id="ul_join_property" class="pop_massage">
- <li>
- <div class="optionsName">姓名</div>
- <div class="inpoutK">
- <input value="{$contact.name}" type="text" class="font0" name="name" id="name">
- </div>
- </li>
- <li>
- <div class="optionsName">手机</div>
- <div class="inpoutK">
- <input value="{$contact.phone}" type="text" class="font0" name="phone" id="phone">
- </div>
- </li>
- <li>
- <div class="optionsName">地址</div>
- <div class="inpoutK">
- <input value="{$contact.address}" type="text" class="font0" name="address" id="address">
- </div>
- </li>
- <li>
- <div class="optionsName">备注</div>
- <div class="inpoutK">
- <input value="" type="text" class="font0" name="note" id="note">
- </div>
- </li>
- </ul>
- </div>
-
- <div class="tc_c_btn2" ontouchstart="" id="xdBtn">
- <a title="返回" class="fanHui" href="javascript:void(0);" ontouchstart="" onclick="_joinBox._prev()"
- style="display: none;"></a>
-
- <div class="join_Btn">
- <input id="input_submit" class="blueBtn" type="submit" value="我要报名"
- style="display: none; width: 100%;">
- <a style="width: 100%;" id="a_submit" class="blueBtn font02" href="javascript:void(0);"
- onclick="submitOrder()">提交</a>
- </div>
- </div>
-
- </div>
- </div>
-
- <div id="alert" class="alert" style="display: none; top: 165px; left: 42.5px;text-align: center;">
- <div id="alert_title">温馨提示</div>
- <div id="alert_text"></div>
- <div id="alert_button"><button id="alert_button_ok" class="button_3" ontouchstart="" onclick="hideAlert()">知道了</button></div>
- <div id="alert_cancel" class="alert_cancel" ontouchstart="" onclick=""></div>
- </div>
- </div>
- <script type="text/javascript" src="__JS__/jquery.min.js"></script>
- <script type="text/javascript" src="__JS__/bootstrap.min.js"></script>
- <script>
- var id = 0;
- var score = 0;
- function hidePop(){
- $("#join_box").hide();
- $("#cover2").hide();
- }
- function showPop(){
- $("#join_box").show();
- $("#cover2").show();
- }
- function doCart(obj , scoreIn ,idIn){
- if(parseFloat(scoreIn) > parseFloat($('#myscore').html())){
- alert("积分不足!");
- return;
- }
- id = idIn;
- score = scoreIn;
- showPop();
- }
-
- var signFlag = true;
- function signIn(obj){
- $.ajax({
- type: "post",
- url: "{:u_addons('Sign://Index/sign')}",
- data: {
-
- },
- success: function (data) {
- if(data){
- var json = eval(data)
- $("#alert").show();
- if (typeof json.score != "undefined") {
- $("#alert_text").html("恭喜您获得"+json.score+"积分");
- }else{
- $("#alert_text").html("对不起,您已签到!");
- }
-
- }
- },
- beforeSend: function () {
-
- },
- complete: function () {
- }
-
- });
-
- // $("#alert").show();
- }
- function hideAlert(){
- $("#alert").hide();
- location.reload();
- }
- var submitFlag = true;
- function submitOrder(){
- if (submitFlag == false) {
- alert("请不要重复操作!");
- return;
- };
- var name = $('#name').val();
- var phone = $('#phone').val();
- var address = $('#address').val();
- var note = $('#note').val();
-
- if (name.length == 0 || phone.length == 0 || address.length == 0) {
- alert("请核对输入的信息!");
- return;
- };
- submitFlag = false;
-
- $.ajax({
- type: "post",
- url: "{:u_addons('Sign://Index/addOrder')}",
- data: {
- name: name,
- phone: phone,
- id: id,
- score: score,
- address: address,
- note: note
- },
- success: function (data) {
- if(data){
- hidePop();
- alert("商品兑换成功!");
- location.reload();
- }
- },
- beforeSend: function () {
-
- },
- complete: function () {
- }
-
- });
- }
- </script>
- </body>
- </html>
Admin_index.html
代码来源: www.wemallshop.com