SchoolPhysicalExamination/application/admin/controller/Editortext.php

301 lines
12 KiB
PHP
Raw Normal View History

2024-11-23 16:46:38 +08:00
<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use app\bj\controller\Common;
use think\Log;
use \think\Validate;
2024-11-29 18:46:37 +08:00
class Editortext extends Base{
2024-11-23 16:46:38 +08:00
protected $page_num = 10;
protected $file_max_pic = 1024*1024*5;//xxxMB
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, '&apos;').replace(/"/g, '&quot;')
// $result['content'] = htmlspecialchars_decode($result['content']);
// $result['content'] = str_replace("'", "&apos;", $result['content']);
// $result['content'] = str_replace('"', '&quot;', $result['content']);
$this->assign([
'result' => $result,
'content' => $result['content'],
]);
return $this->fetch();
}
public function model_content(){
$data = input();
2024-12-26 19:14:44 +08:00
// dump($data);
// die;
2024-11-23 16:46:38 +08:00
// $data['id'] = '3';
if(!array_key_exists('id', $data)){
2024-12-18 09:19:51 +08:00
return $this->msg(10001,'id缺失');
2024-11-23 16:46:38 +08:00
}
2024-11-29 18:46:37 +08:00
// 查看文章是否存在
$article_data = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->find();
if(!$article_data){
return $this->msg(10004);
}
2025-07-23 21:32:05 +08:00
if($article_data['scene_id'] == 2){
header("Location: ".$article_data['content']);
}
2024-11-29 18:46:37 +08:00
$result = $article_data;
// 处理是否有过点赞
2024-11-23 16:46:38 +08:00
if(array_key_exists('token', $data)){
$result['token'] = $data['token'];
2024-11-29 18:46:37 +08:00
// 启动事务处理用户已读记录&文章阅读数
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();
}
2024-11-23 16:46:38 +08:00
if($is_like){
2024-11-29 18:46:37 +08:00
if($is_like['is_like'] == 0){
// 用户没点赞
2024-11-23 16:46:38 +08:00
$result['user_like'] = 0;
}else{
2024-11-29 18:46:37 +08:00
// 用户点过点赞
2024-11-23 16:46:38 +08:00
$result['user_like'] = 1;
}
}else{
2024-11-29 18:46:37 +08:00
// 用户没点过赞
2024-11-23 16:46:38 +08:00
$result['user_like'] = 2;
}
}else{
2024-11-29 18:46:37 +08:00
// 没有用户信息提示要登录
Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->setInc('reading');
2024-11-23 16:46:38 +08:00
$result['user_like'] = 3;
$result['token'] = '';
}
2024-11-29 18:46:37 +08:00
// dump($result);
// die;
2024-11-23 16:46:38 +08:00
$this->assign([
'result' => $result
]);
return $this->fetch();
}
################################################################action################################################################
################################################################action################################################################
################################################################action################################################################
// 添加咨询动作
public function add_content_action(){
2024-12-18 09:19:51 +08:00
$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)){
2024-11-23 16:46:38 +08:00
return $this->msg(10001);
}
2024-12-18 09:19:51 +08:00
$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'],
2025-07-23 21:32:05 +08:00
'scene_id'=>$data["scene_id"],
2024-12-18 09:19:51 +08:00
]);
if($result){
return $this->msg([]);
2024-11-23 16:46:38 +08:00
}else{
2024-12-18 09:19:51 +08:00
return $this->msg(10002);
2024-11-23 16:46:38 +08:00
}
2024-12-18 09:19:51 +08:00
2024-11-23 16:46:38 +08:00
}
// 修改咨询动作
public function edit_content_action(){
2024-12-18 09:19:51 +08:00
$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)){
2024-11-23 16:46:38 +08:00
return $this->msg(10001);
}
2024-12-18 09:19:51 +08:00
$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']),
2025-07-23 21:32:05 +08:00
'cover_image'=>"upload_pic/".$pic_data['name'],
'scene_id'=>$data["scene_id"],
2024-12-18 09:19:51 +08:00
]);
if($result){
return $this->msg([]);
2024-11-23 16:46:38 +08:00
}else{
2024-12-18 09:19:51 +08:00
return $this->msg(10002);
2024-11-23 16:46:38 +08:00
}
2024-12-18 09:19:51 +08:00
2024-11-23 16:46:38 +08:00
}
// 修改排序动作
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################################################################
}