This commit is contained in:
weiz 2024-01-09 11:24:53 +08:00
parent 6a57ca15c9
commit 24a4e1f3b1
7 changed files with 435 additions and 273 deletions

View File

@ -1,77 +1,104 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版 // | likeadmin快速开发前后端分离管理后台PHP版
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力 // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo // | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin // | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin // | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn // | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权 // | likeadmin团队 版权所有 拥有最终解释权
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | author: likeadminTeam // | author: likeadminTeam
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\adminapi\lists\project; namespace app\adminapi\lists\project;
use app\adminapi\lists\BaseAdminDataLists; use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\project\ProjectMaterialBudgetDetail; use app\common\model\material\Material;
use app\common\lists\ListsSearchInterface; use app\common\model\material\MaterialClassify;
use app\common\model\project\Project;
use app\common\model\project\ProjectMaterialBudget;
/** use app\common\model\project\ProjectMaterialBudgetDetail;
* 材料预算明细列表 use app\common\lists\ListsSearchInterface;
* Class ProjectMaterialBudgetDetailLists
* @package app\adminapi\listsproject
*/ /**
class ProjectMaterialBudgetDetailLists extends BaseAdminDataLists implements ListsSearchInterface * 材料预算明细列表
{ * Class ProjectMaterialBudgetDetailLists
* @package app\adminapi\listsproject
*/
/** class ProjectMaterialBudgetDetailLists extends BaseAdminDataLists implements ListsSearchInterface
* @notes 设置搜索条件 {
* @return \string[][]
* @author likeadmin
* @date 2024/01/08 21:52 /**
*/ * @notes 设置搜索条件
public function setSearch(): array * @return \string[][]
{ * @author likeadmin
return [ * @date 2024/01/08 21:52
'=' => ['material_budget_id', 'material_id', 'budget_type'], */
]; public function setSearch(): array
} {
return [
'=' => ['material_budget_id', 'project_id', 'material_id', 'budget_type'],
/** ];
* @notes 获取材料预算明细列表 }
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException /**
* @throws \think\db\exception\ModelNotFoundException * @notes 获取材料预算明细列表
* @author likeadmin * @return array
* @date 2024/01/08 21:52 * @throws \think\db\exception\DataNotFoundException
*/ * @throws \think\db\exception\DbException
public function lists(): array * @throws \think\db\exception\ModelNotFoundException
{ * @author likeadmin
return ProjectMaterialBudgetDetail::where($this->searchWhere) * @date 2024/01/08 21:52
->field(['id', 'material_budget_id', 'material_id', 'budget_type', 'price', 'num', 'amount', 'remark']) */
->limit($this->limitOffset, $this->limitLength) public function lists(): array
->order(['id' => 'desc']) {
->select() return ProjectMaterialBudgetDetail::where($this->searchWhere)
->toArray(); ->field('id,project_id,material_budget_id,material_id,budget_type,price,num,amount,remark')
} ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){
/** $material_budget = ProjectMaterialBudget::field('material_budget_code')->where('id',$data['material_budget_id'])->findOrEmpty();
* @notes 获取材料预算明细数量 $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
* @return int $material = Material::field('first_level,second_level,three_level,name,code,specs,brand,parameter_description,unit')->where('id',$data['material_id'])->findOrEmpty();
* @author likeadmin $material_classify = MaterialClassify::where('id','in',[$material['first_level'],$material['second_level'],$material['three_level']])->column('name','id');
* @date 2024/01/08 21:52 $data['budget_type'] = $data->budget_type_text;
*/ $data['material_budget_code'] = $material_budget['material_budget_code'];
public function count(): int $data['project_name'] = $project['name'];
{ $data['project_code'] = $project['project_code'];
return ProjectMaterialBudgetDetail::where($this->searchWhere)->count(); $data['material_first_level'] = $material_classify[$material['first_level']];
} $data['material_second_level'] = !empty($material_classify[$material['second_level']]) ? $material_classify[$material['second_level']] : '';
$data['material_three_level'] = !empty($material_classify[$material['three_level']]) ? $material_classify[$material['three_level']] : '';
$data['material_name'] = $material['name'];
$data['material_code'] = $material['code'];
$data['material_specs'] = $material['specs'];
$data['material_brand'] = $material['brand'];
$data['material_parameter_description'] = $material['parameter_description'];
$data['material_unit'] = $material['unit'];
//申购数量
$data['apply_num'] = 0;
//剩余预算数量
$data['residual_num'] = $data['num'] - $data['apply_num'];
return $data;
})
->toArray();
}
/**
* @notes 获取材料预算明细数量
* @return int
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function count(): int
{
return ProjectMaterialBudgetDetail::where($this->searchWhere)->count();
}
} }

View File

@ -1,77 +1,93 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版 // | likeadmin快速开发前后端分离管理后台PHP版
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力 // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo // | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin // | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin // | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn // | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权 // | likeadmin团队 版权所有 拥有最终解释权
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | author: likeadminTeam // | author: likeadminTeam
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\adminapi\lists\project; namespace app\adminapi\lists\project;
use app\adminapi\lists\BaseAdminDataLists; use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\project\ProjectMaterialBudget; use app\common\model\project\Project;
use app\common\lists\ListsSearchInterface; use app\common\model\project\ProjectMaterialBudget;
use app\common\lists\ListsSearchInterface;
use app\common\model\project\ProjectMaterialBudgetDetail;
/**
* 材料预算列表
* Class ProjectMaterialBudgetLists /**
* @package app\adminapi\listsproject * 材料预算列表
*/ * Class ProjectMaterialBudgetLists
class ProjectMaterialBudgetLists extends BaseAdminDataLists implements ListsSearchInterface * @package app\adminapi\listsproject
{ */
class ProjectMaterialBudgetLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][] /**
* @author likeadmin * @notes 设置搜索条件
* @date 2024/01/08 16:30 * @return \string[][]
*/ * @author likeadmin
public function setSearch(): array * @date 2024/01/08 16:30
{ */
return [ public function setSearch(): array
'=' => ['project_id', 'material_id', 'budget_type'], {
]; return [
} '=' => ['project_id', 'material_id', 'budget_type'],
];
/** }
* @notes 获取材料预算列表
* @return array
* @throws \think\db\exception\DataNotFoundException /**
* @throws \think\db\exception\DbException * @notes 获取材料预算列表
* @throws \think\db\exception\ModelNotFoundException * @return array
* @author likeadmin * @throws \think\db\exception\DataNotFoundException
* @date 2024/01/08 16:30 * @throws \think\db\exception\DbException
*/ * @throws \think\db\exception\ModelNotFoundException
public function lists(): array * @author likeadmin
{ * @date 2024/01/08 16:30
return ProjectMaterialBudget::where($this->searchWhere) */
->field(['id', 'project_id', 'material_id', 'budget_type', 'num', 'price', 'amount', 'remark']) public function lists(): array
->limit($this->limitOffset, $this->limitLength) {
->order(['id' => 'desc']) return ProjectMaterialBudget::where($this->searchWhere)
->select() ->field('id,project_id,material_budget_code,remark,annex')
->toArray(); ->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'];
* @notes 获取材料预算数量 $data['project_code'] = $project['project_code'];
* @return int //预算总数量
* @author likeadmin $data['total_num'] = ProjectMaterialBudgetDetail::where('material_budget_id',$data['id'])->sum('num');
* @date 2024/01/08 16:30 //预算总金额
*/ $data['total_amount'] = ProjectMaterialBudgetDetail::where('material_budget_id',$data['id'])->sum('amount');
public function count(): int //申购总数量
{ $data['total_apply_num'] = 0;
return ProjectMaterialBudget::where($this->searchWhere)->count(); //剩余预算总数量
} $data['total_residual_num'] = $data['total_num'] - $data['total_apply_num'];
return $data;
})
->toArray();
}
/**
* @notes 获取材料预算数量
* @return int
* @author likeadmin
* @date 2024/01/08 16:30
*/
public function count(): int
{
return ProjectMaterialBudget::where($this->searchWhere)->count();
}
} }

View File

@ -15,6 +15,10 @@
namespace app\adminapi\logic\project; namespace app\adminapi\logic\project;
use app\common\model\material\Material;
use app\common\model\material\MaterialClassify;
use app\common\model\project\Project;
use app\common\model\project\ProjectMaterialBudget;
use app\common\model\project\ProjectMaterialBudgetDetail; use app\common\model\project\ProjectMaterialBudgetDetail;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use think\facade\Db; use think\facade\Db;
@ -38,18 +42,19 @@ class ProjectMaterialBudgetDetailLogic extends BaseLogic
*/ */
public static function add(array $params): bool public static function add(array $params): bool
{ {
$material_budget = ProjectMaterialBudget::field('project_id')->where('id',$params['material_budget_id'])->findOrEmpty();
Db::startTrans(); Db::startTrans();
try { try {
ProjectMaterialBudgetDetail::create([ ProjectMaterialBudgetDetail::create([
'project_id' => $material_budget['project_id'],
'material_budget_id' => $params['material_budget_id'], 'material_budget_id' => $params['material_budget_id'],
'material_id' => $params['material_id'], 'material_id' => $params['material_id'],
'budget_type' => $params['budget_type'], 'budget_type' => $params['budget_type'],
'price' => $params['price'], 'price' => $params['price'],
'num' => $params['num'], 'num' => $params['num'],
'amount' => $params['amount'], 'amount' => $params['price'] * $params['num'],
'remark' => $params['remark'], 'remark' => $params['remark'] ?? '',
]); ]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -69,18 +74,19 @@ class ProjectMaterialBudgetDetailLogic extends BaseLogic
*/ */
public static function edit(array $params): bool public static function edit(array $params): bool
{ {
$material_budget = ProjectMaterialBudget::field('project_id')->where('id',$params['material_budget_id'])->findOrEmpty();
Db::startTrans(); Db::startTrans();
try { try {
ProjectMaterialBudgetDetail::where('id', $params['id'])->update([ ProjectMaterialBudgetDetail::where('id', $params['id'])->update([
'material_budget_id' => $params['material_budget_id'], 'project_id' => $material_budget['project_id'],
'material_id' => $params['material_id'], 'material_budget_id' => $params['material_budget_id'],
'budget_type' => $params['budget_type'], 'material_id' => $params['material_id'],
'price' => $params['price'], 'budget_type' => $params['budget_type'],
'num' => $params['num'], 'price' => $params['price'],
'amount' => $params['amount'], 'num' => $params['num'],
'remark' => $params['remark'], 'amount' => $params['price'] * $params['num'],
'remark' => $params['remark'] ?? '',
]); ]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -113,6 +119,24 @@ class ProjectMaterialBudgetDetailLogic extends BaseLogic
*/ */
public static function detail($params): array public static function detail($params): array
{ {
return ProjectMaterialBudgetDetail::findOrEmpty($params['id'])->toArray(); $data = ProjectMaterialBudgetDetail::field('id,project_id,material_budget_id,material_id,budget_type,price,num,amount,remark')->findOrEmpty($params['id']);
$material_budget = ProjectMaterialBudget::field('material_budget_code')->where('id',$data['material_budget_id'])->findOrEmpty();
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$material = Material::field('first_level,second_level,three_level,name,code,specs,brand,parameter_description,unit')->where('id',$data['material_id'])->findOrEmpty();
$material_classify = MaterialClassify::where('id','in',[$material['first_level'],$material['second_level'],$material['three_level']])->column('name','id');
$data['budget_type_text'] = $data->budget_type_text;
$data['material_budget_code'] = $material_budget['material_budget_code'];
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['material_first_level'] = $material_classify[$material['first_level']];
$data['material_second_level'] = !empty($material_classify[$material['second_level']]) ? $material_classify[$material['second_level']] : '';
$data['material_three_level'] = !empty($material_classify[$material['three_level']]) ? $material_classify[$material['three_level']] : '';
$data['material_name'] = $material['name'];
$data['material_code'] = $material['code'];
$data['material_specs'] = $material['specs'];
$data['material_brand'] = $material['brand'];
$data['material_parameter_description'] = $material['parameter_description'];
$data['material_unit'] = $material['unit'];
return $data->toArray();
} }
} }

View File

@ -15,8 +15,12 @@
namespace app\adminapi\logic\project; 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\ProjectMaterialBudget; use app\common\model\project\ProjectMaterialBudget;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\project\ProjectMaterialBudgetDetail;
use think\facade\Db; use think\facade\Db;
@ -38,9 +42,10 @@ class ProjectMaterialBudgetLogic extends BaseLogic
*/ */
public static function add(array $params): bool public static function add(array $params): bool
{ {
$detail = json_decode($params['material_budget_detail'],true);
Db::startTrans(); Db::startTrans();
try { try {
ProjectMaterialBudget::create([ $project_material_budget = ProjectMaterialBudget::create([
'org_id' => $params['org_id'], 'org_id' => $params['org_id'],
'dept_id' => $params['dept_id'], 'dept_id' => $params['dept_id'],
'project_id' => $params['project_id'], 'project_id' => $params['project_id'],
@ -48,6 +53,19 @@ class ProjectMaterialBudgetLogic extends BaseLogic
'remark' => $params['remark'] ?? '', 'remark' => $params['remark'] ?? '',
'annex' => !empty($params['annex']) ? $params['annex'] : null, 'annex' => !empty($params['annex']) ? $params['annex'] : null,
]); ]);
foreach ($detail as $item)
{
ProjectMaterialBudgetDetail::create([
'project_id' => $params['project_id'],
'material_budget_id' => $project_material_budget->id,
'material_id' => $item['material_id'],
'budget_type' => 0,
'price' => $item['price'],
'num' => $item['num'],
'amount' => $item['price'] * $item['num'],
'remark' => $item['remark'] ?? '',
]);
}
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -67,15 +85,41 @@ class ProjectMaterialBudgetLogic extends BaseLogic
*/ */
public static function edit(array $params): bool public static function edit(array $params): bool
{ {
$detail = json_decode($params['material_budget_detail'],true);
Db::startTrans(); Db::startTrans();
try { try {
ProjectMaterialBudget::where('id', $params['id'])->update([ ProjectMaterialBudget::where('id', $params['id'])->update([
'org_id' => $params['org_id'], 'org_id' => $params['org_id'],
'dept_id' => $params['dept_id'], 'dept_id' => $params['dept_id'],
'project_id' => $params['project_id'], 'project_id' => $params['project_id'],
'remark' => $params['remark'] ?? '', 'remark' => $params['remark'] ?? '',
'annex' => !empty($params['annex']) ? $params['annex'] : null, 'annex' => !empty($params['annex']) ? $params['annex'] : null,
]); ]);
foreach ($detail as $item)
{
if(isset($item['id']) && $item['id'] != ''){
ProjectMaterialBudgetDetail::where('id',$item['id'])->update([
'project_id' => $params['project_id'],
'material_budget_id' => $params['id'],
'material_id' => $item['material_id'],
'price' => $item['price'],
'num' => $item['num'],
'amount' => $item['price'] * $item['num'],
'remark' => $item['remark'] ?? '',
]);
}else{
ProjectMaterialBudgetDetail::create([
'project_id' => $params['project_id'],
'material_budget_id' => $params['id'],
'material_id' => $item['material_id'],
'budget_type' => 0,
'price' => $item['price'],
'num' => $item['num'],
'amount' => $item['price'] * $item['num'],
'remark' => $item['remark'] ?? '',
]);
}
}
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -108,6 +152,14 @@ class ProjectMaterialBudgetLogic extends BaseLogic
*/ */
public static function detail($params): array public static function detail($params): array
{ {
return ProjectMaterialBudget::findOrEmpty($params['id'])->toArray(); $data = ProjectMaterialBudget::field('id,org_id,dept_id,project_id,material_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

@ -1,106 +1,136 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版 // | likeadmin快速开发前后端分离管理后台PHP版
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力 // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo // | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin // | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin // | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn // | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权 // | likeadmin团队 版权所有 拥有最终解释权
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | author: likeadminTeam // | author: likeadminTeam
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\adminapi\validate\project; namespace app\adminapi\validate\project;
use app\common\validate\BaseValidate; use app\common\model\dict\DictData;
use app\common\model\material\Material;
use app\common\model\project\ProjectMaterialBudget;
/** use app\common\validate\BaseValidate;
* 材料预算明细验证器
* Class ProjectMaterialBudgetDetailValidate
* @package app\adminapi\validate\project /**
*/ * 材料预算明细验证器
class ProjectMaterialBudgetDetailValidate extends BaseValidate * Class ProjectMaterialBudgetDetailValidate
{ * @package app\adminapi\validate\project
*/
/** class ProjectMaterialBudgetDetailValidate extends BaseValidate
* 设置校验规则 {
* @var string[]
*/ /**
protected $rule = [ * 设置校验规则
'id' => 'require', * @var string[]
'material_budget_id' => 'require', */
'material_id' => 'require', protected $rule = [
'budget_type' => 'require', 'id' => 'require',
'price' => 'require', 'material_budget_id' => 'require|checkMaterialBudget',
'num' => 'require', 'material_id' => 'require|checkMaterial',
'amount' => 'require', 'budget_type' => 'require|checkBudgetType',
]; 'price' => 'require|float|egt:0',
'num' => 'require|integer|gt:0',
];
/**
* 参数描述
* @var string[] /**
*/ * 参数描述
protected $field = [ * @var string[]
'id' => 'id', */
'material_budget_id' => '材料预算id', protected $message = [
'material_id' => '材料id', 'id.require' => '缺少必要参数',
'budget_type' => '预算类型', 'material_budget_id.require' => '请选择材料预算',
'price' => '材料单价', 'material_id.require' => '请选择材料',
'num' => '材料数量', 'budget_type.require' => '请选择类型',
'amount' => '金额', 'price.require' => '请填写单价',
]; 'price.float' => '单价值必须是数字',
'price.egt' => '单价值必须大于等于0',
'num.require' => '请填写数量',
/** 'num.integer' => '数量值必须时整数',
* @notes 添加场景 'num.gt' => '数量值必须大于0',
* @return ProjectMaterialBudgetDetailValidate ];
* @author likeadmin
* @date 2024/01/08 21:52
*/ /**
public function sceneAdd() * @notes 添加场景
{ * @return ProjectMaterialBudgetDetailValidate
return $this->only(['material_budget_id','material_id','budget_type','price','num','amount']); * @author likeadmin
} * @date 2024/01/08 21:52
*/
public function sceneAdd()
/** {
* @notes 编辑场景 return $this->remove('id',true);
* @return ProjectMaterialBudgetDetailValidate }
* @author likeadmin
* @date 2024/01/08 21:52
*/ /**
public function sceneEdit() * @notes 编辑场景
{ * @return ProjectMaterialBudgetDetailValidate
return $this->only(['id','material_budget_id','material_id','budget_type','price','num','amount']); * @author likeadmin
} * @date 2024/01/08 21:52
*/
public function sceneEdit()
/** {}
* @notes 删除场景
* @return ProjectMaterialBudgetDetailValidate
* @author likeadmin /**
* @date 2024/01/08 21:52 * @notes 删除场景
*/ * @return ProjectMaterialBudgetDetailValidate
public function sceneDelete() * @author likeadmin
{ * @date 2024/01/08 21:52
return $this->only(['id']); */
} public function sceneDelete()
{
return $this->only(['id']);
/** }
* @notes 详情场景
* @return ProjectMaterialBudgetDetailValidate
* @author likeadmin /**
* @date 2024/01/08 21:52 * @notes 详情场景
*/ * @return ProjectMaterialBudgetDetailValidate
public function sceneDetail() * @author likeadmin
{ * @date 2024/01/08 21:52
return $this->only(['id']); */
} public function sceneDetail()
{
return $this->only(['id']);
}
public function checkMaterialBudget($value): bool|string
{
$material_budget = ProjectMaterialBudget::where('id',$value)->findOrEmpty();
if($material_budget->isEmpty()){
return '材料预算信息不存在';
}
return true;
}
public function checkMaterial($value): bool|string
{
$material = Material::where('id',$value)->findOrEmpty();
if($material->isEmpty()){
return '材料信息不存在';
}
return true;
}
public function checkBudgetType($value): bool|string
{
$dict = DictData::where('type_value','budget_type')->column('value');
if(!in_array($value,$dict)){
return '类型值无效';
}
return true;
}
} }

View File

@ -18,6 +18,7 @@ use app\common\model\dept\Dept;
use app\common\model\dept\Orgs; use app\common\model\dept\Orgs;
use app\common\model\material\Material; use app\common\model\material\Material;
use app\common\model\project\Project; use app\common\model\project\Project;
use app\common\model\project\ProjectMaterialBudgetDetail;
use app\common\validate\BaseValidate; use app\common\validate\BaseValidate;
@ -44,6 +45,8 @@ class ProjectMaterialBudgetValidate extends BaseValidate
protected $message = [ protected $message = [
'id.require' => '缺少必要参数', 'id.require' => '缺少必要参数',
'org_id.require' => '请选择组织',
'dept_id.require' => '请选择部门',
'project_id.require' => '请选择项目', 'project_id.require' => '请选择项目',
'material_budget_detail.require' => '请填写材料预算清单' 'material_budget_detail.require' => '请填写材料预算清单'
]; ];
@ -146,6 +149,12 @@ class ProjectMaterialBudgetValidate extends BaseValidate
return '材料预算清单数据格式错误'; return '材料预算清单数据格式错误';
} }
foreach($detail as $v) { foreach($detail as $v) {
if(isset($v['id']) && $v['id'] != ''){
$data_detail = ProjectMaterialBudgetDetail::where('id',$v['id'])->findOrEmpty();
if($data_detail->isEmpty()){
return '材料预算明细信息不存在';
}
}
if(empty($v['material_id'])){ if(empty($v['material_id'])){
return '请选择材料'; return '请选择材料';
}else{ }else{

View File

@ -16,6 +16,7 @@ namespace app\common\model\project;
use app\common\model\BaseModel; use app\common\model\BaseModel;
use app\common\model\dict\DictData;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
@ -30,5 +31,8 @@ class ProjectMaterialBudgetDetail extends BaseModel
protected $name = 'project_material_budget_detail'; protected $name = 'project_material_budget_detail';
protected $deleteTime = 'delete_time'; protected $deleteTime = 'delete_time';
public function getBudgetTypeTextAttr($value,$data){
$dict = DictData::where('type_value','budget_type')->column('name','value');
return $dict[$data['budget_type']];
}
} }