优惠券订单及其他脚本

youxuan_update.php 1.3KB

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