CommentController.php
3.24 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
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
class Home_CommentController extends QLib_Controller_Home_Action
{
public function init()
{
$this->QLayoutTitle()->headTitle('我的评论');
$this->_redirector = $this->_helper->getHelper('Redirector');
$this->QLayoutScript()->offsetSetFile(60, $this->_js('jqueryui'))->offsetSetFile(61, $this->_js('global'))->offsetSetFile(62,$this->_js('user_main'));
$this->QLayoutLink()->offsetSetStylesheet(25, $this->_css('common'))->offsetSetStylesheet(26, $this->_css('myyoho'))->offsetSetStylesheet(27, $this->_css('jqueryuicss'));
}
//评论商品
public function indexAction()
{
$this->view->is_comment = $is_comment = $this->helpGquery('is_comment','N');
$this->view->total = QINComments_Models_Record_Client::getTotal($this->uid,$is_comment);
$this->view->count = $count = QINComments_Models_Record_Client::getCountRecord($this->uid,$is_comment);
$this->view->page = $page = $this->helpPaging('yoho')->setTotal($count)->setSize(5);
$this->view->list = QINComments_Models_Record_Client::getRecordList($this->uid,$is_comment,$page->getOffset(),$page->getSize());
}
public function savacommentAction()
{
$content = QLib_Utils_String::String()->pregReplaceHtml($this->helpGpost('content'));
empty($content) ? $this->helpJsonResult(404, '请添加评论内容') : true;
$product_id = (int)$this->helpGpost('product_id');
$product_id < 1 ? $this->helpJsonResult(404, '请选择要发表评论的商品') : true;
$order_code = (int)$this->helpGpost('order_code');
$order_code < 1 ? $this->helpJsonResult(404,'此订单不存在') : true;
$size_name = $this->helpGpost('size_name');
$color_name = $this->helpGpost('color_name');
//是否登录
$uid = $this->uid;
$uid < 1 ? $this->helpJsonResult(404, '登录后才能发表评论。请您先登录') : true;
//是否购买
$order_goods = QINOrders_Models_Goods_Client::getorderID($product_id,$uid);
$orders = QINOrders_Models_Client::getUserOrderByStatus($uid);
$orderstatus = false;
if (!empty($order_goods)){
foreach ($order_goods as $key => $val){
if (!empty($orders[$val['order_id']])){
$orderstatus = true;
break;
}
}
if ($orderstatus == false){
$this->helpJsonResult(404, '您没有购买过此商品,暂时不能评论!');
}
}else{
$this->helpJsonResult(404, '您没有购买过此商品,暂时不能评论!');
}
$comment = QINComments_Models_Client::getCommentByOrder($product_id, $order_code);
!empty($comment) ? $this->helpJsonResult(403, '您已对该商品发布过评论!') : true;
$id = QINComments_Models_Client::setComments($product_id, $uid, $content,1,$order_code,$size_name,$color_name);
if((int)$id > 0){
QINComments_Models_Record_Client::updateRecordById($product_id, $uid, $order_code);
$this->helpJsonResult(200, '评论成功!');
}else{
$this->helpJsonResult(404, '评论失败,请稍后再试');
}
}
}