首页 > php教程 > php手册 > 正文

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

php中文网
发布: 2016-10-09 08:32:17
原创
1735人浏览过

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

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

AdminController.class // +----------------------------------------------------------------------  
// | OneThink [ WE CAN DO IT JUST THINK IT ]  
// +----------------------------------------------------------------------  
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.  
// +----------------------------------------------------------------------  
// | Author: 麦当苗儿    
// +----------------------------------------------------------------------  
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', "

");  
        $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 /** 
 * 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              // 如果抽取的数据大于总库存时库存清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                  continue;  
            } else {  
                $proSum = $proSum + $proArr[$key];  
            }  
        }  
        foreach ($proArr as $key => $proCur) {  
            if ($proCount[$key]                  continue;  
            } else {  
                $randNum = mt_rand(1, $proSum);  
                if ($randNum                      $result = $key;  
                    break;  
                } else {  
                    $proSum -= $proCur;  
                }  
            }  
        }  
        unset($proArr);  
        return $result;  
    }  
}  
InitController.class /** 
 * 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 
  
    

  
        大转盘管理  
          
    

  
   
 
  
    
  
        
  
            
  
                
  
                    

大转盘设置

    
  
  
  
                  
          
                            
  
                                
  
                                    
  
                            大转盘设置  
                        
      
                        
  
                            大转盘记录  
                        
  
                                 
                                
  
                                    
  
                                        

  
                                            

  
                                                
  
                                                      
                                                    
  
                                                          
                                                    
  
                                                
  
                                                
  
                                                      
                                                    
  
                                                          
                                                    
  
                                                
  
                                                
  
                                                      
                                                    
  
                                                          
                                                        <script> <br /> {$config.activity_explain} <br /> <br /> </script>  
                                                    
  
                                                
  
                                                
  
                                                      
                                                    
  
                                                          
                                                    
  
                                                
  
                                                
  
                                                      
                                                    
  
                                                          
                                                    
  
                                                
  
                                                
  
                                                      
                                                    
  
                                                          
                                                    
  
                                                      
                                                    
  
                                                          
                                                    
  
                                                
  
                                                
  
                                                      
                                                    
  
                                                          
                                                    
  
                                                      
                                                    
  
                                                          
                                                    
  
                                                
  
                                                
  
                                                      
                                                    
  
                                                          
                                                    
  
                                                      
                                                    
  
                                                          
                                                    
  
                                                
  
                                                
  
                                                      
                                                    
  
                                                          
                                                    
  
                                                      
                                                    
  
                                                          
                                                    
  
                                                
  
                                                
  
                                                      
                                                    
  
                                                          
                                                    
  
                                                      
                                                    
  
                                                          
                                                    
  
                                                
  
                                                

微信app下载
微信app下载

微信是一款手机通信软件,支持通过手机网络发送语音短信、视频、图片和文字。微信可以单聊及群聊,还能根据地理位置找到附近的人,带给大家全新的移动沟通体验,有需要的小伙伴快来保存下载体验吧!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号