$user_id=$_GET['user_id'];
if(!$user_id){
$arr=array('code'=>-1,'data'=>"用户不存在");
echo json_encode($arr);exit;
}
$time=time();
//$pay_sql=$db->query("update ecs_order_info set shipping_status=2,order_status=0 where pay_status=2 and pay_time+7200<'$time'");
$state=isset($_GET['state'])?$_GET['state']:1;
$mark = 1;
switch($state){
case 1:
/*订单列表*/
$page=$_GET['page']?$_GET['page']:'1';
$num=20;
$limit=($page-1)*$num;
/*找出用户的所有订单号*/
$sql="select order_id,order_sn,goods_amount,order_amount,add_time,exchange_goods,exchange_shop,user_id from ecs_order_info where user_id='$user_id' order by add_time desc limit $limit,$num";
$data=$db->getAll($sql);
$count=$db->getOne("select count(order_id) as orderSum from ecs_order_info where user_id='$user_id'");
$res=array();
/*循环订单号数组*/
foreach($data as $key=>$value){
$data2 = array();
$order_id=$value['order_id'];
$order_sn=$value['order_sn'];
$goods_amount=$value['goods_amount'];//商品总金额
$order_amount =$value['order_amount'];//应付总金额
$exchange_shop=$value['exchange_shop'];/*订单数量*/
$exchange_goods=$value['exchange_goods'];
if($exchange_goods==null){
$exchange_goods=0;
}
if($exchange_goods==1){
/*如果是积分 根据订单ID去查订单的商品属性*/
$order_sql="select goods.goods_sn,goods.goods_name,goods.goods_id,info.goods_amount,goods.goods_brief,goods.goods_img,goods_thumb,g.goods_number,info.pay_status,info.shipping_status,g.goods_price,info.add_time,e.exchange_integral,info.exchange_shop,g.goods_attr,g.rec_id FROM ecs_order_info as info left join ecs_order_goods as g on g.order_id=info.order_id left join ecs_goods as goods on g.goods_id=goods.goods_id left join ecs_exchange_goods as e on g.goods_id=e.goods_id where g.order_id='$order_id' and user_id='$user_id'";
}
else{
/*根据订单ID去查订单的商品属性*/
$order_sql="select goods.goods_sn,goods.goods_name,goods.goods_id,info.goods_amount,goods.shop_price,goods.goods_brief,goods.goods_img,goods_thumb,g.goods_number,g.goods_price,info.pay_status,info.shipping_status,info.add_time,info.order_id,g.goods_attr,g.rec_id FROM ecs_order_info as info left join ecs_order_goods as g on g.order_id=info.order_id left join ecs_goods as goods on g.goods_id=goods.goods_id where g.order_id='$order_id' and user_id='$user_id'";
}
$date=$db->getAll($order_sql);
//var_dump($date);exit;
if(!$date){
$mark = 0;
}
$data2['res'] = $date;
// $price_money=0;
foreach ($data2['res'] as $k => $v){
/*统计用户订单下的商品数量*/
$goods_number="select sum(goods_number) from ecs_order_goods where order_id='$order_id'";
$number=$db->getOne($goods_number);
// /*计算用户订单的总价钱*/
if($exchange_goods==1){
$price_money=$data2['res'][$k]['exchange_integral']*$exchange_shop;
}else{
$price_money += $data2['res'][$k]['shop_price']*$data2['res'][$k]['goods_number'];
}
$add_time=$v['add_time'];
$add_timed=date("Y-m-d H:i:s",$add_time);
$order_status=$v['pay_status'];
$goods_id=$v['goods_id'];
$data2['res'][$k]['goods_thumb']=constant("FU_ZHUANG").$v['goods_thumb'];
$data2['res'][$k]['goods_img']=constant("FU_ZHUANG").$v['goods_img'];
$data2['res'][$k]['original_img']=constant("FU_ZHUANG").$v['original_img'];
if($order_status==0){
$order_status="去付款";
}elseif($order_status==1){
$order_status="付款中";
}elseif($order_status==2){
$order_status="已付款";
if ($v['shipping_status']==1){
$order_status = '已发货';
}elseif ($v['shipping_status']==2){
$order_status = '已收货';
}elseif($v['shipping_status']==4){
$order_status = '退货中';
}elseif ($v['shipping_status']==5){
$order_status = '已完成';
}elseif ($v['shipping_status']==6){
$order_status = '退货成功';
}elseif ($v['shipping_status']==7){
$order_status = '退货失败';
}elseif ($v['shipping_status']==0){
$order_status = '未发货';
}
}elseif($order_status==9){
$order_status="货到付款";
}
}
/*这个订单下评论的用户*/
$comment_sql="select * from ecs_comment where order_id='$order_id' and id_value='$goods_id' and user_id='$user_id'";
$comment=$db->getAll($comment_sql);
if($comment){
$comment="已评价";/*已经评价*/
}else{
$comment="未评价";/*未评价*/
}
$data2['comment']=$comment;/*是否评论*/
if($v['pay_status'] == 9){
if($comment == "未评价"){
$data2['comment'] = '未确认';
}
}elseif($v['pay_status'] == 0){
unset($data2['comment']);
}
$data2['order_id']=$order_id;/*订单号*/
if($exchange_goods==1){
$data2['number']=$exchange_shop;/*订单数量*/
$type=1;
$data2['type']=$type;
}else{
$data2['number']=$number;/*订单数量*/
$type=0;
$data2['type']=$type;
}
$data2['order_sn']=$order_sn;/*订单编号*/
$data2['order_id']=$order_id;/*订单号*/
$data2['goods_amount']=$goods_amount;//商品总金额
$data2['order_amount'] =$order_amount;//应付总金额
$data2['price']=$price_money;/*订单总价钱*/
$data2['add_time']=$add_timed;/*订单时间*/
$data2['order_status']=$order_status;/*订单状态*/
array_push($res,$data2);
}
if($mark == 0){
$arr=array('code'=>0,'data'=>$res,'msg'=>"商品信息不完全",'count'=>$count);
}else{
$arr=array('code'=>0,'data'=>$res,'count'=>$count);
}
echo json_encode($arr);
break;
错误总结 sql查询时候查询错误然后 报错引起的错误
$v['shipping_status'] =XX;
sql查询没有以后注意打印数据