优惠券订单及其他脚本

sync_15d_refund.php 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. require_once 'DB_PDO.class.php';
  3. require_once 'TBK.class.php';
  4. require_once 'conf.class.php';
  5. define("DETAILDEBUG", 0);//打印流程详细信息,如有需要,设为1
  6. define("LIMIT_NUM", 0);//限制导入条数,0不限制,方便测试,上线设为0
  7. date_default_timezone_set('PRC');
  8. sync_refund();
  9. /**
  10. * 同步失效订单
  11. */
  12. function sync_refund(){
  13. //同步订单脚本
  14. # 1.10分钟一次,同步2天内失效订单
  15. $now = date('Y-m-d H:i:s');
  16. echo "\n\n脚本Start_time:".$now;
  17. $time = date("Y-m-d H:i:s", strtotime('-15 day'));
  18. echo "\nCreate_time:".$time;
  19. $etime = '';
  20. $orderResult = array();
  21. $time_type = 2;//按付款时间查
  22. $tk_status = 13;//查询失效状态订单
  23. for($x=1;$x<1081;$x++){
  24. $position_index = '';//查下一页必要参数
  25. $stime = !empty($etime) ? $etime : $time;
  26. $dstr = $time.' '.($x*20).' minutes';
  27. $etime = date("Y-m-d H:i:s",strtotime($dstr));
  28. //渠道
  29. for($i=1;$i<100;$i++){
  30. $res = TBK::syncOrderNew($i,$stime, $etime, $time_type ,$tk_status,1,$position_index);
  31. if(empty($res)){
  32. break;
  33. }else{
  34. $orderData = $res['data'];
  35. $position_index = $res['position_index'];
  36. }
  37. $orderResult = array_merge($orderResult, $orderData);
  38. }
  39. }
  40. # 统计
  41. $res_count = array(
  42. 'total_num' => 0,
  43. 'insert_num' => 0,
  44. 'update_num' => 0,
  45. 'fail_num' => 0,
  46. 'nshoud_update_num' => 0,
  47. );
  48. #初始化pdo
  49. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  50. foreach($orderResult as $k=>$orderDetail){
  51. $res_count['total_num']++;
  52. echo "/ ************************ order{$res_count['total_num']}-Start ************************* / \n";
  53. echo 'order_id:'.$orderDetail['trade_id'].'|| goods_id:'.$orderDetail['item_id'].'|| orderstatus:'.$orderDetail['tk_status'].'|| order_balance_at: || update_time:'.$now;
  54. if( DETAILDEBUG == 1){
  55. echo 'orderDetail:';
  56. var_dump($orderDetail);
  57. }
  58. $sql = "select id,tk_status from zbds_taoke_orders where trade_id = '".$orderDetail['trade_id']."' and num_iid = '".$orderDetail['item_id']."' limit 1";
  59. $stmt = $_PDO->prepare($sql);
  60. $stmt->execute();
  61. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  62. if(!empty($result)){
  63. if($orderDetail['tk_status'] != $result['tk_status']){
  64. //更新操作
  65. $sql = "update zbds_taoke_orders set tk_status={$orderDetail['tk_status']} WHERE trade_id = '".$orderDetail['trade_id']."' and num_iid = '".$orderDetail['item_id']."'";
  66. $stmt = $_PDO->prepare($sql);
  67. $stmt->execute();
  68. $res = $stmt->rowCount();
  69. if($res){
  70. echo "\n 更新成功 +1";
  71. $res_count['update_num']++;
  72. }else{
  73. echo "\n 更新失败 +1";
  74. $res_count['fail_num']++;
  75. }
  76. }else{
  77. echo "\n 状态未变,不做处理 +1";
  78. $res_count['nshoud_update_num']++;
  79. }
  80. }else{
  81. if(!isset($orderDetail['tk_earning_time'])) $orderDetail['tk_earning_time'] = '2000-00-00 00:00:00';
  82. if(!isset($orderDetail['click_time'])) $orderDetail['click_time'] = $orderDetail['tk_create_time'];
  83. if(!isset($orderDetail['special_id'])) $orderDetail['special_id'] = 0;
  84. if(!isset($orderDetail['relation_id'])) $orderDetail['relation_id'] = 0;
  85. if(!isset($orderDetail['total_commission_fee'])) $orderDetail['total_commission_fee'] = 0;
  86. if(!isset($orderDetail['subsidy_fee'])) $orderDetail['subsidy_fee'] = 0;
  87. if(!isset($orderDetail['pay_price'])) $orderDetail['pay_price'] = 0;
  88. if(!isset($orderDetail['pub_share_fee'])) $orderDetail['pub_share_fee'] = 0;
  89. if(!isset($orderDetail['subsidy_type'])) $orderDetail['subsidy_type'] = 0;
  90. if(!isset($orderDetail['flow_source'])) $orderDetail['flow_source'] = '--';
  91. if(!isset($orderDetail['site_name'])) $orderDetail['site_name'] = '';
  92. if(!isset($orderDetail['adzone_name'])) $orderDetail['adzone_name'] = '';
  93. if(!isset($orderDetail['pub_share_pre_fee'])) $orderDetail['pub_share_pre_fee'] = 0;
  94. if(!isset($orderDetail['alipay_total_price'])) $orderDetail['alipay_total_price'] = 0;
  95. //create_time,click_time,item_title,num_iid,seller_nick,seller_shop_title,item_num,price,tk_status,order_type,income_rate,commission_rate,pay_price,pub_share_pre_fee,alipay_total_price,commission,earning_time,total_commission_rate,total_commission_fee,subsidy_rate,subsidy_fee,subsidy_type,terminal_type,tk3rd_type,trade_parent_id,trade_id,auction_category,site_id,site_name,adzone_id,adzone_name,relation_id,special_id
  96. $res = insertOrder($orderDetail, $res_count);
  97. }
  98. echo "\n/ ** order{$res_count['total_num']}-End ** /";
  99. echo "\n\n\n";
  100. }
  101. echo "\n失效订单:";
  102. var_dump($res_count);
  103. }
  104. function insertOrder($orderDetail, &$res_count){
  105. $orderDetail['item_title'] = addslashes($orderDetail['item_title']);
  106. $orderDetail['seller_nick'] = addslashes($orderDetail['seller_nick']);
  107. $orderDetail['seller_shop_title'] = addslashes($orderDetail['seller_shop_title']);
  108. if(!isset($orderDetail['special_id'])) $orderDetail['special_id'] = null;
  109. if(!isset($orderDetail['relation_id'])) $orderDetail['relation_id'] = null;
  110. $sql = "insert into zbds_taoke_orders(create_time,click_time,item_title,num_iid,seller_nick,seller_shop_title,item_num,price,tk_status,order_type,income_rate,commission_rate,pay_price,pub_share_pre_fee,alipay_total_price,commission,earning_time,total_commission_rate,total_commission_fee,subsidy_rate,subsidy_fee,subsidy_type,terminal_type,tk3rd_type,trade_parent_id,trade_id,auction_category,site_id,site_name,adzone_id,adzone_name,relation_id,special_id) values('".$orderDetail['tk_create_time']."', '". $orderDetail['click_time']."', '". $orderDetail['item_title']."', '". $orderDetail['item_id']."', '". $orderDetail['seller_nick']."', '". $orderDetail['seller_shop_title']."', '". $orderDetail['item_num']."', '". $orderDetail['item_price']."', '". $orderDetail['tk_status']."', '". $orderDetail['order_type']."', '". $orderDetail['income_rate']."', '". $orderDetail['pub_share_rate']."', '". $orderDetail['pay_price']."', '". $orderDetail['pub_share_pre_fee']."', '". $orderDetail['alipay_total_price']."', '". $orderDetail['pub_share_fee']."', '". $orderDetail['tk_earning_time']."', '". $orderDetail['total_commission_rate']."', '". $orderDetail['total_commission_fee']."', '". $orderDetail['subsidy_rate']."', '". $orderDetail['subsidy_fee']."', '". $orderDetail['subsidy_type']."', '". $orderDetail['terminal_type']."', '". $orderDetail['flow_source']."', '". $orderDetail['trade_parent_id']."', '". $orderDetail['trade_id']."', '". $orderDetail['item_category_name']."', '". $orderDetail['site_id']."', '". $orderDetail['site_name']."', '". $orderDetail['adzone_id']."', '". $orderDetail['adzone_name']."', '". $orderDetail['relation_id']."', '". $orderDetail['special_id']."')";
  111. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  112. $stmt = $_PDO->prepare($sql);
  113. $stmt->execute();
  114. $res = $_PDO->lastinsertid();
  115. if($res){
  116. echo "\n 插入成功 +1";
  117. $res_count['insert_num']++;
  118. }else{
  119. echo "\n 插入失败 +1";
  120. $res_count['fail_num']++;
  121. }
  122. return $res;
  123. }