AddController.class.php
1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* 添加评论接口
* $author$ 何岳龙
* $date$ 2016年8月8日11:43:33
*/
namespace Api\Controller\Comment;
use Common\Common\Comment;
class AddController extends AbstractController
{
public function Index()
{
$postData = I('post.');
// parentId不为空时,rootId不能为空
if (! empty($postData['parentId']) && empty($postData['rootId'])) {
$this->_set_error('_ERR_EMPTY_ROOTID');
return false;
}
// 评论内容不能为空
if (empty($postData['cmtContent'])) {
$this->_set_error('_ERR_EMPTY_CMTCONTENT');
return false;
}
// 评论对象ID不能为空
if (empty($postData['cmtObjid'])) {
$this->_set_error('_ERR_EMPTY_CMTOBJ_ID');
return false;
}
// 评论信息入库
$comment = array(
'memUid' => $this->_login->user['memUid'],
'cmtContent' => $postData['cmtContent'],
'rootId' => $postData['rootId'],
'parentId' => $postData['parentId'],
'cmtObjid' => $postData['cmtObjid'],
'cmtAttachids' => $postData['cmtAttachids'],
'cmtAnonymous' => $postData['cmtAnonymous'] ? $postData['cmtAnonymous'] : 2,
);
$result = Comment::instance()->add($comment);
// 添加评论失败
if (empty($result['epId'])) {
$this->_set_error('_ERR_ADD_COMMENT');
return false;
}
$this->_result = $result;
return true;
}
}