lottery_luckyers.auto_cache.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. //$param['deal_id'],
  3. class lottery_luckyers_auto_cache extends auto_cache{
  4. public function load($param)
  5. {
  6. $key = $this->build_key(__CLASS__,$param);
  7. $GLOBALS['cache']->set_dir(APP_ROOT_PATH."public/runtime/data/".__CLASS__."/");
  8. $return = $GLOBALS['cache']->get($key);
  9. if($return === false)
  10. {
  11. $deal_id=intval($param['deal_id']);
  12. if($deal_id)
  13. {
  14. $winner_sn=array();//幸运号
  15. $sn_section=array();//幸运号所属号段;
  16. $deal_item_list=$GLOBALS['db']->getAll("select * from ".DB_PREFIX."deal_item where deal_id=".$deal_id." and type=2 order by id asc");
  17. foreach($deal_item_list as $k=>$v)
  18. {
  19. $lottery_list=$GLOBALS['db']->getAll("select lot.* from ".DB_PREFIX."deal_order_lottery as lot left join ".DB_PREFIX."deal_order as ord on ord.id = lot.order_id where lot.is_winner=0 and lot.deal_id=".$deal_id." and lot.deal_item_id=".$v['id']." and ord.order_status =3 order by id asc");
  20. if($lottery_list)
  21. {
  22. //总数
  23. $total_count=count($lottery_list);
  24. $lottery_numer=ceil($total_count/$v['lottery_measure']);
  25. $yu=$total_count%$v['lottery_measure'];
  26. for($i=1;$i<=$lottery_numer;++$i)
  27. {
  28. $time_sum=0;
  29. if( $i==$lottery_numer && $yu >0 )
  30. {
  31. $start_key=($i-1)*$v['lottery_measure'];
  32. $last_key=$total_count-1;
  33. $sum_last_key=$last_key;
  34. if($yu<10)
  35. {
  36. $last_itme=microtime_format($lottery_list[$sum_last_key]['time_msec'],'Hisx');
  37. $time_sum=$last_itme*10;
  38. }else
  39. {
  40. for($j=0;$j<10;++$j)
  41. {
  42. $time_sum+=microtime_format($lottery_list[$sum_last_key]['time_msec'],'Hisx');
  43. --$sum_last_key;
  44. }
  45. }
  46. }else
  47. {
  48. $start_key=($i-1)*$v['lottery_measure'];
  49. $last_key=$i*$v['lottery_measure']-1;
  50. $sum_last_key=$last_key;
  51. for($j=0;$j<10;++$j)
  52. {
  53. $time_sum+=microtime_format($lottery_list[$sum_last_key]['time_msec'],'Hisx');
  54. --$sum_last_key;
  55. }
  56. }
  57. if($i==$lottery_numer && $yu >0)
  58. $winner_num=$time_sum%$yu+10000001+($i-1)*$v['lottery_measure'];//最后一次,不满抽奖量数,按最后一次个数(余数)求余
  59. else
  60. $winner_num=$time_sum%$v['lottery_measure']+10000001+($i-1)*$v['lottery_measure'];
  61. $winner_sn[]=$v['id'].$winner_num;
  62. //list($start_item, $start_sn)=explode('_',$lottery_list[$start_key]['lottery_sn']);
  63. //list($last_item, $last_sn)=explode('_',$lottery_list[$last_key]['lottery_sn']);
  64. $start_sn_array=split_lottery_sn($lottery_list[$start_key]['lottery_sn']);
  65. $start_sn=$start_sn_array['sn_number'];
  66. $last_sn_array=split_lottery_sn($lottery_list[$last_key]['lottery_sn']);
  67. $last_sn=$last_sn_array['sn_number'];
  68. $sn_section[$v['id'].$winner_num]=array(
  69. 'number'=>$v['id']."_".$i,
  70. 'section_view'=>$lottery_list[$start_key]['lottery_sn']."~".$lottery_list[$last_key]['lottery_sn'],
  71. 'section'=>array('start_sn'=>$start_sn,'last_sn'=>$last_sn)
  72. );
  73. }
  74. //for end
  75. }//if end
  76. }//foreach end
  77. $winner_list=$GLOBALS['db']->getAll("select lot.*,ord.deal_price from ".DB_PREFIX."deal_order_lottery as lot left join ".DB_PREFIX."deal_order as ord on ord.id = lot.order_id where lot.deal_id=".$deal_id." and lot.lottery_sn in ('".implode("','",$winner_sn)."') and ord.order_status =3 order by lot.id asc");
  78. $winner_list_array=array();
  79. foreach($winner_list as $k=>$v)
  80. {
  81. $key_val=$sn_section[$v['lottery_sn']]['number'];
  82. $winner_list_array[$key_val]=$v;
  83. $winner_list_array[$key_val]['number']=$key_val;
  84. $winner_list_array[$key_val]['section_view']=$sn_section[$v['lottery_sn']]['section_view'];
  85. $winner_list_array[$key_val]['section']=$sn_section[$v['lottery_sn']]['section'];
  86. }
  87. $return['winner_list']=$winner_list_array;
  88. }else{
  89. $return=array();
  90. }
  91. $GLOBALS['cache']->set_dir(APP_ROOT_PATH."public/runtime/data/".__CLASS__."/");
  92. $GLOBALS['cache']->set($key,$return);
  93. }
  94. return $return;
  95. }
  96. public function rm($param)
  97. {
  98. $key = $this->build_key(__CLASS__,$param);
  99. $GLOBALS['cache']->set_dir(APP_ROOT_PATH."public/runtime/data/".__CLASS__."/");
  100. $GLOBALS['cache']->rm($key);
  101. }
  102. public function clear_all()
  103. {
  104. $GLOBALS['cache']->set_dir(APP_ROOT_PATH."public/runtime/data/".__CLASS__."/");
  105. $GLOBALS['cache']->clear();
  106. }
  107. }
  108. ?>