Chinaunix首页 | 论坛 | 博客
  • 博客访问: 53689
  • 博文数量: 48
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 260
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-12 11:48
文章分类
文章存档

2016年(48)

我的朋友

分类: PHP

2016-10-11 11:48:23

WeMall微信商城源码签到插件Sign,用于商城的签到系统,分享了部分比较重要的代码,供技术员学习参考


AdminController.class.php

点击(此处)折叠或打开

  1. find();
  2.         $this->assign("config", $config);

  3.         $record = D(’Addons://Sign/AddonSignRecord’); // 实例化User对象

  4.         $count = $record->count();// 查询满足要求的总记录数
  5.         $Page = new \Think\Page($count, 12);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  6.         $Page->setConfig(’theme’, "
  7. %FIRST%
  8. %UP_PAGE%
  9. %LINK_PAGE%
  10. %DOWN_PAGE%
  11. %END%
  12.  %HEADER% %NOW_PAGE%/%TOTAL_PAGE% 页
  13. ");
  14.         $show = $Page->show();// 分页显示输出
  15.         // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
  16.         $record = $record->limit($Page->firstRow .,. $Page->listRows)->order("id desc")->relation(true)->select();

  17.         $this->assign("record", $record);// 赋值数据集
  18.         $this->assign(’page’, $show);// 赋值分页输出

  19.         $this->display();
  20.     }

  21.     public function addConfig()
  22.     {
  23.         M("AddonSignConfig")->where(array("id" => "1"))->save($_POST);
  24.         $this->success(’修改成功’, ’Admin/Admin/index/addon/Sign’);
  25.     }
  26. }


 IndexController.class.php

点击(此处)折叠或打开

  1. appUrl = "http://" . I("server.HTTP_HOST");
  2.     }

  3.     public function init()
  4.     {
  5.         return R("App/Common/init");
  6.     }

  7.     public function oauthRegister($wxuser)
  8.     {
  9.         return R("App/Common/oauthRegister", array($wxuser));
  10.     }

  11.     public function index()
  12.     {

  13.         $user = R("App/Public/oauthLogin");

  14.         // $user = M("User")->where(array("uid" => session("userUid")))->find();
  15.         $contact = M("Contact")->where(array("user_id" => $user["id"]))->find();
  16.         if ($contact) {
  17.             $this->assign("contact", $contact);
  18.         }
  19.         $config = M("Config")->find();
  20.         $this->assign("config", $config);
  21.         $this->assign("user", $user);

  22.         $product = M("addonScore")->select();
  23.         $this->assign("product", $product);
  24.         $this->display();
  25.     }

  26.     public function addOrder()
  27.     {
  28.         // $user = M("User")->where(array("uid" => session("userUid")))->find();
  29.         $user = M("User")->where(array("id" => session("userId")))->find();
  30.         $score = floatval($user["score"]) - floatval($_POST["score"]);
  31.         if ($score >= 0) {
  32.             M("User")->where(array("id" => $user["id"]))->save(array("score" => $score));
  33.         } else {
  34.             return;
  35.         }

  36.         $userHas = M("Contact")->where(array("user_id" => session("userId")))->find();
  37.         if ($userHas) {
  38.             $contact ["id"] = $userHas ["id"];
  39.             $contact ["user_id"] = session("userId");
  40.             $contact ["name"] = $_POST ["name"];
  41.             $contact ["phone"] = $_POST ["phone"];
  42.             $contact ["address"] = $_POST ["address"];
  43.             M("Contact")->save($contact);
  44.         } else {
  45.             $contact ["user_id"] = session("userId");
  46.             $contact ["name"] = $_POST ["name"];
  47.             $contact ["city"] = "";
  48.             $contact ["area"] = "";
  49.             $contact ["phone"] = $_POST ["phone"];
  50.             $contact ["address"] = $_POST ["address"];
  51.             M("Contact")->add($contact);
  52.         }
  53.         $userHas = M("Contact")->where(array("user_id" => session("userId")))->find();
  54.         $contact_id = $userHas["id"];

  55.         $data ["user_id"] = session("userId");
  56.         $data ["contact_id"] = $contact_id;
  57.         $data ["orderid"] = date("ymdhis") . mt_rand(1, 9);
  58.         $data ["totalscore"] = $_POST["score"];
  59.         $data ["status"] = 0;
  60.         $data ["note"] = $_POST ["note"];
  61.         $data ["time"] = date("Y-m-d H:i:s");
  62.         $data ["score_id"] = $_POST ["id"];
  63.         $result = M("AddonScoreOrder")->add($data);
  64.         if ($result) {
  65.             $this->ajaxReturn($result);
  66.         }
  67.     }
  68.     public function sign(){
  69.         $today = date("Y-m-d");
  70.         $where["time"] = array("like", $today . "%");
  71.         $where["user_id"] = session("userId");
  72.         $record = D("Addons://Sign/AddonSignRecord")->where($where)->find();
  73.         if ($record) {
  74.             $this->ajaxReturn(array("status" => 0));
  75.             return;
  76.         }

  77.         $user = M("User")->where(array("id" => session("userId")))->find();

  78.         $count = 0;
  79.         do{
  80.             $count++;
  81.             $yesterday = date("Y-m-d", strtotime("-$count day"));
  82.             $where["time"] = array("like", $yesterday . "%");
  83.             $record = D("AddonSignRecord")->where($where)->find();
  84.         } while ($record);
  85.         $continue_sign = $count-1;

  86.         $config = M("AddonSignConfig")->find();
  87.         if ($config) {
  88.             $addScore = floatval($continue_sign) * floatval($config["continue_sign"]) + floatval($config["first_sign"]);
  89.             M("AddonSignRecord")->add(array("user_id" => session("userId"), "score" => $addScore));

  90.             $score = floatval($user["score"]) + $addScore;
  91.             M("User")->where(array("id" => $user["id"]))->save(array("score" => $score));
  92.             $this->ajaxReturn(array("status" => 1, "score" => $addScore));
  93.         }
  94.     }

  95. }


Index_index.html

点击(此处)折叠或打开

  1. <!DOCTYPE html>
  2. <html lang="zh-cn">
  3. <head>
  4.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5.     <meta charset="utf-8">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  7.     <title>签到系统</title>
  8.     <meta name="format-detection" content="telephone=no, address=no">
  9.     <meta name="apple-mobile-web-app-capable" content="yes">
  10.     <!-- apple devices fullscreen -->
  11.     <meta name="apple-touch-fullscreen" content="yes">
  12.     <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  13.     <link href="__CSS__/bootstrap.min.css" rel="stylesheet">
  14.     <link href="__CSS__/font-awesome.min.css" rel="stylesheet">
  15.     <link href="__CSS__/animate.css" rel="stylesheet">
  16.     <link href="__CSS__/common.css" rel="stylesheet">
  17.     <link href="__CSS__/sign.css" rel="stylesheet">
  18. </head>
  19. <body>
  20. <div class="container container-fill">
  21.     <div class="pcenter-main">
  22.         <div class="head">
  23.             <div class="pdetail">
  24.                 <div class="img-circle"><img src="{$user.avater}"></div>
  25.                 <div class="pull-left">
  26.                     <span class="name">{$user.username}</span>
  27.                     <span class="type">会员ID: {$user.id}</span>
  28.                 </div>
  29.             </div>
  30.             <div class="head-nav">
  31.                 <a class="head-nav-list">积分<span id="myscore">{$user.score}</span></a>
  32.                 <a class="head-nav-list"><span class="pull-center"><span class="btn btn-default" onclick="signIn(this)"
  33.                                                                          style="color: #fff;background-color: transparent;border-color: #fff;">今日签到</span></span></a>
  34.             </div>
  35.         </div>
  36.     </div>
  37.     <div class="scroll-container">
  38.         <div class="wrapper">
  39.             <ul class="list-group">
  40.                 <volist name="product" id="product">
  41.                     <li class="list-group-item">
  42.                         <div class="con">
  43.                             <div class="list-hd">
  44.                                 <h5>{$product.name}</h5>
  45.                             </div>
  46.                             <div class="list-con">
  47.                                 <img src="__PUBLIC__/Uploads/{$product.image}">
  48.                             </div>
  49.                             <div class="list-ft">
  50.                                 <div class="pull-left" style="margin-left: 12px;">积分:<b>{$product.score}</b></div>
  51.                                 <div class="pull-right btn btn-default" style="margin-right: 12px;"><a
  52.                                         onclick="doCart(this , '{$product.score}' , '{$product.id}')" style="color: black;">立即兑换</a>
  53.                                 </div>
  54.                             </div>
  55.                         </div>
  56.                     </li>
  57.                 </volist>
  58.             </ul>
  59.         </div>
  60.     </div>
  61.     <div id="cover2" style="display: none; position: fixed; width: 100%; height: 100%;"></div>
  62.     <div class="tc_c2" id="join_box"
  63.          style="left: 0px; bottom: 0px; z-index: 3000; position: fixed; display: none;width: 100%;">
  64.         <div class="join_box_Xq_out" style="max-height: 641px;">
  65.             <div class="tc_c_close">
  66.                 <div><img title="关闭" onclick="hidePop(this);" ontouchstart="" src="__IMG__/share_qr_close3.png"></div>
  67.             </div>
  68.             <div class="join_box_Xq">
  69.                 <ul id="ul_join_property" class="pop_massage">
  70.                     <li>
  71.                         <div class="optionsName">姓名</div>
  72.                         <div class="inpoutK">
  73.                             <input value="{$contact.name}" type="text" class="font0" name="name" id="name">
  74.                         </div>
  75.                     </li>
  76.                     <li>
  77.                         <div class="optionsName">手机</div>
  78.                         <div class="inpoutK">
  79.                             <input value="{$contact.phone}" type="text" class="font0" name="phone" id="phone">
  80.                         </div>
  81.                     </li>
  82.                     <li>
  83.                         <div class="optionsName">地址</div>
  84.                         <div class="inpoutK">
  85.                             <input value="{$contact.address}" type="text" class="font0" name="address" id="address">
  86.                         </div>
  87.                     </li>
  88.                     <li>
  89.                         <div class="optionsName">备注</div>
  90.                         <div class="inpoutK">
  91.                             <input value="" type="text" class="font0" name="note" id="note">
  92.                         </div>
  93.                     </li>
  94.                 </ul>
  95.             </div>
  96.   
  97.             <div class="tc_c_btn2" ontouchstart="" id="xdBtn">
  98.                 <a title="返回" class="fanHui" href="javascript:void(0);" ontouchstart="" onclick="_joinBox._prev()"
  99.                    style="display: none;"></a>
  100.   
  101.                 <div class="join_Btn">
  102.                     <input id="input_submit" class="blueBtn" type="submit" value="我要报名"
  103.                            style="display: none; width: 100%;">
  104.                     <a style="width: 100%;" id="a_submit" class="blueBtn font02" href="javascript:void(0);"
  105.                        onclick="submitOrder()">提交</a>
  106.                 </div>
  107.             </div>
  108.   
  109.         </div>
  110.     </div>
  111.   
  112.     <div id="alert" class="alert" style="display: none; top: 165px; left: 42.5px;text-align: center;">
  113.         <div id="alert_title">温馨提示</div>
  114.         <div id="alert_text"></div>
  115.         <div id="alert_button"><button id="alert_button_ok" class="button_3" ontouchstart="" onclick="hideAlert()">知道了</button></div>
  116.         <div id="alert_cancel" class="alert_cancel" ontouchstart="" onclick=""></div>
  117.     </div>
  118. </div>
  119. <script type="text/javascript" src="__JS__/jquery.min.js"></script>
  120. <script type="text/javascript" src="__JS__/bootstrap.min.js"></script>
  121. <script>
  122.     var id = 0;
  123.     var score = 0;
  124.     function hidePop(){
  125.         $("#join_box").hide();
  126.         $("#cover2").hide();
  127.     }
  128.     function showPop(){
  129.         $("#join_box").show();
  130.         $("#cover2").show();
  131.     }
  132.     function doCart(obj , scoreIn ,idIn){
  133.         if(parseFloat(scoreIn) > parseFloat($('#myscore').html())){
  134.             alert("积分不足!");
  135.             return;
  136.         }
  137.         id = idIn;
  138.         score = scoreIn;
  139.         showPop();
  140.     }
  141.   
  142.     var signFlag = true;
  143.     function signIn(obj){
  144.         $.ajax({
  145.             type: "post",
  146.             url: "{:u_addons('Sign://Index/sign')}",
  147.             data: {
  148.   
  149.             },
  150.             success: function (data) {
  151.                 if(data){
  152.                     var json = eval(data)
  153.                     $("#alert").show();
  154.                     if (typeof json.score != "undefined") {
  155.                         $("#alert_text").html("恭喜您获得"+json.score+"积分");
  156.                     }else{
  157.                         $("#alert_text").html("对不起,您已签到!");
  158.                     }
  159.   
  160.                 }
  161.             },
  162.             beforeSend: function () {
  163.   
  164.             },
  165.             complete: function () {
  166.             }
  167.   
  168.         });
  169.   
  170.         // $("#alert").show();
  171.     }
  172.     function hideAlert(){
  173.         $("#alert").hide();
  174.         location.reload();
  175.     }
  176.     var submitFlag = true;
  177.     function submitOrder(){
  178.         if (submitFlag == false) {
  179.             alert("请不要重复操作!");
  180.             return;
  181.         };
  182.         var name = $('#name').val();
  183.         var phone = $('#phone').val();
  184.         var address = $('#address').val();
  185.         var note = $('#note').val();
  186.   
  187.         if (name.length == 0 || phone.length == 0 || address.length == 0) {
  188.             alert("请核对输入的信息!");
  189.             return;
  190.         };
  191.         submitFlag = false;
  192.   
  193.         $.ajax({
  194.             type: "post",
  195.             url: "{:u_addons('Sign://Index/addOrder')}",
  196.             data: {
  197.                 name: name,
  198.                 phone: phone,
  199.                 id: id,
  200.                 score: score,
  201.                 address: address,
  202.                 note: note
  203.             },
  204.             success: function (data) {
  205.                 if(data){
  206.                     hidePop();
  207.                     alert("商品兑换成功!");
  208.                     location.reload();
  209.                 }
  210.             },
  211.             beforeSend: function () {
  212.   
  213.             },
  214.             complete: function () {
  215.             }
  216.   
  217.         });
  218.     }
  219. </script>
  220. </body>
  221. </html>


 Admin_index.html

点击(此处)折叠或打开

  1. <section class="content-header">
  2.     <h1>
  3.         签到管理
  4.         <small></small>
  5.     </h1>
  6. </section>
  7. <!-- Main content -->
  8. <section class="content">
  9.     <div class="row">
  10.         <!-- /.col -->
  11.         <div class="col-md-12">
  12.             <div class="box box-danger">
  13.                 <div class="box-header with-border">
  14.                     <h3 class="box-title">签到管理</h3>
  15.                     <!-- /.box-tools -->
  16.                 </div>
  17.                 <!-- /.box-header -->
  18.                 <div class="box-body no-padding">
  19.                     <div class="heading tabs" style="background: transparent;">
  20.                         <ul class="nav nav-tabs pull-left" data-tabs="tabs" id="tabs">
  21.                             <li class="active">
  22.                                 <a data-toggle="tab" href="#tab1"><i class="icon-comments"></i><span>签到设置</span></a>
  23.                             </li>
  24.                             <li class="">
  25.                                 <a data-toggle="tab" href="#tab2"><i class="icon-user"></i><span>签到记录</span></a>
  26.                             </li>
  27.                         </ul>
  28.                     </div>
  29.                     <div class="tab-content padded" id="my-tab-content"style="margin-top: 60px;">
  30.                         <div class="tab-pane active" id="tab1">
  31.                             <!-- <h3>签到设置</h3> -->
  32.   
  33.                             <p>
  34.                             <form action="{:u_addons('Sign://Admin/Admin/addConfig')}" id="myForm" method="post"
  35.                                   onsubmit="return false;" class="form-horizontal">
  36.                                 <div class="form-group">
  37.                                     <label class="control-label col-md-2">签到名称</label>
  38.   
  39.                                     <div class="col-md-7">
  40.                                         <input class="form-control" placeholder="" value="{$config.name}"
  41.                                                name="name" type="text">
  42.                                     </div>
  43.                                 </div>
  44.                                 <div class="form-group">
  45.                                     <label class="control-label col-md-2">首次签到赠送积分</label>
  46.   
  47.                                     <div class="col-md-7">
  48.                                         <input class="form-control" placeholder="" value="{$config.first_sign}"
  49.                                                name="first_sign" type="text">
  50.                                     </div>
  51.                                 </div>
  52.                                 <div class="form-group">
  53.                                     <label class="control-label col-md-2">连续签到增长积分</label>
  54.   
  55.                                     <div class="col-md-7">
  56.                                         <input class="form-control" placeholder=""
  57.                                                value="{$config.continue_sign}" name="continue_sign" type="text">
  58.                                     </div>
  59.                                 </div>
  60.                                <!-- <div class="form-group">
  61.                                     <label class="control-label col-md-2">最大连续签到天数</label>
  62.   
  63.                                     <div class="col-md-7">
  64.                                         <input class="form-control" placeholder="" value="{$config.max_sign}"
  65.                                                name="max_sign" type="text">
  66.                                     </div>
  67.                                 </div> -->
  68.                                 <div class="form-group">
  69.                                     <label class="control-label col-md-2"></label>
  70.   
  71.                                     <div class="col-md-7">
  72.                                         <button class="btn btn-primary"
  73.                                                 onclick="myFormSubmit('{:u_addons(\'Sign://Admin/Admin/index\')}')"
  74.                                                 type="submit">提交
  75.                                         </button>
  76.                                         <button class="btn btn-default-outline">取消</button>
  77.                                     </div>
  78.                                 </div>
  79.                             </form>
  80.                             </p>
  81.                         </div>
  82.                         <div class="tab-pane" id="tab2">
  83.                             <!-- <h3>签到记录</h3> -->
  84.   
  85.                             <p>
  86.   
  87.                             <div class="widget-content padded clearfix">
  88.                                 <table class="table table-hover">
  89.                                     <thead>
  90.                                     <th class="check-header hidden-xs">
  91.                                         <label><input id="checkAll" name="checkAll"
  92.                                                       type="checkbox"><span></span></label>
  93.                                     </th>
  94.                                     <th>
  95.                                         ID
  96.                                     </th>
  97.                                     <th>
  98.                                         用户名
  99.                                     </th>
  100.                                     <th class="hidden-xs">
  101.                                         积分
  102.                                     </th>
  103.                                     <th class="hidden-xs">
  104.                                         时间
  105.                                     </th>
  106.                                     </thead>
  107.                                     <tbody>
  108.                                     <volist name="record" id="record">
  109.                                         <tr>
  110.                                             <td class="check hidden-xs">
  111.                                                 <label><input name="optionsRadios1" type="checkbox"
  112.                                                               value="option1"><span></span></label>
  113.                                             </td>
  114.                                             <td>
  115.                                                 {$record.id}
  116.                                             </td>
  117.                                             <td>
  118.                                                 {$record.username}
  119.                                             </td>
  120.                                             <td class="hidden-xs">
  121.                                                 {$record.score}
  122.                                             </td>
  123.                                             <td class="hidden-xs">
  124.                                                 {$record.time}
  125.                                             </td>
  126.                                         </tr>
  127.                                     </volist>
  128.                                     </tbody>
  129.                                 </table>
  130.                                 {$page}
  131.                             </div>
  132.                             </p>
  133.                         </div>
  134.                     </div>
  135.   
  136.                 </div>
  137.             </div>
  138.             <!-- /. box -->
  139.         </div>
  140.         <!-- /.col -->
  141.     </div>
  142. </section>

代码来源: www.wemallshop.com

阅读(737) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:WeMall微商城源码投票插件Vote的主要源码

给主人留下些什么吧!~~