['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 16:30 */ public function lists(): array { return ProjectMaterialBudget::where($this->searchWhere) ->field('id,project_id,material_budget_code,remark,annex') ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function($data){ $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty(); $data['project_name'] = $project['name']; $data['project_code'] = $project['project_code']; //预算总数量 $data['total_num'] = ProjectMaterialBudgetDetail::where('material_budget_id',$data['id'])->sum('num'); //预算总金额 $data['total_amount'] = ProjectMaterialBudgetDetail::where('material_budget_id',$data['id'])->sum('amount'); //申购总数量 $ProjectMaterialBudgetDetailIds = ProjectMaterialBudgetDetail::where('material_budget_id',$data['id'])->column('id'); $data['total_apply_num'] = MaterialPurchaseRequestDetail::where('project_material_budget_detail_id','in',$ProjectMaterialBudgetDetailIds)->sum('num'); //剩余预算总数量 $data['total_residual_num'] = $data['total_num'] - $data['total_apply_num']; return $data; }) ->toArray(); } /** * @notes 获取材料预算数量 * @return int * @author likeadmin * @date 2024/01/08 16:30 */ public function count(): int { return ProjectMaterialBudget::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" => "项目编码", "total_num" => "预算总数量", "total_apply_num" => "申请总数量", "total_residual_num" => "剩余预算数量", "total_amount" => "预算金额", "remark" => "备注", ]; } }