WeMall微信商城源码投票插件Vote,用于商城的签到系统,分享了部分比较重要的代码,供技术员学习参考
AdminController.class.php
<?php namespace Addons\Vote\Controller; class AdminController extends InitController { public function __construct() { parent::__construct(); } public function index() { $config = M("AddonVoteConfig")->find(); $this->assign("config", $config); $record = D(’Addons://Vote/AddonVoteRecord’); // 实例化User对象 $count = $record->count();// 查询满足要求的总记录数 $Page = new \Think\Page($count, 12);// 实例化分页类 传入总记录数和每页显示的记录数(25) $Page->setConfig(’theme’, "<div class=’widget-content padded text-center’><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("AddonVoteConfig")->where(array("id" => "1"))->save($_POST); $this->success(’设置成功’, ’Admin/Admin/index/addon/Vote’); } }
IndexController.class.php
<?php /** * Created by PhpStorm. * User: heqing * Date: 15/7/30 * Time: 09:40 */ namespace Addons\Vote\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"); // if (!session("userUid")) { // $weObj = $this->init(); // $token = $weObj->getOauthAccessToken(); // if (!$token) { // $weObj = $this->init(); // $url = $weObj->getOauthRedirect($this->appUrl . u_addons(’Vote://App/Index/index’)); // header("location: $url"); // return; // } else { // $wxuser = $weObj->getOauthUserinfo($token["access_token"], $token["openid"]); // session("userUid", $wxuser["openid"]); // $this->oauthRegister($wxuser); // } // } $user = M("User")->where(array("uid" => session("userUid")))->find(); $config = M("AddonVoteConfig")->find(); $this->assign("config", $config); $this->assign("user", $user); M("AddonVoteConfig")->where(array("id"=>$config["id"]))->setInc("visiter_num"); $this->display(); } public function vote() { $username=M(’User’)->where(array("id"=>session("userId")))->find(); M("AddonVoteRecord")->add(array("user_id"=>session("userId"),"username"=>$username[’username’])); M("AddonVoteConfig")->where(array("id"=>I("get.id")))->setInc("vote_num"); } }
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"> <script type="text/javascript" src="__JS__/jquery.min.js"></script> <script type="text/javascript" src="__JS__/bootstrap.min.js"></script> </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" href="">累计投票<span>{$config.vote_num}</span></a> <a class="head-nav-list" href="">访问量<span>{$config.visiter_num}</span></a> </div> </div> </div> <div class="scroll-container"> <div class="wrapper"> <ul class="list-group"> <li class="list-group-item" style="padding: 0px 0px;border-bottom: 1px solid #ccc;"> <div class="con"> <div class="list-hd"> <h5>项目:</h5><span>{$config.name}</span> </div> </div> </li> <li class="list-group-item" style="padding: 1px 0px;border-bottom: 1px solid #ccc;"> <div class="con"> <div class="list-hd"> <h5>时间:</h5><span>{$config.activity_time}</span> </div> </div> </li> <li class="list-group-item" style="padding: 0px;"> <div class="con"> <div class="list-hd"> <h5>投票介绍:</h5><span>{$config.about}</span> </div> </div> </li> </ul> </div> </div> <ul class="nav nav-bardown nav-justified" style="z-index:10;"> <li><a href="javascript:openUrl(’{:u_addons(\’Vote://Index/vote\’,array(\’id\’=>$config[\’id\’]))}’)"><span class="btn btn-default" style="border-radius: 50px;padding: 10px 30px;">点击投票</span></a></li> </ul> </div> <script type="text/javascript"> function openUrl(url){ $.get(url , function (data) { alert(’投票成功!’); location.reload(); }); } </script> </body> </html>
Admin_index.html
<section class="content-header"> <h1> 投票管理 <small></small> </h1> </section> <section class="content"> <div class="row"> <div class="col-md-12"> <div class="box box-danger"> <div class="box-header with-border"> <h3 class="box-title">大转盘设置</h3> <!-- /.box-tools --> </div> <div class="box-body no-padding"> <div class="mailbox-controls"> <div class="btn-group"> <a data-toggle="tab" href="#tab1" class="btn btn-danger "><i class="icon-comments"></i>投票设置</a> </div> <div class="btn-group"> <a data-toggle="tab" href="#tab2" class="btn btn-danger "><i class="icon-user"></i>投票记录</a> </div> <div class="tab-content padded" id="my-tab-content"> <div class="tab-pane active" id="tab1"> <p> <form action="{:u_addons(’Vote://Admin/Admin/addConfig’)}" id="myForm" method="post" onsubmit="return false;" class="form-horizontal"> <div class="form-group"> <label class="control-label col-md-2">投票名称</label> <div style="margin-top:50px" class="col-md-7"> <input class="form-control" placeholder="" value="{$config.name}" name="name" type="text"> </div> </div> <div class="form-group"> <label class="control-label col-md-2">活动时间</label> <div class="col-md-7"> <input class="form-control" placeholder="" value="{$config.activity_time}" name="activity_time" type="text"> </div> </div> <!-- <div class="form-group"> <label class="control-label col-md-2">活动说明</label> <div class="col-md-7"> <!style给定宽度可以影响编辑器的最终宽度 <script type="text/plain" id="myEditor" style="width:100%;height:340px;"></script> </div> </div> --> <div class="form-group"> <label class="control-label col-md-2">活动说明</label> <div class="col-md-7"> <!--style给定宽度可以影响编辑器的最终宽度--> <script id="UEditor" name="about" type="text/plain" style="height:340px;"> {$config.about} </script> </div> </div> <div class="form-group"> <label class="control-label col-md-2"></label> <div class="col-md-7"> <button class="btn btn-danger" onclick="myFormSubmit(’{:u_addons(\’Vote://Admin/Admin/index\’)}’)" type="submit">提交 </button> <button class="btn btn-default-outline">取消</button> </div> </div> </form> </p> </div> <div class="tab-pane" id="tab2"> <p> <div class="widget-content padded clearfix"> <table class="table table-hover"> <thead> <th class="check-header hidden-xs"> <label><input id="checkAll" name="checkAll" type="checkbox"><span></span></label> </th> <th> ID </th> <th> 用户名 </th> <th class="hidden-xs"> 时间 </th> </thead> <tbody> <volist name="record" id="record"> <tr> <td class="check hidden-xs"> <label><input name="optionsRadios1" type="checkbox" value="option1"><span></span></label> </td> <td> {$record.id} </td> <td> {$record.username} </td> <td class="hidden-xs"> {$record.time} </td> </tr> </volist> </tbody> </table> <div class="pull-right"> {$page} </div> </div> </p> </div> </div> </div> </div> </div> </div> </div> </section> <!-- <include file="Common:umeditor"/> --> <script type="text/javascript"> // //实例化编辑器 // var um = UM.getEditor(’myEditor’ , { // textarea : ’about’ // }); // function setFocus() { // UM.getEditor(’myEditor’).focus(); // } $(function() { //实例化编辑器异步载入 var editor = new UE.ui.Editor(); editor.render("UEditor"); }); if (’{$config}’) { $(’select[name="status"]’).val(’{$config.status}’); $(’select[name="everyday"]’).val(’{$config.everyday}’); // UE.getEditor(’myEditor’).setContent(’{$config.activity_explain}’); } </script> <!-- <script> if (’{$config}’) { $(’select[name="status"]’).val(’{$config.status}’); $(’select[name="everyday"]’).val(’{$config.everyday}’); UM.getEditor(’myEditor’).setContent(’{$config.about}’); } </script> -->
wemall官网网址: www.wemallshop.com
回复 (0)
微信扫码 立即评论