Example #1
0
 function comment_add()
 {
     if (!isset($this->user['user_id']) || $this->user['user_id'] === null) {
         die("未登录用户不能评论");
     }
     if (IReq::get('id') === null) {
         die("传递的参数不完整");
     }
     $id = intval(IReq::get('id'));
     $data['point'] = intval(IReq::get('point', 'post'));
     $data['contents'] = IReq::get("contents", 'post');
     $data['contents'] = htmlspecialchars($data['contents'], ENT_QUOTES);
     $data['status'] = 1;
     if ($data['point'] == 0) {
         die("请选择分数");
     }
     $can_submit = Comment_Class::can_comment($id, $this->user['user_id']);
     if ($can_submit[0] != 1) {
         die("您不能评论此件商品");
     }
     $data['comment_time'] = date("Y-m-d", ITime::getNow());
     $tb_comment = new IModel("comment");
     $tb_comment->setData($data);
     $re = $tb_comment->update("id={$id}");
     if ($re) {
         echo "success";
     } else {
         die("评论失败");
     }
 }
Example #2
0
 /**
  * @brief 进行商品评论 ajax操作
  */
 public function comment_add()
 {
     if (!isset($this->user['user_id']) || $this->user['user_id'] === null) {
         die("未登录用户不能评论");
     }
     if (IReq::get('id') === null) {
         die("传递的参数不完整");
     }
     $id = IFilter::act(IReq::get('id'), 'int');
     $data = array();
     $data['point'] = IFilter::act(IReq::get('point'), 'float');
     $data['contents'] = IFilter::act(IReq::get("contents"), 'content');
     $data['status'] = 1;
     if ($data['point'] == 0) {
         die("请选择分数");
     }
     $can_submit = Comment_Class::can_comment($id, $this->user['user_id']);
     if ($can_submit[0] != 1) {
         die("您不能评论此件商品");
     }
     $data['comment_time'] = date("Y-m-d", ITime::getNow());
     $tb_comment = new IModel("comment");
     $tb_comment->setData($data);
     $re = $tb_comment->update("id={$id}");
     if ($re) {
         //同步更新goods表,comments,grade
         $commentRow = $tb_comment->getObj('id = ' . $id);
         $goodsDB = new IModel('goods');
         $goodsDB->setData(array('comments' => 'comments + 1', 'grade' => 'grade + ' . $commentRow['point']));
         $goodsDB->update('id = ' . $commentRow['goods_id'], array('grade', 'comments'));
         echo "success";
     } else {
         die("评论失败");
     }
 }