WeMall微信商城源碼插件大轉盤代碼是用於商業推廣的比較有效的方式,分享了部分比較重要的代碼,供技術員學習參考
WeMall微信商城源碼插件大轉盤代碼是用於商業推廣的比較有效的方式,分享了部分比較重要的程式碼,供技術員學習參考
代碼詳情地址:http://addon.wemallshop.com/Product/addonList/menu_id/1 或 www.wemallshop.com
AdminController.class<?php <?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 AddonsWheelController; <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 ThinkPage($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>%LINK_PAGE%</li>
<li>%DOWN_PAGE%%%%% %TOTAL_PAGE % 頁<a></a>
</li>
</ul>"); <br>
$show = $Page->show();// 分頁顯示輸出 <br>
// 進行分頁資料查詢 注意limit方法的參數要使用Page類別的屬性 <br>
$record = $record->limit($Page->firstRow . ',' . $Page->listRows)->order("id desc")->rellect(truePage->listRows)->order("id
<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>
} <br>
<br>IndexController.class<b></b><?php <code class="prettyprint linenums lang-php">
/** <?php <br />
* 由 PhpStorm 建立。 <br>
* 用戶:heqing<br>
* 日期:15/7/30 <br>
*時間:09:40<br>
*/ <br>
<br>
namespace AddonsWheelController; <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'));
// header("location: $url"); <br> // 返回; <br>
// } 其他 { <br>
// $wxuser = $weObj->getOauthUserinfo($token["access_token"], $token["openid"]); <br>
// session("userUid", $wxuser["openid"]); <br>
// $this->oauthRegister($wxuser); <br>
// } <br>
// } <br>
<br>
$user=M("用戶")->where(array("uid"=>session("userUid")))->find(); <br>
<br>
$config = M("AddonWheelConfig")->find(); <br>
$this->分配(“配置”, $config); <br>
$this->assign("用戶", $user); <br>
<br>
$record = M("AddonWheelRecord")->where(array("user_id" => session("userId")))->order("id desc")->find(); <br>
$this->分配("記錄", $記錄); <br>
$this->顯示(); <br>
} <br>
<br>
/** <br>
* 中獎機率計算 <br>
*/ <br>
函數lotteryJson() <br>
{ <br>
$今天 = 日期("年-月-日"); <br>
$where["time"] = array("like", $today."%"); <br>
$where["user_id"] = 會話("userId"); <br>
$record = D("Addons://Wheel/AddonWheelRecord")->where($where)->find(); <br>
如果($記錄){ <br>
$this->ajaxReturn("-1"); <br>
返回; <br>
} <br>
<br>
$config = M("AddonWheelConfig")->find(); <br>
//獎品機率 <br>
$proArr = 備份( <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 = 備份( <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>
$資料=陣列(<br>
'1' => 0, '2' => 0, '3' => 0, '4' => 0, '5' => 0, '6' => 0 <br>
); <br>
if (!file_exists($file)) { <br>
file_put_contents($file, 序列化($data)); <br>
} 其他 { <br>
$str = file_get_contents($file); <br>
$data = 反序列化($str); <br>
} <br>
$rid = $this->getRand($proArr, $proCount); <br>
<br>
如果($rid > 6){ <br>
$rid=0; <br>
} 其他 { <br>
$rid = $this->returnRid($rid, $file, $data, $proCount, $proArr); <br>
} <br>
<br>
M("AddonWheelRecord")->add(array("user_id" => session("userId"), "level" => $rid)); <br>
迴聲 $rid; <br>
} <br>
<br>
函數 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>
} 其他 { <br>
// 寫入記憶體 <br>
file_put_contents($file, 序列化($data)); <br>
} <br>
與$rid; <br>
} <br>
<br>
/** <br>
* 中獎機率計算, 能用<br>
* $proArr = array('1'=>'機率', '2'=>'機率'); <br> * $proCount = array('1'=>'庫存', '2'=>'庫存'); <br>
*/ <br>
函數 getRand($proArr, $proCount) <br>
{ <br>
$結果 = ''; <br>
$proSum = 0; <br>
foreach($proCount as $key => $val){ <br>
if ($val
則續中; <br>
} 其他 { <br>
$proSum=$proSum+$proArr[$key]; <br>
} <br>
} <br>
foreach($proArr as $key => $proCur){ <br>
if ($proCount[$key]
則續中; <br>
} 其他 { <br>
$randNum = mt_rand(1, $proSum); <br>
if ($randNum
$結果=$鍵; <br>
休息; <br>
} 其他 { <br>
$proSum -= $proCur; <br>
} <br>
} <br>
} <br>
取消設定($proArr); <br>
返回$結果; <br>
} <br>
} <br>
<b>InitController.class</b><code class="prettyprint linenums lang-php"><?php <?php <br />
/** <br>
* 由 PhpStorm 建立。 <br>
* 用戶:heqing<br>
* 日期:15/7/30 <br>
* 時間:12:11<br>
*/ <br>
<br>
命名空間 AddonsWheelController; <br>
<br>
<br>
使用CommonControllerAddon; <br>
<br>
類別 InitController 擴展了 Addon <br>
{ <br>
<br>
公用函數 install() <br>
{ <br>
$install_sql='./Addons/Wheel/Data/install.sql'; <br>
如果(file_exists($install_sql)){ <br>
執行_sql_file($install_sql); <br>
} <br>
$this->success("安裝成功", "Admin/Addon/addon"); <br>
} <br>
<br>
公用函數卸載()<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> <br>
<br>
<div> <br>
<div>
<br>
<br>
<div>
<br>
<label>
<br>
<div>
<br>是<label> </label>
<br>否<div> <br>
<select>
<br>
<div>
<br>
<label>是</label> <br>
<div>否<br> <select>
<br>
<br>
<div>
<br>
<label>
</label>
<br>
<div>
<br>
<label>
</label>
<br>
<div>
<br>
<label>
</label>
<br>
<div>
<br>
<label>
</label>
<br>
<div>
<br>
<label>
</label>
</div>
</div>
</div>
</div>
</div></select>
</div>
</div></select>
</div>
</div></label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div></section>