720 lines
22 KiB
PHP
720 lines
22 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | 小说系统---文案管理 [ WE CAN DO IT JUST THINK IT ]
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\admin\controller;
|
||
use app\common\controller\Admin;
|
||
|
||
class Articles extends Admin {
|
||
|
||
public function _initialize() {
|
||
parent::_initialize();
|
||
//$this->getContentMenu();
|
||
//$this->model_id = $model_id = 7;
|
||
$this->model_id = $model_id = $this->request->param('model_id');
|
||
$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']);
|
||
|
||
// 关键字搜索
|
||
$search_key =$this->modelInfo['search_key']?$this->modelInfo['search_key']:'title';
|
||
|
||
$order = "id desc";
|
||
$map = $this->buildMap($search_key);
|
||
$field = array_filter($grid_list['fields']);
|
||
|
||
$list = $this->model->where($map)->order($order)->paginate($this->modelInfo['list_row']);
|
||
|
||
$data = array(
|
||
'model_id' => $this->modelInfo['id'],
|
||
'grid' => $grid_list,
|
||
'list' => $list,
|
||
'page' => $list->render(),
|
||
);
|
||
|
||
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) {
|
||
$result = $this->model->save($this->param);
|
||
if ($result) {
|
||
//记录行为
|
||
action_log('add_content', 'content', $result, session('auth_user.uid'));
|
||
return $this->success("添加成功!", url('admin/articles/index', array('model_id' => $this->modelInfo['id'])));
|
||
} else {
|
||
return $this->error($this->model->getError(), url('admin/articles/add', array('model_id' => $this->modelInfo['id'])));
|
||
}
|
||
} else {
|
||
print_r($this->modelInfo);
|
||
$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 = 'articles/edit';
|
||
}
|
||
$this->assign($data);
|
||
$this->setMeta("添加" . $this->modelInfo['title']);
|
||
return $this->fetch($template);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 内容修改
|
||
* @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('auth_user.uid'));
|
||
return $this->success("更新成功!", url('admin/articles/index', array('model_id' => $this->modelInfo['id'])));
|
||
} else {
|
||
return $this->error($this->model->getError(), url('admin/articles/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 = 'articles/edit';
|
||
}
|
||
$this->assign($data);
|
||
$this->setMeta("编辑" . $this->modelInfo['title']);
|
||
return $this->fetch($template);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 内容修改
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
public function editor() {
|
||
$cartoonid = input('cartoonid');
|
||
$volumeid = input('volumeid');
|
||
$referral_link_id = input('referral_link_id');
|
||
$model = input('model');
|
||
$mode = input('mode');
|
||
if($referral_link_id){
|
||
$tinfo = db('tuiguang') ->where('id='.$referral_link_id)->find();
|
||
$this->assign('title_id',$tinfo['article_title_id']);
|
||
$this->assign('cover_id',$tinfo['article_cover_id']);
|
||
$this->assign('body_template_id',$tinfo['article_body_template_id']);
|
||
$this->assign('footer_template_id',$tinfo['article_footer_template_id']);
|
||
$this->assign('referral_shortlink',get_agent($referral_link_id,session('user_auth.uid')));
|
||
|
||
$this->assign('referral_link',get_agent($referral_link_id,session('user_auth.uid'),0,false));
|
||
}
|
||
if($model==1){
|
||
$cinfo = db('novel')->where('id='.$cartoonid)->field('title as name,category_id,intro')->find();
|
||
$next_volumeid = db('chapter')->where(array('articleid'=>$cartoonid,'id'=>array('>',$volumeid)))->limit(1)->value('id');
|
||
|
||
if(!empty($cinfo['intro'])&&$mode=='img'){
|
||
$image = config('web_site_url').$this->CreateImage($cartoonid,0,'bookinfo');
|
||
$cinfo['intro'] = '<img src="'.$image.'" />';
|
||
}
|
||
}else{
|
||
$cinfo = db('cartoon')->where('id='.$cartoonid)->field('name,category_id,intro')->find();
|
||
$next_volumeid = db('volume')->where(array('cartoonid'=>$cartoonid,'id'=>array('>',$volumeid)))->limit(1)->value('id');
|
||
}
|
||
|
||
$template = 'articles/editor';
|
||
$this->setMeta("编辑" . $this->modelInfo['title']);
|
||
$this->assign('cartoonid',$cartoonid);
|
||
$this->assign('volumeid',$volumeid);
|
||
$this->assign('next_volumeid',$next_volumeid);
|
||
$this->assign('referral_link_id',$referral_link_id);
|
||
$this->assign('category',$cinfo['category_id']);
|
||
$this->assign('model',$model);
|
||
$this->assign('mode',$mode);
|
||
$this->assign('intro',$cinfo["intro"]);
|
||
$this->assign('cartoonname',$cinfo["name"]);
|
||
return $this->fetch($template);
|
||
}
|
||
/*******获取文案封面*********/
|
||
public function api_get_covers(){
|
||
|
||
$cid = input('cid');
|
||
$model = input('model');
|
||
if($model==2){
|
||
$list = db('ArticlesCovers')->where(array('status'=>1,'category'=>$cid))->select();
|
||
}else{
|
||
$list = db('ArticlesCovers')->where(array('status'=>1))->select();
|
||
}
|
||
|
||
$web_site_url = config('web_site_url');
|
||
$data = array();
|
||
foreach($list as $v){
|
||
$v["cover_url"] =$web_site_url.get_cover($v["cover_url"],'path');
|
||
$data[] = $v;
|
||
}
|
||
header('Content-type: text/json');
|
||
echo json_encode($data);
|
||
|
||
exit();
|
||
|
||
}
|
||
/*******获取文案标题*********/
|
||
public function api_get_titles(){
|
||
$cid = input('cid');
|
||
$model = input('model');
|
||
$list = db('ArticlesTitles')->where(array('status'=>1,'model'=>$model))->select();
|
||
header('Content-type: text/json');
|
||
echo json_encode($list);
|
||
exit();
|
||
|
||
}
|
||
/*******获取原文引导模板*********/
|
||
public function api_get_footer_templates(){
|
||
$web_site_url = config('web_site_url');
|
||
$list = db('ArticlesFooter')->where(array('status'=>1))->select();
|
||
header('Content-type: text/json');
|
||
foreach($list as $v){
|
||
$v["preview_img"] =$web_site_url.get_cover($v["preview_img"],'path');
|
||
$data[] = $v;
|
||
}
|
||
echo json_encode($data);
|
||
exit();
|
||
}
|
||
/*******获取正文模板*********/
|
||
public function api_get_body_templates(){
|
||
$web_site_url = config('web_site_url');
|
||
$list = db('ArticlesBody')->where(array('status'=>1))->select();
|
||
foreach($list as $v){
|
||
$v["preview_img"] =$web_site_url.get_cover($v["preview_img"],'path');
|
||
$data[] = $v;
|
||
}
|
||
header('Content-type: text/json');
|
||
echo json_encode($data);
|
||
exit();
|
||
}
|
||
/*******获取书籍详情*********/
|
||
public function api_get_preview_articles() {
|
||
$model = input('model');
|
||
$mode = input('mode');
|
||
$id = input('current_article_id');
|
||
$cartoonid = input('cartoonid');
|
||
if($model==2){
|
||
$list = db('volume')->where('cartoonid='.$cartoonid.' and id <='.$id.' and status =1')->field('id,volumename,imgsrc')->order('volumeorder ASC')->select();
|
||
foreach($list as $v){
|
||
$content = [];
|
||
$imgsrc = explode(',',$v['imgsrc']);
|
||
if(is_array($imgsrc)){
|
||
foreach($imgsrc as $vv){
|
||
$content[]= '"'.get_cover($vv,'path').'"';
|
||
}
|
||
}else{
|
||
$content[]= '"'.get_cover($v['imgsrc'],'path').'"';
|
||
}
|
||
|
||
$content = implode(',',$content);
|
||
$data[] = array(
|
||
"id"=>$v['id'],
|
||
"title"=>$v['volumename'],
|
||
"idx"=>"1",
|
||
"image_cdn"=>config('web_site_url'),
|
||
"content"=>"[".$content."]",
|
||
"mode"=>0,
|
||
"paragraphs"=>[]
|
||
|
||
);
|
||
}
|
||
}else{
|
||
$list = db('chapter')->where('articleid='.$cartoonid.' and id <='.$id.' and status =1')->field('id,chaptername')->order('chapterorder ASC')->select();
|
||
if($list){
|
||
if($mode=='text'){
|
||
foreach ($list as $k=>$v){
|
||
$content= '"'.db('novel_content')->where("chapterid=".$v['id'])->value('content').'"';
|
||
|
||
$data[] = array(
|
||
"id"=>$v['id'],
|
||
"title"=>$v['chaptername'],
|
||
"idx"=>"1",
|
||
"image_cdn"=>config('web_site_url'),
|
||
"content"=>"[".str_replace("<p>","<p style='padding:0 10px;font-size:18px;text-indent:2em;line-height:30px'>",$content)."]",
|
||
//"content"=>"[".$content."]",
|
||
"mode"=>0,
|
||
"paragraphs"=>[]
|
||
|
||
);
|
||
}
|
||
}else{
|
||
foreach ($list as $k=>$v){
|
||
/**
|
||
$content= '"'.db('novel_content')->where("chapterid=".$v['id'])->value('content').'"';
|
||
$content = str_replace(array('<p></p>','<p>','</p>'),array('','','\n'),$content);
|
||
$images = $this->CreateImage($cartoonid,$v['id']);
|
||
$data[] = array(
|
||
"id"=>$v['id'],
|
||
"title"=>config('web_site_url')."/images/images?id=".$v['id'],
|
||
"idx"=>"1",
|
||
"image_cdn"=>config('web_site_url'),
|
||
"content"=>"[\"/images/textimage?id=".$cartoonid."&chaptrtid=".$v['id']."\"]",
|
||
"mode"=>1,
|
||
"paragraphs"=>[]
|
||
|
||
);
|
||
|
||
$images= db('novel_content')->where("chapterid=".$v['id'])->value('images');
|
||
if($images){
|
||
$images = json_decode($images,true);
|
||
}else{
|
||
$images = $this->CreateImage($cartoonid,$v['id']);
|
||
}
|
||
**/
|
||
$images = $this->CreateImage($cartoonid,$v['id']);
|
||
|
||
$data[] = array(
|
||
"id"=>$v['id'],
|
||
"title"=>config('web_site_url').$this->CreateImage($cartoonid,$v['id'],'chaptertitle'),
|
||
//"title"=>$v['chaptername'],
|
||
"idx"=>"1",
|
||
"image_cdn"=>config('web_site_url'),
|
||
//"content"=>$images,
|
||
"content"=>array($images),
|
||
"mode"=>1,
|
||
"paragraphs"=>[]
|
||
|
||
);
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
header('Content-type: text/json');
|
||
echo json_encode($data);
|
||
exit();
|
||
}
|
||
|
||
/*******生成原文链接时 获取漫画信息*********/
|
||
public function api_get_short_article_info() {
|
||
$id = input('current_article_id');
|
||
$model = input('model');
|
||
if($model==2){
|
||
$info = db('volume')->where(' id ='.$id.' and status =1')->find();
|
||
$data = array(
|
||
"id"=>$id,
|
||
"title"=>$info['volumename'],
|
||
"novel"=>array(
|
||
"id"=>$info['cartoonid'],
|
||
"title"=>$info['cartoonname'],
|
||
"avatar"=>get_cartoon_img($info['cartoonid']),
|
||
)
|
||
);
|
||
}else{
|
||
$info = db('chapter')->where(' id ='.$id.' and status =1')->find();
|
||
$data = array(
|
||
"id"=>$id,
|
||
"title"=>$info['chaptername'],
|
||
"novel"=>array(
|
||
"id"=>$info['articleid'],
|
||
"title"=>$info['articlename'],
|
||
"avatar"=>get_novel_img($info['articleid']),
|
||
)
|
||
);
|
||
}
|
||
|
||
header('Content-type: text/json');
|
||
echo json_encode($data);
|
||
exit();
|
||
}
|
||
/***修改时获取推广信息****/
|
||
public function api_get() {
|
||
$id = input('id');
|
||
$info = db('tuiguang')->where('id='.$id)->find();
|
||
$type = $info['type'] == 1?"verified_mp":"not_verified_mp";
|
||
$data = array(
|
||
"id"=>$info['id'],
|
||
"type"=>"0",
|
||
"description"=>$info['title'],
|
||
"user_id"=>$info['uid'],
|
||
"novel_id"=>$info['articleid'],
|
||
"article_id"=>$info['chapterid'],
|
||
"force_follow_chapter_idx"=>$info['followchapter'],
|
||
"referrer_type"=>$type,
|
||
"wx_article_title_id"=>$info['article_title_id'],
|
||
"wx_article_cover_id"=>$info['article_cover_id'],
|
||
"wx_article_body_template_id"=>$info['article_body_template_id'],
|
||
"wx_article_footer_template_id"=>$info['article_footer_template_id'],
|
||
"created_at"=>"1511769146",
|
||
"is_deleted"=>"0",
|
||
"deleted_at"=>null,
|
||
"is_hidden"=>"0",
|
||
"is_blocked"=>"0"
|
||
);
|
||
header('Content-type: text/json');
|
||
echo json_encode($data);
|
||
exit();
|
||
}
|
||
public function api_get_basic_info_by_idx(){
|
||
|
||
}
|
||
/**保存推广文案*/
|
||
public function api_save() {
|
||
$post_data = file_get_contents('php://input', 'r');
|
||
|
||
$post_data = json_decode($post_data,true);
|
||
|
||
if($post_data['modelid']==2){
|
||
$info = db('volume')->where(' id ='.$post_data['chapterid'].' and status =1')->find();
|
||
$focuschapter = db('cartoon')->where(' id ='.$info['cartoonid'])->value('focuschapter');
|
||
$post_data["modelid"]= $post_data['modelid'];
|
||
$post_data["articleid"]= $info['cartoonid'];
|
||
}else{
|
||
$info = db('chapter')->where(' id ='.$post_data['chapterid'].' and status =1')->find();
|
||
$focuschapter = db('novel')->where(' id ='.$info['articleid'])->value('focuschapter');
|
||
$post_data["modelid"]= $post_data['modelid'];
|
||
$post_data["articleid"]= $info['articleid'];
|
||
}
|
||
if(array_key_exists("showstarttime",$post_data)){
|
||
$post_data["showstarttime"]= strtotime($post_data["showstarttime"]);
|
||
}
|
||
|
||
if(array_key_exists("showendtime",$post_data)){
|
||
$post_data["showendtime"]= strtotime($post_data["showendtime"]);
|
||
}
|
||
$post_data["create_time"]= time();
|
||
$post_data["update_time"]= time();
|
||
//派单渠道类型
|
||
if($post_data["type"] =="verified_mp"){
|
||
$post_data["urltype"]= 1;
|
||
}else{
|
||
$post_data["urltype"]= 2;
|
||
}
|
||
//关注章节序号
|
||
if(empty($post_data["followchapter"])){
|
||
$post_data["followchapter"] = $focuschapter?$focuschapter:config('agent_guanzhu');
|
||
}
|
||
|
||
if($post_data['id']){
|
||
$result= db('tuiguang')->update($post_data);
|
||
if($result){
|
||
header('Content-type: text/json');
|
||
echo json_encode(array('id'=>$post_data['id'],'url'=>get_agent($post_data['id'],session('user_auth.uid'),0,false),'shorturl'=>get_agent($post_data['id'],session('user_auth.uid'))));
|
||
exit();
|
||
}
|
||
}else{
|
||
$post_data["uid"]= session('user_auth.uid');
|
||
$post_data["wxmpid"]= session('wxmpid');
|
||
$result= db('tuiguang')->insertGetId($post_data);
|
||
if($result){
|
||
$shorturl = getSinaShortUrl(get_agent($result,session('user_auth.uid'),0,false));
|
||
db('tuiguang')->where("id=".$result)->setField('shorturl',$shorturl);
|
||
|
||
header('Content-type: text/json');
|
||
echo json_encode(array('id'=>$result,'url'=>get_agent($result,session('user_auth.uid'),0,false),'shorturl'=>get_agent($result,session('user_auth.uid'))));
|
||
exit();
|
||
}
|
||
}
|
||
|
||
exit();
|
||
}
|
||
/**
|
||
* 内容删除
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
public function del() {
|
||
$id = $this->getArrayParam('id');
|
||
if (empty($id)) {
|
||
return $this->error("非法操作!");
|
||
}
|
||
|
||
$map['id'] = array('IN', $id);
|
||
$result = $this->model->where($map)->delete();
|
||
|
||
if (false !== $result) {
|
||
//记录行为
|
||
action_log('delete_content', 'content', $result, session('auth_user.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) {
|
||
$map['id'] = $id;
|
||
$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])));
|
||
} 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 朱亚杰 <xcoolcc@gmail.com>
|
||
*/
|
||
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 CreateImage($id,$chaptrtid,$type=null) {
|
||
|
||
if($type=="bookinfo"){
|
||
$imageUrl=config('web_site_url')."/images/infoimages?id=".$id;
|
||
|
||
if(file_exists(ROOT_PATH."/uploads/obookwimage/".$id."/") === false)
|
||
{
|
||
checkdir(ROOT_PATH."/uploads/obookwimage/".$id."/", 1 );
|
||
}
|
||
$filename = "/uploads/obookwimage/".$id."/book.png";
|
||
if(file_exists(ROOT_PATH.$filename)=== false){
|
||
$source = imagecreatefrompng($imageUrl);
|
||
imagepng($source,ROOT_PATH.$filename);
|
||
}
|
||
return $filename;
|
||
}elseif($type=="chaptertitle"){
|
||
$imageUrl=config('web_site_url')."/images/images?id=".$chaptrtid;
|
||
if(file_exists(ROOT_PATH."/uploads/obookwimage/".$id."/".$chaptrtid."/") === false)
|
||
{
|
||
checkdir(ROOT_PATH."/uploads/obookwimage/".$id."/".$chaptrtid."/", 1 );
|
||
}
|
||
$filename = "/uploads/obookwimage/".$id."/".$chaptrtid."/title.png";
|
||
if(file_exists(ROOT_PATH.$filename)=== false){
|
||
$source = imagecreatefrompng($imageUrl);
|
||
imagepng($source,ROOT_PATH.$filename);
|
||
}
|
||
return $filename;
|
||
}else{
|
||
/**
|
||
$image = array();
|
||
$imageUrl=config('web_site_url')."/images/textimage?id=".$id."&chaptrtid=".$chaptrtid;
|
||
|
||
list($width, $height) = getimagesize($imageUrl);
|
||
$newwidth = $width;
|
||
$p = ceil($height/900);
|
||
$newheight = floor($height / $p);
|
||
$last = $height % $p;
|
||
//创建一新图像
|
||
$source = imagecreatefromjpeg($imageUrl);
|
||
for( $i=0 ; $i< $p; $i++ ){
|
||
|
||
$_p = $newheight*$i;
|
||
if( ( $i + 1 ) == $p )
|
||
$newheight += $last;
|
||
$thumb = ImageCreateTrueColor($newwidth, $newheight);
|
||
imagecopyresized( $thumb, $source, 0, 0, 0, $_p, $newwidth, $height, $width, $height);
|
||
if(file_exists(ROOT_PATH."/uploads/obookwimage/".$id."/".$chaptrtid."/") === false)
|
||
{
|
||
checkdir(ROOT_PATH."/uploads/obookwimage/".$id."/".$chaptrtid."/", 1 );
|
||
}
|
||
if(file_exists(ROOT_PATH."/uploads/obookwimage/".$id."/".$chaptrtid."/{$i}.jpg")=== false){
|
||
imagejpeg( $thumb , ROOT_PATH."/uploads/obookwimage/".$id."/".$chaptrtid."/{$i}.jpg" ,75);//创建小图片,输出质量为75(0~100)
|
||
}
|
||
|
||
$image[] = "/uploads/obookwimage/".$id."/".$chaptrtid."/{$i}.jpg";
|
||
}
|
||
db('novel_content')->where('chapterid = '.$chaptrtid)->update(['images' => json_encode($image)]);
|
||
imagedestroy($source);
|
||
return $image;
|
||
***/
|
||
$imageUrl=config('web_site_url')."/images/textimage?chaptrtid=".$chaptrtid;
|
||
if(file_exists(ROOT_PATH."/uploads/obookwimage/".$id."/".$chaptrtid."/") === false)
|
||
{
|
||
checkdir(ROOT_PATH."/uploads/obookwimage/".$id."/".$chaptrtid."/", 1 );
|
||
}
|
||
$filename = "/uploads/obookwimage/".$id."/".$chaptrtid."/chapter.png";
|
||
if(file_exists(ROOT_PATH.$filename)=== false){
|
||
$source = imagecreatefrompng($imageUrl);
|
||
imagepng($source,ROOT_PATH.$filename);
|
||
}
|
||
return $filename;
|
||
}
|
||
}
|
||
|
||
|
||
public function get_category() {
|
||
$model = input('model');
|
||
$list = db('category')->where('model_id='.$model)->field('id,title')->select();
|
||
$this->ReturnJson(1,'调用成功',$list);
|
||
|
||
}
|
||
|
||
public function imagecreate() {
|
||
$type = input('type');
|
||
$url = input('url');
|
||
|
||
import('Qrcode', EXTEND_PATH);
|
||
$qr = new \Qrcode();
|
||
//生成二维码的图片URL
|
||
$qrimages = ROOT_PATH."/uploads/qrcode/qr.jpg";
|
||
//模板图片URL
|
||
$channel_qrcode_image = ROOT_PATH."/public/novel/images/qrcode".$type.".jpg";
|
||
//合成图片URL
|
||
$qr_save ="/uploads/qrcode/".md5($url.$type).".jpg";
|
||
|
||
$menuurl = get_menuurl(session('user_auth.uid'),session('wxmpid'));
|
||
|
||
|
||
|
||
if($url){
|
||
if(file_exists(ROOT_PATH.$qr_save)===false){
|
||
//参数$level表示容错率,也就是有被覆盖的区域还能识别,分别是 L(QR_ECLEVEL_L,7%),M(QR_ECLEVEL_M,15%),Q(QR_ECLEVEL_Q,25%),H(QR_ECLEVEL_H,30%); 参数$size表示生成图片大小,默认是3;
|
||
$qrcode = $qr->jpg($url,$qrimages,"Q",5);
|
||
$qrcode = file_get_contents($qrimages);
|
||
$qrImg = imagecreatefromstring($qrcode);
|
||
//获取生成的二维码图片信息
|
||
$src_info = getimagesize($qrimages);
|
||
//打开模板图片
|
||
$dst = imagecreatefromstring(file_get_contents($channel_qrcode_image));
|
||
imagecopymerge($dst, $qrImg, 360, 20, 0, 0, 205,205, 80);
|
||
imagejpeg($dst,ROOT_PATH.$qr_save);
|
||
}
|
||
|
||
echo json_encode(array("code"=>200,"image"=>$menuurl.$qr_save));
|
||
}else{
|
||
echo json_encode(array("code"=>0,"image"=>""));
|
||
}
|
||
}
|
||
} |