getData(); $message = $data['message'] ?? exit; $chat_id = $message['chat']['id']; $text = $message['text'] ?? ""; $contact = $message['contact']['phone_number'] ?? ""; $stepFile = "users/$chat_id.step"; $massFile = "users/$chat_id.mass"; $phoneFile = "users/$chat_id.phone"; $locFile = "users/$chat_id.loc"; $step = file_exists($stepFile) ? file_get_contents($stepFile) : "start"; $orderTypes = [ "1kg - 50 000 so'm", "1.5kg - 75 000 so'm", "4.5kg - 220 000 so'm", "7.5kg - 370 000 so'm" ]; if($text=="/start") start(); elseif($text=="Buyurtma") order(); elseif(in_array($text,$orderTypes)) { file_put_contents($massFile,$text); phone(); } elseif($step=="phone") { $phone = $contact ? $contact : $text; file_put_contents($phoneFile,$phone); location(); } elseif($step=="location") { file_put_contents($locFile,$text); confirm(); } elseif($text=="Tasdiqlash") save(); function start() { global $telegram,$chat_id,$stepFile; file_put_contents($stepFile,"start"); $keyboard=[ ["Buyurtma"] ]; $telegram->sendMessage([ 'chat_id'=>$chat_id, 'text'=>"Asal botiga xush kelibsiz", 'reply_markup'=>$telegram->buildKeyBoard($keyboard,false,true) ]); } function order() { global $telegram,$chat_id,$stepFile; file_put_contents($stepFile,"order"); $keyboard=[ ["1kg - 50 000 so'm"], ["1.5kg - 75 000 so'm"], ["4.5kg - 220 000 so'm"], ["7.5kg - 370 000 so'm"] ]; $telegram->sendMessage([ 'chat_id'=>$chat_id, 'text'=>"Hajmni tanlang", 'reply_markup'=>$telegram->buildKeyBoard($keyboard,false,true) ]); } function phone() { global $telegram,$chat_id,$stepFile; file_put_contents($stepFile,"phone"); $keyboard=[ [$telegram->buildKeyboardButton("Raqam yuborish",true)] ]; $telegram->sendMessage([ 'chat_id'=>$chat_id, 'text'=>"Telefon kiriting", 'reply_markup'=>$telegram->buildKeyBoard($keyboard,false,true) ]); } function location() { global $telegram,$chat_id,$stepFile; file_put_contents($stepFile,"location"); $telegram->sendMessage([ 'chat_id'=>$chat_id, 'text'=>"Manzil kiriting" ]); } function confirm() { global $telegram,$chat_id,$stepFile,$massFile,$phoneFile,$locFile; file_put_contents($stepFile,"confirm"); $mass=file_get_contents($massFile); $phone=file_get_contents($phoneFile); $loc=file_get_contents($locFile); $keyboard=[ ["Tasdiqlash"] ]; $text="Buyurtma: $mass $phone $loc"; $telegram->sendMessage([ 'chat_id'=>$chat_id, 'text'=>$text, 'reply_markup'=>$telegram->buildKeyBoard($keyboard,false,true) ]); } function save() { global $telegram,$chat_id,$massFile,$phoneFile,$locFile,$db,$admin_id,$stepFile; $mass=file_get_contents($massFile); $phone=file_get_contents($phoneFile); $loc=file_get_contents($locFile); $stmt=$db->prepare(" INSERT INTO orders (chat_id,mass,phone,location) VALUES (?,?,?,?) "); $stmt->bind_param( "ssss", $chat_id, $mass, $phone, $loc ); $stmt->execute(); $telegram->sendMessage([ 'chat_id'=>$chat_id, 'text'=>"Buyurtma qabul qilindi" ]); $telegram->sendMessage([ 'chat_id'=>$admin_id, 'text'=>"Yangi buyurtma: $mass $phone $loc" ]); start(); } ?>