优惠券订单及其他脚本

sync_liedou_vq.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. require_once 'DB_PDO.class.php';
  3. require_once 'TBK_v2.class.php';
  4. require_once 'confv2.class.php';
  5. define("DETAILDEBUG", 0);//打印流程详细信息,如有需要,设为1
  6. define("LIMIT_NUM", 0);//限制导入条数,0不限制,方便测试,上线设为0
  7. date_default_timezone_set('PRC');
  8. sync_vq();
  9. /**
  10. * 同步维权订单
  11. */
  12. function sync_vq(){
  13. //同步订单脚本
  14. # 1.同步1天内维权订单
  15. $orderResult = array();
  16. $start_time = date("Y-m-d 00:00:00", strtotime('-1 day'));
  17. //渠道二方维权订单
  18. for($i=1;$i<100;$i++){
  19. $res = TBK::syncVqOrder($i, $start_time, 1, 1);
  20. if(empty($res)){
  21. break;
  22. }
  23. $orderResult = array_merge($orderResult, $res);
  24. }
  25. //会员二方维权订单
  26. for($i=1;$i<100;$i++){
  27. $res = TBK::syncVqOrder($i, $start_time, 1, 2);
  28. if(empty($res)){
  29. break;
  30. }
  31. $orderResult = array_merge($orderResult, $res);
  32. }
  33. //渠道三方维权订单
  34. for($i=1;$i<100;$i++){
  35. $res = TBK::syncVqOrder($i, $start_time, 2, 1);
  36. if(empty($res)){
  37. break;
  38. }
  39. $orderResult = array_merge($orderResult, $res);
  40. }
  41. //会员三方维权订单
  42. for($i=1;$i<100;$i++){
  43. $res = TBK::syncVqOrder($i, $start_time, 2, 2);
  44. if(empty($res)){
  45. break;
  46. }
  47. $orderResult = array_merge($orderResult, $res);
  48. }
  49. # 统计
  50. $res_count = array(
  51. 'total_num' => 0,
  52. 'generalupdate_num' => 0,
  53. 'fail_update_num' => 0,
  54. );
  55. #初始化pdo
  56. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  57. foreach($orderResult as $k=>$orderDetail){
  58. if(!isset($orderDetail['tb_trade_id'])) continue;
  59. $res_count['total_num']++;
  60. $order_id=$orderDetail['tb_trade_id'];
  61. if($orderDetail['refund_status'] == '2'){
  62. $maintain_power = 3;
  63. }else{
  64. continue;
  65. }
  66. $power_create_at = $orderDetail['tk_refund_time'];
  67. $power_end_at = isset($orderDetail['tk_refund_suit_time']) ? $orderDetail['tk_refund_suit_time'] : null;
  68. echo 'order_id:'.$order_id.'|| goods_name:'.$orderDetail['tb_auction_title'].'|| maintain_power:'.$maintain_power.'|| power_create_at:'.$power_create_at;
  69. echo "\n";
  70. try{
  71. $_PDO->beginTransaction();
  72. //更新order_rebate
  73. $sql="update order_rebate set maintain_power=:maintain_power,power_create_at=:power_create_at,power_end_at=:power_end_at where order_id=:order_id";
  74. if($maintain_power==3) $sql="update order_rebate set maintain_power=:maintain_power,power_create_at=:power_create_at,power_end_at=:power_end_at,status=0 where order_id=:order_id";
  75. $stmt = $_PDO->prepare($sql);
  76. $stmt->execute(array(':maintain_power'=>$maintain_power,':power_create_at'=>$power_create_at,':power_end_at'=>$power_end_at,':order_id'=>$order_id));
  77. $res = $stmt->rowCount();
  78. echo "更新order_rebate:".$res."\n";
  79. //更新order_rebate_profit
  80. $sql="update order_rebate_profit set maintain_power=:maintain_power,power_create_at=:power_create_at,power_end_at=:power_end_at where order_id=:order_id";
  81. if($maintain_power==3) $sql="update order_rebate_profit set maintain_power=:maintain_power,power_create_at=:power_create_at,power_end_at=:power_end_at,status=0 where order_id=:order_id";
  82. $stmt = $_PDO->prepare($sql);
  83. $stmt->execute(array(':maintain_power'=>$maintain_power,':power_create_at'=>$power_create_at,':power_end_at'=>$power_end_at,':order_id'=>$order_id));
  84. $res = $stmt->rowCount();
  85. echo "更新order_rebate_profit:".$res."\n";
  86. if($res){
  87. $res_count['generalupdate_num']++;
  88. }else{
  89. $res_count['fail_update_num']++;
  90. }
  91. $_PDO->commit();
  92. }catch(Exception $e){
  93. echo 'err_msg'.$e->getMessage()."\n";
  94. $_PDO->rollback();
  95. }
  96. echo "\n/ ** order{$res_count['total_num']}-End ** /";
  97. echo "\n\n\n";
  98. }
  99. echo "\n维权订单:";
  100. var_dump($res_count);
  101. }