完善结算动作

develop
vine_liutk 2023-06-07 15:23:10 +08:00
parent c925a3bcf6
commit 2e6ed6b5be
4 changed files with 92 additions and 17 deletions

View File

@ -7,13 +7,13 @@ use Slowlyo\OwlAdmin\Renderers\Page;
use Slowlyo\OwlAdmin\Renderers\Form;
use Slowlyo\OwlAdmin\Renderers\TableColumn;
use Slowlyo\OwlAdmin\Controllers\AdminController;
use App\Services\Admin\LiveContinueService;
use App\Services\Admin\LiveExitService;
use Illuminate\Http\Request;
use App\Admin\Components;
class LiveExitController extends AdminController
{
protected string $serviceName = LiveContinueService::class;
protected string $serviceName = LiveExitService::class;
public function form(): Form
@ -37,7 +37,7 @@ class LiveExitController extends AdminController
amisMake()->Wrapper()->sm(8)->body([
amisMake()->Panel()->title('结算表单')->body(
amisMake()->form()->title('')->panelClassName('border-0')->mode('horizontal')->name('base_form')
->api(admin_url('live-continue-do'))
->api(admin_url('live-exit-do'))
->body([
amisMake()->FieldSetControl()->title('客人信息')->collapsable(true)->body([
amisMake()->Service()->api([
@ -101,16 +101,6 @@ class LiveExitController extends AdminController
]),
]),
amisMake()->FieldSetControl()->className('mt-10')->title('已缴费明细')->collapsable(true)->body(
amisMake()->FieldSetControl()->title('基础费用')->className('mt-5')->collapsable(true)->size('base')->body(
amisMake()->Service()->schemaApi([
"method"=>'get',
"url" => admin_url('live-const-flow').'?oldman_id=${oldman_id}',
])
),
),
amisMake()->FieldSetControl()->className('mt-10')->title('附加项')->collapsable(true)->body([
amisMake()->ComboControl('del_extends','收费项')->multiple(true)->items([
amisMake()->TextControl('name', '名称'),
@ -121,6 +111,13 @@ class LiveExitController extends AdminController
Components::make()->decimalControl('fee', '金额')
]),
]),
amisMake()->FieldSetControl()->className('mt-10')->title('已缴费明细')->collapsable(true)->body(
amisMake()->Service()->schemaApi([
"method"=>'get',
"url" => admin_url('live-const-flow').'?oldman_id=${oldman_id}',
])
),
])
->actions([
amis('button')->label("生成清单")->level('primary')
@ -142,7 +139,7 @@ class LiveExitController extends AdminController
]
]),
amis('submit')->label('确认结算')->confirmText('是否确认结算,并且已查看结算费用清单?')
->redirect('live-in')
->redirect('oldmen')
->level('danger'),
]),
),
@ -181,6 +178,16 @@ class LiveExitController extends AdminController
}
public function do(Request $request){
$oldManId = $request->input('oldman_id');
$addFee = $request->input('add_extends', []);
$delFee = $request->input('del_extends', []);
$res = $this->service->do($oldManId, [
'add_fee' => $addFee,
'del_fee' => $delFee,
]);
return $this->autoResponse($res, '结算');
}
}

View File

@ -58,7 +58,8 @@ class OldmenController extends AdminController
TableColumn::make()->name('nurse_lv')->type('mapping')->map(Keyword::getByParentKey('nurse_lv')->pluck('name', 'value'))->label('护理等级')->className('text-primary')->sortable(),
TableColumn::make()->name('client_name')->label('委托人'),
TableColumn::make()->name('client_phone')->label('委托人-手机号')->copyable(true),
//状态:未入住、已办理,未入住、已入住
//状态显示:未入住、已办理,未入住、已入住-todo
TableColumn::make()->name('created_at')->label(__('admin.created_at'))->type('datetime')->sortable(true),
amisMake()->Operation()->label(__('admin.actions'))->buttons([
$this->rowEditButton(true, 'lg'),

View File

@ -39,7 +39,7 @@ class LiveContinueService extends OldmenService
return $this->setError('客人状态异常,请刷新后重试!');
}
//判断开始时间和用户截至时间是否相隔1秒-todo
//判断开始时间和用户截至时间是否相隔1秒
if(Carbon::parse($oldMan->avliable_at)->diffInSeconds($startAt) != 1){
return $this->setError('续住开始时间异常,请刷新重试!');
}
@ -68,7 +68,7 @@ class LiveContinueService extends OldmenService
$flow->save();
//更新客人信息状态;
$oldMan->update([
'live_in' => Oldmen::STATUS_LIVE,
'need_pay' => Oldmen::PAY_NORMAL,
'avliable_at' => $endAt,
'nurse_lv' => $newLv,
]);

View File

@ -0,0 +1,67 @@
<?php
namespace App\Services\Admin;
use App\Models\Oldmen;
use App\Models\ConstFlow;
use DB;
use Throwable;
/**
* @method Oldmen getModel()
* @method Oldmen|\Illuminate\Database\Query\Builder query()
*/
class LiveExitService extends OldmenService
{
public function do($oldManId, $feeArr = null){
$oldMan = $this->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('未找到客人信息!');
}
}
}