wangtengyu
2018-12-14 b224c25fb0e56fad8c773494422806f0dcba0d35
用户查询接口 by 王腾宇
2 files modified
100 ■■■■■ changed files
api/userApi.php 66 ●●●●● patch | view | raw | blame | history
web/common/interface.func.php 34 ●●●● patch | view | raw | blame | history
api/userApi.php
@@ -7,33 +7,19 @@
require '../framework/bootstrap.inc.php';
require '../web/common/interface.func.php';
if($_SERVER['REQUEST_METHOD'] != 'POST'){
    http_response_code(405);
} else {
    $retData=checkParam($_POST);
    switch ($retData["regMsg"]){
        case "e00000":
            $userApi = new UserApi();
            switch (getUrl($_SERVER['REQUEST_URI']))
            {
                case "getUserList":
                    exit($userApi->getUserList($retData["regData"]));
                    break;
                default: http_response_code(404);
            }
        case "e00001":
            exit(array(
                "rspCode"=>"e00001",
                "rspMsg"=>"接入平台不存在"
            ));
        case "e00002":
        exit(array(
            "rspCode"=>"e00002",
            "rspMsg"=>"鉴权失败"
        ));
init(function($retData) {
    $userApi = new UserApi();
    switch (getUrl($_SERVER['REQUEST_URI']))
    {
        case "getUserList":
            return $userApi->getUserList($retData["repData"]);
        case "getUserOrderList":
            return $userApi->getUserOrderList($retData["repData"]);
        default: http_response_code(404);
    }
}
    return array();
});
class UserApi
@@ -44,8 +30,32 @@
    public function getUserList($param) 
    {
        $sql = "SELECT * from ims_users where invitation_code=:invitationCode";
        return json_encode(pdo_fetchall("SELECT * from ims_users where invitation_code=:invitationCode",array(":invitationCode"=>"ICA001")),JSON_UNESCAPED_UNICODE);
        $sqlParam = array(':invitationCode' => $param["invitationCode"]);
        $sql = "SELECT u.uid,u.username,u.status,u.starttime,u.joindate,u.endtime,p.qq,p.mobile from ims_users u  left join ims_users_profile p on u.uid = p.uid where invitation_code=:invitationCode";
        if ($param['user_name'] != null && $param['user_name'] != ''){
            $sql = $sql." and u.username like '%".$param["user_name"]."%' ";
        }
        if ($param['phone_number'] != null && $param['phone_number'] != ''){
            $sql = $sql." and p.mobile like '%".$param['phone_number']."%' ";
            $sqlParam[":phone_number"] = $param["phone_number"];
        }
        if ($param['status'] != null && $param['status'] != ''){
            $sql = $sql.' and u.status=:status';
            $sqlParam[":status"] = $param["status"];
        }
        if ($param['min_date'] != null && $param['min_date'] != ''){
            $sql = $sql.' and u.joindate<:min_date';
            $sqlParam[":min_date"] = $param["min_date"];
        }
        if ($param['max_date'] != null && $param['max_date'] != ''){
            $sql = $sql.' and u.joindate>:max_date';
            $sqlParam[":max_date"] = $param["max_date"];
        }
        return pdo_fetchall($sql,$sqlParam);
    }
}
web/common/interface.func.php
@@ -17,6 +17,32 @@
define("SHOP_URL", "http://shop.iemsoft.cn");
function init ($fun) {
    if($_SERVER['REQUEST_METHOD'] != 'POST'){
        http_response_code(405);
    } else {
        $retData=checkParam($_POST);
        switch ($retData["rspCode"]){
            case "e00000":
                try {
                    $retData["rspData"] = $fun($retData);
                } catch (Exception $e){
                    $retData["rspCode"] = "e99999";
                    $retData["rspData"] = $e->getMessage();
                }
                break;
            case "e00001":
                $retData["rspMsg"]="接入平台不存在";
                break;
            case "e00002":
                $retData["rspMsg"]="鉴权失败";
                break;
        }
        exit(json_encode($retData,JSON_UNESCAPED_UNICODE));
    }
}
/**
 * 接口数据校验
 * e00000 检验成功
@@ -29,13 +55,13 @@
    $retData = array();
    $sysKey = $systemId[substr($param["id"],0,7)]; 
    if ($sysKey == null){
        $retData["regMsg"] = "e00001";
        $retData["rspCode"] = "e00001";
    } else {
        if (checkSign($param,$sysKey)){
            $retData["regMsg"] = "e00000";
            $retData["regData"] = json_decode($param["data"],true);
            $retData["rspCode"] = "e00000";
            $retData["repData"] = json_decode($param["data"],true);
        } else {
            $retData["regMsg"] = "e00002";
            $retData["rspCode"] = "e00002";
        }    
    }  
    return $retData;