getDetail($oldManId); if($oldMan){ //判断状态-是否是已经入住状态;未入住状态无法结算; if($oldMan->live_in != Oldmen::STATUS_LIVE){ return $this->setError('客人状态异常,请刷新后重试!'); } $flowList = ConstFlow::where('oldman_id', $oldMan->id) ->whereIn('const_type', [ConstFlow::TYPE_IN, ConstFlow::TYPE_CONTINUE]) ->whereBetween('start_at', [$oldMan->live_in_at, $oldMan->avliable_at])//开始时间在用户这段时间内的清单 ->get(); $flowMoney = 0; foreach($flowList as $flow){ $flowMoney = bcadd($flowMoney, $flow->money, 2); } $flow = new ConstFlow(); $flow->oldman_id = $oldMan->id; $flow->const_type = ConstFlow::TYPE_EXIT; $flow->start_at = $oldMan->live_in_at;//开始入住时间 $flow->end_at = $oldMan->avliable_at;//办理结算时间 $flow->money = bcadd($flowMoney, $this->totalFee($feeArr), 2); $flow->extends = $feeArr; try{ DB::beginTransaction(); //缴费生成流水; $flow->save(); //更新客人信息状态; $oldMan->update([ 'live_in' => Oldmen::STATUS_NORMAL, 'need_pay' => Oldmen::PAY_NORMAL, 'live_in_at' => null, 'avliable_at' => null, 'bonds' => 0,//保证金归零 ]); DB::commit(); }catch(Throwable $th){ DB::rollBack(); report($th); return $this->setError('系统错误,请刷新后重试'); } return true; }else{ return $this->setError('未找到客人信息!'); } } }