浏览代码

fix: 🚑️ Fixed credits check at server creation & formatted prices nicely

IceToast 2 年之前
父节点
当前提交
87ec49008d

+ 1 - 1
app/Console/Commands/ChargeServers.php

@@ -91,7 +91,7 @@ class ChargeServers extends Command
                 }
 
                 // check if the server is canceled or if user has enough credits to charge the server or
-                if ( $server->cancelled || $user->credits < $product->price) {
+                if ( $server->cancelled || $user->credits <= $product->price) {
                     try {
                         // suspend server
                         $this->line("<fg=yellow>{$server->name}</> from user: <fg=blue>{$user->name}</> has been <fg=red>suspended!</>");

+ 2 - 1
app/Http/Controllers/ServerController.php

@@ -131,7 +131,8 @@ class ServerController extends Controller
                 Auth::user()->credits <
                 ($product->minimum_credits == -1
                     ? config('SETTINGS::USER:MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER', 50)
-                    : $product->minimum_credits)
+                    : $product->minimum_credits) ||
+                Auth::user()->credits <= $product->price
             ) {
                 return redirect()->route('servers.index')->with('error', 'You do not have the required amount of '.CREDITS_DISPLAY_NAME.' to use this product!');
             }

+ 1 - 1
resources/views/servers/index.blade.php

@@ -188,7 +188,7 @@
                                         @endif
                                             </div>
                                         <span>
-                                            {{ $server->product->price }}
+                                            {{ number_format($server->product->price) }}
                                         </span>
                                     </div>
                                 </div>

+ 17 - 8
themes/default/views/servers/create.blade.php

@@ -239,14 +239,14 @@
                                         <input type="hidden" name="product" x-model="selectedProduct">
                                     </div>
                                     <div>
-                                        <button type="submit" x-model="selectedProduct" name="product"
-                                            :disabled="product.minimum_credits > user.credits || product.doesNotFit == true ||
-                                                submitClicked"
-                                            :class="product.minimum_credits > user.credits || product.doesNotFit == true ||
-                                                submitClicked ? 'disabled' : ''"
-                                            class="btn btn-primary btn-block mt-2" @click="setProduct(product.id);"
-                                            x-text=" product.doesNotFit == true ? '{{ __('Server cant fit on this Node') }}' : (product.minimum_credits > user.credits ? '{{ __('Not enough') }} {{ CREDITS_DISPLAY_NAME }}!' : '{{ __('Create server') }}')">
-                                        </button>
+										<button type="submit" x-model="selectedProduct" name="product"
+        									:disabled="product.minimum_credits > user.credits || product.price > user.credits || product.doesNotFit == true ||
+            									submitClicked"
+       										:class="product.minimum_credits > user.credits || product.price > user.credits || product.doesNotFit == true ||
+            									submitClicked ? 'disabled' : ''"
+        									class="btn btn-primary btn-block mt-2" @click="setProduct(product.id);"
+        									x-text="product.doesNotFit == true ? '{{ __('Server cant fit on this Node') }}' : (product.minimum_credits > user.credits || product.price > user.credits ? '{{ __('Not enough') }} {{ CREDITS_DISPLAY_NAME }}!' : '{{ __('Create server') }}')">
+    									</button>
                                     </div>
                                 </div>
                             </div>
@@ -376,6 +376,7 @@
                         .catch(console.error)
 
                     this.fetchedProducts = true;
+
                     // TODO: Sortable by user chosen property (cpu, ram, disk...)
                     this.products = response.data.sort((p1, p2) => parseInt(p1.price, 10) > parseInt(p2.price, 10) &&
                         1 || -1)
@@ -385,11 +386,19 @@
                         product.cpu = product.cpu / 100;
                     })
 
+                    //format price to have no decimals if it is a whole number
+                    this.products.forEach(product => {
+                        if (product.price % 1 === 0) {
+                            product.price = Math.round(product.price);
+                        }
+                    })
+
 
                     this.loading = false;
                     this.updateSelectedObjects()
                 },
 
+
                 /**
                  * @description map selected id's to selected objects
                  * @note being used in the server info box