$params['num'], ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 编辑材料采购申请明细 * @param array $params * @return bool * @author likeadmin * @date 2024/01/09 13:47 */ public static function edit(array $params): bool { $data = MaterialPurchaseRequestDetail::where('id',$params['id'])->findOrEmpty(); Db::startTrans(); try { MaterialPurchaseRequestDetail::where('id', $params['id'])->update([ 'num' => $params['num'], 'remark' => $params['remark'] ?? '', 'update_time' => time() ]); //预算数量 $project_material_budget_detail = ProjectMaterialBudgetDetail::field('num')->where('id',$data['project_material_budget_detail_id'])->findOrEmpty(); //已经申购的数量 $purchase_request_num = MaterialPurchaseRequestDetail::where('project_material_budget_detail_id',$data['project_material_budget_detail_id'])->where('id','<>',$params['id'])->sum('num'); if($project_material_budget_detail['num'] - $purchase_request_num - $params['num'] <=0){ ProjectMaterialBudgetDetail::where('id',$data['project_material_budget_detail_id'])->update(['is_residual'=>1,'update_time'=>time()]); }else{ ProjectMaterialBudgetDetail::where('id',$data['project_material_budget_detail_id'])->update(['is_residual'=>0,'update_time'=>time()]); } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 删除材料采购申请明细 * @param array $params * @return bool * @author likeadmin * @date 2024/01/09 13:47 */ public static function delete(array $params): bool { return MaterialPurchaseRequestDetail::destroy($params['id']); } /** * @notes 获取材料采购申请明细详情 * @param $params * @return array * @author likeadmin * @date 2024/01/09 13:47 */ public static function detail($params): array { $data = MaterialPurchaseRequestDetail::field('id,material_purchase_request_id,project_material_budget_detail_id,num')->findOrEmpty($params['id']); $material_purchase_request = MaterialPurchaseRequest::field('material_purchase_request_code,project_id,apply_date,arrival_date')->where('id',$data['material_purchase_request_id'])->findOrEmpty(); $project = Project::field('name,project_code')->where('id',$material_purchase_request['project_id'])->findOrEmpty(); $project_material_budget_detail = ProjectMaterialBudgetDetail::field('material_id')->where('id',$data['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['material_purchase_request_code'] = $material_purchase_request['material_purchase_request_code']; $data['project_name'] = $project['name']; $data['project_code'] = $project['project_code']; $data['apply_date'] = $material_purchase_request['apply_date']; $data['arrival_date'] = $material_purchase_request['arrival_date']; $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']; return $data->toArray(); } }