<?php
require '../../conn/conn.php';
require '../../conn/function.php';

$action=$_GET["action"];
switch($action){

    case "query":
        $code=t(trim($_POST["code"]));
        $no=t(trim($_POST["no"]));

        if(($_POST["code"]!=$_SESSION["CmsCode"] || $_POST["code"]=="" || $_SESSION["CmsCode"]=="")){
            $_SESSION["CmsCode"]="refresh";
            die("{\"code\":\"refresh\",\"msg\":\"请填写正确的计算结果！\"}");
        } else {
            $_SESSION["CmsCode"]="refresh";
            if($no!=""){
                $O=getlist("select * from sl_orders where (O_no='$no' or O_address='$no') and O_state=1");
                if(count($O)==0){
                    die("{\"msg\":\"未查询到相关订单，请重新输入\"}");
                }else{
                    $arr=array(
                        "msg"=>"success",
                        "data"=>$O
                    );
                    die(json_encode($arr));
                }
            }else{
                die("{\"msg\":\"请输入订单号或者预留的联系方式\"}");
            }
        }
    break;

    case "news":
        $id=intval($_GET["id"]);
        if($id==0){
            $N=getrs("select * from sl_news order by N_id desc");
        }else{
            $N=getrs("select * from sl_news where N_id=$id");
        }
        $N["N_content"]=str_replace("\r\n","<br>",$N["N_content"]);
        die(json_encode($N));
    break;
    case "news_list":
    die(json_encode(getlist("select * from sl_news order by N_id desc")));
    break;
}

?>