153 lines
6.8 KiB
PHP
153 lines
6.8 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\ProcurementContract;
|
||
use app\common\model\contract\ProcurementContractDetail;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\material\Material;
|
||
use app\common\model\material\MaterialClassify;
|
||
use app\common\model\material\MaterialPurchaseRequest;
|
||
use app\common\model\material\MaterialPurchaseRequestDetail;
|
||
use app\common\model\project\Project;
|
||
use app\common\model\project\ProjectMaterialBudgetDetail;
|
||
use app\common\model\supplier\Supplier;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 采购明细逻辑
|
||
* Class ProcurementContractDetailLogic
|
||
* @package app\adminapi\logic\contract
|
||
*/
|
||
class ProcurementContractDetailLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加采购明细
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/04 22:30
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ProcurementContractDetail::create([
|
||
'procurement_contract_id' => $params['procurement_contract_id'],
|
||
'material_procurement_application_id' => $params['material_procurement_application_id'],
|
||
'num' => $params['num'],
|
||
'unit_price_including_tax' => $params['unit_price_including_tax'],
|
||
'tax_rate' => $params['tax_rate'],
|
||
'amount_excluding_tax' => $params['amount_excluding_tax'],
|
||
'amount_including_tax' => $params['amount_including_tax']
|
||
]);
|
||
|
||
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:30
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ProcurementContractDetail::where('id', $params['id'])->update([
|
||
'procurement_contract_id' => $params['procurement_contract_id'],
|
||
'material_procurement_application_id' => $params['material_procurement_application_id'],
|
||
'num' => $params['num'],
|
||
'unit_price_including_tax' => $params['unit_price_including_tax'],
|
||
'tax_rate' => $params['tax_rate'],
|
||
'amount_excluding_tax' => $params['amount_excluding_tax'],
|
||
'amount_including_tax' => $params['amount_including_tax']
|
||
]);
|
||
|
||
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:30
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return ProcurementContractDetail::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取采购明细详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/04 22:30
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = ProcurementContractDetail::field('id,material_purchase_request_detail_id,contract_id,num,price,tax_rate,amount_excluding_tax,amount_including_tax')->findOrEmpty($params['id']);
|
||
$contract = ProcurementContract::field('contract_no,contract_name,project_id,supplier_id,contract_type')->where('id',$data['contract_id'])->findOrEmpty();
|
||
$project = Project::field('name,project_code')->where('id',$contract['project_id'])->findOrEmpty();
|
||
$supplier = Supplier::field('supplier_code,supplier_name')->where('id',$contract['supplier_id'])->findOrEmpty();
|
||
$material_purchase_request_detail = MaterialPurchaseRequestDetail::field('material_purchase_request_id,project_material_budget_detail_id')->where('id',$data['material_purchase_request_detail_id'])->findOrEmpty();
|
||
$material_purchase_request = MaterialPurchaseRequest::field('material_purchase_request_code')->where('id',$material_purchase_request_detail['material_purchase_request_id'])->findOrEmpty();
|
||
$project_material_budget_detail = ProjectMaterialBudgetDetail::field('material_id')->where('id',$material_purchase_request_detail['project_material_budget_detail_id'])->findOrEmpty();
|
||
$material = Material::field('first_level,second_level,three_level,name,code,specs,brand,parameter_description,unit')->where('id',$project_material_budget_detail['material_id'])->findOrEmpty();
|
||
$material_classify = MaterialClassify::where('id','in',[$material['first_level'],$material['second_level'],$material['three_level']])->column('name','id');
|
||
$data['project_code'] = $project['project_code'];
|
||
$data['project_name'] = $project['name'];
|
||
$data['supplier_code'] = $supplier['supplier_code'];
|
||
$data['supplier_name'] = $supplier['supplier_name'];
|
||
$data['contract_no'] = $contract['contract_no'];
|
||
$data['contract_name'] = $contract['contract_name'];
|
||
$data['contract_type'] = $contract->contract_type_text;
|
||
$data['material_purchase_request_code'] = $material_purchase_request['material_purchase_request_code'];
|
||
$data['material_first_level'] = !empty($material_classify[$material['first_level']]) ? $material_classify[$material['first_level']] : '';
|
||
$data['material_second_level'] = !empty($material_classify[$material['second_level']]) ? $material_classify[$material['second_level']] : '';
|
||
$data['material_three_level'] = !empty($material_classify[$material['three_level']]) ? $material_classify[$material['three_level']] : '';
|
||
$data['material_name'] = $material['name'];
|
||
$data['material_code'] = $material['code'];
|
||
$data['material_specs'] = $material['specs'];
|
||
$data['material_brand'] = $material['brand'];
|
||
$data['material_parameter_description'] = $material['parameter_description'];
|
||
$data['material_unit'] = $material['unit'];
|
||
$data['tax_rate_text'] = $data->tax_rate_text;
|
||
return $data->toArray();
|
||
}
|
||
} |