public function forceTerminalFeePlan($rent_id) { $ret = []; $ret['status'] = 1; $feePlans = FeePlan::where('rent_id', $rent_id)->where('status', 0)->get(); try { DB::beginTransaction(); foreach ($feePlans as $feeplan) { $feerecord = []; $feerecord['feemeta_id'] = $feeplan['feemeta_id']; $feerecord['rent_id'] = $feeplan['rent_id']; $feerecord['room_id'] = $feeplan['room_id']; $feerecord['building_id'] = $feeplan['building_id']; $feerecord['fee_plan_id'] = $feeplan['id']; $feerecord['fee_name'] = $feeplan['fee_name'] . '-终止费用'; $feerecord['payor'] = $this->user['nick']; $feerecord['user_id'] = $this->user['id']; $feerecord['inc_fee'] = 0; $feerecord = new FeeRecord($feerecord); if (!$feerecord->save()) { DB::rollBack(); abort(500, 'Could not save feeRecord'); } $feeplan['status'] = 1; if (!$feeplan->save()) { DB::rollBack(); abort(500, 'Could not save feePlan'); } } DB::commit(); } catch (Exception $exception) { DB::rollBack(); abort(500, 'Save failed'); } return $ret; }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id, Request $request) { $this->validate($request, ['room_id' => 'required|numeric', 'water_degree' => 'required|numeric', 'electric_degree' => 'required|numeric'], ['required' => 'The :attribute field is required', 'numeric' => 'The :attribute field must be numeric']); $deleteInput = $request->all(); $room = Room::find($deleteInput['room_id']); $contract = Contract::find($id); $feeplancount = FeePlan::where("rent_id", $id)->where('status', 0)->count(); if ($feeplancount > 0) { $ret['status'] = -1; $ret['desc'] = '该租户还有欠款为付清,无法终止合同。如中途退出,请联系主管,先走特殊费用终止流程!'; return $ret; } else { try { DB::beginTransaction(); $room['water_degree'] = $deleteInput['water_degree']; $room['electric_degree'] = $deleteInput['electric_degree']; if (!$room->save()) { abort(500, 'Destroy failed'); } $contract['end_water_degree'] = $deleteInput['water_degree']; $contract['end_electric_degree'] = $deleteInput['electric_degree']; $realendtime = new \DateTime(); $realEndTimeStr = $realendtime->format('Y-m-d'); $contract['real_end_time'] = $realEndTimeStr; if (!$contract->save()) { abort(500, 'Destroy failed'); } DB::commit(); } catch (Exception $exception) { DB::rollBack(); abort(500, 'Destroy failed'); } $ret['status'] = Contract::destroy($id); return $ret; } }
public static function checkNotExistPlanned($feePlan) { $overlapCount = FeePlan::where('rent_id', $feePlan['rent_id'])->where('feemeta_id', $feePlan['feemeta_id'])->where('fee_end_date', '>', $feePlan['fee_start_date'])->count(); return $overlapCount < 1; }