diff --git a/application/admin/controller/Base.php b/application/admin/controller/Base.php index d987517..c716458 100644 --- a/application/admin/controller/Base.php +++ b/application/admin/controller/Base.php @@ -11,6 +11,7 @@ class Base extends Controller{ protected $ceshiyong_token = 'caadd1be045a65f30b92aa805f1de54a'; protected $token_time = 86400*30;//天 + protected $file_size = 1024*1024*10;//10M protected $return_data_all = [ // '0' => ['success',[]], '10001'=>'关键参数缺失', @@ -235,17 +236,18 @@ class Base extends Controller{ // 使用 pathinfo() 函数获取文件名的扩展名 $pathinfo = pathinfo($name); $extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较 + $file_name = $pathinfo['filename']; // 判断扩展名是否不是 .png 或 .gif if ($extension !== 'png' && $extension !== 'gif') { // 修改文件名,将扩展名改为 .jpg - $new_filename = date('YmdHis').$name . '.jpg'; + $new_filename = date('YmdHis').$file_name . '.jpg'; } else { $new_filename = date('YmdHis').$name; } - $info = $file->move(ROOT_PATH . 'public' . DS . 'upload_pic',$new_filename); + $info = $file->validate(['size'=>$this->file_size,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'upload_pic',$new_filename); if($info){ $insert_data = [ - 'url_data'=>"http://wm.tc.com/upload_pic/".$new_filename, + 'url_data'=>"https://tc.pcxbc.com/upload_pic/".$new_filename, 'name'=>$name, 'create_time'=>date('Y-m-d H:i:s'), ]; diff --git a/application/admin/controller/Editortext.php b/application/admin/controller/Editortext.php index 953f9b1..12bd41c 100644 --- a/application/admin/controller/Editortext.php +++ b/application/admin/controller/Editortext.php @@ -76,7 +76,7 @@ class Editortext extends Base{ $data = input(); // $data['id'] = '3'; if(!array_key_exists('id', $data)){ - return $this->msg(10001); + return $this->msg(10001,'id缺失'); } // 查看文章是否存在 $article_data = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->find(); @@ -139,75 +139,50 @@ class Editortext extends Base{ // 添加咨询动作 public function add_content_action(){ - $file = request()->file('cover_image'); - $data = request()->param(); - if(!array_key_exists('title', $data) || !array_key_exists('sector', $data) || !array_key_exists('type', $data) || !array_key_exists('content', $data)){ + $data = input(); + if(!array_key_exists('cover_image', $data) || !array_key_exists('title', $data) || !array_key_exists('sector', $data) || !array_key_exists('type', $data) || !array_key_exists('content', $data)){ return $this->msg(10001); } - $name = time().$file->getInfo()['name']; - $info = $file->move(ROOT_PATH . 'public' . DS . 'editor_upload' . DS . 'cover',$name); - if($info){ - $result = Db::table('admin_editor_text_content')->insert([ - 'title'=>$data['title'], - 'cover_image'=>"editor_upload/cover/".$name, - 'content'=>$data['content'], - 'create_time'=>date('Y-m-d H:i:s'), - 'update_time'=>date('Y-m-d H:i:s'), - 'sector'=>$data['sector'], - 'type'=>$data['type'], - ]); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); - } - + $pic_data = Db::table('admin_pic_manage')->where(['id'=>$data['cover_image']])->find(); + + $result = Db::table('admin_editor_text_content')->insert([ + 'title'=>$data['title'], + 'content'=>$data['content'], + 'create_time'=>date('Y-m-d H:i:s'), + 'update_time'=>date('Y-m-d H:i:s'), + 'sector'=>implode(',', $data['sector']), + 'type'=>implode(',', $data['type']), + 'cover_image'=>"upload_pic/".$pic_data['name'], + ]); + if($result){ + return $this->msg([]); }else{ - return $this->msg(10002,$file->getError()); + return $this->msg(10002); } + } // 修改咨询动作 public function edit_content_action(){ - $file = request()->file('cover_image'); - $data = request()->param(); - if(!array_key_exists('title', $data) || !array_key_exists('sector', $data) || !array_key_exists('type', $data) || !array_key_exists('content', $data)){ + $data = input(); + if(!array_key_exists('cover_image', $data) || !array_key_exists('title', $data) || !array_key_exists('sector', $data) || !array_key_exists('type', $data) || !array_key_exists('content', $data)){ return $this->msg(10001); } - if($file){ - $name = time().$file->getInfo()['name']; - $info = $file->move(ROOT_PATH . 'public' . DS . 'editor_upload' . DS . 'cover',$name); - if($info){ - $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->update([ - 'title'=>$data['title'], - 'cover_image'=>"editor_upload/cover/".$name, - 'content'=>$data['content'], - 'update_time'=>date('Y-m-d H:i:s'), - 'sector'=>$data['sector'], - 'type'=>$data['type'] - ]); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); - } - - }else{ - return $this->msg(10002,$file->getError()); - } + $pic_data = Db::table('admin_pic_manage')->where(['id'=>$data['cover_image']])->find(); + + $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->update([ + 'title'=>$data['title'], + 'content'=>$data['content'], + 'update_time'=>date('Y-m-d H:i:s'), + 'sector'=>implode(',', $data['sector']), + 'type'=>implode(',', $data['type']), + 'cover_image'=>"upload_pic/".$pic_data['name'] + ]); + if($result){ + return $this->msg([]); }else{ - $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->update([ - 'title'=>$data['title'], - 'content'=>$data['content'], - 'update_time'=>date('Y-m-d H:i:s'), - 'sector'=>$data['sector'], - 'type'=>$data['type'] - ]); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); - } + return $this->msg(10002); } + } // 修改排序动作 diff --git a/application/admin/controller/Notice.php b/application/admin/controller/Notice.php index dbd5775..fef0b59 100644 --- a/application/admin/controller/Notice.php +++ b/application/admin/controller/Notice.php @@ -23,6 +23,7 @@ class Notice extends Base{ ###################################################banner图管理start################################################### ###################################################banner图管理start################################################### ###################################################banner图管理start################################################### + public function banner_index($page = 1){ $data = input(); $pd = true; @@ -69,13 +70,71 @@ class Notice extends Base{ return $this->fetch(); } public function banner_edit(){ - + $data = input(); + $return_data = Db::table('admin_notice_banner')->where(['id'=>$data['id']])->find(); + $pic_id = Db::table('admin_pic_manage')->where(['url_data'=>$return_data['pic']])->find(); + $return_data['pic_id'] = $pic_id['id']; + if($return_data['type'] == 1){ + $return_data['jump_url'] = ''; + } + $this->assign([ + 'result' => $return_data, + ]); + return $this->fetch(); + } + + ###################################################action + public function banner_add_or_update_action(){ + $data = input(); + $action_data = [ + 'title' => $data['title'], + 'pic' => $data['banner_img'], + 'type' => $data['type'], + 'jump_url' => '', + 'parameter_data' => $data['parameter_data'], + 'create_time' => date('Y-m-d H:i:s'), + 'scene_data' => $data['scene_data'], + ]; + $pic_data = Db::table('admin_pic_manage')->where(['id'=>$action_data['pic']])->find(); + $action_data['pic'] = $pic_data['url_data']; + if($action_data['type'] == 1){ + $action_data['jump_url'] = "https://tc.pcxbc.com/editortext/model_content?id=".$action_data['parameter_data']; + }else if($action_data['type'] == 2){ + $action_data['jump_url'] = $data['jump_url']; + }else{ + return $this->msg(10002,'选择类型错误'); + } + if($data['action_type'] == 'add'){ + $result = Db::table('admin_notice_banner')->insertGetId($action_data); + }else{ + unset($action_data['create_time']); + unset($action_data['scene_data']); + $result = Db::table('admin_notice_banner')->where(['id'=>$data['id']])->update($action_data); + } + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } public function banner_update_sort(){ - + $data = input(); + $result = Db::table('admin_notice_banner')->where(['id'=>$data['id']])->update(['sort_num'=>$data['data']]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } } public function banner_stop_run(){ - + $data = input(); + $result = Db::table('admin_notice_banner')->where(['id'=>$data['id']])->update(['is_del'=>$data['data']]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } } ###################################################banner图管理end################################################### ###################################################banner图管理end################################################### @@ -84,6 +143,48 @@ class Notice extends Base{ ###################################################首页弹窗管理start################################################### ###################################################首页弹窗管理start################################################### ###################################################首页弹窗管理start################################################### + public function pop_index($page = 1){ + $data = input(); + $pd = true; + $parameter = []; + $parameter['scene_data'] = 1; + if(array_key_exists('tt', $data)){ + $page = $data['page_num']; + unset($data['page_num']); + unset($data['tt']); + $pd = false; + // if($data['status_num'] === "0" || $data['status_num'] === "1"){ + // $parameter['is_del'] = $data['status_num']; + // } + + // if($data['tel']){ + // $parameter['tel'] = $data['tel']; + // } + // if($data['email']){ + // $parameter['email'] = $data['email']; + // } + // if($data['s_time']){ + // $parameter['create_time'] = ['>=',$data['s_time']]; + // } + // if($data['e_time']){ + // $parameter['create_time'] = ['<=',$data['e_time']]; + // } + } + $num = Db::table('admin_notice_banner')->where($parameter)->count(); + $result = Db::table('admin_notice_banner')->where($parameter)->order('is_del,sort_num desc')->page($page,$this->page_num)->select(); + // dump($result); + // die; + if(!$pd){ + $return_result['num'] = $num; + $return_result['data'] = $result; + return $this->msg(0,'success',$return_result); + } + $this->assign([ + 'result' => $result, + 'num' => $num, + ]); + return $this->fetch(); + } ###################################################首页弹窗管理end################################################### ###################################################首页弹窗管理end################################################### @@ -132,310 +233,5 @@ class Notice extends Base{ ###################################################公共用接口end################################################### ###################################################公共用接口end################################################### - - public function index($page = 1){ - $data = input(); - $pd = true; - $parameter = []; - // $parameter['is_del'] = 0; - if(array_key_exists('tt', $data)){ - $page = $data['page_num']; - unset($data['page_num']); - unset($data['tt']); - $pd = false; - // if($data['status_num'] === "0" || $data['status_num'] === "1"){ - // $parameter['is_del'] = $data['status_num']; - // } - - // if($data['tel']){ - // $parameter['tel'] = $data['tel']; - // } - // if($data['email']){ - // $parameter['email'] = $data['email']; - // } - // if($data['s_time']){ - // $parameter['create_time'] = ['>=',$data['s_time']]; - // } - // if($data['e_time']){ - // $parameter['create_time'] = ['<=',$data['e_time']]; - // } - } - $num = Db::table('admin_editor_text_content')->where($parameter)->count(); - $result = Db::table('admin_editor_text_content')->where($parameter)->order('is_del,id desc')->page($page,$this->page_num)->select(); - if(!$pd){ - $return_result['num'] = $num; - $return_result['data'] = $result; - return $this->msg(0,'success',$return_result); - } - $this->assign([ - 'result' => $result, - 'num' => $num, - ]); - return $this->fetch(); - } - - public function add_content(){ - return $this->fetch(); - } - public function edit_content(){ - $data = input(); - $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->find(); - // $result['sector'] = explode(',',$result['sector']); - // dump($result); - // die; - // .replace(/'/g, ''').replace(/"/g, '"') - // $result['content'] = htmlspecialchars_decode($result['content']); - // $result['content'] = str_replace("'", "'", $result['content']); - // $result['content'] = str_replace('"', '"', $result['content']); - $this->assign([ - 'result' => $result, - 'content' => $result['content'], - ]); - return $this->fetch(); - } - - public function model_content(){ - $data = input(); - // $data['id'] = '3'; - if(!array_key_exists('id', $data)){ - return $this->msg(10001); - } - // 查看文章是否存在 - $article_data = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->find(); - if(!$article_data){ - return $this->msg(10004); - } - $result = $article_data; - // 处理是否有过点赞 - if(array_key_exists('token', $data)){ - $result['token'] = $data['token']; - // 启动事务处理用户已读记录&文章阅读数 - Db::startTrans(); - try{ - Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->setInc('reading'); - // 查看文章是否有被观看过 - $is_like = Db::table('admin_editor_text_like_up_log')->where(['aetc_id'=>$data['id'],'token'=>$data['token']])->find(); - if (!$is_like) { - // 如果不存在,则插入新记录 - $save_data = ['token'=>$result['token'],'aetc_id'=>$data['id'],'create_time'=>date('Y-m-d H:i:s')]; - Db::name('admin_editor_text_like_up_log')->insert($save_data); - }else{ - Db::table('admin_editor_text_like_up_log')->where(['id'=>$is_like['id']])->setInc('reading'); - } - // 提交事务 - Db::commit(); - } catch (\Exception $e) { - // 回滚事务 - Db::rollback(); - } - if($is_like){ - if($is_like['is_like'] == 0){ - // 用户没点赞 - $result['user_like'] = 0; - }else{ - // 用户点过点赞 - $result['user_like'] = 1; - } - }else{ - // 用户没点过赞 - $result['user_like'] = 2; - } - }else{ - // 没有用户信息提示要登录 - Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->setInc('reading'); - $result['user_like'] = 3; - $result['token'] = ''; - } - // dump($result); - // die; - $this->assign([ - 'result' => $result - ]); - return $this->fetch(); - } - - - ################################################################action################################################################ - ################################################################action################################################################ - ################################################################action################################################################ - - // 添加咨询动作 - public function add_content_action(){ - $file = request()->file('cover_image'); - $data = request()->param(); - if(!array_key_exists('title', $data) || !array_key_exists('sector', $data) || !array_key_exists('type', $data) || !array_key_exists('content', $data)){ - return $this->msg(10001); - } - $name = time().$file->getInfo()['name']; - $info = $file->move(ROOT_PATH . 'public' . DS . 'editor_upload' . DS . 'cover',$name); - if($info){ - $result = Db::table('admin_editor_text_content')->insert([ - 'title'=>$data['title'], - 'cover_image'=>"editor_upload/cover/".$name, - 'content'=>$data['content'], - 'create_time'=>date('Y-m-d H:i:s'), - 'update_time'=>date('Y-m-d H:i:s'), - 'sector'=>$data['sector'], - 'type'=>$data['type'], - ]); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); - } - - }else{ - return $this->msg(10002,$file->getError()); - } - } - // 修改咨询动作 - public function edit_content_action(){ - $file = request()->file('cover_image'); - $data = request()->param(); - if(!array_key_exists('title', $data) || !array_key_exists('sector', $data) || !array_key_exists('type', $data) || !array_key_exists('content', $data)){ - return $this->msg(10001); - } - if($file){ - $name = time().$file->getInfo()['name']; - $info = $file->move(ROOT_PATH . 'public' . DS . 'editor_upload' . DS . 'cover',$name); - if($info){ - $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->update([ - 'title'=>$data['title'], - 'cover_image'=>"editor_upload/cover/".$name, - 'content'=>$data['content'], - 'update_time'=>date('Y-m-d H:i:s'), - 'sector'=>$data['sector'], - 'type'=>$data['type'] - ]); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); - } - - }else{ - return $this->msg(10002,$file->getError()); - } - }else{ - $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->update([ - 'title'=>$data['title'], - 'content'=>$data['content'], - 'update_time'=>date('Y-m-d H:i:s'), - 'sector'=>$data['sector'], - 'type'=>$data['type'] - ]); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); - } - } - } - - // 修改排序动作 - public function edit_order_action(){ - $data = input(); - if(!array_key_exists('id', $data) || !array_key_exists('data', $data) || !array_key_exists('str', $data)){ - return $this->msg(10001); - } - $data['str'] = $data['str'] == 'loop'?'loop_img':'top_up'; - $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->update([ - $data['str']=>$data['data'], - 'update_time'=>date('Y-m-d H:i:s'), - ]); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); - } - } - - // 上传图片动作 - public function upload_pic_action(){ - // $file1 = request()->file('file'); - $file = request()->file('wangeditor-uploaded-image'); - - if($file){ - $name = $file->getInfo()['name']; - // 使用 pathinfo() 函数获取文件名的扩展名 - $pathinfo = pathinfo($name); - $extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较 - // 判断扩展名是否不是 .png 或 .gif - if ($extension !== 'png' && $extension !== 'gif') { - // 修改文件名,将扩展名改为 .jpg - $new_filename = time().$pathinfo['filename'] . '.jpg'; - } else { - $new_filename = time().$name; - } - $info = $file->move(ROOT_PATH . 'public' . DS . 'editor_upload' . DS . 'pic',$new_filename); - if($info){ - $return_data = [ - 'errno'=>0, - 'data'=>[ - 'url'=>'http://tc.pcxbc.com/editor_upload/pic/'.$new_filename, - ] - ]; - return json($return_data); - }else{ - // 上传失败获取错误信息 - // echo $file->getError(); - $return_data = [ - 'errno'=>9999, - 'message'=>$file->getError() - ]; - return json($return_data); - } - } - } - // 上传视频动作 - public function upload_video_action(){ - // $file1 = request()->file('file'); - $file = request()->file('wangeditor-uploaded-video'); - // dump($file); - // die; - if($file){ - $name = time().$file->getInfo()['name']; - $info = $file->move(ROOT_PATH . 'public' . DS . 'editor_upload' . DS . 'video',$name); - if($info){ - $return_data = [ - 'errno'=>0, - 'data'=>[ - 'url'=>'http://tc.pcxbc.com/editor_upload/video/'.$name, - ] - ]; - return json($return_data); - }else{ - // 上传失败获取错误信息 - // echo $file->getError(); - $return_data = [ - 'errno'=>9999, - 'message'=>$file->getError() - ]; - return json($return_data); - } - } - } - - // 停用启用动作 - public function stop_action(){ - $data = input(); - if(is_array($data['id'])){ - $data['id'] = implode(',',$data['id']); - $result = Db::table('admin_editor_text_content')->where("id in (".$data['id'].")")->update(['is_del'=>$data['is_del']]); - }else{ - $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->update(['is_del'=>$data['is_del']]); - } - - if($result){ - return $this->msg(0,'success'); - }else{ - return $this->msg(10001,'success'); - } - } - - ################################################################other################################################################ - ################################################################other################################################################ - ################################################################other################################################################ - } \ No newline at end of file diff --git a/application/admin/view/editortext/add_content.html b/application/admin/view/editortext/add_content.html index cce8aa1..82be58b 100644 --- a/application/admin/view/editortext/add_content.html +++ b/application/admin/view/editortext/add_content.html @@ -40,9 +40,7 @@ 上传封面