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

2016年(48)

我的朋友

分类: PHP

2016-10-12 11:24:51

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

AdminController.class.php


点击(此处)折叠或打开

  1. <?php
  2. namespace Addons\Vote\Controller;

  3. class AdminController extends InitController
  4. {


  5.     public function __construct()
  6.     {
  7.         parent::__construct();
  8.     }

  9.     public function index()
  10.     {
  11.         $config = M("AddonVoteConfig")->find();
  12.         $this->assign("config", $config);

  13.         $record = D(’Addons://Vote/AddonVoteRecord’); // 实例化User对象
  14.         $count = $record->count();// 查询满足要求的总记录数
  15.         $Page = new \Think\Page($count, 12);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  16.         $Page->setConfig(’theme’, "
    "
    );
  17.         $show = $Page->show();// 分页显示输出
  18.         // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
  19.         $record = $record->limit($Page->firstRow .,. $Page->listRows)->order("id desc")->relation(true)->select();

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

  22.         $this->display();
  23.     }

  24.     public function addConfig()
  25.     {
  26.         M("AddonVoteConfig")->where(array("id" => "1"))->save($_POST);
  27.         $this->success(’设置成功’, ’Admin/Admin/index/addon/Vote’);
  28.     }
  29. }

IndexController.class.php


点击(此处)折叠或打开

  1. <?php
  2. namespace Addons\Vote\Controller;

  3. class IndexController extends InitController
  4. {
  5.     public $appUrl = "";
  6.     public function __construct()
  7.     {
  8.         parent::__construct();
  9.         $this->appUrl = "http://" . I("server.HTTP_HOST");
  10.     }

  11.     public function init()
  12.     {
  13.         return R("App/Common/init");
  14.     }

  15.     public function oauthRegister($wxuser)
  16.     {
  17.         return R("App/Common/oauthRegister", array($wxuser));
  18.     }

  19.     public function index()
  20.     {
  21.         $user=R("App/Public/oauthLogin");

  22.         // if (!session("userUid")) {
  23.         // $weObj = $this->init();
  24.         // $token = $weObj->getOauthAccessToken();
  25.         // if (!$token) {
  26.         // $weObj = $this->init();
  27.         // $url = $weObj->getOauthRedirect($this->appUrl . u_addons(’Vote://App/Index/index’));
  28.         // header("location: $url");
  29.         // return;
  30.         // } else {
  31.         // $wxuser = $weObj->getOauthUserinfo($token["access_token"], $token["openid"]);
  32.         // session("userUid", $wxuser["openid"]);
  33.         // $this->oauthRegister($wxuser);
  34.         // }
  35.         // }

  36.         $user = M("User")->where(array("uid" => session("userUid")))->find();

  37.         $config = M("AddonVoteConfig")->find();
  38.         $this->assign("config", $config);
  39.         $this->assign("user", $user);

  40.         M("AddonVoteConfig")->where(array("id"=>$config["id"]))->setInc("visiter_num");
  41.         $this->display();
  42.     }

  43.     public function vote()
  44.     {
  45.         $username=M(’User’)->where(array("id"=>session("userId")))->find();
  46.        
  47.         M("AddonVoteRecord")->add(array("user_id"=>session("userId"),"username"=>$username[’username’]));
  48.         M("AddonVoteConfig")->where(array("id"=>I("get.id")))->setInc("vote_num");
  49.     }
  50. }

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.     
  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.     <script type="text/javascript" src="__JS__/jquery.min.js"></script>
  19.     <script type="text/javascript" src="__JS__/bootstrap.min.js"></script>
  20. </head>
  21. <body>
  22. <div class="container container-fill">
  23.     <div class="pcenter-main">
  24.         <div class="head">
  25.             <div class="pdetail">
  26.                 <div class="img-circle"><img src="{$user.avater}"></div>
  27.                 <div class="pull-left">
  28.                     <span class="name">{$user.username}</span>
  29.                     <span class="type">会员ID: {$user.id}</span>
  30.                 </div>
  31.             </div>
  32.             <div class="head-nav">
  33.                 <a class="head-nav-list"
  34.                    href="">累计投票<span>{$config.vote_num}</span></a>
  35.                 <a class="head-nav-list"
  36.                    href="">访问量<span>{$config.visiter_num}</span></a>
  37.             </div>
  38.         </div>
  39.     </div>
  40.     <div class="scroll-container">
  41.         <div class="wrapper">
  42.             <ul class="list-group">
  43.                 <li class="list-group-item" style="padding: 0px 0px;border-bottom: 1px solid #ccc;">
  44.                     <div class="con">
  45.                         <div class="list-hd">
  46.                             <h5>项目:</h5><span>{$config.name}</span>
  47.                         </div>
  48.                     </div>
  49.                 </li>
  50.                 <li class="list-group-item" style="padding: 1px 0px;border-bottom: 1px solid #ccc;">
  51.                     <div class="con">
  52.                         <div class="list-hd">
  53.                             <h5>时间:</h5><span>{$config.activity_time}</span>
  54.                         </div>
  55.                     </div>
  56.                 </li>
  57.                 <li class="list-group-item" style="padding: 0px;">
  58.                     <div class="con">
  59.                         <div class="list-hd">
  60.                             <h5>投票介绍:</h5><span>{$config.about}</span>
  61.                         </div>
  62.                     </div>
  63.                 </li>
  64.             </ul>
  65.         </div>
  66.     </div>
  67.     <ul class="nav nav-bardown nav-justified" style="z-index:10;">
  68.         <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>
  69.     </ul>
  70. </div>

  71. <script type="text/javascript">
  72.     function openUrl(url){
  73.         $.get(url , function (data) {
  74.             alert(’投票成功!’);
  75.             location.reload();
  76.         });
  77.     }

  78. </script>
  79. </body>
  80. </html>


Admin_index.html


点击(此处)折叠或打开

  1. <section class="content-header">
  2.     <h1>
  3.         投票管理
  4.         <small></small>
  5.     </h1>
  6. </section>
  7. <section class="content">
  8. <div class="row">
  9.     <div class="col-md-12">
  10.         <div class="box box-danger">
  11.                 <div class="box-header with-border">
  12.                     <h3 class="box-title">大转盘设置</h3>
  13.                 
  14.                 </div>
  15.             <div class="box-body no-padding">
  16.                                 <div class="mailbox-controls">
  17.                                     <div class="btn-group">
  18.                             <a data-toggle="tab" href="#tab1" class="btn btn-danger "><i class="icon-comments"></i>投票设置</a>
  19.                         </div>
  20.                         <div class="btn-group">
  21.                             <a data-toggle="tab" href="#tab2" class="btn btn-danger "><i class="icon-user"></i>投票记录</a>
  22.                         </div>
  23.                                
  24.                             <div class="tab-content padded" id="my-tab-content">
  25.                                 <div class="tab-pane active" id="tab1">
  26.                                     

  27.                                     <p>

  28.                                     <form action="{:u_addons(’Vote://Admin/Admin/addConfig’)}" id="myForm" method="post"
  29.                                           onsubmit="return false;" class="form-horizontal">
  30.                                         <div class="form-group">
  31.                                             <label class="control-label col-md-2">投票名称</label>

  32.                                             <div style="margin-top:50px" class="col-md-7">
  33.                                                 <input class="form-control" placeholder="" value="{$config.name}"
  34.                                                        name="name" type="text">
  35.                                             </div>
  36.                                         </div>
  37.                                         <div class="form-group">
  38.                                             <label class="control-label col-md-2">活动时间</label>

  39.                                             <div class="col-md-7">
  40.                                                 <input class="form-control" placeholder=""
  41.                                                        value="{$config.activity_time}" name="activity_time" type="text">
  42.                                             </div>
  43.                                         </div>
  44.                                         
  45.                                         <div class="form-group">
  46.                                                     <label class="control-label col-md-2">活动说明</label>
  47.                                                     <div class="col-md-7">
  48.                                                         
  49.                                                         <script id="UEditor" name="about" type="text/plain" style="height:340px;">
  50.                                                             {$config.about}

  51.                                                                                         </script>
  52.                                                     </div>
  53.                                                 </div>

  54.                                         <div class="form-group">
  55.                                             <label class="control-label col-md-2"></label>

  56.                                             <div class="col-md-7">
  57.                                                 <button class="btn btn-danger"
  58.                                                         onclick="myFormSubmit(’{:u_addons(\’Vote://Admin/Admin/index\’)}’)"
  59.                                                         type="submit">提交
  60.                                                 </button>
  61.                                                 <button class="btn btn-default-outline">取消</button>
  62.                                             </div>
  63.                                         </div>
  64.                                     </form>
  65.                                     </p>
  66.                                 </div>
  67.                                 <div class="tab-pane" id="tab2">
  68.                                   
  69.                                     <p>

  70.                                     <div class="widget-content padded clearfix">
  71.                                         <table class="table table-hover">
  72.                                             <thead>
  73.                                             <th class="check-header hidden-xs">
  74.                                                 <label><input id="checkAll" name="checkAll"
  75.                                                               type="checkbox"><span></span></label>
  76.                                             </th>
  77.                                             <th>
  78.                                                 ID
  79.                                             </th>
  80.                                             <th>
  81.                                                 用户名
  82.                                             </th>
  83.                                             <th class="hidden-xs">
  84.                                                 时间
  85.                                             </th>
  86.                                             </thead>
  87.                                             <tbody>
  88.                                             <volist name="record" id="record">
  89.                                                 <tr>
  90.                                                     <td class="check hidden-xs">
  91.                                                         <label><input name="optionsRadios1" type="checkbox"
  92.                                                                       value="option1"><span></span></label>
  93.                                                     </td>
  94.                                                     <td>
  95.                                                         {$record.id}
  96.                                                     </td>
  97.                                                     <td>
  98.                                                         {$record.username}
  99.                                                     </td>
  100.                                                     <td class="hidden-xs">
  101.                                                         {$record.time}
  102.                                                     </td>
  103.                                                 </tr>
  104.                                             </volist>
  105.                                             </tbody>
  106.                                         </table>
  107.                                         <div class="pull-right">
  108.                                             
  109.                                             {$page}
  110.                                         </div>
  111.                                         
  112.                                     </div>
  113.                                     </p>
  114.                                 </div>
  115.                             </div>
  116.                         </div>
  117.                     </div>
  118.                 </div>

  119.             </div>
  120.         </div>
  121.     


  122. </section>


  123. <script type="text/javascript">
  124.     // //实例化编辑器
  125.     // var um = UM.getEditor(’myEditor’ , {
  126.     // textarea : ’about’
  127.     // });

  128.     // function setFocus() {
  129.     // UM.getEditor(’myEditor’).focus();
  130.     // }
  131.       $(function() {
  132.     //实例化编辑器异步载入
  133.     var editor = new UE.ui.Editor();
  134.         editor.render("UEditor");
  135.     });

  136.     if ({$config}) {
  137.         $(’select[name="status"]).val({$config.status});
  138.         $(’select[name="everyday"]).val({$config.everyday});
  139.         // UE.getEditor(’myEditor’).setContent({$config.activity_explain});
  140.     }
  141. </script>

wemall官网网址: 

 

阅读(692) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~