179 lines
7.5 KiB
PHP
179 lines
7.5 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\ProcurementContractChange;
|
||
use app\common\model\contract\ProcurementContractDetail;
|
||
use app\common\model\custom\Custom;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* ProcurementContractChange逻辑
|
||
* Class ProcurementContractChangeLogic
|
||
* @package app\adminapi\logic\contract
|
||
*/
|
||
class ProcurementContractChangeLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/12 15:31
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ProcurementContractChange::create([
|
||
'org_id' => $params['org_id'] ?? 0,
|
||
'dept_id' => $params['dept_id'] ?? 0,
|
||
'procurement_contract_id' => $params['procurement_contract_id'] ?? 0,
|
||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||
'project_id' => $params['project_id'] ?? 0,
|
||
'contract_no' => $params['contract_no'] ?? '',
|
||
'supplier_contract_no' => $params['supplier_contract_no'] ?? '',
|
||
'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_excluding_tax' => $params['amount_excluding_tax'] ?? 0,
|
||
'amount_daxie' => $params['amount_daxie'] ?? '',
|
||
'retention_money_rate' => $params['retention_money_rate'] ?? 0,
|
||
'retention_money' => $params['retention_money'] ?? 0,
|
||
'pay_plan' => empty($params['pay_plan']) ? [] : json_encode($params['pay_plan']),
|
||
'remark' => $params['remark'] ?? 0,
|
||
'annex' => $params['annex'] ?? 0,
|
||
]);
|
||
ProcurementContractDetail::where('procurement_contract_id', $params['procurement_contract_id'])->update(['delete_time' =>time()]);
|
||
foreach ($params['material'] ?? [] as $item)
|
||
{
|
||
ProcurementContractDetail::create([
|
||
'procurement_contract_id' => $params['procurement_contract_id'],
|
||
'material_procurement_application_id' => $item['material_procurement_application_id'] ?? 0,
|
||
'num' => $item['num'] ?? 0,
|
||
'unit_price_including_tax' => $item['unit_price_including_tax'] ?? 0,
|
||
'tax_rate' => $item['tax_rate'] ?? 0,
|
||
'amount_excluding_tax' => $item['amount_excluding_tax'] ?? 0,
|
||
'amount_including_tax' => $item['amount_including_tax'] ?? 0,
|
||
]);
|
||
}
|
||
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 15:31
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ProcurementContractChange::where('id', $params['id'])->update([
|
||
'org_id' => $params['org_id'] ?? 0,
|
||
'dept_id' => $params['dept_id'] ?? 0,
|
||
'procurement_contract_id' => $params['procurement_contract_id'] ?? 0,
|
||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||
'approve_id' => $params['approve_id'] ?? 0,
|
||
'contract_no' => $params['contract_no'] ?? '',
|
||
'supplier_contract_no' => $params['supplier_contract_no'] ?? '',
|
||
'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_excluding_tax' => $params['amount_excluding_tax'] ?? 0,
|
||
'amount_daxie' => $params['amount_daxie'] ?? '',
|
||
'retention_money_rate' => $params['retention_money_rate'] ?? 0,
|
||
'retention_money' => $params['retention_money'] ?? 0,
|
||
'pay_plan' => empty($params['pay_plan']) ? [] : json_encode($params['pay_plan']),
|
||
'remark' => $params['remark'] ?? 0,
|
||
'annex' => $params['annex'] ?? 0,
|
||
]);
|
||
ProcurementContractDetail::where('procurement_contract_id', $params['procurement_contract_id'])->update(['delete_time' =>time()]);
|
||
foreach ($params['material'] ?? [] as $item)
|
||
{
|
||
ProcurementContractDetail::create([
|
||
'procurement_contract_id' =>$params['procurement_contract_id'],
|
||
'material_procurement_application_id' => $item['material_procurement_application_id'] ?? 0,
|
||
'num' => $item['num'] ?? 0,
|
||
'unit_price_including_tax' => $item['unit_price_including_tax'] ?? 0,
|
||
'tax_rate' => $item['tax_rate'] ?? 0,
|
||
'amount_excluding_tax' => $item['amount_excluding_tax'] ?? 0,
|
||
'amount_including_tax' => $item['amount_including_tax'] ?? 0,
|
||
]);
|
||
}
|
||
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 15:31
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return ProcurementContractChange::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/12 15:31
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$procurementContractChange = ProcurementContractChange::findOrEmpty($params['id']);
|
||
$procurementContractChange->contract;
|
||
$procurementContractChange->project= null;
|
||
if (!empty($procurementContractChange->contract->project_id)) {
|
||
$procurementContractChange->project = $procurementContractChange->contract->project;
|
||
unset($procurementContractChange->contract->project);
|
||
}
|
||
$procurementContractChange->pay_plan = json_decode($procurementContractChange->pay_plan, true);
|
||
$procurementContractChange->material;
|
||
$procurementContractChange->org;
|
||
$procurementContractChange->dept;
|
||
return $procurementContractChange->toArray();
|
||
}
|
||
} |