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

148 lines
5.5 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\contract\SubcontractingContract;
use app\common\model\contract\SubcontractingContractDetail;
use app\common\model\contract\SubcontractingContractNegotiation;
use app\common\model\project\Project;
use app\common\model\project\ProjectSubcontractSettlement;
use app\common\logic\BaseLogic;
use app\common\model\supplier\Supplier;
use think\facade\Db;
/**
* 分包结算逻辑
* Class ProjectSubcontractSettlementLogic
* @package app\adminapi\logic\project
*/
class ProjectSubcontractSettlementLogic extends BaseLogic
{
/**
* @notes 添加分包结算
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/29 13:59
*/
public static function add(array $params,$admin_id): bool
{
Db::startTrans();
try {
$res = ProjectSubcontractSettlement::create([
'settlement_code' => data_unique_code('分包结算'),
'project_id' => $params['project_id'],
'contract_id' => $params['contract_id'],
'settlement_amount' => $params['settlement_amount'],
'settlement_date' => strtotime($params['settlement_date']),
'remark' => $params['remark'],
'annex' => $params['annex']? json_encode($params['annex']) : null,
'add_user' => $admin_id,
]);
//添加审批信息
addApprove(
'分包结算',
$res->id,
'app\common\model\project\ProjectSubcontractSettlement',
'app\adminapi\logic\project\ProjectSubcontractSettlementLogic',
$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 2023/12/29 13:59
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ProjectSubcontractSettlement::where('id', $params['id'])->update([
'project_id' => $params['project_id'],
'contract_id' => $params['contract_id'],
'settlement_amount' => $params['settlement_amount'],
'settlement_date' => strtotime($params['settlement_date']),
'remark' => $params['remark'],
'annex' => $params['annex']? json_encode($params['annex']) : null,
'add_user' => $params['add_user'],
'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 2023/12/29 13:59
*/
public static function delete(array $params): bool
{
return ProjectSubcontractSettlement::destroy($params['id']);
}
/**
* @notes 获取分包结算详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/29 13:59
*/
public static function detail($params): array
{
$data = ProjectSubcontractSettlement::field('id,settlement_code,project_id,contract_id,settlement_amount,settlement_date,remark,annex')->findOrEmpty($params['id'])->toArray();
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$contract = SubcontractingContract::field('supplier_id,contract_no,contract_name')->where('id',$data['contract_id'])->findOrEmpty();
$supplier = Supplier::field('supplier_code,supplier_name')->where('id',$contract['supplier_id'])->findOrEmpty();
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['contract_name'] = $contract['contract_name'];
$data['contract_code'] = $contract['contract_no'];
$data['supplier_name'] = $supplier['supplier_name'];
$data['supplier_code'] = $supplier['supplier_code'];
//合同金额
$data['contract_amount'] = SubcontractingContractDetail::where('contract_id',$data['contract_id'])->sum('amount_including_tax');
//合同洽商金额
$data['negotiation_amount'] = SubcontractingContractNegotiation::where('contract_id',$data['contract_id'])->sum('negotiation_amount');
//结算差异
$data['settlement_difference'] = bcsub(($data['contract_amount']+$data['negotiation_amount']),$data['settlement_amount']);
return $data;
}
}