From 7a38edb865d4734914b0d5d2d5f8e57a68ed59bd Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Sat, 16 Sep 2023 11:19:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E7=8B=AC=E6=B0=B4?= =?UTF-8?q?=E7=94=B5=E7=BB=AD=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HydropowerFeeController.php | 110 ++++++++++++++++++ .../Controllers/LiveContinueController.php | 2 +- app/Filters/Admin/HydropowerFeeFilter.php | 37 ++++++ app/Http/Controllers/PrintController.php | 64 ++++++++-- app/Models/ConstFlow.php | 4 +- app/Models/HydropowerFee.php | 45 +++++++ app/Services/Admin/HydropowerFeeService.php | 21 ++++ app/Services/Admin/LiveContinueService.php | 13 ++- ...16_094748_create_hydropower_fees_table.php | 33 ++++++ resources/views/print-water-fee.blade.php | 100 ++++++++++++++++ routes/admin.php | 4 +- routes/web.php | 3 +- 12 files changed, 421 insertions(+), 15 deletions(-) create mode 100644 app/Admin/Controllers/HydropowerFeeController.php create mode 100644 app/Filters/Admin/HydropowerFeeFilter.php create mode 100644 app/Models/HydropowerFee.php create mode 100644 app/Services/Admin/HydropowerFeeService.php create mode 100644 database/migrations/2023_09_16_094748_create_hydropower_fees_table.php create mode 100644 resources/views/print-water-fee.blade.php diff --git a/app/Admin/Controllers/HydropowerFeeController.php b/app/Admin/Controllers/HydropowerFeeController.php new file mode 100644 index 0000000..d934a19 --- /dev/null +++ b/app/Admin/Controllers/HydropowerFeeController.php @@ -0,0 +1,110 @@ +baseCRUD() + ->filterTogglable(false) + ->headerToolbar([ + $this->createButton(true, 'lg'), + ...$this->baseHeaderToolBar() + ]) + ->filter( + $this->baseFilter()->body([ + amisMake()->TextControl('name', '姓名')->size('md'), + amisMake()->TextControl('card_no', '身份证')->size('md'), + amisMake()->TextControl('sn', '单据编号')->size('md'), + amis('button')->label(__('admin.reset'))->actionType('clear-and-submit'), + amis('submit')->label(__('admin.search'))->level('primary'), + ])->actions([]) + ) + ->columns([ + amisMake()->TableColumn('sn', '单据编号')->sortable(), + amisMake()->TableColumn('oldman.name', '客人'), + amisMake()->TableColumn('start_at', '开始时间')->type('datetime')->sortable(true), + amisMake()->TableColumn('end_at', '结束时间')->type('datetime')->sortable(true), + amisMake()->TableColumn('money', '金额'), + amisMake()->TableColumn('created_at', '办理时间')->type('datetime')->sortable(true), + amisMake()->Operation()->label(__('admin.actions'))->buttons([ + amisMake()->Button()->label('打印预览')->actionType('url')->blank(true) + ->url(url('/print-water-fee').'?id=${id}')->level('link'), + $this->rowEditButton(true, 'lg'), + $this->rowDeleteButton() + ]), + ]); + + return $this->baseList($crud); + } + + public function form($isEdit = false): Form + { + return $this->baseForm()->body([ + amisMake()->PickerControl('oldman_id', '姓名') + ->valueField('id') + ->labelField('name') + ->joinValues(false)->extractValue(true) + ->size('md') + ->source([ + 'method' => 'get', + 'url' => admin_url('oldmen?_action=getData&live_in='.Oldmen::STATUS_NORMAL), + 'data' => [ + 'name'=>'${term}', + ] + ]) + ->pickerSchema( + [ + 'mode' => 'table', + 'name' => 'monitor_list', + 'headerToolbar' => amisMake()->form() + ->wrapWithPanel(false) + ->className('text-right') + ->target('monitor_list') + ->mode('inline') + ->body([ + amisMake()->TextControl('term', '姓名/身份证号')->addOn( + amis('submit')->label(__('admin.search'))->level('primary') + ) + ]), + 'columns' => [ + TableColumn::make()->name('name')->label('姓名'), + TableColumn::make()->name('card_no')->label('身份证号码'), + ] + ] + )->value(0) + ->required(true), + amisMake()->GroupControl()->body([ + amisMake()->DateControl('start_at', '开始时间')->format('YYYY-MM-DD 00:00:00')->required(true), + amisMake()->DateControl('end_at', '结束时间')->format('YYYY-MM-DD 23:59:59')->required(true), + ]), + Components::make()->decimalControl('money', '金额')->required(true), + + ]); + } + + public function detail(): Form + { + return $this->baseDetail()->body([ + amisMake()->TextControl('id', 'ID')->static(), + amisMake()->TextControl('created_at', __('admin.created_at'))->static(), + amisMake()->TextControl('updated_at', __('admin.updated_at'))->static() + ]); + } +} diff --git a/app/Admin/Controllers/LiveContinueController.php b/app/Admin/Controllers/LiveContinueController.php index c7bbafc..5f35044 100644 --- a/app/Admin/Controllers/LiveContinueController.php +++ b/app/Admin/Controllers/LiveContinueController.php @@ -20,7 +20,7 @@ class LiveContinueController extends AdminController $crud = $this->baseCRUD() ->filterTogglable(false) ->headerToolbar([ - amis('button')->label('续住')->icon('fa fa-plus')->actionType('link')->level('primary')->link('live-in-continue'), + amis('button')->label('续住')->icon('fa fa-plus')->actionType('link')->level('primary')->link('live-continue-do'), ]) ->filter( $this->baseFilter()->body([ diff --git a/app/Filters/Admin/HydropowerFeeFilter.php b/app/Filters/Admin/HydropowerFeeFilter.php new file mode 100644 index 0000000..d51aa68 --- /dev/null +++ b/app/Filters/Admin/HydropowerFeeFilter.php @@ -0,0 +1,37 @@ +where('oldman_id', $oldmanId); + } + + public function sn($sn){ + return $this->where('sn', $sn); + } + + /** + * 名称 + */ + public function name($name){ + return $this->whereHas('oldman', function($q) use ($name) { + return $q->where('name', 'like', '%'.$name.'%'); + }); + } + + /** + * 身份证 + */ + public function cardNo($cardNo){ + return $this->whereHas('oldman', function($q) use ($cardNo) { + return $q->where('card_no', 'like', '%'.$cardNo.'%'); + }); + } +} diff --git a/app/Http/Controllers/PrintController.php b/app/Http/Controllers/PrintController.php index 3761be4..11df203 100644 --- a/app/Http/Controllers/PrintController.php +++ b/app/Http/Controllers/PrintController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\Models\ConstFlow; +use App\Models\{ConstFlow, HydropowerFee}; use Illuminate\Http\Request; use App\Services\Admin\ConstFlowService; @@ -65,6 +65,50 @@ class PrintController extends Controller return view('print-const', compact('name', 'time', 'idsn', 'list', 'total', 'bigTotal', 'timeZone', 'adminName')); } + public function showWaterFee(Request $request){ + $name = ''; + $time = now()->format('Y-m-d H:i:s'); + $sn = ''; + //默认list最少N行,最多N行; + $list = []; + $total = 0; + $bigTotal = ''; + $adminName = ''; + $timeZone = ''; + + $flow = HydropowerFee::find($request->input('id', 0)); + if($flow){ + $flow->load(['oldman', 'adminuser']); + $name = $flow->oldman->name; + $time = $flow->created_at->format('Y-m-d H:i:s'); + $sn = $flow->sn; + $i = 1; + $list[] = [ + 'fee_name' => '水电缴费', + 'fee_value' => $flow->money, + ]; + for($i; $i<4; $i++){ + $list[] = [ + 'fee_name' => '', + 'fee_value' => 0, + ]; + } + if(count($list) > 0){ + $total = collect($list)->sum('fee_value'); + if($total > 0){ + $bigTotal = $this->num2chinese($total); + }else{ + $bigTotal = '负'.$this->num2chinese(abs($total)); + } + } + + $adminName = $flow->adminuser->name; + $timeZone = substr($flow->start_at, 0, 10).'至'.substr($flow->end_at, 0, 10); + } + + return view('print-water-fee', compact('name', 'time', 'list', 'total', 'bigTotal', 'timeZone', 'adminName', 'sn')); + } + private function num2chinese($num) { $cnNums = array( @@ -75,7 +119,7 @@ class PrintController extends Controller $cnDecUnits = array("角", "分"); $cnInteger = "整"; - $intStr = (string)$num; + $intStr = (string)floor($num); $len = strlen($intStr); if ($len > 15 || $num < 0) { return false; // 超出处理范围 @@ -87,6 +131,7 @@ class PrintController extends Controller $zeroCount = 0; $outChinese = ""; + //处理整数部分 for ($i = 0; $i < $len; $i++) { $idx = $len - $i - 1; $thisNum = (int)$intStr[$idx]; @@ -98,18 +143,21 @@ class PrintController extends Controller $outChinese = "零" . $outChinese; // 处理零 } $zeroCount = 0; - $outChinese = $cnNums[$thisNum] . $cnIntUnits[$i % 4] . $outChinese; - if ($i % 4 == 0) { - $outChinese = $cnIntRadice[$i / 4] . $outChinese; + if ($i > 0 && $i % 4 == 0) { + $outChinese = $cnNums[$thisNum] .$cnIntRadice[$i / 4] . $outChinese; + }else{ + $outChinese = $cnNums[$thisNum] . $cnIntUnits[$i % 4] . $outChinese; } } - + if ($zeroCount > 0) { - $outChinese = "零" . $outChinese; // 处理最后的零 + $outChinese = '零'.$outChinese; // 处理最后的零 + }else{ + $outChinese = rtrim($outChinese,'零'); // 处理最后的零 } $outChinese .= "元"; - + // 处理小数部分 if (strpos($num, '.') !== false) { $decPart = substr($num, strpos($num, '.') + 1); diff --git a/app/Models/ConstFlow.php b/app/Models/ConstFlow.php index 0cf2f47..ca1e75c 100644 --- a/app/Models/ConstFlow.php +++ b/app/Models/ConstFlow.php @@ -51,8 +51,8 @@ class ConstFlow extends Model { parent::boot(); // 监听 flow 创建事件,创建sn; - static::creating(function ($oldmen) { - $oldmen->sn = self::createSn(); + static::creating(function ($constFlow) { + $constFlow->sn = self::createSn(); }); } diff --git a/app/Models/HydropowerFee.php b/app/Models/HydropowerFee.php new file mode 100644 index 0000000..3af2a67 --- /dev/null +++ b/app/Models/HydropowerFee.php @@ -0,0 +1,45 @@ +belongsTo(Oldmen::class, 'oldman_id'); + } + + public function adminuser(){ + return $this->belongsTo(AdminUser::class, 'adminuser_id'); + } + + protected static function boot() + { + parent::boot(); + // 监听 flow 创建事件,创建sn; + static::creating(function ($hydropowerFee) { + if(empty($hydropowerFee->sn)){ + $hydropowerFee->sn = self::createSn(); + } + if(empty($hydropowerFee->adminuser_id)){ + $hydropowerFee->adminuser_id = OwlAdmin::user()->id; + } + }); + } + + private static function createSn() + { + return Carbon::now()->isoFormat('YYMMDDHHmmss').rand(1000, 9999); + } +} diff --git a/app/Services/Admin/HydropowerFeeService.php b/app/Services/Admin/HydropowerFeeService.php new file mode 100644 index 0000000..29d126a --- /dev/null +++ b/app/Services/Admin/HydropowerFeeService.php @@ -0,0 +1,21 @@ + $endAt, 'nurse_lv' => $newLv, ]); + //同步水电费 + if(isset($feeArr['live_fee']['water_fee']) && $feeArr['live_fee']['water_fee'] > 0){ + HydropowerFee::create([ + 'oldman_id' => $flow->oldman_id, + 'start_at' => $flow->start_at, + 'end_at' => $flow->end_at, + 'sn' => str_pad($flow->id, 6, '0',STR_PAD_LEFT), + 'adminuser_id'=> $flow->adminuser_id, + 'money' => $feeArr['live_fee']['water_fee'] + ]); + } DB::commit(); }catch(Throwable $th){ DB::rollBack(); diff --git a/database/migrations/2023_09_16_094748_create_hydropower_fees_table.php b/database/migrations/2023_09_16_094748_create_hydropower_fees_table.php new file mode 100644 index 0000000..dc4a200 --- /dev/null +++ b/database/migrations/2023_09_16_094748_create_hydropower_fees_table.php @@ -0,0 +1,33 @@ +id(); + $table->unsignedBigInteger('oldman_id'); + $table->string('sn')->comment('流水编号'); + $table->timestamp('start_at')->nullable()->comment('开始时间'); + $table->timestamp('end_at')->nullable()->comment('结束时间'); + $table->decimal('money', 10, 2)->default(0.00)->nullable()->comment('金额'); + $table->unsignedBigInteger('adminuser_id')->comment('操作人'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('hydropower_fees'); + } +}; diff --git a/resources/views/print-water-fee.blade.php b/resources/views/print-water-fee.blade.php new file mode 100644 index 0000000..cc21b8d --- /dev/null +++ b/resources/views/print-water-fee.blade.php @@ -0,0 +1,100 @@ + + + + + 打印 + + + + + + + + \ No newline at end of file diff --git a/routes/admin.php b/routes/admin.php index 46bca50..d8d147d 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -10,7 +10,7 @@ Route::group([ 'prefix' => config('admin.route.prefix'), 'middleware' => config('admin.route.middleware'), ], function (Router $router) { - // 费用明细 - $router->resource('const_flows', \App\Admin\Controllers\ConstFlowController::class); + // 水电续费 + $router->resource('hydropower_fees', \App\Admin\Controllers\HydropowerFeeController::class); }); \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 05432a8..9fe9431 100644 --- a/routes/web.php +++ b/routes/web.php @@ -16,4 +16,5 @@ use Illuminate\Support\Facades\Route; Route::redirect('/', '/admin', 302); -Route::get('/print-const-flow', [PrintController::class, 'showConst']); \ No newline at end of file +Route::get('/print-const-flow', [PrintController::class, 'showConst']); +Route::get('/print-water-fee', [PrintController::class, 'showWaterFee']); \ No newline at end of file