model_id = $model_id = $this->request->param('model_id'); $this->model_id = $model_id = 16; $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']))); } $grid_list = get_grid_list($this->modelInfo['list_grid']); $allvisit = input('allvisit'); if($allvisit =='asc'){ $order = "allvisit asc"; }else{ $order = "allvisit desc"; } // 关键字搜索 $search_key =$this->modelInfo['search_key']?$this->modelInfo['search_key']:'title'; $map = $this->buildMap($search_key); $field = array_filter($grid_list['fields']); if( session('user_auth.group') != 999){ $map['status'] = 1; } $list = $this->model->where($map)->order($order)->paginate($this->modelInfo['list_row']); //获取授权用户组 $access = config('cartoon_access'); //获取当前用户组 $group = session('user_auth.group'); $data = array( 'grid' => $grid_list, 'list' => $list, 'page' => $list->render(), 'group' => $group, 'access' => $access, 'allvisit' => $allvisit ); if ($this->modelInfo['template_list']) { $template = 'content/' . $this->modelInfo['template_list']; } else { $template = 'content/index'; } $this->assign($data); $this->setMeta($this->modelInfo['title'] . "列表"); return $this->fetch($template); } /** * 内容添加 * @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/cartoon/index', array('model_id' => $this->modelInfo['id']))); } else { return $this->error($this->model->getError(), url('admin/cartoon/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 = 'cartoon/edit'; } $this->assign($data); $this->setMeta("添加" . $this->modelInfo['title']); return $this->fetch($template); } } /** * uploadbook [上传漫画] * * @return type **/ public function uploadcartoon() { if (IS_POST) { $ebook = input('post.ebook'); $ebook = str_replace("./uploads","/uploads",$ebook); $this->param['create_time'] = time(); $this->param['update_time'] = time(); $result = $this->model->save($this->param); if ($result) { $cartoonid = $this->model->getLastInsID(); //增加章节 $target_dir = dirname(APP_PATH)."/uploads/test"; $upfilePath = dirname(APP_PATH)."/uploads/zip"; $file_dir = dirname(APP_PATH); $newfilePath = "/uploads/picture/"; $array_imgs = zipfolder($target_dir,$upfilePath,$newfilePath,$file_dir,$ebook); foreach($array_imgs as $k=>$v){ $param = $fileid = array(); foreach($v as $vo){ $fileid[]= $this->parseFile($vo); } $param['create_time'] = time(); $param['update_time'] = time(); $param['volumename'] = $k; $param['imgsrc'] = implode(",",$fileid); $param['cartoonid'] = $cartoonid; $param['cartoonname'] =$this->param['name']; //发表者UID $param['uid'] = session("user_auth.uid"); //章节序号 $chapterorder = db('volume')->where(array('cartoonid'=>$cartoonid))->count(); $param['volumeorder'] = $chapterorder+1; if($chapterorder >$this->param['setvip']){ $param['isvip'] = 1; $param['saleprice'] = $this->param['saleprice']; } $volumeId = db('volume')->insertGetId($param); $volumeId = db('volume')->getLastInsID(); //更新漫画章节最新信息 db('cartoon')->where(array('id'=>$cartoonid))->update(array('volumes'=>$chapterorder,'lastvolumeid'=>$volumeId,'lastvolume'=>$k)); } //记录行为 action_log('upload_cartoon', 'cartoon', $result, session('user_auth.uid')); return $this->success("添加成功!", url('admin/cartoon/index', array('model_id' => $this->modelInfo['id']))); } else { return $this->error($this->model->getError(), url('admin/cartoon/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(); } } /** * 内容修改 * @author netlife <40150501@qq.com> */ public function edit($id) { if (IS_POST) { $result = $this->model->save($this->param, array('id'=> $id)); if ($result !== false) { //记录行为 action_log('update_content', 'content', $result, session('user_auth.uid')); return $this->success("更新成功!", url('admin/cartoon/index', array('model_id' => $this->modelInfo['id']))); } else { return $this->error($this->model->getError(), url('admin/cartoon/edit', array('model_id' => $this->modelInfo['id'], 'id' => $id))); } } else { if (!$id) { return $this->error("非法操作!"); } $info = $this->model->find($id); if (!$info) { return $this->error($this->model->getError()); } $info['model_id'] = $this->modelInfo['id']; $data = array( 'info' => $info, 'fieldGroup' => $this->getField($this->modelInfo), ); if ($this->modelInfo['template_edit']) { $template = 'content/' . $this->modelInfo['template_edit']; } else { $template = 'cartoon/edit'; } $this->assign($data); $this->setMeta("编辑" . $this->modelInfo['title']); return $this->fetch($template); } } /** * 内容删除 * @author netlife <40150501@qq.com> */ public function del() { $id = $this->getArrayParam('id'); if (empty($id)) { return $this->error("非法操作!"); } $map['id'] = array('IN', $id); //删除对应的章节 db('volume')->where(array('cartoonid'=>array('IN', $id)))->delete(); $result = $this->model->where($map)->delete(); if (false !== $result) { //记录行为 action_log('delete_content', 'content', $result, session('user_auth.uid')); return $this->success("删除成功!"); } else { return $this->error("删除失败!"); } } /** * 设置状态 * @author netlife <40150501@qq.com> */ public function status($id, $status) { $map['id'] = $id; $result = $this->model->where($map)->setField('status', $status); if (false !== $result) { return $this->success("操作成功!"); } else { return $this->error("操作失败!!"); } } /** * 设置置顶 * @author netlife <40150501@qq.com> */ public function settop($id, $is_top) { /** if(IS_POST){ $top = $_POST['is_top']; $map['id'] = $_POST['cartoonid']; if (!isset($top)){ return $this->error("操作失败!!",url('admin/cartoon/index', array('model_id' => $this->modelInfo['id']))); } $is_top= implode(',',$top); $result = $this->model->where($map)->setField('is_top', $is_top); if (false !== $result) { return $this->success("操作成功!",url('admin/cartoon/index', array('model_id' => $this->modelInfo['id']))); } else { return $this->error("操作失败!!",url('admin/cartoon/index', array('model_id' => $this->modelInfo['id']))); } } $map['id'] = $id; $this->setMeta("设置推荐"); $info = $this->model->where($map)->find(); $this->assign('info',$info);; $templete = 'cartoon/settop'; return $this->fetch($templete); **/ $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("操作成功!"); } else { return $this->error("操作失败!!"); } } /****取消推荐******/ public function unsettop($id, $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("操作成功!"); } else { return $this->error("操作失败!!"); } } /** * 获取字段信息 * @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($search_key) { $map = array(); $data = $this->request->param(); foreach ($data as $key => $value) { if ($value) { if ($key == 'keyword') { $map[$search_key] = 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 == 'allvisit') { } 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; } /** * 检测需要动态判断的文档类目有关的权限 * * @return boolean|null * 返回true则表示当前访问有权限 * 返回false则表示当前访问无权限 * 返回null,则会进入checkRule根据节点授权判断权限 * * @author 朱亚杰 */ protected function checkDynamic() { $model_id = $this->request->param('model_id'); if (IS_ROOT) { return true; //管理员允许访问任何页面 } $models = model('AuthGroup')->getAuthModels(session('user_auth.uid')); if (!$model_id) { return false; } elseif (in_array($model_id, $models)) { //返回null继续判断操作权限 return null; } else { return false; //无权限 } return false; } protected function parseFile($info) { $data['create_time'] = time(); //最后访问时间 $data['url'] = $data['path'] = $info; //全路径 $data['md5'] = md5($info); $data['sha1'] = sha1($info); $data['status'] = 1; $id = db('picture')->insertGetId($data); if ($id) { return $id; } else { return false; } } 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 =[ 1=>['type'=>21,'pindao'=>1], 2=>['type'=>13,'pindao'=>2], 3=>['type'=>16,'pindao'=>2], 4=>['type'=>19,'pindao'=>1], 5=>['type'=>11,'pindao'=>1], 6=>['type'=>19,'pindao'=>1], 7=>['type'=>19,'pindao'=>1], 8=>['type'=>21,'pindao'=>1], 9=>['type'=>17,'pindao'=>2], ]; $listurl = "http://m.danwanyd.com/api/cartoon/list.php"; $list = $this->curl_get($listurl); header("Content-Encoding: none\r\n"); ob_start();//打开缓冲区 echo str_repeat(" ",1024*64); echo "本次总共需要同步".count($list)."个,第".($pageli-1)."个正在同步,请稍等...\r\n
"; //foreach($list as $k=>$v){ if($pageli<=count($list)){ $v = $list[$pageli-1]; //获取漫画详情URL $infourl = "http://m.danwanyd.com/api/cartoon/info.php?id={0}"; $infourl = str_replace("{0}",$v["id"],$infourl); //获取漫画详情 $info= $this->curl_get($infourl); //漫画是否存在 $cartooninfo = db('cartoon')->where('name','like','%'.$info["name"].'%')->value('id'); echo str_repeat(" ",1024*64); echo "《".$info["name"]."》开始同步\r\n
"; ob_flush(); flush(); if($cartooninfo){ $cartoonid =$cartooninfo; }else{//不存在 $data['name'] = $info["name"]; $data['category_id'] = $category[$info["category"]]['type']; $data['update_time'] = $data['create_time'] = time(); $data['keywords'] = $info["keywords"]; $data['intro'] = $info["intro"]; $data['author'] = $info["author"]; $save_dir = "uploads/cartoonthumb/".date('Ymd')."/"; if($info["s_cover"]){ $data['cartoonspic'] = file_get_img($info["s_cover"],$save_dir); } if($info["l_cover"]){ $data['cartoonlpic'] = file_get_img($info["l_cover"],$save_dir); } if($info["f_cover"]){ $data['cartoonfpic'] = file_get_img($info["f_cover"],$save_dir); } $data['channel'] = $category[$info["category"]]['pindao']; $data['fullflag'] = $info["fullflag"]; $cartoonid = db("cartoon")->insertGetId($data); } //获取漫画章节URL $volumeurl = "http://m.danwanyd.com/api/cartoon/chapter.php?id={0}"; $volumeurl = str_replace("{0}",$v["id"],$volumeurl); //获取漫画详情 $volume= $this->curl_get($volumeurl); $i = 1; $dir = "uploads/picture/".date('Ymd')."/"; if($volume){ foreach($volume as $kk=>$vv){ $volumes = db('cartoon')->where('id',$cartoonid)->value('volumes'); //判断是否有最新需要同步的章节 if($vv['volumeorder'] >$volumes){ $volumedata = []; $imgsrc = null; if($vv["imgsrc"]){ foreach($vv["imgsrc"] as $vo){ $imgsrc .= file_get_img("http://m.danwanyd.com/".$vo,$dir).","; } }else{ echo str_repeat(" ",1024*64); echo "《".$vv["name"]."》图片为空\r\n
"; ob_flush(); flush(); } if($imgsrc == null ) break(1); //更新章节 $volumedata['cartoonid'] = $cartoonid; $volumedata['cartoonname'] = $info["name"]; $volumedata['volumename'] = $vv["name"]; $volumedata['volumeorder'] = $volumes+1; $volumedata['isvip'] = $vv["isvip"]; $volumedata['saleprice'] = $vv["saleprice"]; $volumedata['imgsrc'] = rtrim($imgsrc, ","); $volumeid = db("volume")->insertGetId($volumedata); if($volumeid){ //更新最新信息至漫画表 db("cartoon")->where('id',$cartoonid)->update(['lastvolume' => $vv["name"],'lastvolumeid' => $volumeid,'volumes' =>['exp','volumes+1'],'update_time'=>time()]); } echo str_repeat(" ",1024*64); echo "《".$info["name"]."》--".$vv["name"]."章节同步完成\r\n
"; ob_flush(); flush(); } } } $pageli++; echo str_repeat(" ",1024*64); echo "《".$info["name"]."》同步完成\r\n
"; ob_flush(); flush(); $jumpUrl = url('cartoon/newsync',array('key'=>$pageli)); echo ""; }else{ echo str_repeat(" ",1024*64); echo "所有内容同步完成\r\n
"; ob_flush(); flush(); } ob_end_flush();//输出并关闭缓冲 die; } }