ECSHOP一淘Feed数据生成程序
一、修改etao_query.php和etao_increment.php的网站参数。
二、新建目录,目录名你可以随便起一个,如:open,etao_query.php和etao_increment.php放在open目录下,在open目录下新建目录taobao/item,把open目录上传到你网站的目录里。
三、执行etao_query.php 生成全量的索引文件 ,执行etao_increment.php是生成增量的索引文件,如:http://ecshop.phpally.com/open/etao_query.php,程序就会自动生成相关的文件的了。
四、进入一淘工作台提交Feed数据。全量更新数据为http://ecshop.phpally.com/open/taobao/FullIndex.xml,增量更新数据为http://ecshop.phpally.com/open/taobao/IncrementIndex.xml。
etao_query.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
<?php /** * ECSHOP 一淘全量Feed数据生成程序 * ============================================================================ * Jacklee的博客 致力于php技术 * http://www.phpally.com * ---------------------------------------------------------------------------- * @author: Jacklee * @email: jack349392900#gmail.com * @date: 2012-03-10 */ define('IN_ECS',true); define('IN_DB_SELECT',true); require(dirname(__FILE__) . '/../includes/init.php'); include_once(ROOT_PATH."/includes/lib_common.php" ); define('IN_ECS', true); define('IN_DB_SELECT', true); define('SITE_URL','http://www.phpally.com/'); define('ET_NAME','PHPALLY');//设置在一淘的用户名 //执行更新动作,更新商品数据 $sql = "SELECT DISTINCT(g.goods_id) FROM ".$ecs->table('goods')." AS g WHERE g.is_delete = '0' AND g.shop_price > '0'"; $product=$db->getAll($sql); $xml='<?xml version="1.0" encoding="utf-8" ?>'; $xml.='<root>'; $xml.='<version>1.0</version>'; $xml.='<modified>'.date('Y-m-d H:i:s').'</modified>'; $xml.='<seller_id>'.ET_NAME.'</seller_id>'; $xml.='<cat_url>'.SITE_URL.'open/taobao/SellerCats.xml</cat_url>'; $xml.='<dir>'.SITE_URL.'open/taobao/item/</dir>'; $xml.='<item_ids>'; foreach($product as $value){ $xml.='<outer_id action="upload">'.$value['goods_id'].'</outer_id>'; } $xml.='</item_ids>'; $xml.='</root>'; //执行:保存历史商品dat:将本次所有的商品写入last_outer.dat中保存 file_put_contents(ROOT_PATH.'open/taobao/last_outer.dat', serialize($product)); header('Content-type: application/xml; charset=utf-8'); file_put_contents(ROOT_PATH.'open/taobao/FullIndex.xml',$xml);; //执行:生成商品目录xml $sql="select * from ".$ecs->table('category')." where parent_id=0"; $cat_detail=$db->getAll($sql); $catxml='<?xml version="1.0" encoding="utf-8"?>'; $catxml.='<root>'; $catxml.='<version>1.0</version>'; $catxml.='<modified>'.local_date('Y-m-d H:i:s').'</modified>'; $catxml.='<seller_id>'.ET_NAME.'</seller_id>'; $catxml.='<seller_cats>'; foreach($cat_detail as $cat) { $catxml.='<cat>'; $catxml.='<scid>'.$cat['cat_id'].'</scid>'; $catxml.='<name><![CDATA['.$cat['cat_name'].']]></name>'; $catxml.='<cats>'; $catsec=$db->getAll("select * from ".$ecs->table('category')." where parent_id='".$cat['cat_id']."'"); foreach($catsec as $catsecvalue) { $catxml.='<cat>'; $catxml.='<scid>'.$catsecvalue['cat_id'].'</scid>'; $catxml.='<name><![CDATA['.$catsecvalue['cat_name'].']]></name>'; $catxml.='</cat>'; } $catxml.='</cats> '; $catxml.='</cat>'; unset($catsec);unset($catsecvalue); } $catxml.='</seller_cats>'; $catxml.='</root>'; header('Content-type: application/xml; charset=utf-8'); file_put_contents(ROOT_PATH.'open/taobao/SellerCats.xml',$catxml); //执行:生成商品包xml $sql="SELECT DISTINCT(g.goods_id),goods_name,promote_start_date,promote_end_date,promote_price,shop_price,goods_thumb,goods_desc,brand_id,goods_img,c.cat_id,c.cat_name FROM ".$ecs->table('goods')." AS g LEFT JOIN ".$ecs->table('category')." as c ON g.cat_id = c.cat_id WHERE goods_thumb is not null AND g.is_delete = '0' AND g.shop_price > '0' GROUP BY g.goods_id DESC "; $product_detail=$db->getAll($sql); $brand=$db->getAll("select * from ".$ecs->table('brand')." order by brand_id"); foreach($brand as $brandvalue){ $brand_info[$brandvalue['brand_id']]=$brandvalue['brand_name']; } foreach($product_detail as $value){ $pxml='<?xml version="1.0" encoding="utf-8"?>'; $pxml.='<item>'; $pxml.='<seller_id>'.ET_NAME.'</seller_id>'; $pxml.='<outer_id>'.$value['goods_id'].'</outer_id>'; $pxml.='<title><![CDATA['.$value['goods_name'].']]></title>'; $pxml.='<type><![CDATA['.$value['cat_name'].']]></type>'; $pxml.='<price>'.$value['shop_price'].'</price>'; if($value['promote_start_date']<gmtime()>>$value['promote_end_date']>gmtime()>>$value['promote_price']>0>>$value['promote_price']<$value['shop_price']){ $value['drate']=price_format($value['promote_price']/$value['shop_price']); $pxml.='<discount>'; $pxml.='<start>'.local_date('Y-m-d-H:i',$value['promote_start_date']).'</start>'; $pxml.='<end>'.local_date('Y-m-d-H:i',$value['promote_end_date']).'</end>'; $pxml.='<dprice>'.$value['promote_price'].'</dprice>'; $pxml.='<drate>'.$value['drate'].'</drate> '; $pxml.='<ddesc>Jacklee的博客-专注于PHP技术</ddesc>'; $pxml.='</discount>'; } $pxml.='<desc><![CDATA['.$value['goods_desc'].']]></desc>'; $pxml.='<brand><![CDATA['.$brand_info[$value['brand_id']].']]></brand>'; $pxml.='<tags><![CDATA['.$brand_info[$value['brand_id']].']]></tags>'; $value['thumb_url']= get_image_path($value['goods_id'], $value['goods_thumb'], true); $pxml.='<image>'.SITE_URL.$value['thumb_url'].'</image>'; $pxml.='<scids>'.$value['cat_id'].'</scids>'; $pxml.='<post_fee>0.00</post_fee>'; $pxml.='<showcase>true</showcase>'; $pxml.='<href>'.SITE_URL.build_uri('goods', array('gid' => $value['goods_id']), $value['goosd_name']).'</href>'; $pxml.='</item>'; header('Content-type: application/xml; charset=utf-8'); file_put_contents(ROOT_PATH.'open/taobao/item/'.$value['goods_id'].'.xml', $pxml); unset($pxml); } //输出全量索引 header('Content-type: application/xml; charset=utf-8'); die($xml); ?> |
etao_increment.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
<?php /** * ECSHOP 一淘增量Feed数据生成程序 * ---------------------------------------------------------------------------- * Jacklee的博客 致力于php技术 * http://www.phpally.com * ---------------------------------------------------------------------------- * @author: Jacklee * @email: jack349392900#gmail.com * @date: 2012-03-10 */ define('IN_ECS',true); define('IN_DB_SELECT',true); require(dirname(__FILE__) . '/../includes/init.php'); include_once(ROOT_PATH."/includes/lib_common.php" ); define('IN_ECS', true); define('IN_DB_SELECT', true); define('SITE_URL','http://www.phpally.com/');//在这里设置站URL define('ET_NAME','PHPALLY');//设置在一淘的用户名 //执行更新动作 $sql="SELECT DISTINCT(g.goods_id),goods_name,last_update,promote_start_date,promote_end_date,promote_price,shop_price,goods_thumb,goods_desc,brand_id,goods_img,c.cat_name,g.cat_id FROM ".$ecs->table('goods')." AS g LEFT JOIN ".$ecs->table('category')." as c ON g.cat_id = c.cat_id WHERE goods_thumb is not null AND g.is_delete = '0' AND g.shop_price > '0' AND g.last_update <> g.add_time group by goods_id"; $this_outer=$db->getAll($sql); $last_outer=unserialize(file_get_contents(ROOT_PATH.'open/taobao/last_outer.dat')); foreach($last_outer as $val){ $last_outer_array[]=$val['goods_id']; } foreach($this_outer as $val){ $this_outer_array[]=$val['goods_id']; } //选出需要新增的 foreach($this_outer as $val){ if(!in_array($val['goods_id'],$last_outer_array)){ $need_add[]=$val['goods_id']; } } //选出需要删除的 foreach($last_outer as $val){ if(!in_array($val['goods_id'],$this_outer_array)){ $need_delete[]=$val['goods_id']; } file_put_contents(ROOT_PATH.'open/taobao/IncrementIndex.xml', $feed_header.$xml_f); } //写新的产品xml if($need_add){ foreach($need_add as $val){ $need_add_where.=$dou.$val; $dou=','; } //执行:生成增量商品包xml $sql="SELECT DISTINCT(g.goods_id),goods_name,promote_start_date,promote_end_date,promote_price,shop_price,goods_thumb,g.cat_id,goods_desc,brand_id,goods_img,c.cat_name FROM ".$ecs->table('goods')." AS g LEFT JOIN ".$ecs->table('category')." as c ON g.cat_id = c.cat_id WHERE goods_thumb is not null and g.is_delete = '0' AND g.shop_price > '0' and g.goods_id in (".$need_add_where.") GROUP BY goods_id"; $product_detail=$db->getAll($sql); $brand=$db->getAll("select * from ".$ecs->table('brand')." order by brand_id"); foreach($brand as $brandvalue){ $brand_info[$brandvalue['brand_id']]=$brandvalue['brand_name']; } foreach($product_detail as $value){ $pxml='<?xml version="1.0" encoding="utf-8"?>'; $pxml.='<item>'; $pxml.='<seller_id>'.ET_NAME.'</seller_id>'; $pxml.='<outer_id>'.$value['goods_id'].'</outer_id>'; $pxml.='<title><![CDATA['.$value['goods_name'].']]></title>'; $pxml.='<type><![CDATA['.$value['cat_name'].']]></type>'; $pxml.='<price>'.$value['shop_price'].'</price>'; if($value['promote_start_date']<gmtime()>>$value['promote_end_date']>gmtime()>>$value['promote_price']>0>>$value['promote_price']<$value['shop_price']){ $value['drate']=price_format($value['promote_price']/$value['shop_price']); $pxml.='<discount>'; $pxml.='<start>'.local_date('Y-m-d-H:i',$value['promote_start_date']).'</start>'; $pxml.='<end>'.local_date('Y-m-d-H:i',$value['promote_end_date']).'</end>'; $pxml.='<dprice>'.$value['promote_price'].'</dprice>'; $pxml.='<drate>'.$value['drate'].'</drate> '; $pxml.='<ddesc>Jacklee的博客-专注于PHP技术</ddesc>'; $pxml.='</discount>'; } $pxml.='<desc><![CDATA['.$value['goods_desc'].']]></desc>'; $pxml.='<brand><![CDATA['.$brand_info[$value['brand_id']].']]></brand>'; $pxml.='<tags><![CDATA['.$brand_info[$value['brand_id']].']]></tags>'; $pxml.='<image>'.$value['goods_thumb'].'</image>'; $pxml.='<scids>'.$value['cat_id'].'</scids>'; $pxml.='<post_fee>0.00</post_fee>'; $pxml.='<showcase>true</showcase>'; $pxml.='<href>'.SITE_URL.build_uri('goods', array('gid' => $value['goods_id']), $value['goosd_name']).'</href>'; $pxml.='</item>'; header('Content-type: application/xml; charset=utf-8'); file_put_contents(ROOT_PATH.'taobao/item/'.$value['goods_id'].'.xml', $pxml); unset($pxml); } } $xml='<?xml version="1.0" encoding="utf-8" ?>'; $xml.='<root>'; $xml.='<version>1.0</version>'; $xml.='<modified>'.local_date('Y-m-d H:i:s').'</modified>'; $xml.='<seller_id>'.ET_NAME.'</seller_id>'; $xml.='<cat_url>'.SITE_URL.'open/taobao/SellerCats.xml</cat_url>'; $xml.='<dir>'.SITE_URL.'open/taobao/item/</dir>'; $xml.='<item_ids>'; if($need_delete){ foreach($need_delete as $value){ $xml.='<outer_id action="delete">'.$value.'</outer_id>'; } } if($need_add){ foreach($need_add as $value){ $xml.='<outer_id action="upload">'.$value.'</outer_id>'; } } $xml.='</item_ids>'; $xml.='</root>'; //执行:保存历史商品data:将本次所有的商品写入last_outer.dat中保存 file_put_contents(ROOT_PATH.'open/taobao/item/last_outer.dat', serialize($this_outer)); //删除不需要的product xml文件 if($need_delete){ foreach($need_delete as $val){ if(file_exists(ROOT_PATH.'open/taobao/item/'.$val.'.xml')){ unlink(ROOT_PATH.'open/taobao/item/'.$val.'.xml'); } } } //输出索引 header('Content-type: application/xml; charset=utf-8'); file_put_contents(ROOT_PATH.'open/taobao/IncrementIndex.xml',$xml);; die($xml); ?> |