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

127 lines
3.9 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.
*/
/**
* 前端店铺商品处理Lib类
*
* @author wangbiao@shopex.cn
* @version 0.1
*/
class tbo2o_shop_items
{
function __construct(){
$this->_shopItemObj = app::get('tbo2o')->model('shop_items');
}
/**
* 批量插入
*
* @return void
* @author
**/
public function batchInsert($items, $shop)
{
if (empty($items)) return false;
$shopSkuLib = kernel::single('tbo2o_shop_skus');
$shop_bn_crc32 = $shopSkuLib->crc32($shop['shop_bn']);
$dateline = time();
$taog_id = array();
foreach ($items as $key=>$item)
{
$iid = $item['iid'] ? $item['iid'] : $item['num_iid'];
$id = md5($shop['shop_id'].$iid);
$items[$key]['taog_id'] = $id;
$taog_id[] = $id;
}
$frame_set = array();
$rows = $this->_shopItemObj->getList('id,frame_set', array('id'=>$taog_id));
foreach ($rows as $row) {
$frame_set[$row['id']] = $row['frame_set'];
}
unset($taog_id,$rows);
$data = array();
foreach ($items as $item)
{
$iid = $item['iid'] ? $item['iid'] : $item['num_iid'];
//iid已经存在则跳过
$item_row = $this->_shopItemObj->dump(array('iid'=>$iid), 'id');
if($item_row)
{
continue;
}
#在售库存
$taog_store = 0;
#店铺库存
$shop_store = $item['num'];
$data[] = array(
'id' => $item['taog_id'],
'shop_id' => $shop['shop_id'],
'shop_bn' => $shop['shop_bn'],
'shop_name' => $shop['name'],
'shop_type' => $shop['shop_type'],
'iid' => $iid,
'bn' => $item['outer_id'],
'title' => $item['title'],
'detail_url' => $item['detail_url'],
'approve_status' => $item['approve_status'] ? $item['approve_status'] : $item['status'],
'price' => $item['price'],
'shop_store' => $shop_store,
'taog_store' => $taog_store,
'frame_set' => $frame_set[$item['taog_id']] == 'false' ? 'false' : 'true',
'download_time' => $dateline,
'update_time' => $dateline,
);
}
//获取REPLACE sql语句(使用inventorydepth公共函数库)
$sql = inventorydepth_func::get_replace_sql($this->_shopItemObj, $data);
$this->_shopItemObj->db->exec($sql);
}
/**
* @description 删除过时数据
* @access public
* @param void
* @return void
*/
public function deletePassData($shop_id,$time)
{
$sql = 'DELETE FROM `tbo2o_shop_items` WHERE shop_id = "'.$shop_id.'" AND download_time < '.$time;
$this->_shopItemObj->db->exec($sql);
}
/**
* 清空表
*
* @return void
* @author
**/
public function truncate()
{
$sql = 'TRUNCATE TABLE `tbo2o_shop_items`';
$this->_shopItemObj->db->exec($sql);
}
}