makeFeelist($flow->const_type, array_merge($flow->extends, [ 'oldman_id' => $flow->oldman_id, 'live_in_at' => $flow->start_at, 'avliable_at' => $flow->end_at ])); } public function delete(string $ids): mixed { $id = collect(explode(',', $ids)); // 所有ID foreach ($id as $value) { $_flow = ConstFlow::find($value); if($_flow->const_type == ConstFlow::TYPE_IN){ $_oldman = Oldmen::find($_flow->oldman_id); //如果还有续费记录未删除,则提示先删除续费记录; if(ConstFlow::where('oldman_id', $_oldman->id)->where('const_type', '>', ConstFlow::TYPE_IN)->where('end_at', '<=', $_oldman->avliable_at)->exists()){ return $this->setError('请先删除该用户续费记录'); } //如果删除入住;则判断当前用户状态是否是入住,是,则变更为未入住; if($_oldman->live_in_at == $_flow->start_at && $_oldman->live_in == Oldmen::STATUS_LIVE){ $_oldman->update([ 'live_in' => Oldmen::STATUS_NORMAL, 'need_pay' => Oldmen::PAY_NORMAL, 'live_in_at' => null, 'avliable_at' => null, 'bonds' => [],//保证金归零 ]); } } } $id = $id->unique(); return $this->query()->whereIn($this->primaryKey(), $id)->delete(); } }