diff --git a/backend/app/Platform/Shopee/Constants/PaymentMethod.php b/backend/app/Platform/Shopee/Constants/PaymentMethod.php index 0877ac0..58dd5b2 100644 --- a/backend/app/Platform/Shopee/Constants/PaymentMethod.php +++ b/backend/app/Platform/Shopee/Constants/PaymentMethod.php @@ -13,212 +13,119 @@ enum PaymentMethod: int { use EnumConstantsTrait; - #[Message("Cybersource [ID, VN, TW, SG, MY, TH, PH]")] - case CYBERSOURCE = 1; + #[Message("Credit Card/Debit Card")] + case CREDIT_CARD_DEBIT_CARD = 1; - #[Message("Nicepay Credit Card [ID]")] - case NICEPAY_CREDIT_CARD = 2; + #[Message("Cash on Delivery")] + case CASH_ON_DELIVERY = 2; - #[Message("IPay88 Credit Card [MY]")] - case IPAY88_CREDIT_CARD = 3; + #[Message("PayNow")] + case PAYNOW = 3; - #[Message("Airpay Credit Card [PH]")] - case AIRPAY_CREDIT_CARD_PH = 4; + #[Message("ShopeePay")] + case SHOPEEPAY = 4; - #[Message("Stripe CC [PH]")] - case STRIPE_CC = 5; + #[Message("Apple Pay")] + case APPLE_PAY = 5; - #[Message("Airpay Credit Card [ID, VN, TW, TH]")] - case AIRPAY_CREDIT_CARD = 6; + #[Message("Google Pay")] + case GOOGLE_PAY = 6; - #[Message("Bank Transfer [ID]")] - case BANK_TRANSFER_ID = 7; + #[Message("DBS PayLah!")] + case DBS_PAYLAH = 7; - #[Message("Bank BCA (Manual Transfer) [ID]")] - case BANK_BCA_MANUAL_TRANSFER = 8; + #[Message("JKO Pay")] + case JKO_PAY = 8; - #[Message("Bank Mandiri (Manual Transfer) [ID]")] - case BANK_MANDIRI_MANUAL_TRANSFER = 9; + #[Message("Bank Transfer")] + case BANK_TRANSFER = 9; - #[Message("Bank BNI (Manual Transfer) [ID]")] - case BANK_BNI_MANUAL_TRANSFER = 10; + #[Message("SPayLater")] + case SPAYLATER = 10; - #[Message("Bank BRI (Manual Transfer) [ID]")] - case BANK_BRI_MANUAL_TRANSFER = 11; + #[Message("Linked Bank Account")] + case LINKED_BANK_ACCOUNT = 11; - #[Message("Bank CIMB Niaga (Manual Transfer) [ID]")] - case BANK_CIMB_NIAGA_MANUAL_TRANSFER = 12; + #[Message("Mari Savings Account")] + case MARI_SAVINGS_ACCOUNT = 12; - #[Message("Bank Transfer [VN]")] - case BANK_TRANSFER_VN = 13; + #[Message("Credit / Debit Card")] + case CREDIT_DEBIT_CARD = 13; - #[Message("Fubon Bank Transfer [TW]")] - case FUBON_BANK_TRANSFER = 14; + #[Message("Online / Offline Payment")] + case ONLINE_OFFLINE_PAYMENT = 14; - #[Message("Esun Bank Transfer [TW]")] - case ESUN_BANK_TRANSFER = 15; + #[Message("BPI Online")] + case BPI_ONLINE = 15; - #[Message("Bank Transfer [TW]")] - case BANK_TRANSFER_TW = 16; + #[Message("Payment waived")] + case PAYMENT_WAIVED = 16; - #[Message("Esun CB Bank Transfer [TW]")] - case ESUN_CB_BANK_TRANSFER = 17; + #[Message("SeaBank")] + case SEABANK = 17; - #[Message("Bank Transfer [SG]")] - case BANK_TRANSFER_SG = 18; + #[Message("Online Payment")] + case ONLINE_PAYMENT = 18; - #[Message("Bank Transfer [MY]")] - case BANK_TRANSFER_MY = 19; + #[Message("Indomaret / i.Saku")] + case INDOMARET_ISAKU = 19; - #[Message("ATM Payment [TH]")] - case ATM_PAYMENT = 20; + #[Message("Credit Card Installment")] + case CREDIT_CARD_INSTALLMENT = 20; - #[Message("ATM Payment (BBL) [TH]")] - case ATM_PAYMENT_BBL = 21; + #[Message("SeaBank Bayar Instan")] + case SEABANK_BAYAR_INSTAN = 21; - #[Message("Bank Transfer [TH]")] - case BANK_TRANSFER_TH = 22; + #[Message("Alfamart / Alfamidi / Dan+Dan")] + case ALFAMART_ALFAMIDI_DANDAN = 22; - #[Message("ATM Payment (KBANK) [TH]")] - case ATM_PAYMENT_KBANK = 23; + #[Message("BCA OneKlik")] + case BCA_ONEKLIK = 23; - #[Message("ATM Payment (KTB) [TH]")] - case ATM_PAYMENT_KTB = 24; + #[Message("Mobile Banking")] + case MOBILE_BANKING = 24; - #[Message("ATM Payment (SCB) [TH]")] - case ATM_PAYMENT_SCB = 25; + #[Message("QR Promptpay")] + case QR_PROMPTPAY = 25; - #[Message("ATM Payment (BAY) [TH]")] - case ATM_PAYMENT_BAY = 26; + #[Message("ShopeePay Linked Bank Account")] + case SHOPEEPAY_LINKED_BANK_ACCOUNT = 26; - #[Message("Online Payment (KBANK) [TH]")] - case ONLINE_PAYMENT_KBANK = 27; + #[Message("Online Banking")] + case ONLINE_BANKING = 27; - #[Message("Online Payment (BAY) [TH]")] - case ONLINE_PAYMENT_BAY = 28; + #[Message("Maybank2u")] + case MAYBANK2U = 28; - #[Message("Bank Transfer [PH]")] - case BANK_TRANSFER_PH = 29; + #[Message("Cash Payment at Convenience Stores")] + case CASH_PAYMENT_CONVENIENCE_STORES = 29; - #[Message("Cash on Delivery [ID, VN, SG, MY, TH, PH]")] - case CASH_ON_DELIVERY = 30; + #[Message("Mari Credit")] + case MARI_CREDIT = 30; - #[Message("現付 [TW]")] - case COD_TW = 31; + #[Message("Credit Card Points")] + case CREDIT_CARD_POINTS = 31; - #[Message("Shopee Seller Wallet [ID]")] - case SHOPEE_SELLER_WALLET = 32; + #[Message("Mari Credit Card Instant Checkout")] + case MARI_CREDIT_CARD_INSTANT_CHECKOUT = 32; - #[Message("Shopee Wallet [ID, VN, TW, SG, MY, TH, PH]")] + #[Message("Shopee Wallet")] case SHOPEE_WALLET = 33; - #[Message("Indomaret [ID]")] - case INDOMARET = 34; + #[Message("Cash Payment at Physical Stores")] + case CASH_PAYMENT_PHYSICAL_STORES = 34; - #[Message("Bank BRI (Virtual Account) [ID]")] - case BANK_BRI_VIRTUAL_ACCOUNT = 35; + #[Message("ShopeePay Balance")] + case SHOPEEPAY_BALANCE = 35; - #[Message("Bank BCA (Virtual Account) [ID]")] - case BANK_BCA_VIRTUAL_ACCOUNT = 36; + #[Message("BPI for Payment")] + case BPI_FOR_PAYMENT = 36; - #[Message("Bank Mandiri (Virtual Account) [ID]")] - case BANK_MANDIRI_VIRTUAL_ACCOUNT = 37; + #[Message("MariBank")] + case MARIBANK = 37; - #[Message("Bank BNI (Virtual Account) [ID]")] - case BANK_BNI_VIRTUAL_ACCOUNT = 38; - - #[Message("Virtual Account Parent [ID]")] - case VIRTUAL_ACCOUNT_PARENT = 39; - - #[Message("Android Pay [SG]")] - case ANDROID_PAY = 40; - - #[Message("MOLPay [MY]")] - case MOLPAY = 41; - - #[Message("iPay 88 [MY]")] - case IPAY_88 = 42; - - #[Message("iBanking Payment [TH]")] - case IBANKING_PAYMENT = 43; - - #[Message("iBanking Payment (BBL) [TH]")] - case IBANKING_PAYMENT_BBL = 44; - - #[Message("iBanking Payment (KTB) [TH]")] - case IBANKING_PAYMENT_KTB = 45; - - #[Message("iBanking Payment (SCB) [TH]")] - case IBANKING_PAYMENT_SCB = 46; - - #[Message("Dragonpay - Remittance Center [PH]")] - case DRAGONPAY_REMITTANCE_CENTER = 47; - - #[Message("Dragonpay - OTC [PH]")] - case DRAGONPAY_OTC = 48; - - #[Message("Dragonpay - Online Payment [PH]")] - case DRAGONPAY_ONLINE_PAYMENT = 49; - - #[Message("Buyer-Seller Self Arrange [ID, VN, TW, SG, MY, TH, PH]")] - case BUYER_SELLER_SELF_ARRANGE = 50; - - #[Message("Kredivo [ID]")] - case KREDIVO = 51; - - #[Message("Kredivo - BNPL [ID]")] - case KREDIVO_BNPL = 52; - - #[Message("Kredivo - 3 Months Installment [ID]")] - case KREDIVO_3_MONTHS_INSTALLMENT = 53; - - #[Message("Kredivo - 6 Months Installment [ID]")] - case KREDIVO_6_MONTHS_INSTALLMENT = 54; - - #[Message("Kredivo - 12 Months Installment [ID]")] - case KREDIVO_12_MONTHS_INSTALLMENT = 55; - - #[Message("Nicepay Credit Card Installment [ID]")] - case NICEPAY_CREDIT_CARD_INSTALLMENT = 56; - - #[Message("BCA One Klik [ID]")] - case BCA_ONE_KLIK = 57; - - #[Message("Akulaku [ID]")] - case AKULAKU = 58; - - #[Message("Free [VN, TW, SG, MY, TH, PH]")] - case FREE = 59; - - #[Message("iPay88 CC Installment [MY]")] - case IPAY88_CC_INSTALLMENT = 60; - - #[Message("Ebanx Credit Card [BR]")] - case EBANX_CREDIT_CARD = 61; - - #[Message("Ebanx Credit Card Installment [BR]")] - case EBANX_CREDIT_CARD_INSTALLMENT = 62; - - #[Message("Ebanx Credit Card Installment 1x installment plan [BR]")] - case EBANX_CREDIT_CARD_INSTALLMENT_1X = 63; - - #[Message("Ebanx Credit Card Installment 2x installment plan [BR]")] - case EBANX_CREDIT_CARD_INSTALLMENT_2X = 64; - - #[Message("Ebanx Credit Card Installment 3x installment plan [BR]")] - case EBANX_CREDIT_CARD_INSTALLMENT_3X = 65; - - #[Message("Ebanx Credit Card Installment 4x installment plan [BR]")] - case EBANX_CREDIT_CARD_INSTALLMENT_4X = 66; - - #[Message("Ebanx Credit Card Installment 5x installment plan [BR]")] - case EBANX_CREDIT_CARD_INSTALLMENT_5X = 67; - - #[Message("Ebanx Credit Card Installment 6x installment plan [BR]")] - case EBANX_CREDIT_CARD_INSTALLMENT_6X = 68; - - #[Message("Ebanx Boleto [BR]")] - case EBANX_BOLETO = 69; + #[Message("Domestic NAPAS Card")] + case DOMESTIC_NAPAS_CARD = 38; #[Message("Other - Unknown or new payment method")] case OTHER = 255; diff --git a/backend/app/Platform/Shopee/EntityParse/Order.php b/backend/app/Platform/Shopee/EntityParse/Order.php index f023ce7..4a8180d 100644 --- a/backend/app/Platform/Shopee/EntityParse/Order.php +++ b/backend/app/Platform/Shopee/EntityParse/Order.php @@ -8,7 +8,11 @@ use App\Model\Company; use App\Model\Model as Entity; use App\Model\Store; use App\Entity\Parse\EntityParse; +use App\Platform\Shopee\Constants\OrderStatus; +use App\Platform\Shopee\Constants\PaymentMethod; use Hyperf\Collection\LazyCollection; +use Hyperf\Context\ApplicationContext; +use Psr\Log\LoggerInterface; use InvalidArgumentException; /** @@ -131,7 +135,10 @@ class Order extends EntityParse 'company_id' => $this->getCompany()->id, 'platform_id' => 25, 'store_id' => $this->getStore()->id, - 'unique_id' => $record['unique_id'] ?? $this->getData()['unique_id'] ?? null, + 'order_status_id'=> OrderStatus::{$record['order_status']}->value, + 'platform_order_id' => $record['order_sn'], + 'payment_method_id' => $this->parsePaymentMethod($record['payment_method'] ?? ''), + 'presale' => false, 'raw_data' => json_encode($record['raw']), // 根据实际业务需求映射其他字段 // 例如: @@ -148,6 +155,72 @@ class Order extends EntityParse return []; } + /** + * 解析 Shopee 支付方式字符串到 PaymentMethod 枚举值 + * + * @param string $paymentMethodStr Shopee 返回的支付方式字符串 + * @return int PaymentMethod 枚举值 + */ + private function parsePaymentMethod(string $paymentMethodStr): int + { + // 支付方式映射表:Shopee 字符串 => PaymentMethod 枚举 + $paymentMap = [ + 'Credit Card/Debit Card' => PaymentMethod::CREDIT_CARD_DEBIT_CARD, + 'Cash on Delivery' => PaymentMethod::CASH_ON_DELIVERY, + 'PayNow' => PaymentMethod::PAYNOW, + 'ShopeePay' => PaymentMethod::SHOPEEPAY, + 'Apple Pay' => PaymentMethod::APPLE_PAY, + 'Google Pay' => PaymentMethod::GOOGLE_PAY, + 'DBS PayLah!' => PaymentMethod::DBS_PAYLAH, + 'JKO Pay' => PaymentMethod::JKO_PAY, + 'Bank Transfer' => PaymentMethod::BANK_TRANSFER, + 'SPayLater' => PaymentMethod::SPAYLATER, + 'Linked Bank Account' => PaymentMethod::LINKED_BANK_ACCOUNT, + 'Mari Savings Account' => PaymentMethod::MARI_SAVINGS_ACCOUNT, + 'Credit / Debit Card' => PaymentMethod::CREDIT_DEBIT_CARD, + 'Online / Offline Payment' => PaymentMethod::ONLINE_OFFLINE_PAYMENT, + 'BPI Online' => PaymentMethod::BPI_ONLINE, + 'Payment waived' => PaymentMethod::PAYMENT_WAIVED, + 'SeaBank' => PaymentMethod::SEABANK, + 'Online Payment' => PaymentMethod::ONLINE_PAYMENT, + 'Indomaret / i.Saku' => PaymentMethod::INDOMARET_ISAKU, + 'Credit Card Installment' => PaymentMethod::CREDIT_CARD_INSTALLMENT, + 'SeaBank Bayar Instan' => PaymentMethod::SEABANK_BAYAR_INSTAN, + 'Alfamart / Alfamidi / Dan+Dan' => PaymentMethod::ALFAMART_ALFAMIDI_DANDAN, + 'BCA OneKlik' => PaymentMethod::BCA_ONEKLIK, + 'Mobile Banking' => PaymentMethod::MOBILE_BANKING, + 'QR Promptpay' => PaymentMethod::QR_PROMPTPAY, + 'ShopeePay Linked Bank Account' => PaymentMethod::SHOPEEPAY_LINKED_BANK_ACCOUNT, + 'Online Banking' => PaymentMethod::ONLINE_BANKING, + 'Maybank2u' => PaymentMethod::MAYBANK2U, + 'Cash Payment at Convenience Stores' => PaymentMethod::CASH_PAYMENT_CONVENIENCE_STORES, + 'Mari Credit' => PaymentMethod::MARI_CREDIT, + 'Credit Card Points' => PaymentMethod::CREDIT_CARD_POINTS, + 'Mari Credit Card Instant Checkout' => PaymentMethod::MARI_CREDIT_CARD_INSTANT_CHECKOUT, + 'Shopee Wallet' => PaymentMethod::SHOPEE_WALLET, + 'Cash Payment at Physical Stores' => PaymentMethod::CASH_PAYMENT_PHYSICAL_STORES, + 'ShopeePay Balance' => PaymentMethod::SHOPEEPAY_BALANCE, + 'BPI for Payment' => PaymentMethod::BPI_FOR_PAYMENT, + 'MariBank' => PaymentMethod::MARIBANK, + 'Domestic NAPAS Card' => PaymentMethod::DOMESTIC_NAPAS_CARD, + ]; + + // 如果找到匹配的支付方式,返回对应的枚举值 + if (isset($paymentMap[$paymentMethodStr])) { + return $paymentMap[$paymentMethodStr]->value; + } + + // 未找到匹配,记录日志并返回 OTHER + $logger = ApplicationContext::getContainer()->get(LoggerInterface::class); + $logger->warning('Shopee unknown payment method detected', [ + 'payment_method' => $paymentMethodStr, + 'platform' => 'shopee', + 'parser' => self::class, + ]); + + return PaymentMethod::OTHER->value; + } + /** * 可选:覆盖唯一标识符提取逻辑 *