Files
OMS/app/tbo2o/lib/shop/service/tbfx.php
2026-01-04 19:08:31 +08:00

119 lines
3.8 KiB
PHP

<?php
/**
* Copyright 2012-2026 ShopeX (https://www.shopex.cn)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* 淘宝商品处理
*
* @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;
}
}