使用php将mysql转换成json_php中将数据库中的文件转化为json

  • Post author:
  • Post category:php


if(!defined(‘IN_SCCMS’)) {

exit(‘Access Denied’);

}

$json = stripslashes($_SGET[‘json’]); //去斜杠

$getarray = json_decode($json,true); //转码

$op = $getarray[‘op’];

$uid = $getarray[‘uid’];

$uid=1;

if(!$uid){

$msg = urlencode (“nodata”);

$data = array(result => 2,msg => $msg);

echo urldecode ( json_encode ( $data ) );

exit;

}

switch ($op){

case “del” :

$id=$getarray[‘id’]?$getarray[‘id’]:”;

$sql=”select wishjoin.*,wish.* from “.$_SC[‘tablepre’].”wishjoin as wishjoin

left join “.$_SC[‘tablepre’].”wish as wish on wish.id=wishjoin.wishid

where wishjoin.id = {$id}”;

$query = $_SGLOBAL[‘db’]->query($sql);

$result = $_SGLOBAL[‘db’]->fetch_array($query);

//如果该愿望已经结束是是不允许退出投稿的

if($result[‘status’]==3 or $result[‘status’]==4){

$msg = urlencode (“error”);

$data = array(result => 2,msg => $msg);

echo urldecode ( json_encode ( $data ) );

exit;

}

//删除投稿表数据

$sql=”delete from “.$_SC[‘tablepre’].”wishjoin where id=”.$id.” and uid=”.$_SGLOBAL[‘sc_uid’];

$query = $_SGLOBAL[‘db’]->query($sql);

//给用户加钱

$sql = “update “.$_SC[‘tablepre’].”user set money=money+{$result[‘money’]} where uid=”.$_SGLOBAL[‘sc_uid’];

$query = $_SGLOBAL[‘db’]->query($sql);

//该愿望报名人数减1

$sql = “update “.$_SC[‘tablepre’].”wish set participants=participants-1 where id={$result[‘wishid’]}”;

//记录财务记录

$data=array(

“uid”=> $_SGLOBAL[‘sc_uid’],

“wishid”=> $result[‘wishid’],

“iotype”=> 1,

“buytype”=> 4,

“money”=> $result[“money”],

“description”=> “退出愿望投稿,退投稿费”.$result[“money”].”元”,

“dateline”=> $_SGLOBAL[‘timestamp’],

);

inserttable($_SC[‘tablepre’],”userfinance”, $data, 1 );

$msg = urlencode (“done”);

$data = array(result => 2,msg => $msg);

echo urldecode ( json_encode ( $data ) );

exit;

break;

case “usercomment” :

if(submitcheck(‘submit’)){

//如果愿望状态不为3或者4的话是不允许评论

$sql=”select wish.* from “.$_SC[‘tablepre’].”wish as wish

left join “.$_SC[‘tablepre’].”wishresult as wishresult on wish.id=wishresult.wishid

where wishresult.id = {$_POST[‘id’]}”;

$query = $_SGLOBAL[‘db’]->query($sql);

$result = $_SGLOBAL[‘db’]->fetch_array($query);

if($result[‘status’]!=3){

showmessage(“不允许评论!”, $_POST[‘refer’],3);

}

//检查这条愿望是否已经评论过了,如果已经评论过了不允许评论了

$sql=”select * from “.$_SC[‘tablepre’].”wishresult as wishresult

where wishresult.id = {$_POST[‘id’]}”;

$query = $_SGLOBAL[‘db’]->query($sql);

$result = $_SGLOBAL[‘db’]->fetch_array($query);

if($result[‘usercomment’]){

$msg = urlencode (“error”);

$data = array(result => 2,msg => $msg);

echo urldecode ( json_encode ( $data ) );

exit;

}

//这个人是最终的结果才有评论的资格

if($_SGLOBAL[‘sc_uid’]!=$result[‘serveruid’]){

showmessage(“没有权限!”, $_POST[‘refer’],3);

}

$data=array(

“usercomment”=> 1,

“ucgrade”=> $_POST[‘ucgrade’],

“uccontent”=> $_POST[‘uccontent’],

“ucdateline”=> $_SGLOBAL[‘timestamp’],

);

updatetable($_SC[‘tablepre’],’wishresult’,$data,’id=’.$_POST[‘id’],0);

//检查这个愿望是否已经评价完了,如果评价完了状态改为4

if($result[‘usercomment’] and $result[‘servecomment’]){

$data=array(

“status”=> 4,

);

updatetable($_SC[‘tablepre’],’wish’,$data,’id=’.$result[“wishid”],0);

}

$msg = urlencode (“error”);

$data = array(result => 2,msg => $msg);

echo urldecode ( json_encode ( $data ) );

exit;

}else{

//评价许愿人

$id=$_SGET[‘id’]?$_SGET[‘id’]:”;

$sql=”select wish.*,category.catname,wishtradetype.name as tradetype,wishtradetype.fieldtable as fieldtable,user.avatar,user.username

from “.$_SC[‘tablepre’].”wish as wish

left join “.$_SC[‘tablepre’].”category as category on category.catid=wish.catid

left join “.$_SC[‘tablepre’].”wishtradetype as wishtradetype on wish.ttid=wishtradetype.id

left join “.$_SC[‘tablepre’].”user as user on user.uid=wish.uid

where wish.id = {$id}”;

$query = $_SGLOBAL[‘db’]->query($sql);

$result = $_SGLOBAL[‘db’]->fetch_array($query);

//如果愿望状态不为3或者4的话是不允许评论

if(!($result[‘status’]==3 or $result[‘status’]==4)){

$msg = urlencode (“error”);

$data = array(result => 2,msg => $msg);

echo urldecode ( json_encode ( $data ) );

exit;

}

//查询愿望结果

$sql=”select wishresult.*,user.username as serverusername

from “.$_SC[‘tablepre’].”wishresult as wishresult

left join “.$_SC[‘tablepre’].”user as user on wishresult.serveruid=user.uid

where wishresult.wishid = {$id} and wishresult.serveruid={$_SGLOBAL[‘sc_uid’]}”;

$query = $_SGLOBAL[‘db’]->query($sql);

$wishresult = $_SGLOBAL[‘db’]->fetch_array($query);

//这个人是最终的结果才有评论的资格

if($_SGLOBAL[‘sc_uid’]!=$wishresult[‘serveruid’]){

$msg = urlencode (“error”);

$data = array(result => 2,msg => $msg);

echo urldecode ( json_encode ( $data ) );

exit;

}

}

break;

case “view” :

$id=$_SGET[‘id’]?$_SGET[‘id’]:”;

$sql=”select wish.*,wish.id as wishid,category.catname,wishtradetype.name as tradetype,wishtradetype.fieldtable as fieldtable

from “.$_SC[‘tablepre’].”wish as wish

left join “.$_SC[‘tablepre’].”category as category on category.catid=wish.catid

left join “.$_SC[‘tablepre’].”wishtradetype as wishtradetype on wish.ttid=wishtradetype.id

where wish.id = {$id}”;

$query = $_SGLOBAL[‘db’]->query($sql);

$result = $_SGLOBAL[‘db’]->fetch_array($query);

if(!($result[‘status’]==3 or $result[‘status’]==4)){

$msg = urlencode (“nopermission”);

$data = array(result => 2,msg => $msg);

echo urldecode ( json_encode ( $data ) );

exit;

}

if(!empty($result[‘fieldtable’])){

$sql=”select *

from “.$_SC[‘tablepre’].”wish_{$result[‘fieldtable’]} as wish_{$result[‘fieldtable’]}

where wishid = {$result[‘wishid’]}”;

$query = $_SGLOBAL[‘db’]->query($sql);

$resultdetail = $_SGLOBAL[‘db’]->fetch_array($query);

$result = array_merge($result, $resultdetail);

}

$sql=”select wishjoin.*,user.*

from “.$_SC[‘tablepre’].”wishjoin as wishjoin

left join “.$_SC[‘tablepre’].”user as user on user.uid=wishjoin.uid

where wishjoin.wishid = {$result[‘wishid’]} limit 0,5″;

$query = $_SGLOBAL[‘db’]->query($sql);

$wishjoinuid = array();

while ($value = $_SGLOBAL[‘db’]->fetch_array($query)) {

array_push($wishjoinuid, $value[‘uid’]);

}

if(!(in_array($_SGLOBAL[‘sc_uid’],$wishjoinuid))) {

$msg = urlencode (“error”);

$data = array(result => 2,msg => $msg);

echo urldecode ( json_encode ( $data ) );

exit;

}

//获取这个愿望的结果

$sql=”select *

from “.$_SC[‘tablepre’].”wishresult as wishresult

where wishid = {$result[‘wishid’]}”;

$query = $_SGLOBAL[‘db’]->query($sql);

$wishresult = $_SGLOBAL[‘db’]->fetch_array($query);

break;

default:

//开始查询

$sstatus=$getarray[‘sstatus’]?$getarray[‘sstatus’]:”;

$scatid=$getarray[‘scatid’]?$getarray[‘scatid’]:”;

$sname=$getarray[‘sname’]?$getarray[‘sname’]:”;

if(!empty($scatid)){

$getplus.= ‘&scatid=’.$scatid;

}

if(!empty($sname)){

$getplus.= ‘&sname=’.$sname;

}

//开始查询

$page = $getarray[‘page’];

$perpage = empty($getarray[‘perpage’])?”5″:$getarray[‘perpage’];

if($page<1) $page = 1;

$start = ($page-1)*$perpage;

//检查开始数

ckstart($start, $perpage);

$sql=”select wish.*,category.catname,wishtradetype.name as tradename,wishjoin.id,wishjoin.wishid,wishjoin.dateline,wishjoin.money,wishjoin.uid as joinuid,wishresult.serveruid from

“.$_SC[‘tablepre’].”wish as wish left join “.$_SC[‘tablepre’].”wishjoin as wishjoin on

wishjoin.wishid=wish.id left join “.$_SC[‘tablepre’].”category as category on

wish.catid=category.catid left join “.$_SC[‘tablepre’].”wishtradetype as wishtradetype on

wish.ttid=wishtradetype.id left join “.$_SC[‘tablepre’].”wishresult as wishresult on

wishresult.wishid=wish.id where wishjoin.uid=’$uid'”;

if(!empty($scatid)){

if(!empty($_SGLOBAL[‘category’][$scatid][‘subid’])){

$sql.=” and wish.catid in ({$_SGLOBAL[‘category’][$scatid][‘subid’]})”;

}else{

$sql.=” and wish.catid = $scatid”;

}

}

if($sstatus){

$sql.=” and wish.status=3 and wishresult.usercomment=0 and wishresult.serveruid=’$uid'”;

}

if($sname){

$sql.=” and wish.name like ‘%{$sname}%'”;

}

$query = $_SGLOBAL[‘db’]->query($sql);

$count=mysql_num_rows($query);

$sql.=’ order by wishjoin.dateline desc limit ‘.$start.’,’.$perpage;

$query = $_SGLOBAL[‘db’]->query($sql);

while ($value = $_SGLOBAL[‘db’]->fetch_array($query)) {

$value[‘name’] = urlencode ( $value[‘name’] );

$value[‘picfilepath’]= picredirect($value[‘picfilepath’],0,1);

$value[‘dateline’] =  date(‘Y-m-d’,$value[‘dateline’]) ;

$value[‘catname’] = urlencode ( $value[‘catname’] );

$value[‘ttname’] = urlencode ( $value[‘ttname’] );

$wishlist[]=$value;

}

if($wishlist){

$data[‘list’] = $wishlist;

$data[‘result’] = 1;

$data[‘rows’] = $count;

}else{

$msg = urlencode (“nodata”);

$data = array(result => 2,msg => $msg);

}

echo urldecode ( json_encode ( $data ) );

break;

}

?>



版权声明:本文为weixin_29240343原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。