码迷,mamicode.com
首页 > 微信 > 详细

WeMall微信商城源码插件大转盘代码详情

时间:2016-10-06 17:21:22      阅读:469      评论:0      收藏:0      [点我收藏+]

标签:

WeMall微信商城源码插件大转盘代码是用于商业推广的比较有效的方式,分享了部分比较重要的代码,供技术员学习参考

 

代码详情地址:http://addon.wemallshop.com/Product/addonList/menu_id/1 或 www.wemallshop.com

AdminController.class

Php代码  技术分享
  1. <?php  
  2. // +----------------------------------------------------------------------  
  3. // | OneThink [ WE CAN DO IT JUST THINK IT ]  
  4. // +----------------------------------------------------------------------  
  5. // | Copyright (c) 2013 http://www.onethink.cn All rights reserved.  
  6. // +----------------------------------------------------------------------  
  7. // | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>  
  8. // +----------------------------------------------------------------------  
  9. namespace Addons\Wheel\Controller;  
  10.   
  11. class AdminController extends InitController  
  12. {  
  13.   
  14.   
  15.     // public function __construct()  
  16.     // {  
  17.     //     parent::__construct();  
  18.     // }  
  19.   
  20.     public function index()  
  21.     {  
  22.         $config = M("AddonWheelConfig")->find();  
  23.         $this->assign("config", $config);  
  24.   
  25.         $record = D(‘Addons://Wheel/AddonWheelRecord‘); // 实例化User对象  
  26.         $count = $record->count();// 查询满足要求的总记录数  
  27.         $Page = new \Think\Page($count, 12);// 实例化分页类 传入总记录数和每页显示的记录数(25)  
  28.         $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>");  
  29.         $show = $Page->show();// 分页显示输出  
  30.         // 进行分页数据查询 注意limit方法的参数要使用Page类的属性  
  31.         $record = $record->limit($Page->firstRow . ‘,‘ . $Page->listRows)->order("id desc")->relation(true)->select();  
  32.   
  33.         $this->assign("record", $record);// 赋值数据集  
  34.         $this->assign(‘page‘, $show);// 赋值分页输出  
  35.   
  36.         $this->display();  
  37.     }  
  38.   
  39.     public function addConfig()  
  40.     {  
  41.         M("AddonWheelConfig")->where(array("id" => "1"))->save($_POST);  
  42.         $this->success(‘设置成功‘, ‘Admin/Admin/index/addon/Wheel‘);  
  43.     }  
  44. }  

 

IndexController.class

Php代码  技术分享
  1. <?php  
  2. /** 
  3.  * Created by PhpStorm. 
  4.  * User: heqing 
  5.  * Date: 15/7/30 
  6.  * Time: 09:40 
  7.  */  
  8.   
  9. namespace Addons\Wheel\Controller;  
  10.   
  11. // class IndexController extends InitController  
  12. // {  
  13. //     public function index()  
  14. //     {  
  15. //         $this->show(‘SystemInfo Index index‘);  
  16. //     }  
  17.   
  18.   
  19. // }  
  20.   
  21. class IndexController extends InitController  
  22. {  
  23.     public $appUrl = "";  
  24.     public function __construct()  
  25.     {  
  26.         parent::__construct();  
  27.         $this->appUrl = "http://" . I("server.HTTP_HOST");  
  28.     }  
  29.   
  30.     public function init()  
  31.     {  
  32.         return R("App/Common/init");  
  33.     }  
  34.   
  35.     public function oauthRegister($wxuser)  
  36.     {  
  37.         return R("App/Common/oauthRegister", array($wxuser));  
  38.     }  
  39.   
  40.     public function index()  
  41.     {  
  42.         $user=R("App/Public/oauthLogin");  
  43.   
  44.         // if (!session("userUid")) {  
  45.         //     $weObj = $this->init();  
  46.         //     $token = $weObj->getOauthAccessToken();  
  47.         //     if (!$token) {  
  48.         //         $weObj = $this->init();  
  49.         //         $url = $weObj->getOauthRedirect($this->appUrl . u_addons(‘Wheel://App/Index/index‘));  
  50.         //         header("location: $url");  
  51.         //         return;  
  52.         //     } else {  
  53.         //         $wxuser = $weObj->getOauthUserinfo($token["access_token"], $token["openid"]);  
  54.         //         session("userUid", $wxuser["openid"]);  
  55.         //         $this->oauthRegister($wxuser);  
  56.         //     }  
  57.         // }  
  58.   
  59.         $user = M("User")->where(array("uid" => session("userUid")))->find();  
  60.   
  61.         $config = M("AddonWheelConfig")->find();  
  62.         $this->assign("config", $config);  
  63.         $this->assign("user", $user);  
  64.   
  65.         $record = M("AddonWheelRecord")->where(array("user_id" => session("userId")))->order("id desc")->find();  
  66.         $this->assign("record", $record);  
  67.         $this->display();  
  68.     }  
  69.   
  70.     /** 
  71.      * 中奖机率计算 
  72.      */  
  73.     function lotteryJson()  
  74.     {  
  75.         $today = date("Y-m-d");  
  76.         $where["time"] = array("like", $today . "%");  
  77.         $where["user_id"] = session("userId");  
  78.         $record = D("Addons://Wheel/AddonWheelRecord")->where($where)->find();  
  79.         if ($record) {  
  80.             $this->ajaxReturn("-1");  
  81.             return;  
  82.         }  
  83.   
  84.         $config = M("AddonWheelConfig")->find();  
  85.         //奖品概率  
  86.         $proArr = array(  
  87.             ‘1‘ => $config["level1_prob"],   
  88.             ‘2‘ => $config["level2_prob"],   
  89.             ‘3‘ => $config["level3_prob"],   
  90.             ‘4‘ => $config["level4_prob"],   
  91.             ‘5‘ => $config["level5_prob"],   
  92.             ‘6‘ => $config["level6_prob"],   
  93.             ‘7‘ => $config["level7_prob"]  
  94.         );  
  95.         //奖品库存  
  96.         $proCount = array(  
  97.             ‘1‘ => $config["level1_store"],  
  98.             ‘2‘ => $config["level2_store"],  
  99.             ‘3‘ => $config["level3_store"],  
  100.             ‘4‘ => $config["level4_store"],  
  101.             ‘5‘ => $config["level5_store"],  
  102.             ‘6‘ => $config["level6_store"],  
  103.             ‘7‘ => $config["level7_store"]  
  104.         );  
  105.         $file = ‘./Data/wheel.txt‘;  
  106.         $data = array(  
  107.             ‘1‘ => 0, ‘2‘ => 0, ‘3‘ => 0, ‘4‘ => 0, ‘5‘ => 0, ‘6‘ => 0  
  108.         );  
  109.         if (!file_exists($file)) {  
  110.             file_put_contents($file, serialize($data));  
  111.         } else {  
  112.             $str = file_get_contents($file);  
  113.             $data = unserialize($str);  
  114.         }  
  115.         $rid = $this->getRand($proArr, $proCount);  
  116.   
  117.         if ($rid > 6) {  
  118.             $rid = 0;  
  119.         } else {  
  120.             $rid = $this->returnRid($rid, $file, $data, $proCount, $proArr);  
  121.         }  
  122.   
  123.         M("AddonWheelRecord")->add(array("user_id" => session("userId"), "level" => $rid));  
  124.         echo $rid;  
  125.     }  
  126.   
  127.     function returnRid($rid, $file, $data, $proCount, $proArr)  
  128.     {  
  129.         $data[$rid] = $data[$rid] + 1;  
  130.         $count = $proCount[$rid]; // 总库存  
  131.         if ($count < $data[$rid]) {  
  132.             // 如果抽取的数据大于总库存时库存清0  
  133.             $proCount[$rid] = 0;  
  134.             // 然后继续计算一直计算出某个值的库存不为0  
  135.             $rid = returnRid($rid, $file, $data, $proCount, $proArr);  
  136.         } else {  
  137.             // 写入缓存  
  138.             file_put_contents($file, serialize($data));  
  139.         }  
  140.         return $rid;  
  141.     }  
  142.   
  143.     /** 
  144.      * 中奖概率计算, 能用 
  145.      * $proArr = array(‘1‘=>‘概率‘, ‘2‘=>‘概率‘); 
  146.      * $proCount = array(‘1‘=>‘库存‘, ‘2‘=>‘库存‘); 
  147.      */  
  148.     function getRand($proArr, $proCount)  
  149.     {  
  150.         $result = ‘‘;  
  151.         $proSum = 0;  
  152.         foreach ($proCount as $key => $val) {  
  153.             if ($val <= 0) {  
  154.                 continue;  
  155.             } else {  
  156.                 $proSum = $proSum + $proArr[$key];  
  157.             }  
  158.         }  
  159.         foreach ($proArr as $key => $proCur) {  
  160.             if ($proCount[$key] <= 0) {  
  161.                 continue;  
  162.             } else {  
  163.                 $randNum = mt_rand(1, $proSum);  
  164.                 if ($randNum <= $proCur) {  
  165.                     $result = $key;  
  166.                     break;  
  167.                 } else {  
  168.                     $proSum -= $proCur;  
  169.                 }  
  170.             }  
  171.         }  
  172.         unset($proArr);  
  173.         return $result;  
  174.     }  
  175. }  

 

InitController.class

Php代码  技术分享
  1. <?php  
  2. /** 
  3.  * Created by PhpStorm. 
  4.  * User: heqing 
  5.  * Date: 15/7/30 
  6.  * Time: 12:11 
  7.  */  
  8.   
  9. namespace Addons\Wheel\Controller;  
  10.   
  11.   
  12. use Common\Controller\Addon;  
  13.   
  14. class InitController extends Addon  
  15. {  
  16.   
  17.     public function install()  
  18.     {  
  19.         $install_sql = ‘./Addons/Wheel/Data/install.sql‘;  
  20.         if (file_exists($install_sql)) {  
  21.             execute_sql_file($install_sql);  
  22.         }  
  23.          $this->success("安装成功", "Admin/Addon/addon");  
  24.     }  
  25.   
  26.     public function uninstall()  
  27.     {  
  28.         $uninstall_sql = ‘./Addons/Wheel/Data/uninstall.sql‘;  
  29.         if (file_exists($uninstall_sql)) {  
  30.             execute_sql_file($uninstall_sql);  
  31.         }  
  32.         $this->success("卸载成功", "Admin/Addon/addon");  
  33.     }  
  34. }  

 

前台

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. <!-- /.box-tools -->  
  14.   </div>  
  15.                   
  16.           
  17.                             <div class="box-body no-padding">  
  18.                                 <div class="mailbox-controls">  
  19.                                     <div class="btn-group">  
  20.                             <data-toggle="tab" href="#tab1" class="btn btn-danger "><class="icon-comments"></i>大转盘设置</a>  
  21.                         </div>      
  22.                         <div class="btn-group">  
  23.                             <data-toggle="tab" href="#tab2" class="btn btn-danger "><class="icon-user"></i>大转盘记录</a>  
  24.                         </div>  
  25.                                  
  26.                                 <div class="tab-content padded" id="my-tab-content">  
  27.                                     <div class="tab-pane active" id="tab1">  
  28.                                         <p>  
  29.                                             <form action="{:u_addons(‘Wheel://Admin/Admin/addConfig‘)}" id="myForm" method="post" onsubmit="return false;" class="form-horizontal">  
  30.                                                 <div class="form-group">  
  31.                                                     <label class="control-label col-md-2">大转盘名称</label>  
  32.                                                     <div class="col-md-7">  
  33.                                                         <input class="form-control" placeholder="" value="{$config.name}" name="name" type="text">  
  34.                                                     </div>  
  35.                                                 </div>  
  36.                                                 <div class="form-group">  
  37.                                                     <label class="control-label col-md-2">活动时间</label>  
  38.                                                     <div class="col-md-7">  
  39.                                                         <input class="form-control" placeholder="" value="{$config.activity_time}" name="activity_time" type="text">  
  40.                                                     </div>  
  41.                                                 </div>  
  42.                                                 <div class="form-group">  
  43.                                                     <label class="control-label col-md-2">活动说明</label>  
  44.                                                     <div class="col-md-7">  
  45.                                                         <!--style给定宽度可以影响编辑器的最终宽度-->  
  46.                                                         <script id="UEditor" name="activity_explain" type="text/plain" style="height:500px;">  
  47.                                                             {$config.activity_explain}  
  48.   
  49.                                                                                         </script>  
  50.                                                     </div>  
  51.                                                 </div>  
  52.                                                 <div class="form-group">  
  53.                                                     <label class="control-label col-md-2">状态</label>  
  54.                                                     <div class="col-md-7">  
  55.                                                         <select class="form-control" name="status">  
  56.                                                             <option value="1">是</option>  
  57.                                                             <option value="0">否</option>  
  58.                                                         </select>  
  59.                                                     </div>  
  60.                                                 </div>  
  61.                                                 <div class="form-group">  
  62.                                                     <label class="control-label col-md-2">一天参与一次</label>  
  63.                                                     <div class="col-md-7">  
  64.                                                         <select class="form-control" name="everyday">  
  65.                                                             <option value="1">是</option>  
  66.                                                             <option value="0">否</option>  
  67.                                                         </select>  
  68.                                                     </div>  
  69.                                                 </div>  
  70.                                                 <div class="form-group">  
  71.                                                     <label class="control-label col-md-2">一等奖中奖概率</label>  
  72.                                                     <div class="col-md-2">  
  73.                                                         <input class="form-control" placeholder="" value="{$config.level1_prob}" name="level1_prob" type="text">  
  74.                                                     </div>  
  75.                                                     <label class="control-label col-md-2">一等奖库存</label>  
  76.                                                     <div class="col-md-2">  
  77.                                                         <input class="form-control" placeholder="" value="{$config.level1_store}" name="level1_store" type="text">  
  78.                                                     </div>  
  79.                                                 </div>  
  80.                                                 <div class="form-group">  
  81.                                                     <label class="control-label col-md-2">二等奖中奖概率</label>  
  82.                                                     <div class="col-md-2">  
  83.                                                         <input class="form-control" placeholder="" value="{$config.level2_prob}" name="level2_prob" type="text">  
  84.                                                     </div>  
  85.                                                     <label class="control-label col-md-2">二等奖库存</label>  
  86.                                                     <div class="col-md-2">  
  87.                                                         <input class="form-control" placeholder="" value="{$config.level2_store}" name="level2_store" type="text">  
  88.                                                     </div>  
  89.                                                 </div>  
  90.                                                 <div class="form-group">  
  91.                                                     <label class="control-label col-md-2">三等奖中奖概率</label>  
  92.                                                     <div class="col-md-2">  
  93.                                                         <input class="form-control" placeholder="" value="{$config.level3_prob}" name="level3_prob" type="text">  
  94.                                                     </div>  
  95.                                                     <label class="control-label col-md-2">三等奖库存</label>  
  96.                                                     <div class="col-md-2">  
  97.                                                         <input class="form-control" placeholder="" value="{$config.level3_store}" name="level3_store" type="text">  
  98.                                                     </div>  
  99.                                                 </div>  
  100.                                                 <div class="form-group">  
  101.                                                     <label class="control-label col-md-2">四等奖中奖概率</label>  
  102.                                                     <div class="col-md-2">  
  103.                                                         <input class="form-control" placeholder="" value="{$config.level4_prob}" name="level4_prob" type="text">  
  104.                                                     </div>  
  105.                                                     <label class="control-label col-md-2">四等奖库存</label>  
  106.                                                     <div class="col-md-2">  
  107.                                                         <input class="form-control" placeholder="" value="{$config.level4_store}" name="level4_store" type="text">  
  108.                                                     </div>  
  109.                                                 </div>  
  110.                                                 <div class="form-group">  
  111.                                                     <label class="control-label col-md-2">五等奖中奖概率</label>  
  112.                                                     <div class="col-md-2">  
  113.                                                         <input class="form-control" placeholder="" value="{$config.level5_prob}" name="level5_prob" type="text">  
  114.                                                     </div>  
  115.                                                     <label class="control-label col-md-2">五等奖库存</label>  
  116.                                                     <div class="col-md-2">  
  117.                                                         <input class="form-control" placeholder="" value="{$config.level5_store}" name="level5_store" type="text">  
  118.                                                     </div>  
  119.                                                 </div>  
  120.                                                 <div class="form-group">  
  121.                                                     <label class="control-label col-md-2">六等奖中奖概率</label>  
  122.                                                     <div class="col-md-2">  
  123.                                                         <input class="form-control" placeholder="" value="{$config.level6_prob}" name="level6_prob" type="text">  
  124.                                                     </div>  
  125.                                                     <label class="control-label col-md-2">六等奖库存</label>  
  126.                                                     <div class="col-md-2">  
  127.                                                         <input class="form-control" placeholder="" value="{$config.level6_store}" name="level6_store" type="text">  
  128.                                                     </div>  
  129.                                                 </div>  
  130.                                                 <div class="form-group">  
  131.                                                     <label class="control-label col-md-2">未中奖概率</label>  
  132.                                                     <div class="col-md-2">  
  133.                                                         <input class="form-control" placeholder="" value="{$config.level7_prob}" name="level7_prob" type="text">  
  134.                                                     </div>  
  135.                                                     <label class="control-label col-md-2">未中奖概率</label>  
  136.                                                     <div class="col-md-2">  
  137.                                                         <input class="form-control" placeholder="" value="{$config.level7_store}" name="level7_store" type="text">  
  138.                                                     </div>  
  139.                                                 </div>  
  140.                                                 <div class="form-group">  
  141.                                                     <label class="control-label col-md-2"></label>  
  142.                                                     <div class="col-md-7">  
  143.                                                         <button class="btn btn-danger" onclick="myFormSubmit(‘{:u_addons(\‘Wheel://Admin/Admin/index\‘)}‘)" type="submit">提交  
  144.                                                         </button>  
  145.                                                         <button class="btn btn-default-outline">取消</button>  
  146.                                                     </div>  
  147.                                                 </div>  
  148.                                             </form>  
  149.                                         </p>  
  150.                                     </div>  
  151.                                     <div class="tab-pane" id="tab2">  
  152.                                         <p>  
  153.                                             <div class="widget-content padded clearfix">  
  154.                                                 <table class="table table-hover">  
  155.                                                     <thead>  
  156.                                                         <th class="check-header hidden-xs">  
  157.                                                             <label>  
  158.                                                                 <input id="checkAll" name="checkAll" type="checkbox"><span></span></label>  
  159.                                                         </th>  
  160.                                                         <th>  
  161.                                                             ID  
  162.                                                         </th>  
  163.                                                         <th>  
  164.                                                             用户名  
  165.                                                         </th>  
  166.                                                         <th class="hidden-xs">  
  167.                                                             奖项  
  168.                                                         </th>  
  169.                                                         <th class="hidden-xs">  
  170.                                                             时间  
  171.                                                         </th>  
  172.                                                     </thead>  
  173.                                                     <tbody>  
  174.                                                         <volist name="record" id="record">  
  175.                                                             <tr>  
  176.                                                                 <td class="check hidden-xs">  
  177.                                                                     <label>  
  178.                                                                         <input name="optionsRadios1" type="checkbox" value="option1"><span></span></label>  
  179.                                                                 </td>  
  180.                                                                 <td>  
  181.                                                                     {$record.id}  
  182.                                                                 </td>  
  183.                                                                 <td>  
  184.                                                                     {$record.username}  
  185.                                                                 </td>  
  186.                                                                 <td class="hidden-xs">  
  187.                                                                     {$record.level}  
  188.                                                                 </td>  
  189.                                                                 <td class="hidden-xs">  
  190.                                                                     {$record.time}  
  191.                                                                 </td>  
  192.                                                             </tr>  
  193.                                                         </volist>  
  194.                                                     </tbody>  
  195.                                                 </table>  
  196.                                                 <div class="box-footer no-padding">  
  197.                
  198. <div class="pull-right" style="margin-bottom: 6px">  
  199.                                                             {$page}  
  200. <!-- /.btn-group -->  
  201.  </div>  
  202.                                                     </div>  
  203.                                                 </div>  
  204.                                             </div>  
  205.                                         </p>  
  206.                                     </div>  
  207.                                 </div>  
  208.                             </div>  
  209.                         </div>  
  210.                     </div>  
  211.                 </div>  
  212.               
  213.          
  214.       
  215. </section>  
  216.   
  217. <!-- <script type="text/javascript">  
  218. //实例化编辑器  
  219. var um = UM.getEditor(‘myEditor‘, {  
  220.     textarea: ‘activity_explain‘  
  221. });  
  222.   
  223. function setFocus() {  
  224.     UM.getEditor(‘myEditor‘).focus();  
  225. }  
  226. </script>  
  227. <script>  
  228. if (‘{$config}‘) {  
  229.     $(‘select[name="status"]‘).val(‘{$config.status}‘);  
  230.     $(‘select[name="everyday"]‘).val(‘{$config.everyday}‘);  
  231.     UM.getEditor(‘myEditor‘).setContent(‘{$config.activity_explain}‘);  
  232. }  
  233. </script>  
  234.  -->  
  235.   
  236. <script type="text/javascript">  
  237.     $(function() {  
  238.     //实例化编辑器异步载入  
  239.     var editor = new UE.ui.Editor();  
  240.         editor.render("UEditor");  
  241.     });  
  242.   
  243.     if (‘{$config}‘) {  
  244.         $(‘select[name="status"]‘).val(‘{$config.status}‘);  
  245.         $(‘select[name="everyday"]‘).val(‘{$config.everyday}‘);  
  246.         // UE.getEditor(‘myEditor‘).setContent(‘{$config.activity_explain}‘);  
  247.     }  
  248. </script>  

 

Index_index

Html代码  技术分享
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  5.     <meta name="viewport"  
  6.           content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">  
  7.     <meta name="apple-mobile-web-app-capable" content="yes">  
  8.     <meta name="apple-mobile-web-app-status-bar-style" content="black">  
  9.     <meta name="format-detection" content="telephone=no">  
  10.     <meta name="description" content="微信">  
  11.     <META HTTP-EQUIV="Pragma" CONTENT="no-cache">  
  12.     <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">  
  13.     <META HTTP-EQUIV="Expires" CONTENT="0">  
  14.     <title>{$config.name}</title>  
  15.     <link href="__CSS__/activity-style2.css" rel="stylesheet" type="text/css">  
  16.     <link href="__CSS__/pan.css" rel="stylesheet" type="text/css">  
  17. </head>  
  18. <body class="activity-lottery-winning">  
  19. <div id="loader" style="text-align: center;height:30px;line-height: 30px;background: white;display: none;"><img  
  20.         src="__IMG__/load.gif" align="absmiddle"/> 请稍后,数据传输中 ...  
  21. </div>  
  22. <div class="main">  
  23.     <script src="__JS__/jquery.min.js" type="text/javascript"></script>  
  24.     <div class="panBg">  
  25.         <img src="__IMG__/header.png" class="headerImg">  
  26.   
  27.         <div class="wenZi">  
  28.             <img src="__IMG__/dazhuanpan.png" class="zhuanPan">  
  29.         </div>  
  30.   
  31.         <div id="outercont">  
  32.             <div id="outer-cont">  
  33.                 <div id="outer"><img src="__IMG__/zp8-.png"></div>  
  34.             </div>  
  35.             <div id="inner-cont">  
  36.                 <div id="inner"><img src="__IMG__/activity-lottery-2.png"></div>  
  37.             </div>  
  38.         </div>  
  39.   
  40.         <div class="btnBox">  
  41.             <button class="left" id="myPrizes">我的奖品</button>  
  42.             <button class="right" id="goToMall" onclick="location.href = ‘{:U(\‘App/Index/index\‘)}‘">进店逛逛</button>  
  43.         </div>  
  44.     </div>  
  45.   
  46.   
  47.     <div class="footer">  
  48.         <div class="explain"><span id="explain">活动说明&gt;&gt;</span></div>  
  49.         <div class="copyright">由 inuoer 技术支持</div>  
  50.     </div>  
  51.   
  52.     <div class="ruleBox" id="rule" style="display: none;">  
  53.         <span class="close"></span>  
  54.   
  55.         <div class="content">  
  56.             <h4>活动时间</h4>  
  57.   
  58.             <id="activityTime">{$config.activity_time}</p>  
  59.             <!--<h4>奖项设置</h4>  
  60.             <p  id="activityPrize"></p>-->  
  61.             <h4>活动说明</h4>  
  62.             <pre id="descriptor">{$config.activity_explain}</pre>  
  63.         </div>  
  64.     </div>  
  65.   
  66.     <div class="ruleBox" id="winPrize" style="display: none;">  
  67.         <span class="close"></span>  
  68.   
  69.         <div class="content">  
  70.             <div class="null"><empty name="record[‘level‘]">暂无奖品,继续加油哦~<else/>恭喜您获得  
  71.                 {$record.level}等奖<br/>时间:{$record.time}</empty></div>  
  72.         </div>  
  73.     </div>  
  74.   
  75.     <div class="shareTip" id="shareTip"></div>  
  76.   
  77.     <div class="popup not" id="not" style="display: none;">  
  78.         <div class="content">  
  79.             <em></em>  
  80.   
  81.             <div class="text">很遗憾,您未中奖!</div>  
  82.             <div class="buttonBox">  
  83.                 <button class="ok">知道了</button>  
  84.             </div>  
  85.         </div>  
  86.         <!--end content-->  
  87.     </div>  
  88.   
  89.     <div class="popup lost" id="lost" style="display: none;">  
  90.         <div class="content">  
  91.             <em></em>  
  92.   
  93.             <div class="text">点击右上角按钮,分享到朋友圈</div>  
  94.             <div class="buttonBox">  
  95.                 <button class="ok">知道了</button>  
  96.             </div>  
  97.         </div>  
  98.         <!--end content-->  
  99.     </div>  
  100.   
  101.     <div class="popup win" id="win" style="display: none;">  
  102.         <div class="content">  
  103.             <em></em>  
  104.   
  105.             <div class="text">恭喜您得到<span id="winlevel"></span>等奖</div>  
  106.             <div class="buttonBox">  
  107.                 <button class="cancel" onclick="leave();">低调离开</button>  
  108.                 <button class="ok mr_left10" onclick="flaunt();">立即炫耀</button>  
  109.             </div>  
  110.         </div>  
  111.         <!--end content-->  
  112.     </div>  
  113. </div>  
  114.   
  115. <script type="text/javascript">  
  116.     $(function () {  
  117.         window.requestAnimFrame = (function () {  
  118.             return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||  
  119.                     function (callback) {  
  120.                         window.setTimeout(callback, 1000 / 60);  
  121.                     }  
  122.         })();  
  123.         var totalDeg = 360 * 3 + 0;  
  124.         var steps = [];  
  125.   
  126.         var lostDeg = [72, 128, 180 , 230 , 285 , 360];  
  127. //        var prizeDeg = [36, 102, 158, 202, 259, 314];  
  128.         var prizeDeg = [314, 259, 202, 158, 102, 36];  
  129.         var prize, sncode;  
  130.         var count = 0;  
  131.         var now = 0;  
  132.         var a = 0.01;  
  133.         var outter, inner, timer, running = false;  
  134.         var level = 0;  
  135.   
  136.         function countSteps() {  
  137.             var t = Math.sqrt(2 * totalDeg / a);  
  138.             var v = a * t;  
  139.             for (var i = 0; i < t; i++) {  
  140.                 steps.push((2 * v * i - a * i * i) / 2)  
  141.             }  
  142.             steps.push(totalDeg)  
  143.         }  
  144.   
  145.         function step() {  
  146.             outter.style.webkitTransform = ‘rotate(‘ + steps[now++] + ‘deg)‘;  
  147.             outter.style.MozTransform = ‘rotate(‘ + steps[now++] + ‘deg)‘;  
  148.             if (now steps.length) {  
  149.                 running = true;  
  150.                 requestAnimFrame(step)  
  151.             } else {  
  152. //                running = false;  
  153.   
  154.                 if (level == 0) {  
  155.                     $(‘#not‘).show();  
  156.                 } else {  
  157.                     $(‘#win‘).show();  
  158.                     $(‘#winlevel‘).html(level);  
  159.                 }  
  160.             }  
  161.         }  
  162.   
  163.         function start(deg) {  
  164.             degdeg = deg || lostDeg[parseInt(lostDeg.length * Math.random())];  
  165.             running = true;  
  166.             clearInterval(timer);  
  167.             totalDeg = 360 * 5 + deg;  
  168.             steps = [];  
  169.             now = 0;  
  170.             countSteps();  
  171.             requestAnimFrame(step);  
  172.         }  
  173.   
  174.         window.start = start;  
  175.         outter = document.getElementById(‘outer‘);  
  176.         inner = document.getElementById(‘inner‘);  
  177.         i = 10;  
  178.         $("#inner").click(function () {  
  179.   
  180. //            if (running) {  
  181. //                alert("今日已用完,请明天再来!");  
  182. //                return;  
  183. //            }  
  184.   
  185.             $(‘#loader‘).show();  
  186.             $(‘#inner-cont‘).css(‘top‘, ‘-210px‘);  
  187.   
  188.             $.get("{:u_addons(‘Wheel://App/Index/lotteryJson‘)}", function (rid) {  
  189.                 level = rid;  
  190.                 $(‘#loader‘).hide();  
  191.                 $(‘#inner-cont‘).css(‘top‘, ‘-210px‘);  
  192.                 if(rid == "-1"){  
  193.                     alert("今日已用完,请明天再来!");  
  194.                     return;  
  195.                 }  
  196.                 if (rid == 0) {  
  197.                     start();  
  198.                 } else {  
  199.                     start(prizeDeg[rid - 1]);  
  200.                 }  
  201.             });  
  202.         });  
  203.   
  204.         $(".close").click(function () {  
  205.             $(this).parent().hide();  
  206.         });  
  207.   
  208.         $(‘#explain‘).click(function(){  
  209.             $(‘#rule‘).show();  
  210.         });  
  211.   
  212.         $(‘#myPrizes‘).click(function () {  
  213.             $(‘#winPrize‘).show();  
  214.         });  
  215.   
  216.         $(‘.ok‘).click(function () {  
  217.             $(‘.popup‘).hide();  
  218.         });  
  219.   
  220.         $(‘#shareTip‘).click(function () {  
  221.             $(this).hide();  
  222.             location.reload();  
  223.         });  
  224.     });  
  225.     function leave(){  
  226.         $(‘#win‘).hide();  
  227.         location.reload();  
  228.     }  
  229.   
  230.     function flaunt(){  
  231.         $(‘#win‘).hide();  
  232.         $(‘#shareTip‘).show();  
  233.     }  
  234. </script>  
  235. </body>  
  236. </html>  

 

KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架

官网:http://js.koahub.com

技术分享

WeMall微信商城源码插件大转盘代码详情

标签:

原文地址:http://www.cnblogs.com/jycxqe/p/5934009.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!