新增分包预算
This commit is contained in:
parent
9b061bf179
commit
a3212c907c
@ -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\ProjectSubpackageBudgetLists;
|
||||
use app\adminapi\logic\project\ProjectSubpackageBudgetLogic;
|
||||
use app\adminapi\validate\project\ProjectSubpackageBudgetValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 分包预算控制器
|
||||
* Class ProjectSubpackageBudgetController
|
||||
* @package app\adminapi\controller\project
|
||||
*/
|
||||
class ProjectSubpackageBudgetController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取分包预算列表
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ProjectSubpackageBudgetLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加分包预算
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ProjectSubpackageBudgetValidate())->post()->goCheck('add');
|
||||
$result = ProjectSubpackageBudgetLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectSubpackageBudgetLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑分包预算
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ProjectSubpackageBudgetValidate())->post()->goCheck('edit');
|
||||
$result = ProjectSubpackageBudgetLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectSubpackageBudgetLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除分包预算
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ProjectSubpackageBudgetValidate())->post()->goCheck('delete');
|
||||
ProjectSubpackageBudgetLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取分包预算详情
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ProjectSubpackageBudgetValidate())->goCheck('detail');
|
||||
$result = ProjectSubpackageBudgetLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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\ProjectSubpackageBudgetDetailLists;
|
||||
use app\adminapi\logic\project\ProjectSubpackageBudgetDetailLogic;
|
||||
use app\adminapi\validate\project\ProjectSubpackageBudgetDetailValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 分包预算明细控制器
|
||||
* Class ProjectSubpackageBudgetDetailController
|
||||
* @package app\adminapi\controller\project
|
||||
*/
|
||||
class ProjectSubpackageBudgetDetailController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取分包预算明细列表
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ProjectSubpackageBudgetDetailLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加分包预算明细
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ProjectSubpackageBudgetDetailValidate())->post()->goCheck('add');
|
||||
$result = ProjectSubpackageBudgetDetailLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectSubpackageBudgetDetailLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑分包预算明细
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ProjectSubpackageBudgetDetailValidate())->post()->goCheck('edit');
|
||||
$result = ProjectSubpackageBudgetDetailLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectSubpackageBudgetDetailLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除分包预算明细
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ProjectSubpackageBudgetDetailValidate())->post()->goCheck('delete');
|
||||
ProjectSubpackageBudgetDetailLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取分包预算明细详情
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ProjectSubpackageBudgetDetailValidate())->goCheck('detail');
|
||||
$result = ProjectSubpackageBudgetDetailLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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\ProjectSubpackageBudget;
|
||||
use app\common\model\project\ProjectSubpackageBudgetDetail;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* 分包预算明细列表
|
||||
* Class ProjectSubpackageBudgetDetailLists
|
||||
* @package app\adminapi\listsproject
|
||||
*/
|
||||
class ProjectSubpackageBudgetDetailLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['project_id', 'subpackage_budget_id'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取分包预算明细列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return ProjectSubpackageBudgetDetail::where($this->searchWhere)
|
||||
->field('id,project_id,subpackage_budget_id,work_type,work_content,project_features,unit,num,price,amount,remark')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($data){
|
||||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||||
$subpackage_budget = ProjectSubpackageBudget::field('subpackage_budget_code')->where('id',$data['subpackage_budget_id'])->findOrEmpty();
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
$data['subpackage_budget_code'] = $subpackage_budget['subpackage_budget_code'];
|
||||
//已分包工作量
|
||||
$data['has_subcontract_num'] = 0;
|
||||
//剩余工作量
|
||||
$data['residue_num'] = $data['num'] - $data['has_subcontract_num'];
|
||||
return $data;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取分包预算明细数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return ProjectSubpackageBudgetDetail::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
92
app/adminapi/lists/project/ProjectSubpackageBudgetLists.php
Normal file
92
app/adminapi/lists/project/ProjectSubpackageBudgetLists.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?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\ProjectSubpackageBudget;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\project\ProjectSubpackageBudgetDetail;
|
||||
|
||||
|
||||
/**
|
||||
* 分包预算列表
|
||||
* Class ProjectSubpackageBudgetLists
|
||||
* @package app\adminapi\listsproject
|
||||
*/
|
||||
class ProjectSubpackageBudgetLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['project_id'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取分包预算列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return ProjectSubpackageBudget::where($this->searchWhere)
|
||||
->field('id,project_id,subpackage_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'] = ProjectSubpackageBudgetDetail::where('subpackage_budget_id',$data['id'])->sum('num');
|
||||
//预算总金额
|
||||
$data['total_amount'] = ProjectSubpackageBudgetDetail::where('subpackage_budget_id',$data['id'])->sum('amount');
|
||||
//已分包工作量
|
||||
$data['has_subcontract_num'] = 0;
|
||||
//剩余工作量
|
||||
$data['residue_num'] = $data['total_num'] - $data['has_subcontract_num'];
|
||||
return $data;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取分包预算数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return ProjectSubpackageBudget::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
<?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\ProjectSubpackageBudget;
|
||||
use app\common\model\project\ProjectSubpackageBudgetDetail;
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 分包预算明细逻辑
|
||||
* Class ProjectSubpackageBudgetDetailLogic
|
||||
* @package app\adminapi\logic\project
|
||||
*/
|
||||
class ProjectSubpackageBudgetDetailLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加分包预算明细
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
$subpackage_budget = ProjectSubpackageBudget::where('id',$params['subpackage_budget_id'])->findOrEmpty();
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProjectSubpackageBudgetDetail::create([
|
||||
'project_id' => $subpackage_budget['project_id'],
|
||||
'subpackage_budget_id' => $params['subpackage_budget_id'],
|
||||
'work_type' => $params['work_type'],
|
||||
'work_content' => $params['work_content'],
|
||||
'project_features' => $params['project_features'] ?? '',
|
||||
'unit' => $params['unit'],
|
||||
'num' => $params['num'],
|
||||
'price' => $params['price'],
|
||||
'amount' => $params['num'] * $params['price'],
|
||||
'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/10 15:19
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
$subpackage_budget = ProjectSubpackageBudget::where('id',$params['subpackage_budget_id'])->findOrEmpty();
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProjectSubpackageBudgetDetail::where('id', $params['id'])->update([
|
||||
'project_id' => $subpackage_budget['project_id'],
|
||||
'subpackage_budget_id' => $params['subpackage_budget_id'],
|
||||
'work_type' => $params['work_type'],
|
||||
'work_content' => $params['work_content'],
|
||||
'project_features' => $params['project_features'] ?? '',
|
||||
'unit' => $params['unit'],
|
||||
'num' => $params['num'],
|
||||
'price' => $params['price'],
|
||||
'amount' => $params['num'] * $params['price'],
|
||||
'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/10 15:19
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ProjectSubpackageBudgetDetail::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取分包预算明细详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$data = ProjectSubpackageBudgetDetail::field('id,project_id,subpackage_budget_id,work_type,work_content,project_features,unit,num,price,amount,remark')
|
||||
->findOrEmpty($params['id']);
|
||||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||||
$subpackage_budget = ProjectSubpackageBudget::field('subpackage_budget_code')->where('id',$data['subpackage_budget_id'])->findOrEmpty();
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
$data['subpackage_budget_code'] = $subpackage_budget['subpackage_budget_code'];
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
173
app/adminapi/logic/project/ProjectSubpackageBudgetLogic.php
Normal file
173
app/adminapi/logic/project/ProjectSubpackageBudgetLogic.php
Normal file
@ -0,0 +1,173 @@
|
||||
<?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\ProjectSubpackageBudget;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\project\ProjectSubpackageBudgetDetail;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 分包预算逻辑
|
||||
* Class ProjectSubpackageBudgetLogic
|
||||
* @package app\adminapi\logic\project
|
||||
*/
|
||||
class ProjectSubpackageBudgetLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加分包预算
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
$detail = json_decode($params['subpackage_budget_detail'],true);
|
||||
Db::startTrans();
|
||||
try {
|
||||
$res = ProjectSubpackageBudget::create([
|
||||
'org_id' => $params['org_id'],
|
||||
'dept_id' => $params['dept_id'],
|
||||
'project_id' => $params['project_id'],
|
||||
'subpackage_budget_code' => data_unique_code('项目分包预算'),
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => !empty($params['annex']) ? $params['annex'] : null,
|
||||
]);
|
||||
foreach ($detail as $item)
|
||||
{
|
||||
ProjectSubpackageBudgetDetail::create([
|
||||
'project_id' => $params['project_id'],
|
||||
'subpackage_budget_id' => $res->id,
|
||||
'work_type' => $item['work_type'],
|
||||
'work_content' => $item['work_content'],
|
||||
'project_features' => $item['project_features'] ?? '',
|
||||
'unit' => $item['unit'],
|
||||
'num' => $item['num'],
|
||||
'price' => $item['price'],
|
||||
'amount' => $item['num'] * $item['price'],
|
||||
'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/10 15:19
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
$detail = json_decode($params['subpackage_budget_detail'],true);
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProjectSubpackageBudget::where('id', $params['id'])->update([
|
||||
'org_id' => $params['org_id'],
|
||||
'dept_id' => $params['dept_id'],
|
||||
'project_id' => $params['project_id'],
|
||||
'subpackage_budget_code' => data_unique_code('项目分包预算'),
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => !empty($params['annex']) ? $params['annex'] : null,
|
||||
]);
|
||||
foreach ($detail as $item)
|
||||
{
|
||||
if(isset($item['id']) && $item['id'] != ''){
|
||||
ProjectSubpackageBudgetDetail::where('id',$item['id'])->update([
|
||||
'project_id' => $params['project_id'],
|
||||
'subpackage_budget_id' => $params['id'],
|
||||
'work_type' => $item['work_type'],
|
||||
'work_content' => $item['work_content'],
|
||||
'project_features' => $item['project_features'] ?? '',
|
||||
'unit' => $item['unit'],
|
||||
'num' => $item['num'],
|
||||
'price' => $item['price'],
|
||||
'amount' => $item['num'] * $item['price'],
|
||||
'remark' => $item['remark'] ?? '',
|
||||
]);
|
||||
}else{
|
||||
ProjectSubpackageBudgetDetail::create([
|
||||
'project_id' => $params['project_id'],
|
||||
'subpackage_budget_id' => $params['id'],
|
||||
'work_type' => $item['work_type'],
|
||||
'work_content' => $item['work_content'],
|
||||
'project_features' => $item['project_features'] ?? '',
|
||||
'unit' => $item['unit'],
|
||||
'num' => $item['num'],
|
||||
'price' => $item['price'],
|
||||
'amount' => $item['num'] * $item['price'],
|
||||
'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/10 15:19
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ProjectSubpackageBudget::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取分包预算详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$data = ProjectSubpackageBudget::field('id,org_id,dept_id,project_id,subpackage_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();
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
<?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\ProjectSubpackageBudget;
|
||||
use app\common\model\project\ProjectSubpackageBudgetDetail;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 分包预算明细验证器
|
||||
* Class ProjectSubpackageBudgetDetailValidate
|
||||
* @package app\adminapi\validate\project
|
||||
*/
|
||||
class ProjectSubpackageBudgetDetailValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'subpackage_budget_id' => 'require|checkSubpackageBudget',
|
||||
'work_type' => 'require',
|
||||
'work_content' => 'require',
|
||||
'unit' => 'require',
|
||||
'num' => 'require|float|egt:0',
|
||||
'price' => 'require|float|egt:0',
|
||||
];
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'subpackage_budget_id' => '分包预算id',
|
||||
'work_type' => '工作类型',
|
||||
'work_content' => '工作内容',
|
||||
'unit' => '单位',
|
||||
'num' => '工作量',
|
||||
'price' => '单价',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return ProjectSubpackageBudgetDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id',true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return ProjectSubpackageBudgetDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return ProjectSubpackageBudgetDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return ProjectSubpackageBudgetDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function checkSubpackageBudget($value): bool|string
|
||||
{
|
||||
$data = ProjectSubpackageBudget::where('id',$value)->findOrEmpty();
|
||||
if($data->isEmpty()){
|
||||
return '分包预算信息不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,188 @@
|
||||
<?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\ProjectSubpackageBudgetDetail;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 分包预算验证器
|
||||
* Class ProjectSubpackageBudgetValidate
|
||||
* @package app\adminapi\validate\project
|
||||
*/
|
||||
class ProjectSubpackageBudgetValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'org_id' => 'require|checkOrg',
|
||||
'dept_id' => 'require|checkDept',
|
||||
'project_id' => 'require|checkProject',
|
||||
'annex' => 'checkAnnex',
|
||||
'subpackage_budget_detail' => 'require|checkSubpackageBudgetDetail'
|
||||
];
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'org_id' => '组织id',
|
||||
'dept_id' => '部门id',
|
||||
'project_id' => '项目id',
|
||||
'material_budget_detail' => '分包预算明细'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return ProjectSubpackageBudgetValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id',true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return ProjectSubpackageBudgetValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return ProjectSubpackageBudgetValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return ProjectSubpackageBudgetValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/10 15:19
|
||||
*/
|
||||
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 != ''){
|
||||
$annex = json_decode($value,true);
|
||||
if(empty($annex) || !is_array($annex)){
|
||||
return '附件格式错误';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkSubpackageBudgetDetail($value): bool|string
|
||||
{
|
||||
$detail = json_decode($value,true);
|
||||
if(empty($detail) || !is_array($detail)){
|
||||
return '分包预算明细数据格式错误';
|
||||
}
|
||||
foreach($detail as $v) {
|
||||
if(isset($v['id']) && $v['id'] != ''){
|
||||
$data_detail = ProjectSubpackageBudgetDetail::where('id',$v['id'])->findOrEmpty();
|
||||
if($data_detail->isEmpty()){
|
||||
return '分包预算明细信息不存在';
|
||||
}
|
||||
}
|
||||
if(empty($v['work_type'])){
|
||||
return '请填写工作类型';
|
||||
}
|
||||
if(empty($v['work_content'])){
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
36
app/common/model/project/ProjectSubpackageBudget.php
Normal file
36
app/common/model/project/ProjectSubpackageBudget.php
Normal 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 ProjectSubpackageBudget
|
||||
* @package app\common\model\project
|
||||
*/
|
||||
class ProjectSubpackageBudget extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'project_subpackage_budget';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
public function getAnnexAttr($value){
|
||||
return !empty($value) ? json_decode($value) : '';
|
||||
}
|
||||
}
|
34
app/common/model/project/ProjectSubpackageBudgetDetail.php
Normal file
34
app/common/model/project/ProjectSubpackageBudgetDetail.php
Normal 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 ProjectSubpackageBudgetDetail
|
||||
* @package app\common\model\project
|
||||
*/
|
||||
class ProjectSubpackageBudgetDetail extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'project_subpackage_budget_detail';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user