## 接口情況
作者:ncgis
時間:20150422
作用:獲取商品評論
提交方法:GET
提交參數
~~~
good_id:商品id
limit:每頁數量默認10[可選]
page:當前頁 默認1 [可選]
~~~
所在文件:product
接口地址:http://test.lingsq.com/index.php/api?method=lingsqapi.api.product.commentdetail&good_id=[good\_id]&limit=[limit]&page=[page]
返回數據樣式:
~~~
{
"status":false,
"comment_count":1,
"data":
[
{
"author":"\u4e70\u5bb6\uff1ab****6",
"time":"2015-04-22 08:56:42",
"comment":"\u5f88\u597d\u6211\u6536\u5230\u8d27\u4e86",
"items":
[
{"author":"b****6","time":"2015-04-22 08:57:35","comment":"\u4e0d\u9519\u54e6"}
]
}
],
"goods_point":
{
"avg_num":"5.00",
"avg":5,
"count":"1"
}
}
~~~
數據說明
~~~
status:用戶登錄狀態
comment_count:評論數量
author:評論用戶
time:評論時間
comment:評論
items:追加評論項
avg_num:平均數
avg:(不曉得和上面的有什么區別)
count:評論總數
~~~
## 實現代碼
~~~
public function commentdetail()
{
if(empty($_GET["good_id"]))
{
$back["errNo"]=20005;
$back["errMsg"]=$this->errMsg($back["errNo"]);
return $back;
}
$page=empty($_GET["page"])?1:$_GET["page"];
$limit=$_GET["limit"];
$page = intval($page);
$gid = intval($_GET["good_id"]);
$limit = $limit?intval($limit):10;
$offset = ($page-1)*$limit;
$aData = array();
$aData['status'] = $this->member_id?true:false;
$objComment = &app::get('b2c')->model('member_comments');
$filter = array('type_id'=>$gid,'object_type'=>'discuss','for_comment_id'=>0,'display'=>'true','comments_type'=>'1','comment|noequal'=>'','comment|noequal'=>null);
$aData['comment_count'] = $objComment->count($filter);
$sql = " select c.comment_id,c.author,c.time,c.comment,c.addon,c.author_id,m.name as author_alias
from sdb_b2c_member_comments as c
left join sdb_b2c_members as m on c.author_id=m.member_id
left join sdb_b2c_order_items as i on c.order_id=i.order_id and c.type_id=i.goods_id
where c.object_type='discuss' and c.for_comment_id=0 and c.type_id=".intval($gid)." and c.display='true' and c.comments_type='1' and c.comment is not null and c.comment != ''
group by comment_id,i.goods_id order by time desc limit {$offset},{$limit}";
$aData['data'] = array();
$aId = array();
foreach((array)$objComment->db->select($sql) as $val){
$val['addon'] = unserialize($val['addon']);
if(!empty($val['author_alias'])) $val['author'] = $val['author_alias'];
if(isset($val['addon']['hidden_name']) && $val['addon']['hidden_name'] == 'YES' && ($val['author_id'] !=0 || $val['author_id'] !=1)){
$val['author'] = mb_substr($val['author'], 0, 1, 'UTF-8').'****'.mb_substr($val['author'], mb_strlen($string, 'UTF-8')-1, 1, 'UTF-8');
}
$val['author'] = '買家:'.$val['author'];
$val['time'] = date('Y-m-d H:i:s',$val['time']);
$aId[] = $val['comment_id'];
unset($val['author_alias'],$val['author_id'],$val['addon']);
$aData['data'][] = $val;
}
if(!empty($aId)){
$addition = array();
$temp = $objComment->getList('comment_id,for_comment_id',array('for_comment_id' => $aId,'comments_type'=>'3','display' => 'true'));
foreach((array)$temp as $rows){
$aId[] = $rows['comment_id'];
$addition[$rows['for_comment_id']][] = $rows['comment_id'];
}
$aReply = (array)kernel::single('business_message_disask')->getCommentsReply($aId, true);
foreach((array)$aData['data'] as $key => $rows){
foreach($aReply as $rkey => $rrows){
$condition1 = $rows['comment_id'] == $rrows['for_comment_id'];
$condition2 = !empty($addition) && isset($addition[$rows['comment_id']]) && in_array($rrows['for_comment_id'],$addition[$rows['comment_id']]);
if($condition1 || $condition2){
$aData['data'][$key]['items'][] = array(
'author' => ($aReply[$rkey]['comments_type']==0&&$aReply[$rkey]['author']!='管理員')?'掌柜':$aReply[$rkey]['author'],
'time' => date('Y-m-d H:i:s',$aReply[$rkey]['time']),
'comment' => $aReply[$rkey]['comment'],
);
}
}
unset($aData['data'][$key]['comment_id']);
}
}
$args = array($gid,$page);
$objGoods = app::get('b2c')->model('goods');
$objPoint = app::get('business')->model('comment_goods_point');
$aGoods_list = $objGoods->getRow('avg_point,comments_count',array('goods_id'=>$gid,'store_id|than'=>0));
$aData['goods_point'] = array('avg_num'=>$aGoods_list['avg_point'],'avg'=>$objPoint->star_class($aGoods_list['avg_point']),'count'=>$aGoods_list['comments_count']);
return $aData;
}
~~~
- 手機是否使用驗證接口
- 返回碼所代表的含義
- 發送手機驗證碼接口
- 用戶注冊接口
- 獲取商品所有分類
- 獲取商品列表
- 用戶登陸接口
- 獲取商品詳細信息
- 獲取產品圖文詳情
- 獲取商品評論列表
- 獲取推薦商品
- 獲取找回密碼短信
- 重置密碼
- 獲取每日特惠商品
- 獲取輪播圖
- 用戶中心首頁
- 獲取用戶收藏商品
- 刪除用戶收藏商品
- 獲取所有訂單(所有訂單、代付款訂單、待收貨訂單、退換貨訂單)
- 加入購物車
- 獲取購物車商品
- 刪除購物車商品
- 購物車商品移入收藏夾
- 添加收貨地址
- 獲取用戶收貨地址
- 添加用戶收藏
- 提交訂單
- 填寫訂單
- 退出登錄
- 確認支付成功(正在驗證支付狀態)
- 驗證自動登陸
- 獲取訂單詳情
- 設置默認收貨地址
- 刪除收貨地址
- 修改收貨地址