File manager - Edit - /var/www/order.cmtc.ac.th/user/checkout_4.php
Back
<?php session_start(); include('../config/db.php'); // ✅ ตรวจสอบตะกร้า if(!isset($_SESSION['cart']) || count($_SESSION['cart']) == 0){ header("Location: index.php"); exit; } // ✅ รับข้อมูลจากฟอร์ม $fullname = $_POST['fullname'] ?? ''; $phone = $_POST['phone'] ?? ''; $address = $_POST['address'] ?? ''; $zipcode = $_POST['zipcode'] ?? ''; $receive_method = $_POST['receive_method'] ?? ''; // ✅ ดึงข้อมูลสินค้าจากตะกร้า $ids = implode(",", array_keys($_SESSION['cart'])); $res = $conn->query("SELECT * FROM products WHERE id IN ($ids)"); $items = []; $total = 0.00; while($r = $res->fetch_assoc()){ $pid = (int)$r['id']; $qty = (int)$_SESSION['cart'][$pid]; $sum = (float)$r['price'] * $qty; $total += $sum; $items[] = [ 'id' => $pid, 'name' => $r['name'], 'qty' => $qty, 'price' => (float)$r['price'], 'sum' => $sum ]; } // ✅ ข้อมูลบัญชีพร้อมเพย์จาก “ถุงเงิน” $account_name = "เหรียญที่ระลึก-ทำบุญอาคารอเนกประสงค์"; $owner_name = "วิทยาลัยเทคนิคเชียงใหม่"; $merchant_id = "010753700088820"; // ← Merchant ID จากถุงเงิน (ยืนยันว่า 15 หลัก) // ✅ ฟอร์แมตจำนวนเงิน 2 ตำแหน่ง (เช่น 119.00) $amount = number_format($total, 2, '.', ''); $amount_gen = number_format($total, 0, '.', ''); $amount_num=strlen($amount_gen); echo "amount_gen=$amount_gen amount_num=$amount_num<br>"; // ✅ สร้างรหัส QR Payload ตามโครงสร้างด้านบน // ✅ สร้างภาพ QR ด้วย PHP QR Code และสุ่มชื่อไฟล์ require_once '../libs/phpqrcode/qrlib.php'; $tmpDir = '../libs/phpqrcode/tmp'; if (!is_dir($tmpDir)) { @mkdir($tmpDir, 0777, true); } // สุ่มชื่อไฟล์กันซ้ำ $qrFilename = 'qr_' . date('YmdHis') . '_' . bin2hex(random_bytes(3)) . '.png'; $tempFile = $tmpDir . '/' . $qrFilename; $Q1="00020101021130750016A000000677010112011501075370008820502194M099400W70423284XK0309CMTCCOINS5303764540"; if($amount_num==3){ $Q2="6"; $Q4=".005802TH6208070400006304691B"; } if($amount_num==4){ $Q2="7"; $Q4=".005802TH620807040000630449B5"; } if($amount_num==5){ $Q2="8"; $Q4=".005802TH620807040000630449B5"; } $Q3="$amount_gen"; $qr_string="$Q1$Q2$Q3$Q4"; echo "$qr_string<br>"; $code1="00020101021130750016A000000677010112011501075370008820502194M099400W70423284XK0309CMTCCOINS53037645802TH62080704000063047D50"; //หลีกร้อย 6 $code2="00020101021130750016A000000677010112011501075370008820502194M099400W70423284XK0309CMTCCOINS53037645406999.005802TH6208070400006304691B"; //หลักพัน 7 $code3="00020101021130750016A000000677010112011501075370008820502194M099400W70423284XK0309CMTCCOINS530376454071000.005802TH620807040000630449B5"; //หลักหมื่น 8 $code4="00020101021130750016A000000677010112011501075370008820502194M099400W70423284XK0309CMTCCOINS5303764540810000.005802TH620807040000630449B5"; // ระดับ ECC: M, ขนาด 6, margin 2 //QRcode::png($qr_string, $tempFile, QR_ECLEVEL_M, 6, 2); QRcode::png($qr_string, $tempFile, QR_ECLEVEL_M, 6, 2); ?> <?php include('template_user_header.php'); ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>🧾 ยืนยันการชำระเงิน</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <style> body,*{font-family:'Kanit',sans-serif!important;} .qr-box { text-align:center; border:1px dashed #ccc; border-radius:10px; padding:20px; background:#fafafa; } .qr-box img { width:220px; margin:10px auto; } .account-info { text-align:center; font-size:1rem; color:#333; } .summary-box { background:#fff; border-radius:10px; padding:20px; box-shadow:0 2px 6px rgba(0,0,0,0.1); } </style> </head> <body class="bg-light"> <div class="container py-5"> <div class="summary-box"> <h4 class="mb-3">📋 สรุปรายการสั่งจอง</h4> <!-- ✅ รายละเอียดผู้สั่ง --> <div class="mb-4"> <h6 class="text-secondary mb-2">👤 ข้อมูลผู้จอง</h6> <p><b>ชื่อ-นามสกุล:</b> <?=htmlspecialchars($fullname)?></p> <p><b>เบอร์โทรศัพท์:</b> <?=htmlspecialchars($phone)?></p> <p><b>วิธีรับสินค้า:</b> <?=htmlspecialchars($receive_method)?></p> <?php if($receive_method == 'จัดส่งทางไปรษณีย์'): ?> <p><b>ที่อยู่จัดส่ง:</b> <?=nl2br(htmlspecialchars($address))?></p> <p><b>รหัสไปรษณีย์:</b> <?=htmlspecialchars($zipcode)?></p> <?php endif; ?> </div> <!-- ✅ ตารางสินค้า --> <table class="table table-bordered mt-3 bg-white"> <thead class="table-secondary text-center"> <tr><th>ชื่อเหรียญ</th><th>จำนวน</th><th>ราคา/หน่วย</th><th>รวม</th></tr> </thead> <tbody> <?php foreach($items as $it): ?> <tr> <td><?=$it['name']?></td> <td class="text-center"><?=$it['qty']?></td> <td class="text-end"><?=number_format($it['price'],2)?></td> <td class="text-end"><?=number_format($it['sum'],2)?></td> </tr> <?php endforeach; ?> <tr class="table-light"> <th colspan="3" class="text-end">ยอดรวม</th> <th class="text-end text-success"><?=number_format($total,2)?></th> </tr> </tbody> </table> <!-- ✅ QR สำหรับโอน --> <div class="qr-box mt-4"> <h6>📱 สแกน QR Code เพื่อชำระเงิน</h6> <img src="<?=$tempFile?>" alt="QR PromptPay"> <div class="account-info"> <p><b><?=$owner_name?><br>ชื่อบัญชี:</b> <?=$account_name?></p> <p><b>ยอดที่ต้องชำระ:</b> <span class="text-success"><?=number_format($total,2)?> บาท</span></p> <small class="text-muted">* กรุณาแนบสลิปหลังจากชำระเงิน</small> </div> </div> <!-- ✅ ฟอร์มแนบสลิป --> <form method="post" action="upload_slip.php" enctype="multipart/form-data" class="mt-4"> <input type="hidden" name="fullname" value="<?=htmlspecialchars($fullname)?>"> <input type="hidden" name="phone" value="<?=htmlspecialchars($phone)?>"> <input type="hidden" name="address" value="<?=htmlspecialchars($address)?>"> <input type="hidden" name="zipcode" value="<?=htmlspecialchars($zipcode)?>"> <input type="hidden" name="receive_method" value="<?=htmlspecialchars($receive_method)?>"> <input type="hidden" name="total" value="<?=htmlspecialchars($total)?>"> <input type="hidden" name="qr_string" value="<?=htmlspecialchars($qr_string)?>"> <?php foreach($items as $i): ?> <input type="hidden" name="product_name[]" value="<?=htmlspecialchars($i['name'])?>"> <input type="hidden" name="qty[]" value="<?=$i['qty']?>"> <input type="hidden" name="price[]" value="<?=$i['price']?>"> <?php endforeach; ?> <div class="mb-3 mt-4"> <label>📎 แนบสลิปชำระเงิน (จำเป็น)</label> <input type="file" name="slip" class="form-control" accept="image/*" required> </div> <button type="submit" class="btn btn-success w-100 py-2">💾 ส่งหลักฐานการชำระเงิน</button> </form> </div> </div> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.42 |
proxy
|
phpinfo
|
Settings