初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\course;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class CommentLike extends Model
|
||||
{
|
||||
// 表名
|
||||
public $name = 'comment_like';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'integer';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = false;
|
||||
protected $deleteTime = false;
|
||||
|
||||
/**
|
||||
* 判断某用户是否点赞
|
||||
* @param $commentId
|
||||
* @param $userId
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsLike($commentId,$userId){
|
||||
$res = self::where([
|
||||
'comment_id'=>$commentId,
|
||||
'user_id'=>$userId,
|
||||
'uniacid'=>UNIACID
|
||||
])->find();
|
||||
|
||||
if($res){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 点赞
|
||||
* @param $commentId
|
||||
* @param $userId
|
||||
* @return bool
|
||||
*/
|
||||
public function setLike($commentId,$userId){
|
||||
$isLike = $this->getIsLike($commentId,$userId);
|
||||
|
||||
if($isLike){
|
||||
self::where([
|
||||
'comment_id'=>$commentId,
|
||||
'user_id'=>$userId,
|
||||
])->delete();
|
||||
}else{
|
||||
self::save([
|
||||
'comment_id'=>$commentId,
|
||||
'user_id'=>$userId,
|
||||
'uniacid'=>UNIACID,
|
||||
'createtime'=>time()
|
||||
]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user