优惠券订单及其他脚本

user_favorite_update.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 distinct goods_id FROM `tbk`.`user_favorites` where `create_at` >'2018-07-01 00:00:00' and create_at<='2018-08-15 00:00:00' and `is_coupon` =1 and `coupon_end_time` is null ; ";
  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_end_time) ) continue;
  23. $coupon_end_time = $result->coupon_end_time;
  24. $coupon_start_time = $result->coupon_start_time;
  25. $sql = " update user_favorites set coupon_end_time = :coupon_end_time,coupon_start_time=:coupon_start_time where goods_id = :goods_id ";
  26. $stmt = $_PDO->prepare($sql);
  27. $stmt->execute(array(':coupon_end_time'=>$coupon_end_time,':coupon_start_time'=>$coupon_start_time,':goods_id'=>$v['goods_id']));
  28. $res = $stmt->rowCount();
  29. if($res){
  30. var_dump($v['goods_id']);
  31. $update_num++;
  32. echo "\n更新成功:".$res;
  33. }
  34. //if($total_num == 3) break;
  35. }
  36. echo "\n总共".$total_num."条数据";
  37. echo "\n成功更新".$update_num."条数据";