['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(); } }