Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Classes;
  4.  
  5. use App\Models\ProductBonus;
  6. use App\Models\Product;
  7.  
  8. use App\Models\Setting;
  9.  
  10. class Rabatt
  11. {
  12. public static function rabattpriceformat($cent, $pid = 0, $amount = 0) {
  13. return self::withoutCurrencyX($cent, $pid, $amount) . ' ' . Setting::getShopCurrency();
  14. }
  15.  
  16. public static function withoutCurrencyX($cent, $pid, $a) {
  17. return number_format(self::rabattprice($cent, $pid, $a) / 100, 2, ',', '.');
  18. }
  19.  
  20. public static function rabattprice($price, $productId = 0, $amount = 0) {
  21. return floor($price * self::rab($productId, $amount));
  22. }
  23.  
  24. public static function priceProduct($pid, $amount = 1) {
  25. $product = Product::where('id', $pid)->get()->first();
  26.  
  27. if($product != null) {
  28. $bonuses = ProductBonus::where('product_id', $pid)->orderByDesc('min_amount')->get();
  29.  
  30. foreach($bonuses as $bonus) {
  31. if($amount >= $bonus->min_amount) {
  32. return floor($product->price_in_cent * $bonus->percent);
  33. }
  34. }
  35.  
  36. return $product->price_in_cent;
  37. }
  38.  
  39. return 0;
  40. }
  41.  
  42. public static function rabX($pid, $amount) {
  43. $product = Product::where('id', $pid)->get()->first();
  44.  
  45. if($product != null) {
  46. $bonuses = ProductBonus::where('product_id', $pid)->orderByDesc('min_amount')->get();
  47.  
  48. foreach($bonuses as $bonus) {
  49. if($amount >= $bonus->min_amount) {
  50. return $bonus->percent;
  51. }
  52. }
  53. }
  54.  
  55. return 1;
  56. }
  57.  
  58. public static function rab($pid, $amount) {
  59. $product = Product::where('id', $pid)->get()->first();
  60.  
  61. if($product != null) {
  62. $bonuses = ProductBonus::where('product_id', $pid)->orderByDesc('min_amount')->get();
  63.  
  64. foreach($bonuses as $bonus) {
  65. if($amount >= $bonus->min_amount) {
  66. return $bonus->percent;
  67. }
  68. }
  69. }
  70.  
  71. return 1;
  72. }
  73.  
  74. public static function newprice($price, $productId = 0, $amount = 0) {
  75. if(self::rab($productId, $amount) == 1) {
  76. return $price;
  77. }
  78. return $price - floor($price * self::rab($productId, $amount));
  79. }
  80.  
  81. public static function price($price) {
  82. return $price;
  83. }
  84.  
  85. public static function priceformat($cent) {
  86. return self::withoutCurrency($cent) . ' ' . Setting::getShopCurrency();
  87. }
  88.  
  89. public static function priceformat2($cent) {
  90. return self::withoutCurrency2($cent) . ' ' . Setting::getShopCurrency();
  91. }
  92.  
  93. public static function withoutCurrency($cent) {
  94. return number_format(self::price($cent) / 100, 2, ',', '.');
  95. }
  96.  
  97. public static function withoutCurrency2($cent) {
  98. return number_format(self::price2($cent) / 100, 2, ',', '.');
  99. }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement