Merge pull request 'add project_cost_budget' (#182) from zhangwei into dev
Reviewed-on: #182
This commit is contained in:
commit
ade97f7eeb
108
app/adminapi/controller/project/ProjectCostBudgetController.php
Normal file
108
app/adminapi/controller/project/ProjectCostBudgetController.php
Normal 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\ProjectCostBudgetLists;
|
||||
use app\adminapi\logic\project\ProjectCostBudgetLogic;
|
||||
use app\adminapi\validate\project\ProjectCostBudgetValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 费用预算控制器
|
||||
* Class ProjectCostBudgetController
|
||||
* @package app\adminapi\controller\project
|
||||
*/
|
||||
class ProjectCostBudgetController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取费用预算列表
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ProjectCostBudgetLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加费用预算
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ProjectCostBudgetValidate())->post()->goCheck('add');
|
||||
$result = ProjectCostBudgetLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectCostBudgetLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑费用预算
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ProjectCostBudgetValidate())->post()->goCheck('edit');
|
||||
$result = ProjectCostBudgetLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectCostBudgetLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除费用预算
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ProjectCostBudgetValidate())->post()->goCheck('delete');
|
||||
ProjectCostBudgetLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取费用预算详情
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ProjectCostBudgetValidate())->goCheck('detail');
|
||||
$result = ProjectCostBudgetLogic::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\ProjectCostBudgetDetailLists;
|
||||
use app\adminapi\logic\project\ProjectCostBudgetDetailLogic;
|
||||
use app\adminapi\validate\project\ProjectCostBudgetDetailValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 费用预算明细控制器
|
||||
* Class ProjectCostBudgetDetailController
|
||||
* @package app\adminapi\controller\project
|
||||
*/
|
||||
class ProjectCostBudgetDetailController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取费用预算明细列表
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ProjectCostBudgetDetailLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加费用预算明细
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ProjectCostBudgetDetailValidate())->post()->goCheck('add');
|
||||
$result = ProjectCostBudgetDetailLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectCostBudgetDetailLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑费用预算明细
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ProjectCostBudgetDetailValidate())->post()->goCheck('edit');
|
||||
$result = ProjectCostBudgetDetailLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectCostBudgetDetailLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除费用预算明细
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ProjectCostBudgetDetailValidate())->post()->goCheck('delete');
|
||||
ProjectCostBudgetDetailLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取费用预算明细详情
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ProjectCostBudgetDetailValidate())->goCheck('detail');
|
||||
$result = ProjectCostBudgetDetailLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
93
app/adminapi/lists/project/ProjectCostBudgetDetailLists.php
Normal file
93
app/adminapi/lists/project/ProjectCostBudgetDetailLists.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?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\ProjectCostBudget;
|
||||
use app\common\model\project\ProjectCostBudgetDetail;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\project\ProjectCostTempSet;
|
||||
|
||||
|
||||
/**
|
||||
* 费用预算明细列表
|
||||
* Class ProjectCostBudgetDetailLists
|
||||
* @package app\adminapi\listsproject
|
||||
*/
|
||||
class ProjectCostBudgetDetailLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['project_id', 'cost_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/16 14:32
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return ProjectCostBudgetDetail::where($this->searchWhere)
|
||||
->field('id,project_id,cost_budget_id,project_cost_temp_id,unit,amount,standard,remark')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($data){
|
||||
$cost_budget = ProjectCostBudget::field('cost_budget_code')->where('id',$data['cost_budget_id'])->findOrEmpty();
|
||||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||||
$project_cost_temp = ProjectCostTempSet::field('first_level_subject,second_level_subject,third_level_subject,is_travel')->where('id',$data['project_cost_temp_id'])->findOrEmpty();
|
||||
$data['cost_budget_code'] = $cost_budget['cost_budget_code'];
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
$data['first_level_subject'] = $project_cost_temp['first_level_subject'];
|
||||
$data['second_level_subject'] = $project_cost_temp['second_level_subject'];
|
||||
$data['third_level_subject'] = $project_cost_temp['third_level_subject'];
|
||||
$data['is_travel'] = $project_cost_temp['is_travel'];
|
||||
$data['is_travel_text'] = $project_cost_temp->is_travel_text;
|
||||
return $data;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取费用预算明细数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return ProjectCostBudgetDetail::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
87
app/adminapi/lists/project/ProjectCostBudgetLists.php
Normal file
87
app/adminapi/lists/project/ProjectCostBudgetLists.php
Normal 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\ProjectCostBudget;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\project\ProjectCostBudgetDetail;
|
||||
|
||||
|
||||
/**
|
||||
* 费用预算列表
|
||||
* Class ProjectCostBudgetLists
|
||||
* @package app\adminapi\listsproject
|
||||
*/
|
||||
class ProjectCostBudgetLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['project_id'],
|
||||
'%like%' => ['cost_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 14:32
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return ProjectCostBudget::where($this->searchWhere)
|
||||
->field('id,org_id,dept_id,project_id,cost_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_amount'] = ProjectCostBudgetDetail::where('cost_budget_id',$data['id'])->sum('amount');
|
||||
return $data;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取费用预算数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return ProjectCostBudget::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
@ -42,7 +42,6 @@ class ProjectEquipmentBudgetLists extends BaseAdminDataLists implements ListsSea
|
||||
return [
|
||||
'=' => ['project_id'],
|
||||
'%like%' => ['equipment_budget_code'],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
134
app/adminapi/logic/project/ProjectCostBudgetDetailLogic.php
Normal file
134
app/adminapi/logic/project/ProjectCostBudgetDetailLogic.php
Normal file
@ -0,0 +1,134 @@
|
||||
<?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\ProjectCostBudget;
|
||||
use app\common\model\project\ProjectCostBudgetDetail;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\project\ProjectCostTempSet;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 费用预算明细逻辑
|
||||
* Class ProjectCostBudgetDetailLogic
|
||||
* @package app\adminapi\logic\project
|
||||
*/
|
||||
class ProjectCostBudgetDetailLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加费用预算明细
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
$cost_budget = ProjectCostBudget::field('project_id')->where('id',$params['cost_budget_id'])->findOrEmpty();
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProjectCostBudgetDetail::create([
|
||||
'project_id' => $cost_budget['project_id'],
|
||||
'cost_budget_id' => $params['cost_budget_id'],
|
||||
'project_cost_temp_id' => $params['project_cost_temp_id'],
|
||||
'unit' => $params['unit'],
|
||||
'amount' => $params['amount'],
|
||||
'standard' => $params['standard'] ?? '',
|
||||
'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 14:32
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
$cost_budget = ProjectCostBudget::field('project_id')->where('id',$params['cost_budget_id'])->findOrEmpty();
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProjectCostBudgetDetail::where('id', $params['id'])->update([
|
||||
'project_id' => $cost_budget['project_id'],
|
||||
'cost_budget_id' => $params['cost_budget_id'],
|
||||
'project_cost_temp_id' => $params['project_cost_temp_id'],
|
||||
'unit' => $params['unit'],
|
||||
'amount' => $params['amount'],
|
||||
'standard' => $params['standard'] ?? '',
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'update_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 2024/01/16 14:32
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ProjectCostBudgetDetail::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取费用预算明细详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$data = ProjectCostBudgetDetail::field('id,project_id,cost_budget_id,project_cost_temp_id,unit,amount,standard,remark')->findOrEmpty($params['id']);
|
||||
$cost_budget = ProjectCostBudget::field('cost_budget_code')->where('id',$data['cost_budget_id'])->findOrEmpty();
|
||||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||||
$project_cost_temp = ProjectCostTempSet::field('first_level_subject,second_level_subject,third_level_subject,is_travel')->where('id',$data['project_cost_temp_id'])->findOrEmpty();
|
||||
$data['cost_budget_code'] = $cost_budget['cost_budget_code'];
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
$data['first_level_subject'] = $project_cost_temp['first_level_subject'];
|
||||
$data['second_level_subject'] = $project_cost_temp['second_level_subject'];
|
||||
$data['third_level_subject'] = $project_cost_temp['third_level_subject'];
|
||||
$data['is_travel'] = $project_cost_temp['is_travel'];
|
||||
$data['is_travel_text'] = $project_cost_temp->is_travel_text;
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
162
app/adminapi/logic/project/ProjectCostBudgetLogic.php
Normal file
162
app/adminapi/logic/project/ProjectCostBudgetLogic.php
Normal file
@ -0,0 +1,162 @@
|
||||
<?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\ProjectCostBudget;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\project\ProjectCostBudgetDetail;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 费用预算逻辑
|
||||
* Class ProjectCostBudgetLogic
|
||||
* @package app\adminapi\logic\project
|
||||
*/
|
||||
class ProjectCostBudgetLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加费用预算
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$res = ProjectCostBudget::create([
|
||||
'org_id' => $params['org_id'],
|
||||
'dept_id' => $params['dept_id'],
|
||||
'project_id' => $params['project_id'],
|
||||
'cost_budget_code' => data_unique_code('项目费用预算'),
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||||
]);
|
||||
foreach ($params['cost_budget_detail'] as $item)
|
||||
{
|
||||
ProjectCostBudgetDetail::create([
|
||||
'project_id' => $params['project_id'],
|
||||
'cost_budget_id' => $res->id,
|
||||
'project_cost_temp_id' => $item['project_cost_temp_id'],
|
||||
'unit' => $item['unit'],
|
||||
'amount' => $item['amount'],
|
||||
'standard' => $item['standard'] ?? '',
|
||||
'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 14:32
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProjectCostBudget::where('id', $params['id'])->update([
|
||||
'org_id' => $params['org_id'],
|
||||
'dept_id' => $params['dept_id'],
|
||||
'project_id' => $params['project_id'],
|
||||
'cost_budget_code' => data_unique_code('项目费用预算'),
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||||
]);
|
||||
foreach ($params['cost_budget_detail'] as $item)
|
||||
{
|
||||
if(isset($item['id']) && $item['id'] != ''){
|
||||
ProjectCostBudgetDetail::where('id',$item['id'])->update([
|
||||
'project_id' => $params['project_id'],
|
||||
'cost_budget_id' => $params['id'],
|
||||
'project_cost_temp_id' => $item['project_cost_temp_id'],
|
||||
'unit' => $item['unit'],
|
||||
'amount' => $item['amount'],
|
||||
'standard' => $item['standard'] ?? '',
|
||||
'remark' => $item['remark'] ?? '',
|
||||
]);
|
||||
}else{
|
||||
ProjectCostBudgetDetail::create([
|
||||
'project_id' => $params['project_id'],
|
||||
'cost_budget_id' => $params['id'],
|
||||
'project_cost_temp_id' => $item['project_cost_temp_id'],
|
||||
'unit' => $item['unit'],
|
||||
'amount' => $item['amount'],
|
||||
'standard' => $item['standard'] ?? '',
|
||||
'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 14:32
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ProjectCostBudget::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取费用预算详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$data = ProjectCostBudget::field('id,org_id,dept_id,project_id,cost_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,120 @@
|
||||
<?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\ProjectCostBudget;
|
||||
use app\common\model\project\ProjectCostTempSet;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 费用预算明细验证器
|
||||
* Class ProjectCostBudgetDetailValidate
|
||||
* @package app\adminapi\validate\project
|
||||
*/
|
||||
class ProjectCostBudgetDetailValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'cost_budget_id' => 'require|checkCostBudget',
|
||||
'project_cost_temp_id' => 'require|checkProjectCostTemp',
|
||||
'unit' => 'require',
|
||||
'amount' => 'require|float|gt:0',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'cost_budget_id' => '费用预算id',
|
||||
'project_cost_temp_id' => '项目费用模板id',
|
||||
'unit' => '单位',
|
||||
'amount' => '预算金额',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return ProjectCostBudgetDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id',true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return ProjectCostBudgetDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return ProjectCostBudgetDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return ProjectCostBudgetDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function checkCostBudget($value): bool|string
|
||||
{
|
||||
$data = ProjectCostBudget::where('id',$value)->findOrEmpty();
|
||||
if($data->isEmpty()){
|
||||
return '费用预算信息不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkProjectCostTemp($value): bool|string
|
||||
{
|
||||
$data = ProjectCostTempSet::where('id',$value)->findOrEmpty();
|
||||
if($data->isEmpty()){
|
||||
return '项目费用模板信息不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
175
app/adminapi/validate/project/ProjectCostBudgetValidate.php
Normal file
175
app/adminapi/validate/project/ProjectCostBudgetValidate.php
Normal file
@ -0,0 +1,175 @@
|
||||
<?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\ProjectCostBudgetDetail;
|
||||
use app\common\model\project\ProjectCostTempSet;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 费用预算验证器
|
||||
* Class ProjectCostBudgetValidate
|
||||
* @package app\adminapi\validate\project
|
||||
*/
|
||||
class ProjectCostBudgetValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'org_id' => 'require|checkOrg',
|
||||
'dept_id' => 'require|checkDept',
|
||||
'project_id' => 'require|checkProject',
|
||||
'annex' => 'checkAnnex',
|
||||
'cost_budget_detail' => 'require|checkCostBudgetDetail'
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '缺少必要参数',
|
||||
'org_id.require' => '请选择组织',
|
||||
'dept_id.require' => '请选择部门',
|
||||
'project_id.require' => '请选择项目',
|
||||
'cost_budget_detail.require' => '请填写费用预算清单'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return ProjectCostBudgetValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id',true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return ProjectCostBudgetValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return ProjectCostBudgetValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return ProjectCostBudgetValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 14:32
|
||||
*/
|
||||
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 checkCostBudgetDetail($value): bool|string
|
||||
{
|
||||
if(empty($value) || !is_array($value)){
|
||||
return '费用预算清单数据格式错误';
|
||||
}
|
||||
foreach($value as $v) {
|
||||
if(isset($v['id']) && $v['id'] != ''){
|
||||
$data = ProjectCostBudgetDetail::where('id',$v['id'])->findOrEmpty();
|
||||
if($data->isEmpty()){
|
||||
return '费用预算明细信息不存在';
|
||||
}
|
||||
}
|
||||
if(empty($v['project_cost_temp_id'])){
|
||||
return '科目模板不能为空';
|
||||
}else{
|
||||
$temp = ProjectCostTempSet::where('id',$v['project_cost_temp_id'])->findOrEmpty();
|
||||
if($temp->isEmpty()){
|
||||
return '科目模板不存在';
|
||||
}
|
||||
}
|
||||
if(empty($v['amount'])){
|
||||
return '预算金额不能为空';
|
||||
}else{
|
||||
if(!is_numeric($v['amount']) || $v['amount'] < 0){
|
||||
return '预算金额必须是大于0的数字';
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
36
app/common/model/project/ProjectCostBudget.php
Normal file
36
app/common/model/project/ProjectCostBudget.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 ProjectCostBudget
|
||||
* @package app\common\model\project
|
||||
*/
|
||||
class ProjectCostBudget extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'project_cost_budget';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
public function getAnnexAttr($value){
|
||||
return !empty($value) ? json_decode($value,true) : '';
|
||||
}
|
||||
}
|
34
app/common/model/project/ProjectCostBudgetDetail.php
Normal file
34
app/common/model/project/ProjectCostBudgetDetail.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 ProjectCostBudgetDetail
|
||||
* @package app\common\model\project
|
||||
*/
|
||||
class ProjectCostBudgetDetail extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'project_cost_budget_detail';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
@ -30,5 +30,9 @@ class ProjectCostTempSet extends BaseModel
|
||||
protected $name = 'project_cost_temp_set';
|
||||
|
||||
|
||||
|
||||
public function getIsTravelTextAttr($value,$data): string
|
||||
{
|
||||
$arr = [1=>'是', 2=>'否'];
|
||||
return $arr[$data['is_travel']];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user