优惠券订单及其他脚本

xiaobian_update.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 goods_id from youxuan_goods order by id desc limit 200";
  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 )) continue;
  23. $commission_rate = $result->commission_rate/100;
  24. $sql = " update goods set commission_rate = :commission_rate where goods_id = :goods_id ";
  25. $stmt = $_PDO->prepare($sql);
  26. $stmt->execute(array(':commission_rate'=>$commission_rate,':goods_id'=>$v['goods_id']));
  27. $res = $stmt->rowCount();
  28. if($res){
  29. $update_num++;
  30. echo "\n\n更新成功:".$res;
  31. var_dump($v['goods_id']);
  32. }
  33. //if($total_num == 3) break;
  34. }
  35. echo "\n总共".$total_num."条数据";
  36. echo "\n成功更新".$update_num."条数据";