public function do_like() { $this->check_login(); $id = intval($_GET['id']); //posts表中id $posts_model = M("Posts"); $can_like = sp_check_user_action("posts{$id}", 1); if ($can_like) { $posts_model->save(array("id" => $id, "post_like" => array("exp", "post_like+1"))); $this->success("赞好啦!"); } else { $this->error("您已赞过啦!"); } }
public function do_like() { $this->check_login(); $object_id = $_GET['id']; //content表中id $can_like = sp_check_user_action($object_id, 1); //这个函数是会有副作用的,不只是简单的check。如果没有结果会写数据库,坑。 if ($can_like) { D('content')->saveByUUID($object_id, array("post_like" => array("exp", "post_like+1"))); D('like')->data(['user_id' => sp_get_current_userid(), 'object_id' => $object_id])->add(); $this->success("赞好啦!"); } else { $this->error("您已赞过啦!"); } }
public function set_like() { $this->check_login(); $id = intval($_GET['id']); $type = intval($_GET['like_type']); if ($type != 1) { $type = -1; } $can_set_like = sp_check_user_action("qiushi{$id}", 1); if ($can_set_like) { if ($type == 1) { M("Qiushi")->save(array("id" => $id, "likes" => array("exp", "likes+1"))); $this->success("您赞了一个!"); } else { M("Qiushi")->save(array("id" => $id, "unlikes" => array("exp", "unlikes+1"))); $this->success("您拍了一板砖!"); } } else { $this->error("您已经点过了!"); } }