mirror of
https://gitee.com/ShopeX/OMS
synced 2026-04-06 06:55:36 +08:00
108 lines
3.4 KiB
PHP
108 lines
3.4 KiB
PHP
<?php
|
||
/**
|
||
* Copyright © ShopeX (http://www.shopex.cn). All rights reserved.
|
||
* See LICENSE file for license details.
|
||
*/
|
||
|
||
/**
|
||
* 淘宝商品处理
|
||
*
|
||
* @author wangbiao@shopex.cn
|
||
* @version 0.1
|
||
*/
|
||
class tbo2o_shop_service_tbfx extends tbo2o_shop_service_common
|
||
{
|
||
public $approve_status = array(
|
||
array('filter'=>array(),'name'=>'全部','flag'=>'all','alias'=>'全部'),
|
||
);
|
||
|
||
function __construct(&$app)
|
||
{
|
||
$this->app = $app;
|
||
}
|
||
|
||
/**
|
||
* 下载全部
|
||
*
|
||
* @return void
|
||
* @author
|
||
**/
|
||
public function downloadList($filter,$shop_id,$offset=0,$limit=200,&$errormsg)
|
||
{
|
||
$shopService = kernel::single('tbo2o_shop_request_items');
|
||
$count = 0;
|
||
|
||
do
|
||
{
|
||
if ($count>60) {
|
||
$errormsg = '超出最大循环次数';
|
||
return false;
|
||
}
|
||
usleep(1000000);
|
||
$result = $shopService->fenxiao_products_get($filter,$shop_id,$offset,$limit);
|
||
|
||
if ($result === false) {
|
||
$errormsg = $shopService->get_err_msg();
|
||
# 临时做一下兼容,待明天矩阵更新后还原
|
||
if (false !== strpos($errormsg,'请求失败:') && strtotime('2013-3-21')>=time()) {
|
||
$errormsg = '';
|
||
} elseif (false !== strpos($errormsg,'This ban will last for 1 more seconds') ) {
|
||
$errormsg = '';
|
||
} else {
|
||
return false;
|
||
}
|
||
} else {
|
||
break;
|
||
}
|
||
|
||
$count++;
|
||
}while(true);
|
||
# 请求商品
|
||
|
||
# 数据为空
|
||
if(empty($result['products']['fenxiao_product'])){
|
||
$this->totalResults = 0;
|
||
return array();
|
||
}
|
||
|
||
$this->totalResults = $result['total_results'];
|
||
|
||
$data = array();
|
||
foreach ($result['products']['fenxiao_product'] as $value) {
|
||
$product = array(
|
||
'outer_id' => $value['outer_id'] ? $value['outer_id'] : '',
|
||
'iid' => $value['pid'] ? $value['pid'] : '',
|
||
'title' => $value['name'] ? $value['name'] : '',
|
||
'approve_status' => $value['status']=='up' ? 'onsale' : 'instock',
|
||
'price' => $value['standard_price'],
|
||
'num' => $value['quantity'] > 0 ? $value['quantity'] : 0,
|
||
|
||
'default_img_url' => $value['pictures'],
|
||
'props' => $value['properties'],
|
||
'simple' => 'true',
|
||
'skus' => '',
|
||
);
|
||
|
||
if ($value['skus']['fenxiao_sku']) {
|
||
$skus = array();
|
||
foreach ((array) $value['skus']['fenxiao_sku'] as $v) {
|
||
$skus[] = array(
|
||
'sku_id' => $v['id'],
|
||
'properties' => $v['properties'],
|
||
'price' => $v['standard_price'],
|
||
'quantity' => $v['quantity'] > 0 ? $v['quantity'] : 0,
|
||
'properties_name' => $v['name'],
|
||
'outer_id' => $v['outer_id'],
|
||
);
|
||
}
|
||
|
||
$product['simple'] = 'false';
|
||
$product['skus']['sku'] = $skus;
|
||
}
|
||
|
||
$data[] = $product;
|
||
}
|
||
|
||
return $data;
|
||
}
|
||
} |