ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 接口情况 作者:ncgis 时间:20150422 作用:获取推荐商品 提交方法:GET 提交参数 ~~~ limit:每页数量默认10[可选] page:当前页 默认1 [可选] ~~~ 提交地址:http://test.lingsq.com/index.php/api?method=lingsqapi.api.product.getRecommendProduct 正式地址:http://www.lingsq.com/index.php/api?method=lingsqapi.api.product.getRecommendProduct 返回数据样式: ~~~ { "data": { "total":1, "page":1, "item": [ {"id":"99","goods_id":"329","price":"11.800","d_order":"1","is_active":"true","name":"\u6728\u7cd6\u9187\u4e2d\u74f656g\u871c\u6843\u9999","imageurl":"http:\/\/test.lingsq.com\/public\/images\/store76\/cd\/1b\/a9\/0736f8625d2a24820b74cbd83661ecbe.jpg?1428298520#h"}, {"id":"100","goods_id":"322","price":"4.000","d_order":"1","is_active":"true","name":"\u78e8\u53e4\u529b48g\u5de7\u514b\u529b","imageurl":"http:\/\/test.lingsq.com\/public\/images\/store76\/c2\/2d\/37\/10524725c20132b7a9d3dc4f38a89c06.jpg?1428029680#h"}, {"id":"101","goods_id":"319","price":"3.900","d_order":"1","is_active":"true","name":"\u597d\u591a\u9c7c\u8304\u6c4133g","imageurl":"http:\/\/test.lingsq.com\/public\/images\/store76\/83\/9a\/bf\/52cea1021f0068312e855bbb08c7d463.jpg?1428026605#h"}, {"id":"102","goods_id":"315","price":"17.500","d_order":"1","is_active":"true","name":"12p\u5de7\u514b\u529b\u6d3e","imageurl":"http:\/\/test.lingsq.com\/public\/images\/store76\/43\/5b\/a1\/fb45f314c7158a8857de34412a1ec6d7.jpg?1427965265#h"}, {"id":"103","goods_id":"300","price":"16.900","d_order":"1","is_active":"true","name":"\u6b23\u548c\u516d\u6708\u9c9c\u7279\u7ea7\u539f\u6c41\u9171\u6cb9500ml","imageurl":"http:\/\/test.lingsq.com\/public\/images\/store76\/b2\/df\/ea\/e2d82a7f55cd8ab48ac44d9c01e90a97.jpg?1427955015#h"}, {"id":"104","goods_id":"294","price":"14.800","d_order":"1","is_active":"true","name":"\u6b23\u548c1L\u516d\u6708\u9c9c\u7279\u7ea7\u9171\u6cb9","imageurl":"http:\/\/test.lingsq.com\/public\/images\/store76\/bd\/ab\/9f\/9f0e85b096573d0686e50e1d8883a203.jpg?1427953690#h"}, {"id":"105","goods_id":"290","price":"15.800","d_order":"1","is_active":"true","name":"\u6052\u987a348ml\u65e0\u7cd6\u9999\u918b","imageurl":"http:\/\/test.lingsq.com\/public\/images\/store76\/7d\/65\/e1\/51279add1d53470c5d1e2861ae7950db.jpg?1427952617#h"}, {"id":"106","goods_id":"285","price":"11.900","d_order":"1","is_active":"true","name":"\u6c49\u9ad8\u7eff\u8c46\u7c89\u4e1d500g","imageurl":"http:\/\/test.lingsq.com\/public\/images\/store76\/7b\/c4\/30\/90fc2c690d5c57f3c8a4169dd21ab0e5.jpg?1430379497#h"}, {"id":"108","goods_id":"199","price":"0.100","d_order":"1","is_active":"true","name":"\u5fb7\u56fd\u725b\u5976","imageurl":"http:\/\/test.lingsq.com\/public\/images\/store76\/6a\/86\/61\/1e46c514b6f9afaca7f698d569405f40.jpg?1430382080#h"} ] }, "errNo":1, "errMsg":"ok", "res":"" } ~~~ 数据说明 ~~~ total:总页数 page:当前页 id:推荐id值 goods_id:商品id price:价格 d_order:后台排序字段 is_active:是否激活 name:商品名称 imageurl:图片 ~~~ ## 实现代码 ~~~ public function getRecommendProduct() { $page=empty($_GET["page"])?1:intval($_GET["page"]); $pagelimit=empty($_GET["pagelimit"])?10:intval($_GET["pagelimit"]); $mdl_recgoods = app::get('cellphone')->model('recgoods'); $sql=' select a.id,a.goods_id,b.price,a.d_order,a.is_active,b.name,b.image_default_id from sdb_cellphone_recgoods as a left join sdb_b2c_goods as b on a.goods_id=b.goods_id where a.is_active="true" order by a.d_order asc limit '.($page-1)*$pagelimit.','.$pagelimit; $data = $mdl_recgoods->db->select($sql); if($data) { foreach($data as &$val) { $val['imageurl'] = base_storager::image_path($val['image_default_id'],'s'); unset($val['image_default_id']); } } $count_sql='select count(a.goods_id) as _count from sdb_cellphone_recgoods as a left join sdb_b2c_goods as b on a.goods_id=b.goods_id where a.is_active="true" order by a.d_order asc '; $count=$mdl_recgoods->db->selectrow($count_sql); $g_count=$count['_count']; $total=ceil($g_count/ $pagelimit); $back["total"]=$total; $back["page"]=$page; $back["item"]=$data; $pdata["data"]["data"]=$back; $pdata["data"]['errNo'] = 1; $pdata["data"]['errMsg'] = $this->errMsg($pdata["data"]['errNo']); return $pdata["data"]; } ~~~