@@ -415,6 +415,8 @@ public function serverCreation(Request $request)
415415 ]);
416416 return redirect ('/dashboard/server/create ' )->with ('success ' , '成功花費 $ ' . number_format ($ price , 2 ) . ' SDC 創建伺服器! ' );
417417 } else {
418+ $ user ->increment ('coins ' , $ price );
419+ $ user ->save ();
418420 return redirect ('/dashboard/server/create ' )->with ('error ' , '創建伺服器時發生錯誤 ' . $ res );
419421 }
420422 }
@@ -483,6 +485,8 @@ public function unsuspendServer(Request $request)
483485 ]);
484486 return redirect ('/dashboard/server/manage ' )->with ('success ' , '成功花費 $ ' . number_format ($ price , 2 ) . ' SDC 續約伺服器 ' );
485487 } else {
488+ $ user ->increment ('coins ' , $ price );
489+ $ user ->save ();
486490 return redirect ('/dashboard/server/manage ' )->with ('error ' , '續約伺服器時發生錯誤 ' . $ res );
487491 }
488492 } else {
@@ -572,7 +576,18 @@ public function modifyServer(Request $request)
572576 if ($ total ['ports ' ] - $ resData ['attributes ' ]['feature_limits ' ]['allocations ' ] + $ data ['ports ' ] > $ user ->ports ) {
573577 return redirect ('/dashboard/server/manage ' )->with ('error ' , '你沒有那麼多 Ports 資源來編輯這個伺服器 ' );
574578 }
575-
579+ $ new_price = config ('shdactyl.fee.create ' ) * config ('shdactyl.fee.node. ' . $ resData ['attributes ' ]['node ' ]) * ((config ('shdactyl.fee.resource.cpu ' ) * $ data ['cpu ' ]) + (config ('shdactyl.fee.resource.ram ' ) * $ data ['ram ' ]) + (config ('shdactyl.fee.resource.disk ' ) * $ data ['disk ' ]) + (config ('shdactyl.fee.resource.databases ' ) * $ data ['databases ' ]) + (config ('shdactyl.fee.resource.backups ' ) * $ data ['backups ' ]) + (config ('shdactyl.fee.resource.ports ' ) * $ data ['ports ' ]));
580+ $ old_price = config ('shdactyl.fee.create ' ) * config ('shdactyl.fee.node. ' . $ resData ['attributes ' ]['node ' ]) * ((config ('shdactyl.fee.resource.cpu ' ) * $ resData ['attributes ' ]['limits ' ]['cpu ' ]) + (config ('shdactyl.fee.resource.ram ' ) * $ resData ['attributes ' ]['limits ' ]['memory ' ]) + (config ('shdactyl.fee.resource.disk ' ) * $ resData ['attributes ' ]['limits ' ]['disk ' ]) + (config ('shdactyl.fee.resource.databases ' ) * $ resData ['attributes ' ]['feature_limits ' ]['databases ' ]) + (config ('shdactyl.fee.resource.backups ' ) * $ resData ['attributes ' ]['feature_limits ' ]['backups ' ]) + (config ('shdactyl.fee.resource.ports ' ) * $ resData ['attributes ' ]['feature_limits ' ]['allocations ' ]));
581+ if ($ new_price < $ old_price ) {
582+ $ price = 0 ;
583+ } else {
584+ $ price = $ new_price - $ old_price ;
585+ }
586+ if ($ user ->coins < $ price ) {
587+ return redirect ('/dashboard/server/manage ' )->with ('error ' , '你沒有足夠的代幣來編輯伺服器 ' );
588+ }
589+ $ user ->decrement ('coins ' , $ price );
590+ $ user ->save ();
576591 $ response = Http::withHeaders ([
577592 'Accept ' => 'application/json ' ,
578593 'Authorization ' => $ auth ,
@@ -601,7 +616,7 @@ public function modifyServer(Request $request)
601616 [
602617 'title ' => '[編輯伺服器] ' ,
603618 'description ' => '帳號:<@ ' . $ user ->discord_id . '> ( ' . $ user ->discord_id . ')\n ' .
604- '伺服器識別碼: ' . $ serverData ['attributes ' ]['identifier ' ] . '\n伺服器名稱: ' . $ serverData ['attributes ' ]['name ' ] . '\n節點識別碼: ' . $ serverData ['attributes ' ]['node ' ] . '\n處理器: ' . $ serverData ['attributes ' ]['limits ' ]['cpu ' ] . '%\n記憶體: ' . $ serverData ['attributes ' ]['limits ' ]['memory ' ] . ' MiB\n儲存空間: ' . $ serverData ['attributes ' ]['limits ' ]['disk ' ] . ' MiB\n資料庫: ' . $ serverData ['attributes ' ]['feature_limits ' ]['databases ' ] . ' 個\n額外端口: ' . $ serverData ['attributes ' ]['feature_limits ' ]['allocations ' ] . ' 個\n備份欄位: ' . $ serverData ['attributes ' ]['feature_limits ' ]['backups ' ] . ' 個 ' ,
619+ '伺服器識別碼: ' . $ serverData ['attributes ' ]['identifier ' ] . '\n伺服器名稱: ' . $ serverData ['attributes ' ]['name ' ] . '\n節點識別碼: ' . $ serverData ['attributes ' ]['node ' ] . '\n花費:$ ' . number_format ( $ price , 2 ) . ' SDC\ n處理器: ' . $ serverData ['attributes ' ]['limits ' ]['cpu ' ] . '%\n記憶體: ' . $ serverData ['attributes ' ]['limits ' ]['memory ' ] . ' MiB\n儲存空間: ' . $ serverData ['attributes ' ]['limits ' ]['disk ' ] . ' MiB\n資料庫: ' . $ serverData ['attributes ' ]['feature_limits ' ]['databases ' ] . ' 個\n額外端口: ' . $ serverData ['attributes ' ]['feature_limits ' ]['allocations ' ] . ' 個\n備份欄位: ' . $ serverData ['attributes ' ]['feature_limits ' ]['backups ' ] . ' 個 ' ,
605620 'color ' => '#03cafc ' ,
606621 'footer ' => [
607622 'icon_url ' => config ('shdactyl.webhook.icon_url ' ),
@@ -614,8 +629,10 @@ public function modifyServer(Request $request)
614629 ],
615630 ]
616631 ]);
617- return redirect ('/dashboard/server/manage ' )->with ('success ' , '成功編輯伺服器 ' );
632+ return redirect ('/dashboard/server/manage ' )->with ('success ' , '成功花費 $ ' . number_format ( $ price , 2 ) . ' SDC 編輯伺服器 ' );
618633 } else {
634+ $ user ->increment ('coins ' , $ price );
635+ $ user ->save ();
619636 return redirect ('/dashboard/server/manage ' )->with ('error ' , '編輯伺服器時發生錯誤 ' . $ response );
620637 }
621638 } else {
@@ -639,6 +656,11 @@ public function redeemCoupon(Request $request)
639656 ->whereJsonContains ('content->code ' , $ realCoupon ->code )->first ();
640657
641658 if (!$ history ) {
659+
660+ $ user ->increment ('coins ' , $ realCoupon ->coins );
661+ $ user ->save ();
662+ $ realCoupon ->used_times ++;
663+ $ realCoupon ->save ();
642664 ActionLog::create ([
643665 'action_type ' => 'resource.coupon.redeem ' ,
644666 'user_id ' => $ user ->id ,
@@ -664,10 +686,6 @@ public function redeemCoupon(Request $request)
664686 ],
665687 ]
666688 ]);
667- $ user ->increment ('coins ' , $ realCoupon ->coins );
668- $ user ->save ();
669- $ realCoupon ->used_times ++;
670- $ realCoupon ->save ();
671689 return redirect ('/dashboard/resource/coupon ' )->with ('success ' , '成功兌換名為 " ' . $ realCoupon ->name . '" 的代碼並獲得了 $ ' . $ realCoupon ->coins . ' SDC ' );
672690
673691 } else {
0 commit comments