This commit is contained in:
weiz 2024-01-11 11:43:25 +08:00
parent 6fb4376c40
commit 0db484f9fe
7 changed files with 140 additions and 86 deletions

View File

@ -16,9 +16,9 @@
namespace app\adminapi\controller\contract;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\contract\SubcontractingContractNegotiationLists;
use app\adminapi\logic\contract\SubcontractingContractNegotiationLogic;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\contract\SubcontractingContractNegotiationLists;
use app\adminapi\logic\contract\SubcontractingContractNegotiationLogic;
use app\adminapi\validate\contract\SubcontractingContractNegotiationValidate;

View File

@ -19,6 +19,7 @@ use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\contract\SubcontractingContract;
use app\common\lists\ListsSearchInterface;
use app\common\model\contract\SubcontractingContractDetail;
use app\common\model\contract\SubcontractingContractNegotiation;
use app\common\model\project\Project;
use app\common\model\supplier\Supplier;
@ -69,6 +70,10 @@ class SubcontractingContractLists extends BaseAdminDataLists implements ListsSea
$data['supplier_name'] = $supplier['supplier_name'];
$data['supplier_code'] = $supplier['supplier_code'];
$data['contract_type'] = $data->contract_type_text;
//洽商金额
$data['negotiation_amount'] = SubcontractingContractNegotiation::where('subcontracting_contract_id',$data['id'])->sum('negotiation_amount');
//实际合同金额
$data['reality_contract_amount'] = $data['contract_amount'] + $data['negotiation_amount'];
//不含税金额
$data['excluding_tax_amount'] = SubcontractingContractDetail::where('contract_id',$data['id'])->sum('amount_excluding_tax');
//已付款金额

View File

@ -16,8 +16,11 @@ namespace app\adminapi\lists\contract;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\contract\SubcontractingContract;
use app\common\model\contract\SubcontractingContractNegotiation;
use app\common\lists\ListsSearchInterface;
use app\common\model\project\Project;
use app\common\model\supplier\Supplier;
use think\facade\Db;
/**
@ -38,7 +41,8 @@ class SubcontractingContractNegotiationLists extends BaseAdminDataLists implemen
public function setSearch(): array
{
return [
'=' => ['scn.subcontracting_contract_id', 'scn.negotiation_name', 'scn.negotiation_no', 'scn.negotiation_type'],
'=' => ['project_id','subcontracting_contract_id','negotiation_type'],
'%like%' => ['negotiation_name','negotiation_no']
];
}
@ -54,23 +58,21 @@ class SubcontractingContractNegotiationLists extends BaseAdminDataLists implemen
*/
public function lists(): array
{
return Db::name('SubcontractingContractNegotiation')->alias('scn')
->where($this->searchWhere)
->whereNull('scn.delete_time')
->leftJoin('orgs o','o.id = scn.org_id')
->leftJoin('dept d','d.id = scn.dept_id')
->leftJoin('procurement_contract pc','pc.id = scn.subcontracting_contract_id')
->leftJoin('project p','p.id = pc.project_id')
->field('scn.*, d.name as dept_name, o.name as org_name, p.name as project_name, p.project_code, pc.contract_no, pc.contract_name')
return SubcontractingContractNegotiation::where($this->searchWhere)
->field('id,project_id,subcontracting_contract_id,negotiation_name,negotiation_no,negotiation_amount,negotiation_type,sign_date,warranty_amount,warranty_expire_date')
->limit($this->limitOffset, $this->limitLength)
->order(['scn.id' => 'desc'])
->select()->each(function($item, $key){
//关联数据后续添加
$item['approve_no'] = '付款单号';
$item['approve_step'] = '流程步骤';
$item['approve_settle_status'] = 1;
return $item;
->order(['id' => 'desc'])
->select()->each(function($data){
$subcontracting_contract = SubcontractingContract::field('supplier_id,contract_no')->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_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();
}
@ -84,13 +86,7 @@ class SubcontractingContractNegotiationLists extends BaseAdminDataLists implemen
*/
public function count(): int
{
return Db::name('SubcontractingContractNegotiation')->alias('scn')
->where($this->searchWhere)
->whereNull('scn.delete_time')
->leftJoin('orgs o','o.id = scn.org_id')
->leftJoin('dept d','d.id = scn.dept_id')
->leftJoin('procurement_contract pc','pc.id = scn.subcontracting_contract_id')
->leftJoin('project p','p.id = pc.project_id')->count();
return SubcontractingContractNegotiation::where($this->searchWhere)->count();
}
}

View File

@ -15,8 +15,11 @@
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;
@ -28,7 +31,6 @@ use think\facade\Db;
class SubcontractingContractNegotiationLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
@ -38,24 +40,24 @@ class SubcontractingContractNegotiationLogic extends BaseLogic
*/
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([
'org_id' => $params['org_id'] ?? 0,
'dept_id' => $params['dept_id'] ?? 0,
'subcontracting_contract_id' => $params['subcontracting_contract_id'] ?? 0,
'negotiation_name' => $params['negotiation_name'] ?? '',
'negotiation_no' => $params['negotiation_no'] ?? '',
'negotiation_amount' => $params['negotiation_amount'] ?? 0,
'negotiation_type' => $params['negotiation_type'] ?? 0,
'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' => $params['Warranty_expire_date'] ?? '',
'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'] ?? '',
'negotiation_basis' => $params['negotiation_basis'] ?? '',
'negotiation_quotation' => !empty($params['negotiation_quotation']) ? $params['negotiation_quotation'] : null,
'negotiation_basis' => !empty($params['negotiation_basis']) ? $params['negotiation_basis'] : null,
]);
Db::commit();
return true;
} catch (\Exception $e) {
@ -75,24 +77,24 @@ class SubcontractingContractNegotiationLogic extends BaseLogic
*/
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([
'org_id' => $params['org_id'] ?? 0,
'dept_id' => $params['dept_id'] ?? 0,
'subcontracting_contract_id' => $params['subcontracting_contract_id'] ?? 0,
'negotiation_name' => $params['negotiation_name'] ?? '',
'negotiation_no' => $params['negotiation_no'] ?? '',
'negotiation_amount' => $params['negotiation_amount'] ?? 0,
'negotiation_type' => $params['negotiation_type'] ?? 0,
'warranty_amount' => $params['warranty_amount'] ?? 0,
'Warranty_expire_date' => $params['Warranty_expire_date'] ?? '',
'negotiation_content' => $params['negotiation_content'] ?? '',
'negotiation_detail' => $params['negotiation_detail'] ?? '',
'negotiation_quotation' => $params['negotiation_quotation'] ?? '',
'negotiation_basis' => $params['negotiation_basis'] ?? '',
'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' => !empty($params['negotiation_quotation']) ? $params['negotiation_quotation'] : null,
'negotiation_basis' => !empty($params['negotiation_basis']) ? $params['negotiation_basis'] : null,
'update_time' => time(),
]);
Db::commit();
return true;
} catch (\Exception $e) {
@ -125,17 +127,17 @@ class SubcontractingContractNegotiationLogic extends BaseLogic
*/
public static function detail($params): array
{
$subcontractingContractNegotiation = SubcontractingContractNegotiation::findOrEmpty($params['id']);
$subcontractingContractNegotiation->contract;
$subcontractingContractNegotiation->org;
$subcontractingContractNegotiation->dept;
$subcontractingContractNegotiation->project = null;
if (!empty($subcontractingContractNegotiation->contract->project)) {
$subcontractingContractNegotiation->project = $subcontractingContractNegotiation->contract->project;
unset($subcontractingContractNegotiation->contract->project);
}
$subcontractingContractNegotiation->negotiation_quotation = json_decode($subcontractingContractNegotiation->negotiation_quotation, true);
$subcontractingContractNegotiation->negotiation_basis = json_decode($subcontractingContractNegotiation->negotiation_basis, true);
return $subcontractingContractNegotiation->toArray();
$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')->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_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();
}
}

View File

@ -15,6 +15,8 @@
namespace app\adminapi\validate\contract;
use app\common\model\contract\SubcontractingContract;
use app\common\model\dict\DictData;
use app\common\validate\BaseValidate;
@ -32,9 +34,15 @@ class SubcontractingContractNegotiationValidate extends BaseValidate
*/
protected $rule = [
'id' => 'require',
'subcontracting_contract_id' => 'require',
'subcontracting_contract_id' => 'require|checkSubcontractingContract',
'sign_date' => 'require|dateFormat:Y-m-d',
'negotiation_name' => 'require',
'negotiation_amount' => 'require',
'negotiation_amount' => 'require|float|egt:0',
'negotiation_type' => 'require|checkNegotiationType',
'warranty_amount' => 'float|egt:0',
'warranty_expire_date' => 'dateFormat:Y-m-d',
'negotiation_quotation' => 'checkAnnex',
'negotiation_basis' => 'checkAnnex',
];
@ -44,6 +52,13 @@ class SubcontractingContractNegotiationValidate extends BaseValidate
*/
protected $field = [
'id' => 'id',
'subcontracting_contract_id' => '分包合同',
'sign_date' => '签约日期',
'negotiation_name' => '洽商单名称',
'negotiation_amount' => '洽商金额',
'negotiation_type' => '洽商类别',
'warranty_amount' => '洽商质保金额',
'warranty_expire_date' => '洽商质保到期时间'
];
@ -65,9 +80,7 @@ class SubcontractingContractNegotiationValidate extends BaseValidate
* @date 2023/12/12 17:21
*/
public function sceneEdit()
{
return $this->only(['id', 'subcontracting_contract_id', 'negotiation_name', 'negotiation_amount']);
}
{}
/**
@ -92,5 +105,34 @@ class SubcontractingContractNegotiationValidate extends BaseValidate
{
return $this->only(['id']);
}
public function checkSubcontractingContract($value): bool|string
{
$data = SubcontractingContract::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '分包合同信息不存在';
}
return true;
}
public function checkNegotiationType($value): bool|string
{
$dict = DictData::where('type_value','negotiation_type')->column('value');
if(!in_array($value,$dict)){
return '洽商类别无效';
}
return true;
}
public function checkAnnex($value): bool|string
{
if(!empty($value) && $value != ''){
$annex = json_decode($value,true);
if(empty($annex) || !is_array($annex)){
return '附件格式错误';
}
}
return true;
}
}

View File

@ -33,7 +33,7 @@ class SubcontractingContract extends BaseModel
public function getSigningDateAttr($value): string
{
return empty($value) ? '' : date('Y-m-d H:i:s', $value);
return empty($value) ? '' : date('Y-m-d', $value);
}
public function getAnnexAttr($value){

View File

@ -16,6 +16,7 @@ namespace app\common\model\contract;
use app\common\model\BaseModel;
use app\common\model\dict\DictData;
use think\model\concern\SoftDelete;
@ -29,20 +30,28 @@ class SubcontractingContractNegotiation extends BaseModel
use SoftDelete;
protected $name = 'subcontracting_contract_negotiation';
protected $deleteTime = 'delete_time';
public function contract()
{
return $this->belongsTo(\app\common\model\contract\ProcurementContract::class, 'subcontracting_contract_id');
}
public function org()
{
return $this->hasOne(\app\common\model\dept\Orgs::class, 'id', 'org_id');
}
public function dept()
{
return $this->hasOne(\app\common\model\dept\Dept::class, 'id', 'dept_id');
}
public function getSignDateAttr($value): string
{
return empty($value) ? '' : date('Y-m-d', $value);
}
public function getWarrantyExpireDateAttr($value): string
{
return empty($value) ? '' : date('Y-m-d', $value);
}
public function getNegotiationQuotationAttr($value){
return !empty($value) ? json_decode($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');
return $dict[$data['negotiation_type']];
}
}