BuildDivision

This commit is contained in:
weiz 2023-12-22 09:36:25 +08:00
parent 934dc07c7a
commit 86f7e740b6
5 changed files with 450 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\build;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\build\BuildDivisionLists;
use app\adminapi\logic\build\BuildDivisionLogic;
use app\adminapi\validate\build\BuildDivisionValidate;
/**
* 分部分项划分控制器
* Class BuildDivisionController
* @package app\adminapi\controller\build
*/
class BuildDivisionController extends BaseAdminController
{
/**
* @notes 获取分部分项划分列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/22 09:17
*/
public function lists()
{
return $this->dataLists(new BuildDivisionLists());
}
/**
* @notes 添加分部分项划分
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/22 09:17
*/
public function add()
{
$params = (new BuildDivisionValidate())->post()->goCheck('add');
$result = BuildDivisionLogic::add($params,$this->adminId);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(BuildDivisionLogic::getError());
}
/**
* @notes 编辑分部分项划分
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/22 09:17
*/
public function edit()
{
$params = (new BuildDivisionValidate())->post()->goCheck('edit');
$result = BuildDivisionLogic::edit($params,$this->adminId);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(BuildDivisionLogic::getError());
}
/**
* @notes 删除分部分项划分
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/22 09:17
*/
public function delete()
{
$params = (new BuildDivisionValidate())->post()->goCheck('delete');
BuildDivisionLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取分部分项划分详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/22 09:17
*/
public function detail()
{
$params = (new BuildDivisionValidate())->goCheck('detail');
$result = BuildDivisionLogic::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\build;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\build\BuildDivision;
use app\common\lists\ListsSearchInterface;
/**
* 分部分项划分列表
* Class BuildDivisionLists
* @package app\adminapi\listsbuild
*/
class BuildDivisionLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/22 09:17
*/
public function setSearch(): array
{
return [
'%like%' => ['division_engineering', 'sub_division_engineering', 'subentry_engineering', 'subentry_engineering_code'],
];
}
/**
* @notes 获取分部分项划分列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/22 09:17
*/
public function lists(): array
{
return BuildDivision::where($this->searchWhere)
->field(['id', 'division_engineering', 'sub_division_engineering', 'subentry_engineering', 'subentry_engineering_code'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取分部分项划分数量
* @return int
* @author likeadmin
* @date 2023/12/22 09:17
*/
public function count(): int
{
return BuildDivision::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,119 @@
<?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\build;
use app\common\model\auth\Admin;
use app\common\model\build\BuildDivision;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 分部分项划分逻辑
* Class BuildDivisionLogic
* @package app\adminapi\logic\build
*/
class BuildDivisionLogic extends BaseLogic
{
/**
* @notes 添加分部分项划分
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/22 09:17
*/
public static function add(array $params,$admin_id): bool
{
Db::startTrans();
try {
BuildDivision::create([
'division_engineering' => $params['division_engineering'],
'sub_division_engineering' => $params['sub_division_engineering'],
'subentry_engineering' => $params['subentry_engineering'],
'subentry_engineering_code' => $params['subentry_engineering_code'],
'add_user' => $admin_id,
'update_user' => $admin_id,
]);
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/22 09:17
*/
public static function edit(array $params,$admin_id): bool
{
Db::startTrans();
try {
BuildDivision::where('id', $params['id'])->update([
'division_engineering' => $params['division_engineering'],
'sub_division_engineering' => $params['sub_division_engineering'],
'subentry_engineering' => $params['subentry_engineering'],
'subentry_engineering_code' => $params['subentry_engineering_code'],
'update_user' => $admin_id,
'updatte_time' => time(),
]);
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/22 09:17
*/
public static function delete(array $params): bool
{
return BuildDivision::destroy($params['id']);
}
/**
* @notes 获取分部分项划分详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/22 09:17
*/
public static function detail($params): array
{
$data = BuildDivision::findOrEmpty($params['id'])->toArray();
$admin = Admin::where('id','in',[$data['add_user'],$data['update_user']])->column('name','id');
$data['add_user_name'] = $admin[$data['add_user']];
$data['update_user_name'] = $admin[$data['update_user']];
return $data;
}
}

View File

@ -0,0 +1,112 @@
<?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\build;
use app\common\validate\BaseValidate;
/**
* 分部分项划分验证器
* Class BuildDivisionValidate
* @package app\adminapi\validate\build
*/
class BuildDivisionValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'division_engineering' => 'require',
'sub_division_engineering' => 'require',
'subentry_engineering' => 'require',
'subentry_engineering_code' => 'require'
];
protected $message = [
'id.require' => '缺少必要参数',
'division_engineering.require' => '请填写分部工程',
'sub_division_engineering.require' => '请填写子分部工程',
'subentry_engineering.require' => '请填写分项工程',
'subentry_engineering_code.require' => '请填写分项工程编码'
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'division_engineering' => '分部工程',
'sub_division_engineering' => '子分部工程',
'subentry_engineering' => '分项工程',
'subentry_engineering_code' => '分项工程编码',
'add_user' => '添加人',
'update_user' => '更新人',
];
/**
* @notes 添加场景
* @return BuildDivisionValidate
* @author likeadmin
* @date 2023/12/22 09:17
*/
public function sceneAdd()
{
return $this->only(['division_engineering','sub_division_engineering','subentry_engineering','subentry_engineering_code']);
}
/**
* @notes 编辑场景
* @return BuildDivisionValidate
* @author likeadmin
* @date 2023/12/22 09:17
*/
public function sceneEdit()
{
return $this->only(['id','division_engineering','sub_division_engineering','subentry_engineering','subentry_engineering_code']);
}
/**
* @notes 删除场景
* @return BuildDivisionValidate
* @author likeadmin
* @date 2023/12/22 09:17
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return BuildDivisionValidate
* @author likeadmin
* @date 2023/12/22 09:17
*/
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\build;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 分部分项划分模型
* Class BuildDivision
* @package app\common\model\build
*/
class BuildDivision extends BaseModel
{
use SoftDelete;
protected $name = 'build_division';
protected $deleteTime = 'delete_time';
}