engineering/app/adminapi/logic/project/ProjectSubpackageBudgetLogic.php
2024-02-19 17:49:52 +08:00

206 lines
7.1 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\oa\FlowApprove;
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,$admin_id): bool
{
$detail = $params['subpackage_budget_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' => $params['annex']? json_encode($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 =$params['subpackage_budget_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' => $params['annex']? json_encode($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,approve_id')->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'];
$approve_data = FlowApprove::where('id',$data['approve_id'])->findOrEmpty();
$data['approve_check_status'] = $approve_data['check_status'];
return $data->toArray();
}
public static function approve($params,$admin_id): bool{
$data = ProjectSubpackageBudget::where('id',$params['id'])->findOrEmpty();
$approve_data = FlowApprove::where('id',$data['approve_id'])->findOrEmpty();
if(!empty($data['approve_id']) && $approve_data['check_status'] != 3){
self::setError('当前内容存在审核信息,请勿重复提交');
return false;
}
Db::startTrans();
try {
$res = addApprove(
'分包预算',
$params['id'],
'app\common\model\project\ProjectSubpackageBudget',
$params['path'],
$params['flow_id'],
$admin_id
);
if($res){
ProjectSubpackageBudget::where('id',$params['id'])->update([
'approve_id' => $res,
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}