コード例 #1
0
<?php

include __DIR__ . '/common.php';
$account = $argv[1];
if (empty($account)) {
    exit('请输入账号!');
}
$expression = date('z', time()) % 2;
$sql = 'select count(*) as counts from ws_product where account="' . $account . '" and isPromoted = "false"';
$ret = sqlQuery($sql);
$pages = ceil($ret[0]['counts'] / 100);
$wishProductApi = new WishProductApi($account, 1);
for ($i = 0; $i < $pages; $i++) {
    $sql = 'select * from ws_product where account="' . $account . '" and isPromoted = "false" limit ' . $i * 100 . ',100';
    $ret = sqlQuery($sql);
    foreach ($ret as $itemKey => $itemVal) {
        $num = substr(md5($itemVal['spu']), 0, 1);
        $sql = 'select * from ws_product_' . $num . ' where productId="' . $itemVal['productId'] . '"';
        $itemRet = sqlQuery($sql);
        foreach ($itemRet as $detailKey => $detailVal) {
            if ($expression === 1) {
                $price = $detailVal['variantsPrice'] - 0.01;
            } else {
                $price = $detailVal['variantsPrice'] + 0.01;
            }
            $data = array('sku' => $detailVal['variantsSku'], 'price' => $price);
            $wishRet = $wishProductApi->variantUpdate($data);
            $wishRet = json_decode($wishRet, true);
            if ($wishRet['code'] === 0) {
                $sql = 'update ws_product_' . $num . ' set variantsPrice=' . $price . ' where productId="' . $itemVal['productId'] . '" and variantsSku="' . $detailVal['variantsSku'] . '"';
                echo $sql, PHP_EOL;
コード例 #2
0
 /**
  * 功能:上传并保存待刊登的料号
  */
 public function saveWaitProduct()
 {
     set_time_limit(0);
     //print_r($_REQUEST);
     if (empty($_REQUEST['account'])) {
         self::$errCode = '1507';
         self::$errMsg = '请填写需要刊登的账号...';
         return false;
     }
     $tags = explode(',', $_REQUEST['tags']);
     if (count($tags) < 10) {
         self::$errCode = '1508';
         self::$errMsg = '商品关键字的数据少于10个, 请重新输入!!!';
         return false;
     }
     $accountAbbr = C('ACCOUNTABBR')[$_REQUEST['account']];
     $spu = str_ireplace($accountAbbr, '', $_REQUEST['spu']);
     $spu = str_ireplace('#', '', $spu);
     $productInfo = self::getProductBySpu($spu, $_REQUEST['account']);
     if (!empty($productInfo)) {
         self::updateWaitData($spu, $_REQUEST['account']);
         //将上传状态更改已上传
         self::$errCode = '1509';
         self::$errMsg = '此料号已经刊登,请不要重复刊登!';
         return false;
     }
     $wishProductApi = new WishProductApi($_REQUEST['account'], 1);
     //$wishProductApi->setSandbox();		//设置从沙盒刊登
     $productAct = new WishProductAct();
     $extraImage = $productAct->imageReplace($_REQUEST['extra_images']);
     $spuImage = isset($_REQUEST['skuImg']) ? current($_REQUEST['skuImg']) : $_REQUEST['main_image'];
     $mainImage = $productAct->imageReplace($spuImage);
     $spuData = array('name' => $_REQUEST['title'], 'description' => $_REQUEST['description'], 'tags' => $_REQUEST['tags'], 'sku' => $_REQUEST['sku'][0], 'color' => $_REQUEST['color'][0], 'size' => $_REQUEST['size'][0], 'inventory' => $_REQUEST['inventory'][0], 'price' => $_REQUEST['price'][0], 'shipping' => $_REQUEST['shipping'][0], 'msrp' => $_REQUEST['msrp'][0], 'shipping_time' => $_REQUEST['shipping_time'][0], 'main_image' => end($mainImage), 'parent_sku' => count($_REQUEST['sku']) > 1 ? $_REQUEST['spu'] : $_REQUEST['sku'][0], 'extra_images' => implode('|', $extraImage));
     $skuData = array();
     if (count($_REQUEST['sku']) > 1) {
         foreach ($_REQUEST['sku'] as $skuKey => $skuVal) {
             if ($skuKey === 0) {
                 continue;
             }
             $mainImage = $productAct->imageReplace($_REQUEST['skuImg'][$skuKey]);
             $skuData[] = array('parent_sku' => $_REQUEST['spu'], 'sku' => $_REQUEST['sku'][$skuKey], 'color' => $_REQUEST['color'][$skuKey], 'size' => $_REQUEST['size'][$skuKey], 'inventory' => $_REQUEST['inventory'][$skuKey], 'price' => $_REQUEST['price'][$skuKey], 'shipping' => $_REQUEST['shipping'][$skuKey], 'msrp' => $_REQUEST['msrp'][$skuKey], 'shipping_time' => $_REQUEST['shipping_time'][$skuKey], 'main_image' => end($mainImage));
         }
     }
     //		print_r($spuData);
     //		print_r($skuData);exit;
     $spuStatus = $wishProductApi->createProductSpu($spuData);
     errorLog($_REQUEST['spu'] . ':' . json_encode($spuStatus), 'uploadStatus', 'uploadProduct');
     if (!empty($spuStatus)) {
         //上传成功,已经返回了数据
         self::updateWaitData($_REQUEST['spu'], $_REQUEST['account']);
     }
     if (!empty($skuData)) {
         foreach ($skuData as $skuKey => $skuVal) {
             $skuStatus = $wishProductApi->createProductSku($skuVal);
             errorLog($_REQUEST['spu'] . ':' . json_encode($skuStatus), 'uploadStatus', 'uploadProduct');
         }
     }
     return $spuStatus;
 }
コード例 #3
0
$d->close();
$newDir = WEB_PATH . 'log/productInfo/' . date('Y/m-d') . '/';
if (!is_dir($newDir)) {
    mkdir($newDir, 0777, true);
    if (!is_dir($newDir)) {
        exit('不能建立目录!');
    }
}
$errorDir = WEB_PATH . 'log/productInfo/' . date('Y/m-d') . '/errorProduct/';
if (!is_dir($errorDir)) {
    mkdir($errorDir, 0777, true);
    if (!is_dir($errorDir)) {
        exit('不能建立目录!');
    }
}
$wishProductApi = new WishProductApi('geshan0728', 1);
$num = 0;
$uploadNum = rand(10, 20);
foreach ($files as $fileKey => $fileVal) {
    $spuInfo = explode('.', $fileVal);
    $spuSn = $spuInfo[0];
    if (!empty($spuArr)) {
        if (!in_array($spuSn, $spuArr)) {
            continue;
        }
    }
    errorLog('开始上传,' . $spuSn, 'tip');
    $sql = 'select spu from `ws_product` where spu = "' . $spuSn . '"';
    $query = $dbConn->query($sql);
    $ret = $dbConn->fetch_array_all($query);
    if (!empty($ret)) {