💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## 接口情况 作者:ncgis 时间:20150421 作用:获取每日特惠商品 提交方法:GET 提交参数 ~~~ limit:每页数量默认10[可选] page:当前页 默认1 [可选] ~~~ 所在文件:product 接口地址:http://test.lingsq.com/index.php/api?method=lingsqapi.api.product.getChannelProduct 正式地址:http://www.lingsq.com/index.php/api?method=lingsqapi.api.product.getChannelProduct 返回数据样式: ~~~ {"data":{"item":[{"id":"1","goods_id":"392","price":"13.500","d_order":"1","is_active":"true","name":"\u5fb7\u8299\u9ed1\u5de7\u514b\u529b84g","imageurl":"http:\/\/test.lingsq.com\/public\/images\/store76\/e5\/de\/5d\/50def4bd43ab5f4b8484261f26d91b7e.jpg?1428719794#h"},{"id":"2","goods_id":"390","price":"5.800","d_order":"2","is_active":"true","name":"\u5fb7\u8299\u9187\u9999\u6469\u5361\u53ca\u70e4\u5df4\u65e6\u672843g","imageurl":"http:\/\/test.lingsq.com\/public\/images\/store76\/9d\/12\/24\/94e8c8ab8fb0dc899f262db2d60a968f.jpg?1428656345#h"}],"total":1,"page":1},"errNo":1,"errMsg":"ok","res":""} ~~~ 参数解释 ~~~ total:总页数 page:当前页 id:推荐id值 goods_id:商品id price:价格 d_order:后台排序字段 is_active:是否激活 name:商品名称 imageurl:图片 ~~~ ## 实现代码 ~~~ public function getChannelProduct() { $time=time(); $type_id=empty($_GET["type_id"])?1:$_GET["type_id"]; $page=empty($_GET["page"])?1:intval($_GET["page"]); $pagelimit=empty($_GET["pagelimit"])?10:intval($_GET["pagelimit"]); $mdl_channel = app::get('cellphone')->model('channel'); $sql=' select a.id,a.goods_id,b.price,a.d_order,a.is_active,b.name,b.image_default_id from sdb_cellphone_channel as a left join sdb_b2c_goods as b on a.goods_id=b.goods_id where a.type_id="'.$type_id.'" and a.start_time<="'.$time.'" and end_time>= "'.$time.'" and a.is_active="true" order by a.d_order asc limit '.($page-1)*$pagelimit.','.$pagelimit; $data = $mdl_channel->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_channel as a left join sdb_b2c_goods as b on a.goods_id=b.goods_id where a.type_id="'.$type_id.'" and a.start_time<="'.$time.'" and end_time>= "'.$time.'" and a.is_active="true" order by a.d_order asc '; $count=$mdl_channel->db->selectrow($count_sql); $g_count=$count['_count']; $total=ceil($g_count/ $pagelimit); $back["item"]=$data; $back["total"]=$total; $back["page"]=$page; $pdata['data']["data"]=$back; $pdata['data']['errNo'] = 1; $pdata['data']['errMsg'] = $this->errMsg($pdata['data']['errNo']); return $pdata['data']; } ~~~