179 lines
7.4 KiB
PHP
179 lines
7.4 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\contract;
|
||
|
||
|
||
use app\common\model\contract\SubcontractingContract;
|
||
use app\common\model\contract\ProcurementContract;
|
||
use app\common\model\contract\SubcontractingContractDetail;
|
||
use app\common\model\custom\Custom;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* SubcontractingContract逻辑
|
||
* Class SubcontractingContractLogic
|
||
* @package app\adminapi\logic\contract
|
||
*/
|
||
class SubcontractingContractLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/12 17:15
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$subcontractingContract = ProcurementContract::create([
|
||
'project_id' => $params['project_id'] ?? 0,
|
||
'approve_id' => $params['approve_id'] ?? 0,
|
||
'contract_cate' => 2,
|
||
'contract_no' => $params['contract_no'] ?? '',
|
||
'contract_name' => $params['contract_name'] ?? '',
|
||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||
'contract_type' => $params['contract_type'] ?? 0,
|
||
'signing_date' => strtotime($params['signing_date']),
|
||
'pay_type' => $params['pay_type'] ?? 0,
|
||
'account_period' => $params['account_period'] ?? 0,
|
||
'amount' => $params['amount'] ?? 0,
|
||
'amount_daxie' => $params['amount_daxie'] ?? '',
|
||
'tax_rate' => $params['tax_rate'] ?? 0,
|
||
'amount_excluding_tax' => $params['amount_excluding_tax'] ?? 0,
|
||
'retention_money_rate' => $params['retention_money_rate'] ?? '',
|
||
'retention_money' => $params['retention_money'] ?? 0,
|
||
'pay_plan' => empty($params['pay_plan']) ? [] : json_encode($params['pay_plan']),
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex'] ?? '',
|
||
]);
|
||
SubcontractingContractDetail::where('subcontracting_contract_id', $subcontractingContract->id)->update(['delete_time' =>time()]);
|
||
foreach ($params['work'] ?? [] as $item)
|
||
{
|
||
SubcontractingContractDetail::create([
|
||
'subcontracting_contract_id' => $subcontractingContract->id,
|
||
'subcontracting_budget_id' => $item['subcontracting_budget_id'] ?? 0,
|
||
'workload' => $item['workload'] ?? '',
|
||
'unit_price_including_tax' => $item['unit_price_including_tax'] ?? 0,
|
||
'amount_excluding_tax' => $item['amount_excluding_tax'] ?? 0,
|
||
'amount_including_tax' => $item['amount_including_tax'] ?? 0,
|
||
'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 2023/12/12 17:15
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ProcurementContract::where('id', $params['id'])->update([
|
||
'project_id' => $params['project_id'] ?? 0,
|
||
'approve_id' => $params['approve_id'] ?? 0,
|
||
'contract_cate' => 2,
|
||
'contract_no' => $params['contract_no'] ?? '',
|
||
'contract_name' => $params['contract_name'] ?? '',
|
||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||
'contract_type' => $params['contract_type'] ?? 0,
|
||
'signing_date' => strtotime($params['signing_date']),
|
||
'pay_type' => $params['pay_type'] ?? 0,
|
||
'account_period' => $params['account_period'] ?? 0,
|
||
'amount' => $params['amount'] ?? 0,
|
||
'amount_daxie' => $params['amount_daxie'] ?? '',
|
||
'tax_rate' => $params['tax_rate'] ?? 0,
|
||
'amount_excluding_tax' => $params['amount_excluding_tax'] ?? 0,
|
||
'retention_money_rate' => $params['retention_money_rate'] ?? '',
|
||
'retention_money' => $params['retention_money'] ?? 0,
|
||
'pay_plan' => empty($params['pay_plan']) ? [] : json_encode($params['pay_plan']),
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex'] ?? '',
|
||
]);
|
||
SubcontractingContractDetail::where('subcontracting_contract_id', $params['id'])->update(['delete_time' =>time()]);
|
||
foreach ($params['work'] ?? [] as $item)
|
||
{
|
||
SubcontractingContractDetail::create([
|
||
'subcontracting_contract_id' => $params['id'],
|
||
'subcontracting_budget_id' => $item['subcontracting_budget_id'] ?? 0,
|
||
'workload' => $item['workload'] ?? '',
|
||
'unit_price_including_tax' => $item['unit_price_including_tax'] ?? 0,
|
||
'amount_excluding_tax' => $item['amount_excluding_tax'] ?? 0,
|
||
'amount_including_tax' => $item['amount_including_tax'] ?? 0,
|
||
'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 2023/12/12 17:15
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
SubcontractingContractDetail::where('subcontracting_contract_id', $params['id'])->update(['delete_time' =>time()]);
|
||
return ProcurementContract::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/12 17:15
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$subcontractingContract = ProcurementContract::findOrEmpty($params['id']);
|
||
$subcontractingContract->supplier = null;
|
||
$subcontractingContract->custom = null;
|
||
if (!empty($subcontractingContract->project->custom_id)) {
|
||
$subcontractingContract->custom = Custom::findOrEmpty($subcontractingContract->project->custom_id);
|
||
}
|
||
$subcontractingContract->pay_plan = json_decode($subcontractingContract->pay_plan, true);
|
||
$subcontractingContract->project;
|
||
$subcontractingContract->work;
|
||
return $subcontractingContract->toArray();
|
||
}
|
||
} |