优惠券订单及其他脚本

specialSaleUp.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. require_once 'DB_PDO.class.php';
  3. require_once 'TBK.class.php';
  4. require_once 'confv2.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 from special_sale_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->coupon_id) && !empty($result->coupon_id)){
  23. $coupon_id = $result->coupon_id;
  24. $coupon_info = $result->coupon_info;
  25. $coupon_start_time = $result->coupon_start_time;
  26. $coupon_end_time = $result->coupon_end_time;
  27. $coupon_remain_count = $result->coupon_remain_count;
  28. }else{
  29. $coupon_id = '';
  30. $coupon_info = '';
  31. $coupon_start_time = '';
  32. $coupon_end_time = '';
  33. $coupon_remain_count = 0;
  34. }
  35. $sql = " update special_sale_goods set coupon_id = :coupon_id,coupon_info = :coupon_info,coupon_start_time = :coupon_start_time,coupon_end_time = :coupon_end_time,coupon_remain_count = :coupon_remain_count where num_iid = :goods_id ";
  36. $stmt = $_PDO->prepare($sql);
  37. $stmt->execute(array(':coupon_id'=>$coupon_id,':coupon_info'=>$coupon_info,':coupon_start_time'=>$coupon_start_time,':coupon_end_time'=>$coupon_end_time,':coupon_remain_count'=>$coupon_remain_count,':goods_id'=>$v['goods_id']));
  38. $res = $stmt->rowCount();
  39. if($res){
  40. $update_num++;
  41. echo "\n\n更新成功:".$res;
  42. var_dump($v['goods_id']);
  43. }
  44. //if($total_num == 3) break;
  45. }
  46. echo "\n总共".$total_num."条数据";
  47. echo "\n成功更新".$update_num."条数据";