dlh_test_server/app/admin/controller/BusinessSchool.php
2024-09-21 10:13:34 +08:00

188 lines
5.7 KiB
PHP

<?php
namespace app\admin\controller;
use app\common\basics\AdminBase;
use app\admin\logic\BusinessSchoolLogic;
use app\common\server\JsonServer;
use app\admin\validate\BusinessSchoolValidate;
use app\admin\validate\BusinessSchoolCategoryValidate;
use app\common\utils\UploadAliOSS;
class BusinessSchool extends AdminBase
{
private static $UPLOAD_VIDEO_PATH = 'business_school/video';
// 显示内容列表
public function content()
{
if ($this->request->isAjax()) {
$get = $this->request->get();
$lists = BusinessSchoolLogic::content($get);
return JsonServer::success("获取成功", $lists);
}
return view('', [
'category' => BusinessSchoolLogic::getCategory()
]);
}
// 添加内容
public function add_content()
{
if ($this->request->isAjax()) {
(new BusinessSchoolValidate())->goCheck('add');
$post = $this->request->post();
$res = BusinessSchoolLogic::add_content($post);
if ($res === false) {
$error = BusinessSchoolLogic::getError() ?: '新增失败';
return JsonServer::error($error);
}
return JsonServer::success('新增成功');
}
return view('', [
'category' => BusinessSchoolLogic::getCategory()
]);
}
// 修改内容
public function edit_content()
{
if ($this->request->isAjax()) {
(new BusinessSchoolValidate())->goCheck('edit');
$post = $this->request->post();
$res = BusinessSchoolLogic::edit_content($post);
if ($res === false) {
$error = BusinessSchoolLogic::getError() ?: '编辑失败';
return JsonServer::error($error);
}
return JsonServer::success('编辑成功');
}
$id = $this->request->get('id');
return view('', [
'detail' => BusinessSchoolLogic::detail_content($id),
'category' => BusinessSchoolLogic::getCategory()
]);
}
public function del_content()
{
if ($this->request->isAjax()) {
(new BusinessSchoolValidate())->goCheck('id');
$id = $this->request->post('id');
$res = BusinessSchoolLogic::del_content($id);
if ($res === false) {
$error = BusinessSchoolLogic::getError() ?: '删除失败';
return JsonServer::error($error);
}
return JsonServer::success('删除成功');
}
return JsonServer::success('异常');
}
// 上传视频到OSS
public function uploadVideo()
{
$result = UploadAliOSS::uploadFile(self::$UPLOAD_VIDEO_PATH);
if ($result['code'] == 1) {
return JsonServer::success('', $result['data']);
}
return JsonServer::error('上传失败');
}
// 删除视频
public function delVideo()
{
if ($this->request->isAjax()) {
$file = $this->request->post('videoFile');
UploadAliOSS::delFile(self::$UPLOAD_VIDEO_PATH . '/' . basename($file));
}
}
// 显示分类列表
public function category()
{
if ($this->request->isAjax()) {
$get = $this->request->get();
$lists = BusinessSchoolLogic::category($get);
return JsonServer::success("获取成功", $lists);
}
return view();
}
// 添加分类
public function add_category()
{
if ($this->request->isAjax()) {
(new BusinessSchoolCategoryValidate())->goCheck('add');
$post = $this->request->post();
$res = BusinessSchoolLogic::add_category($post);
if ($res === false) {
$error = BusinessSchoolLogic::getError() ?: '新增失败';
return JsonServer::error($error);
}
return JsonServer::success('新增成功');
}
return view();
}
// 修改分类
public function edit_category()
{
if ($this->request->isAjax()) {
(new BusinessSchoolCategoryValidate())->goCheck('edit');
$post = $this->request->post();
$res = BusinessSchoolLogic::edit_category($post);
if ($res === false) {
$error = BusinessSchoolLogic::getError() ?: '编辑失败';
return JsonServer::error($error);
}
return JsonServer::success('编辑成功');
}
$id = $this->request->get('id');
return view('', [
'detail' => BusinessSchoolLogic::detail_category($id)
]);
}
// 删除分类
public function del_category()
{
if ($this->request->isAjax()) {
(new BusinessSchoolCategoryValidate())->goCheck('id');
$id = $this->request->post('id');
$res = BusinessSchoolLogic::del_category($id);
if ($res === false) {
$error = BusinessSchoolLogic::getError() ?: '删除失败';
return JsonServer::error($error);
}
return JsonServer::success('删除成功');
}
return JsonServer::error('异常');
}
// 隐藏分类
public function hide_category()
{
if ($this->request->isAjax()) {
(new BusinessSchoolCategoryValidate())->goCheck('id');
$id = $this->request->post('id');
$res = BusinessSchoolLogic::hide_category($id);
if ($res === false) {
$error = BusinessSchoolLogic::getError() ?: '操作失败';
return JsonServer::error($error);
}
return JsonServer::success('操作成功');
}
return JsonServer::success('异常');
}
}