Merge pull request 'add project_equipment_budget' (#181) from zhangwei into dev

Reviewed-on: #181
This commit is contained in:
weiz 2024-01-16 14:16:49 +08:00
commit b0d8f590f4
10 changed files with 1061 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\project;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\project\ProjectEquipmentBudgetLists;
use app\adminapi\logic\project\ProjectEquipmentBudgetLogic;
use app\adminapi\validate\project\ProjectEquipmentBudgetValidate;
/**
* 机具预算控制器
* Class ProjectEquipmentBudgetController
* @package app\adminapi\controller\project
*/
class ProjectEquipmentBudgetController extends BaseAdminController
{
/**
* @notes 获取机具预算列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function lists()
{
return $this->dataLists(new ProjectEquipmentBudgetLists());
}
/**
* @notes 添加机具预算
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function add()
{
$params = (new ProjectEquipmentBudgetValidate())->post()->goCheck('add');
$result = ProjectEquipmentBudgetLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ProjectEquipmentBudgetLogic::getError());
}
/**
* @notes 编辑机具预算
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function edit()
{
$params = (new ProjectEquipmentBudgetValidate())->post()->goCheck('edit');
$result = ProjectEquipmentBudgetLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ProjectEquipmentBudgetLogic::getError());
}
/**
* @notes 删除机具预算
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function delete()
{
$params = (new ProjectEquipmentBudgetValidate())->post()->goCheck('delete');
ProjectEquipmentBudgetLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取机具预算详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function detail()
{
$params = (new ProjectEquipmentBudgetValidate())->goCheck('detail');
$result = ProjectEquipmentBudgetLogic::detail($params);
return $this->data($result);
}
}

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\project;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\project\ProjectEquipmentBudgetDetailLists;
use app\adminapi\logic\project\ProjectEquipmentBudgetDetailLogic;
use app\adminapi\validate\project\ProjectEquipmentBudgetDetailValidate;
/**
* 机具预算明细控制器
* Class ProjectEquipmentBudgetDetailController
* @package app\adminapi\controller\project
*/
class ProjectEquipmentBudgetDetailController extends BaseAdminController
{
/**
* @notes 获取机具预算明细列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function lists()
{
return $this->dataLists(new ProjectEquipmentBudgetDetailLists());
}
/**
* @notes 添加机具预算明细
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function add()
{
$params = (new ProjectEquipmentBudgetDetailValidate())->post()->goCheck('add');
$result = ProjectEquipmentBudgetDetailLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ProjectEquipmentBudgetDetailLogic::getError());
}
/**
* @notes 编辑机具预算明细
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function edit()
{
$params = (new ProjectEquipmentBudgetDetailValidate())->post()->goCheck('edit');
$result = ProjectEquipmentBudgetDetailLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ProjectEquipmentBudgetDetailLogic::getError());
}
/**
* @notes 删除机具预算明细
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function delete()
{
$params = (new ProjectEquipmentBudgetDetailValidate())->post()->goCheck('delete');
ProjectEquipmentBudgetDetailLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取机具预算明细详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function detail()
{
$params = (new ProjectEquipmentBudgetDetailValidate())->goCheck('detail');
$result = ProjectEquipmentBudgetDetailLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,87 @@
<?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\project;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\project\Project;
use app\common\model\project\ProjectEquipmentBudget;
use app\common\model\project\ProjectEquipmentBudgetDetail;
use app\common\lists\ListsSearchInterface;
/**
* 机具预算明细列表
* Class ProjectEquipmentBudgetDetailLists
* @package app\adminapi\listsproject
*/
class ProjectEquipmentBudgetDetailLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function setSearch(): array
{
return [
'=' => ['project_id', 'equipment_budget_id'],
'%like%' => ['type', 'name'],
];
}
/**
* @notes 获取机具预算明细列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function lists(): array
{
return ProjectEquipmentBudgetDetail::where($this->searchWhere)
->field('id,project_id,equipment_budget_id,type,name,spec,unit,num,price,amount,remark')
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){
$equipment_budget = ProjectEquipmentBudget::field('equipment_budget_code')->where('id',$data['equipment_budget_id'])->findOrEmpty();
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$data['equipment_budget_code'] = $equipment_budget['equipment_budget_code'];
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
return $data;
})
->toArray();
}
/**
* @notes 获取机具预算明细数量
* @return int
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function count(): int
{
return ProjectEquipmentBudgetDetail::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,90 @@
<?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\project;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\project\Project;
use app\common\model\project\ProjectEquipmentBudget;
use app\common\lists\ListsSearchInterface;
use app\common\model\project\ProjectEquipmentBudgetDetail;
/**
* 机具预算列表
* Class ProjectEquipmentBudgetLists
* @package app\adminapi\listsproject
*/
class ProjectEquipmentBudgetLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function setSearch(): array
{
return [
'=' => ['project_id'],
'%like%' => ['equipment_budget_code'],
];
}
/**
* @notes 获取机具预算列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function lists(): array
{
return ProjectEquipmentBudget::where($this->searchWhere)
->field(['id', 'project_id', 'equipment_budget_code', 'remark', 'annex'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
//预算总量
$data['total_num'] = ProjectEquipmentBudgetDetail::where('equipment_budget_id',$data['id'])->sum('num');
//预算总金额
$data['total_amount'] = ProjectEquipmentBudgetDetail::where('equipment_budget_id',$data['id'])->sum('amount');
return $data;
})
->toArray();
}
/**
* @notes 获取机具预算数量
* @return int
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function count(): int
{
return ProjectEquipmentBudget::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,132 @@
<?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\project;
use app\common\model\project\Project;
use app\common\model\project\ProjectEquipmentBudget;
use app\common\model\project\ProjectEquipmentBudgetDetail;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 机具预算明细逻辑
* Class ProjectEquipmentBudgetDetailLogic
* @package app\adminapi\logic\project
*/
class ProjectEquipmentBudgetDetailLogic extends BaseLogic
{
/**
* @notes 添加机具预算明细
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/16 11:40
*/
public static function add(array $params): bool
{
$equipment_budget = ProjectEquipmentBudget::field('project_id')->where('id',$params['equipment_budget_id'])->findOrEmpty();
Db::startTrans();
try {
ProjectEquipmentBudgetDetail::create([
'project_id' => $equipment_budget['project_id'],
'equipment_budget_id' => $params['equipment_budget_id'],
'type' => $params['type'],
'name' => $params['name'],
'spec' => $params['spec'] ?? '',
'unit' => $params['unit'],
'num' => $params['num'],
'price' => $params['price'],
'amount' => $params['amount'],
'remark' => $params['remark'] ?? '',
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑机具预算明细
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/16 11:40
*/
public static function edit(array $params): bool
{
$equipment_budget = ProjectEquipmentBudget::field('project_id')->where('id',$params['equipment_budget_id'])->findOrEmpty();
Db::startTrans();
try {
ProjectEquipmentBudgetDetail::where('id', $params['id'])->update([
'project_id' => $equipment_budget['project_id'],
'equipment_budget_id' => $params['equipment_budget_id'],
'type' => $params['type'],
'name' => $params['name'],
'spec' => $params['spec'] ?? '',
'unit' => $params['unit'],
'num' => $params['num'],
'price' => $params['price'],
'amount' => $params['amount'],
'remark' => $params['remark'] ?? '',
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除机具预算明细
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/16 11:40
*/
public static function delete(array $params): bool
{
return ProjectEquipmentBudgetDetail::destroy($params['id']);
}
/**
* @notes 获取机具预算明细详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/01/16 11:40
*/
public static function detail($params): array
{
$data = ProjectEquipmentBudgetDetail::field('id,project_id,equipment_budget_id,type,name,spec,unit,num,price,amount,remark')->findOrEmpty($params['id']);
$equipment_budget = ProjectEquipmentBudget::field('equipment_budget_code')->where('id',$data['equipment_budget_id'])->findOrEmpty();
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$data['equipment_budget_code'] = $equipment_budget['equipment_budget_code'];
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
return $data->toArray();
}
}

View File

@ -0,0 +1,170 @@
<?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\project;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\project\Project;
use app\common\model\project\ProjectEquipmentBudget;
use app\common\logic\BaseLogic;
use app\common\model\project\ProjectEquipmentBudgetDetail;
use think\facade\Db;
/**
* 机具预算逻辑
* Class ProjectEquipmentBudgetLogic
* @package app\adminapi\logic\project
*/
class ProjectEquipmentBudgetLogic extends BaseLogic
{
/**
* @notes 添加机具预算
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/16 11:40
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$res = ProjectEquipmentBudget::create([
'org_id' => $params['org_id'],
'dept_id' => $params['dept_id'],
'project_id' => $params['project_id'],
'equipment_budget_code' => data_unique_code('项目机具预算'),
'remark' => $params['remark'] ?? '',
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
]);
foreach ($params['equipment_budget_detail'] as $item)
{
ProjectEquipmentBudgetDetail::create([
'project_id' => $params['project_id'],
'equipment_budget_id' => $res->id,
'type' => $item['type'],
'name' => $item['name'],
'spec' => $item['spec'] ?? '',
'unit' => $item['unit'],
'price' => $item['price'],
'num' => $item['num'],
'amount' => $item['price'] * $item['num'],
'remark' => $item['remark'] ?? '',
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑机具预算
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/16 11:40
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ProjectEquipmentBudget::where('id', $params['id'])->update([
'org_id' => $params['org_id'],
'dept_id' => $params['dept_id'],
'project_id' => $params['project_id'],
'remark' => $params['remark'] ?? '',
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
]);
foreach ($params['equipment_budget_detail'] as $item)
{
if(isset($item['id']) && $item['id'] != ''){
ProjectEquipmentBudgetDetail::where('id',$item['id'])->update([
'project_id' => $params['project_id'],
'equipment_budget_id' => $params['id'],
'type' => $item['type'],
'name' => $item['name'],
'spec' => $item['spec'] ?? '',
'unit' => $item['unit'],
'price' => $item['price'],
'num' => $item['num'],
'amount' => $item['price'] * $item['num'],
'remark' => $item['remark'] ?? '',
]);
}else{
ProjectEquipmentBudgetDetail::create([
'project_id' => $params['project_id'],
'equipment_budget_id' => $params['id'],
'type' => $item['type'],
'name' => $item['name'],
'spec' => $item['spec'] ?? '',
'unit' => $item['unit'],
'price' => $item['price'],
'num' => $item['num'],
'amount' => $item['price'] * $item['num'],
'remark' => $item['remark'] ?? '',
]);
}
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除机具预算
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/16 11:40
*/
public static function delete(array $params): bool
{
return ProjectEquipmentBudget::destroy($params['id']);
}
/**
* @notes 获取机具预算详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/01/16 11:40
*/
public static function detail($params): array
{
$data = ProjectEquipmentBudget::field('id,org_id,dept_id,project_id,equipment_budget_code,remark,annex')->findOrEmpty($params['id']);
$org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty();
$dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty();
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$data['org_name'] = $org['name'];
$data['dept_name'] = $dept['name'];
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
return $data->toArray();
}
}

View File

@ -0,0 +1,114 @@
<?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\project;
use app\common\model\project\ProjectEquipmentBudget;
use app\common\validate\BaseValidate;
/**
* 机具预算明细验证器
* Class ProjectEquipmentBudgetDetailValidate
* @package app\adminapi\validate\project
*/
class ProjectEquipmentBudgetDetailValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'equipment_budget_id' => 'require|checkEquipmentBudget',
'type' => 'require',
'name' => 'require',
'unit' => 'require',
'num' => 'require|float|gt:0',
'price' => 'require|float|gt:0',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'equipment_budget_id' => '机具预算id',
'type' => '机具类别',
'name' => '机具名称',
'unit' => '单位',
'num' => '数量',
'price' => '单价',
];
/**
* @notes 添加场景
* @return ProjectEquipmentBudgetDetailValidate
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return ProjectEquipmentBudgetDetailValidate
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return ProjectEquipmentBudgetDetailValidate
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ProjectEquipmentBudgetDetailValidate
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkEquipmentBudget($value): bool|string
{
$data = ProjectEquipmentBudget::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '机具预算信息不存在';
}
return true;
}
}

View File

@ -0,0 +1,182 @@
<?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\project;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\project\Project;
use app\common\model\project\ProjectEquipmentBudgetDetail;
use app\common\validate\BaseValidate;
/**
* 机具预算验证器
* Class ProjectEquipmentBudgetValidate
* @package app\adminapi\validate\project
*/
class ProjectEquipmentBudgetValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'org_id' => 'require|checkOrg',
'dept_id' => 'require|checkDept',
'project_id' => 'require|checkProject',
'annex' => 'checkAnnex',
'equipment_budget_detail' => 'require|checkEquipmentBudgetDetail'
];
protected $message = [
'id.require' => '缺少必要参数',
'org_id.require' => '请选择组织',
'dept_id.require' => '请选择部门',
'project_id.require' => '请选择项目',
'equipment_budget_detail.require' => '请填机具预算清单'
];
/**
* @notes 添加场景
* @return ProjectEquipmentBudgetValidate
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return ProjectEquipmentBudgetValidate
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return ProjectEquipmentBudgetValidate
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ProjectEquipmentBudgetValidate
* @author likeadmin
* @date 2024/01/16 11:40
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkOrg($value): bool|string
{
$org = Orgs::where('id',$value)->findOrEmpty();
if($org->isEmpty()){
return '组织不存在';
}
return true;
}
public function checkDept($value,$rule,$data): bool|string
{
$dept = Dept::where('id',$value)->findOrEmpty();
if($dept->isEmpty()){
return '部门不存在';
}
if($dept['org_id'] != $data['org_id']){
return '部门无效';
}
return true;
}
public function checkProject($value): bool|string
{
$project = Project::where('id',$value)->findOrEmpty();
if($project->isEmpty()){
return '项目信息不存在';
}
if($project['is_budget'] != 1){
return '该项目没有编制总预算,不能添加材料预算';
}
return true;
}
public function checkAnnex($value): bool|string
{
if(!empty($value) && $value != ''){
if(!is_array($value)){
return '附件格式错误';
}
}
return true;
}
public function checkEquipmentBudgetDetail($value): bool|string
{
if(empty($value) || !is_array($value)){
return '机具预算清单数据格式错误';
}
foreach($value as $v) {
if(isset($v['id']) && $v['id'] != ''){
$data = ProjectEquipmentBudgetDetail::where('id',$v['id'])->findOrEmpty();
if($data->isEmpty()){
return '机具预算明细信息不存在';
}
}
if(empty($v['type'])){
return '机具类别不能为空';
}
if(empty($v['name'])){
return '机具名称不能为空';
}
if(empty($v['unit'])){
return '单位不能为空';
}
if(empty($v['num'])){
return '数量不能为空';
}else{
if(!is_numeric($v['num']) || $v['num'] < 0){
return '数量必须是大于0的数字';
}
}
if(empty($v['price'])){
return '单价不能为空';
}else{
if(!is_numeric($v['price']) || $v['price'] < 0){
return '单价必须是大于0的数字';
}
}
}
return true;
}
}

View File

@ -0,0 +1,36 @@
<?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\project;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 机具预算模型
* Class ProjectEquipmentBudget
* @package app\common\model\project
*/
class ProjectEquipmentBudget extends BaseModel
{
use SoftDelete;
protected $name = 'project_equipment_budget';
protected $deleteTime = 'delete_time';
public function getAnnexAttr($value){
return !empty($value) ? json_decode($value,true) : '';
}
}

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\project;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 机具预算明细模型
* Class ProjectEquipmentBudgetDetail
* @package app\common\model\project
*/
class ProjectEquipmentBudgetDetail extends BaseModel
{
use SoftDelete;
protected $name = 'project_equipment_budget_detail';
protected $deleteTime = 'delete_time';
}