WeMall微信商城源码插件大转盘代码是用于商业推广的比较有效的方式,分享了部分比较重要的代码,供技术员学习参考
代码详情地址:http://addon.wemallshop.com/Product/addonList/menu_id/1 或 www.wemallshop.com
AdminController.class
Php代码
- <?php
- // +----------------------------------------------------------------------
- // | OneThink [ WE CAN DO IT JUST THINK IT ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
- // +----------------------------------------------------------------------
- // | Author: 麦当苗儿 <[email protected]> <http://www.zjzit.cn>
- // +----------------------------------------------------------------------
- namespace Addons\Wheel\Controller;
- class AdminController extends InitController
- {
- // public function __construct()
- // {
- // parent::__construct();
- // }
- public function index()
- {
- $config = M("AddonWheelConfig")->find();
- $this->assign("config", $config);
- $record = D(‘Addons://Wheel/AddonWheelRecord‘); // 实例化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("AddonWheelConfig")->where(array("id" => "1"))->save($_POST);
- $this->success(‘设置成功‘, ‘Admin/Admin/index/addon/Wheel‘);
- }
- }
IndexController.class
Php代码
- <?php
- /**
- * Created by PhpStorm.
- * User: heqing
- * Date: 15/7/30
- * Time: 09:40
- */
- namespace Addons\Wheel\Controller;
- // class IndexController extends InitController
- // {
- // public function index()
- // {
- // $this->show(‘SystemInfo Index index‘);
- // }
- // }
- 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(‘Wheel://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("AddonWheelConfig")->find();
- $this->assign("config", $config);
- $this->assign("user", $user);
- $record = M("AddonWheelRecord")->where(array("user_id" => session("userId")))->order("id desc")->find();
- $this->assign("record", $record);
- $this->display();
- }
- /**
- * 中奖机率计算
- */
- function lotteryJson()
- {
- $today = date("Y-m-d");
- $where["time"] = array("like", $today . "%");
- $where["user_id"] = session("userId");
- $record = D("Addons://Wheel/AddonWheelRecord")->where($where)->find();
- if ($record) {
- $this->ajaxReturn("-1");
- return;
- }
- $config = M("AddonWheelConfig")->find();
- //奖品概率
- $proArr = array(
- ‘1‘ => $config["level1_prob"],
- ‘2‘ => $config["level2_prob"],
- ‘3‘ => $config["level3_prob"],
- ‘4‘ => $config["level4_prob"],
- ‘5‘ => $config["level5_prob"],
- ‘6‘ => $config["level6_prob"],
- ‘7‘ => $config["level7_prob"]
- );
- //奖品库存
- $proCount = array(
- ‘1‘ => $config["level1_store"],
- ‘2‘ => $config["level2_store"],
- ‘3‘ => $config["level3_store"],
- ‘4‘ => $config["level4_store"],
- ‘5‘ => $config["level5_store"],
- ‘6‘ => $config["level6_store"],
- ‘7‘ => $config["level7_store"]
- );
- $file = ‘./Data/wheel.txt‘;
- $data = array(
- ‘1‘ => 0, ‘2‘ => 0, ‘3‘ => 0, ‘4‘ => 0, ‘5‘ => 0, ‘6‘ => 0
- );
- if (!file_exists($file)) {
- file_put_contents($file, serialize($data));
- } else {
- $str = file_get_contents($file);
- $data = unserialize($str);
- }
- $rid = $this->getRand($proArr, $proCount);
- if ($rid > 6) {
- $rid = 0;
- } else {
- $rid = $this->returnRid($rid, $file, $data, $proCount, $proArr);
- }
- M("AddonWheelRecord")->add(array("user_id" => session("userId"), "level" => $rid));
- echo $rid;
- }
- function returnRid($rid, $file, $data, $proCount, $proArr)
- {
- $data[$rid] = $data[$rid] + 1;
- $count = $proCount[$rid]; // 总库存
- if ($count < $data[$rid]) {
- // 如果抽取的数据大于总库存时库存清0
- $proCount[$rid] = 0;
- // 然后继续计算一直计算出某个值的库存不为0
- $rid = returnRid($rid, $file, $data, $proCount, $proArr);
- } else {
- // 写入缓存
- file_put_contents($file, serialize($data));
- }
- return $rid;
- }
- /**
- * 中奖概率计算, 能用
- * $proArr = array(‘1‘=>‘概率‘, ‘2‘=>‘概率‘);
- * $proCount = array(‘1‘=>‘库存‘, ‘2‘=>‘库存‘);
- */
- function getRand($proArr, $proCount)
- {
- $result = ‘‘;
- $proSum = 0;
- foreach ($proCount as $key => $val) {
- if ($val <= 0) {
- continue;
- } else {
- $proSum = $proSum + $proArr[$key];
- }
- }
- foreach ($proArr as $key => $proCur) {
- if ($proCount[$key] <= 0) {
- continue;
- } else {
- $randNum = mt_rand(1, $proSum);
- if ($randNum <= $proCur) {
- $result = $key;
- break;
- } else {
- $proSum -= $proCur;
- }
- }
- }
- unset($proArr);
- return $result;
- }
- }
InitController.class
Php代码
- <?php
- /**
- * Created by PhpStorm.
- * User: heqing
- * Date: 15/7/30
- * Time: 12:11
- */
- namespace Addons\Wheel\Controller;
- use Common\Controller\Addon;
- class InitController extends Addon
- {
- public function install()
- {
- $install_sql = ‘./Addons/Wheel/Data/install.sql‘;
- if (file_exists($install_sql)) {
- execute_sql_file($install_sql);
- }
- $this->success("安装成功", "Admin/Addon/addon");
- }
- public function uninstall()
- {
- $uninstall_sql = ‘./Addons/Wheel/Data/uninstall.sql‘;
- if (file_exists($uninstall_sql)) {
- execute_sql_file($uninstall_sql);
- }
- $this->success("卸载成功", "Admin/Addon/addon");
- }
- }
前台
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(‘Wheel://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 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 id="UEditor" name="activity_explain" type="text/plain" style="height:500px;">
- {$config.activity_explain}
- </script>
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-md-2">状态</label>
- <div class="col-md-7">
- <select class="form-control" name="status">
- <option value="1">是</option>
- <option value="0">否</option>
- </select>
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-md-2">一天参与一次</label>
- <div class="col-md-7">
- <select class="form-control" name="everyday">
- <option value="1">是</option>
- <option value="0">否</option>
- </select>
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-md-2">一等奖中奖概率</label>
- <div class="col-md-2">
- <input class="form-control" placeholder="" value="{$config.level1_prob}" name="level1_prob" type="text">
- </div>
- <label class="control-label col-md-2">一等奖库存</label>
- <div class="col-md-2">
- <input class="form-control" placeholder="" value="{$config.level1_store}" name="level1_store" type="text">
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-md-2">二等奖中奖概率</label>
- <div class="col-md-2">
- <input class="form-control" placeholder="" value="{$config.level2_prob}" name="level2_prob" type="text">
- </div>
- <label class="control-label col-md-2">二等奖库存</label>
- <div class="col-md-2">
- <input class="form-control" placeholder="" value="{$config.level2_store}" name="level2_store" type="text">
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-md-2">三等奖中奖概率</label>
- <div class="col-md-2">
- <input class="form-control" placeholder="" value="{$config.level3_prob}" name="level3_prob" type="text">
- </div>
- <label class="control-label col-md-2">三等奖库存</label>
- <div class="col-md-2">
- <input class="form-control" placeholder="" value="{$config.level3_store}" name="level3_store" type="text">
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-md-2">四等奖中奖概率</label>
- <div class="col-md-2">
- <input class="form-control" placeholder="" value="{$config.level4_prob}" name="level4_prob" type="text">
- </div>
- <label class="control-label col-md-2">四等奖库存</label>
- <div class="col-md-2">
- <input class="form-control" placeholder="" value="{$config.level4_store}" name="level4_store" type="text">
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-md-2">五等奖中奖概率</label>
- <div class="col-md-2">
- <input class="form-control" placeholder="" value="{$config.level5_prob}" name="level5_prob" type="text">
- </div>
- <label class="control-label col-md-2">五等奖库存</label>
- <div class="col-md-2">
- <input class="form-control" placeholder="" value="{$config.level5_store}" name="level5_store" type="text">
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-md-2">六等奖中奖概率</label>
- <div class="col-md-2">
- <input class="form-control" placeholder="" value="{$config.level6_prob}" name="level6_prob" type="text">
- </div>
- <label class="control-label col-md-2">六等奖库存</label>
- <div class="col-md-2">
- <input class="form-control" placeholder="" value="{$config.level6_store}" name="level6_store" type="text">
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-md-2">未中奖概率</label>
- <div class="col-md-2">
- <input class="form-control" placeholder="" value="{$config.level7_prob}" name="level7_prob" type="text">
- </div>
- <label class="control-label col-md-2">未中奖概率</label>
- <div class="col-md-2">
- <input class="form-control" placeholder="" value="{$config.level7_store}" name="level7_store" type="text">
- </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(\‘Wheel://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>
- <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.level}
- </td>
- <td class="hidden-xs">
- {$record.time}
- </td>
- </tr>
- </volist>
- </tbody>
- </table>
- <div class="box-footer no-padding">
- <div class="pull-right" style="margin-bottom: 6px">
- {$page}
- <!-- /.btn-group -->
- </div>
- </div>
- </div>
- </div>
- </p>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </section>
- <!-- <script type="text/javascript">
- //实例化编辑器
- var um = UM.getEditor(‘myEditor‘, {
- textarea: ‘activity_explain‘
- });
- function setFocus() {
- UM.getEditor(‘myEditor‘).focus();
- }
- </script>
- <script>
- if (‘{$config}‘) {
- $(‘select[name="status"]‘).val(‘{$config.status}‘);
- $(‘select[name="everyday"]‘).val(‘{$config.everyday}‘);
- UM.getEditor(‘myEditor‘).setContent(‘{$config.activity_explain}‘);
- }
- </script>
- -->
- <script type="text/javascript">
- $(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>
Index_index
Html代码
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <meta name="viewport"
- content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
- <meta name="apple-mobile-web-app-capable" content="yes">
- <meta name="apple-mobile-web-app-status-bar-style" content="black">
- <meta name="format-detection" content="telephone=no">
- <meta name="description" content="微信">
- <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
- <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
- <META HTTP-EQUIV="Expires" CONTENT="0">
- <title>{$config.name}</title>
- <link href="__CSS__/activity-style2.css" rel="stylesheet" type="text/css">
- <link href="__CSS__/pan.css" rel="stylesheet" type="text/css">
- </head>
- <body class="activity-lottery-winning">
- <div id="loader" style="text-align: center;height:30px;line-height: 30px;background: white;display: none;"><img
- src="__IMG__/load.gif" align="absmiddle"/> 请稍后,数据传输中 ...
- </div>
- <div class="main">
- <script src="__JS__/jquery.min.js" type="text/javascript"></script>
- <div class="panBg">
- <img src="__IMG__/header.png" class="headerImg">
- <div class="wenZi">
- <img src="__IMG__/dazhuanpan.png" class="zhuanPan">
- </div>
- <div id="outercont">
- <div id="outer-cont">
- <div id="outer"><img src="__IMG__/zp8-.png"></div>
- </div>
- <div id="inner-cont">
- <div id="inner"><img src="__IMG__/activity-lottery-2.png"></div>
- </div>
- </div>
- <div class="btnBox">
- <button class="left" id="myPrizes">我的奖品</button>
- <button class="right" id="goToMall" onclick="location.href = ‘{:U(\‘App/Index/index\‘)}‘">进店逛逛</button>
- </div>
- </div>
- <div class="footer">
- <div class="explain"><span id="explain">活动说明>></span></div>
- <div class="copyright">由 inuoer 技术支持</div>
- </div>
- <div class="ruleBox" id="rule" style="display: none;">
- <span class="close"></span>
- <div class="content">
- <h4>活动时间</h4>
- <p id="activityTime">{$config.activity_time}</p>
- <!--<h4>奖项设置</h4>
- <p id="activityPrize"></p>-->
- <h4>活动说明</h4>
- <pre id="descriptor">{$config.activity_explain}</pre>
- </div>
- </div>
- <div class="ruleBox" id="winPrize" style="display: none;">
- <span class="close"></span>
- <div class="content">
- <div class="null"><empty name="record[‘level‘]">暂无奖品,继续加油哦~<else/>恭喜您获得
- {$record.level}等奖<br/>时间:{$record.time}</empty></div>
- </div>
- </div>
- <div class="shareTip" id="shareTip"></div>
- <div class="popup not" id="not" style="display: none;">
- <div class="content">
- <em></em>
- <div class="text">很遗憾,您未中奖!</div>
- <div class="buttonBox">
- <button class="ok">知道了</button>
- </div>
- </div>
- <!--end content-->
- </div>
- <div class="popup lost" id="lost" style="display: none;">
- <div class="content">
- <em></em>
- <div class="text">点击右上角按钮,分享到朋友圈</div>
- <div class="buttonBox">
- <button class="ok">知道了</button>
- </div>
- </div>
- <!--end content-->
- </div>
- <div class="popup win" id="win" style="display: none;">
- <div class="content">
- <em></em>
- <div class="text">恭喜您得到<span id="winlevel"></span>等奖</div>
- <div class="buttonBox">
- <button class="cancel" onclick="leave();">低调离开</button>
- <button class="ok mr_left10" onclick="flaunt();">立即炫耀</button>
- </div>
- </div>
- <!--end content-->
- </div>
- </div>
- <script type="text/javascript">
- $(function () {
- window.requestAnimFrame = (function () {
- return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
- function (callback) {
- window.setTimeout(callback, 1000 / 60);
- }
- })();
- var totalDeg = 360 * 3 + 0;
- var steps = [];
- var lostDeg = [72, 128, 180 , 230 , 285 , 360];
- // var prizeDeg = [36, 102, 158, 202, 259, 314];
- var prizeDeg = [314, 259, 202, 158, 102, 36];
- var prize, sncode;
- var count = 0;
- var now = 0;
- var a = 0.01;
- var outter, inner, timer, running = false;
- var level = 0;
- function countSteps() {
- var t = Math.sqrt(2 * totalDeg / a);
- var v = a * t;
- for (var i = 0; i < t; i++) {
- steps.push((2 * v * i - a * i * i) / 2)
- }
- steps.push(totalDeg)
- }
- function step() {
- outter.style.webkitTransform = ‘rotate(‘ + steps[now++] + ‘deg)‘;
- outter.style.MozTransform = ‘rotate(‘ + steps[now++] + ‘deg)‘;
- if (now < steps.length) {
- running = true;
- requestAnimFrame(step)
- } else {
- // running = false;
- if (level == 0) {
- $(‘#not‘).show();
- } else {
- $(‘#win‘).show();
- $(‘#winlevel‘).html(level);
- }
- }
- }
- function start(deg) {
- degdeg = deg || lostDeg[parseInt(lostDeg.length * Math.random())];
- running = true;
- clearInterval(timer);
- totalDeg = 360 * 5 + deg;
- steps = [];
- now = 0;
- countSteps();
- requestAnimFrame(step);
- }
- window.start = start;
- outter = document.getElementById(‘outer‘);
- inner = document.getElementById(‘inner‘);
- i = 10;
- $("#inner").click(function () {
- // if (running) {
- // alert("今日已用完,请明天再来!");
- // return;
- // }
- $(‘#loader‘).show();
- $(‘#inner-cont‘).css(‘top‘, ‘-210px‘);
- $.get("{:u_addons(‘Wheel://App/Index/lotteryJson‘)}", function (rid) {
- level = rid;
- $(‘#loader‘).hide();
- $(‘#inner-cont‘).css(‘top‘, ‘-210px‘);
- if(rid == "-1"){
- alert("今日已用完,请明天再来!");
- return;
- }
- if (rid == 0) {
- start();
- } else {
- start(prizeDeg[rid - 1]);
- }
- });
- });
- $(".close").click(function () {
- $(this).parent().hide();
- });
- $(‘#explain‘).click(function(){
- $(‘#rule‘).show();
- });
- $(‘#myPrizes‘).click(function () {
- $(‘#winPrize‘).show();
- });
- $(‘.ok‘).click(function () {
- $(‘.popup‘).hide();
- });
- $(‘#shareTip‘).click(function () {
- $(this).hide();
- location.reload();
- });
- });
- function leave(){
- $(‘#win‘).hide();
- location.reload();
- }
- function flaunt(){
- $(‘#win‘).hide();
- $(‘#shareTip‘).show();
- }
- </script>
- </body>
- </html>
KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架
时间: 2024-09-29 18:16:34