model_id = $model_id = $this->request->param('model_id');
$this->model_id = $model_id = 1;
$list = db('Model')->column('*', 'id');
if (empty($list[$model_id])) {
return $this->error("无此模型!");
} else {
$this->modelInfo = $list[$model_id];
$this->model = M($this->modelInfo['name']);
}
$this->assign('model_id', $model_id);
$this->assign('model_list', $list);
}
/**
* 内容列表
* @return [html] [页面内容]
* @author netlife <40150501@qq.com>
*/
public function index() {
if ($this->modelInfo['list_grid'] == '') {
return $this->error("列表定义不正确!", url('admin/model/edit', array('id' => $this->modelInfo['id'])));
}
$allvisit = input('allvisit');
$is_new = input('is_new');
$is_free = input('is_free');
$booknumber = input('booknumber');
if($is_new && $allvisit =='asc'){
$order = "`index` DESC,allvisit asc,id desc";
}elseif($is_new && $allvisit =='desc'){
$order = "`index` DESC,allvisit desc,id desc";
}elseif(empty($is_new)&&$allvisit =='asc'){
$order = "`index` DESC,id desc";
}elseif($is_new&&empty($allvisit)){
$order = "`index` DESC,id desc";
}else{
$order = "`index` DESC";
}
$grid_list = get_grid_list($this->modelInfo['list_grid']);
//$order = "id desc";
$map = $this->buildMap();
$field = array_filter($grid_list['fields']);
if($is_free){
$articleid = db('limitedfree')->where('enddate >'.time())->order('create_time DESC')->limit(1)->value('articleid');
$map['id'] = ['in',$articleid];
}
if($booknumber){
$map['booknumber'] = $booknumber;
}
//原order 排序等于 上面$order
$list = $this->model->where($map)->order('id desc')->paginate($this->modelInfo['list_row'],false,['query' => ['is_new'=>input('is_new'),'status'=>input('status'),'channel'=>input('channel'),'category_id'=>input('category_id'),'fullflag'=>input('fullflag'),'allvisit'=>$allvisit,'booknumber'=>$booknumber]]);
$category = db('category')->where('model_id=1')->select();
//获取授权用户组
$access = config('cartoon_access');
//获取当前用户组
$group = session('user_auth.group');
$data = array(
'grid' => $grid_list,
'list' => $list,
'page' => $list->render(),
'group' => $group,
'is_new' => input('is_new'),
'is_free' => input('is_free'),
'status' => input('status'),
'channel' => input('channel'),
'fullflag'=> input('fullflag'),
'category'=> $category,
'category_id'=>input('category_id'),
'access' => $access,
'allvisit' => $allvisit,
'cid' => input('cid'),
'cp' => cp(),
);
if ($this->modelInfo['template_list']) {
$template = 'content/' . $this->modelInfo['template_list'];
}
$this->assign($data);
$this->setMeta($this->modelInfo['title'] . "列表");
return $this->fetch($template);
}
/*****本周推荐*****/
public function recommend() {
if ($this->modelInfo['list_grid'] == '') {
return $this->error("列表定义不正确!", url('admin/model/edit', array('id' => $this->modelInfo['id'])));
}
$order = "`index` DESC";
$grid_list = get_grid_list($this->modelInfo['list_grid']);
//$order = "id desc";
$map = $this->buildMap();
$field = array_filter($grid_list['fields']);
$map['']=['exp','FIND_IN_SET(9,is_top)'];
$list = $this->model->where($map)->order($order)->paginate($this->modelInfo['list_row']);
$category = db('category')->where('model_id=1')->select();
$data = array(
'grid' => $grid_list,
'list' => $list,
'page' => $list->render(),
'category'=> $category
);
$this->assign($data);
$this->setMeta("本周推荐");
return $this->fetch();
}
/*****派单榜单*****/
public function hot() {
if ($this->modelInfo['list_grid'] == '') {
return $this->error("列表定义不正确!", url('admin/model/edit', array('id' => $this->modelInfo['id'])));
}
$order = "`index` DESC";
$grid_list = get_grid_list($this->modelInfo['list_grid']);
//$order = "id desc";
$map = $this->buildMap();
$field = array_filter($grid_list['fields']);
$map['']=['exp','FIND_IN_SET(10,is_top)'];
$list = $this->model->where($map)->order($order)->paginate($this->modelInfo['list_row']);
$category = db('category')->where('model_id=1')->select();
$data = array(
'grid' => $grid_list,
'list' => $list,
'page' => $list->render(),
'category'=> $category
);
$this->assign($data);
$this->setMeta("本周推荐");
return $this->fetch();
}
/**
* 内容添加
* @author netlife <40150501@qq.com>
*/
public function add() {
if (IS_POST) {
$this->param['uid'] = session('user_auth.uid');
$result = $this->model->save($this->param);
if ($result) {
//记录行为
action_log('add_content', 'content', $result, session('user_auth.uid'));
return $this->success("添加成功!", url('admin/novel/index', array('model_id' => $this->modelInfo['id'])));
} else {
return $this->error($this->model->getError(), url('admin/novel/add', array('model_id' => $this->modelInfo['id'])));
}
} else {
$info = array(
'model_id' => $this->modelInfo['id'],
);
$data = array(
'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo),
);
if ($this->modelInfo['template_add']) {
$template = 'content/' . $this->modelInfo['template_add'];
} else {
$template = 'novel/edit';
}
$this->assign($data);
$this->setMeta("添加" . $this->modelInfo['title']);
return $this->fetch($template);
}
}
/**
* 数字转汉字
*
* @return type
**/
public function numToWord($num)
{
$chiNum = array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');
$chiUni = array('','十', '百', '千', '万', '亿', '十', '百', '千');
$chiStr = '';
$num_str = (string)$num;
$count = strlen($num_str);
$last_flag = true; //上一个 是否为0
$zero_flag = true; //是否第一个
$temp_num = null; //临时数字
$chiStr = '';//拼接结果
if ($count == 2) {//两位数
$temp_num = $num_str[0];
$chiStr = $temp_num == 1 ? $chiUni[1] : $chiNum[$temp_num].$chiUni[1];
$temp_num = $num_str[1];
$chiStr .= $temp_num == 0 ? '' : $chiNum[$temp_num];
}else if($count > 2){
$index = 0;
for ($i=$count-1; $i >= 0 ; $i--) {
$temp_num = $num_str[$i];
if ($temp_num == 0) {
if (!$zero_flag && !$last_flag ) {
$chiStr = $chiNum[$temp_num]. $chiStr;
$last_flag = true;
}
}else{
$chiStr = $chiNum[$temp_num].$chiUni[$index%9] .$chiStr;
$zero_flag = false;
$last_flag = false;
}
$index ++;
}
}else{
$chiStr = $chiNum[$num_str[0]];
}
return $chiStr;
}
/**
* uploadbook [上传小说]
*
* @return type
**/
public function uploadbook() {
if (IS_POST) {
$ebook = input('post.ebook');
if(empty($ebook)){
return $this->error("电子书不能为空");
}
if(empty($this->param["category_id"])){
return $this->error("小说分类不能为空");
}
if(empty($this->param["title"])){
return $this->error("小说名字不能为空");
}
//小说存在
$articleinfo = db('novel')->where('title','like','%'.$this->param["title"].'%')->value('id');
if($articleinfo){
$articleid =$articleinfo;
$chapters = db('novel')->where('title','like','%'.$this->param["title"].'%')->value('chapters');
}else{//不存在
$this->param['create_time'] = time();
$this->param['update_time'] = time();
$result = $this->model->save($this->param);
$articleid = $this->model->getLastInsID();
$chapters =0;
}
//增加章节
if($articleid){
if($this->param["booktypes"] == 2){
$bookList = $this->readList($ebook, $this->param["booktypes"]);
}else{
$bookList = $this->readList($ebook, 1);
}
$i = $chapters?$chapters:1;
foreach($bookList as $k=>$v){
$chapterdata['articleid'] = $articleid;
$chapterdata['uid'] = session("user_auth.uid");
$chapterdata['chaptername'] = $v["name"];
//$chapterdata['content'] = $v["content"];
$chapterdata['create_time'] = time();
$chapterdata['update_time'] = time();
$chapterdata['size'] = get_count_content($v['content']);
$chapterdata['saleprice'] = round($chapterdata['size']/1000*config('wordsperegold'));
if($i>20){
$chapterdata['isvip'] = 1;
$chapterdata['saleprice'] = round($chapterdata['size']/1000*config('wordsperegold'));
}
$chapterdata['chapterorder'] = $i;
$chapterdata['articlename'] = $this->param['title'];
db('chapter')->insert($chapterdata);
$chapterId = db('chapter')->getLastInsID();
//更新小说章节内容
$ocontent['chapterid'] = $chapterId;
$ocontent['content'] = $this->format_content($v["content"]);
//数据分表开启的时候
if(config('partition')){
$rule = [
'type' => 'mod', // 分表方式
'num' => 10 // 分表数量
];
db("novel_content")->partition(['chapterid' => $chapterId], "chapterid", $rule)->insert($ocontent);
}else{
db("novel_content")->insert($ocontent);
}
//更新小说章节最新信息
db('novel')->where(array('id'=>$articleid))->update(array('lastvolumeid'=>$chapterId,'lastvolume'=>$v["name"]));
$size += $chapterdata['size'];
$i++;
}
//更新小说总字数
db('novel')->where(array('id'=>$articleid))->update(array('chapters'=>count($bookList),'update_time'=>time(),'size'=>array('exp', '`size`+'.$size)));
}
//记录行为
action_log('add_content', 'content', $result, session('user_auth.uid'));
return $this->success("添加成功!", url('admin/novel/index', array('model_id' => $this->modelInfo['id'])));
/**
} else {
return $this->error($this->model->getError(), url('admin/novel/add', array('model_id' => $this->modelInfo['id'])));
}
***/
} else {
$info = array(
'model_id' => $this->modelInfo['id'],
);
$data = array(
'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo),
);
$this->assign($data);
$this->setMeta("上传小说");
return $this->fetch();
}
}
/**
* chapterupdate [章节批量更新]
*
* @return type
**/
public function chapterupdate() {
if (IS_POST) {
$ebook = input('post.ebook');
$articleid = $bookid = input('post.bookid');
if(empty($bookid)){
return $this->error("小说不存在");
}
if(empty($ebook)){
return $this->error("电子书不能为空");
}
//增加章节
if($bookid){
$chapterlist = db('chapter')->where('articleid='.$bookid)->order('chapterorder ASC')->column('id');
$bookList = $this->readList($ebook, 1);
//上传的章节大于目前章节
if(count($bookList)>=count($chapterlist)){
$i=1;
$size = 0;
foreach($bookList as $k=>$v){
if($chapterlist[$k]){
$chapterdata['chaptername'] = $v["name"];
$chapterdata['update_time'] = time();
$chapterdata['size'] = get_count_content($v['content']);
// if($i>20 && $chapterdata['saleprice'] == 0){
// $chapterdata['isvip'] = 1;
// if($chapterlist[$k]['saleprice'] <= 30){
// $chapterdata['saleprice'] = 50;
// }
// }
$chapterdata['chapterorder'] = $i;
db('chapter')->where('id', $chapterlist[$k])->update($chapterdata);
$lastvolumeid = $chapterlist[$k];
//更新小说章节内容
$ocontent['content'] = $this->format_content($v["content"]);
//数据分表开启的时候
if(config('partition')){
$rule = [
'type' => 'mod', // 分表方式
'num' => 10 // 分表数量
];
db("novel_content")->partition(['chapterid' =>$chapterlist[$k]], "chapterid", $rule)->where('chapterid', $chapterlist[$k])->update($ocontent);
}else{
db("novel_content")->where('chapterid',$lastvolumeid)->update($ocontent);
}
//记录行为
action_log('update_chapter', 'chapter', $lastvolumeid,session('user_auth.uid'));
}else{//章节不存在的情况下
$chapterdata['articleid'] = $articleid;
$chapterdata['uid'] = session("user_auth.uid");
$chapterdata['chaptername'] = $v["name"];
$chapterdata['create_time'] = time();
$chapterdata['update_time'] = time();
$chapterdata['size'] = get_count_content($v['content']);;
// if($i>20 && $chapterdata['saleprice'] == 0){
// $chapterdata['isvip'] = 1;
// $chapterdata['saleprice'] = 50;
// }
$chapterdata['chapterorder'] = $i;
$chapterdata['articlename'] =get_novel($bookid,'title');
db('chapter')->insert($chapterdata);
$lastvolumeid = $chapterId = db('chapter')->getLastInsID();
//更新小说章节内容
$ocontent['chapterid'] = $chapterId;
$ocontent['content'] = $this->format_content($v["content"]);
//数据分表开启的时候
if(config('partition')){
$rule = [
'type' => 'mod', // 分表方式
'num' => 10 // 分表数量
];
db("novel_content")->partition(['chapterid' => $chapterId], "chapterid", $rule)->insert($ocontent);
}else{
db("novel_content")->insert($ocontent);
}
//记录行为
action_log('add_chapter', 'chapter', $lastvolumeid,session('user_auth.uid'));
}
//更新小说章节最新信息
db('novel')->where(array('id'=>$bookid))->update(array('lastvolumeid'=>$lastvolumeid,'lastvolume'=>$v["name"]));
$size += $chapterdata['size'];
$i++;
}
//更新小说总字数
db('novel')->where(array('id'=>$bookid))->update(array('chapters'=>$i,'update_time'=>time(),'size'=>$size));
}else{
$i=0;
$chapterorder = 1;
$size = 0;
$notchapter = array();
foreach($chapterlist as $k=>$v){
if($v&&$bookList[$i]){
$chapterid= $v;
$chapterdata['chaptername'] = $bookList[$i]["name"];
$chapterdata['update_time'] = time();
$chapterdata['size'] = get_count_content($bookList[$i]['content']);
// if($i>20 && $chapterdata['saleprice'] == 0){
// $chapterdata['isvip'] = 1;
// if($v['saleprice'] <= 30){
// $chapterdata['saleprice'] = 50;
// }
// }
$chapterdata['chapterorder'] = $chapterorder;
db('chapter')->where('id', $chapterid)->update($chapterdata);
$lastvolumeid = $chapterid;
//更新小说章节内容
$ocontent['content'] = $this->format_content($bookList[$i]["content"]);
//数据分表开启的时候
if(config('partition')){
$rule = [
'type' => 'mod', // 分表方式
'num' => 10 // 分表数量
];
db("novel_content")->partition(['chapterid' => $chapterid], "chapterid", $rule)->where('chapterid',$chapterid)->update($ocontent);
}else{
db("novel_content")->where('chapterid',$chapterid)->update($ocontent);
}
//记录行为
action_log('update_chapter', 'chapter', $chapterid,session('user_auth.uid'));
//更新小说章节最新信息
db('novel')->where(array('id'=>$bookid))->update(array('lastvolumeid'=>$lastvolumeid,'lastvolume'=>$bookList[$i]["name"]));
$size += $chapterdata['size'];
$i++;
}else{//章节不存在的情况下
$notchapter[]=$v;
}
$chapterorder++;
}
//更新小说总字数
db('novel')->where(array('id'=>$bookid))->update(array('chapter'=>$i,'update_time'=>time(),'size'=>$size));
//删除不存在的章节
if($notchapter){
//删除章节
db('chapter')->where(['id'=>array('IN',$notchapter)])->delete();
//删除章节内容
db('novel_content')->where(['chapterid'=>array('IN',$notchapter)])->delete();
//记录行为
action_log('delete_chapter', 'chapter', '', session('user_auth.uid'));
}
}
Cache::store('redis')->set('chapterinfo'.$lastvolumeid,'');
Cache::store('redis')->set('chaptercontent'.$lastvolumeid, '');
}
return $this->success("更新成功!", url('admin/novel/index'));
} else {
$this->assign('bookid',input('id'));
$this->setMeta("章节批量更新");
return $this->fetch();
}
}
public function setfocuschapter() {
$bookid = input('bookid');
$volumeorder = input('volumeorder');
$uid = session('user_auth.uid');
//是否存在此本书的关注信息
$focuschapter = db('chapter_focus')->where(array('uid'=>$uid,'articleid'=>$bookid))->find();
if($focuschapter){
$result =db('chapter_focus')->where(array('uid'=>$uid,'articleid'=>$bookid))->setField('focuschapter', $volumeorder);
}else{
$data = array(
"uid"=>$uid,
"create_time"=>time(),
"update_time"=>time(),
"articleid"=>$bookid,
"focuschapter"=>$volumeorder
);
$result=db('chapter_focus')->insert($data);
}
if (false !== $result) {
//批量设置推广链接关注章节
$tuiguang = db('tuiguang')->where(array('uid'=>$uid,'articleid'=>$bookid))->column('id');
if($tuiguang){
foreach ($tuiguang as $k=>$v){
db('tuiguang')->where('id='.$v)->setField('followchapter', $volumeorder);
}
}
return $this->success("操作成功!");
} else {
return $this->error("操作失败!!");
}
}
public function sync() {
header('Content-Type: text/event-stream'); // 以事件流的形式告知浏览器进行显示
header('Cache-Control: no-cache'); // 告知浏览器不进行缓存
header('X-Accel-Buffering: no'); // 关闭加速缓冲
$this->setMeta("同步小说");
return $this->fetch();
}
/*****同步小说数据****/
public function newsync() {
$pageli = input('key')>0?input('key'):1;
$category = [
"玄幻奇幻"=>['id'=>23,'channel'=>1],
"武侠仙侠"=>['id'=>24,'channel'=>1],
"都市校园"=>['id'=>25,'channel'=>1],
"历史军事"=>['id'=>26,'channel'=>1],
"网游竞技"=>['id'=>27,'channel'=>1],
"科幻灵异"=>['id'=>28,'channel'=>1],
"总裁豪门"=>['id'=>29,'channel'=>2],
"古代言情"=>['id'=>30,'channel'=>2],
"青春校园"=>['id'=>31,'channel'=>2],
"女频灵异"=>['id'=>32,'channel'=>2],
];
$listurl = "http://www.youyuezw.com/api/cps/get_book_list.php";
$list = $this->curl_get($listurl);
header("Content-Encoding: none\r\n");
ob_start();//打开缓冲区
echo str_repeat(" ",1024*64);
echo "本次总共需要同步".count($list)."个,第".$pageli."个正在同步,请稍等...\r\n
";
if($pageli<=count($list)){
$v = $list[$pageli-1];
//获取小说详情URL
$infourl = "http://www.youyuezw.com/api/cps/get_book_info.php?bookid={0}";
$infourl = str_replace("{0}",$v["articleid"],$infourl);
//获取小说详情
$info= $this->curl_get($infourl);
//小说存在
$articleinfo = db('novel')->where('title','like','%'.$info["articlename"].'%')->value('id');
echo str_repeat(" ",1024*64);
echo "《".$info["articlename"]."》开始同步\r\n
";
ob_flush();
flush();
if($articleinfo){
$articleid =$articleinfo;
}else{//不存在
$data['create_time'] = strtotime($info['postdate']);
$data['update_time'] = strtotime($info['lastupdate']);
$data['title'] = $info['articlename'];
$data['keywords'] = $info['keywords'];
$data['author'] = $info['author'];
$data['intro'] = $info['intro'];
$data['fullflag'] = $info['fullflag'];
$data['articletype'] = 1;
if($info['sort']){
$data['channel'] = $category[$info['sort']]['channel'];
$data['category_id'] = $category[$info['sort']]['id'];
}else{
$data['channel'] = 0;
$data['category_id'] = 0;
}
$save_dir = "uploads/novelhumb/".date('Ymd')."/";
if($info["cover"]){
$data['cover'] = file_get_img($info["cover"],$save_dir,1);
}
$articleid = db("novel")->insertGetId($data);
}
//获取小说章节URL
$volumeurl = "http://www.youyuezw.com/api/cps/get_chapter_list.php?bookid={0}";
$volumeurl = str_replace("{0}",$v["articleid"],$volumeurl);
//获取小说详情
$volume= $this->curl_get($volumeurl);
if($volume){
$chapters = db('novel')->where('id',$articleid)->value('chapters');
$i = 1;
foreach($volume as $kk=>$vv){
//判断是否有最新需要同步的章节
if($vv['chapterorder'] >$chapters){
//更新章节
$chapter['articleid'] = $articleid;
$chapter['articlename'] = $info['articlename'];
$chapter['uid'] = session('user_auth.uid');
$chapter['chaptername'] = $vv["chaptername"];
$chapter['size'] = $vv["words"];
$chapter['isvip'] = $vv["isvip"];
$chapter['saleprice'] = $vv["saleprice"];
$chapter['create_time'] = strtotime($vv["postdate"])?strtotime($vv["postdate"]):time();
$chapter['update_time'] = strtotime($vv["lastupdate"])?strtotime($vv["lastupdate"]):time();
$chapter['chapterorder'] = $chapters+$i;
$chapterid = db("chapter")->insertGetId($chapter);
if($chapterid){
//更新最新信息至小说表
db("novel")->where('id',$articleid)->update(['lastvolume' => $vv["chaptername"],'lastvolumeid' => $chapterid,'chapters' =>['exp','chapters+1'],'size' =>['exp','size+'.$vv["words"]],'update_time'=>time()]);
}
//获取小说内容URL
$contenturl = "http://www.youyuezw.com/api/cps/get_chapter_content.php?bookid={0}&chapterid={1}";
$contenturl = str_replace(array("{0}","{1}"),array($v["articleid"],$vv["chapterid"]),$contenturl);
//获取小说内容
$content= $this->curl_get($contenturl);
$ocontent['chapterid'] = $chapterid;
$ocontent['content'] = "
".str_replace(array("\r\n", "\r", "\n"),'
',$content["content"])."
"; db("novel_content")->insert($ocontent); $i++; echo str_repeat(" ",1024*64); echo "《".$info["articlename"]."》--".$vv["chaptername"]."章节同步完成\r\n","
"),array("","\r\n\r\n\t"),$content); echo strip_tags($content); } } } /** * 设置置顶 * @author netlife <40150501@qq.com> */ public function settop() { $id=input('id'); $is_top = input('is_top'); /* $map['id'] = $id; $result = $this->model->where($map)->setField('is_top', $is_top); if (false !== $result) { return $this->success("操作成功!"); } else { return $this->error("操作失败!!"); } */ $map['id'] = $id; $top = $this->model->where($map)->value('is_top'); if($top){ $top = explode(',',$top); $top[] = $is_top; array_unique($top); $is_top = implode(",",$top); } $result = $this->model->where($map)->setField('is_top', $is_top); if (false !== $result) { return $this->success("操作成功!",url('novel/index')); } else { return $this->error("操作失败!!",url('novel/index')); } } /****取消推荐******/ public function unsettop() { $id=input('id'); $is_top = input('is_top'); $map['id'] = $id; $top = $this->model->where($map)->value('is_top'); if($top){ $top = explode(',',$top); foreach($top as $k=>$v){ if($v ==$is_top){ unset($top[$k]); } } $is_top = implode(",",$top); } $result = $this->model->where($map)->setField('is_top', $is_top); if (false !== $result) { return $this->success("操作成功!",url('novel/index')); } else { return $this->error("操作失败!!",url('novel/index')); } } /****设置VIP******/ public function setvip() { $id = input('id'); if (empty($id)) { return $this->error("非法操作!"); } if(IS_POST){ $post = input('post.'); $isvip = $post['type']=='vip'?1:0; if($isvip){ db('chapter')->where(['articleid'=>$post['articleid']])->update(['isvip' =>0]); } $chapter = db('chapter')->where(['articleid'=>$post['articleid'],'chapterorder'=>array('>',$post['chapterid'])])->order('chapterorder asc')->column('id,saleprice'); foreach($chapter as $k=>$v){ $saleprice = 50; if($isvip && $v==0){ db('chapter')->where('id='.$k)->update(['isvip' =>$isvip,'saleprice'=>$saleprice]); }else{ db('chapter')->where('id='.$k)->update(['isvip' =>$isvip]); } Cache::store('redis')->set('chapterinfo'.$k,''); } return $this->success("设置成功!", url('admin/novel/index', array('model_id' => $this->modelInfo['id']))); } $chapter = db('chapter')->where('articleid='.$id)->order('chapterorder asc')->column('id,chaptername,chapterorder,isvip'); $this->assign('id',$id); $this->setMeta("批量设置VIP"); $this->assign('chapter',$chapter); return $this->fetch(); } /*****字数统计******/ public function setsize() { $id = input('id'); if (empty($id)) { return $this->error("非法操作!"); } $chapter = db('chapter')->where(['articleid'=>$id,'status'=>1])->column('id'); $chaptersize = 0; foreach($chapter as $v){ $content = db('novel_content')->where('chapterid = '.$v)->value('content'); $content = $this->textstr($content); $size = round(strlen(preg_replace('/\\s/', '', strip_tags($content)))/3); db('chapter')->where('id='.$v)->cache('bookinfo'.$id)->update(['size' =>$size]); $chaptersize +=$size; } db('novel')->where(['id'=>$id])->update(['size' =>$chaptersize]); return $this->success("设置成功!", url('admin/novel/index', array('model_id' => $this->modelInfo['id']))); } /***设置价格*****/ public function setprice() { $getid = input(); if(is_array($getid['id'])){ $id = implode(',',$getid['id']); }else{ $id = $getid['id']; } if(IS_POST){ $post = input('post.'); if (is_numeric($post['articleid'])) { $chapter = db('chapter') ->where('articleid', $post['articleid']) ->where('chapterorder', '>=', $post['start']) ->where('chapterorder', '<=', $post['end']) ->order('chapterorder asc') ->column('id,chaptername'); } foreach($chapter as $k=>$v){ db('chapter')->where('id='.$k)->update(['saleprice' =>$post['price']]); Cache::store('redis')->set('chapterinfo'.$k,''); } echo json_encode(['res'=>'设置成功!']); die; } $chapter = db('chapter')->where('articleid='.$id)->where('isvip=1')->order('chapterorder asc,id asc')->column('id,chaptername,chapterorder,isvip,saleprice'); $this->assign('id',$id); $this->assign('chapter',$chapter); $this->setMeta("批量设置价格"); return $this->fetch(); } /****设置章节数******/ public function setchapters() { $novel = db('novel')->where('status=1')->column('id'); foreach ($novel as $k=>$v){ $chapters = db('chapter')->where(' articleid='.$v. ' and chaptertype=0')->count(); db('novel')->where('id',$v)->update(['chapters' => $chapters]); } } /** * 获取字段信息 * @return array 字段数组 * @author netlife <40150501@qq.com> */ protected function getField() { $field_group = parse_config_attr($this->modelInfo['attribute_group']); $map['model_id'] = $this->modelInfo['id']; if ($this->request->action() == 'add') { $map['is_show'] = array('in', array('1', '2')); } elseif ($this->request->action() == 'edit') { $map['is_show'] = array('in', array('1', '3')); } //获得数组的第一条数组 $rows = model('Attribute')->getFieldlist($map, 'id'); if (!empty($rows)) { foreach ($rows as $key => $value) { $list[$value['group_id']][] = $value; } foreach ($field_group as $key => $value) { $fields[$value] = isset($list[$key]) ? $list[$key] : array(); } }else{ $fields = array(); } return $fields; } /** * 创建搜索 * @return [array] [查询条件] */ protected function buildMap() { $map = array(); $data = $this->request->param(); foreach ($data as $key => $value) { if ($value) { if ($key == 'keyword') { $map['title'] = array("LIKE", "%$value%"); } elseif ($key == 'category') { $map['category_id'] = $value; } elseif ($key == 'create_time') { $map['create_time'] = array('BETWEEN', array(strtotime($value[0]), strtotime($value[1]))); } elseif ($key == 'fullflag') { $map['fullflag'] = $value==1?1:0; } elseif ($key == 'is_new' || $key == 'allvisit'||$key == 'is_free') { } else { $map[$key] = $value; } } } if (isset($map['page'])) { unset($map['page']); } if (isset($map['model_id'])) { unset($map['model_id']); } $this->assign($data); return $map; } protected function last_month_today($time){ $last_month_time = mktime(date("G", $time), date("i", $time), date("s", $time), date("n", $time), 0, date("Y", $time)); $last_month_t = date("t", $last_month_time); if ($last_month_t < date("j", $time)) { return date("Y-m-t H:i:s", $last_month_time); } return date(date("Y-m", $last_month_time) . "-d", $time); } /** * 检测需要动态判断的文档类目有关的权限 * * @return boolean|null * 返回true则表示当前访问有权限 * 返回false则表示当前访问无权限 * 返回null,则会进入checkRule根据节点授权判断权限 * * @author 朱亚杰',$string); $string ='
'.$string.'
'; return $string; } // 整本内容替换 public function repstr(){ $id = input('id'); $book = db('novel')->field('title,chapters')->where('id',$id)->find(); $this->assign('book',$book); $this->assign('id',$id); $this->setMeta("整本内容替换"); return $this->fetch(); } //开始替换 public function arepstr(){ $data = input('post.'); if($data){ $content_id = db('chapter')->field('id')->where('articleid',$data['id'])->select(); if(!$content_id){ return 2; exit; } $str = $data['str']; $repstr = $data['repstr']; foreach($content_id as $k=>$v){ $content = db('novel_content')->where('chapterid',$v['id'])->value('content'); $content = str_replace($str,$repstr,$content); db('novel_content')->where('chapterid',$v['id'])->update(['content'=>$content]); } return 1; } } // 整本的书的章节内容替换 public function replacebook(){ $data = input('post.'); if($data){ $title = db('novel')->where('id',$data['id'])->value('title'); $bookList = $this->readList($data['ebook'],2); $i=1; foreach($bookList as $k=>$v){ $contents = $this->format_content($v["content"]); $cid = db('chapter')->where([ 'articleid'=>$data['id'], 'chapterorder'=>$i ])->value('id'); if($cid){ db('chapter')->where('id',$cid)->update(['chaptername'=>$v['name']]); db('novel_content')->where('chapterid',$cid)->update(['content'=>$contents]); Cache::store('redis')->set('chaptercontent'.$cid, $contents,3600); }else{ //拆分后新增章节 $chapterdata['articleid'] = $data['id']; $chapterdata['chaptername'] = $v["name"]; $chapterdata['create_time'] = time(); $chapterdata['update_time'] = time(); $chapterdata['size'] = get_count_content($v['content']); $chapterdata['saleprice'] = round($chapterdata['size']/1000*config('wordsperegold')); if($i>20){ $chapterdata['isvip'] = 1; $chapterdata['saleprice'] = round($chapterdata['size']/1000*config('wordsperegold')); } $chapterdata['chapterorder'] = $i; $chapterdata['articlename'] = $title; db('chapter')->insert($chapterdata); $chapterId = db('chapter')->getLastInsID(); //新增章节内容 $ocontent['chapterid'] = $chapterId; $ocontent['content'] = $contents; db("novel_content")->insert($ocontent); Cache::store('redis')->set('chaptercontent'.$chapterId, $contents,3600); } $i++; } return 1; } } // 查找字符串 public function saestr(){ $data = input('post.'); if($data){ $content_id = db('chapter')->field('id')->where('articleid',$data['id'])->select(); if(!$content_id){ exit(json_encode(array('status'=>2,'msg'=>'没有文章'))); } $str = $data['str']; $strmun = 0; foreach($content_id as $k=>$v){ $content = db('novel_content')->where('chapterid',$v['id'])->value('content'); $strmun += substr_count($content,$str); } if($strmun==0){ exit(json_encode(array('status'=>1,'msg'=>'该词未发现'))); }else{ exit(json_encode(array('status'=>1,'msg'=>'该词整部书出现:'.$strmun.'次'))); } } } // 获取第3方书籍 public function getbooks(){ import("Getbooks.Getbooks", EXTEND_PATH,'.php'); $obj = new \Getbooks(); $list = $obj->GetAll(); foreach($list as $k=>$v){ $list[$k]['lastupdate'] = substr($v['lastupdate'],0,4).'-'.substr($v['lastupdate'],4,2).'-'.substr($v['lastupdate'],6,2).' '.substr($v['lastupdate'],8,2).':'.substr($v['lastupdate'],10,2); } $this->assign('list',$list); $this->setMeta("书籍列表"); return $this->fetch(); } // 获取第三方书籍详情 public function getbookinfo(){ $id = input('id'); if($id){ import("Getbooks.Getbooks", EXTEND_PATH,'.php'); $obj = new \Getbooks(); $data = $obj->GetBookAttr($id); } $this->assign('data',$data); $this->setMeta("添加到书库"); return $this->fetch(); } // 添加第三方书籍 到书库 public function addthirdbook(){ $data = input(''); if($data){ //小说存在 $articleinfo = db('novel')->where('title',$data['title'])->value('id'); if($articleinfo){ exit(json_encode(array('status'=>2,'msg'=>'小说存在'))); }else{ $id = $data['articleid']; //第三方书ID unset($data['articleid']); $data['create_time'] = time(); $data['update_time'] = time(); // 添加小说 $resbook = db('novel')->insert($data); // 添加章节 if($resbook){ $articleid = db('novel')->getLastInsID(); //书库书ID import("Getbooks.Getbooks", EXTEND_PATH,'.php'); $obj = new \Getbooks(); $chapterlist = $obj->GetChapterList($id); //根据书ID获取第三方书章节 $i = 0; $size = 0; foreach($chapterlist as $k=>$v){ $chapterdata['articleid'] = $articleid; $chapterdata['uid'] = session("user_auth.uid"); $chapterdata['chaptername'] = $v['chaptername']; $chapterdata['create_time'] = time(); $chapterdata['update_time'] = time(); // 获取第三方的章节内容 $chapter_content = $obj->GetChapterContent($id,$v['chapterid']); $chapterdata['size'] = get_count_content($chapter_content['content']); $chapterdata['saleprice'] = round($chapterdata['size']/1000*config('wordsperegold')); if($i>20){ $chapterdata['isvip'] = 1; $chapterdata['saleprice'] = round($chapterdata['size']/1000*config('wordsperegold')); } $chapterdata['chapterorder'] = $v['chapterorder']; db('chapter')->insert($chapterdata); $chapterId = db('chapter')->getLastInsID(); //更新小说章节内容 $ocontent['chapterid'] = $chapterId; $ocontent['content'] = $this->format_content($chapter_content['content']); db("novel_content")->insert($ocontent); //更新小说章节最新信息 db('novel')->where(array('id'=>$articleid))->update(array('lastvolumeid'=>$chapterId,'lastvolume'=>$v["chaptername"])); $size += $chapterdata['size']; $i++; } //更新小说总字数 db('novel')->where(array('id'=>$articleid))->update(array('size'=>array('exp', '`size`+'.$size))); } exit(json_encode(array('status'=>1,'msg'=>'上传该书籍到书库成功'))); } } } }