-
-
require_once (APP_ROOT . "./class/class_lib.php");
- require_once libfile('class/StoreProcs');
- pc_base::load_app_class('table_sub','',0);
- /**
- * 大轉盤
- * @author Administrator
- *
- */
- class lib_dzp_lottery extends app_lib {
- /**
- * 獎品表
- */
- public $lottery = 'activity_lyq_lottery';
- /**
- * 獎品日誌表
- */
- public $lottery_log = 'activity_lyq_lottery_log';
- /**
- * n等獎品
- */
- private $level = array();
- /**
- * 獎品資訊
- */
- private $lotteryArray = array();
- /***
- * 隨機數結束位數
- */
- 私人 $max = 30000;
- /**
- * 類別 true:預設false:掌蘇
- */
- private $type=true;
- /**
- * 中獎專業戶
- */
- private $tel_zy=false;
- /**
- * 讀取配置
- */
- public function load_setting() {
- $data=getcache('lyqdzp_setting');
- define('TIME', time()); //目前時間
- define('L_START', strtotime($data['l_start'])); // 報名開始時間
- define('L_END', strtotime($data['l_end'])); // 報名結束時間,-1意思昨天 23:59:59
- define('L_DAY_START',$data['l_day_start']); //每天開始時間
- define('L_DAY_END', $data['l_day_end']);//每天結束時間
- define('L_DAY_CISHU', $data['l_day_cishu']);//每天取得獎品數量
- define('L_CISHU', $data['l_cishu']);//總共獲得獎品數量
- define('L_MIN', 20);//最少來福幣
- define(' L_LFB', $data['l_lfb']);//減少來福幣
- define('L_ZY', $data['l_zy']); //專業戶
- define('L_QUANSHU', $data['l_quanshu']);//圈數,大轉盤開始圈數
- define('L_KONGJIANG', intval($data['l_kongjian']) );//空獎機率
- $host='www.****.com'; //現網
- if($_SERVER['HTTP_HOST']=='221.****0'){
- $host='221.*****'; //測試機
- }elseif($_SERVER['HTTP_HOST']=='125.com'){
- $host='125life.com';//本地
- }elseif(strpos($ _SERVER['HTTP_HOST'],'192.168.')==0){
- $host=$_SERVER['HTTP_HOST'].'/125e.com';//本地
- }
- define( 'L_SITE', 'http://'.$host.'/'); //網域最後加/
- define('L_URL', L_SITE.'index.php');//存取位址
-
- //只能透過flash位址存取
- $s=L_SITE. 'flash/dzp/i.swf';
- if(preg_replace('/swf.*$/','swf',$_SERVER['HTTP_REFERER'])!=$s&&$this->type){
- exit('老兄你已經得到了了達到達到多了,請透過正規途徑搖獎!
- }
- $this->load();
- }
- /**
- * 黑名單
- */
- private $heimingdan = array();
- /**
- * 讀取獎品配置
- */
- public function load() {
- $this->setlottery ();
- $this->heimingdan = getcache('tel', 'blanklist');
- }
- 導管函數 setlottery() {
- $time=strtotime(date('Y-m-d',TIME));
- $sql = "選擇 u.*";
- $sql .= ", (select COUNT(l.lotteryid) from " . DB::table ( $this->lottery_log ) . " AS l where u.lotteryid=l.lotteryid and l.isleading=' 1 ') 作為數字 “;
- $sql .= "來自" 。DB::table ( $this->lottery ) 。 “如你”;
- $sql .= " 其中 1 "; sql .= "和u.isdisable='0' ";
- $sql .= " 和u.time_start$sql .= " 和u.time_end>='$ time' ";
- $sql .= " ORDER BY u.listorder ";
- $d = DB::fetch_all ( $sql );
- $總和= 0;
- foreach ( $d as $r ) {
- $r ['sum_over'] = intval ( $r ['sum'] ) - intval ( $r ['num'] );
- if ($r ['sum'] > 0) {
- $sum += $r ['sum']
- $r['msg']=str_replace('{name}', $r['name'],$ r['msg']);
- $this->lotteryArray [$r ['lotteryid']] = $r;
- }
- if($sum$m = 1;
- $ 機率= 0
- $newsum=0
- //80%空獎+20%獎
- $this->max = $sum + $sum * (L_KONGJIANG/100) / ((100-L_KONGJIANG)/100);
- foreach ( $this->lotteryArray as $r ) {
- if ($r ['sum'] > 0) {
- $newsum=$r ['sum'];
- if( $r['機率']>0){
- $機率=0
- $probability=ceil($r ['sum'] *100/$r['機率']);
- if($probability>0){
- $newsum=$probability;
- }
- }
- $this->level [$r ['lotteryid']] ['start'] = $m;
- $this->level [$r ['lotteryid']] ['end'] = $m + $newsum;
- $m = $m + $r ['sum'];
- }
- }
- }
- /**
- * 偵測使用者是否中獎 0 謝謝參與,其他 回傳獎品data資料
- * @param array $user array(uid,tel,ip)
- */
- 公用函數檢定($user) {
- if (intval ( $user ['uid'] ) < ; 1) {
- //沒有登入
- return 0;
- }
- if(intval(TIME)//您來早了,活動還沒開始!
- }
- if(intval(TIME)>intval(L_END)){
- //已經過了活動時間,非常遺憾,謝謝!
- return -22;
- }
- if ($this->get_user_lfb ( $user ['uid'] ) //$this->credit ( $user ['uid '], -11, $logid );
- return -11; //您的來福幣餘額不足
- }
-
- $data = array(
- 'uid' => $ user ['uid'],
- 'tel' => $user ['tel'],
- 'ip' => $user ['ip'],
- 'addtime' => time ()
- );
- $logid = DB::insert ( $this->lottery_log, $data, true );
-
-
- //檢查使用者每天已中獎品數
- if ($this->get_lottery ( $user ['uid'], strtotime ( date ( 'Y-m-d', TIME ) ), strtotime ( "+1day", strtotime ( date ( 'Y-m-d', TIME ) ) ) , true ) >= L_DAY_CISHU) {
- $this->credit ( $user ['uid'], -12, $logid );
- //很遺憾,你本次什麼也沒抽到!
- return -12;
- }
- //檢查使用者全部已中獎品數
- if ($this->get_lottery ( $user ['uid'], 0, 0, true ) > L_CISHU&&L_CISHU >0) {
- $this->credit ( $user ['uid'], -12, $logid );
- //很遺憾,你這次什麼也沒抽到!
- return -15;
- }
- //偵測黑名單,設定機率
- if ($this->checkhei ( $user ['tel'] ) > 0) {
- $this ->credit ( $user ['uid'], -13, $logid );
- //很遺憾,你本次什麼都沒有抽到!
- return -13;
- }
- $lotteryid = $this->choujiang();
- $this->credit ( $user ['uid'], $lotteryidhao);
- if ($lotteryid > 0) {
- return $this->lotteryArray [$lotteryid];
- } else {
- return -4;
- }
- //-1獎品已發完
- //-2本時段獎品已玩
- //-3不發獎品
- //-4獎品有問題
- //-11您的來福幣餘額不足
- //-12很遺憾,你本次什麼都沒有抽到!
- //-13黑名單裡面,很遺憾,你本次什麼也沒抽到!
- //-14中獎專業戶禁止中高講高獎品
- //-15已超過yizhong總獎品數
- //-16 掌蘇傳遞手機號碼錯誤
- //-21您來早了,活動還沒開始!
- //-22已經過了活動時間,非常遺憾,謝謝!
- //-23對不起,現在不是活動時間,活動時間為每天
- }
- /**
- * 顯示
- * @param unknown_type $data
- */
- public function show($data){
- $ok= 0;//3中獎
- $zz=0;//轉盤度數
- $result='';//獎品名稱
- $lotteryid=0;//獎品ID
- if(is_array( $data)){
- $ok=3;
- $result=$data['msg'];
- $zz=$data['angle']+L_QUANSHU*360;
- $lotteryid =$data['lotteryid'];
- }else{
- $m='';
- switch($data){
- case 0:{
- $m= '請先登入! ';
- }break;
- case -11:{
- $m= '您的來福幣餘額不足! ';
- }break;
- case -12:{
- $m= '很遺憾,你這次什麼也沒抽到! ';
- }break;
- case -21:{
- $m= '您來早了,活動還沒開始! ';
- }break;
- case -22:{
- $m= '已經過了活動時間,非常遺憾,謝謝! ';
- }break;
- case -23:{
- $m= '對不起,現在不是活動時間,活動時間為每天'.L_DAY_START.':00-'.L_DAY_END.':00' ;
- }break;
- default:{
- $m= '很遺憾,你這次什麼都沒有抽到!';
- }休息;
- }
- $結果=$m;
- $ok=3;//3中獎
- $zz=360+L_QUANSHU*360;//再接再厲
- }
- header("Expires:Mon,26Jul199705:00:00GMT");
- header("快取控制:無緩存,必須重新驗證");
- header("Pragma:no-cache" );
- header("內容類型:text/html;charset=utf-8");
- if(!$this->type){
- echo json_encode(array('return'=>$ lotteryid,
- 'msg'=>$result));
- }else{
- echo ''."n";
- echo ''."n";
- echo ''."n";
- echo ''."n";
- }
- 退出;
- }
- /**
- * 抽獎的號碼
- */
- private $hao=0;
- /**
- * 抽獎開始
- */
- 私有函數choujian() {
- $j = 0;
- $lotteryid = 0;
- $j = mt_rand ( 1, $this->max );
- $this->hao=$j;
- foreach ( $this->level as $k = > $r ) {
- if ($r ['start'] $j ) {
- $lotteryid = $k;
- 休息;
- }
- }
- $d = array(
- 1 => array(
- 'time' => strtotime ( date ( 'Y-m-d 00:00:00', TIME ) ) ,
- 'time_end' => strtotime ( date ( 'Y-m-d 07:59:59', TIME ) )
- )
- );
- for ($i=2;$i$d[$i]=array(
- 'time' => strtotime ( date ( 'Y-m-d '.( $i+6).':00:00', TIME ) ),
- ' time_end' => strtotime ( date ( 'Y-m-d '.($i+6).':59:59', TIME ) )
- );
- }
- if($lotteryid>0){
- $l=$this->lotteryArray [$lotteryid];
- $sql = "從" 選取count(*) m 。 DB::table ( $this->lottery_log );
- $sql .= " 其中lotteryid='$lotteryid' ";
- $s= intval ( DB::result_first ( $sql ) );
- $sum_over=$l['sum']-$s;
- if($sum_over>0){
- //本贏得獎品數
- $sum=0;
- foreach ($d as $k=>$r){
- if(TIME>=$r['time']&&TIMEif($ l['time_'.$k] >0){//個數限制
- $sum=$this->get_lottery_id(0,$r['time'],$r['time_end']+ 1,$lotteryid);
- if( $sum>=$l['time_'.$k]){
- //本獎勵品已玩
- $lotteryid=-2;
- 休息;
- }
- }elseif ( $l['time_'.$k]==0){
- //不發獎品
- $lotteryid=-3;
- 休息;
- }else{
- //-1不限制
- }
-
- }
- }
- if($this->tel_zy && $lotteryid>0&&$lotteryid$lotteryid=-14
- ; }
- }else{
- //獎品已發完
- $lotteryid=-1;
- }
- }else{
- //獎品有問題
- $lotteryid=- 4;
- }
- 回傳$lotteryid;
-
- }
- /**
- * 偵測黑名單與一般使用者,機率
- * @param string $tel
- * @return 大於1 表示本次禁止抽
- */
- 私有函數checkhei($tel) {
- $n = mt_rand (rand (rand] 1, 100 );
- if (in_array ( $tel, $this->heimingdan ['tel'] ) && L_ZY > 0) {
- $this->tel_zy=true;
- if ($n > L_ZY) {
- 回傳1;
- }
- }else{
- //號碼偵測
- if (!self::check_tel($tel)) {
- return 1;
- }
- }
- 回傳0;
- }
- /**
- * 合計獎品數
- * @param intval $uid
- * @param intval $start
- * @param intval $end
- * @param bool $bool true 獲得獎品數false 未獲得獎品數
- * @return number
- */
- 私有函數get_lottery($uid = 0, $start = 0, $end = 0, $bool = false) {
- $sql = "從" 選取count(*) m 。 DB::table ( $this->lottery_log );
- $sql .= " 其中1 ";
- if (intval ( $start ) > 0) {
- $sql .= " and addtime>= '$start' ";
- }
- if (intval ( $end ) > 0) {
- $sql .= " and addtime}
- if ( $bool) {
- $sql .= " and lotteryid>0 ";
- }
- if (intval ( $uid ) > 0) {
- $sql .= " and uid='$uid ' ";
- }
- return intval ( DB::result_first ( $sql ) );
- }
- /**
- * 合計獎品數
- * @param intval $uid
- * @param intval $start
- * @param intval $end
- * @param intval $bool 獎品id
- * return number
- */
- 私有函數_lottery_id($uid = 0, $start = 0, $end = 0, $lotteryid = 0) {
-
- $ sql = "從" 選擇count(*) m 。 DB::table ( $this->lottery_log );
- $sql .= " 其中1 ";
- if (intval ( $start ) > 0) {
- $sql .= " and addtime>= '$start' ";
- }
- if (intval ( $end ) > 0) {
- $sql .= " and addtime}
- if ( $lotteryid>=0) {
- $sql .= " and lotteryid='$lotteryid' ";
- }
- if (intval ( $uid ) > 0) {
- $sql .= " and uid='$uid' ";
- }
- return intval ( DB::result_first ( $sql ) );
- }
- /**
- * 取得使用者來福幣
- * @param intval $uid
- * @return number
- */
- public function get_user_lfb($uid) {
- $sql = "從sz_common_member_count 選擇extcredits2 ";
- $sql .= " 其中1 ";
- $sql .= " and uid='$uid' ";
- return intval ( DB::result_first ( $ $sql ) );
- }
- /**
- * 記錄日誌和更新使用者來福幣
- * @param intval $uid
- * @param intval $r 回傳值
- * @param intval $logid
- * @param intval $otteryid
- */
- 私有函數積分($uid, $result, $logid = 0, $lotteryid = 0,$hao=0) {
- $data =大批();
- if ($lotteryid > 0) {
- $data ['lotteryid'] = $lotteryid;
- $data['iswining'] = 1;
- }
- $data['iswining'] = 1;
- }
- $ data ['結果'] = $結果;
- $data['hao'] = $hao;
- $data['HTTP_REFERER'] = $_SERVER['HTTP_REFERER'];
- DB::Update ( $this->lottery_log, $data, " logid='$logid' " );
- if (L_LFB > 0) {
- $sql = 'UPDATE sz_common_member_count SET extcredits2=extcredits2-' 。 L_LFB 。 ' 其中 uid=' 。 $uid;
- DB::query ( $sql );
- $this->credit_log ( $uid, 'reduce', L_LFB, 1, '積分清零活動' );
- }
- }
- /**
- *手機號碼檢查
- */
- 私有函數check_tel($tel){
- $ different_network=table_sub::get_ Different_network();
- if (!preg_match("/$ Different_work/$ ",$tel)) {
- 回傳false;
- }
- 回傳true;
- }
- /**
- * 預存程序連結
- */
- private $StoreProcs;
- /** *
- * 來福幣日誌預存程序
- * @param intval $uid
- * @param string $op add增加reduce 消耗
- * @param intval $creditvalue 來福幣 @param intval $credittype 1來福幣2來福點
- * @param string $oreason 說明
- */
- 私有函數credit_log($uid, $op, $creditvalue, $credittype, $oreason) {
- if (! $this->StoreProcs) {
- $this->StoreProcs = new StoreProcs ();
- }
- //呼叫預存程序
- $this->StoreProcs->query ( "call app_credit_log($uid,'$op','$credittype',1,$ creditvalue,'$原因')" );
- }
-
}
複製程式碼
三,呼叫:
-
-
-
$dzp=new lib_dzp_lottery();
- $u=array('uid'=>$_G ['uid '],'tel'=>$_G ['tel'],'ip'=> $_G ['clientip']) ;
- $dzp->load_setting();
- $dzp->show( $dzp->check($u));
?>
複製程式碼
|