File manager - Edit - /home/webapp69.cm.in.th/u69319090006/shop/db.js
Back
/** * SkyMall - Enterprise Multi-Category Marketplace Prototype * Core Logic & LocalStorage Mock Database Management */ // ========================================================================== // 1. INITIAL MOCK DATABASE SEED DATA & STATE MANAGEMENT // ========================================================================== const DEFAULT_CATEGORIES = [ { name: "ไอที/สมาร์ทโฟน", icon: "fa-laptop" }, { name: "เสื้อผ้า/แฟชั่น", icon: "fa-shirt" }, { name: "เครื่องใช้ในบ้าน", icon: "fa-couch" }, { name: "สุขภาพ/ความงาม", icon: "fa-spa" }, { name: "เกม/ของเล่น", icon: "fa-gamepad" }, { name: "สัตว์เลี้ยง", icon: "fa-paw" }, { name: "กีฬา/การท่องเที่ยว", icon: "fa-person-running" }, { name: "ยานยนต์", icon: "fa-car" } ]; const DEFAULT_PRODUCTS = [ { id: "prod-1", name: "Smartphone SkyPhone Pro Max", category: "ไอที/สมาร์ทโฟน", price: 32900, originalPrice: 35900, stock: 25, rating: 4.8, reviewsCount: 42, sellerId: "seller1", sellerName: "ร้านอุปกรณ์ไอที SkyTech", image: "https://images.unsplash.com/photo-1511707171634-5f897ff02aa9?auto=format&fit=crop&w=600&q=80", images: [ "https://images.unsplash.com/photo-1511707171634-5f897ff02aa9?auto=format&fit=crop&w=600&q=80", "https://images.unsplash.com/photo-1592899677977-9c10ca588bbd?auto=format&fit=crop&w=600&q=80", "https://images.unsplash.com/photo-1565849904461-04a58ad377e0?auto=format&fit=crop&w=600&q=80", "https://images.unsplash.com/photo-1580910051074-3eb694886505?auto=format&fit=crop&w=600&q=80" ], description: "สมาร์ทโฟนดีไซน์พรีเมียม กล้องระดับโปร ชิปประมวลผลความเร็วสูง แบตเตอรี่อึดตลอดวัน", active: true, soldCount: 120, isOfficial: true, colors: ["Space Black", "Titanium Silver"], sizes: ["256GB", "512GB"], variants: [ { name: "Space Black / 256GB", price: 32900, stock: 15 }, { name: "Titanium Silver / 512GB", price: 37900, stock: 10 } ] }, { id: "prod-2", name: "เสื้อเชิ้ตลายสก็อตพรีเมียม SkyShirt", category: "เสื้อผ้า/แฟชั่น", price: 890, originalPrice: 1290, stock: 50, rating: 4.6, reviewsCount: 28, sellerId: "seller2", sellerName: "เสื้อผ้าแฟชั่น SkyThreads", image: "https://images.unsplash.com/photo-1596755094514-f87e34085b2c?auto=format&fit=crop&w=600&q=80", images: [ "https://images.unsplash.com/photo-1596755094514-f87e34085b2c?auto=format&fit=crop&w=600&q=80", "https://images.unsplash.com/photo-1602810318383-e386cc2a3ccf?auto=format&fit=crop&w=600&q=80", "https://images.unsplash.com/photo-1603252109303-2751441dd157?auto=format&fit=crop&w=600&q=80" ], description: "เสื้อเชิ้ตแขนยาวเนื้อผ้าคอตตอน 100% สวมใส่สบาย ระบายอากาศได้ดี เหมาะสำหรับทุกโอกาส", active: true, soldCount: 85, isOfficial: false, colors: ["Navy Blue", "Crimson Red"], sizes: ["M", "L", "XL"], variants: [ { name: "Navy Blue / M", price: 890, stock: 20 }, { name: "Crimson Red / L", price: 890, stock: 30 } ] }, { id: "prod-3", name: "หูฟังไร้สายบูลทูธ Noise Cancelling", category: "ไอที/สมาร์ทโฟน", price: 3590, originalPrice: 4990, stock: 30, rating: 4.9, reviewsCount: 65, sellerId: "seller1", sellerName: "ร้านอุปกรณ์ไอที SkyTech", image: "https://images.unsplash.com/photo-1505740420928-5e560c06d30e?auto=format&fit=crop&w=600&q=80", images: [ "https://images.unsplash.com/photo-1505740420928-5e560c06d30e?auto=format&fit=crop&w=600&q=80", "https://images.unsplash.com/photo-1484704849700-f032a568e944?auto=format&fit=crop&w=600&q=80", "https://images.unsplash.com/photo-1546435770-a3e426bf472b?auto=format&fit=crop&w=600&q=80", "https://images.unsplash.com/photo-1583394838336-acd977736f90?auto=format&fit=crop&w=600&q=80" ], description: "หูฟังไร้สายระบบตัดเสียงรบกวนอัจฉริยะ เสียงเบสนุ่มลึก ฟังเพลงต่อเนื่องยาวนานถึง 30 ชั่วโมง", active: true, soldCount: 210, isOfficial: true, colors: ["Matte Black", "Ivory White"], sizes: ["Standard"], variants: [ { name: "Matte Black / Standard", price: 3590, stock: 30 } ] }, { id: "prod-4", name: "เก้าอี้เพื่อสุขภาพ Ergonomic Chair", category: "เครื่องใช้ในบ้าน", price: 5490, originalPrice: 7990, stock: 15, rating: 4.7, reviewsCount: 19, sellerId: "seller1", sellerName: "ร้านอุปกรณ์ไอที SkyTech", image: "https://images.unsplash.com/photo-1580481072645-022f9a6d8310?auto=format&fit=crop&w=600&q=80", images: [ "https://images.unsplash.com/photo-1580481072645-022f9a6d8310?auto=format&fit=crop&w=600&q=80", "https://images.unsplash.com/photo-1505797149-43b0069ec26b?auto=format&fit=crop&w=600&q=80", "https://images.unsplash.com/photo-1586023492125-27b2c045efd7?auto=format&fit=crop&w=600&q=80" ], description: "เก้าอี้ทำงานเพื่อสุขภาพ รองรับสรีระแผ่นหลังและคอ ปรับระดับได้รอบทิศทาง ลดอาการปวดออฟฟิศซินโดรม", active: true, soldCount: 45, isOfficial: false, colors: ["Charcoal Gray", "Midnight Black"], sizes: ["Standard"], variants: [ { name: "Charcoal Gray / Standard", price: 5490, stock: 15 } ] } ]; const DEFAULT_IMAGE_PLACEHOLDERS = { default: "https://placehold.co/600x400/e2e8f0/64748b?text=No+Image" }; const MOCK_SLIP_IMAGE = "https://placehold.co/300x400/e2e8f0/64748b?text=Sample+Slip"; const SLIDE_PROMO_COUPONS = [ { code: "TECH100", type: "amount", value: 100, minSpend: 1000 }, { code: "FASHION50", type: "amount", value: 50, minSpend: 500 }, { code: "PETS20", type: "percent", value: 20, minSpend: 300 }, { code: "VINTAGE15", type: "percent", value: 15, minSpend: 200 }, { code: "FLASH15", type: "percent", value: 15, minSpend: 0 } ]; const DEFAULT_COUPONS = [ { code: "WELCOME100", type: "amount", value: 100, minSpend: 500 }, { code: "SKYSALE10", type: "percent", value: 10, minSpend: 300 }, ...SLIDE_PROMO_COUPONS ]; const state = { currentRole: "client", currentUser: null, dailyPointsClaimed: false, cart: [], wishlist: [], products: [], orders: [], coupons: [], postLoginRedirect: null, appliedCoupon: null, selectedSlipBase64: "", lastOrderResult: null, activeFilters: { search: "", category: "all", sellerId: "all", priceMin: null, priceMax: null, ratingMode: "min", ratingMin: 0, ratings: [], freeShipping: false, hasCoupon: false, colors: [], sizes: [] }, sortBy: "default" }; const SESSION_TIMEOUT_MS = 2 * 60 * 60 * 1000; const db = { getUsers() { try { const data = localStorage.getItem("sk_users"); return data ? JSON.parse(data) : []; } catch (e) { return []; } }, saveUsers(users) { localStorage.setItem("sk_users", JSON.stringify(users)); }, getProducts() { try { const data = localStorage.getItem("sk_products"); if (data) { const parsed = JSON.parse(data); if (Array.isArray(parsed) && parsed.length > 0) { return parsed.map(p => { if (!p.images || !Array.isArray(p.images) || p.images.length === 0) { const defaultProd = DEFAULT_PRODUCTS.find(dp => dp.id === p.id); p.images = (defaultProd && defaultProd.images) ? defaultProd.images : [p.image || DEFAULT_IMAGE_PLACEHOLDERS.default]; } return p; }); } } localStorage.setItem("sk_products", JSON.stringify(DEFAULT_PRODUCTS)); return DEFAULT_PRODUCTS; } catch (e) { return typeof DEFAULT_PRODUCTS !== 'undefined' ? DEFAULT_PRODUCTS : []; } }, saveProducts(products) { localStorage.setItem("sk_products", JSON.stringify(products)); }, getOrders() { try { const data = localStorage.getItem("sk_orders"); return data ? JSON.parse(data) : []; } catch (e) { return []; } }, saveOrders(orders) { localStorage.setItem("sk_orders", JSON.stringify(orders)); }, getCoupons() { try { const data = localStorage.getItem("sk_coupons"); let coupons = data ? JSON.parse(data) : [...DEFAULT_COUPONS]; if (typeof SLIDE_PROMO_COUPONS !== 'undefined') { SLIDE_PROMO_COUPONS.forEach(sc => { if (!coupons.some(c => c.code === sc.code)) { coupons.push(sc); } }); } localStorage.setItem("sk_coupons", JSON.stringify(coupons)); return coupons; } catch (e) { return typeof DEFAULT_COUPONS !== 'undefined' ? [...DEFAULT_COUPONS] : []; } }, saveCoupons(coupons) { localStorage.setItem("sk_coupons", JSON.stringify(coupons)); }, getWishlist() { const user = db.getCurrentUser(); if (!user) return []; try { const data = localStorage.getItem(`sk_wishlist_${user.username}`); return data ? JSON.parse(data) : []; } catch (e) { return []; } }, saveWishlist(wishlist) { const user = db.getCurrentUser(); if (!user) return; localStorage.setItem(`sk_wishlist_${user.username}`, JSON.stringify(wishlist)); }, getCurrentUser() { try { const data = localStorage.getItem("sk_current_user"); const sessionTimeStr = localStorage.getItem("sk_session_time"); if (!data) return null; if (sessionTimeStr) { const lastSessionTime = parseInt(sessionTimeStr, 10); if (Date.now() - lastSessionTime > SESSION_TIMEOUT_MS) { localStorage.removeItem("sk_current_user"); localStorage.removeItem("sk_session_time"); return null; } } localStorage.setItem("sk_session_time", Date.now().toString()); return JSON.parse(data); } catch (e) { return null; } }, setCurrentUser(user) { if (user) { localStorage.setItem("sk_current_user", JSON.stringify(user)); localStorage.setItem("sk_session_time", Date.now().toString()); state.currentUser = user; } else { localStorage.removeItem("sk_current_user"); localStorage.removeItem("sk_session_time"); state.currentUser = null; state.wishlist = []; } } };
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.25 |
proxy
|
phpinfo
|
Settings