TEMU
This commit is contained in:
@@ -40,13 +40,13 @@ if (isset($_REQUEST['record']) && $_REQUEST['isDuplicate'] == "false") {
|
||||
if (isset($focus->id) && $focus->id != '') {
|
||||
$focus->format_all_fields();
|
||||
}
|
||||
} else if (isset($_REQUEST['ecommerceZS'])) {
|
||||
} else if (isset($_REQUEST['ecommerceZSApilo'])) {
|
||||
$new_number = true;
|
||||
$focus->stock_id = 'cf16804e-f698-5e09-2da3-6553588446ae';
|
||||
$focus->register_date = date("d.m.Y");
|
||||
$focus->parent_id = 'b5612f7f-85e5-f930-293e-62cead14b424';
|
||||
$db = $GLOBALS['db'];
|
||||
$invoiceIds = $_SESSION[$_REQUEST['ecommerceZS']];
|
||||
$invoiceIds = $_SESSION[$_REQUEST['ecommerceZSApilo']];
|
||||
$i = $db->fetchByAssoc($db->query("SELECT register_date FROM ecommerce_invoices WHERE id = '$invoiceIds[0]'"));
|
||||
$focus->delivery_date = date("d.m.Y");
|
||||
$focus->payment_date = date("d.m.Y");
|
||||
@@ -92,6 +92,65 @@ GROUP BY ip.ecmproduct_id, ip.price_netto;
|
||||
$documentNos[] = $row['document_no'];
|
||||
}
|
||||
$focus->pdf_text = "Dotyczy faktur: " . implode(', ', $documentNos);
|
||||
} else if (isset($_REQUEST['ecommerceZSTemu'])) {
|
||||
$orders = json_decode($_SESSION[$_REQUEST['ecommerceZSTemu']]);
|
||||
$new_number = true;
|
||||
$focus->stock_id = 'cf16804e-f698-5e09-2da3-6553588446ae';
|
||||
$focus->register_date = date("d.m.Y");
|
||||
$focus->parent_id = '8b99791c-4e32-4443-fa57-69037059fe3f';
|
||||
$db = $GLOBALS['db'];
|
||||
$invoiceIds = $_SESSION[$_REQUEST['ecommerceZSApilo']];
|
||||
$focus->delivery_date = date("d.m.Y");
|
||||
$focus->payment_date = date("d.m.Y");
|
||||
$focus->send_date = date("d.m.Y");
|
||||
$focus->payment_date_days = 0;
|
||||
$focus->status = 's30';
|
||||
$focus->order_source = 'temu-'.$_REQUEST['temuCountry'];
|
||||
|
||||
$documentNos = array();
|
||||
$products = array();
|
||||
foreach ($orders as $order) {
|
||||
$documentNos[] = $order->orderNumber;
|
||||
foreach($order->products as $product) {
|
||||
$prod = $db->fetchByAssoc($db->query("SELECT id, name, code, unit_id FROM ecmproducts WHERE code = '".$product->extCode."' AND deleted = 0"));
|
||||
if (!isset($prod)) {
|
||||
echo 'Brak produktu, nie wystawiaj dokumentu! '.$product->extCode.'<br>';
|
||||
} else {
|
||||
$products[] = array(
|
||||
'product_id' => $prod['id'],
|
||||
'product_code' => $prod['code'],
|
||||
'name' => $prod['name'],
|
||||
'quantity' => $product->soldFactor,
|
||||
'price_start' => 0.01,
|
||||
'price_netto' => 0.01,
|
||||
'unit_id' => $prod['unit_id'],
|
||||
'unit_name' => $app_list_strings['ecmproducts_unit_dom'][$prod['unit_id']],
|
||||
'ecmvat_name' => '0%',
|
||||
'ecmvat_value' => 0,
|
||||
'ecmvat_id' => '9b783d21-5548-6653-e1d6-49610eb3f9dd',
|
||||
);
|
||||
}
|
||||
}
|
||||
$prod = $db->fetchByAssoc($db->query("SELECT id FROM ecmproducts WHERE code = '".$order->productCode."'"));
|
||||
}
|
||||
|
||||
$groupedProducts = array();
|
||||
|
||||
foreach ($products as $p) {
|
||||
$pid = $p['product_id'];
|
||||
if (!isset($groupedProducts[$pid])) {
|
||||
$groupedProducts[$pid] = $p;
|
||||
} else {
|
||||
$groupedProducts[$pid]['quantity'] += $p['quantity'];
|
||||
}
|
||||
}
|
||||
$groupedProducts = array_values($groupedProducts);
|
||||
|
||||
$edit->ss->assign('ECOMMERCE_PRODUCTS', json_encode($groupedProducts));
|
||||
|
||||
$query = "SELECT document_no FROM ecommerce_invoices WHERE id IN ('" . implode('\',\'', $invoiceIds) . "')";
|
||||
$res = $db->query($query);
|
||||
$focus->pdf_text = "Dotyczy zamówień: " . implode(', ', $documentNos);
|
||||
} else if ($_REQUEST['isDuplicate'] == "true") {
|
||||
$new_number = true;
|
||||
$duplicate = true;
|
||||
|
||||
166
modules/EcmSales/bimit_importTemuOrders.php
Normal file
166
modules/EcmSales/bimit_importTemuOrders.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
function noquote($v){
|
||||
$j = json_encode($v, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
|
||||
return (is_string($v) && $j[0]==='"' && substr($j,-1)==='"') ? substr($j,1,-1) : $j;
|
||||
}
|
||||
function sign_md5($p, $secret){
|
||||
ksort($p, SORT_STRING);
|
||||
$s = $secret;
|
||||
foreach($p as $k=>$v){ if($v!=='' && $v!==null) $s .= $k . noquote($v); }
|
||||
$s .= $secret;
|
||||
return strtoupper(md5($s));
|
||||
}
|
||||
|
||||
function getTemuOrders($from, $to, $country, $pageSize = 50){
|
||||
$APP_KEY = '02cbeff8afd35247294810033b036cfe';
|
||||
$APP_SECRET = '8ecfa21b55cddf66c66043cbb80756efc4ba6596';
|
||||
$ACCESS_TOKEN_DE = 'eploouslfhwjwwzvz5okvmu29stwwdw9l3ullz8pv6y4raips8gouzwcqmv';
|
||||
$ACCESS_TOKEN_PL = 'eplyaf6ogcpewjtzytw8q9ahvx7haqntzk8wsz7vokjusvpry93gy9cvn2c';
|
||||
$ACCESS_TOKEN_FR = 'eplhrdwtdgjpfelzmyelnsifakqjzfza6rpa8neb7nqc8djxj11hlenl3u2';
|
||||
$BASE_URL = 'https://openapi-b-eu.temu.com/openapi/router';
|
||||
$REGION_ID = 162;
|
||||
// --- parse daty ---
|
||||
if (!is_int($from)) $from = strtotime($from);
|
||||
if (!is_int($to)) $to = strtotime($to);
|
||||
|
||||
if (!$from || !$to) return [];
|
||||
if ($from > $to) { $tmp = $from; $from = $to; $to = $tmp; }
|
||||
|
||||
|
||||
$page = 1;
|
||||
$out = [];
|
||||
$seenAnyInRange = false;
|
||||
$guardPages = 500;
|
||||
|
||||
while ($guardPages-- > 0) {
|
||||
$biz = array(
|
||||
"type" => "bg.order.list.v2.get",
|
||||
//"regionId" => $REGION_ID,
|
||||
"pageNumber" => $page,
|
||||
"pageSize" => $pageSize
|
||||
);
|
||||
switch ($country) {
|
||||
case 'pl': $ACCESS_TOKEN = $ACCESS_TOKEN_PL; break;
|
||||
case 'fr': $ACCESS_TOKEN = $ACCESS_TOKEN_FR; break;
|
||||
default: $ACCESS_TOKEN = $ACCESS_TOKEN_DE; break;
|
||||
}
|
||||
$common = array(
|
||||
'app_key' => $APP_KEY,
|
||||
'access_token' => $ACCESS_TOKEN,
|
||||
'data_type' => 'JSON',
|
||||
'timestamp' => (int)floor(microtime(true)),
|
||||
);
|
||||
$req = $biz + $common;
|
||||
$req['sign'] = sign_md5($req, $APP_SECRET);
|
||||
|
||||
$payload = json_encode($req, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, array(
|
||||
CURLOPT_URL => $BASE_URL,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
|
||||
CURLOPT_POSTFIELDS => $payload,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
));
|
||||
$resp = curl_exec($ch);
|
||||
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$cerr = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($resp === false || $http !== 200) {
|
||||
break;
|
||||
}
|
||||
|
||||
$data = json_decode($resp, true);
|
||||
if ($data['success'] == false) {
|
||||
var_dump('Błąd ładowania zamówień TEMU '.$country.': '.$data['errorMsg']);
|
||||
break;
|
||||
}
|
||||
if (!is_array($data)
|
||||
|| !isset($data['result']['pageItems'])
|
||||
|| !is_array($data['result']['pageItems'])
|
||||
|| count($data['result']['pageItems']) === 0) {
|
||||
break;
|
||||
}
|
||||
$items = $data['result']['pageItems'];
|
||||
|
||||
usort($items, function($a, $b){
|
||||
$ta = isset($a['parentOrderMap']['parentOrderTime']) ? (int)$a['parentOrderMap']['parentOrderTime'] : 0;
|
||||
$tb = isset($b['parentOrderMap']['parentOrderTime']) ? (int)$b['parentOrderMap']['parentOrderTime'] : 0;
|
||||
if ($ta == $tb) return 0;
|
||||
return ($ta > $tb) ? -1 : 1;
|
||||
});
|
||||
|
||||
$maxTs = isset($items[0]['parentOrderMap']['parentOrderTime']) ? (int)$items[0]['parentOrderMap']['parentOrderTime'] : 0;
|
||||
$last = $items[count($items)-1];
|
||||
$minTs = isset($last['parentOrderMap']['parentOrderTime']) ? (int)$last['parentOrderMap']['parentOrderTime'] : 0;
|
||||
|
||||
foreach ($items as $row) {
|
||||
if (!isset($row['parentOrderMap']['parentOrderSn'])) continue;
|
||||
|
||||
$ts = isset($row['parentOrderMap']['parentOrderTime']) ? (int)$row['parentOrderMap']['parentOrderTime'] : 0;
|
||||
if ($ts < $from || $ts > $to) continue;
|
||||
|
||||
$pst = isset($row['parentOrderMap']['parentOrderStatus']) ? (int)$row['parentOrderMap']['parentOrderStatus'] : -1;
|
||||
if (!($pst === 4 || $pst === 5)) continue;
|
||||
|
||||
$seenAnyInRange = true;
|
||||
|
||||
$orderSn = $row['parentOrderMap']['parentOrderSn'];
|
||||
|
||||
// check if order exitst
|
||||
$db = $GLOBALS['db'];
|
||||
$exists = $db->fetchByAssoc($db->query("SELECT id FROM ecmsales WHERE pdf_text LIKE '%$orderSn%'"));
|
||||
if (isset($exists['id'])) continue;
|
||||
|
||||
$products = array();
|
||||
|
||||
if (isset($row['orderList']) && is_array($row['orderList'])) {
|
||||
foreach ($row['orderList'] as $ol) {
|
||||
if (!isset($ol['productList']) || !is_array($ol['productList'])) continue;
|
||||
foreach ($ol['productList'] as $p) {
|
||||
// hacks :)
|
||||
if ($p['extCode'] == 'FR00259_52_15g_amz_de-1') {
|
||||
$p['extCode'] = 'FR00259_52_15g_amz_de';
|
||||
}
|
||||
if ($p['extCode'] == 'FR00138_1000_amz_de-1') {
|
||||
$p['extCode'] = 'FR00138_1000_amz_de';
|
||||
}
|
||||
$products[] = array(
|
||||
'extCode' => isset($p['extCode']) ? $p['extCode'] : null,
|
||||
'soldFactor' => isset($p['soldFactor']) ? $p['soldFactor'] : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$out[] = array(
|
||||
'orderNumber' => $orderSn,
|
||||
'issueTime' => $ts,
|
||||
'issueDate' => $ts ? date('Y-m-d H:i:s', $ts) : null,
|
||||
'products' => $products,
|
||||
'raw' => $row,
|
||||
);
|
||||
}
|
||||
|
||||
if ($minTs >= $from) {
|
||||
$page++;
|
||||
continue;
|
||||
}
|
||||
if ($maxTs < $from) {
|
||||
break;
|
||||
}
|
||||
if (!$seenAnyInRange) {
|
||||
$page++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
usort($out, function($a, $b){
|
||||
if ($a['issueTime'] == $b['issueTime']) return 0;
|
||||
return ($a['issueTime'] > $b['issueTime']) ? -1 : 1;
|
||||
});
|
||||
return $out;
|
||||
}
|
||||
@@ -3,6 +3,8 @@ ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
|
||||
|
||||
require_once ('modules/EcmSales/bimit_importTemuOrders.php');
|
||||
|
||||
$db = $GLOBALS['db'];
|
||||
global $app_list_strings;
|
||||
|
||||
@@ -18,9 +20,9 @@ if (isset($_REQUEST['date_from'])) {
|
||||
foreach ($invoices as $invoice) {
|
||||
$invoiceIds[] = $invoice['id'];
|
||||
}
|
||||
$sessionId = create_guid();
|
||||
$_SESSION[$sessionId] = $invoiceIds;
|
||||
$smarty->assign('sessionId', $sessionId);
|
||||
$sessionIdApilo = create_guid();
|
||||
$_SESSION[$sessionIdApilo] = $invoiceIds;
|
||||
$smarty->assign('sessionIdApilo', $sessionIdApilo);
|
||||
|
||||
$invoiceNo = array();
|
||||
foreach ($invoices as $invoice) {
|
||||
@@ -28,6 +30,39 @@ if (isset($_REQUEST['date_from'])) {
|
||||
}
|
||||
$smarty->assign('invoicesNo', join(", ", $invoiceNo));
|
||||
|
||||
$dateFrom = date('Y-m-d', strtotime($_REQUEST['date_from']));
|
||||
$dateTo = date('Y-m-d', strtotime($_REQUEST['date_to']));
|
||||
|
||||
$ordersPl = getTemuOrders($dateFrom.' 00:00:00', $dateTo.' 23:59:59', 'pl', 50);
|
||||
$orderNoPl = array();
|
||||
foreach ($ordersPl as $order) {
|
||||
$orderNoPl[] = $order['orderNumber'];
|
||||
}
|
||||
$smarty->assign('ordersNoPl', join(", ", $orderNoPl));
|
||||
$sessionIdTemuPl = create_guid();
|
||||
$_SESSION[$sessionIdTemuPl] = json_encode($ordersPl);
|
||||
$smarty->assign('sessionIdTemuPl', $sessionIdTemuPl);
|
||||
|
||||
$ordersDe = getTemuOrders($dateFrom.' 00:00:00', $dateTo.' 23:59:59', 'de', 50);
|
||||
$orderNoDe = array();
|
||||
foreach ($ordersDe as $order) {
|
||||
$orderNoDe[] = $order['orderNumber'];
|
||||
}
|
||||
$smarty->assign('ordersNoDe', join(", ", $orderNoDe));
|
||||
$sessionIdTemuDe = create_guid();
|
||||
$_SESSION[$sessionIdTemuDe] = json_encode($ordersDe);
|
||||
$smarty->assign('sessionIdTemuDe', $sessionIdTemuDe);
|
||||
|
||||
$ordersFr = getTemuOrders($dateFrom.' 00:00:00', $dateTo.' 23:59:59', 'fr', 50);
|
||||
$orderNoFr = array();
|
||||
foreach ($ordersFr as $order) {
|
||||
$orderNoFr[] = $order['orderNumber'];
|
||||
}
|
||||
$smarty->assign('ordersNoFr', join(", ", $orderNoFr));
|
||||
$sessionIdTemuFr = create_guid();
|
||||
$_SESSION[$sessionIdTemuFr] = json_encode($ordersFr);
|
||||
$smarty->assign('sessionIdTemuFr', $sessionIdTemuFr);
|
||||
|
||||
$smarty->assign('date_from', $_REQUEST['date_from']);
|
||||
$smarty->assign('date_to', $_REQUEST['date_to']);
|
||||
echo $smarty->display(getcwd() . '/modules/EcmSales/eCommerceZS/eCommerceZS.tpl');
|
||||
|
||||
@@ -63,7 +63,22 @@
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
ZS zbiorcza dla FV:<br> {$invoicesNo}
|
||||
<b>ZS zbiorcza dla FV (Apilo):</b><br> {$invoicesNo}
|
||||
<br><br>
|
||||
<input title="Wystaw ZS" class="button primary" type="button" name="Edit" id="edit_button" value="Wystaw ZS"
|
||||
onclick="window.open('index.php?module=EcmSales&action=EditView&ecommerceZS={$sessionId}')">
|
||||
<input title="Wystaw ZS" class="button primary" type="button" name="Edit" id="edit_button" value="Wystaw ZS Apilo"
|
||||
onclick="window.open('index.php?module=EcmSales&action=EditView&ecommerceZSApilo={$sessionIdApilo}')">
|
||||
<br><br>
|
||||
<b>ZS zbiorcza dla zamówień TEMU PL:</b><br> {$ordersNoPl}
|
||||
<br><br>
|
||||
<input title="Wystaw ZS" class="button primary" type="button" name="Edit" id="edit_button" value="Wystaw ZS Temu PL"
|
||||
onclick="window.open('index.php?module=EcmSales&action=EditView&temuCountry=PL&ecommerceZSTemu={$sessionIdTemuPl}')">
|
||||
<br><br>
|
||||
<b>ZS zbiorcza dla zamówień TEMU DE:</b><br> {$ordersNoDe}
|
||||
<br><br>
|
||||
<input title="Wystaw ZS" class="button primary" type="button" name="Edit" id="edit_button" value="Wystaw ZS Temu DE"
|
||||
onclick="window.open('index.php?module=EcmSales&action=EditView&temuCountry=DE&ecommerceZSTemu={$sessionIdTemuDe}')">
|
||||
<br><br>
|
||||
<b>ZS zbiorcza dla zamówień TEMU FR:</b><br> {$ordersNoFr}
|
||||
<br><br>
|
||||
<input title="Wystaw ZS" class="button primary" type="button" name="Edit" id="edit_button" value="Wystaw ZS Temu FR"
|
||||
onclick="window.open('index.php?module=EcmSales&action=EditView&temuCountry=FR&ecommerceZSTemu={$sessionIdTemuFr}')">
|
||||
Reference in New Issue
Block a user