ecshop采集当当产品入库
2009-09-22 11:56 来源:www.chinab4c.com 作者:ecshop专家
<!-- $Id: picture_batch.htm 15409 2008-12-09 02:36:22Z sunxiaodong $ -->
{insert_scripts files="../js/utils.js"}
{include file="pageheader.htm"}
<script>
function check(){
var obj = document.getElementById("cat_id");
var cat_id = obj.options[obj.selectedIndex].value;
if(cat_id == 0){
alert("请选择分类");
return false;
}
var frm = document.forms['theForm'];
var bookid = frm.elements['bookid'].value;
if(bookid == ''){
alert("输入要采集的书本ID");
return false;
}
}
</script>
<div class="main-div">
<form action="?act=start" method="post" name="theForm" onsubmit="return check();">
<table cellspacing="1" cellpadding="3" width="100%">
<tr>
<td>分类</td>
<td ><select name="cat_id" id="cat_id"><option value="0">{$lang.all_category}</caption>{$cat_list}</select> </td>
</tr>
<tr>
<td>产品ID</td>
<td ><input type="text" name="bookid" size="100">用逗号隔开</td>
</tr>
<tr>
<td>相关设置</td>
<td><input type="checkbox" name="best" value="1">是否精华<input type="checkbox" name="host" value="1">是否热买<input type="checkbox" name="new" value="1">是否新品</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" class="button" value="采集" />
</td>
</tr>
</table>
</form>
</div>
{include file="pagefooter.htm"}
<?php
/**
* ECSHOP 图片批量处理程序
* ============================================================================
* 版权所有 2005-2008 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: sunxiaodong $
* $Id: picture_batch.php 15532 2009-01-07 10:48:14Z sunxiaodong $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
include_once(ROOT_PATH . 'includes/cls_image.php');
include_once(ROOT_PATH . '/admin/includes/lib_goods.php');
$image = new cls_image($_CFG['bgcolor']);
$act = $_REQUEST['act'];
if($act == 'collect'){
$smarty->assign('cat_list', cat_list(0, 0));
$smarty -> display('collect.htm');
}elseif($act == 'start'){
$bid = explode(",",$_REQUEST['bookid']);
if($bid){
$bid = array_unique($bid);
foreach($bid as $k){
/***********************************/
$url = "http://product.dangdang.com/product.aspx?product_id=".$k;
$thumb = '';
$thumb1 = '';
$thumb2 = '';
$str = file($url);
if($str){
$string = join('',$str);
preg_match("/<span\s*class=\"black000\">(.*?)<\/span>/is",$string,$title);
preg_match("/<span\s*class=\"redc30\">(.*?)<b>([\d\.]*)(.*?)<\/b><\/span>/i",$string,$price);
preg_match("/<img\s*src=\"(.*?)\"\s*id=\"img_show_prd\"/",$string,$img);
preg_match("/<div\sid='author_'\s*>(.*?)<\/div>/is",$string,$auth);
preg_match("/<div\sid='publisher_'>(.*?)<\/div>/is", iconv("gbk","utf-8",$string), $pub);
preg_match("/<span\s*class=\"del\"\s*id=\"originalPriceTag\">(.*?)<\/span>/i",iconv("gbk","utf-8",$string),$market_price);
preg_match_all("/<div\s*class=\"zhengwen\">(.*?)<\/div>/is",$string,$desc);
$array['goods_desc'] = $desc[1][1];
if($market_price[1]){
$array['market_price'] = str_replace("¥","",$market_price[1]);
}
if($pub[1]){
$s = trim(strip_tags($pub[1]));
$a = explode(":",$s);
$array['pub'] = addslashes($a[1]);
}
if($auth[1]){
$s = iconv("gbk","utf-8",trim(strip_tags($auth[1])));
$a = explode(":",$s);
$array['auth'] = addslashes($a[1]);
}
$array['title'] = iconv("gbk","utf-8",strip_tags($title[1]));
$array['price'] = $price[2];
$array['img'] = $img[1];
if($img[1]){
$dn = "images/".date("Ym")."/thumb_img/";
$dn1 = "images/".date("Ym")."/source_img/";
$dn2 = "images/".date("Ym")."/goods_img/";
if(!file_exists('../'.$dn)){
mkdir($dn,"7777");
}
if(!file_exists('../'.$dn1)){
mkdir($dn1,"7777");
}
if(!file_exists('../'.$dn2)){
mkdir($dn2,"7777");
}
$thumb = $dn.date("YmhHis").strrchr($img[1],".");
$thumb1 = $dn1.date("YmhHis").strrchr($img[1],".");
$thumb2 = $dn2.date("YmhHis").strrchr($img[1],".");
$file = fopen("../".$thumb,"w");
fwrite($file,file_get_contents($img[1]));
fclose($file);
$file1 = fopen("../".$thumb1,"w");
fwrite($file1,file_get_contents($img[1]));
fclose($file1);
$file2 = fopen("../".$thumb2,"w");
fwrite($file2,file_get_contents($img[1]));
fclose($file2);
}
if(!$array['title']){
preg_match("/<div\s*class=\"mall_goods_title_text\">(.*?)<\/div>/i",$string,$title1);
$array['title'] = strip_tags($title1[1]);
preg_match("/<b\s*id=\"salePriceTag\">(.*?)<\/b>/i",$string,$price);
if($price[1]){
$array['price'] = str_replace("¥","",$price[1]);
}
preg_match("/<img\s*id='largePic'\s*src=\"(.*?)\"[^>]*\/>/i",$string,$img);
if($img){
$array['img'] = $img[1];
if($img[1]){
$fn = date("YmhHis").strrchr($img[1],".");
$file = fopen($fn,"w");
fwrite($file,file_get_contents($img[1]));
fclose($file);
}
}
}
$info = array(
'cat_id' => $_REQUEST['cat_id'],
'goods_name' => $array['title'],
'market_price' => $array['market_price'],
'shop_price' => $array['price'],
'goods_thumb' => $thumb,
'goods_img' => $thumb1,
'original_img' => $thumb2,
'goods_number' => 100,
'goods_desc' => iconv("gbk","utf-8",$array['goods_desc']),
'add_time' => time(),
'is_new' => intval($_REQUEST['new']),
'is_best' => intval($_REQUEST['best']),
'is_hot' => intval($_REQUEST['host']),
'goods_sn' => 'ECS'.date("YmdHs"),
);
if($info['goods_name']){
if($array[pub]){
$bid = $db -> getOne("select brand_id from ".$ecs->table('brand')." where brand_name = '$array[pub]'");
if($bid){
$info['brand_id'] = $bid;
}else{
$sql = "insert into ".$ecs->table('brand')."(brand_name) values('$array[pub]')";
$db -> query($sql);
$info['brand_id'] = $db -> insert_id();
}
}
$db -> autoExecute($GLOBALS['ecs']->table('goods'), $info, 'INSERT');
$id = $db -> insert_id();
if($id){
$sql1 = "insert into ".$GLOBALS['ecs']->table('goods_attr'). " values('','$id','1','$array[auth]','')";
$sql2 = "insert into ".$GLOBALS['ecs']->table('goods_attr'). " values('','$id','2','$array[pub]','')";
$GLOBALS['db'] -> query($sql1);
$GLOBALS['db'] -> query($sql2);
}
}
}else{
$array['msg'] = 'false';
}
/***********************************/
}
}
$link[0]['text'] = "返回商品列表";
$link[0]['href'] = 'goods.php?act=list';
$link[1]['text'] = '返回继续采集';
$link[1]['href'] = 'collect.php?act=collect';
sys_msg('采集完毕', 0, $link);
}
?>
最近更新
常用插件
- ecshop红包修改成满多少减
我们在长期使用ecshop的时候,我们可以发现。ecshop的红包是一个非常强...
- ecshop分类树中统计商品数
最近忙于开发其他项目,在不少朋友不断要求和催促的情况下,做出了该小...
- ecshop通用红包编码
很多时候,为了结合促销,必须扩展一下ecshop的红包功能。ecshop的红包...
- ecshop购物车功能改进[插件
ecshop购物车功能改进[插件套餐]主要是我们最近开发工作和开发项目中。...
- ecshop降价通知登记插件
ecshop降价通知登记插件,主要是为了方便某些客户,对商品价格要求比...