My SMM panel
 
 
 
 
 
 

128 line
3.1 KiB

  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Http;
  5. use Illuminate\Support\Facades\Log;
  6. use App\Models\Supplier;
  7. use App\Models\Order;
  8. class Supply extends Controller
  9. {
  10. // Accepts a site name, service id, and integer/array of supplier rows to
  11. // create
  12. public static function fetch($site) {
  13. return Http::post(config("services.$site.link"), ['key' =>
  14. config("services.$site.key"), 'action' => 'services']);
  15. }
  16. public static function smmkings($service_id, $id) {
  17. $services = Http::post(config("services.smmkings.link"), ['key' =>
  18. config("services.smmkings.key"), 'action' => 'services'])->json();
  19. foreach ($services as $service) {
  20. if ($service['service'] == $id){
  21. $s = new Supplier;
  22. $s->service_id = $service_id;
  23. $s->supplier = 'smmkings';
  24. $s->supplier_id = (int) $service['service'];
  25. $s->supplier_name = $service['name'];
  26. $s->min = (int) $service['min'];
  27. $s->max = (int) $service['max'];
  28. $s->cost = $service['rate'] * 100;
  29. $s->save();
  30. return $s;
  31. }
  32. }
  33. }
  34. public static function smmworld($service_id, $id) {
  35. $services = Http::post(config("services.smmworld.link"), ['key' =>
  36. config("services.smmworld.key"), 'action' => 'services']);
  37. $services = $services['services'];
  38. foreach ($services as $service) {
  39. if ($service['id'] == $id){
  40. $s = new Supplier;
  41. $s->service_id = $service_id;
  42. $s->supplier = 'smmworld';
  43. $s->supplier_id = $service['id'];
  44. $s->supplier_name = $service['name'];
  45. $s->min = $service['min'];
  46. $s->max = $service['max'];
  47. $s->cost = $service['price_per_k'] * 100;
  48. $s->save();
  49. return $s;
  50. }
  51. }
  52. }
  53. public static function fulfill($order) {
  54. if (gettype($order) == 'integer') {
  55. $order = Order::find($order);
  56. }
  57. return Supply::orderPrimary($order);
  58. }
  59. public static function fulfillAny($order) {
  60. if (gettype($order) == 'integer') {
  61. $order = Order::find($order);
  62. }
  63. if (Supply::orderPrimary($order)) {
  64. };
  65. }
  66. public static function orderPrimary($order) {
  67. if (gettype($order) == 'integer') {
  68. $order = Order::find($order);
  69. }
  70. $primary = $order->service->primary;
  71. switch ($primary->supplier) {
  72. case 'smmkings':
  73. return Supply::orderSmmkings($order, $primary);
  74. break;
  75. case 'smmworld':
  76. return Supply::orderSmmworld($order, $primary);
  77. break;
  78. }
  79. }
  80. public static function orderSmmkings($order, $supplier) {
  81. if ($supplier->supplier != 'smmkings') {
  82. return false;
  83. }
  84. $response = Http::post(config("services.smmkings.link"), ['key' =>
  85. config("services.smmkings.key"), 'action' => 'add',
  86. 'service' => $supplier->supplier_id, 'link' =>
  87. $order->url, 'quantity' => $order->quantity])->json();
  88. return $response;
  89. }
  90. public static function orderSmmworld($order, $supplier) {
  91. if ($supplier->supplier != 'smmworld') {
  92. return false;
  93. }
  94. $response = Http::post(config("services.smmworld.link"), ['key' =>
  95. config("services.smmworld.key"), 'action' => 'add',
  96. 'service' => $supplier->supplier_id, 'link' => $order->url, 'quantity' =>
  97. $order->quantity])->json();
  98. return $response;
  99. }
  100. }