新增费用科目

This commit is contained in:
yaooo 2023-12-18 16:23:18 +08:00
parent cb81194486
commit 72b9ee5abc
5 changed files with 427 additions and 0 deletions

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller\cost;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\cost\CostSubjectLists;
use app\adminapi\logic\cost\CostSubjectLogic;
use app\adminapi\validate\cost\CostSubjectValidate;
/**
* CostSubject控制器
* Class CostSubjectController
* @package app\adminapi\controller\cost
*/
class CostSubjectController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/18 15:41
*/
public function lists()
{
return $this->dataLists(new CostSubjectLists());
}
/**
* @notes 添加
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/18 15:41
*/
public function add()
{
$params = (new CostSubjectValidate())->post()->goCheck('add');
$result = CostSubjectLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(CostSubjectLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/18 15:41
*/
public function edit()
{
$params = (new CostSubjectValidate())->post()->goCheck('edit');
$result = CostSubjectLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(CostSubjectLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/18 15:41
*/
public function delete()
{
$params = (new CostSubjectValidate())->post()->goCheck('delete');
CostSubjectLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/18 15:41
*/
public function detail()
{
$params = (new CostSubjectValidate())->goCheck('detail');
$result = CostSubjectLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,77 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\cost;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\cost\CostSubject;
use app\common\lists\ListsSearchInterface;
/**
* CostSubject列表
* Class CostSubjectLists
* @package app\adminapi\listscost
*/
class CostSubjectLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/18 15:41
*/
public function setSearch(): array
{
return [
'=' => ['sn', 'subject1'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/18 15:41
*/
public function lists(): array
{
return CostSubject::where($this->searchWhere)
->field(['id', 'sn', 'subject1', 'subject2'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/12/18 15:41
*/
public function count(): int
{
return CostSubject::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,110 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\cost;
use app\common\model\cost\CostSubject;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* CostSubject逻辑
* Class CostSubjectLogic
* @package app\adminapi\logic\cost
*/
class CostSubjectLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/18 15:41
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
CostSubject::create([
'sn' => $params['sn'],
'subject1' => $params['subject1'],
'subject2' => $params['subject2'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/18 15:41
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
CostSubject::where('id', $params['id'])->update([
'sn' => $params['sn'],
'subject1' => $params['subject1'],
'subject2' => $params['subject2'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/18 15:41
*/
public static function delete(array $params): bool
{
return CostSubject::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/18 15:41
*/
public static function detail($params): array
{
return CostSubject::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,98 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\cost;
use app\common\validate\BaseValidate;
/**
* CostSubject验证器
* Class CostSubjectValidate
* @package app\adminapi\validate\cost
*/
class CostSubjectValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'sn' => 'require',
'subject1' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'sn' => '科目编码',
'subject1' => '一级科目',
];
/**
* @notes 添加场景
* @return CostSubjectValidate
* @author likeadmin
* @date 2023/12/18 15:41
*/
public function sceneAdd()
{
return $this->only(['sn','subject1']);
}
/**
* @notes 编辑场景
* @return CostSubjectValidate
* @author likeadmin
* @date 2023/12/18 15:41
*/
public function sceneEdit()
{
return $this->only(['id','sn','subject1']);
}
/**
* @notes 删除场景
* @return CostSubjectValidate
* @author likeadmin
* @date 2023/12/18 15:41
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return CostSubjectValidate
* @author likeadmin
* @date 2023/12/18 15:41
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model\cost;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* CostSubject模型
* Class CostSubject
* @package app\common\model\cost
*/
class CostSubject extends BaseModel
{
use SoftDelete;
protected $name = 'cost_subject';
protected $deleteTime = 'delete_time';
}