wemall微信商城源码插件大转盘代码是用于商业推广的比较有效的方式,分享了部分比较重要的代码,供技术员学习参考
wemall微信商城源码插件大转盘代码是用于商业推广的比较有效的方式,分享了部分比较重要的代码,供技术员学习参考
代码详情地址:http://addon.wemallshop.com/product/addonlist/menu_id/1 或 www.wemallshop.com
admincontroller.classfind();
$this->assign(config, $config);
$record = d('addons://wheel/addonwheelrecord'); // 实例化user对象
$count = $record->count();// 查询满足要求的总记录数
$page = new \think\page($count, 12);// 实例化分页类 传入总记录数和每页显示的记录数(25)
$page->setconfig('theme', %first%%up_page%%link_page%%down_page%%end% %header% %now_page%/%total_page% 页
);
$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.classshow('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.classsuccess(安装成功, 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
大转盘管理
大转盘设置
大转盘设置
大转盘记录
大转盘名称
活动时间
活动说明
状态
是
否
一天参与一次
是
否
一等奖中奖概率
一等奖库存
二等奖中奖概率
二等奖库存
三等奖中奖概率
三等奖库存
四等奖中奖概率
四等奖库存
五等奖中奖概率
五等奖库存