146 lines
5.0 KiB
PHP
146 lines
5.0 KiB
PHP
<?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\Contract;
|
||
use app\common\model\contract\ContractNegotiation;
|
||
use app\common\model\custom\Custom;
|
||
use app\common\model\project\Project;
|
||
use app\common\model\project\ProjectSettlement;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 甲方结算逻辑
|
||
* Class ProjectSettlementLogic
|
||
* @package app\adminapi\logic\project
|
||
*/
|
||
class ProjectSettlementLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加甲方结算
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/29 10:22
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$res = ProjectSettlement::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\ProjectSettlement',
|
||
'app\adminapi\logic\project\ProjectSettlementLogic',
|
||
$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 10:22
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ProjectSettlement::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,
|
||
'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 10:22
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return ProjectSettlement::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取甲方结算详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/29 10:22
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = ProjectSettlement::field('id,settlement_code,project_id,contract_id,settlement_amount,settlement_date,remark,annex')->findOrEmpty($params['id'])->toArray();
|
||
$project = Project::field('custom_id,name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||
$contract = Contract::field('contract_name,contract_code,amount')->where('id',$data['contract_id'])->findOrEmpty();
|
||
$custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty();
|
||
$data['project_name'] = $project['name'];
|
||
$data['project_code'] = $project['project_code'];
|
||
$data['contract_name'] = $contract['contract_name'];
|
||
$data['contract_code'] = $contract['contract_code'];
|
||
$data['custom_name'] = $custom['name'];
|
||
//合同金额
|
||
$data['contract_amount'] = $contract['amount'];
|
||
//洽商金额
|
||
$data['negotiation_amount'] = ContractNegotiation::where('contract_id',$data['contract_id'])->sum('negotiation_amount');
|
||
//结算差异
|
||
$data['settlement_difference'] = bcsub(($data['contract_amount']+$data['negotiation_amount']),$data['settlement_amount']);
|
||
return $data;
|
||
}
|
||
} |