//您来早了,活动还没有开始!

return -21;

}

if(intval(TIME)>intval(L_END)){

//已经过了活动时间,非常遗憾,谢谢!

return -22;

}

if ($this->get_user_lfb ( $user ['uid'] ) < L_MIN) {

//$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'], $lotteryid<1?$lotteryid:0, $logid, $lotteryid ,$this->hao);

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= '很遗憾,你本次什么也没有抽到!';

}break;

}

$result=$m;

$ok=3;//3中奖

$zz=360+L_QUANSHU*360;//再接再厉

}

header("Expires:Mon,26Jul199705:00:00GMT");

header("Cache-Control:no-cache,must-revalidate");

header("Pragma:no-cache");

header("Content-type: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";

}

exit;

}

/**

* 抽奖的号

*/

private $hao=0;

/**

* 抽奖开始

*/

private function choujiang() {

$j = 0;

$lotteryid = 0;

$j = mt_rand ( 1, $this->max );

$this->hao=$j;

foreach ( $this->level as $k => $r ) {

if ($r ['start'] <= $j && $r ['end'] > $j) {

$lotteryid = $k;

break;

}

}

$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<=17;$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 = "select count(*) m from " . DB::table ( $this->lottery_log );

$sql .= " where 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']&&TIME<=$r['time_end']){

if($l['time_'.$k]>0){//个数限制

$sum=$this->get_lottery_id(0,$r['time'],$r['time_end']+1,$lotteryid);

if($sum>=$l['time_'.$k]){

//本时段奖品已玩

$lotteryid=-2;

break;

}

}elseif ($l['time_'.$k]==0){

//不发奖品

$lotteryid=-3;

break;

}else{

//-1 不限制

}

}

}

if($this->tel_zy && $lotteryid>0&&$lotteryid<4){

$lotteryid=-14;

}

}else{

//奖品已发完

$lotteryid=-1;

}

}else{

//奖品有问题

$lotteryid=-4;

}

return $lotteryid;

}

/**

* 检测黑名单和普通用户,概率

* @param string $tel

* @return 大于1 表示本次禁止抽

*/

private function checkhei($tel) {

$n = mt_rand ( 1, 100 );

if (in_array ( $tel, $this->heimingdan ['tel'] ) && L_ZY > 0) {

$this->tel_zy=true;

if ($n > L_ZY) {

return 1;

}

}else{

//号码检测

if (!self::check_tel($tel)) {

return 1;

}

}

return 0;

}

/**

* 合计奖品数

* @param intval $uid

* @param intval $start

* @param intval $end

* @param bool $bool true 获得奖品数 false 不统计

* @return number

*/

private function get_lottery($uid = 0, $start = 0, $end = 0, $bool = false) {

$sql = "select count(*) m from " . DB::table ( $this->lottery_log );

$sql .= " where 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

*/

private function get_lottery_id($uid = 0, $start = 0, $end = 0, $lotteryid = 0) {

$sql = "select count(*) m from " . DB::table ( $this->lottery_log );

$sql .= " where 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 = "select extcredits2 from sz_common_member_count ";

$sql .= " where 1 ";

$sql .= " and uid='$uid' ";

return intval ( DB::result_first ( $sql ) );

}

/**

* 记录日志和更新用户来福币

* @param intval $uid

* @param intval $r 返回值

* @param intval $logid

* @param intval $lotteryid

*/

private function credit($uid, $result, $logid = 0, $lotteryid = 0,$hao=0) {

$data = array();

if ($lotteryid > 0) {

$data ['lotteryid'] = $lotteryid;

$data ['iswinning'] = 1;

}

$data ['result'] = $result;

$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 . ' WHERE uid=' . $uid;

DB::query ( $sql );

$this->credit_log ( $uid, 'reduce', L_LFB, 1, '积分清零活动' );

}

}

/**

*手机号检查

*/

private function check_tel($tel){

$different_network=table_sub::get_different_network();

if (!preg_match("/$different_network/",$tel)) {

return false;

}

return true;

}

/**

* 存储过程链接

*/

private $StoreProcs;

/**

* 来福币日志 存储过程

* @param intval $uid

* @param string $op add增加 reduce 消耗

* @param intval $creditvalue 来福币

* @param intval $credittype 1来福币 2来福点

* @param string $oreason 说明

*/

private function 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,'$oreason')" );

}

}

PHP 每小时抽奖,php分时间段的抽奖程序代码相关推荐

  1. 7-7 12-24小时制 (15 分)

    7-7 12-24小时制 (15 分) 编写一个程序,要求用户输入24小时制的时间,然后显示12小时制的时间. 输入格式: 输入在一行中给出带有中间的:符号(半角的冒号)的24小时制的时间,如12:3 ...

  2. 【PAT乙】1069 微博转发抽奖 (20分) set

    1069 微博转发抽奖 (20分) 小明 PAT 考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔 N 个人就发出一个红包.请你编写程序帮助他确定中奖名单. 输入格式: 输入第一行 ...

  3. linux分时间段循环执行脚本

    linux分时间段循环执行某脚本 解决方法: 假如我要把2017-01-01到2018-01-01时间段按6个月拆开执行脚本可以参考这个完整的sh脚本:http://www.yayihouse.com ...

  4. 1069 微博转发抽奖 (20分)

    1069 微博转发抽奖 (20分) 小明 PAT 考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔 N 个人就发出一个红包.请你编写程序帮助他确定中奖名单. 输入格式: 输入第一行 ...

  5. cron 表达式,每小时的XX分执行一次,每小时一次

    每小时一次,每次在该小时的10分开始执行: 0 10 0/1 * * ? 每小时一次,每次在该小时的35分开始执行: 0 35 0/1 * * ? 有这两个示例就能很直观的看出来,想调整到该时段的某分 ...

  6. PAT 乙级 1069 微博转发抽奖 (20 分)

    题目:PAT 乙级 1069 微博转发抽奖 (20 分) 经验总结: 可以建立一个set,用于存放中奖用户.若set中有此用户,代表此用户已中奖,奖品顺延. C++代码: #include<bi ...

  7. 1069 微博转发抽奖 (20 分)(算法分析+代码实现)

    1069 微博转发抽奖 (20 分) 题目链接 算法分析 用flag记录是否输出过获奖人名字 用map类型take记录某人是否拿走过奖品 用cnt记录间隔人数 然后按要求输出就好. 代码实现 #inc ...

  8. js处理人性化时间长度展示,1分钟以内显示秒数,1分钟以上1小时以内显示分钟数和秒数,1小时以上1天以内显示小时数和分钟数

    1分钟以内显示秒数 59秒 1分钟以上1小时以内显示分钟数和秒数 23分30秒 1小时以上1天以内显示小时数和分钟数 1小时20分 1天以上显示天数和小时数 3天21小时 核心代码 function ...

  9. 1069 微博转发抽奖 (20 分)

    1069 微博转发抽奖 (20 分) 小明 PAT 考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔 N 个人就发出一个红包.请你编写程序帮助他确定中奖名单. 输入格式: 输入第一 ...

最新文章

  1. 使用虚拟机运行Ubuntu时,主机与宿主机共享文件的方法。
  2. 【MyBatis】学习纪要六:动态SQL
  3. Codeforces Round #490 (Div. 3)
  4. 前后端分离的思考与实践
  5. java下载文件夹_java如何通过共享目录下载文件夹(有子文件夹)到本地目录?...
  6. Beta 冲刺 (4/7)
  7. VAE【keras实现】
  8. vue @click 如何绑定多个方法
  9. 1.2 文本域(含可编辑表格实现)
  10. git 应用 merge
  11. ElasticSearch的基本用法与集群搭建
  12. html5游戏开发-零基础开发《圣诞老人送礼物》小游戏
  13. Interface Project
  14. ET5.0 配置Excel
  15. 手机点餐APP开发需求分析
  16. C# 串口+示波+数据存储+截图
  17. 配置消息推送服务器,自动化部署和消息推送
  18. 瑞萨单片机boot程序中串口打印字符串乱码-问题记录
  19. 农夫过河实验报告c语言,农夫过河实验报告.doc
  20. 读Spring的源代码五:AutoWired是如何实现注入的

热门文章

  1. caffe matio问题
  2. [深度学习]Ubuntu16.04 + GTX 1050 + cuda8.0 + cuDNN5.1 + caffe安装详解
  3. Windows下用VS2013加载caffemodel做图像分类
  4. 颜色排序(Sort Colors)
  5. TiKV 源码解析系列文章(二)raft-rs proposal 示例情景分析
  6. 【计算机网络】聊一聊那些常见的网络通信的性能指标
  7. Linux实战案例(4)CentOS清除用户登录记录和命令历史方法
  8. AngularJS 学习
  9. linux下改变文件的字符编码
  10. [置顶]       设计模式之六大原则——单一职责原则(SRP)