优惠券订单及其他脚本

sale_goods_update.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. require_once 'DB_PDO.class.php';
  3. require_once 'TBK.class.php';
  4. require_once 'conf.class.php';
  5. define("KEYURL","https://item.taobao.com/item.htm?id=");
  6. /**
  7. * 更新优选商品剩余数量数据
  8. */
  9. #设置时区
  10. date_default_timezone_set('PRC');
  11. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  12. $sql = " select num_iid as goods_id, commission_rate from sale_goods order by id desc";
  13. $stmt = $_PDO->prepare($sql);
  14. $stmt->execute();
  15. $goods = $stmt->fetchAll(PDO::FETCH_ASSOC);
  16. $total_num = 0;
  17. $update_num = 0;
  18. foreach( $goods as $k=>$v ){
  19. $total_num++;
  20. $keyword = KEYURL.$v['goods_id'];
  21. $result = TBK::search( $keyword );
  22. if( !isset($result->commission_rate )){
  23. $commission_rate = $v['commission_rate'];
  24. }else{
  25. $commission_rate = $result->commission_rate;
  26. }
  27. $sql = " update sale_goods set commission_rate = :commission_rate, commission_rate_2 = :commission_rate_2 where num_iid = :goods_id ";
  28. $stmt = $_PDO->prepare($sql);
  29. $stmt->execute(array(':commission_rate'=>$commission_rate, ':commission_rate_2'=>$v['commission_rate'], ':goods_id'=>$v['goods_id']));
  30. $res = $stmt->rowCount();
  31. if($res){
  32. $update_num++;
  33. echo "\n\n更新成功:".$res;
  34. var_dump($v['goods_id']);
  35. }
  36. //if($total_num == 3) break;
  37. }
  38. echo "\n总共".$total_num."条数据";
  39. echo "\n成功更新".$update_num."条数据";