Authored by Rock Zhang

添加商品详情页用户咨询点赞以及有用接口

Code Review By Rock Zhang
... ... @@ -138,4 +138,40 @@ class DetailData
return Yohobuy::post(Yohobuy::API_URL, $param);
}
/**
* 咨询点赞
*
* @param int $uid 用户ID
* @param int $id 咨询ID
* @return array
*/
public static function upvoteConsult($uid, $id)
{
$param = Yohobuy::param();
$param['method'] = 'app.consult.like';
$param['id'] = $id;
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 咨询有用
*
* @param int $uid 用户ID
* @param int $id 咨询ID
* @return array
*/
public static function usefulConsult($uid, $id)
{
$param = Yohobuy::param();
$param['method'] = 'app.consult.useful';
$param['id'] = $id;
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...
... ... @@ -567,6 +567,11 @@ class DetailModel
$build['question'] = $value['ask'];
$build['time'] = $value['askTime'];
$build['answer'] = $value['answer'];
$build['id'] = $value['id'];
$build['isLike'] = $value['isLike'];
$build['like'] = $value['like'];
$build['isUseful'] = $value['isUseful'];
$build['useful'] = $value['useful'];
$result[] = $build;
}
}
... ... @@ -577,6 +582,66 @@ class DetailModel
}
/**
* 咨询点赞
*
* @param int $uid 用户ID
* @param int $id 咨询ID
* @return array
*/
public static function upvoteConsult($uid, $id)
{
$result = array('code' => 400, 'message' => '出错啦~');
do {
$record = DetailData::upvoteConsult($uid, $id);
if (empty($uid)) {
$result['code'] = 401;
$result['message'] = '用户id为空';
break;
}
// 处理数据
if ($record && isset($record['code'])) {
$result['code'] = $record['code'];
$result['message'] = $record['message'];
}
}while(false);
return $result;
}
/**
* 咨询有用
*
* @param int $uid 用户ID
* @param int $id 咨询ID
* @return array
*/
public static function usefulConsult($uid, $id)
{
$result = array('code' => 400, 'message' => '出错啦~');
do {
$record = DetailData::upvoteConsult($uid, $id);
if (empty($uid)) {
$result['code'] = 401;
$result['message'] = '用户id为空';
break;
}
// 处理数据
if ($record && isset($record['code'])) {
$result['code'] = $record['code'];
$result['message'] = $record['message'];
}
}while(false);
return $result;
}
/**
* 获取为你优选的商品
*
* @param int $productSkn 商品SKN
... ...
... ... @@ -163,6 +163,38 @@ class DetailController extends AbstractAction
$this->_view->display('consults', $data);
}
/*
* 咨询点赞
*/
public function consultupvoteAction()
{
$result = array();
if ($this->isAjax()) {
$uid = $this->getUid();
$id = $this->get('id');
$result = \Product\DetailModel::upvoteConsult($uid, $id);
}
$this->echoJson($result);
}
/*
* 咨询有用
*/
public function consultusefulAction()
{
$result = array();
if ($this->isAjax()) {
$uid = $this->getUid();
$id = $this->get('id');
$result = \Product\DetailModel::upvoteConsult($uid, $id);
}
$this->echoJson($result);
}
/**
* 我要咨询表单
*/
... ...