更新采购合同模块
This commit is contained in:
parent
8ab08b3ac0
commit
274ba66514
@ -38,7 +38,7 @@ class ProcurementContractLists extends BaseAdminDataLists implements ListsSearch
|
|||||||
public function setSearch(): array
|
public function setSearch(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'=' => ['supplier_id', 'project_id'],
|
'=' => ['supplier_id', 'project_id', 'contract_no'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ class ProcurementContractLists extends BaseAdminDataLists implements ListsSearch
|
|||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
return ProcurementContract::where($this->searchWhere)
|
return ProcurementContract::where($this->searchWhere)
|
||||||
->field(['id', 'supplier_id', 'approve_id', 'project_id', 'contract_no', 'supplier_contract_no', 'contract_type', 'signing_date', 'pay_type', 'account_period', 'amount', 'amount_excluding_tax', 'amount_daxie', 'retention_money_rate', 'retention_money'])
|
->field(['*'])
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
->select()
|
->select()
|
||||||
|
165
app/adminapi/logic/contract/ProcurementContractLogic.php
Normal file
165
app/adminapi/logic/contract/ProcurementContractLogic.php
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
<?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\ProcurementContract;
|
||||||
|
use app\common\model\contract\ProcurementContractDetail;
|
||||||
|
use app\common\logic\BaseLogic;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 采购合同逻辑
|
||||||
|
* Class ProcurementContractLogic
|
||||||
|
* @package app\adminapi\logic\contract
|
||||||
|
*/
|
||||||
|
class ProcurementContractLogic extends BaseLogic
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加采购合同
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/04 22:08
|
||||||
|
*/
|
||||||
|
public static function add(array $params): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
$procurementContract = ProcurementContract::create([
|
||||||
|
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||||
|
'approve_id' => $params['approve_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'] ?? '',
|
||||||
|
'retention_money' => $params['retention_money'] ?? 0,
|
||||||
|
'remark' => $params['remark'] ?? '',
|
||||||
|
'annex' => $params['annex'] ?? ''
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach ($params['material'] ?? [] as $item)
|
||||||
|
{
|
||||||
|
ProcurementContractDetail::create([
|
||||||
|
'procurement_contract_id' => $procurementContract->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/04 22:08
|
||||||
|
*/
|
||||||
|
public static function edit(array $params): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
ProcurementContract::where('id', $params['id'])->update([
|
||||||
|
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||||
|
'approve_id' => $params['approve_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'] ?? '',
|
||||||
|
'retention_money' => $params['retention_money'] ?? 0,
|
||||||
|
'remark' => $params['remark'] ?? '',
|
||||||
|
'annex' => $params['annex'] ?? ''
|
||||||
|
]);
|
||||||
|
ProcurementContractDetail::where('procurement_contract_id', $params['id'])->delete();
|
||||||
|
foreach ($params['material'] ?? [] as $item)
|
||||||
|
{
|
||||||
|
ProcurementContractDetail::create([
|
||||||
|
'procurement_contract_id' => $params['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/04 22:08
|
||||||
|
*/
|
||||||
|
public static function delete(array $params): bool
|
||||||
|
{
|
||||||
|
return ProcurementContract::destroy($params['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取采购合同详情
|
||||||
|
* @param $params
|
||||||
|
* @return array
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/04 22:08
|
||||||
|
*/
|
||||||
|
public static function detail($params): array
|
||||||
|
{
|
||||||
|
$procurementContract = ProcurementContract::findOrEmpty($params['id']);
|
||||||
|
$procurementContract->project = $procurementContract->project;
|
||||||
|
$procurementContract->material = $procurementContract->material;
|
||||||
|
return $procurementContract->toArray();
|
||||||
|
}
|
||||||
|
}
|
@ -1,136 +0,0 @@
|
|||||||
<?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\ProcurementContract;
|
|
||||||
use app\common\logic\BaseLogic;
|
|
||||||
use think\facade\Db;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 采购合同逻辑
|
|
||||||
* Class ProcurementContractLogic
|
|
||||||
* @package app\adminapi\logic\contract
|
|
||||||
*/
|
|
||||||
class ProcurementContractLogic extends BaseLogic
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 添加采购合同
|
|
||||||
* @param array $params
|
|
||||||
* @return bool
|
|
||||||
* @author likeadmin
|
|
||||||
* @date 2023/12/04 22:08
|
|
||||||
*/
|
|
||||||
public static function add(array $params): bool
|
|
||||||
{
|
|
||||||
Db::startTrans();
|
|
||||||
try {
|
|
||||||
ProcurementContract::create([
|
|
||||||
'supplier_id' => $params['supplier_id'],
|
|
||||||
'approve_id' => $params['approve_id'],
|
|
||||||
'project_id' => $params['project_id'],
|
|
||||||
'contract_no' => $params['contract_no'],
|
|
||||||
'supplier_contract_no' => $params['supplier_contract_no'],
|
|
||||||
'contract_type' => $params['contract_type'],
|
|
||||||
'signing_date' => strtotime($params['signing_date']),
|
|
||||||
'pay_type' => $params['pay_type'],
|
|
||||||
'account_period' => $params['account_period'],
|
|
||||||
'amount' => $params['amount'],
|
|
||||||
'amount_excluding_tax' => $params['amount_excluding_tax'],
|
|
||||||
'amount_daxie' => $params['amount_daxie'],
|
|
||||||
'retention_money_rate' => $params['retention_money_rate'],
|
|
||||||
'retention_money' => $params['retention_money'],
|
|
||||||
'remark' => $params['remark'],
|
|
||||||
'annex' => $params['annex']
|
|
||||||
]);
|
|
||||||
|
|
||||||
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/04 22:08
|
|
||||||
*/
|
|
||||||
public static function edit(array $params): bool
|
|
||||||
{
|
|
||||||
Db::startTrans();
|
|
||||||
try {
|
|
||||||
ProcurementContract::where('id', $params['id'])->update([
|
|
||||||
'supplier_id' => $params['supplier_id'],
|
|
||||||
'approve_id' => $params['approve_id'],
|
|
||||||
'project_id' => $params['project_id'],
|
|
||||||
'contract_no' => $params['contract_no'],
|
|
||||||
'supplier_contract_no' => $params['supplier_contract_no'],
|
|
||||||
'contract_type' => $params['contract_type'],
|
|
||||||
'signing_date' => strtotime($params['signing_date']),
|
|
||||||
'pay_type' => $params['pay_type'],
|
|
||||||
'account_period' => $params['account_period'],
|
|
||||||
'amount' => $params['amount'],
|
|
||||||
'amount_excluding_tax' => $params['amount_excluding_tax'],
|
|
||||||
'amount_daxie' => $params['amount_daxie'],
|
|
||||||
'retention_money_rate' => $params['retention_money_rate'],
|
|
||||||
'retention_money' => $params['retention_money'],
|
|
||||||
'remark' => $params['remark'],
|
|
||||||
'annex' => $params['annex']
|
|
||||||
]);
|
|
||||||
|
|
||||||
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/04 22:08
|
|
||||||
*/
|
|
||||||
public static function delete(array $params): bool
|
|
||||||
{
|
|
||||||
return ProcurementContract::destroy($params['id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 获取采购合同详情
|
|
||||||
* @param $params
|
|
||||||
* @return array
|
|
||||||
* @author likeadmin
|
|
||||||
* @date 2023/12/04 22:08
|
|
||||||
*/
|
|
||||||
public static function detail($params): array
|
|
||||||
{
|
|
||||||
return ProcurementContract::findOrEmpty($params['id'])->toArray();
|
|
||||||
}
|
|
||||||
}
|
|
@ -57,7 +57,7 @@ class QuotationLogic extends BaseLogic
|
|||||||
'remark' => $params['remark'] ?? '',
|
'remark' => $params['remark'] ?? '',
|
||||||
'annex' => $params['annex'] ?? '',
|
'annex' => $params['annex'] ?? '',
|
||||||
]);
|
]);
|
||||||
foreach ($params['product'] as $item)
|
foreach ($params['product'] ?? [] as $item)
|
||||||
{
|
{
|
||||||
QuotationDetail::create([
|
QuotationDetail::create([
|
||||||
'quotation_id' => $quotation->id,
|
'quotation_id' => $quotation->id,
|
||||||
@ -105,7 +105,7 @@ class QuotationLogic extends BaseLogic
|
|||||||
'annex' => $params['annex'] ?? '',
|
'annex' => $params['annex'] ?? '',
|
||||||
]);
|
]);
|
||||||
QuotationDetail::where('quotation_id', $params['id'])->delete();
|
QuotationDetail::where('quotation_id', $params['id'])->delete();
|
||||||
foreach ($params['product'] as $item)
|
foreach ($params['product'] ?? [] as $item)
|
||||||
{
|
{
|
||||||
QuotationDetail::create([
|
QuotationDetail::create([
|
||||||
'quotation_id' => $params['id'],
|
'quotation_id' => $params['id'],
|
||||||
|
@ -32,6 +32,10 @@ class ProcurementContractValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'id' => 'require',
|
'id' => 'require',
|
||||||
|
'supplier_id' => 'require',
|
||||||
|
'approve_id' => 'require',
|
||||||
|
'project_id' => 'require',
|
||||||
|
'material' => 'require|array|checkMaterial',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@ -64,7 +68,7 @@ class ProcurementContractValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneEdit()
|
public function sceneEdit()
|
||||||
{
|
{
|
||||||
return $this->only(['id']);
|
return $this->only(['id', 'supplier_id', 'approve_id', 'project_id', 'material']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -91,4 +95,28 @@ class ProcurementContractValidate extends BaseValidate
|
|||||||
return $this->only(['id']);
|
return $this->only(['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkMaterial($value, $rule, $data)
|
||||||
|
{
|
||||||
|
$firstData = $value[0] ?? [];
|
||||||
|
if (empty($firstData['material_procurement_application_id'])) {
|
||||||
|
return '材料采购申请id不能为空!';
|
||||||
|
}
|
||||||
|
if (empty($firstData['num'])) {
|
||||||
|
return '材料数量不能为空!';
|
||||||
|
}
|
||||||
|
if (empty($firstData['unit_price_including_tax'])) {
|
||||||
|
return '材料含税单价不能为空!';
|
||||||
|
}
|
||||||
|
if (empty($firstData['tax_rate'])) {
|
||||||
|
return '材料税率不能为空!';
|
||||||
|
}
|
||||||
|
if (empty($firstData['amount_excluding_tax'])) {
|
||||||
|
return '材料不含税金额不能为空!';
|
||||||
|
}
|
||||||
|
if (empty($firstData['amount_including_tax'])) {
|
||||||
|
return '材料含税金额不能为空!';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -30,5 +30,19 @@ class ProcurementContract extends BaseModel
|
|||||||
protected $name = 'procurement_contract';
|
protected $name = 'procurement_contract';
|
||||||
protected $deleteTime = 'delete_time';
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
|
public function project()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(\app\common\model\project\Project::class, 'project_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function material()
|
||||||
|
{
|
||||||
|
return $this->hasMany(\app\common\model\contract\ProcurementContractDetail::class, 'procurement_contract_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSigningDateAttr($value)
|
||||||
|
{
|
||||||
|
return empty($value) ? '' : date('Y-m-d H:i:s', $value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user