优惠券订单及其他脚本

sync_liedou_refund.php 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. require_once 'DB_PDO.class.php';
  3. require_once 'TBK_v2.class.php';
  4. require_once 'confv2.class.php';
  5. require_once 'RedisClass.php';
  6. define("DETAILDEBUG", 0);//打印流程详细信息,如有需要,设为1
  7. define("LIMIT_NUM", 0);//限制导入条数,0不限制,方便测试,上线设为0
  8. date_default_timezone_set('PRC');
  9. sync_refund();
  10. /**
  11. * 同步失效订单
  12. */
  13. function sync_refund(){
  14. //同步订单脚本
  15. # 1.10分钟一次,同步2天内失效订单
  16. $now = date('Y-m-d H:i:s');
  17. echo "\n\n脚本Start_time:".$now;
  18. $time = date("Y-m-d H:i:s", strtotime('-2 day'));
  19. echo "\nCreate_time:".$time;
  20. $_time=1200;
  21. $orderResult = array();
  22. for($x=144;$x>0;$x--){
  23. $dstr = '-'.($x*20).' minutes';
  24. $stime = date("Y-m-d H:i:s",strtotime($dstr));
  25. //渠道失效订单
  26. for($i=1;$i<100;$i++){
  27. $res = TBK::syncOrder($i,$stime,$_time,13,'create_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::syncOrder($i,$stime,$_time,13,'create_time',1,3);
  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::syncOrder($i,$stime,$_time,13,'create_time',2,2);
  44. if(empty($res)){
  45. break;
  46. }
  47. $orderResult = array_merge($orderResult, $res);
  48. }
  49. //会员三方失效订单
  50. for($i=1;$i<100;$i++){
  51. $res = TBK::syncOrder($i,$stime,$_time,13,'create_time',2,3);
  52. if(empty($res)){
  53. break;
  54. }
  55. $orderResult = array_merge($orderResult, $res);
  56. }
  57. }
  58. # 统计
  59. $res_count = array(
  60. 'total_num' => 0,
  61. 'insert_num' => 0,
  62. 'update_num' => 0,
  63. 'fail_num' => 0,
  64. 'nshoud_update_num' => 0,
  65. );
  66. #初始化pdo
  67. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  68. foreach($orderResult as $k=>$orderDetail){
  69. $res_count['total_num']++;
  70. echo "/ ************************ order{$res_count['total_num']}-Start ************************* / \n";
  71. echo 'order_id:'.$orderDetail['trade_id'].'|| goods_id:'.$orderDetail['num_iid'].'|| orderstatus:'.$orderDetail['tk_status'].'|| order_balance_at: || update_time:'.$now;
  72. if( DETAILDEBUG == 1){
  73. echo 'orderDetail:';
  74. var_dump($orderDetail);
  75. }
  76. # 花生联盟活跃relation逻辑 //退款逻辑跳过
  77. if($orderDetail['adzone_id'] == '102465800487'){
  78. echo "\n花生订单跳过\n";
  79. continue;
  80. }
  81. $sql = "select id,tk_status from liedou_taoke_orders where trade_id = '".$orderDetail['trade_id']."' and num_iid = '".$orderDetail['num_iid']."' limit 1";
  82. $stmt = $_PDO->prepare($sql);
  83. $stmt->execute();
  84. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  85. if(!empty($result)){
  86. if($orderDetail['tk_status'] != $result['tk_status']){
  87. //更新操作
  88. $sql = "update liedou_taoke_orders set tk_status={$orderDetail['tk_status']} WHERE trade_id = '".$orderDetail['trade_id']."' and num_iid = '".$orderDetail['num_iid']."'";
  89. $stmt = $_PDO->prepare($sql);
  90. $stmt->execute();
  91. $res = $stmt->rowCount();
  92. if($res){
  93. echo "\n 更新成功 +1";
  94. $res_count['update_num']++;
  95. }else{
  96. echo "\n 更新失败 +1";
  97. $res_count['fail_num']++;
  98. }
  99. }else{
  100. echo "\n 状态未变,不做处理 +1";
  101. $res_count['nshoud_update_num']++;
  102. }
  103. }else{
  104. if(!isset($orderDetail['earning_time'])) $orderDetail['earning_time'] = '2000-00-00 00:00:00';
  105. if(!isset($orderDetail['click_time'])) $orderDetail['click_time'] = $orderDetail['create_time'];
  106. if(!isset($orderDetail['special_id'])) $orderDetail['special_id'] = 0;
  107. if(!isset($orderDetail['relation_id'])) $orderDetail['relation_id'] = 0;
  108. if(!isset($orderDetail['total_commission_fee'])) $orderDetail['total_commission_fee'] = 0;
  109. if(!isset($orderDetail['subsidy_fee'])) $orderDetail['subsidy_fee'] = 0;
  110. if(!isset($orderDetail['pay_price'])) $orderDetail['pay_price'] = 0;
  111. if(!isset($orderDetail['commission'])) $orderDetail['commission'] = 0;
  112. if(!isset($orderDetail['subsidy_type'])) $orderDetail['subsidy_type'] = 0;
  113. if(!isset($orderDetail['tk3rd_type'])) $orderDetail['tk3rd_type'] = '--';
  114. if(!isset($orderDetail['site_name'])) $orderDetail['site_name'] = '';
  115. if(!isset($orderDetail['adzone_name'])) $orderDetail['adzone_name'] = '';
  116. if(!isset($orderDetail['pub_share_pre_fee'])) $orderDetail['pub_share_pre_fee'] = 0;
  117. if(!isset($orderDetail['alipay_total_price'])) $orderDetail['alipay_total_price'] = 0;
  118. //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
  119. $res = insertOrder($orderDetail, $res_count);
  120. }
  121. echo "\n/ ** order{$res_count['total_num']}-End ** /";
  122. echo "\n\n\n";
  123. }
  124. echo "\n失效订单:";
  125. var_dump($res_count);
  126. }
  127. function insertOrder($orderDetail, &$res_count){
  128. $orderDetail['item_title'] = addslashes($orderDetail['item_title']);
  129. $orderDetail['seller_nick'] = addslashes($orderDetail['seller_nick']);
  130. $orderDetail['seller_shop_title'] = addslashes($orderDetail['seller_shop_title']);
  131. if(!isset($orderDetail['special_id'])) $orderDetail['special_id'] = null;
  132. if(!isset($orderDetail['relation_id'])) $orderDetail['relation_id'] = null;
  133. $sql = "insert into liedou_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['create_time']."', '". $orderDetail['click_time']."', '". $orderDetail['item_title']."', '". $orderDetail['num_iid']."', '". $orderDetail['seller_nick']."', '". $orderDetail['seller_shop_title']."', '". $orderDetail['item_num']."', '". $orderDetail['price']."', '". $orderDetail['tk_status']."', '". $orderDetail['order_type']."', '". $orderDetail['income_rate']."', '". $orderDetail['commission_rate']."', '". $orderDetail['pay_price']."', '". $orderDetail['pub_share_pre_fee']."', '". $orderDetail['alipay_total_price']."', '". $orderDetail['commission']."', '". $orderDetail['earning_time']."', '". $orderDetail['total_commission_rate']."', '". $orderDetail['total_commission_fee']."', '". $orderDetail['subsidy_rate']."', '". $orderDetail['subsidy_fee']."', '". $orderDetail['subsidy_type']."', '". $orderDetail['terminal_type']."', '". $orderDetail['tk3rd_type']."', '". $orderDetail['trade_parent_id']."', '". $orderDetail['trade_id']."', '". $orderDetail['auction_category']."', '". $orderDetail['site_id']."', '". $orderDetail['site_name']."', '". $orderDetail['adzone_id']."', '". $orderDetail['adzone_name']."', '". $orderDetail['relation_id']."', '". $orderDetail['special_id']."')";
  134. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  135. $stmt = $_PDO->prepare($sql);
  136. $stmt->execute();
  137. $res = $_PDO->lastinsertid();
  138. if($res){
  139. echo "\n 插入成功 +1";
  140. $res_count['insert_num']++;
  141. }else{
  142. echo "\n 插入失败 +1";
  143. $res_count['fail_num']++;
  144. }
  145. return $res;
  146. }