2023-01-29 10:26:52 +08:00

50 lines
1.3 KiB
PHP

<?php
namespace app\common\model;
/**
* 阅读历史模型
*/
class History extends Base{
public function add($uid,$cartoon,$volume,$model=2){
$history = db('history')->where(['articleid'=>$cartoon['id'],'model'=>$model])->where('uid',$uid)->find();
if(count($history)==0){
$data['articleid'] =$cartoon['id'];
$data['uid'] =$uid;
$data['model'] =$model;
$data['name'] =$cartoon['name'];
$data['chapterid'] =$volume['id'];
$data['chaptername'] =$volume['volumename'];
$data['order'] =$volume['volumeorder'];
$data['create_time'] =time();
$data['update_time'] =time();
$res=db('history')->insert($data);
//添加浏览次数
db('cartoon')->where('id',$cartoon['id'])->update(array('allvisit'=>array('exp', '`allvisit`+1')));
if($res){
return true;
}
}else{
//更新记录表
$data['chapterid'] =$volume['id'];
$data['chaptername'] =$volume['volumename'];
$data['order'] =$volume['volumeorder'];
$data['update_time'] =time();
db('history')->where('id',$history['id'])->update($data);
return true;
}
}
public function find($uid,$bookid,$model) {
$history = db('history')->where(array('model'=>$model,'articleid'=>$bookid,'uid'=>$uid))->find();
if($history){
return $history;
}else{
return 0;
}
}
}