This commit is contained in:
weiz 2024-03-21 14:37:08 +08:00
parent 55d16cfdb5
commit 7430279c85
2 changed files with 216 additions and 211 deletions

View File

@ -12,26 +12,26 @@
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\contract;
namespace app\adminapi\logic\contract;
use app\common\model\auth\Admin;
use app\common\model\contract\Contract;
use app\common\model\contract\ContractNegotiation;
use app\common\logic\BaseLogic;
use app\common\model\custom\Custom;
use app\common\model\oa\FlowApprove;
use app\common\model\project\Project;
use think\facade\Db;
use app\common\logic\BaseLogic;
use app\common\model\auth\Admin;
use app\common\model\contract\Contract;
use app\common\model\contract\ContractNegotiation;
use app\common\model\custom\Custom;
use app\common\model\oa\FlowApprove;
use app\common\model\project\Project;
use think\facade\Db;
/**
/**
* 合同洽商逻辑
* Class ContractNegotiationLogic
* @package app\adminapi\logic\contract
*/
class ContractNegotiationLogic extends BaseLogic
{
class ContractNegotiationLogic extends BaseLogic
{
/**
@ -43,8 +43,8 @@ class ContractNegotiationLogic extends BaseLogic
*/
public static function add(array $params): bool
{
$contract = Contract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty();
$profit = $params['negotiation_amount'] - (($params['labor_costs']?:0) + ($params['material_costs']?:0));
$contract = Contract::field('project_id')->where('id', $params['contract_id'])->findOrEmpty();
$profit = $params['negotiation_amount'] - (($params['labor_costs'] ?: 0) + ($params['material_costs'] ?: 0));
$profit_rate = $profit / $params['negotiation_amount'];
Db::startTrans();
try {
@ -58,7 +58,7 @@ class ContractNegotiationLogic extends BaseLogic
'labor_costs' => $params['labor_costs'] ?? 0,
'material_costs' => $params['material_costs'] ?? 0,
'warranty_amount' => $params['warranty_amount'] ?? 0,
'warranty_expire_date' => !empty($params['Warranty_expire_date']) ? strtotime($params['Warranty_expire_date']) : 0,
'warranty_expire_date' => !empty($params['warranty_expire_date']) ? strtotime($params['warranty_expire_date']) : 0,
'profit' => $profit,
'profit_rate' => $profit_rate,
'negotiation_content' => $params['negotiation_content'] ?? '',
@ -85,8 +85,8 @@ class ContractNegotiationLogic extends BaseLogic
*/
public static function edit(array $params): bool
{
$contract = Contract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty();
$profit = $params['negotiation_amount'] - (($params['labor_costs']??0) + ($params['material_costs']??0));
$contract = Contract::field('project_id')->where('id', $params['contract_id'])->findOrEmpty();
$profit = $params['negotiation_amount'] - (($params['labor_costs'] ?? 0) + ($params['material_costs'] ?? 0));
$profit_rate = $profit / $params['negotiation_amount'];
Db::startTrans();
try {
@ -99,7 +99,7 @@ class ContractNegotiationLogic extends BaseLogic
'labor_costs' => $params['labor_costs'] ?? 0,
'material_costs' => $params['material_costs'] ?? 0,
'warranty_amount' => $params['warranty_amount'] ?? 0,
'warranty_expire_date' => !empty($params['Warranty_expire_date']) ? strtotime($params['Warranty_expire_date']) : 0,
'warranty_expire_date' => !empty($params['warranty_expire_date']) ? strtotime($params['warranty_expire_date']) : 0,
'profit' => $profit,
'profit_rate' => $profit_rate,
'negotiation_content' => $params['negotiation_content'] ?? '',
@ -140,10 +140,10 @@ class ContractNegotiationLogic extends BaseLogic
public static function detail($params): array
{
$data = ContractNegotiation::findOrEmpty($params['id']);
$contract = Contract::field('contract_name,contract_code,contract_type,contract_pricing_method,contract_date,business_director')->where('id',$data['contract_id'])->findOrEmpty();
$project = Project::field('custom_id,name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty();
$business_director = Admin::field('name')->where('id',$contract['business_director'])->findOrEmpty();
$contract = Contract::field('contract_name,contract_code,contract_type,contract_pricing_method,contract_date,business_director')->where('id', $data['contract_id'])->findOrEmpty();
$project = Project::field('custom_id,name,project_code')->where('id', $data['project_id'])->findOrEmpty();
$custom = Custom::field('name')->where('id', $project['custom_id'])->findOrEmpty();
$business_director = Admin::field('name')->where('id', $contract['business_director'])->findOrEmpty();
$data['contract_name'] = $contract['contract_name'];
$data['contract_code'] = $contract['contract_code'];
$data['contract_type'] = $contract->contract_type_text;
@ -154,15 +154,16 @@ class ContractNegotiationLogic extends BaseLogic
$data['project_code'] = $project['project_code'];
$data['custom_name'] = $custom['name'];
$data['negotiation_type_text'] = $data->negotiation_type_text;
$approve_data = FlowApprove::where('id',$data['approve_id'])->findOrEmpty();
$approve_data = FlowApprove::where('id', $data['approve_id'])->findOrEmpty();
$data['approve_check_status'] = $approve_data['check_status'];
return $data->toArray();
}
public static function approve($params,$admin_id): bool{
$data = ContractNegotiation::where('id',$params['id'])->findOrEmpty();
$approve_data = FlowApprove::where('id',$data['approve_id'])->findOrEmpty();
if(!empty($data['approve_id']) && $approve_data['check_status'] != 3){
public static function approve($params, $admin_id): bool
{
$data = ContractNegotiation::where('id', $params['id'])->findOrEmpty();
$approve_data = FlowApprove::where('id', $data['approve_id'])->findOrEmpty();
if (!empty($data['approve_id']) && $approve_data['check_status'] != 3) {
self::setError('当前内容存在审核信息,请勿重复提交');
return false;
}
@ -176,8 +177,8 @@ class ContractNegotiationLogic extends BaseLogic
$params['flow_id'],
$admin_id
);
if($res){
Contract::where('id',$params['id'])->update([
if ($res) {
Contract::where('id', $params['id'])->update([
'approve_id' => $res,
]);
}
@ -189,4 +190,4 @@ class ContractNegotiationLogic extends BaseLogic
return false;
}
}
}
}

View File

@ -12,42 +12,46 @@
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model\contract;
namespace app\common\model\contract;
use app\common\model\BaseModel;
use app\common\model\dict\DictData;
use think\model\concern\SoftDelete;
use app\common\model\BaseModel;
use app\common\model\dict\DictData;
use think\model\concern\SoftDelete;
/**
/**
* 合同洽商模型
* Class ContractNegotiation
* @package app\common\model\contract
*/
class ContractNegotiation extends BaseModel
{
class ContractNegotiation extends BaseModel
{
use SoftDelete;
protected $name = 'contract_negotiation';
protected $deleteTime = 'delete_time';
public function getWarrantyExpireDateAttr($value): string
{
return empty($value) ? '' : date('Y-m-d H:i:s', $value);
return empty($value) ? '' : date('Y-m-d', $value);
}
public function getNegotiationQuotationAttr($value){
public function getNegotiationQuotationAttr($value)
{
return !empty($value) ? json_decode($value) : '';
}
public function getNegotiationBasisAttr($value){
public function getNegotiationBasisAttr($value)
{
return !empty($value) ? json_decode($value) : '';
}
public function getNegotiationTypeTextAttr($value,$data){
$dict = DictData::where('type_value','negotiation_type')->column('name','value');
public function getNegotiationTypeTextAttr($value, $data)
{
$dict = DictData::where('type_value', 'negotiation_type')->column('name', 'value');
return !empty($data['negotiation_type']) ? $dict[$data['negotiation_type']] : '';
}
}
}