65 lines
1.3 KiB
PHP
65 lines
1.3 KiB
PHP
<?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;
|
|
}
|
|
} |