博客> WeMall微信商城签到插件Sign的主要源码
WeMall微信商城签到插件Sign的主要源码
2019-07-16 15:27 评论:0 阅读:668 wemallshop
html php 商城源码

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

AdminController.class.php

<?php

namespace Addons\Sign\Controller;

class AdminController extends InitController
{

    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $config = M("AddonSignConfig")->find();
        $this->assign("config", $config);

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

        $count = $record->count();// 查询满足要求的总记录数
        $Page = new \Think\Page($count, 12);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $Page->setConfig(’theme’, "<div class=’widget-content><ul class=’pagination’></li><li>%FIRST%</li><li>%UP_PAGE%</li><li>%LINK_PAGE%</li><li>%DOWN_PAGE%</li><li>%END%</li><li><a> %HEADER%  %NOW_PAGE%/%TOTAL_PAGE% 页</a></ul></div>");
        $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

&lt;?php
namespace Addons\Sign\Controller;

class IndexController extends InitController
{
    public $appUrl = "";
    public function __construct()
    {
        parent::__construct();
        $this->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>
&lt;html lang="zh-cn"&gt;
&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"&gt;
    &lt;title&gt;签到系统&lt;/title&gt;
    &lt;meta name="format-detection" content="telephone=no, address=no"&gt;
    &lt;meta name="apple-mobile-web-app-capable" content="yes"&gt;
    &lt;!-- apple devices fullscreen --&gt;
    &lt;meta name="apple-touch-fullscreen" content="yes"&gt;
    &lt;meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"&gt;
    &lt;link href="__CSS__/bootstrap.min.css" rel="stylesheet"&gt;
    &lt;link href="__CSS__/font-awesome.min.css" rel="stylesheet"&gt;
    &lt;link href="__CSS__/animate.css" rel="stylesheet"&gt;
    &lt;link href="__CSS__/common.css" rel="stylesheet"&gt;
    &lt;link href="__CSS__/sign.css" rel="stylesheet"&gt;
&lt;/head&gt;
&lt;body&gt;
<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" xss=removed xss=removed>今日签到</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" xss=removed>积分:<b>{$product.score}</b></div>
                                <div class="pull-right btn btn-default" xss=removed><a xss=removed xss=removed>立即兑换</a>
                                </div>
                            </div>
                        </div>
                    </li>
                </volist>
            </ul>
        </div>
    </div>
    <div id="cover2" xss=removed></div>
    <div class="tc_c2" id="join_box" xss=removed>
        <div class="join_box_Xq_out" xss=removed>
            <div class="tc_c_close">
                <div><img title="关闭" xss=removed xss=removed 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">
                            &lt;input value="{$contact.name}" type="text" class="font0" name="name" id="name"&gt;
                        </div>
                    </li>
                    <li>
                        <div class="optionsName">手机</div>
                        <div class="inpoutK">
                            &lt;input value="{$contact.phone}" type="text" class="font0" name="phone" id="phone"&gt;
                        </div>
                    </li>
                    <li>
                        <div class="optionsName">地址</div>
                        <div class="inpoutK">
                            &lt;input value="{$contact.address}" type="text" class="font0" name="address" id="address"&gt;
                        </div>
                    </li>
                    <li>
                        <div class="optionsName">备注</div>
                        <div class="inpoutK">
                            &lt;input value="" type="text" class="font0" name="note" id="note"&gt;
                        </div>
                    </li>
                </ul>
            </div>

            <div class="tc_c_btn2" xss=removed id="xdBtn">
                <a title="返回" class="fanHui" href="[removed]void(0);" xss=removed xss=removed xss=removed></a>

                <div class="join_Btn">
                    &lt;input id="input_submit" class="blueBtn" type="submit" value="我要报名"
                           style="display: none; width: 100%;"&gt;
                    <a xss=removed id="a_submit" class="blueBtn font02" href="[removed]void(0);" xss=removed>提交</a>
                </div>
            </div>

        </div>
    </div>

    <div id="alert" class="alert" xss=removed>
        <div id="alert_title">温馨提示</div>
        <div id="alert_text"></div>
        <div id="alert_button">&lt;button id="alert_button_ok" class="button_3" ontouchstart="" onclick="hideAlert&#40;&#41;"&gt;知道了&lt;/button&gt;</div>
        <div id="alert_cancel" class="alert_cancel" xss=removed xss=removed></div>
    </div>
</div>
[removed][removed]
[removed][removed]
[removed]
    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&#40;"积分不足!"&#41;;
            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&#40;data&#41;
                    $("#alert").show();
                    if (typeof json.score != "undefined") {
                        $("#alert_text").html("恭喜您获得"+json.score+"积分");
                    }else{
                        $("#alert_text").html("对不起,您已签到!");
                    }

                }
            },
            beforeSend: function () {

            },
            complete: function () {
            }

        });

        // $("#alert").show();
    }
    function hideAlert&#40;&#41;{
        $("#alert").hide();
        location.reload();
    }
    var submitFlag = true;
    function submitOrder(){
        if (submitFlag == false) {
            alert&#40;"请不要重复操作!"&#41;;
            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&#40;"请核对输入的信息!"&#41;;
            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&#40;"商品兑换成功!"&#41;;
                    location.reload();
                }
            },
            beforeSend: function () {

            },
            complete: function () {
            }

        });
    }
[removed]
&lt;/body&gt;
&lt;/html&gt;

Admin_index.html

<section class="content-header">
    <h1>
        签到管理
        <small></small>
    </h1>
</section>
&lt;!-- Main content --&gt;
<section class="content">
    <div class="row">
        &lt;!-- /.col --&gt;
        <div class="col-md-12">
            <div class="box box-danger">
                <div class="box-header with-border">
                    <h3 class="box-title">签到管理</h3>
                    &lt;!-- /.box-tools --&gt;
                </div>
                &lt;!-- /.box-header --&gt;
                <div class="box-body no-padding">
                    <div class="heading tabs" xss=removed>
                        <ul class="nav nav-tabs pull-left" data-tabs="tabs" id="tabs">
                            <li class="active">
                                <a data-toggle="tab" href="#tab1"><i class="icon-comments"></i><span>签到设置</span></a>
                            </li>
                            <li class="">
                                <a data-toggle="tab" href="#tab2"><i class="icon-user"></i><span>签到记录</span></a>
                            </li>
                        </ul>
                    </div>
                    <div class="tab-content padded" id="my-tab-content" xss=removed>
                        <div class="tab-pane active" id="tab1">
                            &lt;!-- <h3>签到设置</h3> --&gt;

                            <p>
                            &lt;form action="{:u_addons(’Sign://Admin/Admin/addConfig’)}" id="myForm" method="post"
                                  onsubmit="return false;" class="form-horizontal"&gt;
                                <div class="form-group">
                                    <label class="control-label col-md-2">签到名称</label>

                                    <div class="col-md-7">
                                        &lt;input class="form-control" placeholder="" value="{$config.name}"
                                               name="name" type="text"&gt;
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="control-label col-md-2">首次签到赠送积分</label>

                                    <div class="col-md-7">
                                        &lt;input class="form-control" placeholder="" value="{$config.first_sign}"
                                               name="first_sign" type="text"&gt;
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="control-label col-md-2">连续签到增长积分</label>

                                    <div class="col-md-7">
                                        &lt;input class="form-control" placeholder=""
                                               value="{$config.continue_sign}" name="continue_sign" type="text"&gt;
                                    </div>
                                </div>
                               &lt;!--  <div class="form-group">
                                    <label class="control-label col-md-2">最大连续签到天数</label>

                                    <div class="col-md-7">
                                        &lt;input class="form-control" placeholder="" value="{$config.max_sign}"
                                               name="max_sign" type="text"&gt;
                                    </div>
                                </div> --&gt;
                                <div class="form-group">
                                    <label class="control-label col-md-2"></label>

                                    <div class="col-md-7">
                                        &lt;button class="btn btn-primary"
                                                onclick="myFormSubmit(’{:u_addons(\\’Sign://Admin/Admin/index\\’)}’)"
                                                type="submit"&gt;提交
                                        &lt;/button&gt;
                                        &lt;button class="btn btn-default-outline"&gt;取消&lt;/button&gt;
                                    </div>
                                </div>
                            &lt;/form&gt;
                            </p>
                        </div>
                        <div class="tab-pane" id="tab2">
                            &lt;!-- <h3>签到记录</h3> --&gt;

                            <p>

                            <div class="widget-content padded clearfix">
                                <table class="table table-hover">
                                    <thead>
                                    <th class="check-header hidden-xs">
                                        <label>&lt;input id="checkAll" name="checkAll"
                                                      type="checkbox"&gt;<span></span></label>
                                    </th>
                                    <th>
                                        ID
                                    </th>
                                    <th>
                                        用户名
                                    </th>
                                    <th class="hidden-xs">
                                        积分
                                    </th>
                                    <th class="hidden-xs">
                                        时间
                                    </th>
                                    </thead>
                                    <tbody>
                                    <volist name="record" id="record">
                                        <tr>
                                            <td class="check hidden-xs">
                                                <label>&lt;input name="optionsRadios1" type="checkbox"
                                                              value="option1"&gt;<span></span></label>
                                            </td>
                                            <td>
                                                {$record.id}
                                            </td>
                                            <td>
                                                {$record.username}
                                            </td>
                                            <td class="hidden-xs">
                                                {$record.score}
                                            </td>
                                            <td class="hidden-xs">
                                                {$record.time}
                                            </td>
                                        </tr>
                                    </volist>
                                    </tbody>
                                </table>
                                {$page}
                            </div>
                            </p>
                        </div>
                    </div>                    

                </div>
            </div>
            &lt;!-- /. box --&gt;
        </div>
        &lt;!-- /.col --&gt;
    </div>
</section>

wemall官网网址: www.wemallshop.com

收藏
0
sina weixin mail 回到顶部