old-hotel-new/app/Services/Admin/LiveInService.php

73 lines
2.1 KiB
PHP

<?php
namespace App\Services\Admin;
use App\Models\ConstFlow;
use App\Models\Oldmen;
use DB;
use Throwable;
/**
* @method Oldmen getModel()
* @method Oldmen|\Illuminate\Database\Query\Builder query()
*/
class LiveInService extends OldmenService
{
public function listQuery()
{
$filter = $this->getModelFilter();
$query = $this->query();
if($this->withRelationships){
$query->with($this->withRelationships);
}
if ($filter) {
$query->filter(request()->input(), $filter)->where('live_in', Oldmen::STATUS_LIVE);
}
return $query;
}
public function do($oldManId, $startAt, $endAt, $feeArr = null){
$oldMan = $this->getDetail($oldManId);
if($oldMan){
//判断状态-是否是已经入住状态;已入住状态无法再入住;
if($oldMan->live_in != Oldmen::STATUS_NORMAL){
return $this->setError('客人状态异常,请刷新后充试!');
}
$flow = new ConstFlow();
$flow->oldman_id = $oldMan->id;
$flow->const_type = ConstFlow::TYPE_IN;
$flow->start_at = $startAt;
$flow->end_at = $endAt;
$flow->money = $this->totalFee($feeArr);
$flow->extends = $feeArr;
try{
DB::beginTransaction();
//缴费生成流水;
$flow->save();
//更新客人信息状态;
$oldMan->update([
'live_in' => Oldmen::STATUS_LIVE,
'live_in_at' => $startAt,
'avliable_at' => $endAt,
'bonds' => $feeArr['bonds_fee'] ?? [] //记录保证金
]);
DB::commit();
}catch(Throwable $th){
DB::rollBack();
report($th);
return $this->setError('系统错误,请刷新后重试');
}
return true;
}else{
return $this->setError('未找到客人信息!');
}
}
}