namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Helpers\Anhyeuem37; use App\Helpers\Smm as Smm_Global; use Illuminate\Validation\Rule; use Illuminate\Http\Response; use App\Models\Server; use App\Models\Services; use App\Models\Subcategory; use App\Models\Category; use App\Models\Orders; use App\Models\Card; use App\Models\Ticket; use App\Models\Activity_log; use App\Models\SmmPanel_Activity; use App\Models\SmmPanel; use App\Models\SmmPanel_percent; use App\Models\User; use App\Models\Websites; use App\Models\Settings; use App\Models\Transaction; use App\Models\History_order; use App\Http\Controllers\ApiLive; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; use Illuminate\Support\Facades\DB; class Api extends Controller { public function v2(request $request) { if ($request->action == "services") { $servers = Server::where("status", 1)->get(); $data = array(); foreach ($servers as $server) { $services = Subcategory::where("id", $server["id_service"])->where("status", 1)->first(); if ($services) { $category = Category::where("id", $services["id_category"])->where("status", 1)->first(); if ($category) { if ($server["speed"] == 1) { $type = "Special"; } elseif ($server["comment"] == 0) { $type = "Default"; } elseif ($server["comment"] == 1) { $type = "Custom Comments"; } $data[] = array("service" => $server["id"], "platform" => $category["name"], "category" => $services["name"], "name" => $server["detail"], "type" => $type, "rate" => $server["price"], "min" => $server["min"], "max" => $server["max"], "note" => $server["note"]); } } } return response()->json($data, 200, array(), JSON_PRETTY_PRINT); } elseif ($request->action == "add") { $validator = Validator::make($request->all(), array("link" => "required", "service" => "required|numeric", "quantity" => array("nullable", "numeric", Rule::requiredIf(function () use($request) { return empty($request->comments); }))), array("link.required" => "Invalid Link !", "service.required" => "Invalid service !", "service.numeric" => "Invalid service !", "quantity.numeric" => "Invalid quantity !", "quantity.required" => "Invalid quantity !")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("error" => $firstErrorMessage), 422); } $requestData = $request->toArray(); if (isset($requestData["comments"])) { $comments = explode("\xa", $requestData["comments"]); $requestData["quantity"] = count($comments); } $server = Server::where("id", $requestData["service"])->first(); if ($server) { if ($requestData["quantity"] < $server["min"] || $requestData["quantity"] > $server["max"]) { return response()->json(array("error" => "Invalid quantity"), 401); } if ($server->gioihan != 0) { $originalLink = $requestData["link"]; $cleanedLink = strtok($originalLink, "?"); $cleanedLink = rtrim($cleanedLink, "/"); $existingOrder = Orders::where(function ($query) use($originalLink, $cleanedLink) { $query->where("link", $originalLink)->orWhere("link", $cleanedLink); })->first(); if ($existingOrder) { return response()->json(array("error" => "Tham lam... Link/video này đã đạt giới hạn mua rồi nha !"), 401); } } $total = 0; $user = User::where("token", $requestData["key"])->first(); $level = $user->level >= 1 ? "level" . $user->level : "price"; $total = $server->{$level} * $requestData["quantity"]; if ($total > $user->balance) { return response()->json(array("error" => "Balance not enough !"), 401); } if ($server->gioihan != 0) { $cleanedLink = strtok($requestData["link"], "?"); $cleanedLink = rtrim($cleanedLink, "/"); $existingIds = Orders::pluck("id_order")->toArray(); do { $id_order = mt_rand(1000000, 9999999); } while (in_array($id_order, $existingIds)); $data = array("id_order" => $id_order, "link" => $cleanedLink, "server" => $requestData["service"], "total" => $total, "reaction" => isset($requestData["reaction"]) ? $requestData["service"] : "like", "quantity" => $requestData["quantity"], "username" => $user->username, "status" => "inprogress"); $fields = array("speed", "minutes", "time", "days"); } else { $existingIds = Orders::pluck("id_order")->toArray(); do { $id_order = mt_rand(1000000, 9999999); } while (in_array($id_order, $existingIds)); $data = array("id_order" => $id_order, "link" => $requestData["link"], "server" => $requestData["service"], "total" => $total, "reaction" => isset($requestData["reaction"]) ? $requestData["service"] : "like", "quantity" => $requestData["quantity"], "username" => $user->username, "status" => "inprogress"); $fields = array("speed", "minutes", "time", "days"); } foreach ($fields as $field) { if (isset($requestData[$field])) { $data[$field] = $requestData[$field]; } } if (isset($requestData["comments"])) { $data["quantity"] = $requestData["quantity"]; $data["comments"] = $requestData["comments"]; } else { $data["quantity"] = $requestData["quantity"]; } if (isset($requestData["comments"])) { $data["comments"] = $requestData["comments"]; } else { if (isset($requestData["reaction"])) { $data["reaction"] = $requestData["reaction"]; } else { $data["reaction"] = "like"; } } $apiLive = new ApiLive(); $apiResult = $apiLive->checkapi($data); if (!$apiResult["status"]) { return response()->json(array("error" => $apiResult["message"]), 401); } $user->update(array("balance" => $user->balance - $total)); $newOrder = Orders::create($data); if (isset($apiResult["order_api"])) { $newOrder->order_smm = $apiResult["order_api"]; if (isset($apiResult["type"])) { $newOrder->type = $apiResult["type"]; } $newOrder->save(); } History_order::create(array("type" => "-", "begin_balance" => $user->balance + $total, "quantity_balance" => $total, "change_balance" => $user->balance - $total, "note" => "Đơn hàng #" . $newOrder->id_order . " Tăng " . $requestData["quantity"] . "Seeding tại máy chủ " . $requestData["service"] . " trừ số tiền " . $total . " trong tài khoản", "username" => $user->username)); Activity_log::create(array("content" => "Tài khoản " . $user->username . " mua dịch vụ bằng API", "username" => $user->username)); $chatId = Settings::where("key", "telegram_chat_id")->first()->value; $tokenTelegram = Settings::where("key", "telegram")->first()->value; $message = "Đơn hàng mới từ API!\xa- Tài khoản: " . $user->username . " \xa- Mã đơn: " . $newOrder->id_order . "
- Số lượng: " . $requestData["quantity"] . "
- Link/ID: " . $requestData["link"] . "\xa- Máy chủ: " . $requestData["service"] . "\xa- Thanh toán: " . $total . " VND
"; if ($chatId && $tokenTelegram) { $result = Anhyeuem37::sendTelegramMessage($chatId, $tokenTelegram, $message); } return response()->json(array("order" => $newOrder->id_order), 200); } else { return response()->json(array("error" => "Invalid service !"), 401); } } elseif ($request->action == "status") { $validator = Validator::make($request->all(), array("orders" => "required_without:order"), array("orders.required_without" => "Incorrect order ID!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("error" => $firstErrorMessage), 422); } if ($request->orders) { $result = array(); $orderIds = explode(",", $request->orders); foreach ($orderIds as $orderId) { $key = User::where("token", $request->key)->first(); $orders = Orders::where("id_order", $orderId)->get(); if ($orders->isNotEmpty()) { foreach ($orders as $order) { if ($order->username != $key->username) { $result[$orderId] = array("error" => "Incorrect order ID"); } else { switch ($order->status) { case "pending": $order->status = "Pending"; break; case "inprogress": $order->status = "In progress"; break; case "processing": $order->status = "Processing"; break; case "success": $order->status = "Completed"; break; case "partial": $order->status = "Partial"; break; case "error": case "cancel": $order->status = "Canceled"; break; } $result[$orderId] = array("charge" => $order->total, "start_count" => $order->start, "status" => $order->status, "remains" => $order->quantity - $order->run); } } } else { $result[$orderId] = array("error" => "Incorrect order ID"); } } $new_array = $result; return response()->json($new_array, 200); } else { if ($request->order) { $order = Orders::where("id_order", $request->order)->first(); if ($order) { $key = User::where("token", $request->key)->first(); if ($order->username != $key->username) { return response()->json(array($request->order => array("error" => "Incorrect order ID")), 200); } else { switch ($order->status) { case "pending": $order->status = "Pending"; break; case "inprogress": $order->status = "In progress"; break; case "processing": $order->status = "Processing"; break; case "success": $order->status = "Completed"; break; case "partial": $order->status = "Partial"; break; case "error": case "cancel": $order->status = "Canceled"; break; } return response()->json(array($order->id_order => array("charge" => $order->total, "start_count" => $order->start, "status" => $order->status, "remains" => $order->quantity - $order->run)), 200); } } else { return response()->json(array($request->order => "Incorrect order ID"), 200); } } } } elseif ($request->action == "cancel") { $validator = Validator::make($request->all(), array("orders" => "required"), array("orders.required" => "Invalid ID Order !")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("order" => 1, "cancel" => array("error" => $firstErrorMessage)), 422); } $requestData = $request->toArray(); $orderId = $requestData["orders"]; $user = User::where("token", $requestData["key"])->first(); if (!$orderId) { return response()->json(array("order" => 1, "cancel" => array("error" => "Vui lòng nhập id_order")), 200); } if (!preg_match("/^[a-zA-Z0-9]+$/", $orderId)) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "id_order không hợp lệ!")), 200); } $order = Orders::where("id_order", $orderId)->first(); if (!$order) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Đơn hàng không tồn tại !")), 200); } if ($order->status == "success") { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Đơn hàng này đã hoàn thành không thể huỷ!")), 200); } elseif ($order->status == "error") { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Đơn hàng này đã được huỷ trước đó!")), 200); } elseif ($order->total == 0) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Máy chủ free không hỗ trợ huỷ !")), 200); } $server = Server::where("id", $order->server)->where("status", 1)->first(); if (!$server) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Server không tồn tại hoặc không hoạt động !")), 200); } $partner = SmmPanel::where("id", $server->smmpanel)->where("status", 1)->first(); if (!$partner) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Dịch vụ không tồn tại hoặc không hoạt động !")), 200); } Smm_Global::init(array("link" => $partner->link, "token" => $partner->token)); $data = array("key" => $partner->token, "action" => "cancel", "orders" => $order->order_smm); if ($partner->json == 1) { $data["service"] = (string) $data["service"]; $response = Smm_Global::connect($data, true); } else { $response = Smm_Global::connect($data); } $result = json_decode($response, true); if (isset($result[0]["cancel"]["error"])) { $errorMessage = $result[0]["cancel"]["error"]; if ($errorMessage == "error.cancel_unavailable") { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Hủy đơn thất bại, máy chủ không hỗ trợ hủy hoàn !")), 200); } else { return response()->json(array("order" => $orderId, "cancel" => array("error" => $errorMessage)), 200); } } elseif (isset($result[0]["cancel"]["error"]) && $result[0]["order"]) { $order->update(array("note" => "Gửi yêu cầu hủy đơn hàng thành công")); return response()->json(array("order" => $requestData["orders"], "cancel" => 1), 200); } else { if (!$order) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Đơn hàng không tồn tại!")), 200); } $existingTicket = Ticket::where("id_order", $request->orders)->first(); if ($existingTicket) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Mã đơn hàng này đã tồn tại hỗ trợ!")), 200); } $content = htmlspecialchars($request->content, ENT_QUOTES, "UTF-8"); $id = Ticket::create(array("id_order" => $request->orders, "title" => "Yêu cầu hủy đơn hàng", "content" => "Yêu cầu hủy đơn tự động đã được gửi đến Admin và chờ xử lý", "level" => "2", "username" => $user->username, "status" => 0)); if ($id) { $chatId = Settings::where("key", "telegram_chat_id")->first()->value; $tokenTelegram = Settings::where("key", "telegram")->first()->value; $message = "Thông Báo Hỗ Trợ Mới !\xa* Yêu cầu hủy đơn tự động thất bại do API nguồn " . $partner->name . " của bạn không hỗ trợ hoặc không cung cấp apiv2 hủy đơn tự động, bạn cần hủy thủ công bằng tay cho khách hàng
- Nội dung: Yêu cầu hủy đơn hàng
- Username: " . $user->username . "\xa- ID order: " . $request->orders . "\xa- ID đơn gốc: " . $order->order_smm . "
- Mức độ: 2
"; if ($chatId && $tokenTelegram) { $result = Anhyeuem37::sendTelegramMessage($chatId, $tokenTelegram, $message); } return response()->json(array("order" => $requestData["orders"], "cancel" => "1"), 200); } else { return response()->json(array("order" => 1, "cancel" => array("error" => "Gửi ticket yêu cầu hủy đơn thất bại !")), 200); } } } elseif ($request->action == "refill") { $validator = Validator::make($request->all(), array("order" => "required"), array("order.required" => "Invalid ID Order !")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("order" => 1, "refill" => $firstErrorMessage), 422); } $requestData = $request->toArray(); $orderId = $requestData["order"]; if (!$orderId) { return array("error" => "Thiếu id_order"); } if (!preg_match("/^[a-zA-Z0-9]+$/", $orderId)) { return array("error" => "id_order không hợp lệ"); } $order = Orders::where("id_order", $orderId)->first(); if (!$order) { return with(array("error" => "Đơn hàng không tồn tại !")); } $server = Server::where("id", $order->server)->where("status", 1)->first(); if (!$server) { return with(array("error" => "Server không tồn tại hoặc không hoạt động !")); } $partner = SmmPanel::where("id", $server->smmpanel)->where("status", 1)->first(); if (!$partner) { return with(array("error" => "Dịch vụ không tồn tại hoặc không hoạt động !")); } Smm_Global::init(array("link" => $partner->link, "token" => $partner->token)); $data = array("key" => $partner->token, "action" => "refill", "order" => $order->order_smm); if ($partner->json == 1) { $data["service"] = (string) $data["service"]; $response = Smm_Global::connect($data, true); } else { $response = Smm_Global::connect($data); } $result = json_decode($response, true); if (isset($result["refill"])) { $order->update(array("note" => "Refill đơn hàng")); return with(array("success" => "Refill đơn hàng thành công !")); } else { return with(array("error" => "Error: " . (isset($result["error"]) ? $result["error"] : (isset($result["message"]) ? $result["message"] : "Dịch vụ không hỗ trợ bảo hành")))); } } elseif ($request->action == "balance") { $result = User::where("token", $request->key)->first(); if ($result) { return response()->json(array("balance" => $result["balance"], "currency" => "VND"), 200); } } else { return response()->json(array("error" => "Incorrect request"), 200); } } public function websites(Request $request) { $validator = Validator::make($request->all(), array("domain_add" => "required", "domain" => "required", "username" => "required"), array("domain_add.required" => "Vui lòng nhập mã tên miền cần thêm!", "domain.required" => "Vui lòng nhập mã tên miền gốc!", "domain.required" => "Vui lòng nhập tên đăng nhập!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("status" => "error", "data" => $firstErrorMessage), 422); } $website_add = Websites::where("domain", $request->domain_add)->first(); if (!$website_add) { $website = Websites::where("domain", $request->domain)->first(); if ($website) { Websites::create(array("domain" => $request->domain_add, "parent_id" => $website->id, "username" => $request->username, "status" => 1)); return response()->json(array("status" => "success", "data" => "Thêm thành công"), 200); } else { return response()->json(array("status" => "error", "data" => "Không tìm thấy website gốc!"), 422); } } else { return response()->json(array("status" => "error", "data" => "Websites cần thêm đã tồn tại!"), 422); } } public function check(Request $request) { $validator = Validator::make($request->all(), array("token" => "required"), array("token.required" => "Vui lòng nhập mã Token!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("status" => "error", "data" => $firstErrorMessage), 422); } $user = User::where("token", $request->token)->first(); if ($user) { $data = array("status" => "success", "data" => array("name" => $user->name, "username" => $user->username, "email" => $user->email, "password" => $user->password, "token" => $user->token)); return response()->json($data, 200); } else { return response()->json(array("status" => "error", "data" => "Token không chính xác!"), 422); } } public function active(Request $request) { $validator = Validator::make($request->all(), array("domain" => "required", "token" => "required"), array("domain.required" => "Vui lòng nhập tên miền!", "token.required" => "Vui lòng nhập mã Token!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("error" => $firstErrorMessage), 422); } $websites = Websites::where("domain", $request->domain)->where("status", 1)->first(); if (!$websites) { return response()->json(array("status" => "error", "data" => "Không tìm thấy website hoặc chưa được kích hoạt!"), 422); } $id_website_official = Websites::where("id", $websites->parent_id)->first(); if (!$id_website_official) { return response()->json(array("status" => "error", "data" => "Không tìm thấy Website chính thức!"), 422); } try { $response = Anhyeuem37::curl("https://" . $id_website_official->domain . "/api/check", array("token" => $request->token)); $response = json_decode($response, true); if ($response && isset($response["status"]) && $response["status"] == "success") { if ($response["data"]["username"] == $websites->username) { $data = array("status" => "success", "data" => array("domain" => $id_website_official->domain, "name" => $response["data"]["name"], "username" => $response["data"]["username"], "email" => $response["data"]["email"], "password" => $response["data"]["password"], "token" => $response["data"]["token"])); return response()->json($data, 200); } else { return response()->json(array("status" => "error", "data" => "Token không không hợp lệ"), 422); } } else { return response()->json(array("status" => "error", "data" => $response["data"]), 422); } } catch (\Exception $e) { return response()->json(array("status" => "error", "data" => "Có lỗi xảy ra trong quá trình xác thực"), 500); } } public function card(Request $request) { $validator = Validator::make($request->all(), array("request_id" => "required", "callback_sign" => "required"), array("request_id.required" => "Vui lòng request_id!", "callback_sign.required" => "Vui lòng sign callback!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("error" => $firstErrorMessage), 422); } $data = $request->all(); $card_pending = Card::where("sign", $data["callback_sign"])->where("request_id", $data["request_id"])->where("status", 0)->first(); if ($card_pending) { $user = User::where("username", $card_pending->username)->first(); $card = Settings::where("key", "card")->value("value"); switch ($data["status"]) { case 1: $total_amount = $card_pending->amount - $card_pending->amount * $card / 100; $card_pending->update(array("status" => $data["status"])); $user->update(array("balance" => $user->balance + $total_amount)); Transaction::create(array("type" => "Card", "amount" => $total_amount, "username" => $card_pending->username, "description" => "Nạp thẻ cào " . $card_pending->serial . " mệnh giá " . $card_pending->amount . " nhận " . $total_amount . " ", "transaction_id" => $card_pending->request_id, "status" => 1)); $chatId = Settings::where("key", "telegram_chat_id")->first()->value; $tokenTelegram = Settings::where("key", "telegram")->first()->value; $message = "Thông Báo Nạp Card !\xa- Tài khoản: " . $user . "
- Loại thẻ: " . $card_pending->serial . "
- Mệnh giá: " . $card_pending->amount . " VND
- Thực nhận: " . $total_amount . " VND
"; if ($chatId && $tokenTelegram) { $result = Anhyeuem37::sendTelegramMessage($chatId, $tokenTelegram, $message); } break; case 2: $total_amount = $card_pending->amount / 2; $total_amount = $total_amount - $total_amount * $card / 100; $card_pending->update(array("status" => $data["status"])); $user->update(array("balance" => $user->balance + $total_amount)); Transaction::create(array("type" => "Card", "amount" => $total_amount, "username" => $card_pending->username, "description" => "Nạp thẻ cào " . $card_pending->serial . " mệnh giá " . $card_pending->amount . " nhận " . $total_amount . '', "transaction_id" => $card_pending->request_id, "status" => 1)); $chatId = Settings::where("key", "telegram_chat_id")->first()->value; $tokenTelegram = Settings::where("key", "telegram")->first()->value; $message = "Thông Báo Nạp Card !\xa- Tài khoản: " . $user . "
- Loại thẻ: " . $card_pending->serial . "
- Mệnh giá: " . $card_pending->amount . " VND
- Thực nhận: " . $total_amount . " VND
"; if ($chatId && $tokenTelegram) { $result = Anhyeuem37::sendTelegramMessage($chatId, $tokenTelegram, $message); } break; default: $card_pending->update(array("status" => $data["status"])); break; } } } }
namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Helpers\Anhyeuem37; use App\Helpers\Smm as Smm_Global; use Illuminate\Validation\Rule; use Illuminate\Http\Response; use App\Models\Server; use App\Models\Services; use App\Models\Subcategory; use App\Models\Category; use App\Models\Orders; use App\Models\Card; use App\Models\Ticket; use App\Models\Activity_log; use App\Models\SmmPanel_Activity; use App\Models\SmmPanel; use App\Models\SmmPanel_percent; use App\Models\User; use App\Models\Websites; use App\Models\Settings; use App\Models\Transaction; use App\Models\History_order; use App\Http\Controllers\ApiLive; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; use Illuminate\Support\Facades\DB; class Api extends Controller { public function v2(request $request) { if ($request->action == "services") { $servers = Server::where("status", 1)->get(); $data = array(); foreach ($servers as $server) { $services = Subcategory::where("id", $server["id_service"])->where("status", 1)->first(); if ($services) { $category = Category::where("id", $services["id_category"])->where("status", 1)->first(); if ($category) { if ($server["speed"] == 1) { $type = "Special"; } elseif ($server["comment"] == 0) { $type = "Default"; } elseif ($server["comment"] == 1) { $type = "Custom Comments"; } $data[] = array("service" => $server["id"], "platform" => $category["name"], "category" => $services["name"], "name" => $server["detail"], "type" => $type, "rate" => $server["price"], "min" => $server["min"], "max" => $server["max"], "note" => $server["note"]); } } } return response()->json($data, 200, array(), JSON_PRETTY_PRINT); } elseif ($request->action == "add") { $validator = Validator::make($request->all(), array("link" => "required", "service" => "required|numeric", "quantity" => array("nullable", "numeric", Rule::requiredIf(function () use($request) { return empty($request->comments); }))), array("linkrequired" => "Invalid Link !", "servicerequired" => "Invalid service !", "servicenumeric" => "Invalid service !", "quantitynumeric" => "Invalid quantity !", "quantityrequired" => "Invalid quantity !")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("error" => $firstErrorMessage), 422); } $requestData = $request->toArray(); if (isset($requestData["comments"])) { $comments = explode("\xa", $requestData["comments"]); $requestData["quantity"] = count($comments); } $server = Server::where("id", $requestData["service"])->first(); if ($server) { if ($requestData["quantity"] < $server["min"] || $requestData["quantity"] > $server["max"]) { return response()->json(array("error" => "Invalid quantity"), 401); } if ($server->gioihan != 0) { $originalLink = $requestData["link"]; $cleanedLink = strtok($originalLink, "?"); $cleanedLink = rtrim($cleanedLink, "/"); $existingOrder = Orders::where(function ($query) use($originalLink, $cleanedLink) { $query->where("link", $originalLink)->orWhere("link", $cleanedLink); })->first(); if ($existingOrder) { return response()->json(array("error" => "Tham lam... Link/video này đã đạt giới hạn mua rồi nha !"), 401); } } $total = 0; $user = User::where("token", $requestData["key"])->first(); $level = $user->level >= 1 ? "level" . $user->level : "price"; $total = $server->{$level} * $requestData["quantity"]; if ($total > $user->balance) { return response()->json(array("error" => "Balance not enough !"), 401); } if ($server->gioihan != 0) { $cleanedLink = strtok($requestData["link"], "?"); $cleanedLink = rtrim($cleanedLink, "/"); $existingIds = Orders::pluck("id_order")->toArray(); do { $id_order = mt_rand(1000000, 9999999); } while (in_array($id_order, $existingIds)); $data = array("id_order" => $id_order, "link" => $cleanedLink, "server" => $requestData["service"], "total" => $total, "reaction" => isset($requestData["reaction"]) ? $requestData["service"] : "like", "quantity" => $requestData["quantity"], "username" => $user->username, "status" => "inprogress"); $fields = array("speed", "minutes", "time", "days"); } else { $existingIds = Orders::pluck("id_order")->toArray(); do { $id_order = mt_rand(1000000, 9999999); } while (in_array($id_order, $existingIds)); $data = array("id_order" => $id_order, "link" => $requestData["link"], "server" => $requestData["service"], "total" => $total, "reaction" => isset($requestData["reaction"]) ? $requestData["service"] : "like", "quantity" => $requestData["quantity"], "username" => $user->username, "status" => "inprogress"); $fields = array("speed", "minutes", "time", "days"); } foreach ($fields as $field) { if (isset($requestData[$field])) { $data[$field] = $requestData[$field]; } } if (isset($requestData["comments"])) { $data["quantity"] = $requestData["quantity"]; $data["comments"] = $requestData["comments"]; } else { $data["quantity"] = $requestData["quantity"]; } if (isset($requestData["comments"])) { $data["comments"] = $requestData["comments"]; } else { if (isset($requestData["reaction"])) { $data["reaction"] = $requestData["reaction"]; } else { $data["reaction"] = "like"; } } $apiLive = new ApiLive(); $apiResult = $apiLive->checkapi($data); if (!$apiResult["status"]) { return response()->json(array("error" => $apiResult["message"]), 401); } $user->update(array("balance" => $user->balance - $total)); $newOrder = Orders::create($data); if (isset($apiResult["order_api"])) { $newOrder->order_smm = $apiResult["order_api"]; if (isset($apiResult["type"])) { $newOrder->type = $apiResult["type"]; } $newOrder->save(); } History_order::create(array("type" => "-", "begin_balance" => $user->balance + $total, "quantity_balance" => $total, "change_balance" => $user->balance - $total, "note" => "Đơn hàng #" . $newOrder->id_order . " Tăng " . $requestData["quantity"] . "Seeding tại máy chủ " . $requestData["service"] . " trừ số tiền " . $total . " trong tài khoản", "username" => $user->username)); Activity_log::create(array("content" => "Tài khoản " . $user->username . " mua dịch vụ bằng API", "username" => $user->username)); $chatId = Settings::where("key", "telegram_chat_id")->first()->value; $tokenTelegram = Settings::where("key", "telegram")->first()->value; $message = "Đơn hàng mới từ API!\xa- Tài khoản: " . $user->username . " \xa- Mã đơn: " . $newOrder->id_order . "
- Số lượng: " . $requestData["quantity"] . "
- Link/ID: " . $requestData["link"] . "\xa- Máy chủ: " . $requestData["service"] . "\xa- Thanh toán: " . $total . " VND
"; if ($chatId && $tokenTelegram) { } return response()->json(array("order" => $newOrder->id_order), 200); } else { return response()->json(array("error" => "Invalid service !"), 401); } } elseif ($request->action == "status") { $validator = Validator::make($request->all(), array("orders" => "required_without:order"), array("ordersrequired_without" => "Incorrect order ID!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("error" => $firstErrorMessage), 422); } if ($request->orders) { $orderIds = explode(",", $request->orders); foreach ($orderIds as $orderId) { $key = User::where("token", $request->key)->first(); $orders = Orders::where("id_order", $orderId)->get(); if ($orders->isNotEmpty()) { foreach ($orders as $order) { if ($order->username != $key->username) { $result[$orderId] = array("error" => "Incorrect order ID"); } else { switch ($order->status) { case "pending": $order->status = "Pending"; break; case "inprogress": $order->status = "In progress"; break; case "processing": $order->status = "Processing"; break; case "success": $order->status = "Completed"; break; case "partial": $order->status = "Partial"; break; case "error": case "cancel": $order->status = "Canceled"; break; } $result[$orderId] = array("charge" => $order->total, "start_count" => $order->start, "status" => $order->status, "remains" => $order->quantity - $order->run); } } } else { $result[$orderId] = array("error" => "Incorrect order ID"); } } $new_array = $result; return response()->json($new_array, 200); } else { if ($request->order) { $order = Orders::where("id_order", $request->order)->first(); if ($order) { $key = User::where("token", $request->key)->first(); if ($order->username != $key->username) { return response()->json(array($request->order => array("error" => "Incorrect order ID")), 200); } else { switch ($order->status) { case "pending": $order->status = "Pending"; break; case "inprogress": $order->status = "In progress"; break; case "processing": $order->status = "Processing"; break; case "success": $order->status = "Completed"; break; case "partial": $order->status = "Partial"; break; case "error": case "cancel": $order->status = "Canceled"; break; } return response()->json(array($order->id_order => array("charge" => $order->total, "start_count" => $order->start, "status" => $order->status, "remains" => $order->quantity - $order->run)), 200); } } else { return response()->json(array($request->order => "Incorrect order ID"), 200); } } } } elseif ($request->action == "cancel") { $validator = Validator::make($request->all(), array("orders" => "required"), array("ordersrequired" => "Invalid ID Order !")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("order" => 1, "cancel" => array("error" => $firstErrorMessage)), 422); } $requestData = $request->toArray(); $orderId = $requestData["orders"]; $user = User::where("token", $requestData["key"])->first(); if (!$orderId) { return response()->json(array("order" => 1, "cancel" => array("error" => "Vui lòng nhập id_order")), 200); } if (!preg_match("/^[a-zA-Z0-9]+$/", $orderId)) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "id_order không hợp lệ!")), 200); } $order = Orders::where("id_order", $orderId)->first(); if (!$order) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Đơn hàng không tồn tại !")), 200); } if ($order->status == "success") { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Đơn hàng này đã hoàn thành không thể huỷ!")), 200); } elseif ($order->status == "error") { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Đơn hàng này đã được huỷ trước đó!")), 200); } elseif ($order->total == 0) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Máy chủ free không hỗ trợ huỷ !")), 200); } $server = Server::where("id", $order->server)->where("status", 1)->first(); if (!$server) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Server không tồn tại hoặc không hoạt động !")), 200); } $partner = SmmPanel::where("id", $server->smmpanel)->where("status", 1)->first(); if (!$partner) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Dịch vụ không tồn tại hoặc không hoạt động !")), 200); } Smm_Global::init(array("link" => $partner->link, "token" => $partner->token)); $data = array("key" => $partner->token, "action" => "cancel", "orders" => $order->order_smm); if ($partner->json == 1) { $data["service"] = (string) $data["service"]; $response = Smm_Global::connect($data, true); } else { $response = Smm_Global::connect($data); } if (isset("A"["cancel"]["error"])) { $errorMessage = "A"["cancel"]["error"]; if ($errorMessage == "errorcancel_unavailable") { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Hủy đơn thất bại, máy chủ không hỗ trợ hủy hoàn !")), 200); } else { return response()->json(array("order" => $orderId, "cancel" => array("error" => $errorMessage)), 200); } } elseif (isset("A"["cancel"]["error"]) && "A"["order"]) { $order->update(array("note" => "Gửi yêu cầu hủy đơn hàng thành công")); return response()->json(array("order" => $requestData["orders"], "cancel" => 1), 200); } else { if (!$order) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Đơn hàng không tồn tại!")), 200); } $existingTicket = Ticket::where("id_order", $request->orders)->first(); if ($existingTicket) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Mã đơn hàng này đã tồn tại hỗ trợ!")), 200); } $content = htmlspecialchars($request->content, ENT_QUOTES, "UTF-8"); $id = Ticket::create(array("id_order" => $request->orders, "title" => "Yêu cầu hủy đơn hàng", "content" => "Yêu cầu hủy đơn tự động đã được gửi đến Admin và chờ xử lý", "level" => "2", "username" => $user->username, "status" => 0)); if ($id) { $chatId = Settings::where("key", "telegram_chat_id")->first()->value; $tokenTelegram = Settings::where("key", "telegram")->first()->value; $message = "Thông Báo Hỗ Trợ Mới !\xa* Yêu cầu hủy đơn tự động thất bại do API nguồn " . $partner->name . " của bạn không hỗ trợ hoặc không cung cấp apiv2 hủy đơn tự động, bạn cần hủy thủ công bằng tay cho khách hàng
- Nội dung: Yêu cầu hủy đơn hàng
- Username: " . $user->username . "\xa- ID order: " . $request->orders . "\xa- ID đơn gốc: " . $order->order_smm . "
- Mức độ: 2
"; if ($chatId && $tokenTelegram) { } return response()->json(array("order" => $requestData["orders"], "cancel" => "1"), 200); } else { return response()->json(array("order" => 1, "cancel" => array("error" => "Gửi ticket yêu cầu hủy đơn thất bại !")), 200); } } } elseif ($request->action == "refill") { $validator = Validator::make($request->all(), array("order" => "required"), array("orderrequired" => "Invalid ID Order !")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("order" => 1, "refill" => $firstErrorMessage), 422); } $requestData = $request->toArray(); $orderId = $requestData["order"]; if (!$orderId) { return array("error" => "Thiếu id_order"); } if (!preg_match("/^[a-zA-Z0-9]+$/", $orderId)) { return array("error" => "id_order không hợp lệ"); } $order = Orders::where("id_order", $orderId)->first(); if (!$order) { return with(array("error" => "Đơn hàng không tồn tại !")); } $server = Server::where("id", $order->server)->where("status", 1)->first(); if (!$server) { return with(array("error" => "Server không tồn tại hoặc không hoạt động !")); } $partner = SmmPanel::where("id", $server->smmpanel)->where("status", 1)->first(); if (!$partner) { return with(array("error" => "Dịch vụ không tồn tại hoặc không hoạt động !")); } Smm_Global::init(array("link" => $partner->link, "token" => $partner->token)); $data = array("key" => $partner->token, "action" => "refill", "order" => $order->order_smm); if ($partner->json == 1) { $data["service"] = (string) $data["service"]; $response = Smm_Global::connect($data, true); } else { $response = Smm_Global::connect($data); } if (isset($result["refill"])) { $order->update(array("note" => "Refill đơn hàng")); return with(array("success" => "Refill đơn hàng thành công !")); } else { return with(array("error" => "Error: " . (isset($result["error"]) ? $result["error"] : (isset($result["message"]) ? $result["message"] : "Dịch vụ không hỗ trợ bảo hành")))); } } elseif ($request->action == "balance") { if ($result) { return response()->json(array("balance" => $result["balance"], "currency" => "VND"), 200); } } else { return response()->json(array("error" => "Incorrect request"), 200); } } public function websites(Request $request) { $validator = Validator::make($request->all(), array("domain_add" => "required", "domain" => "required", "username" => "required"), array("domain_addrequired" => "Vui lòng nhập mã tên miền cần thêm!", "domainrequired" => "Vui lòng nhập mã tên miền gốc!", "domainrequired" => "Vui lòng nhập tên đăng nhập!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("status" => "error", "data" => $firstErrorMessage), 422); } $website_add = Websites::where("domain", $request->domain_add)->first(); if (!$website_add) { $website = Websites::where("domain", $request->domain)->first(); if ($website) { Websites::create(array("domain" => $request->domain_add, "parent_id" => $website->id, "username" => $request->username, "status" => 1)); return response()->json(array("status" => "success", "data" => "Thêm thành công"), 200); } else { return response()->json(array("status" => "error", "data" => "Không tìm thấy website gốc!"), 422); } } else { return response()->json(array("status" => "error", "data" => "Websites cần thêm đã tồn tại!"), 422); } } public function check(Request $request) { $validator = Validator::make($request->all(), array("token" => "required"), array("tokenrequired" => "Vui lòng nhập mã Token!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("status" => "error", "data" => $firstErrorMessage), 422); } $user = User::where("token", $request->token)->first(); if ($user) { $data = array("status" => "success", "data" => array("name" => $user->name, "username" => $user->username, "email" => $user->email, "password" => $user->password, "token" => $user->token)); return response()->json($data, 200); } else { return response()->json(array("status" => "error", "data" => "Token không chính xác!"), 422); } } public function active(Request $request) { $validator = Validator::make($request->all(), array("domain" => "required", "token" => "required"), array("domainrequired" => "Vui lòng nhập tên miền!", "tokenrequired" => "Vui lòng nhập mã Token!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("error" => $firstErrorMessage), 422); } $websites = Websites::where("domain", $request->domain)->where("status", 1)->first(); if (!$websites) { return response()->json(array("status" => "error", "data" => "Không tìm thấy website hoặc chưa được kích hoạt!"), 422); } $id_website_official = Websites::where("id", $websites->parent_id)->first(); if (!$id_website_official) { return response()->json(array("status" => "error", "data" => "Không tìm thấy Website chính thức!"), 422); } try { $response = Anhyeuem37::curl("https://" . $id_website_official->domain . "/api/check", array("token" => $request->token)); $response = json_decode($response, true); if ($response && isset($response["status"]) && $response["status"] == "success") { if ($response["data"]["username"] == $websites->username) { $data = array("status" => "success", "data" => array("domain" => $id_website_official->domain, "name" => $response["data"]["name"], "username" => $response["data"]["username"], "email" => $response["data"]["email"], "password" => $response["data"]["password"], "token" => $response["data"]["token"])); return response()->json($data, 200); } else { return response()->json(array("status" => "error", "data" => "Token không không hợp lệ"), 422); } } else { return response()->json(array("status" => "error", "data" => $response["data"]), 422); } } catch (\Exception $e) { return response()->json(array("status" => "error", "data" => "Có lỗi xảy ra trong quá trình xác thực"), 500); } } public function card(Request $request) { $validator = Validator::make($request->all(), array("request_id" => "required", "callback_sign" => "required"), array("request_idrequired" => "Vui lòng request_id!", "callback_signrequired" => "Vui lòng sign callback!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("error" => $firstErrorMessage), 422); } $data = $request->all(); $card_pending = Card::where("sign", $data["callback_sign"])->where("request_id", $data["request_id"])->where("status", 0)->first(); if ($card_pending) { $user = User::where("username", $card_pending->username)->first(); $card = Settings::where("key", "card")->value("value"); switch ($data["status"]) { case 1: $total_amount = $card_pending->amount - $card_pending->amount * $card / 100; $card_pending->update(array("status" => $data["status"])); $user->update(array("balance" => $user->balance + $total_amount)); Transaction::create(array("type" => "Card", "amount" => $total_amount, "username" => $card_pending->username, "description" => "Nạp thẻ cào " . $card_pending->serial . " mệnh giá " . $card_pending->amount . " nhận " . $total_amount . " ", "transaction_id" => $card_pending->request_id, "status" => 1)); $chatId = Settings::where("key", "telegram_chat_id")->first()->value; $tokenTelegram = Settings::where("key", "telegram")->first()->value; $message = "Thông Báo Nạp Card !\xa- Tài khoản: " . $user . "
- Loại thẻ: " . $card_pending->serial . "
- Mệnh giá: " . $card_pending->amount . " VND
- Thực nhận: " . $total_amount . " VND
"; if ($chatId && $tokenTelegram) { } break; case 2: $total_amount = $card_pending->amount / 2; $total_amount = $total_amount - $total_amount * $card / 100; $card_pending->update(array("status" => $data["status"])); $user->update(array("balance" => $user->balance + $total_amount)); Transaction::create(array("type" => "Card", "amount" => $total_amount, "username" => $card_pending->username, "description" => "Nạp thẻ cào " . $card_pending->serial . " mệnh giá " . $card_pending->amount . " nhận " . $total_amount . '', "transaction_id" => $card_pending->request_id, "status" => 1)); $chatId = Settings::where("key", "telegram_chat_id")->first()->value; $tokenTelegram = Settings::where("key", "telegram")->first()->value; $message = "Thông Báo Nạp Card !\xa- Tài khoản: " . $user . "
- Loại thẻ: " . $card_pending->serial . "
- Mệnh giá: " . $card_pending->amount . " VND
- Thực nhận: " . $total_amount . " VND
"; if ($chatId && $tokenTelegram) { } break; default: $card_pending->update(array("status" => $data["status"])); break; } } } }
namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Helpers\Anhyeuem37; use App\Helpers\Smm as Smm_Global; use Illuminate\Validation\Rule; use Illuminate\Http\Response; use App\Models\Server; use App\Models\Services; use App\Models\Subcategory; use App\Models\Category; use App\Models\Orders; use App\Models\Card; use App\Models\Ticket; use App\Models\Activity_log; use App\Models\SmmPanel_Activity; use App\Models\SmmPanel; use App\Models\SmmPanel_percent; use App\Models\User; use App\Models\Websites; use App\Models\Settings; use App\Models\Transaction; use App\Models\History_order; use App\Http\Controllers\ApiLive; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; use Illuminate\Support\Facades\DB; class Api extends Controller { public function v2(request $request) { if ($request->action == "services") { $servers = Server::where("status", 1)->get(); $data = array(); foreach ($servers as $server) { $services = Subcategory::where("id", $server["id_service"])->where("status", 1)->first(); if ($services) { $category = Category::where("id", $services["id_category"])->where("status", 1)->first(); if ($category) { if ($server["speed"] == 1) { } elseif ($server["comment"] == 0) { "Special" = "Default"; } elseif ($server["comment"] == 1) { "Special" = "Custom Comments"; } $data[] = array("service" => $server["id"], "platform" => $category["name"], "category" => $services["name"], "name" => $server["detail"], "type" => "Special", "rate" => $server["price"], "min" => $server["min"], "max" => $server["max"], "note" => $server["note"]); } } } return response()->json($data, 200, array(), JSON_PRETTY_PRINT); } elseif ($request->action == "add") { $validator = Validator::make($request->all(), array("link" => "required", "service" => "required|numeric", "quantity" => array("nullable", "numeric", Rule::requiredIf(function () use($request) { return empty($request->comments); }))), array("linkrequired" => "Invalid Link !", "servicerequired" => "Invalid service !", "servicenumeric" => "Invalid service !", "quantitynumeric" => "Invalid quantity !", "quantityrequired" => "Invalid quantity !")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("error" => $firstErrorMessage), 422); } $requestData = $request->toArray(); if (isset($requestData["comments"])) { $comments = explode("\xa", $requestData["comments"]); $requestData["quantity"] = count($comments); } $server = Server::where("id", $requestData["service"])->first(); if ($server) { if ($requestData["quantity"] < $server["min"] || $requestData["quantity"] > $server["max"]) { return response()->json(array("error" => "Invalid quantity"), 401); } if ($server->gioihan != 0) { $originalLink = $requestData["link"]; $cleanedLink = strtok($originalLink, "?"); $cleanedLink = rtrim($cleanedLink, "/"); $existingOrder = Orders::where(function ($query) use($originalLink, $cleanedLink) { $query->where("link", $originalLink)->orWhere("link", $cleanedLink); })->first(); if ($existingOrder) { return response()->json(array("error" => "Tham lam... Link/video này đã đạt giới hạn mua rồi nha !"), 401); } } $total = 0; $user = User::where("token", $requestData["key"])->first(); $level = $user->level >= 1 ? "level" . $user->level : "price"; $total = $server->{$level} * $requestData["quantity"]; if ($total > $user->balance) { return response()->json(array("error" => "Balance not enough !"), 401); } if ($server->gioihan != 0) { $cleanedLink = strtok($requestData["link"], "?"); $cleanedLink = rtrim($cleanedLink, "/"); $existingIds = Orders::pluck("id_order")->toArray(); do { $id_order = mt_rand(1000000, 9999999); } while (in_array($id_order, $existingIds)); $data = array("id_order" => $id_order, "link" => $cleanedLink, "server" => $requestData["service"], "total" => $total, "reaction" => isset($requestData["reaction"]) ? $requestData["service"] : "like", "quantity" => $requestData["quantity"], "username" => $user->username, "status" => "inprogress"); $fields = array("speed", "minutes", "time", "days"); } else { $existingIds = Orders::pluck("id_order")->toArray(); do { $id_order = mt_rand(1000000, 9999999); } while (in_array($id_order, $existingIds)); $data = array("id_order" => $id_order, "link" => $requestData["link"], "server" => $requestData["service"], "total" => $total, "reaction" => isset($requestData["reaction"]) ? $requestData["service"] : "like", "quantity" => $requestData["quantity"], "username" => $user->username, "status" => "inprogress"); $fields = array("speed", "minutes", "time", "days"); } foreach ($fields as $field) { if (isset($requestData[$field])) { $data[$field] = $requestData[$field]; } } if (isset($requestData["comments"])) { $data["quantity"] = $requestData["quantity"]; $data["comments"] = $requestData["comments"]; } else { $data["quantity"] = $requestData["quantity"]; } if (isset($requestData["comments"])) { $data["comments"] = $requestData["comments"]; } else { if (isset($requestData["reaction"])) { $data["reaction"] = $requestData["reaction"]; } else { $data["reaction"] = "like"; } } $apiLive = new ApiLive(); $apiResult = $apiLive->checkapi($data); if (!$apiResult["status"]) { return response()->json(array("error" => $apiResult["message"]), 401); } $user->update(array("balance" => $user->balance - $total)); $newOrder = Orders::create($data); if (isset($apiResult["order_api"])) { $newOrder->order_smm = $apiResult["order_api"]; if (isset($apiResult["type"])) { $newOrder->type = $apiResult["type"]; } $newOrder->save(); } History_order::create(array("type" => "-", "begin_balance" => $user->balance + $total, "quantity_balance" => $total, "change_balance" => $user->balance - $total, "note" => "Đơn hàng #" . $newOrder->id_order . " Tăng " . $requestData["quantity"] . "Seeding tại máy chủ " . $requestData["service"] . " trừ số tiền " . $total . " trong tài khoản", "username" => $user->username)); Activity_log::create(array("content" => "Tài khoản " . $user->username . " mua dịch vụ bằng API", "username" => $user->username)); $chatId = Settings::where("key", "telegram_chat_id")->first()->value; $tokenTelegram = Settings::where("key", "telegram")->first()->value; $message = "Đơn hàng mới từ API!\xa- Tài khoản: " . $user->username . " \xa- Mã đơn: " . $newOrder->id_order . "
- Số lượng: " . $requestData["quantity"] . "
- Link/ID: " . $requestData["link"] . "\xa- Máy chủ: " . $requestData["service"] . "\xa- Thanh toán: " . $total . " VND
"; if ($chatId && $tokenTelegram) { } return response()->json(array("order" => $newOrder->id_order), 200); } else { return response()->json(array("error" => "Invalid service !"), 401); } } elseif ($request->action == "status") { $validator = Validator::make($request->all(), array("orders" => "required_without:order"), array("ordersrequired_without" => "Incorrect order ID!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("error" => $firstErrorMessage), 422); } if ($request->orders) { $orderIds = explode(",", $request->orders); foreach ($orderIds as $orderId) { $key = User::where("token", $request->key)->first(); $orders = Orders::where("id_order", $orderId)->get(); if ($orders->isNotEmpty()) { foreach ($orders as $order) { if ($order->username != $key->username) { $result[$orderId] = array("error" => "Incorrect order ID"); } else { switch ($order->status) { case "pending": $order->status = "Pending"; break; case "inprogress": $order->status = "In progress"; break; case "processing": $order->status = "Processing"; break; case "success": $order->status = "Completed"; break; case "partial": $order->status = "Partial"; break; case "error": case "cancel": $order->status = "Canceled"; break; } $result[$orderId] = array("charge" => $order->total, "start_count" => $order->start, "status" => $order->status, "remains" => $order->quantity - $order->run); } } } else { $result[$orderId] = array("error" => "Incorrect order ID"); } } $new_array = $result; return response()->json($new_array, 200); } else { if ($request->order) { $order = Orders::where("id_order", $request->order)->first(); if ($order) { $key = User::where("token", $request->key)->first(); if ($order->username != $key->username) { return response()->json(array($request->order => array("error" => "Incorrect order ID")), 200); } else { switch ($order->status) { case "pending": $order->status = "Pending"; break; case "inprogress": $order->status = "In progress"; break; case "processing": $order->status = "Processing"; break; case "success": $order->status = "Completed"; break; case "partial": $order->status = "Partial"; break; case "error": case "cancel": $order->status = "Canceled"; break; } return response()->json(array($order->id_order => array("charge" => $order->total, "start_count" => $order->start, "status" => $order->status, "remains" => $order->quantity - $order->run)), 200); } } else { return response()->json(array($request->order => "Incorrect order ID"), 200); } } } } elseif ($request->action == "cancel") { $validator = Validator::make($request->all(), array("orders" => "required"), array("ordersrequired" => "Invalid ID Order !")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("order" => 1, "cancel" => array("error" => $firstErrorMessage)), 422); } $requestData = $request->toArray(); $orderId = $requestData["orders"]; $user = User::where("token", $requestData["key"])->first(); if (!$orderId) { return response()->json(array("order" => 1, "cancel" => array("error" => "Vui lòng nhập id_order")), 200); } if (!preg_match("/^[a-zA-Z0-9]+$/", $orderId)) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "id_order không hợp lệ!")), 200); } $order = Orders::where("id_order", $orderId)->first(); if (!$order) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Đơn hàng không tồn tại !")), 200); } if ($order->status == "success") { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Đơn hàng này đã hoàn thành không thể huỷ!")), 200); } elseif ($order->status == "error") { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Đơn hàng này đã được huỷ trước đó!")), 200); } elseif ($order->total == 0) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Máy chủ free không hỗ trợ huỷ !")), 200); } $server = Server::where("id", $order->server)->where("status", 1)->first(); if (!$server) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Server không tồn tại hoặc không hoạt động !")), 200); } $partner = SmmPanel::where("id", $server->smmpanel)->where("status", 1)->first(); if (!$partner) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Dịch vụ không tồn tại hoặc không hoạt động !")), 200); } Smm_Global::init(array("link" => $partner->link, "token" => $partner->token)); $data = array("key" => $partner->token, "action" => "cancel", "orders" => $order->order_smm); if ($partner->json == 1) { $data["service"] = (string) $data["service"]; $response = Smm_Global::connect($data, true); } else { $response = Smm_Global::connect($data); } if (isset("A"["cancel"]["error"])) { $errorMessage = "A"["cancel"]["error"]; if ($errorMessage == "errorcancel_unavailable") { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Hủy đơn thất bại, máy chủ không hỗ trợ hủy hoàn !")), 200); } else { return response()->json(array("order" => $orderId, "cancel" => array("error" => $errorMessage)), 200); } } elseif (isset("A"["cancel"]["error"]) && "A"["order"]) { $order->update(array("note" => "Gửi yêu cầu hủy đơn hàng thành công")); return response()->json(array("order" => $requestData["orders"], "cancel" => 1), 200); } else { if (!$order) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Đơn hàng không tồn tại!")), 200); } $existingTicket = Ticket::where("id_order", $request->orders)->first(); if ($existingTicket) { return response()->json(array("order" => $orderId, "cancel" => array("error" => "Mã đơn hàng này đã tồn tại hỗ trợ!")), 200); } $content = htmlspecialchars($request->content, ENT_QUOTES, "UTF-8"); $id = Ticket::create(array("id_order" => $request->orders, "title" => "Yêu cầu hủy đơn hàng", "content" => "Yêu cầu hủy đơn tự động đã được gửi đến Admin và chờ xử lý", "level" => "2", "username" => $user->username, "status" => 0)); if ($id) { $chatId = Settings::where("key", "telegram_chat_id")->first()->value; $tokenTelegram = Settings::where("key", "telegram")->first()->value; $message = "Thông Báo Hỗ Trợ Mới !\xa* Yêu cầu hủy đơn tự động thất bại do API nguồn " . $partner->name . " của bạn không hỗ trợ hoặc không cung cấp apiv2 hủy đơn tự động, bạn cần hủy thủ công bằng tay cho khách hàng
- Nội dung: Yêu cầu hủy đơn hàng
- Username: " . $user->username . "\xa- ID order: " . $request->orders . "\xa- ID đơn gốc: " . $order->order_smm . "
- Mức độ: 2
"; if ($chatId && $tokenTelegram) { } return response()->json(array("order" => $requestData["orders"], "cancel" => "1"), 200); } else { return response()->json(array("order" => 1, "cancel" => array("error" => "Gửi ticket yêu cầu hủy đơn thất bại !")), 200); } } } elseif ($request->action == "refill") { $validator = Validator::make($request->all(), array("order" => "required"), array("orderrequired" => "Invalid ID Order !")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("order" => 1, "refill" => $firstErrorMessage), 422); } $requestData = $request->toArray(); $orderId = $requestData["order"]; if (!$orderId) { return array("error" => "Thiếu id_order"); } if (!preg_match("/^[a-zA-Z0-9]+$/", $orderId)) { return array("error" => "id_order không hợp lệ"); } $order = Orders::where("id_order", $orderId)->first(); if (!$order) { return with(array("error" => "Đơn hàng không tồn tại !")); } $server = Server::where("id", $order->server)->where("status", 1)->first(); if (!$server) { return with(array("error" => "Server không tồn tại hoặc không hoạt động !")); } $partner = SmmPanel::where("id", $server->smmpanel)->where("status", 1)->first(); if (!$partner) { return with(array("error" => "Dịch vụ không tồn tại hoặc không hoạt động !")); } Smm_Global::init(array("link" => $partner->link, "token" => $partner->token)); $data = array("key" => $partner->token, "action" => "refill", "order" => $order->order_smm); if ($partner->json == 1) { $data["service"] = (string) $data["service"]; $response = Smm_Global::connect($data, true); } else { $response = Smm_Global::connect($data); } if (isset($result["refill"])) { $order->update(array("note" => "Refill đơn hàng")); return with(array("success" => "Refill đơn hàng thành công !")); } else { return with(array("error" => "Error: " . (isset($result["error"]) ? $result["error"] : (isset($result["message"]) ? $result["message"] : "Dịch vụ không hỗ trợ bảo hành")))); } } elseif ($request->action == "balance") { if ($result) { return response()->json(array("balance" => $result["balance"], "currency" => "VND"), 200); } } else { return response()->json(array("error" => "Incorrect request"), 200); } } public function websites(Request $request) { $validator = Validator::make($request->all(), array("domain_add" => "required", "domain" => "required", "username" => "required"), array("domain_addrequired" => "Vui lòng nhập mã tên miền cần thêm!", "domainrequired" => "Vui lòng nhập mã tên miền gốc!", "domainrequired" => "Vui lòng nhập tên đăng nhập!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("status" => "error", "data" => $firstErrorMessage), 422); } $website_add = Websites::where("domain", $request->domain_add)->first(); if (!$website_add) { $website = Websites::where("domain", $request->domain)->first(); if ($website) { Websites::create(array("domain" => $request->domain_add, "parent_id" => $website->id, "username" => $request->username, "status" => 1)); return response()->json(array("status" => "success", "data" => "Thêm thành công"), 200); } else { return response()->json(array("status" => "error", "data" => "Không tìm thấy website gốc!"), 422); } } else { return response()->json(array("status" => "error", "data" => "Websites cần thêm đã tồn tại!"), 422); } } public function check(Request $request) { $validator = Validator::make($request->all(), array("token" => "required"), array("tokenrequired" => "Vui lòng nhập mã Token!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("status" => "error", "data" => $firstErrorMessage), 422); } $user = User::where("token", $request->token)->first(); if ($user) { $data = array("status" => "success", "data" => array("name" => $user->name, "username" => $user->username, "email" => $user->email, "password" => $user->password, "token" => $user->token)); return response()->json($data, 200); } else { return response()->json(array("status" => "error", "data" => "Token không chính xác!"), 422); } } public function active(Request $request) { $validator = Validator::make($request->all(), array("domain" => "required", "token" => "required"), array("domainrequired" => "Vui lòng nhập tên miền!", "tokenrequired" => "Vui lòng nhập mã Token!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("error" => $firstErrorMessage), 422); } $websites = Websites::where("domain", $request->domain)->where("status", 1)->first(); if (!$websites) { return response()->json(array("status" => "error", "data" => "Không tìm thấy website hoặc chưa được kích hoạt!"), 422); } $id_website_official = Websites::where("id", $websites->parent_id)->first(); if (!$id_website_official) { return response()->json(array("status" => "error", "data" => "Không tìm thấy Website chính thức!"), 422); } try { $response = Anhyeuem37::curl("https://" . $id_website_official->domain . "/api/check", array("token" => $request->token)); $response = json_decode($response, true); if ($response && isset($response["status"]) && $response["status"] == "success") { if ($response["data"]["username"] == $websites->username) { $data = array("status" => "success", "data" => array("domain" => $id_website_official->domain, "name" => $response["data"]["name"], "username" => $response["data"]["username"], "email" => $response["data"]["email"], "password" => $response["data"]["password"], "token" => $response["data"]["token"])); return response()->json($data, 200); } else { return response()->json(array("status" => "error", "data" => "Token không không hợp lệ"), 422); } } else { return response()->json(array("status" => "error", "data" => $response["data"]), 422); } } catch (\Exception $e) { return response()->json(array("status" => "error", "data" => "Có lỗi xảy ra trong quá trình xác thực"), 500); } } public function card(Request $request) { $validator = Validator::make($request->all(), array("request_id" => "required", "callback_sign" => "required"), array("request_idrequired" => "Vui lòng request_id!", "callback_signrequired" => "Vui lòng sign callback!")); if ($validator->fails()) { $firstErrorMessage = $validator->errors()->first(); return response()->json(array("error" => $firstErrorMessage), 422); } $data = $request->all(); $card_pending = Card::where("sign", $data["callback_sign"])->where("request_id", $data["request_id"])->where("status", 0)->first(); if ($card_pending) { $user = User::where("username", $card_pending->username)->first(); $card = Settings::where("key", "card")->value("value"); switch ($data["status"]) { case 1: $total_amount = $card_pending->amount - $card_pending->amount * $card / 100; $card_pending->update(array("status" => $data["status"])); $user->update(array("balance" => $user->balance + $total_amount)); Transaction::create(array("type" => "Card", "amount" => $total_amount, "username" => $card_pending->username, "description" => "Nạp thẻ cào " . $card_pending->serial . " mệnh giá " . $card_pending->amount . " nhận " . $total_amount . " ", "transaction_id" => $card_pending->request_id, "status" => 1)); $chatId = Settings::where("key", "telegram_chat_id")->first()->value; $tokenTelegram = Settings::where("key", "telegram")->first()->value; $message = "Thông Báo Nạp Card !\xa- Tài khoản: " . $user . "
- Loại thẻ: " . $card_pending->serial . "
- Mệnh giá: " . $card_pending->amount . " VND
- Thực nhận: " . $total_amount . " VND
"; if ($chatId && $tokenTelegram) { } break; case 2: $total_amount = $card_pending->amount / 2; $total_amount = $total_amount - $total_amount * $card / 100; $card_pending->update(array("status" => $data["status"])); $user->update(array("balance" => $user->balance + $total_amount)); Transaction::create(array("type" => "Card", "amount" => $total_amount, "username" => $card_pending->username, "description" => "Nạp thẻ cào " . $card_pending->serial . " mệnh giá " . $card_pending->amount . " nhận " . $total_amount . '', "transaction_id" => $card_pending->request_id, "status" => 1)); $chatId = Settings::where("key", "telegram_chat_id")->first()->value; $tokenTelegram = Settings::where("key", "telegram")->first()->value; $message = "Thông Báo Nạp Card !\xa- Tài khoản: " . $user . "
- Loại thẻ: " . $card_pending->serial . "
- Mệnh giá: " . $card_pending->amount . " VND
- Thực nhận: " . $total_amount . " VND
"; if ($chatId && $tokenTelegram) { } break; default: $card_pending->update(array("status" => $data["status"])); break; } } } }
© 2023 Quttera Ltd. All rights reserved.