144 lines
6.2 KiB
PHP
144 lines
6.2 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\SubcontractingContractNegotiation;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\project\Project;
|
||
use app\common\model\supplier\Supplier;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* SubcontractingContractNegotiation逻辑
|
||
* Class SubcontractingContractNegotiationLogic
|
||
* @package app\adminapi\logic\contract
|
||
*/
|
||
class SubcontractingContractNegotiationLogic extends BaseLogic
|
||
{
|
||
|
||
/**
|
||
* @notes 添加
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/12 17:21
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
$subcontracting_contract = SubcontractingContract::field('project_id')->where('id',$params['subcontracting_contract_id'])->findOrEmpty();
|
||
Db::startTrans();
|
||
try {
|
||
SubcontractingContractNegotiation::create([
|
||
'project_id' => $subcontracting_contract['project_id'],
|
||
'subcontracting_contract_id' => $params['subcontracting_contract_id'],
|
||
'sign_date' => strtotime($params['sign_date']),
|
||
'negotiation_name' => $params['negotiation_name'],
|
||
'negotiation_no' => data_unique_code('QS-FBHT'),
|
||
'negotiation_amount' => $params['negotiation_amount'],
|
||
'negotiation_type' => $params['negotiation_type'],
|
||
'warranty_amount' => $params['warranty_amount'] ?? 0,
|
||
'warranty_expire_date' => !empty($params['Warranty_expire_date']) ? strtotime($params['Warranty_expire_date']) : 0,
|
||
'negotiation_content' => $params['negotiation_content'] ?? '',
|
||
'negotiation_detail' => $params['negotiation_detail'] ?? '',
|
||
'negotiation_quotation' => $params['negotiation_quotation'] ? json_encode($params['negotiation_quotation']) : null,
|
||
'negotiation_basis' => $params['negotiation_basis'] ? json_encode($params['negotiation_basis']) : 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/12 17:21
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
$subcontracting_contract = SubcontractingContract::field('project_id')->where('id',$params['subcontracting_contract_id'])->findOrEmpty();
|
||
Db::startTrans();
|
||
try {
|
||
SubcontractingContractNegotiation::where('id', $params['id'])->update([
|
||
'project_id' => $subcontracting_contract['project_id'],
|
||
'subcontracting_contract_id' => $params['subcontracting_contract_id'],
|
||
'sign_date' => strtotime($params['sign_date']),
|
||
'negotiation_name' => $params['negotiation_name'],
|
||
'negotiation_amount' => $params['negotiation_amount'],
|
||
'negotiation_type' => $params['negotiation_type'],
|
||
'warranty_amount' => $params['warranty_amount'] ?? 0,
|
||
'warranty_expire_date' => !empty($params['Warranty_expire_date']) ? strtotime($params['Warranty_expire_date']) : 0,
|
||
'negotiation_content' => $params['negotiation_content'] ?? '',
|
||
'negotiation_detail' => $params['negotiation_detail'] ?? '',
|
||
'negotiation_quotation' => $params['negotiation_quotation'] ? json_encode($params['negotiation_quotation']) : null,
|
||
'negotiation_basis' => $params['negotiation_basis'] ? json_encode($params['negotiation_basis']) : 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/12 17:21
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return SubcontractingContractNegotiation::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/12 17:21
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = SubcontractingContractNegotiation::field('id,project_id,subcontracting_contract_id,negotiation_name,negotiation_no,negotiation_amount,negotiation_type,sign_date,warranty_amount,warranty_expire_date,negotiation_content,negotiation_detail,negotiation_quotation,negotiation_basis')
|
||
->findOrEmpty($params['id']);
|
||
$subcontracting_contract = SubcontractingContract::field('supplier_id,contract_no,contract_name')->where('id',$data['subcontracting_contract_id'])->findOrEmpty();
|
||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||
$supplier = Supplier::field('supplier_name,supplier_code')->where('id',$subcontracting_contract['supplier_id'])->findOrEmpty();
|
||
$data['contract_name'] = $subcontracting_contract['contract_name'];
|
||
$data['contract_no'] = $subcontracting_contract['contract_no'];
|
||
$data['supplier_name'] = $supplier['supplier_name'];
|
||
$data['supplier_code'] = $supplier['supplier_code'];
|
||
$data['project_code'] = $project['project_code'];
|
||
$data['project_name'] = $project['name'];
|
||
$data['negotiation_type_text'] = $data->negotiation_type_text;
|
||
return $data->toArray();
|
||
}
|
||
} |