123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- require_once 'DB_PDO.class.php';
- require_once 'TBK.class.php';
- require_once 'conf.class.php';
- define("KEYURL","https://item.taobao.com/item.htm?id=");
- /**
- * 更新优选商品剩余数量数据
- */
- #设置时区
- date_default_timezone_set('PRC');
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- $sql = " select num_iid as goods_id, commission_rate from sale_goods order by id desc";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute();
- $goods = $stmt->fetchAll(PDO::FETCH_ASSOC);
- $total_num = 0;
- $update_num = 0;
- foreach( $goods as $k=>$v ){
- $total_num++;
- $keyword = KEYURL.$v['goods_id'];
- $result = TBK::search( $keyword );
- if( !isset($result->commission_rate )){
- $commission_rate = $v['commission_rate'];
- }else{
- $commission_rate = $result->commission_rate;
- }
-
- $sql = " update sale_goods set commission_rate = :commission_rate, commission_rate_2 = :commission_rate_2 where num_iid = :goods_id ";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':commission_rate'=>$commission_rate, ':commission_rate_2'=>$v['commission_rate'], ':goods_id'=>$v['goods_id']));
- $res = $stmt->rowCount();
- if($res){
- $update_num++;
- echo "\n\n更新成功:".$res;
- var_dump($v['goods_id']);
- }
- //if($total_num == 3) break;
- }
- echo "\n总共".$total_num."条数据";
- echo "\n成功更新".$update_num."条数据";
|