PHP写接口的日常

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP写接口的日常相关的知识,希望对你有一定的参考价值。

public function commentList(){
    $info = $this->getUserByToken();
    $shop_id = $info[‘shop_id‘];
    $page = I(‘post.page‘)?:1;
    $pagesize = I(‘post.pagesize‘)?:C(‘ROLLPAGE‘);
    $c_type = I(‘post.c_type‘);
    $serach = I(‘post.serach‘);
    $and = "";
    if($c_type == 1){  #  商品
        if($c_type != 0){
            $and .= " and co.c_type=‘{$c_type}‘";
        }
        if($search){
            $and .= " and (c.c_name like ‘%{$search}%‘)";
        }
    }else{
        $sql0 = "select count(s.s_id) as itemcount from `erp_commod_comment` as co left join `erp_shopping_service` as s on co.c_id=s.s_id left join `erp_customer` as cu on co.customer_id=cu.customer_id where co.shop_id=‘{$shop_id}‘{$and}";
    }
    if($c_type == 1){  #  商品
        $sql0 = "select count(c.c_id) as itemcount from `erp_commod_comment` as co left join `erp_commod` as c on co.c_id=c.c_id left join `erp_customer` as cu on co.customer_id=cu.customer_id where co.shop_id=‘{$shop_id}‘{$and}";
    }else{
        $sql0 = "select count(s.s_id) as itemcount from `erp_commod_comment` as co left join `erp_shopping_service` as s on co.c_id=s.s_id left join `erp_customer` as cu on co.customer_id=cu.customer_id where co.shop_id=‘{$shop_id}‘{$and}";
    }
    $itemcount = M()->query($sql0)[0][‘itemcount‘];
    $pagecount = ceil($itemcount/$pagesize);
    $limit = ($page-1)*$pagesize;
    $offset = " limit {$limit},{$pagesize}";
    if($c_type == 1){  #  商品
        $sql1 = "select c.c_id,c.c_pic,c.c_name,cu.customer_id,cu.customer_name,cu.customer_type,cu.headimgurl,co.com_id,co.com_content,co.com_time,co.com_score,co.thumb_num,co.com_is_return,co.com_status from `erp_commod_comment` as co left join `erp_commod` as c on co.c_id=c.c_id left join `erp_customer` as cu on co.customer_id=cu.customer_id where co.shop_id=‘{$shop_id}‘{$and} order by co.com_status asc,co.com_time desc{$offset}";
    }else{  #  服务
        $sql1 = "select s.s_id,s.s_pic,s.s_name,cu.customer_id,cu.customer_name,cu.customer_type,cu.headimgurl,co.com_id,co.com_content,co.com_time,co.com_score,co.thumb_num,co.com_is_return,co.com_status from `erp_commod_comment` as co left join `erp_shopping_service` as s on co.c_id=s.s_id left join `erp_customer` as cu on co.customer_id=cu.customer_id where co.shop_id=‘{$shop_id}‘{$and} order by co.com_status asc,co.com_time desc{$offset}";
    }
    $sql1 = "";
    $data = M()->query($sql1);
    foreach ($data as $key => $value) {
        $data[$key][‘shop_id‘] = M(‘commod‘,‘erp_‘)->where([‘c_id‘=>$value[‘c_id‘]])->getField(‘shop_id‘);
    }
    $ret = array();
    $ret[‘data‘] = $data;
    $ret[‘page‘] = array(
            ‘pagecount‘=>(int)$pagecount,
            ‘itemcount‘=>(int)$itemcount,
        );
    $this->ret(1,‘‘,$ret);
}

以上是关于PHP写接口的日常的主要内容,如果未能解决你的问题,请参考以下文章

译文:18个实用的JavaScript代码片段,助你快速处理日常编程任务

日常Google翻译接口编写

php如何实现多继承?

超级有用的9个PHP代码片段

Python如何调用别人写好的脚本

PHP必用代码片段