修复前端数据库报错

This commit is contained in:
李志强 2025-05-19 16:04:45 +08:00
parent 41a2d69f22
commit 1587524031
11 changed files with 47 additions and 55 deletions

View File

@ -201,7 +201,7 @@
// 配置图片上传 // 配置图片上传
editorConfig.MENU_CONF['uploadImage'] = { editorConfig.MENU_CONF['uploadImage'] = {
server: '{:url("index/upload_imgs")}', server: '{:url("index/upload_img")}',
fieldName: 'file', fieldName: 'file',
maxFileSize: 10 * 1024 * 1024, // 10M maxFileSize: 10 * 1024 * 1024, // 10M
maxNumberOfFiles: 10, maxNumberOfFiles: 10,
@ -236,13 +236,8 @@
customInsert(res, insertFn) { customInsert(res, insertFn) {
// res 即服务端的返回结果 // res 即服务端的返回结果
if (res.code === 0 && res.data) { if (res.code === 0 && res.data) {
// 从res.data中获取src字段 // 直接使用res.data作为图片地址
const url = String(res.data.src || ''); insertFn(res.data);
if (url) {
insertFn(url);
} else {
layer.msg('图片地址无效', { icon: 2 });
}
} else { } else {
layer.msg('图片上传失败', { icon: 2 }); layer.msg('图片上传失败', { icon: 2 });
} }

View File

@ -212,7 +212,7 @@
// 配置图片上传 // 配置图片上传
editorConfig.MENU_CONF['uploadImage'] = { editorConfig.MENU_CONF['uploadImage'] = {
server: '{:url("index/upload_imgs")}', server: '{:url("index/upload_img")}',
fieldName: 'file', fieldName: 'file',
maxFileSize: 10 * 1024 * 1024, // 10M maxFileSize: 10 * 1024 * 1024, // 10M
maxNumberOfFiles: 10, maxNumberOfFiles: 10,

View File

@ -10,9 +10,9 @@ use think\facade\Env;
use think\facade\Config; use think\facade\Config;
use app\index\model\Banner; use app\index\model\Banner;
use app\index\model\ResourcesCategory; use app\index\model\ResourcesCategory;
use app\index\model\ArticleCategory; use app\index\model\ArticlesCategory;
use app\index\model\Resources; use app\index\model\Resources;
use app\index\model\Article; use app\index\model\Articles;
class Index extends Base class Index extends Base
@ -38,7 +38,7 @@ class Index extends Base
public function siteNewslist() public function siteNewslist()
{ {
// 获取站点资讯分类顶级分类id为1的子分类 // 获取站点资讯分类顶级分类id为1的子分类
$categories = ArticleCategory::where('cid', 1) $categories = ArticlesCategory::where('cid', 1)
->where('delete_time', null) ->where('delete_time', null)
->select() ->select()
->toArray(); ->toArray();
@ -54,7 +54,7 @@ class Index extends Base
]; ];
// 获取该分类下的文章限制4条 // 获取该分类下的文章限制4条
$articles = Article::where('cate', $category['id']) $articles = Articles::where('cate', $category['id'])
->where('delete_time', null) ->where('delete_time', null)
->where('status', 2) ->where('status', 2)
->order('id', 'desc') ->order('id', 'desc')
@ -79,7 +79,7 @@ class Index extends Base
public function technicalArticleslist() public function technicalArticleslist()
{ {
// 获取技术文章分类顶级分类id为3的子分类 // 获取技术文章分类顶级分类id为3的子分类
$categories = ArticleCategory::where('cid', 3) $categories = ArticlesCategory::where('cid', 3)
->where('delete_time', null) ->where('delete_time', null)
->select() ->select()
->toArray(); ->toArray();
@ -97,7 +97,7 @@ class Index extends Base
$categoryImageMap[$category['id']] = $category['image'] ?? ''; $categoryImageMap[$category['id']] = $category['image'] ?? '';
// 获取每个分类下的文章限制12条 // 获取每个分类下的文章限制12条
$articles = Article::where('cate', $category['id']) $articles = Articles::where('cate', $category['id'])
->where('delete_time', null) ->where('delete_time', null)
->where('status', 2) ->where('status', 2)
->order('id', 'desc') ->order('id', 'desc')

View File

@ -7,6 +7,9 @@ use app\index\controller\Base;
use think\facade\Db; use think\facade\Db;
use think\facade\View; use think\facade\View;
use think\facade\Request; use think\facade\Request;
use app\index\model\Resources;
use app\index\model\ResourcesCategory;
use app\index\model\Attachments;
class Program extends Base class Program extends Base
{ {
@ -27,27 +30,24 @@ class Program extends Base
} }
// 获取程序列表 // 获取程序列表
$programs = Db::table('yz_resources') $programs = Resources::where($where)
->where($where)
->order('id DESC') ->order('id DESC')
->paginate([ ->paginate([
'list_rows' => 10, 'list_rows' => 10,
'query' => Request::instance()->param() 'query' => Request::param()
]); ]);
// 获取分类信息 // 获取分类信息
$category = null; $category = null;
if ($cateId > 0) { if ($cateId > 0) {
$category = Db::table('yz_resources_category') $category = ResourcesCategory::where('id', $cateId)
->where('id', $cateId)
->where('delete_time', null) ->where('delete_time', null)
->where('status', 1) ->where('status', 1)
->find(); ->find();
} }
// 获取所有分类 // 获取所有分类
$categories = Db::table('yz_resources_category') $categories = ResourcesCategory::where('delete_time', null)
->where('delete_time', null)
->where('status', 1) ->where('status', 1)
->select() ->select()
->toArray(); ->toArray();
@ -59,19 +59,22 @@ class Program extends Base
'categories' => $categories 'categories' => $categories
]); ]);
return view('list'); return View::fetch('list');
} }
// 程序详情页 // 程序详情页
public function detail() public function detail()
{ {
$id = Request::param('id/d', 0); $id = Request::param('id/d', 0);
$program = Db::table('yz_resources')->where('id', $id)->find(); $program = Resources::where('id', $id)->find();
if (!$program) {
return json(['code' => 0, 'msg' => '程序不存在或已被删除']);
}
// 如果size没有从附件表中获取 // 如果size没有从附件表中获取
if (empty($program['size']) && !empty($program['fileurl'])) { if (empty($program['size']) && !empty($program['fileurl'])) {
$attachment = Db::table('yz_attachments') $attachment = Attachments::where('src', $program['fileurl'])
->where('src', $program['fileurl'])
->find(); ->find();
if ($attachment && !empty($attachment['size'])) { if ($attachment && !empty($attachment['size'])) {
@ -86,26 +89,19 @@ class Program extends Base
} }
} }
} }
if (!$program) {
return json(['code' => 0, 'msg' => '程序不存在或已被删除']);
}
// 获取分类名称 // 获取分类名称
$cateName = Db::table('yz_resources_category') $cateName = ResourcesCategory::where('id', $program['cate'])
->where('id', $program['cate'])
->value('name'); ->value('name');
// 获取上一个和下一个程序 // 获取上一个和下一个程序
$prevProgram = Db::table('yz_resources') $prevProgram = Resources::where('id', '<', $id)
->where('id', '<', $id)
->where('delete_time', null) ->where('delete_time', null)
->where('status', 1) ->where('status', 1)
->order('id DESC') ->order('id DESC')
->find(); ->find();
$nextProgram = Db::table('yz_resources') $nextProgram = Resources::where('id', '>', $id)
->where('id', '>', $id)
->where('delete_time', null) ->where('delete_time', null)
->where('status', 1) ->where('status', 1)
->order('id ASC') ->order('id ASC')
@ -154,7 +150,7 @@ class Program extends Base
'relatedPrograms' => $relatedPrograms 'relatedPrograms' => $relatedPrograms
]); ]);
return view('detail'); return View::fetch('detail');
} }
// 程序下载 // 程序下载
@ -167,8 +163,7 @@ class Program extends Base
$id = Request::param('id/d', 0); $id = Request::param('id/d', 0);
// 更新下载次数 // 更新下载次数
$result = Db::table('yz_resources') $result = Resources::where('id', $id)
->where('id', $id)
->where('delete_time', null) ->where('delete_time', null)
->inc('downloads', 1) ->inc('downloads', 1)
->update(); ->update();
@ -186,8 +181,7 @@ class Program extends Base
$id = Request::param('id/d', 0); $id = Request::param('id/d', 0);
// 获取总访问量 // 获取总访问量
$totalViews = Db::table('yz_resources') $totalViews = Resources::where('id', $id)
->where('id', $id)
->value('views'); ->value('views');
return json([ return json([
@ -214,16 +208,16 @@ class Program extends Base
try { try {
// 更新访问次数 // 更新访问次数
$program = Db::table('yz_resources')->where('id', $id)->find(); $program = Resources::where('id', $id)->find();
if (!$program) { if (!$program) {
return json(['code' => 0, 'msg' => '程序不存在']); return json(['code' => 0, 'msg' => '程序不存在']);
} }
// 更新访问次数 // 更新访问次数
Db::table('yz_resources')->where('id', $id)->inc('views')->update(); Resources::where('id', $id)->inc('views')->update();
// 获取更新后的访问次数 // 获取更新后的访问次数
$newViews = Db::table('yz_resources')->where('id', $id)->value('views'); $newViews = Resources::where('id', $id)->value('views');
return json(['code' => 1, 'msg' => '更新成功', 'data' => ['views' => $newViews]]); return json(['code' => 1, 'msg' => '更新成功', 'data' => ['views' => $newViews]]);
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -3,6 +3,6 @@ namespace app\index\model;
use think\Model; use think\Model;
class Article extends Model class Articles extends Model
{ {
} }

View File

@ -0,0 +1,8 @@
<?php
namespace app\index\model;
use think\Model;
class ArticlesCategory extends Model
{
}

View File

@ -3,6 +3,6 @@ namespace app\index\model;
use think\Model; use think\Model;
class ArticleCategory extends Model class Attachments extends Model
{ {
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

View File

@ -1,4 +1,4 @@
<?php /*a:2:{s:60:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\articles\add.php";i:1747626013;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1746849526;}*/ ?> <?php /*a:2:{s:60:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\articles\add.php";i:1747641342;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1746849526;}*/ ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@ -295,7 +295,7 @@
// 配置图片上传 // 配置图片上传
editorConfig.MENU_CONF['uploadImage'] = { editorConfig.MENU_CONF['uploadImage'] = {
server: '<?php echo url("index/upload_imgs"); ?>', server: '<?php echo url("index/upload_img"); ?>',
fieldName: 'file', fieldName: 'file',
maxFileSize: 10 * 1024 * 1024, // 10M maxFileSize: 10 * 1024 * 1024, // 10M
maxNumberOfFiles: 10, maxNumberOfFiles: 10,
@ -330,13 +330,8 @@
customInsert(res, insertFn) { customInsert(res, insertFn) {
// res 即服务端的返回结果 // res 即服务端的返回结果
if (res.code === 0 && res.data) { if (res.code === 0 && res.data) {
// 从res.data中获取src字段 // 直接使用res.data作为图片地址
const url = String(res.data.src || ''); insertFn(res.data);
if (url) {
insertFn(url);
} else {
layer.msg('图片地址无效', { icon: 2 });
}
} else { } else {
layer.msg('图片上传失败', { icon: 2 }); layer.msg('图片上传失败', { icon: 2 });
} }