228 lines
9.0 KiB
PHP
228 lines
9.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\contract;
|
||
|
||
|
||
use app\common\model\auth\Admin;
|
||
use app\common\model\bid\BidBuyBiddingDocument;
|
||
use app\common\model\contract\Contract;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\finance\FinanceReturnedMoney;
|
||
use app\common\model\finance\FinanceReturnedRecord;
|
||
use app\common\model\project\Project;
|
||
use app\common\model\custom\Custom;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 项目合同逻辑
|
||
* Class ContractLogic
|
||
* @package app\adminapi\logic\contract
|
||
*/
|
||
class ContractLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加项目合同
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/02 17:19
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
$buy_bidding_document = BidBuyBiddingDocument::field('project_id')->where('id',$params['buy_bidding_document_id'])->findOrEmpty();
|
||
$returned_money = $params['returned_money'];//json_decode($params['returned_money'],true);
|
||
Db::startTrans();
|
||
try {
|
||
$contractRes = Contract::create([
|
||
"org_id" => $params['org_id'],
|
||
"dept_id" =>$params['dept_id'],
|
||
"project_id" => $buy_bidding_document['project_id'],
|
||
"buy_bidding_document_id" => $params['buy_bidding_document_id'],
|
||
"contract_name" =>$params['contract_name'],
|
||
'contract_code' => data_unique_code('PHT'),
|
||
"contract_type" => $params['contract_type'],
|
||
"contract_pricing_method" => $params['contract_pricing_method'],
|
||
"party_a" => $params['party_a'],
|
||
"party_a_contact_address" => $params['party_a_contact_address'] ?? '',
|
||
"party_a_diretor" => $params['party_a_diretor'] ?? '',
|
||
"party_a_phone" => $params['party_a_phone'] ?? '',
|
||
"party_a_mobile" => $params['party_a_mobile'] ?? '',
|
||
"party_a_email" => $params['party_a_email'] ?? '',
|
||
"party_b" => $params['party_b'],
|
||
"party_b_contact_address" => $params['party_b_contact_address'] ?? '',
|
||
"party_b_diretor" => $params['party_b_diretor'] ?? '',
|
||
"party_b_phone" => $params['party_b_phone'] ?? '',
|
||
"party_b_mobile" => $params['party_b_mobile'] ?? '',
|
||
"party_b_email" => $params['party_b_email'] ?? '',
|
||
"amount" => $params['amount'],
|
||
"business_director" => $params['business_director'],
|
||
"contract_status" => $params['contract_status'],
|
||
"expire" => strtotime($params['expire']),
|
||
"contract_date" => strtotime($params['contract_date']),
|
||
"main_content" => $params['main_content'] ?? '',
|
||
"remark" => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
]);
|
||
foreach ($returned_money as $item)
|
||
{
|
||
FinanceReturnedMoney::create([
|
||
'project_id' => $buy_bidding_document['project_id'],
|
||
'contract_id' => $contractRes->id,
|
||
'return_date' => strtotime($item['return_date']),
|
||
'period' => $item['period'],
|
||
'amount' => $item['amount'],
|
||
'return_status' => 2,
|
||
'return_duty_id' => 0,
|
||
'remark' => $item['remark'] ?? '',
|
||
'annex' => null,
|
||
]);
|
||
}
|
||
Project::where('id',$buy_bidding_document['project_id'])->update([
|
||
'status' => 3,
|
||
'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/02 17:19
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
$buy_bidding_document = BidBuyBiddingDocument::field('project_id')->where('id',$params['buy_bidding_document_id'])->findOrEmpty();
|
||
$returned_money = $params['returned_money'];
|
||
Db::startTrans();
|
||
try {
|
||
Contract::where('id', $params['id'])->update([
|
||
"org_id" => $params['org_id'],
|
||
"dept_id" =>$params['dept_id'],
|
||
"project_id" => $buy_bidding_document['project_id'],
|
||
"buy_bidding_document_id" => $params['buy_bidding_document_id'],
|
||
"contract_name" =>$params['contract_name'],
|
||
"contract_type" => $params['contract_type'],
|
||
"contract_pricing_method" => $params['contract_pricing_method'],
|
||
"party_a" => $params['party_a'],
|
||
"party_a_contact_address" => $params['party_a_contact_address'] ?? '',
|
||
"party_a_diretor" => $params['party_a_diretor'] ?? '',
|
||
"party_a_phone" => $params['party_a_phone'] ?? '',
|
||
"party_a_mobile" => $params['party_a_mobile'] ?? '',
|
||
"party_a_email" => $params['party_a_email'] ?? '',
|
||
"party_b" => $params['party_b'],
|
||
"party_b_contact_address" => $params['party_b_contact_address'] ?? '',
|
||
"party_b_diretor" => $params['party_b_diretor'] ?? '',
|
||
"party_b_phone" => $params['party_b_phone'] ?? '',
|
||
"party_b_mobile" => $params['party_b_mobile'] ?? '',
|
||
"party_b_email" => $params['party_b_email'] ?? '',
|
||
"amount" => $params['amount'],
|
||
"business_director" => $params['business_director'],
|
||
"contract_status" => $params['contract_status'],
|
||
"expire" => strtotime($params['expire']),
|
||
"contract_date" => strtotime($params['contract_date']),
|
||
"main_content" => $params['main_content'] ?? '',
|
||
"remark" => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
]);
|
||
foreach ($returned_money as $item)
|
||
{
|
||
if(isset($item['id']) && $item['id'] != ''){
|
||
FinanceReturnedMoney::where('id',$item['id'])->update([
|
||
'project_id' => $buy_bidding_document['project_id'],
|
||
'contract_id' => $params['id'],
|
||
'return_date' => strtotime($item['return_date']),
|
||
'period' => $item['period'],
|
||
'amount' => $item['amount'],
|
||
'return_status' => 2,
|
||
'return_duty_id' => 0,
|
||
'remark' => $item['remark'] ?? '',
|
||
'annex' => null,
|
||
]);
|
||
}else{
|
||
FinanceReturnedMoney::create([
|
||
'project_id' => $buy_bidding_document['project_id'],
|
||
'contract_id' => $params['id'],
|
||
'return_date' => strtotime($item['return_date']),
|
||
'period' => $item['period'],
|
||
'amount' => $item['amount'],
|
||
'return_status' => 2,
|
||
'return_duty_id' => 0,
|
||
'remark' => $item['remark'] ?? '',
|
||
'annex' => null,
|
||
]);
|
||
}
|
||
}
|
||
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/02 17:19
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return Contract::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取项目合同详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/02 17:19
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = Contract::findOrEmpty($params['id']);
|
||
$project = Project::field('custom_id,name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||
$custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty();
|
||
$buy_bidding_document = BidBuyBiddingDocument::field('bid_document_no')->where('id',$data['buy_bidding_document_id'])->findOrEmpty();
|
||
$business_director = Admin::field('name')->where('id',$data['business_director'])->findOrEmpty();
|
||
$data['custom_name'] = $custom['name'];
|
||
$data['bid_document_no'] = $buy_bidding_document['bid_document_no'];
|
||
$data['project_name'] = $project['name'];
|
||
$data['project_code'] = $project['project_code'];
|
||
$data['contract_type_text'] = $data->contract_type_text;
|
||
$data['contract_pricing_method_text'] = $data->contract_pricing_method_text;
|
||
$data['contract_status_text'] = $data->contract_status_text;
|
||
$data['contract_pricing_method_text'] = $data->contract_pricing_method_text;
|
||
$data['business_director_name'] = $business_director['name'];
|
||
$data['returned_amount'] = FinanceReturnedRecord::where('contract_id',$data['id'])->sum('amount');
|
||
return $data->toArray();
|
||
}
|
||
} |