<?php
error_reporting(0); 
include("../../config/qiantai.php");
session_start();
if(!isset($_SESSION['username'])){echo "<script>alert('请重新登录!')</script><script>top.location.href='index$dshz'</script>";exit;}
$username=$_SESSION['username'];
$type="where name='$username'";
$user=queryall(user,$type);
$userid=$user['userid'];
if(!$user){echo "<script>alert('请重新登录!')</script><script>top.location.href='index$dshz'</script>";exit;}
if($_POST){
$postid=ubo($_POST['id']);
$name=ubo(iconv("UTF-8","GB2312",$_POST['name']));
$zt=ubo($_POST['zt']);
$lx=ubo($_POST[lx]);
if($lx=='pltj'){
$postid=ubo($_POST['id']);
$ids=rtrim($postid, ','); 
$idsArray = explode(",",$ids);
foreach ($idsArray as $id){
$type="where id='$id'";
$xitong=queryall(shipin,$type);
//读取分类信息
$type="where id='$xitong[flid]'";
$fl=queryall(fenlei,$type);
$flname=$fl[name];
$type="where name='$flname' and userid='$userid'";
$dlfl=queryall(dlfl,$type);
if($dlfl){
$flid=$dlfl[id];
}else{
if($fl){
$type="(`id`, `name`, `userid`, `yc`) VALUES (null,'$flname','$userid','1')"; 
dbinsert(dlfl,$type);
$type="where name='$flname' and userid='$userid'";
$dlfl=queryall(dlfl,$type);
$flid=$dlfl[id];
}
}
//读取分类信息
$xitongid=$xitong[id];
$money=$xitong[money];
$sjmoney=$xitong[sj];
$postname=$xitong[name];
$sjm=random(200);
$zykey=md5($userid.$sjm.$shijian);
$posturl=$xitong['url'];
$ddhtz=md5($zykey);
$ddhtzds=substr($ddhtz,0,10);
$longdsu='http://'.$user[url]."/wx".random($size)."/".$zykey.$ddhtzds.'ubodl';
$longdsujfh=urlencode($longdsu);
$link =dwz($longdsujfh,$dwzjk);   
$type="where spid='$id' and userid='$userid'";
$shiping=queryall(daili,$type);
if($shiping){
}else{
$type="order by id DESC limit 0,1";
$shipin=queryall(daili,$type);
if ($shipin['id']==null){
$shipinid="1";
}else{
$shipinid=$shipin['id']+1;
}
$type="(`id`, `money`, `sj`, `cs`, `url`, `userid`, `name`, `zykey`, `shijian`, `zt`, `spid`, `link`, `lei`, `lx`, `pic`, `flid`) VALUES ('$shipinid','$money','$sjmoney','0','$posturl','$userid','$postname','$zykey','$shijian','已审核','$xitongid','$link','0','1','$xitong[pic]','$flid')"; 
dbinsert(daili,$type);
$lujing="../../peizhi/dl/".$zykey.".txt";
$neir =$shipinid."|ubo|".$userid."|ubo|".$sjmoney."|ubo|".$money."|ubo|"."0";
writefile($lujing,$neir);
}
}
echo json_encode(array('zt'=>"1"));
}elseif($lx=='fssz'){
$fs=ubo($_POST['fs']);
$type="fs='$fs'   where userid='$userid'";
upalldt(user,$type);
echo json_encode(array('zt'=>"1"));
}elseif($lx=='mbsz'){
$mb=ubo($_POST['mb']);
$type="mb='$mb'   where userid='$userid'";
upalldt(user,$type);
echo json_encode(array('zt'=>"1"));
}elseif($lx=='shikan'){
$postid=ubo($_POST['id']);
$zt=ubo($_POST['zt']);
if($zt==1){
$type="lx='2'   where id='$postid'";
upalldt(daili,$type);
}else{
$type="lx='1'   where id='$postid'";
upalldt(daili,$type);
}
echo json_encode(array('zt'=>"1"));
}elseif($lx=='plshikan'){
$postid=ubo($_POST['id']);
$ids=rtrim($postid, ','); 
$idsArray = explode(",",$ids);
foreach ($idsArray as $id){
$type="lx='2' where id='$id'";
upalldt(daili,$type);
}
echo json_encode(array('zt'=>"1"));
}elseif($lx=='fb'){
$postid=ubo($_POST["id"]);
$title=iconv("UTF-8","GB2312",$_POST['title']);
$issuiji=ubo($_POST["issuiji"]);
$sjm=random(200);
$zykey=md5($userid.$sjm.$shijian);
$type="where id='$postid'";
$shipin=queryall(shipin,$type);
//读取分类信息
$type="where id='$shipin[flid]'";
$fl=queryall(fenlei,$type);
$flname=$fl[name];
$type="where name='$flname' and userid='$userid'";
$dlfl=queryall(dlfl,$type);
if($dlfl){
$flid=$dlfl[id];
}else{
if($fl){
$type="(`id`, `name`, `userid`, `yc`) VALUES (null,'$flname','$userid','1')"; 
dbinsert(dlfl,$type);
$type="where name='$flname' and userid='$userid'";
$dlfl=queryall(dlfl,$type);
$flid=$dlfl[id];
}
}
//读取分类信息
if($shipin){
if($title==null){
$err=ubo(iconv("UTF-8","GB2312","标题不能为空"));
$errstr= array ('status'=>"2",'msg'=>$err);   
echo json_encode($errstr);
exit;
}
if($sjsz==0){
$money=ubo($_POST['guding']);
$sj=ubo($_POST['guding']);
}else{
$money=ubo($_POST['end']);
$sj=ubo($_POST['start']);
}
$posturl=$shipin['url'];
$pic=$shipin['pic'];
$ddhtz=md5($zykey);
$ddhtzds=substr($ddhtz,0,10);
$longdsu='http://'.$user[url]."/wx".random($size)."/".$zykey.$ddhtzds.'ubodl';
$longdsujfh=urlencode($longdsu);
$link =dwz($longdsujfh,$dwzjk);   
$type="order by id DESC limit 0,1";
$shipintg=queryall(daili,$type);
if ($shipintg['id']==null){
$shipinid="1";
}else{
$shipinid=$shipintg['id']+1;
}
$type="(`id`, `money`, `sj`, `cs`, `url`, `userid`, `name`, `zykey`, `shijian`, `zt`, `spid`, `link`, `lei`, `lx`, `pic`, `flid`) VALUES ('$shipinid','$money','$sj','0','$posturl','$userid','$title','$zykey','$shijian','已审核','$postid','$link','0','1','$pic','$flid')"; 
dbinsert(daili,$type);
$lujing="../../peizhi/dl/".$zykey.".txt";
$neir =$shipinid."|ubo|".$userid."|ubo|".$sj."|ubo|".$money."|ubo|"."0";
writefile($lujing,$neir);
$errstr= array ('status'=>"1");   
echo json_encode($errstr);
}else{
$err=iconv("UTF-8","GB2312","视频ID不存在");
$errstr= array ('status'=>"0",'msg'=>$err);   
echo json_encode($errstr);
exit;
}
}elseif($lx=='jiage'){
$postid=ubo($_POST['id']);
$money=ubo($_POST['money']);
if($money==null){
$err=iconv("GB2312","UTF-8","金额不能为空");
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}
if (strpos($money, '-') !== false) {
$ppp = explode('-',$money); 
$sjmoney=$ppp['0'];
$gdmoney=$ppp['1'];
if($sjmoney<$zxm){
$err=iconv("GB2312","UTF-8","随机起始金额最小限制为: ".$zxm.'  元');
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}elseif($gdmoney>$zdm){
$err=iconv("GB2312","UTF-8","随机结束金额最大限制为: ".$zdm.'  元');
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}else{
$type="money='$gdmoney',sj='$sjmoney' where id='$postid'";
upalldt(daili,$type);
$type="where id='$postid'";
$shipin=queryall(daili,$type);
$lujing="../../peizhi/dl/".$shipin[zykey].".txt";
$neir =$postid."|ubo|".$shipin[userid]."|ubo|".$sjmoney."|ubo|".$gdmoney."|ubo|".$shipin[lei];
writefile($lujing,$neir);
echo json_encode(array('zt'=>"1"));
}
}else{
if($money<$zxm){
$err=iconv("GB2312","UTF-8","金额最小限制为: ".$zxm.'  元');
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}elseif($money>$zdm){
$err=iconv("GB2312","UTF-8","金额最大限制为: ".$zdm.'  元');
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}else{
$type="money='$money',sj='$money' where id='$postid'";
upalldt(daili,$type);
$type="where id='$postid'";
$shipin=queryall(daili,$type);
$lujing="../../peizhi/dl/".$shipin[zykey].".txt";
$neir =$postid."|ubo|".$shipin[userid]."|ubo|".$money."|ubo|".$money."|ubo|".$shipin[lei];
writefile($lujing,$neir);
echo json_encode(array('zt'=>"1"));
}
}
}elseif($lx=='lei'){
if($lei==1){
$postid=ubo($_POST['id']);
$money=ubo($_POST['money']);
if($money==null){
$err=iconv("GB2312","UTF-8","金额不能为空");
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}elseif($money<1){
$err=iconv("GB2312","UTF-8","金额不能小于1元");
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}elseif($money>$lm){
$err=iconv("GB2312","UTF-8","暗雷金额最大限制为: ".$lm.'  元');
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}else{
$type="lei='$money' where id='$postid'";
upalldt(daili,$type);
$type="where id='$postid'";
$shipin=queryall(daili,$type);
$lujing="../../peizhi/dl/".$shipin[zykey].".txt";
$neir =$postid."|ubo|".$shipin[userid]."|ubo|".$shipin[sj]."|ubo|".$shipin[money]."|ubo|".$money;
writefile($lujing,$neir);
echo json_encode(array('zt'=>"1"));
}
}
}elseif($lx=='gengxin'){
$postid=ubo($_POST['id']);
$ids=rtrim($postid, ','); 
$idsArray = explode(",",$ids);
foreach ($idsArray as $id){
$type="where id='$id'";
$daili=queryall(daili,$type);
if($daili[zt]=='待审核'){
}else{
$ddhtz=md5($daili[zykey]);
$ddhtzds=substr($ddhtz,0,10);
$longdsu='http://'.$user[url]."/wx".random($size)."/".$daili[zykey].$ddhtzds.'ubodl';
$longdsujfh=urlencode($longdsu);
$link =dwz($longdsujfh,$dwzjk);  
$type="link='$link' where id='$id'";
upalldt(daili,$type);
}
}
echo json_encode(array('zt'=>"1"));

}elseif($lx=='fenxiang'){
$postid=ubo($_POST['id']);
$ids=rtrim($postid, ','); 
$idsArray = explode(",",$ids);
foreach ($idsArray as $id){
$type="where id='$id'";
$daili=queryall(daili,$type);
$type="order by id DESC limit 0,1";
$shipin=queryall(shipin,$type);
if ($shipin['id']==null){
$shipinid="1";
}else{
$shipinid=$shipin['id']+1;
}
$type="where name='$daili[name]'";
$shipinto=queryall(shipin,$type);
if(!$shipinto){
$type="(`id`, `money`, `sj`, `cs`, `url`, `name`, `zykey`, `shijian`, `pic`, `flid`) VALUES ('$shipinid','$daili[money]','$daili[sj]','0','$daili[url]','$daili[name]','$daili[zykey]','$daili[shijian]','$daili[pic]','$daili[flid]')"; 
dbinsert(shipin,$type);
$lujing="../../peizhi/xt/".$zykey.".txt";
$neir =$shipinid."|ubo|"."admin"."|ubo|".$sj."|ubo|".$money."|ubo|"."0";
writefile($lujing,$neir);
}
}
echo json_encode(array('zt'=>"1"));
}elseif($lx=='zonglian'){
$query = mysql_query("SELECT * FROM daili  where  userid='$userid' and zt='已审核' order by rand() limit 1");
while($row = mysql_fetch_array($query)) {
$paycode=base64_encode($row[id]);
$link='http://'.$user[url].'/zonglink-'.$paycode.$dshz; 
$longurlyt=$link;
$long=urlencode($longurlyt);
$zl2 =dwz($long,$dwzjk); 
$zyname=iconv("GB2312","UTF-8",$row[name]);
$arr[] = array('url'=>$zl2,'name'=>$zyname); 
}
echo json_encode(array('zt'=>"1",'lists'=>$arr));
}elseif($lx=='dwz'){
$query = mysql_query("SELECT * FROM daili  where  userid='$userid' and zt='已审核'");
while($daili= mysql_fetch_array($query)) {
$ddhtz=md5($daili[zykey]);
$ddhtzds=substr($ddhtz,0,10);
$longdsu='http://'.$user[url]."/wx".random($size)."/".$daili[zykey].$ddhtzds.'ubodl';
$longdsujfh=urlencode($longdsu);
$link =dwz($longdsujfh,$dwzjk);  
$type="link='$link' where id='$daili[id]'";
upalldt(daili,$type);
}
echo json_encode(array('zt'=>"1"));
}elseif($lx=='jiagegengxin'){
$sjmoney=ubo($_POST['sjmoney']);
$gdmoney=ubo($_POST['gdmoney']);
if($sjsz==1){
if($sjmoney==null or $gdmoney==null ){
$err=iconv("GB2312","UTF-8","金额不能为空");
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}elseif($sjmoney<$zxm){
$err=iconv("GB2312","UTF-8","随机起始金额最小限制为: ".$zxm.'  元');
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}elseif($gdmoney>$zdm){
$err=iconv("GB2312","UTF-8","随机结束金额最大限制为: ".$zdm.'  元');
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}else{
$postid=ubo($_POST['id']);
$ids=rtrim($postid, ','); 
$idsArray = explode(",",$ids);
foreach ($idsArray as $id){
$type="money='$gdmoney',sj='$sjmoney' where id='$id'";
upalldt(daili,$type);
$type="where id='$id'";
$shipin=queryall(daili,$type);
$lujing="../../peizhi/dl/".$shipin[zykey].".txt";
$neir =$id."|ubo|".$shipin[userid]."|ubo|".$sjmoney."|ubo|".$gdmoney."|ubo|".$shipin[lei];
writefile($lujing,$neir);
}
echo json_encode(array('zt'=>"1"));
}
}else{
if($sjmoney==null){
$err=iconv("GB2312","UTF-8","金额不能为空");
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}elseif($sjmoney>$zdm){
$err=iconv("GB2312","UTF-8","固定金额最大限制为: ".$zdm.'  元');
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}else{
$postid=ubo($_POST['id']);
$ids=rtrim($postid, ','); 
$idsArray = explode(",",$ids);
foreach ($idsArray as $id){
$type="money='$sjmoney',sj='$sjmoney' where id='$id'";
upalldt(daili,$type);
$type="where id='$id'";
$shipin=queryall(daili,$type);
$lujing="../../peizhi/dl/".$shipin[zykey].".txt";
$neir =$id."|ubo|".$shipin[userid]."|ubo|".$sjmoney."|ubo|".$sjmoney."|ubo|".$shipin[lei];
writefile($lujing,$neir);
}
echo json_encode(array('zt'=>"1"));
}
}
}elseif($lx=='name'){
$postid=ubo($_POST['id']);
$namekk=ubo(iconv("UTF-8","GB2312",$_POST['name']));  
$type="name='$namekk' where id='$postid'";
upalldt(daili,$type);
echo json_encode(array('zt'=>"1"));
}elseif($lx=='shanchu'){
$postids=ubo($_POST['ids']);
$strbbbyyy=rtrim($postids, ','); 
$strbbbyyyArray = explode(",",$strbbbyyy);
foreach ($strbbbyyyArray as $postid){
$type="where id='$postid'";
$shipin=queryall(daili,$type);
unlink('../../peizhi/dl/'.$shipin[zykey].".txt"); 
$type="id='$postid'";
dbdel(daili,$type);
}
echo json_encode(array('zt'=>"1"));
//视频外链添加
}elseif($lx=='tjwl'){
$zykey=iconv("UTF-8","GB2312",ubo($_POST["zykey"]));
$posturl=iconv("UTF-8","GB2312",ubo($_POST["url"]));
$name=iconv("UTF-8","GBK",ubo($_POST["name"]));
$zl=iconv("UTF-8","GBK",ubo($_POST["zl"]));
$fl=iconv("UTF-8","GBK",ubo($_POST["fl"]));
if($fl=='请选择'){
$err=iconv("GB2312","UTF-8","分类未选择");
$errstr= array ('status'=>"0",'msg'=>$err);   
echo json_encode($errstr);
exit;
}
$sjmoney=ubo($_POST['sj']);
$gdmoney=ubo($_POST['money']);
if($sjmoney<$zxm){
$err=iconv("GB2312","UTF-8","随机起始金额最小限制为: ".$zxm.'  元');
$errstr= array ('status'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}elseif($gdmoney>$zdm){
$err=iconv("GB2312","UTF-8","随机结束金额最大限制为: ".$zdm.'  元');
$errstr= array ('status'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}else{
$type="where name='$name'and userid='$userid' ";
$row=queryall(daili,$type);
if($row){
$err=iconv("GB2312","UTF-8","视频已存在");
$errstr= array ('status'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}else{
$ddhtz=md5($zykey);
$ddhtzds=substr($ddhtz,0,10);
$longdsu='http://'.$user[url]."/wx".random($size)."/".$zykey.$ddhtzds.'ubodl';
$longdsujfh=urlencode($longdsu);
$link =dwz($longdsujfh,$dwzjk);   
$type="order by id DESC limit 0,1";
$shipin=queryall(daili,$type);
if ($shipin['id']==null){
$shipinid="1";
}else{
$shipinid=$shipin['id']+1;
}
if($sh=='1'){
$type="(`id`, `money`, `sj`, `cs`, `url`, `userid`, `name`, `zykey`, `zt`, `shijian`, `spid`, `link`, `lei`, `pic`, `lx`, `flid`) VALUES ('$shipinid','$gdmoney','$sjmoney','0','$posturl','$userid','$name','$zykey','待审核','$shijian','','$link','0','','$zl','$fl')"; 
dbinsert(daili,$type);
}else{
$type="(`id`, `money`, `sj`, `cs`, `url`, `userid`, `name`, `zykey`, `zt`, `shijian`, `spid`, `link`, `lei`, `pic`, `lx`, `flid`) VALUES ('$shipinid','$gdmoney','$sjmoney','0','$posturl','$userid','$name','$zykey','已审核','$shijian','','$link','0','','$zl','$fl')"; 
dbinsert(daili,$type);
$lujing="../../peizhi/dl/".$zykey.".txt";
$neir =$shipinid."|ubo|".$userid."|ubo|".$sjmoney."|ubo|".$gdmoney."|ubo|"."0";
writefile($lujing,$neir);
}
$errstr = array ('status'=>"1");   
echo json_encode($errstr);
}
}
//会员资料修改
}elseif($lx=='user'){
$nikname=iconv("UTF-8","GB2312",ubo($_POST["nikname"]));
$txname=iconv("UTF-8","GB2312",ubo($_POST["txname"]));
$weixin=iconv("UTF-8","GB2312",ubo($_POST["weixin"]));
$qq=iconv("UTF-8","GB2312",ubo($_POST["qq"]));
$tixian=iconv("UTF-8","GB2312",ubo($_POST["tixian"]));
$pass=md5(iconv("UTF-8","GB2312",ubo($_POST["pass"])));
$ypass=iconv("UTF-8","GB2312",ubo($_POST["pass"]));
$newpass=md5(iconv("UTF-8","GB2312",ubo($_POST["newpass"])));
if($pass==$user['pass']){
if($newpass==null){
$err=iconv("UTF-8","GB2312","新密码不能为空");
$errstr= array ('status'=>"false",'msg'=>$err);   
echo json_encode($errstr);
}else{
$type="nikname='$nikname',txname='$txname',weixin='$weixin',qq='$qq',tixian='$tixian',pass='$newpass',ypass='$ypass' where userid='$userid'";
upalldt(user,$type);
$errstr= array ('status'=>"true");   
echo json_encode($errstr);
}
}else{
$err=iconv("UTF-8","GB2312","密码不正确");
$errstr= array ('status'=>"false",'msg'=>$err);   
echo json_encode($errstr);
}
}elseif($lx=='addskm'){
$pd=iconv("UTF-8","GB2312",ubo($_POST["pd"]));
$txname=iconv("UTF-8","GB2312",ubo($_POST["txname"]));
$tixian=iconv("UTF-8","GB2312",ubo($_POST["tixian"]));
if($pd==null){
$err=iconv("GB2312","UTF-8","请上传收款码后保存");
$errstr = array ('status'=>"false",'msg'=>$err);   
echo json_encode($errstr);
exit;
} 
$type="txname='$txname',tixian='$tixian',skm='$pd' where userid='$userid'";
upalldt(user,$type);
$errstr= array ('status'=>"true");   
echo json_encode($errstr);
//邀请码购买
}elseif($lx=='yqmgm'){
$sl=ubo($_POST['sl']);
if($sl){
$slpd=$sl*$yqm;
if($user['money']>=$slpd){
$sl3=$user['money']-$slpd;
for($i =1; $i<=$sl; $i++){
$xgg=random(8).$i.random(4);
$type="where yqm='$xgg'";
$xggts=queryall(yqm,$type);
if($xggts){
}else{
$type="money='$sl3' where userid='$userid'";
upalldt(user,$type);
$type="(`id`, `userid`, `yqm`, `shijian`, `name`, `zt`, `lx`) VALUES (null,'$userid','$xgg','$shijian','','未使用','dl')"; 
dbinsert(yqm,$type);
}
}
$err = array ('status'=>"1");   
echo json_encode($err);
}else{
$err=iconv("GB2312","UTF-8","余额不足");
$errstr= array ('status'=>"false",'msg'=>$err);   
echo json_encode($errstr);
}
}else{
$err=iconv("GB2312","UTF-8","购买数量不能为空");
$errstr= array ('status'=>"false",'msg'=>$err);   
echo json_encode($errstr);
}
//提现
}elseif($lx=='tx'){
$pass=md5(ubo($_POST['pass']));
$postmoney=ubo($_POST['money']);
$sql="select sum(money) from pay where  userid='$userid'   and shijian='$day'";
if ($res=mysql_query($sql)){
list($txpd)=mysql_fetch_row($res);
mysql_free_result($res);
} 
$sql2 = mysql_query("SELECT * FROM pay WHERE   userid='$userid'   and shijian='$day' ");
$txcs2 = mysql_num_rows($sql2);
if($txcs2>=$txcs){
$err=iconv("GB2312","UTF-8","今日提现次数已超限");  
$errstr = array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
exit;
}
if($pass==$user['pass']){
if($user['money']>=$postmoney){
if($postmoney>=$js){ 
if($txpd==$daymoney){
$err=iconv("GB2312","UTF-8","今日提现已超过系统限制的最大提现金额 ".$daymoney);  
$errstr = array ('status'=>"false",'msg'=>$err);   
echo json_encode($errstr);
exit;
}
if($postmoney>=$txmoney){
$err=iconv("GB2312","UTF-8","提现超过 ".$txmoney." 请联系客服 ".$weixin." 安全提现");  
$errstr = array ('status'=>"false",'msg'=>$err);   
echo json_encode($errstr);
}else{
$type="(`id`,`userid`,`shijian`,`money`,`zt`) VALUES (null, '$userid', '$day', '$postmoney', '等待支付')";
dbinsert(pay,$type);
$postmoneyoney=$user['money']-$postmoney;
$type="money='$postmoneyoney' where userid='$userid'";
upalldt(user,$type);
$postmoneyoney2=$user['txmoney']+$postmoney;
$type="txmoney='$postmoneyoney2' where userid='$userid'";
upalldt(user,$type);
$tjr=$user['tjr'];
$type="where userid='$tjr'";
$user2=queryall(user,$type);
if($user2[fy]){
$dlfy=$user2[fy];
}else{
$dlfy=$fy;
}
if($user['money']>=$yye){
$fymoney=($postmoney*$dlfy)/100;
$name=$user['name'];
$type="(`id`,`shijian`,`fymoney`,`name`,`money2`,`tjr`) VALUES (null, '$shijian', '$fymoney', '$name', '$postmoney', '$tjr')";
dbinsert(fanyong,$type);

$postmoneyoney3=$user2['money']+$fymoney;
$type="money='$postmoneyoney3' where userid='$tjr'";
upalldt(user,$type);
}
$err=iconv("GB2312","UTF-8","提现成功，等待审核");  
$errstr = array ('status'=>"true",'msg'=>$err);   
echo json_encode($errstr);
}
}else{ 
$err=iconv("GB2312","UTF-8","提现金额必须大于$js");  
$errstr = array ('status'=>"false",'msg'=>$err);   
echo json_encode($errstr);
}
}else{
$err=iconv("GB2312","UTF-8","账户余额不足");  
$errstr = array ('status'=>"false",'msg'=>$err);   
echo json_encode($errstr);
}
}else{
$err=iconv("GB2312","UTF-8","提现密码不对");  
$errstr = array ('status'=>"false",'msg'=>$err);   
echo json_encode($errstr);
}

//盒子生成
}elseif($lx=='api'){
$type="where userid='$userid'";
$wangzhan=queryall(wangzhan,$type);
$postname=$wangzhan['name'];
$video= ubo(trim($_POST['video']));  
if($video){
$data = trim($video);  
$groupData= explode("\n", $data);
$sl=count($groupData);
if($sl>100){
$err=iconv("GB2312","UTF-8","每次最多设置100条链接");  
$errstr = array ('status'=>"false",'msg'=>$err);   
echo json_encode($errstr);
exit;
}
foreach($groupData as $videolist){
$urllist = preg_replace("/(\r\n|\n|\r|\t)/i", '', $videolist);
$str="/^https?.+\.(mp4|m3u8)$/i";  
if (!preg_match($str,$urllist)){  
}else{
$db=md5($shijian.random(100));
$hezishijian=strtotime (date("y-m-d h:i:s")); //当前时间  
$tzdizhi='http://'.$user[url].'/hezishow-'.$db.'.html?t='.$hezishijian;
$longurlyt=$tzdizhi;
$long=urlencode($longurlyt);
$zl2 =dwz($long,$dwzjk); 
$type="where url='$urllist' and biaoshi='$db'";
$w=queryall(lishi,$type);
if(!$w){
$type="(`id`, `userid`, `name`, `url`, `link`, `biaoshi`) VALUES (null,'$userid','$postname','$urllist','$zl2','$db')"; 
dbinsert(lishi,$type);
}
$arr[] = array('url'=>$zl2); 
}
}
echo json_encode(array('zt'=>"1",'lists'=>$arr));
}else{
$err=iconv("GB2312","UTF-8","视频地址不能为空");  
$errstr = array ('status'=>"false",'msg'=>$err);   
echo json_encode($errstr);
}
}elseif($lx=='yjskto'){
$sql= "WHERE 1=1";
$sql.=" and userid='$userid' ";
$query = mysql_query("select * from  daili  ".$sql."");
while ($a=mysql_fetch_array($query)) { 
$type="lx='1' where id='$a[id]'";
upalldt(daili,$type);
}
echo json_encode(array('zt'=>"1"));

}elseif($lx=='jiagegengxin2'){
$sjmoney=ubo($_POST['sjmoney']);
$gdmoney=ubo($_POST['gdmoney']);
if($sjsz==1){
if($sjmoney==null or $gdmoney==null ){
$err=iconv("GB2312","UTF-8","金额不能为空");
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}elseif($sjmoney<$zxm){
$err=iconv("GB2312","UTF-8","随机起始金额最小限制为: ".$zxm.'  元');
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}elseif($gdmoney>$zdm){
$err=iconv("GB2312","UTF-8","随机结束金额最大限制为: ".$zdm.'  元');
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}else{
$sql= "WHERE 1=1";
$sql.=" and userid='$userid' ";
$query = mysql_query("select * from  daili  ".$sql."");
while ($a=mysql_fetch_array($query)) { 
$type="money='$gdmoney',sj='$sjmoney' where id='$a[id]'";
upalldt(daili,$type);
$type="where id='$a[id]'";
$shipin=queryall(daili,$type);
$lujing="../../peizhi/dl/".$shipin[zykey].".txt";
$neir =$a[id]."|ubo|".$shipin[userid]."|ubo|".$sjmoney."|ubo|".$gdmoney."|ubo|".$shipin[lei];
writefile($lujing,$neir);
}
echo json_encode(array('zt'=>"1"));
}
}else{
if($sjmoney==null){
$err=iconv("GB2312","UTF-8","金额不能为空");
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}elseif($sjmoney>$zdm){
$err=iconv("GB2312","UTF-8","固定金额最大限制为: ".$zdm.'  元');
$errstr= array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}else{
$sql= "WHERE 1=1";
$sql.=" and userid='$userid' ";
$query = mysql_query("select * from  daili  ".$sql."");
while ($a=mysql_fetch_array($query)) { 
$type="money='$sjmoney',sj='$sjmoney' where id='$a[id]'";
upalldt(daili,$type);
$type="where id='$a[id]'";
$shipin=queryall(daili,$type);
$lujing="../../peizhi/dl/".$shipin[zykey].".txt";
$neir =$a[id]."|ubo|".$shipin[userid]."|ubo|".$sjmoney."|ubo|".$sjmoney."|ubo|".$shipin[lei];
writefile($lujing,$neir);
}
echo json_encode(array('zt'=>"1"));
}
}
}elseif($lx=='yjtj'){
$sql= "WHERE 1=1";
$query = mysql_query("select * from  shipin  ".$sql."");
while ($a=mysql_fetch_array($query)) { 
$type="where id='$a[id]'";
$xitong=queryall(shipin,$type);
//读取分类信息
$type="where id='$xitong[flid]'";
$fl=queryall(fenlei,$type);
$flname=$fl[name];
$type="where name='$flname' and userid='$userid'";
$dlfl=queryall(dlfl,$type);
if($dlfl){
$flid=$dlfl[id];
}else{
if($fl){
$type="(`id`, `name`, `userid`, `yc`) VALUES (null,'$flname','$userid','1')"; 
dbinsert(dlfl,$type);
$type="where name='$flname' and userid='$userid'";
$dlfl=queryall(dlfl,$type);
$flid=$dlfl[id];
}
}
//读取分类信息
$xitongid=$xitong[id];
$money=$xitong[money];
$sjmoney=$xitong[sj];
$postname=$xitong[name];
$sjm=random(200);
$zykey=md5($userid.$sjm.$shijian);
$posturl=$xitong['url'];
$ddhtz=md5($zykey);
$ddhtzds=substr($ddhtz,0,10);
$longdsu='http://'.$user[url]."/wx".random($size)."/".$zykey.$ddhtzds.'ubodl';
$longdsujfh=urlencode($longdsu);
$link =dwz($longdsujfh,$dwzjk);   
$type="where spid='$a[id]' and userid='$userid'";
$shiping=queryall(daili,$type);
if($shiping){
}else{
$type="order by id DESC limit 0,1";
$shipin=queryall(daili,$type);
if ($shipin['id']==null){
$shipinid="1";
}else{
$shipinid=$shipin['id']+1;
}
$type="(`id`, `money`, `sj`, `cs`, `url`, `userid`, `name`, `zykey`, `shijian`, `zt`, `spid`, `link`, `lei`, `lx`, `pic`, `flid`) VALUES ('$shipinid','$money','$sjmoney','0','$posturl','$userid','$postname','$zykey','$shijian','已审核','$xitongid','$link','0','1','$xitong[pic]','$flid')"; 
dbinsert(daili,$type);
$lujing="../../peizhi/dl/".$zykey.".txt";
$neir =$shipinid."|ubo|".$userid."|ubo|".$sjmoney."|ubo|".$money."|ubo|"."0";
writefile($lujing,$neir);
}
}
echo json_encode(array('zt'=>"1"));
}elseif($lx=='scpk'){
$type="WHERE userid='$userid'";
$row=queryall(daili,$type);  
unlink('../../peizhi/dl/'.$row[zykey].".txt"); 
$type="userid='$userid'";
dbdel(daili,$type);
echo json_encode(array('zt'=>"1"));
}elseif($lx=='flsc'){
$type="id='$postid'";
dbdel(dlfl,$type);
echo json_encode(array('zt'=>"1"));
}elseif($lx=='fladd'){
$postname=iconv("UTF-8","GB2312",ubo($_POST['name']));
$type="WHERE name='$postname' and userid='$userid'";
$fenlei=queryall(dlfl,$type); 
if($fenlei){
$err=iconv("GB2312","UTF-8","分类名称已存在");
$errstr = array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}else{
$type="(`id`, `name`, `userid`, `yc`) VALUES (null,'$postname','$userid','1')"; 
dbinsert(dlfl,$type);
echo json_encode(array('zt'=>"1"));
}
}elseif($lx=='flname'){
$type="WHERE name='$name'";
$fenlei=queryall(dlfl,$type); 
if($fenlei){
$err=iconv("GB2312","UTF-8","分类名称不能相同");
$errstr = array ('zt'=>"0",'msg'=>$err);   
echo json_encode($errstr);
}else{
$type="name='$name'   where id='$postid'";
upalldt(dlfl,$type);
$json_data = array ('zt'=>"1");   
echo json_encode($json_data);
}
}elseif($lx=='flsz'){
$type="yc='$zt'   where id='$postid'";
upalldt(dlfl,$type);
echo json_encode(array('zt'=>"1"));
}elseif($lx=='fledit'){
$postids=ubo($_POST['ids']);
$fl=ubo($_POST['fl']);
$er=iconv("UTF-8","GB2312",$fl);
if($er=='请选择'){
$err=iconv("GB2312","UTF-8","分类未选择");
echo json_encode(array('zt'=>'0','msg'=>$err));
exit;
}
$toids=base64_decode($postids);
$ids=rtrim($toids, ','); 
$idsArray = explode(",",$ids);
foreach ($idsArray as $id){
$type="flid='$fl'   where id='$id'";
upalldt(daili,$type);
}
echo json_encode(array('zt'=>"1"));
}elseif($lx=='hezisz'){
$postid=ubo($_POST['id']);
$type="hzmb='$postid'   where userid='$userid'";
upalldt(user,$type);
echo json_encode(array('zt'=>"1"));
}elseif($lx=='linkmbsz'){
$postid=ubo($_POST['id']);
$type="mb='$postid'   where userid='$userid'";
upalldt(user,$type);
echo json_encode(array('zt'=>"1"));
}elseif($lx=='dssz'){
$postid=ubo($_POST['id']);
$type="dsmb='$postid'   where userid='$userid'";
upalldt(user,$type);
echo json_encode(array('zt'=>"1"));
}
}else{
echo err();
}
?>
