engineering/app/adminapi/logic/project/ProjectCostBudgetLogic.php
2024-02-03 15:25:23 +08:00

172 lines
5.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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,$admin_id): 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'] ?? '',
]);
}
//添加审批信息
addApprove(
'项目费用预算',
$res->id,
'app\common\model\project\ProjectCostBudget',
'app\adminapi\logic\project\ProjectCostBudgetLogic',
$params['approve_detail']['flow_type'],
$params['approve_detail']['flow_path'],
$admin_id
);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑费用预算
* @param array $params
* @return bool
* @author likeadmin
* @date 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();
}
}