engineering/app/adminapi/lists/project/ProjectMaterialBudgetDetailLists.php
2024-01-30 17:34:03 +08:00

144 lines
5.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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\lists\project;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsExcelInterface;
use app\common\model\material\Material;
use app\common\model\material\MaterialClassify;
use app\common\model\material\MaterialPurchaseRequestDetail;
use app\common\model\project\Project;
use app\common\model\project\ProjectMaterialBudget;
use app\common\model\project\ProjectMaterialBudgetDetail;
use app\common\lists\ListsSearchInterface;
/**
* 材料预算明细列表
* Class ProjectMaterialBudgetDetailLists
* @package app\adminapi\listsproject
*/
class ProjectMaterialBudgetDetailLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function setSearch(): array
{
return [
'=' => ['material_budget_id', 'project_id', 'material_id', 'budget_type'],
];
}
/**
* @notes 获取材料预算明细列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function lists(): array
{
return ProjectMaterialBudgetDetail::where($this->searchWhere)
->field('id,project_id,material_budget_id,material_id,budget_type,price,num,amount,remark')
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){
$material_budget = ProjectMaterialBudget::field('material_budget_code')->where('id',$data['material_budget_id'])->findOrEmpty();
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$material = Material::field('first_level,second_level,three_level,name,code,specs,brand,parameter_description,unit')->where('id',$data['material_id'])->findOrEmpty();
$material_classify = MaterialClassify::where('id','in',[$material['first_level'],$material['second_level'],$material['three_level']])->column('name','id');
$data['budget_type'] = $data->budget_type_text;
$data['material_budget_code'] = $material_budget['material_budget_code'];
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_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['budget_type'] = $data->budget_type_text;
//申购数量
$data['apply_num'] = MaterialPurchaseRequestDetail::where('project_material_budget_detail_id',$data['id'])->sum('num');;
//剩余预算数量
$data['residual_num'] = $data['num'] - $data['apply_num'];
return $data;
})
->toArray();
}
/**
* @notes 获取材料预算明细数量
* @return int
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function count(): int
{
return ProjectMaterialBudgetDetail::where($this->searchWhere)->count();
}
public function setFileName(): string
{
return '材料预算明细列表';
}
/**
* @notes 导出字段
* @return string[]
* @author 段誉
* @date 2022/11/24 16:17
*/
public function setExcelFields(): array
{
return [
"id" => "id",
"material_budget_code" => "预算单号",
"project_name" => "项目名称",
"project_code" => "项目编码",
"budget_type" => "类型",
"material_first_level" => "材料大类",
"material_second_level" => "材料中类",
"material_three_level" => "材料小类",
"material_name" => "材料名称",
"material_code" => "材料编码",
"material_specs" => "规格型号",
"material_brand" => "品牌",
"material_parameter_description" => "参数说明",
"material_unit" => "单位",
"apply_num" => "申请数量",
"num" => "预算数量",
"residual_num" => "剩余预算数量",
"price" => "单价",
"amount" => "金额",
"remark" => "备注",
];
}
}