Files
swiftadmin/app/admin/controller/system/Company.php

108 lines
2.9 KiB
PHP
Raw Normal View History

2022-08-19 19:48:37 +08:00
<?php
2023-04-25 20:11:49 +08:00
2022-08-19 19:48:37 +08:00
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
use app\AdminController;
use app\common\model\system\Company as CompanyModel;
2022-11-28 19:11:12 +08:00
use support\Response;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
2022-08-19 19:48:37 +08:00
use Webman\Http\Request;
/**
* 公司信息
* Class Company
* @package app\admin\controller\system
*/
2023-07-03 10:08:34 +08:00
class Company extends AdminController
2022-08-19 19:48:37 +08:00
{
2023-07-03 10:08:34 +08:00
2022-08-19 19:48:37 +08:00
// 初始化函数
public function __construct()
{
parent::__construct();
$this->model = new CompanyModel();
}
/**
* 获取资源列表
2022-11-28 19:11:12 +08:00
* @return Response
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
2022-08-19 19:48:37 +08:00
*/
public function index(): \support\Response
{
if (request()->isAjax()) {
// 生成查询条件
$post = input();
$where = array();
if (!empty($post['title'])) {
2023-07-03 10:08:34 +08:00
$where[] = ['title', 'like', '%' . $post['title'] . '%'];
2022-08-19 19:48:37 +08:00
}
// 生成查询数据
$list = $this->model->where($where)->select()->toArray();
return $this->success('查询成功', null, $list, count($list));
}
2023-07-03 10:08:34 +08:00
return view('/system/company/index');
2022-08-19 19:48:37 +08:00
}
/**
* 添加公司信息
2023-07-03 10:08:34 +08:00
* @return Response
2022-08-19 19:48:37 +08:00
*/
2023-07-03 10:08:34 +08:00
public function add(): Response
2022-08-19 19:48:37 +08:00
{
2023-07-03 10:08:34 +08:00
if (request()->isPost()) {
$post = request()->post();
if ($this->model->create($post)) {
2022-08-19 19:48:37 +08:00
return $this->success();
}
return $this->error();
}
2023-07-03 10:08:34 +08:00
return view('/system/company/add', [
'data' => $this->getTableFields()
2022-08-19 19:48:37 +08:00
]);
}
/**
* 编辑公司信息
2023-07-03 10:08:34 +08:00
* @return Response
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
2022-08-19 19:48:37 +08:00
*/
2023-07-03 10:08:34 +08:00
public function edit(): Response
2022-08-19 19:48:37 +08:00
{
$id = input('id');
if (request()->isPost()) {
$post = request()->post();
2023-07-03 10:08:34 +08:00
if ($this->model->update($post)) {
2022-08-19 19:48:37 +08:00
return $this->success();
}
return $this->error();
}
$data = $this->model->find($id);
2023-07-03 10:08:34 +08:00
return view('/system/company/add', [
'data' => $data
]);
2022-08-19 19:48:37 +08:00
}
}