欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

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

程序员文章站 2022-03-13 22:21:39
...
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


大转盘管理








大转盘设置
































































































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

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

相关文章

相关视频


网友评论

文明上网理性发言,请遵守 新闻评论服务协议

我要评论
  • WeMall微信商城源码插件大转盘代码详情
  • 专题推荐

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

    认证0级讲师

    推荐视频教程
  • WeMall微信商城源码插件大转盘代码详情javascript初级视频教程
  • WeMall微信商城源码插件大转盘代码详情jquery 基础视频教程
  • 视频教程分类