修复前端数据库报错

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

View File

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

View File

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

View File

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

View File

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