首页 >php教程 >php手册 >WeMall微信商城源码插件大转盘代码详情

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

WBOY
WBOY原创
2016-10-09 08:32:171577浏览

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

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

AdminController.class<?php <br /> // +----------------------------------------------------------------------  <br> // | OneThink [ WE CAN DO IT JUST THINK IT ]  <br> // +----------------------------------------------------------------------  <br> // | Copyright (c) 2013 http://www.onethink.cn All rights reserved.  <br> // +----------------------------------------------------------------------  <br> // | Author: 麦当苗儿 <zuojiazi> <http:>  <br> // +----------------------------------------------------------------------  <br> namespace Addons\Wheel\Controller;  <br>   <br> class AdminController extends InitController  <br> {  <br>   <br>   <br>     // public function __construct()  <br>     // {  <br>     //     parent::__construct();  <br>     // }  <br>   <br>     public function index()  <br>     {  <br>         $config = M("AddonWheelConfig")->find();  <br>         $this->assign("config", $config);  <br>   <br>         $record = D('Addons://Wheel/AddonWheelRecord'); // 实例化User对象  <br>         $count = $record->count();// 查询满足要求的总记录数  <br>         $Page = new \Think\Page($count, 12);// 实例化分页类 传入总记录数和每页显示的记录数(25)  <br>         $Page->setConfig('theme', "<div><ul> <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></li> </ul></div>");  <br>         $show = $Page->show();// 分页显示输出  <br>         // 进行分页数据查询 注意limit方法的参数要使用Page类的属性  <br>         $record = $record->limit($Page->firstRow . ',' . $Page->listRows)->order("id desc")->relation(true)->select();  <br>   <br>         $this->assign("record", $record);// 赋值数据集  <br>         $this->assign('page', $show);// 赋值分页输出  <br>   <br>         $this->display();  <br>     }  <br>   <br>     public function addConfig()  <br>     {  <br>         M("AddonWheelConfig")->where(array("id" => "1"))->save($_POST);  <br>         $this->success('设置成功', 'Admin/Admin/index/addon/Wheel');  <br>     }  <br> }  </http:></zuojiazi>
IndexController.class<?php <br /> /** <br>  * Created by PhpStorm. <br>  * User: heqing <br>  * Date: 15/7/30 <br>  * Time: 09:40 <br>  */  <br>   <br> namespace Addons\Wheel\Controller;  <br>   <br> // class IndexController extends InitController  <br> // {  <br> //     public function index()  <br> //     {  <br> //         $this->show('SystemInfo Index index');  <br> //     }  <br>   <br>   <br> // }  <br>   <br> class IndexController extends InitController  <br> {  <br>     public $appUrl = "";  <br>     public function __construct()  <br>     {  <br>         parent::__construct();  <br>         $this->appUrl = "http://" . I("server.HTTP_HOST");  <br>     }  <br>   <br>     public function init()  <br>     {  <br>         return R("App/Common/init");  <br>     }  <br>   <br>     public function oauthRegister($wxuser)  <br>     {  <br>         return R("App/Common/oauthRegister", array($wxuser));  <br>     }  <br>   <br>     public function index()  <br>     {  <br>         $user=R("App/Public/oauthLogin");  <br>   <br>         // if (!session("userUid")) {  <br>         //     $weObj = $this->init();  <br>         //     $token = $weObj->getOauthAccessToken();  <br>         //     if (!$token) {  <br>         //         $weObj = $this->init();  <br>         //         $url = $weObj->getOauthRedirect($this->appUrl . u_addons('Wheel://App/Index/index'));  <br>         //         header("location: $url");  <br>         //         return;  <br>         //     } else {  <br>         //         $wxuser = $weObj->getOauthUserinfo($token["access_token"], $token["openid"]);  <br>         //         session("userUid", $wxuser["openid"]);  <br>         //         $this->oauthRegister($wxuser);  <br>         //     }  <br>         // }  <br>   <br>         $user = M("User")->where(array("uid" => session("userUid")))->find();  <br>   <br>         $config = M("AddonWheelConfig")->find();  <br>         $this->assign("config", $config);  <br>         $this->assign("user", $user);  <br>   <br>         $record = M("AddonWheelRecord")->where(array("user_id" => session("userId")))->order("id desc")->find();  <br>         $this->assign("record", $record);  <br>         $this->display();  <br>     }  <br>   <br>     /** <br>      * 中奖机率计算 <br>      */  <br>     function lotteryJson()  <br>     {  <br>         $today = date("Y-m-d");  <br>         $where["time"] = array("like", $today . "%");  <br>         $where["user_id"] = session("userId");  <br>         $record = D("Addons://Wheel/AddonWheelRecord")->where($where)->find();  <br>         if ($record) {  <br>             $this->ajaxReturn("-1");  <br>             return;  <br>         }  <br>   <br>         $config = M("AddonWheelConfig")->find();  <br>         //奖品概率  <br>         $proArr = array(  <br>             '1' => $config["level1_prob"],   <br>             '2' => $config["level2_prob"],   <br>             '3' => $config["level3_prob"],   <br>             '4' => $config["level4_prob"],   <br>             '5' => $config["level5_prob"],   <br>             '6' => $config["level6_prob"],   <br>             '7' => $config["level7_prob"]  <br>         );  <br>         //奖品库存  <br>         $proCount = array(  <br>             '1' => $config["level1_store"],  <br>             '2' => $config["level2_store"],  <br>             '3' => $config["level3_store"],  <br>             '4' => $config["level4_store"],  <br>             '5' => $config["level5_store"],  <br>             '6' => $config["level6_store"],  <br>             '7' => $config["level7_store"]  <br>         );  <br>         $file = './Data/wheel.txt';  <br>         $data = array(  <br>             '1' => 0, '2' => 0, '3' => 0, '4' => 0, '5' => 0, '6' => 0  <br>         );  <br>         if (!file_exists($file)) {  <br>             file_put_contents($file, serialize($data));  <br>         } else {  <br>             $str = file_get_contents($file);  <br>             $data = unserialize($str);  <br>         }  <br>         $rid = $this->getRand($proArr, $proCount);  <br>   <br>         if ($rid > 6) {  <br>             $rid = 0;  <br>         } else {  <br>             $rid = $this->returnRid($rid, $file, $data, $proCount, $proArr);  <br>         }  <br>   <br>         M("AddonWheelRecord")->add(array("user_id" => session("userId"), "level" => $rid));  <br>         echo $rid;  <br>     }  <br>   <br>     function returnRid($rid, $file, $data, $proCount, $proArr)  <br>     {  <br>         $data[$rid] = $data[$rid] + 1;  <br>         $count = $proCount[$rid]; // 总库存  <br>         if ($count              // 如果抽取的数据大于总库存时库存清0  <br>             $proCount[$rid] = 0;  <br>             // 然后继续计算一直计算出某个值的库存不为0  <br>             $rid = returnRid($rid, $file, $data, $proCount, $proArr);  <br>         } else {  <br>             // 写入缓存  <br>             file_put_contents($file, serialize($data));  <br>         }  <br>         return $rid;  <br>     }  <br>   <br>     /** <br>      * 中奖概率计算, 能用 <br>      * $proArr = array('1'=>'概率', '2'=>'概率'); <br>      * $proCount = array('1'=>'库存', '2'=>'库存'); <br>      */  <br>     function getRand($proArr, $proCount)  <br>     {  <br>         $result = '';  <br>         $proSum = 0;  <br>         foreach ($proCount as $key => $val) {  <br>             if ($val                  continue;  <br>             } else {  <br>                 $proSum = $proSum + $proArr[$key];  <br>             }  <br>         }  <br>         foreach ($proArr as $key => $proCur) {  <br>             if ($proCount[$key]                  continue;  <br>             } else {  <br>                 $randNum = mt_rand(1, $proSum);  <br>                 if ($randNum                      $result = $key;  <br>                     break;  <br>                 } else {  <br>                     $proSum -= $proCur;  <br>                 }  <br>             }  <br>         }  <br>         unset($proArr);  <br>         return $result;  <br>     }  <br> }  
InitController.class<?php <br /> /** <br>  * Created by PhpStorm. <br>  * User: heqing <br>  * Date: 15/7/30 <br>  * Time: 12:11 <br>  */  <br>   <br> namespace Addons\Wheel\Controller;  <br>   <br>   <br> use Common\Controller\Addon;  <br>   <br> class InitController extends Addon  <br> {  <br>   <br>     public function install()  <br>     {  <br>         $install_sql = './Addons/Wheel/Data/install.sql';  <br>         if (file_exists($install_sql)) {  <br>             execute_sql_file($install_sql);  <br>         }  <br>          $this->success("安装成功", "Admin/Addon/addon");  <br>     }  <br>   <br>     public function uninstall()  <br>     {  <br>         $uninstall_sql = './Addons/Wheel/Data/uninstall.sql';  <br>         if (file_exists($uninstall_sql)) {  <br>             execute_sql_file($uninstall_sql);  <br>         }  <br>         $this->success("卸载成功", "Admin/Addon/addon");  <br>     }  <br> }  
前台
Admin_index <section>  <br>     <h1>  <br>         大转盘管理  <br>         <small></small>  <br>     </h1>  <br> </section>   <br>  <section>  <br>     <div>  <br>         <div>  <br>             <div>  <br>                 <div>  <br>                     <h3>大转盘设置</h3>    <br> <!-- /.box-tools -->  <br>   </div>  <br>                   <br>           <br>                             <div>  <br>                                 <div>  <br>                                     <div>  <br>                             <a><i></i>大转盘设置</a>  <br>                         </div>      <br>                         <div>  <br>                             <a><i></i>大转盘记录</a>  <br>                         </div>  <br>                                  <br>                                 <div>  <br>                                     <div>  <br>                                         <p>  <br>                                             </p> <form>  <br>                                                 <div>  <br>                                                     <label>大转盘名称</label>  <br>                                                     <div>  <br>                                                         <input>  <br>                                                     </div>  <br>                                                 </div>  <br>                                                 <div>  <br>                                                     <label>活动时间</label>  <br>                                                     <div>  <br>                                                         <input>  <br>                                                     </div>  <br>                                                 </div>  <br>                                                 <div>  <br>                                                     <label>活动说明</label>  <br>                                                     <div>  <br>                                                         <!--style给定宽度可以影响编辑器的最终宽度-->  <br>                                                         <script> <br /> {$config.activity_explain} <br /> <br /> </script>  <br>                                                     </div>  <br>                                                 </div>  <br>                                                 <div>  <br>                                                     <label>状态</label>  <br>                                                     <div>  <br>                                                         <select>  <br>                                                             <option>是</option>  <br>                                                             <option>否</option>  <br>                                                         </select>  <br>                                                     </div>  <br>                                                 </div>  <br>                                                 <div>  <br>                                                     <label>一天参与一次</label>  <br>                                                     <div>  <br>                                                         <select>  <br>                                                             <option>是</option>  <br>                                                             <option>否</option>  <br>                                                         </select>  <br>                                                     </div>  <br>                                                 </div>  <br>                                                 <div>  <br>                                                     <label>一等奖中奖概率</label>  <br>                                                     <div>  <br>                                                         <input>  <br>                                                     </div>  <br>                                                     <label>一等奖库存</label>  <br>                                                     <div>  <br>                                                         <input>  <br>                                                     </div>  <br>                                                 </div>  <br>                                                 <div>  <br>                                                     <label>二等奖中奖概率</label>  <br>                                                     <div>  <br>                                                         <input>  <br>                                                     </div>  <br>                                                     <label>二等奖库存</label>  <br>                                                     <div>  <br>                                                         <input>  <br>                                                     </div>  <br>                                                 </div>  <br>                                                 <div>  <br>                                                     <label>三等奖中奖概率</label>  <br>                                                     <div>  <br>                                                         <input>  <br>                                                     </div>  <br>                                                     <label>三等奖库存</label>  <br>                                                     <div>  <br>                                                         <input>  <br>                                                     </div>  <br>                                                 </div>  <br>                                                 <div>  <br>                                                     <label>四等奖中奖概率</label>  <br>                                                     <div>  <br>                                                         <input>  <br>                                                     </div>  <br>                                                     <label>四等奖库存</label>  <br>                                                     <div>  <br>                                                         <input>  <br>                                                     </div>  <br>                                                 </div>  <br>                                                 <div>  <br>                                                     <label>五等奖中奖概率</label>  <br>                                                     <div>  <br>                                                         <input>  <br>                                                     </div>  <br>                                                     <label>五等奖库存</label>  <br>                                                     <div>  <br>                                                         <input>  <br>                                                     </div>  <br>                                                 </div>  <br>                                                 <div></div> </form> </div> </div> </div> </div> </div> </div> </div></section>

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn