时时彩号码的采集,以及开奖。

采集json串

{
    "rows": 5,
    "code": "cqssc",
    "info": "免费接口随机延迟3-6分钟,实时接口请访问opencai.net或QQ:23081452(注明彩票或API)",
    "data": [
        {
            "expect": "20171108058",
            "opencode": "9,7,6,9,8",
            "opentime": "2017-11-08 15:40:40",
            "opentimestamp": 1510126840
        },
        {
            "expect": "20171108057",
            "opencode": "8,8,4,2,4",
            "opentime": "2017-11-08 15:30:40",
            "opentimestamp": 1510126240
        },
        {
            "expect": "20171108056",
            "opencode": "1,5,8,5,9",
            "opentime": "2017-11-08 15:20:40",
            "opentimestamp": 1510125640
        },
        {
            "expect": "20171108055",
            "opencode": "7,9,2,0,9",
            "opentime": "2017-11-08 15:10:40",
            "opentimestamp": 1510125040
        },
        {
            "expect": "20171108054",
            "opencode": "7,6,9,4,4",
            "opentime": "2017-11-08 15:00:40",
            "opentimestamp": 1510124440
        }
    ]
}

//采集号码

 public function zdcj(){
        $ssc = json_decode(file_get_contents('http://f.apiplus.cn/cqssc.json'), true);
        $ssc = $ssc['data'][0];  //最新一期
        $date = preg_replace("/^(\d{8})(\d{3})$/", "$1-$2", $ssc['expect']);   //获取期数
        $haoma = str_replace(',', '', $ssc['opencode']); //号码格式
        $time = $ssc['opentimestamp']; //开奖时间
        $result = $this->db->GetOne("select * from `@#_shishi_1` where `qishu` = '$date'");
        if (!$result) {
            $this->db->Query("INSERT INTO `@#_shishi_1`(`qishu`,`haoma`,`time`) VALUES ('$date','$haoma','$time')");
            return $haoma;
        }
    }

$url = "http://ssc.buguyuan.cn/?/go/index/get_caipiao";
        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
        $ssc = curl_exec($ch);
        curl_close($ch);
        $ssc=json_decode($ssc,TRUE);
        $over_time=time()-$ssc['time'];
        if($ssc==NUll || $over_time>850){
            //获取普通接口
            $url = "http://a.tthaoduo.com/api/open_get?token=88vhxut6763nxa4q57&code=cqssc&format=json";
            $ch = curl_init();
            curl_setopt ($ch, CURLOPT_URL, $url);
            curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
            $ssc = curl_exec($ch);
            curl_close($ch);
            $ssc=json_decode($ssc,TRUE);
            $ssc = $ssc['data'][0];
            $date = preg_replace("/^(\d{8})(\d{3})$/", "$1-$2", $ssc['expect']);
            $haoma = str_replace(',', '', $ssc['opencode']);
            $time = $ssc['opentimestamp'];            
        }else{
            $date = $ssc['qishu'];
            $haoma =$ssc['haoma'];
               $time = $ssc['time'];
        }
        $result = $this->db->GetOne("select * from `@#_shishi_1` where `qishu` = '$date'");
        if (!$result) {
            $this->db->Query("INSERT INTO `@#_shishi_1`(`qishu`,`haoma`,`time`) VALUES ('$date','$haoma','$time')");
            return $haoma;
        }

 

 

//自动开奖

 public function zdkj(){
        $shoplist = $this->db->GetList("select * from `@#_shoplist` where `q_end_time` is not null and `jiexiao_time` = '0'");
        foreach($shoplist as $key=>$val){
            $code = $this->db->GetOne("select haoma,qishu from `@#_shishi_1` where `qishu` = '$val[caipiao_qishu]'");
            if ($code['haoma'] && $code['qishu'] == $val['caipiao_qishu']) {
                $haoma = $code['haoma'];
                $number = $val['q_counttime']+$haoma;
                $code = 10000001+fmod($number,intval($val['zongrenshu']));
                $time = time();
                if ($val['lucky_number']) {
                    $chazhi = $code - $val['lucky_number'];
                    $q_counttime = $val['q_counttime'] - $chazhi;
                    $u_go_info = $this->db->GetOne("select * from `@#_member_go_record` where `shopid` = '$val[id]' and `goucode` LIKE  '%$val[lucky_number]%'");
                    $u_info = $this->db->GetOne("select uid,username,email,mobile,auto_user,img from `@#_member` where `uid` = '$u_go_info[uid]'");
                    $code=$val['lucky_number'];
                    $u_info['user_ip'] = $u_go_info['ip'];
                    $userinfo = serialize($u_info);
                    $result1 = $this->db->Query("UPDATE `@#_member_go_record` SET `huode` = '$val[lucky_number]',`jx_time` = '$time',`is_tishi`=1 where `id` = '$u_go_info[id]' and `uid` = '$u_go_info[uid]' and `shopid` = '$val[id]'");
                    $result = $this->db->Query("UPDATE `@#_shoplist` set `q_counttime` = '$q_counttime',`q_uid` = '$u_info[uid]',`caipiao_haoma`='$haoma',`q_user`='$userinfo',`q_user_code`='$val[lucky_number]',`jiexiao_time`='$time' where `id`='$val[id]'");
                     
                   
                } else {
                    
                    $u_go_info = $this->db->GetOne("select * from `@#_member_go_record` where `shopid` = '$val[id]' and `goucode` LIKE  '%$code%'");
        
                    $u_info = $this->db->GetOne("select uid,username,email,mobile,auto_user,img from `@#_member` where `uid` = '$u_go_info[uid]'");
                    $u_info['user_ip'] = $u_go_info['ip'];
                    $userinfo = serialize($u_info);
                   
                    $result1 = $this->db->Query("UPDATE `@#_member_go_record` SET `huode` = '$code',`jx_time` = '$time',`is_tishi`=1 where `id` = '$u_go_info[id]' and `uid` = '$u_go_info[uid]' and `shopid` = '$val[id]'");
                    $result = $this->db->Query("UPDATE `@#_shoplist` set `q_uid` = '$u_info[uid]',`caipiao_haoma`='$haoma',`q_user`='$userinfo',`q_user_code`='$code',`jiexiao_time`='$time' where `id`='$val[id]'");
                }
                 if ($result && $result1 && $u_info['auto_user']!='1') {
                    $this->db->Autocommit_commit();
                    if ($u_info['mobile']) {
                        $content = $this->db->GetOne("select value from `@#_caches` where `key` = 'template_mobile_shop'");
                        if ($content) {
                            $content = str_ireplace('00000000', $code, $content['value']);
                        } else {
                            $content =  "你在"._cfg("web_name")."够买的商品已中奖,中奖码是:".$code;
                        }
                        _sendmobile($u_info['mobile'],$content);
                    }
                }else{
                    $this->db->Autocommit_rollback();
                    
                }
            }
        }
    }

 

 

  //生成下一期
    public function scxyq(){
        $shopid = $_REQUEST['id'];
        $shop = $this->db->GetOne("select * from `@#_shoplist` where `id` = '$shopid'");
        if($shop['qishu'] < $shop['maxqishu']){  
            $time = time();
            System::load_app_fun("content",G_ADMIN_DIR);        
            $goods = $shop;
            $qishu = $goods['qishu']+1;
            $shenyurenshu = $goods['zongrenshu'] - $goods['def_renshu'];
            $query_table = content_get_codes_table();
            $q_1 = $this->db->Query("INSERT INTO `@#_shoplist` (`sid`,`cateid`, `brandid`, `title`, `title_style`, `title2`, `keywords`, `description`, `money`, `yunjiage`, `zongrenshu`, `canyurenshu`,`shenyurenshu`,`def_renshu`, `qishu`,`maxqishu`,`thumb`, `picarr`, `content`,`codes_table`,`xsjx_time`,`renqi`,`pos`, `time`)
                    VALUES
                    ('$goods[sid]','$goods[cateid]','$goods[brandid]','$goods[title]','$goods[title_style]','$goods[title2]','$goods[keywords]','$goods[description]','$goods[money]','$goods[yunjiage]','$goods[zongrenshu]','$goods[def_renshu]','$shenyurenshu','$goods[def_renshu]','$qishu','$goods[maxqishu]','$goods[thumb]','$goods[picarr]','$goods[content]','$query_table','0','$goods[renqi]','$goods[pos]','$time')
                    ");             
            $id = $this->db->insert_id();       
            $q_2 = content_get_go_codes($goods['zongrenshu'],3000,$id);
            $q_3 = $this->db->Query("UPDATE `@#_shop` SET `canyurenshu`='$goods[def_renshu]',`shenyurenshu`='$shenyurenshu',`shopid`='$id' WHERE `sid`='$shop[sid]' ");
            if($q_1 && $q_2 && $q_3){
                  _message('自动生成成功!');
            }else{
                  _message('自动生成失败!');
            }
        }else{
                 _message('最大期数!');
            }
    }

 

 


    //手动开奖
       public function sdkj(){
        $id = $_REQUEST['id'];
        $qishu = $this->db->GetOne("select * from `@#_shoplist` where `id` = '$id'");
        if($qishu['is_miaokai']){
            $code['haoma'] = '00000';
        }else{
            if($qishu['caipiao_qishu'] == '00000'){
                 $code['haoma'] = '00000';
            }else{
                $code = $this->db->GetOne("select haoma from `@#_shishi_1` where `qishu` = '$qishu[caipiao_qishu]'");
                if (!$code) {
                    _message('没有采集这一期的中奖号码');
                }
            }
        }
        $haoma = $code['haoma'];
        $code = 10000001+fmod($qishu['q_counttime']+intval($code['haoma']),$qishu['zongrenshu']);
        $time = time();
        if ($qishu['lucky_number'] > 0) {
            $tocode->zd_lucky_number($qishu,intval($haoma));
            $content = addslashes($tocode->go_content);
            $counttime = $tocode->count_time;
            $this->db->Query("UPDATE `@#_shoplist` set `q_counttime` = '$counttime',`q_content` = '$content' where `id`='$qishu[id]'");
            $code = $val['lucky_number'];
                         
                       
        }else if(empty($qishu['lucky_number']) && $qishu['is_jiqi_zj'] == 1){
            $tocode->zd_zd_jq_zj($qishu,$haoma);
            $content = addslashes($tocode->go_content);
            $counttime = $tocode->count_time;
            $this->db->Query("UPDATE `@#_shoplist` set `q_counttime` = '$counttime',`q_content` = '$content' where `id`='$qishu[id]'");   
            $code = 10000001+fmod($counttime+intval($haoma),intval($qishu['zongrenshu']));                    
        }
            $u_go_info = $this->db->GetOne("select * from `@#_member_go_record` where `shopid` = '$id' and `goucode` LIKE  '%$code%'");
            $u_info = $this->db->GetOne("select uid,username,email,mobile,auto_user,img from `@#_member` where `uid` = '$u_go_info[uid]'");
            $u_info['user_ip'] = $u_go_info['ip'];
            $userinfo = serialize($u_info);
            
            $result1 = $this->db->Query("UPDATE `@#_member_go_record` SET `huode` = '$code',is_huode='1',`jx_time` = '$time',`is_tishi`=1 where `id` = '$u_go_info[id]' and `uid` = '$u_go_info[uid]' and `shopid` = '$id'");
            $result = $this->db->Query("UPDATE `@#_shoplist` set `q_uid` = '$u_info[uid]',`is_accomplish`='2',`q_user`='$userinfo',`caipiao_haoma`='$haoma',`q_user_code`='$code',`jiexiao_time`='$time' where `id`='$id'");
            
        
           if ($result && $result1 && $u_info['auto_user']!='1') {
            $this->db->Autocommit_commit();
                    if($qishu['is_room'] =='1'){
                             $roomshop=$this->db->Query("UPDATE `@#_roomshop` set `status`='2' where shopid='$id'");
                    }
                    if ($u_info['mobile']) {
                        $content = $this->db->GetOne("select value from `@#_caches` where `key` = 'template_mobile_shop'");
                        if ($content) {
                            $content = str_ireplace('00000000', $code, $content['value']);
                        } else {
                            $content =  "你在"._cfg("web_name")."够买的商品已中奖,中奖码是:".$code;
                        }
                        _sendmobile($u_info['mobile'],$content);
                    }

               $ext = array('中奖号码:'.$code, '商品ID:'.$id, '中奖人ID:'.$u_go_info[uid] );
               $this->admin_log('goodsLOG', '手动开奖', $ext);
            _messageadmin('恭喜你开奖成功了');
        }elseif($u_info['auto_user']==="1"){
           _messageadmin('开奖成功');
        }else{
            $this->db->Autocommit_rollback();
            _messageadmin('开奖失败');
        }
    }

posted @ 2017-11-08 16:36  肖张  阅读(1225)  评论(0编辑  收藏  举报