Amazon SP API拉取日期范围报告和分类树
2023-07-08 16:10 天心PHP 阅读(688) 评论(3) 编辑 收藏 举报基础类:https://www.cnblogs.com/xiangshihua/p/16598177.html
日期范围报告 GET_DATE_RANGE_FINANCIAL_TRANSACTION_DATA
日期范围报告无法申请报告,只能通过爬虫去模拟后台登陆点击生成报告(升级后抓取不到 report_id)记录生成报告成功的时间
再用 GET_DATE_RANGE_FINANCIAL_TRANSACTION_DATA 报告列表去匹配 上面成功时间最近的一个报告拉取
日期范围报告由于每个站点的表头不一样可以做成配置
SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for yibai_amazon_report_zn_title -- ---------------------------- DROP TABLE IF EXISTS `yibai_amazon_report_zn_title`; CREATE TABLE `yibai_amazon_report_zn_title` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID', `column` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'column', `title` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '标题', `UK` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'UK', `DE` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'DE', `FR` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'FR', `ES` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'ES', `IT` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'IT', `NL` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'NL', `PL` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'PL', `SE` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'SE', `TR` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'TR', `US` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'US', `CA` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'CA', `MX` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'MX', `BR` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'BR', `JP` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'JP', `creator` int(11) NOT NULL DEFAULT 0 COMMENT '添加人', `create_time` datetime(0) NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '创建时间', `update_time` datetime(0) NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '修改时间', `BE` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '比利时', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 33 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'Amazon日期范围报告表头' ROW_FORMAT = Compact; -- ---------------------------- -- Records of yibai_amazon_report_zn_title -- ---------------------------- INSERT INTO `yibai_amazon_report_zn_title` VALUES (1, 'date_time', 'date/time', 'date/time', 'Datum/Uhrzeit', 'date/heure', 'fecha y hora', 'Data/Ora', 'datum/tijd', 'data/godzina', 'datum/tid', 'tarih/saat', 'date/time', 'date/time', 'fecha/hora', 'data/hora', 'HM-46スピーカーマイク Delaman ハンドヘルド', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'date/heure'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (2, 'settlement_id', 'settlement id', 'settlement id', 'Abrechnungsnummer', 'numéro de versement', 'identificador de pago', 'Numero pagamento', 'schikkings-ID', 'identyfikator rozliczenia', 'reglerings-id', 'hesap kesim no', 'settlement id', 'settlement id', 'Id de liquidación', 'id de liquidação', '決済番号', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'Identifiant du paiement'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (3, 'type', 'type', 'type', 'Typ', 'type', 'tipo', 'Tipo', 'type', 'typ', 'typ', 'tip', 'type', 'type', 'tipo ', 'tipo', 'トランザクションの種類', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'type'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (4, 'order_id', 'order id', 'order id', 'Bestellnummer', 'numéro de la commande', 'número de pedido', 'Numero ordine', 'bestelnummer', 'identyfikator zamówienia', 'beställnings-id', 'sipariş no', 'order id', 'order id', 'Id del pedido', 'id do pedido', '注文番号', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'Numéro de la commande'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (5, 'sku', 'sku', 'sku', 'SKU', 'sku', 'sku', 'SKU', 'sku', 'sku', 'sku', 'sku', 'sku', 'sku', 'sku', 'sku', 'SKU', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'SKU'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (6, 'description', 'description', 'description', 'Beschreibung', 'description', 'descripción', 'Descrizione', 'beschrijving', 'opis', 'beskrivning', 'açıklama', 'description', 'description', 'descripción', 'descrição', '説明', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'description'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (7, 'quantity', 'quantity', 'quantity', 'Menge', 'quantité', 'cantidad', 'Quantità', 'aantal', 'ilość', 'antal', 'adet', 'quantity', 'quantity', 'cantidad', 'quantidade', '数量', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'quantité'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (8, 'marketplace', 'marketplace', 'marketplace', 'Marketplace', 'Marketplace', 'web de Amazon', 'Marketplace', 'marketplace', 'rynek', 'marknadsplats', 'pazar yeri', 'marketplace', 'marketplace', 'marketplace', 'mercado', 'Amazon 出品サービス', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'site de vente'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (9, 'account_type', 'account type', '', '', '', '', '', '', '', '', '', 'account type', '', '', 'tipo de conta', '', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', ''); INSERT INTO `yibai_amazon_report_zn_title` VALUES (10, 'fulfillment', 'fulfillment', 'fulfilment', 'Versand', 'traitement', 'gestión logística', 'Gestione', 'fulfillment', 'realizacja', 'leverans', 'gönderim', 'fulfillment', 'fulfillment', 'cumplimiento', 'atendimento', 'フルフィルメント', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'expédition'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (11, 'order_city', 'order city', 'order city', 'Ort der Bestellung', 'ville d', 'ciudad de procedencia del pedido', 'Città di provenienza dell', 'bestelling stad', 'miejscowość zamówienia', 'stad för beställning', 'sipariş şehri', 'order city', 'order city', 'ciudad del pedido', 'cidade do pedido', '市町村', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'ville de la commande'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (12, 'order_state', 'order state', 'order state', 'Bundesland', 'Région d', 'comunidad autónoma de procedencia del pedido', 'Provincia di provenienza dell', 'status bestelling', 'stan zamówienia', 'delstat för beställning', 'sipariş durumu', 'order state', 'order state', 'estado del pedido', 'estado do pedido', '都道府県', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'état de la commande'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (13, 'order_postal', 'order postal', 'order postal', 'Postleitzahl', 'code postal de la commande', 'código postal de procedencia del pedido', 'CAP dell', 'bestelling per post', 'przekaz pocztowy', 'postadress för beställning', 'sipariş postası', 'order postal', 'order postal', 'código postal del pedido', 'postal do pedido', '郵便番号', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'commande postale'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (14, 'tax_collection_model', 'tax collection model', 'tax collection model', 'Steuererhebungsmodell', 'Modèle de perception des taxes', 'Formulario de recaudación de impuestos', 'modello di riscossione delle imposte', '', '', '', '', 'tax collection model', 'tax collection model', 'modelo de recaudación de impuestos', '', '税金徴収型', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', ''); INSERT INTO `yibai_amazon_report_zn_title` VALUES (15, 'product_sales', 'product sales', 'product sales', 'Umsätze', 'ventes de produits', 'ventas de productos', 'Vendite', 'verkoop van producten', 'sprzedaż produktów', 'försäljning av produkter', 'ürün satışları', 'product sales', 'product sales', 'ventas de productos', 'vendas do produto', '商品売上', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'ventes de produits'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (16, 'product_sales_tax', 'product sales tax', 'product sales tax', 'Produktumsatzsteuer', 'Taxes sur la vente des produits', 'impuesto de ventas de productos', 'imposta sulle vendite dei prodotti', '', '', '', '', 'product sales tax', 'product sales tax', 'impuesto de ventas de productos', '', '商品の売上税', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', ''); INSERT INTO `yibai_amazon_report_zn_title` VALUES (17, 'shipping_credits', 'shipping credits', 'shipping credits', 'Gutschrift für Versandkosten', 'crédits d', 'abonos de envío', 'Accrediti per le spedizioni', 'Verzendtegoeden', 'noty kredytowe za wysyłkę', 'fraktkrediter', 'kargo kredileri', 'shipping credits', 'shipping credits', 'créditos de envío', 'créditos de remessa', '配送料', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'crédits d’expédition'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (18, 'shipping_credits_tax', 'shipping credits tax', 'shipping credits tax', 'Steuer auf Versandgutschrift', 'taxe sur les crédits d’expédition', 'impuestos por abonos de envío', 'imposta accrediti per le spedizioni', '', 'środki na pokrycie pakowania na prezent', '', '', 'shipping credits tax', 'shipping credits tax', 'impuesto de abono de envío', '', '配送料の税金', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', ''); INSERT INTO `yibai_amazon_report_zn_title` VALUES (19, 'gift_wrap_credits', 'gift wrap credits', 'gift wrap credits', 'Gutschrift für Geschenkverpackung', 'crédits sur l', 'abonos de envoltorio para regalo', 'Accrediti per confezioni regalo', 'kredietpunten cadeauverpakking', '', 'krediter för presentinslagning', '', 'gift wrap credits', 'gift wrap credits', 'créditos por envoltorio de regalo', '', 'ギフト包装手数料', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'crédits d’emballage-cadeau'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (20, 'gift_wrap_credits_tax', 'gift wrap credits tax', 'gift wrap credits tax', 'Steuer auf Geschenkverpackungsgutschriften', 'Taxes sur les crédits cadeaux', 'giftwrap credits tax', 'imposta sui crediti confezione regalo', '', '', '', '', 'giftwrap credits tax', 'giftwrap credits tax', 'impuesto de créditos de envoltura', '', 'ギフト包装クレジットの税金', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', ''); INSERT INTO `yibai_amazon_report_zn_title` VALUES (21, 'regulatory_fee', 'Regulatory fee', '', '', '', '', '', '', '', '', '', 'Regulatory Fee', 'Regulatory fee', 'Tarifa reglamentaria', '', '', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', ''); INSERT INTO `yibai_amazon_report_zn_title` VALUES (22, 'tax_on_regulatory_fee', 'Tax on regulatory fee', '', '', '', '', '', '', '', '', '', 'Tax On Regulatory Fee', 'Tax on regulatory fee', 'Impuesto sobre tarifa reglamentaria', '', 'Amazonポイントの費用', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', ''); INSERT INTO `yibai_amazon_report_zn_title` VALUES (23, 'promotional_rebates', 'promotional rebates', 'promotional rebates', 'Rabatte aus Werbeaktionen', 'Rabais promotionnels', 'devoluciones promocionales', 'Sconti promozionali', '', 'rabaty promocyjne', 'kampanjrabatter', 'promosyon indirimleri', 'promotional rebates', 'promotional rebates', 'descuentos promocionales', 'descontos promocionais', 'プロモーション割引額', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'Total des réductions'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (24, 'promotional_rebates_tax', 'promotional rebates tax', 'promotional rebates tax', 'Steuer auf Aktionsrabatte', 'Taxes sur les remises promotionnelles', 'promotional rebates tax', 'imposta sugli sconti promozionali', 'promotiekortingen', '', '', '', 'promotional rebates tax', 'promotional rebates tax', 'impuesto de reembolsos promocionales', 'imposto de vendas coletados', 'プロモーション割引の税金', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', ''); INSERT INTO `yibai_amazon_report_zn_title` VALUES (25, 'sales_tax_collected', 'sales tax collected', '', '', '', '', '', 'ge?nde omzetbelasting', 'pobrany podatek od sprzeda?y', 'Inkasserad moms', '', '', '', '', 'tarifas de venda', '', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'taxe de ventes prélevée'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (26, 'marketplace_facilitator_tax', 'marketplace facilitator tax', '', '', '', '', '', 'Belasting voor marketplace-facilitator', 'Marketplace Facilitator Tax', 'Skatt för marknadsplatsförmedlare', '', '', '', '', '', '', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'Taxe Marketplace Facilitator'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (27, 'marketplace_withheld_tax', 'marketplace withheld tax', 'marketplace withheld tax', 'Einbehaltene Steuer auf Marketplace', 'Taxes retenues sur le site de vente', 'impuesto retenido en el sitio web', 'trattenuta IVA del marketplace', '', '', '', '', 'marketplace withheld tax', 'marketplace withheld tax', 'impuesto de retenciones en la plataforma', '', '源泉徴収税を伴うマーケットプレイス', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', ''); INSERT INTO `yibai_amazon_report_zn_title` VALUES (28, 'selling_fees', 'selling fees', 'selling fees', 'Verkaufsgebühren', 'frais de vente', 'tarifas de venta', 'Commissioni di vendita', 'verkoopkosten', 'opłaty za sprzedaż', 'försäljningsavgifter', 'satış ücretleri', 'selling fees', 'selling fees', 'tarifas de venta', '', '手数料', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'frais de vente'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (29, 'fba_fees', 'fba fees', 'fba fees', 'Gebühren zu Versand durch Amazon', 'Frais Expédié par Amazon', 'tarifas de Logística de Amazon', 'Costi del servizio Logistica di Amazon', 'fba-vergoedingen', 'opłaty za fba', 'fba-avgifter', 'Amazon Lojistik ücretleri', 'fba fees', 'fba fees', 'tarifas fba', 'taxas fba', 'FBA 手数料', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'Frais pour le service Expédié par Amazon'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (30, 'other_transaction_fees', 'other transaction fees', 'other transaction fees', 'Andere Transaktionsgebühren', 'autres frais de transaction', 'tarifas de otras transacciones', 'Altri costi relativi alle transazioni', 'overige transactiekosten', 'inne opłaty transakcyjne', 'övriga transaktionsavgifter', 'diğer işlem ücretleri', 'other transaction fees', 'other transaction fees', 'tarifas de otra transacción', 'taxas de outras transações', 'トランザクションに関するその他の手数料', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'autres frais de transaction'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (31, 'other', 'other', 'other', 'Andere', 'autre', 'otro', 'Altro', 'overige', 'inne', 'Övrigt', 'diğer', 'other', 'other', 'otro', 'outro', 'その他', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'autres'); INSERT INTO `yibai_amazon_report_zn_title` VALUES (32, 'total', 'total', 'total', 'Gesamt', 'total', 'total', 'totale', 'totaal', 'suma', 'totalt', 'toplam', 'total', 'total', 'total', 'total', '合計', 5249, '2022-05-12 08:29:57', '2023-07-06 11:09:58', 'total'); SET FOREIGN_KEY_CHECKS = 1;
2.根据抓取回来的 report_id 得到 reportDocumentId
$result = $requestReport->getreportstatus($account->merchant_id,strtolower($account->site),'/reports/2021-06-30/reports/'.$val['reportid'],"","","GET");//按reportid拉取 Array ( [reportType] => GET_DATE_RANGE_FINANCIAL_TRANSACTION_DATA [processingEndTime] => 2023-07-05T09:53:55+00:00 [processingStatus] => DONE [marketplaceIds] => Array ( [0] => A33AVAJ2PDY3EV ) [reportDocumentId] => amzn1.spdoc.1.4.eu.eea6506b-801e-4e09-86fd-ca0586f647de.T2317I9CIX7RVN.1202 [reportId] => 627541019543 [dataEndTime] => 2023-06-30T21:00:00+00:00 [createdTime] => 2023-07-05T09:53:55+00:00 [processingStartTime] => 2023-07-05T09:53:55+00:00 [dataStartTime] => 2023-05-31T21:00:00+00:00 )
3.根据 reportDocumentId 得到下载文件的url
Array ( [reportDocumentId] => amzn1.spdoc.1.4.eu.eea6506b-801e-4e09-86fd-ca0586f647de.T2317I9CIX7RVN.1202 [url] => https://tortuga-prod-eu.s3-eu-west-1.amazonaws.com/%2FNinetyDays/amzn1.tortuga.4.eu.eea6506b-801e-4e09-86fd-ca0586f647de.T2317I9CIX7RVN?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230708T074426Z&X-Amz-SignedHeaders=host&X-Amz-Expires=300&X-Amz-Credential=AKIAX2ZVOZFBO35GNC5T%2F20230708%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Signature=512531251748090b6bbfa2cb546e9efa846de21e8a87c309f0f05523d7810dba )
4.解析数据
CREATE TABLE `yibai_amazon_report_zn_detail_new` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', `account_name` varchar(50) NOT NULL DEFAULT '' COMMENT '账号', `group_id` int(11) NOT NULL DEFAULT '0' COMMENT '组ID', `account_id` int(10) NOT NULL DEFAULT '0' COMMENT '账号ID', `date_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'date_time', `settlement_id` varchar(50) NOT NULL DEFAULT '' COMMENT 'settlement_id', `type` varchar(60) NOT NULL DEFAULT '' COMMENT 'type', `order_id` varchar(50) NOT NULL DEFAULT '' COMMENT 'order_id', `sku` varchar(50) NOT NULL DEFAULT '' COMMENT 'sku', `description` varchar(255) NOT NULL DEFAULT '' COMMENT 'description', `quantity` int(6) NOT NULL DEFAULT '0' COMMENT 'quantity', `marketplace` varchar(50) NOT NULL DEFAULT '' COMMENT 'marketplace', `account_type` varchar(50) NOT NULL DEFAULT '' COMMENT 'account type', `fulfillment` varchar(50) NOT NULL DEFAULT '' COMMENT 'fulfillment', `order_city` varchar(50) NOT NULL DEFAULT '' COMMENT 'order_city', `order_state` varchar(255) NOT NULL DEFAULT '' COMMENT 'order_state', `order_postal` varchar(50) NOT NULL DEFAULT '' COMMENT 'order_postal', `tax_collection_model` varchar(50) NOT NULL DEFAULT '' COMMENT 'tax_collection_model', `product_sales` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'product_sales', `product_sales_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'product_sales_原文', `product_sales_tax` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'product_sales_tax', `product_sales_tax_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'product_sales_tax_原文', `shipping_credits` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'shipping_credits', `shipping_credits_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'shipping_credits_原文', `shipping_credits_tax` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'shipping_credits_tax', `shipping_credits_tax_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'shipping_credits_tax_原文', `gift_wrap_credits` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'gift_wrap_credits', `gift_wrap_credits_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'gift_wrap_credits_原文', `gift_wrap_credits_tax` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'gift_wrap_credits_tax', `gift_wrap_credits_tax_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'gift_wrap_credits_tax_原文', `regulatory_fee` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'regulatory_fee', `regulatory_fee_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'regulatory_fee_原文', `tax_on_regulatory_fee` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'tax_on_regulatory_fee', `tax_on_regulatory_fee_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'tax_on_regulatory_fee_原文', `promotional_rebates` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'promotional_rebates', `promotional_rebates_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'promotional_rebates_原文', `promotional_rebates_tax` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'promotional_rebates_tax', `promotional_rebates_tax_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'promotional_rebates_tax_原文', `sales_tax_collected` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'sales_tax_collected', `sales_tax_collected_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'sales_tax_collected_原文', `marketplace_facilitator_tax` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'marketplace_facilitator_tax', `marketplace_facilitator_tax_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'marketplace_facilitator_tax_原文', `marketplace_withheld_tax` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'marketplace_withheld_tax', `marketplace_withheld_tax_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'marketplace_withheld_tax_原文', `selling_fees` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'selling_fees', `selling_fees_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'selling_fees_原文', `fba_fees` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'fba_fees', `fba_fees_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'fba_fees_原文', `other_transaction_fees` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'other_transaction_fees', `other_transaction_fees_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'other_transaction_fees_原文', `other` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'other', `other_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'other_原文', `total` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'total', `total_txt` varchar(100) NOT NULL DEFAULT '' COMMENT 'total_原文', `creator` int(11) NOT NULL DEFAULT '0' COMMENT 'creator', `create_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'create_time', `batchnumber` char(8) NOT NULL DEFAULT '0' COMMENT '批次', `is_config` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0:默认 1:已加入中文配置表', `is_user` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0:系统拉取 1:人工导入', PRIMARY KEY (`id`) USING BTREE, KEY `idx_acc` (`account_id`) USING BTREE, KEY `idx_ct` (`create_time`) USING BTREE, KEY `idx_bn` (`batchnumber`) USING BTREE, KEY `idx_fulfillment` (`fulfillment`) USING BTREE, KEY `idx_type` (`type`) USING BTREE, KEY `idx_sku` (`sku`) USING BTREE, KEY `idx_order_id` (`order_id`) USING BTREE, KEY `idx_is_config` (`is_config`) ) ENGINE=InnoDB AUTO_INCREMENT=117442 DEFAULT CHARSET=utf8mb4 COMMENT='Amazon日期范围报告表';
其中需要对 内容的 一些时间,和金额 进行转换
例如 date_time 的时间转换
/* * 时间格式转换 */ public function datechange($site,$dateval){ switch ($site){ case 'us': $datearr = ['Jan'=>1,'Feb'=>2,'Mar'=>3,'Apr'=>4,'May'=>5,'Jun'=>6,'Jul'=>7,'Aug'=>8,'Sep'=>9,'Sept'=>9,'Oct'=>10,'Nov'=>11,'Dec'=>12]; $arr = explode(' ',$dateval); $month = $datearr[$arr[0]]; $year = $arr[2]; $arr[1] = str_replace(',','',$arr[1]); $day = $arr[1]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; case 'ca': $datearr = ['Jan'=>1,'Feb'=>2,'Mar'=>3,'Apr'=>4,'May'=>5,'Jun'=>6,'Jul'=>7,'Aug'=>8,'Sep'=>9,'Sept'=>9,'Oct'=>10,'Nov'=>11,'Dec'=>12]; $arr = explode(' ',$dateval); $month = $datearr[$arr[0]]; $year = $arr[2]; $arr[1] = str_replace(',','',$arr[1]); $day = $arr[1]; $arr[4] = str_replace('.','',$arr[4]); $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; case 'mx': $datearr = ['ene'=>1,'feb'=>2,'mar'=>3,'abr'=>4,'may'=>5,'jun'=>6,'jul'=>7,'ago'=>8,'sep'=>9,'sept'=>9,'oct'=>10,'nov'=>11,'dic'=>12]; $arr = explode(' ',$dateval); $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; case 'uk': $datearr = ['Jan'=>1,'Feb'=>2,'Mar'=>3,'Apr'=>4,'May'=>5,'Jun'=>6,'Jul'=>7,'Aug'=>8,'Sep'=>9,'Sept'=>9,'Oct'=>10,'Nov'=>11,'Dec'=>12]; $arr = explode(' ',$dateval); if($datearr[$arr[1]]){ $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; }else{ $dataarr = explode('.',$arr[0]); $month = $dataarr[1]; $year = $dataarr[2]; $day = $dataarr[0]; $time = $arr[1]; return $year.'-'.$month.'-'.$day.' '.$time; } case 'de': $datearr = ['jan'=>1,'feb'=>2,'mrt'=>3,'apr'=>4,'mei'=>5,'jun'=>6,'jul'=>7,'aug'=>8,'sep'=>9,'sept'=>9,'okt'=>10,'nov'=>11,'dec'=>12]; $arr = explode(' ',$dateval); if($datearr[$arr[1]]){ $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; }else{ $dataarr = explode('.',$arr[0]); $month = $dataarr[1]; $year = $dataarr[2]; $day = $dataarr[0]; $time = $arr[1]; return $year.'-'.$month.'-'.$day.' '.$time; } case 'fr': $datearr = ['janv'=>1,'févr'=>2,'mars'=>3,'avr'=>4,'mai'=>5,'juin'=>6,'juil'=>7,'août'=>8,'sept'=>9,'sept'=>9,'oct'=>10,'nov'=>11,'déc'=>12]; $arr = explode(' ',$dateval); $arr[1] = str_replace('.','',$arr[1]); $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; case 'es': $datearr = ['ene'=>1,'feb'=>2,'mar'=>3,'abr'=>4,'may'=>5,'jun'=>6,'jul'=>7,'ago'=>8,'sep'=>9,'sept'=>9,'oct'=>10,'nov'=>11,'dic'=>12]; $arr = explode(' ',$dateval); if($datearr[$arr[1]]){ $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; }else{ $datearr = ['janv'=>1,'févr'=>2,'mars'=>3,'avr'=>4,'mai'=>5,'juin'=>6,'juil'=>7,'août'=>8,'sep'=>9,'sept'=>9,'oct'=>10,'nov'=>11,'déc'=>12]; $arr = explode(' ',$dateval); $arr[1] = str_replace('.','',$arr[1]); if($datearr[$arr[1]]){ $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; }else{ $arr1 = explode('.',$arr[0]); $year = $arr1[2]; $month = $arr1[1]; $day = $arr1[0]; $time = $arr[1]; return $year.'-'.$month.'-'.$day.' '.$time; } } case 'sp': $datearr = ['ene'=>1,'feb'=>2,'mar'=>3,'abr'=>4,'may'=>5,'jun'=>6,'jul'=>7,'ago'=>8,'sep'=>9,'sept'=>9,'oct'=>10,'nov'=>11,'dic'=>12]; $arr = explode(' ',$dateval); if($datearr[$arr[1]]){ $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; }else{ $datearr = ['janv'=>1,'févr'=>2,'mars'=>3,'avr'=>4,'mai'=>5,'juin'=>6,'juil'=>7,'août'=>8,'sep'=>9,'sept'=>9,'oct'=>10,'nov'=>11,'déc'=>12]; $arr = explode(' ',$dateval); $arr[1] = str_replace('.','',$arr[1]); if($datearr[$arr[1]]){ $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; }else{ $arr1 = explode('.',$arr[0]); $year = $arr1[2]; $month = $arr1[1]; $day = $arr1[0]; $time = $arr[1]; return $year.'-'.$month.'-'.$day.' '.$time; } } case 'it': $datearr = ['gen'=>1,'feb'=>2,'mar'=>3,'apr'=>4,'mag'=>5,'giu'=>6,'lug'=>7,'ago'=>8,'set'=>9,'sept'=>9,'ott'=>10,'nov'=>11,'dic'=>12]; $arr = explode(' ',$dateval); if($datearr[$arr[1]]){ $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; }else{ $datearr = ['jan'=>1,'feb'=>2,'mrt'=>3,'apr'=>4,'mei'=>5,'jun'=>6,'jul'=>7,'aug'=>8,'sep'=>9,'sept'=>9,'okt'=>10,'nov'=>11,'dec'=>12]; $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; } case 'nl': $datearr = ['jan'=>1,'feb'=>2,'mrt'=>3,'apr'=>4,'mei'=>5,'jun'=>6,'jul'=>7,'aug'=>8,'sep'=>9,'sept'=>9,'okt'=>10,'nov'=>11,'dec'=>12]; $arr = explode(' ',$dateval); $arr[1] = str_replace('.','',$arr[1]); $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; case 'pl': $datearr = ['sty'=>1,'lut'=>2,'mar'=>3,'kwi'=>4,'maj'=>5,'cze'=>6,'lip'=>7,'sie'=>8,'wrz'=>9,'paź'=>10,'lis'=>11,'gru'=>12]; $arr = explode(' ',$dateval); $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; case 'se': $datearr = ['jan'=>1,'feb'=>2,'mars'=>3,'apr'=>4,'maj'=>5,'juni'=>6,'juli'=>7,'aug'=>8,'sep'=>9,'sept'=>9,'okt'=>10,'nov'=>11,'dec'=>12]; $arr = explode(' ',$dateval); $arr[1] = str_replace('.','',$arr[1]); if($datearr[$arr[1]]){ $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; }else{ $datearr = ['jan'=>1,'feb'=>2,'mrt'=>3,'apr'=>4,'mei'=>5,'jun'=>6,'jul'=>7,'aug'=>8,'sep'=>9,'sept'=>9,'okt'=>10,'nov'=>11,'dec'=>12]; $arr = explode(' ',$dateval); $arr[1] = str_replace('.','',$arr[1]); $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; } case 'tr': $datearr = ['Oca'=>1,'Şub'=>2,'Mar'=>3,'Nis'=>4,'May'=>5,'Haz'=>6,'Tem'=>7,'Ağu'=>8,'Eyl'=>9,'Eki'=>10,'Kas'=>11,'Ara'=>12]; $arr = explode(' ',$dateval); $month = $datearr[$arr[1]]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; case 'jp': $arr = explode(' ',$dateval); $dataarr = explode('/',$arr[0]); $month = $dataarr[1]; $year = $dataarr[0]; $day = $dataarr[2]; $time = $arr[1]; return $year.'-'.$month.'-'.$day.' '.$time; case 'br': $datearr = ['jan'=>1,'fev'=>2,'mar'=>3,'abr'=>4,'mai'=>5,'jun'=>6,'jul'=>7,'ago'=>8,'set'=>9,'sept'=>9,'out'=>10,'nov'=>11,'dez'=>12]; $arr = explode(' ',$dateval); $arr[2] = str_replace('.','',$arr[2]); $month = $datearr[$arr[2]]; $year = $arr[4]; $day = $arr[0]; $time = $arr[5]; return $year.'-'.$month.'-'.$day.' '.$time; case 'be': $datearr = ['janv'=>1,'févr'=>2,'mars'=>3,'avr'=>4,'mai'=>5,'juin'=>6,'juil'=>7,'août'=>8,'sept'=>9,'sept'=>9,'oct'=>10,'nov'=>11,'déc'=>12]; $arr = explode(' ',$dateval); $arr[1] = str_replace('.','',$arr[1]); $month = $datearr[strtolower($arr[1])]; $year = $arr[2]; $day = $arr[0]; $time = $arr[3]; return $year.'-'.$month.'-'.$day.' '.$time; default: return '0000-00-00 00:00:00'; break; } }
对一些金额的转换
public function format_number_string1($text){ $text = trim($text); if ($text == '') { return (float)$text; } // 去掉空格 // 逗号统一转成小数点处理 $text = str_replace(chr(194) . chr(160),'',$text); $text = str_replace(' ', '', $text); $text = str_replace('?', '', $text); $result = strpos($text, '.');//点 $result1= strpos($text, ',');//豆 if($result !== false && $result1 !==false) {//存在两个字符 if($result1>$result){//前面是。后面是, $text = str_replace('.', '', $text); $text = str_replace(',', '.', $text); }else{//前面是,后面是. $text = str_replace(',', '', $text); } }else{ $text = str_replace(',', '.', $text); } $text = str_replace('−', '-', $text); $text = str_replace(' ', '', $text); // 只保留最后一个小数点 $count = substr_count($text, '.'); if ($count > 1) { $parts = explode('.', $text); $last = array_pop($parts); $text = implode('', $parts) . '.' . $last; } return (float)$text; }
对详情特色字符的转换
public function format_number_string($str){ $str = trim($str); $str = str_replace(',',' ',$str); $str = str_replace('"', ' ', $str); $str = str_replace("'", ' ', $str); $str = str_replace("【𝐏𝐫𝐨𝐦𝐨𝐭𝐢𝐨𝐧 𝐝𝐞 𝐏â𝐪𝐮𝐞𝐬】", '[promotion de paques]', $str); return $str; }
对日本编码的转换
mb_convert_encoding(trim($value[$sort]), 'utf-8', 'shift-jis');
解析数据函数
public function getreportlistingstatus($val,$type){ $requestReport = new AmazonAllListingNew(); $taskmodel = new AmazonReportZnDaterangeTask(); $rapmodel = new RpaRequestReportLog(); $detailmodel = new AmazonReportZnDetailNew(); $errmodel = new AmazonReportZnErr(); $requestlog = new AmazonReportZnRequestLog(); $datetime = date('Y-m-d 00:00:00', strtotime('-2 day')); $batchnumber = date('Ymd', strtotime($datetime)); $account_id = $val['account_id']; $accountname = YbModel::model('AmazonAccount')->queryPairs('id,account_name',"status=1");//查询; $account = YbModel::model('AmazonAccount')->findByPk($account_id); if($type==1){ //$result = $requestReport->applicationreport($account->merchant_id,strtolower($account->site),'/reports/2021-06-30/reports?reportTypes='.self::REPORT_TYPE.'&marketplaceIds='.$account->market_place_id,'','','GET');//拉取列表 $result = $requestReport->getreportstatus($account->merchant_id,strtolower($account->site),'/reports/2021-06-30/reports/'.$val['reportid'],"","","GET");//按reportid拉取 $data = $list = []; if(isset($result['processingStatus']) && is_array($result)){ $datatask = $taskmodel->queryPairs('account_id,id',"account_id={$account_id} and status=1 and reportid='{$val['reportid']}' and batchnumber='{$val['batchnumber']}'");//查询 $data['account_id'] = $account_id; $data['account_name'] = $accountname[$account_id]; $data['reporttype'] = self::REPORT_TYPE; $data['processingstatus'] = $result['processingStatus']; $data['processingendtime'] = date('Y-m-d H:i:s',strtotime($result['processingEndTime'])); $data['reportdocumentid'] = $result['reportDocumentId']; $data['status'] = $result['processingStatus']=='DONE'?2:1; $data['is_down'] = 0; if($datatask){ $data['update_date'] = date('Y-m-d H:i:s'); $taskmodel->updateAll($data,"id=".$datatask[$account_id]); }else{ $data['create_date'] = date('Y-m-d H:i:s'); $list[] = $data; $taskmodel->batchInsertAll($taskmodel->tableName(), array_keys($list[0]), $list, true); } echo 'Doll'; }else{ $taskmodel->updateAll(['status'=>3,'update_date'=>date('Y-m-d H:i:s')],"account_id={$account_id} and status=1 and reportid='{$val['reportid']}' and batchnumber='{$val['batchnumber']}'"); } }else if($type==2){ $result = $requestReport->getreportsurl($account->merchant_id,$account->site,'/reports/2021-06-30/documents/'.$val['reportdocumentid'],"","","GET");//获取报告下载链接 if(isset($result['url'])){ $url = Yii::getPathOfAlias('webroot') . '/upload/amazoncsv/'; $taskmodel->updateAll(['url'=>$result['url'],'update_date'=>date('Y-m-d H:i:s')],"id=".$val['id']); $tmp_name = $val['account_id'].'_'.$val['batchnumber'].'.csv'; if (file_exists($url . $tmp_name)) { @unlink($url . $tmp_name); } $detailmodel->deleteAll('account_id='.$account_id.' and batchnumber="'.$val['batchnumber'].'"'); $requestReport->getFile($result['url'],$url,$tmp_name); $csvlist = $taskmodel->readCSV($url . $tmp_name); $titlearr = []; $modeltitle = new AmazonReportZnTitle(); $listtitle = $modeltitle->getDbConnection()->createCommand() ->select('column,UK,DE,FR,ES,IT,NL,PL,SE,TR,US,CA,MX,BR,JP,BE') ->from($modeltitle->tableName()) ->queryAll(); $keylist = array_keys($listtitle[0]); foreach ($listtitle as $tkey=>$tval){ foreach ($keylist as $kval){ if($tval[$kval]){ $titlearr[strtolower($kval)][] = $tval['column']; } } } $titlearr['sp'] = $titlearr['es']; $users = self::getUserNameArray(); $accounts = self::getAccountNameArray(); $file = $data = $listdata = array(); $is_account_type = 1; //记录条数 $objMyExcel = new MyExcel(); $excel_data = $objMyExcel->get_excel_con($url . $tmp_name);//得到文件数据 $num = in_array($account->site,['tr'])?(count($excel_data) - 7) : (count($excel_data) - 8);//实际数据条数 $batchnumberlen = strlen($val['batchnumber']); if($batchnumberlen==6) {//按月 $msql = 'select count(*) as num from yibai_amazon_report_zn_detail_new where account_id='.$account_id.' and batchnumber like "'.$val['batchnumber'].'%" '; $mcount = $detailmodel->getDbConnection()->createCommand($msql)->queryScalar(); $logdata = $loglist = []; $logdata['planid'] = $val['batchnumber']; $logdata['request_body'] = $val['accountid']; $logdata['response_body'] = json_encode($val); $logdata['type'] = 1; $logdata['create_time'] = date('Y-m-d H:i:s'); $logdata['status'] = 3;//结果成功 if($num>$mcount){//覆盖 $logdata['remarks'] = '覆盖数据'; $logdata['request_body'] = $account_id; $logdata['response_body'] = '批次:'.$val['batchnumber'].',账户:'.$account_id.',重试的条数大于当前的,覆盖数据'.$num.'>'.$mcount; $detailmodel->deleteAll("batchnumber like '".$val['batchnumber']."%' and account_id=".$account_id);//删除所有的 $loglist[] = $logdata; $requestlog->batchReplaceAll("{{amazon_report_zn_request_log}}", array_keys($loglist[0]), $loglist); //$errmodel->updateAll(['errorMsg'=>'覆盖旧数据'.$num.'>'.$mcount,'remarks'=>'覆盖旧数据'.$num.'>'.$mcount],'planId='.$val['batchnumber'].' and account_id='.$account_id); }else{ $logdata['remarks'] = '不做处理'; $logdata['request_body'] = $account_id; $logdata['response_body'] = '批次:'.$val['batchnumber'].',账户:'.$account_id.',重试的条数小于等于当前的,不做处理'.$num.'<='.$mcount; $loglist[] = $logdata; $requestlog->batchReplaceAll("{{amazon_report_zn_request_log}}", array_keys($loglist[0]), $loglist); //$errmodel->updateAll(['errorMsg'=>'不做处理'.$num.'<='.$mcount,'remarks'=>'不做处理'.$num.'<='.$mcount],'planId='.$val['planid'].' and account_id='.$account_id); $taskmodel->updateAll(['is_down' => 1,'update_at' => date("Y-m-d H:i:s"), 'num' => $num, 'is_true' => $num == $mcount ? 0 : 1], "id='{$val['id']}'"); //记录日志了终止执行 $msg = $val['batchnumber'].'的账户'.$account_id.'比按天拉取的少'.$num.'<='.$mcount; echo $msg; return $msg; } } foreach ($csvlist as $key => $value) { if (!$value[0]) { continue; } $file['acc'] = $account->account_name; $file['bnum'] = $val['batchnumber']; $file['accid'] = $account->id; $file['groupid'] = $account->group_id; $site = $account->site; if (in_array($site, ['tr','br'])) { $flag = 0 <= $key && $key < 7; if($key==6){ if(count($value)<10){ $taskmodel->updateAll(['is_down' => 1,'update_date' => date("Y-m-d H:i:s"), 'num' => 0, 'is_true' => 0], "id='{$val['id']}'"); return '文件错误'; } } } else { $flag = 0 <= $key && $key < 8; if($key==7){ if(count($value)<10){ $taskmodel->updateAll(['is_down' => 1,'update_date' => date("Y-m-d H:i:s"), 'num' => 0, 'is_true' => 0], "id='{$val['id']}'"); return '文件错误'; } } } if($site == 'us' && $key==7){ if(!in_array('account type',$value)){ $is_account_type = 0;//代表表格里面的account type不存在 } } if ($flag) { continue; } if($site == 'us' && $is_account_type==0 && in_array('account_type',$titlearr[$site])){ array_splice($titlearr[$site],8,1); } $data['account_name'] = $file['acc']; $data['account_id'] = $file['accid']; $data['group_id'] = $file['groupid']; $data['batchnumber'] = $file['bnum']; $data['creator'] = 1; $data['create_time'] = date("Y-m-d H:i:s"); $number_field_list = [ "product_sales", "product_sales_tax", "shipping_credits", "shipping_credits_tax", "gift_wrap_credits", "gift_wrap_credits_tax", "regulatory_fee", "tax_on_regulatory_fee", "promotional_rebates", "promotional_rebates_tax", "sales_tax_collected", "marketplace_facilitator_tax", "marketplace_withheld_tax", "selling_fees", "fba_fees", "other_transaction_fees", "other", "total", "description", ]; $sort = 0;//字段顺序 foreach ($titlearr[$site] as $k => $v) { if ($v) { // 数字字段格式化 if (in_array($v, $number_field_list)) { if ($v == 'description') { $data[$v] = $this->format_number_string($value[$sort]); } else { $data[$v.'_txt'] = $value[$sort]; $data[$v] = $this->format_number_string1($value[$sort]); } if ($site == 'jp') { $data[$v] = mb_convert_encoding(trim($data[$v]), 'utf-8', 'shift-jis'); } } else { if ($v == 'quantity') { if (!trim($value[$sort])) { $data[$v] = 0; } else { $data[$v] = (int)str_replace(',', '', trim($value[$sort])); } }else if($v == 'order_state'){ if($site == 'jp'){ $data[$v] = mb_convert_encoding(trim($value[$sort]), 'utf-8', 'shift-jis'); }else{ $data[$v] = str_replace(',', '', trim($value[$sort])); $data[$v] = str_replace('𝔹𝕖𝕝𝕘𝕚𝕢𝕦𝕖', 'Belgique', trim($data[$v])); } } else { if ($site == 'jp') { $data[$v] = mb_convert_encoding(trim($value[$sort]), 'utf-8', 'shift-jis'); } else { $data[$v] = trim($value[$sort]); } if($v == 'date_time'){ $data[$v] = date('Y-m-d H:i:s',strtotime($detailmodel->datechange($site,$data[$v]))); } } } $sort++; } } if (!$data['date_time']) { continue; } $listdata[] = $data; if ($listdata && count($listdata) >= 2000) { $fart = $detailmodel->batchReplaceAll("{{amazon_report_zn_detail_new}}", array_keys($listdata[0]), $listdata); if ($fart) { $listdata = []; } } } if ($listdata && is_array($listdata)) { $fart = $detailmodel->batchReplaceAll("{{amazon_report_zn_detail_new}}", array_keys($listdata[0]), $listdata); if (!$fart) { return "批量添加数据错误"; } } $taskmodel->updateAll(['is_down' => 1,'processingstatus' => '_DONE_','update_date' => date("Y-m-d H:i:s"), 'num' => $num], "id='{$val['id']}'"); $rapmodel->updateAll(['get_report_result' => 1,'get_report_time' => date("Y-m-d H:i:s")], "id='{$val['request_report_id']}'"); if (file_exists($url . $tmp_name)) { @unlink($url . $tmp_name); } } } } public function getFile($url, $save_dir = '', $filename = '', $type = 0) { if (trim($url) == '') { return false; } if (trim($save_dir) == '') { $save_dir = './'; } if (0 !== strrpos($save_dir, '/')) { $save_dir .= '/'; } //创建保存目录 if (!file_exists($save_dir) && !mkdir($save_dir, 0777, true)) { return false; } //获取远程文件所采用的方法 if ($type) { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $content = curl_exec($ch); curl_close($ch); } else { ob_start(); readfile($url); $content = ob_get_contents(); ob_end_clean(); } //echo $content; $size = strlen($content); //文件大小 $fp2 = @fopen($save_dir . $filename, 'a'); @fwrite($fp2, $content); @fclose($fp2); unset($content, $url); return array( 'status' => 1, 'file_name' => $filename, 'save_path' => $save_dir . $filename, 'file_size' => $size ); } public function read_gz($gz_file){ $buffer_size = 4096; // read 4kb at a time $file = gzopen($gz_file, 'rb'); $str=''; while(!gzeof($file)) { $str.=gzread($file, $buffer_size); } gzclose($file); return $str; }
分类树:GET_XML_BROWSE_TREE_DATA
一样的请求报告
$result = $requestReport->applicationreport($account->merchant_id,strtolower($account->site),'/reports/2021-06-30/reports',"",["marketplaceIds"=>[$account->market_place_id],"reportType"=>self::REPORT_TYPE,"reportOptions"=>["MarketplaceId"=>$account->market_place_id,"RootNodesOnly"=>'false']]);
一样的获取 reportDocumentId
$result = $requestReport->getreportstatus($account->merchant_id,strtolower($account->site),'/reports/2021-06-30/reports/'.$val['report_id'],"","","GET");
一样的得到下载连接
$result = $requestReport->getreportsurl($account->merchant_id,$account->site,'/reports/2021-06-30/documents/'.$val['request_id'],"","","GET");//获取报告下载链接
得到的下载连接是不能直接打开的 内容是 gzip编码 获取也是乱码 要通过
$content = file_get_contents("compress.zlib://".$result['url']); $content =simplexml_load_string($content); //xml转object $content= json_encode($content); //objecct转json $content=json_decode($content,true); //json转array
或者存入到txt文件里面
$handle = fopen("compress.zlib://".$result['url'], "rb"); $fp = fopen('aa.txt', 'w');//打开一个文件, while (!feof($handle)) { //循环读取远程文件 $contents = ''; $contents = fread($handle, 1048576);//每次读取1M fwrite($fp, $contents);//将远程文件内容写入打开的vv.mp4文件 } fclose($handle); fclose($fp);