优惠券订单及其他脚本

sync_liedou_refund15.php 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. set_time_limit(0);
  10. ini_set('memory_limit','1024M');
  11. sync_refund();
  12. /**
  13. * 同步失效订单
  14. */
  15. function sync_refund(){
  16. //同步订单脚本
  17. # 1.同步15天内失效订单
  18. $now = date('Y-m-d H:i:s');
  19. echo "\n\n脚本Start_time:".$now;
  20. $time = date("Y-m-d H:i:s", strtotime('-15 day'));
  21. echo "\nCreate_time:".$time;
  22. $_time=1200;
  23. $orderResult = array();
  24. for($x=1080;$x>0;$x--){
  25. $dstr = '-'.($x*20).' minutes';
  26. $stime = date("Y-m-d H:i:s",strtotime($dstr));
  27. //渠道失效订单
  28. for($i=1;$i<100;$i++){
  29. $res = TBK::syncOrder($i,$stime,$_time,13,'create_time',1,2);
  30. if(empty($res)){
  31. break;
  32. }
  33. $orderResult = array_merge($orderResult, $res);
  34. }
  35. //会员失效订单
  36. for($i=1;$i<100;$i++){
  37. $res = TBK::syncOrder($i,$stime,$_time,13,'create_time',1,3);
  38. if(empty($res)){
  39. break;
  40. }
  41. $orderResult = array_merge($orderResult, $res);
  42. }
  43. //渠道三方失效订单
  44. for($i=1;$i<100;$i++){
  45. $res = TBK::syncOrder($i,$stime,$_time,13,'create_time',2,2);
  46. if(empty($res)){
  47. break;
  48. }
  49. $orderResult = array_merge($orderResult, $res);
  50. }
  51. //会员三方失效订单
  52. for($i=1;$i<100;$i++){
  53. $res = TBK::syncOrder($i,$stime,$_time,13,'create_time',2,3);
  54. if(empty($res)){
  55. break;
  56. }
  57. $orderResult = array_merge($orderResult, $res);
  58. }
  59. }
  60. # 统计
  61. $res_count = array(
  62. 'total_num' => 0,
  63. 'insert_num' => 0,
  64. 'update_num' => 0,
  65. 'fail_num' => 0,
  66. 'nshoud_update_num' => 0,
  67. );
  68. #初始化pdo
  69. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  70. foreach($orderResult as $k=>$orderDetail){
  71. $res_count['total_num']++;
  72. echo "/ ************************ order{$res_count['total_num']}-Start ************************* / \n";
  73. echo 'order_id:'.$orderDetail['trade_id'].'|| goods_id:'.$orderDetail['num_iid'].'|| orderstatus:'.$orderDetail['tk_status'].'|| order_balance_at: || update_time:'.$now;
  74. if( DETAILDEBUG == 1){
  75. echo 'orderDetail:';
  76. var_dump($orderDetail);
  77. }
  78. # 花生联盟活跃relation逻辑 //退款逻辑跳过
  79. if($orderDetail['adzone_id'] == '102465800487'){
  80. echo "\n花生订单跳过\n";
  81. continue;
  82. }
  83. $sql = "select id,tk_status from liedou_taoke_orders where trade_id = '".$orderDetail['trade_id']."' and num_iid = '".$orderDetail['num_iid']."' limit 1";
  84. $stmt = $_PDO->prepare($sql);
  85. $stmt->execute();
  86. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  87. if(!empty($result)){
  88. if($orderDetail['tk_status'] != $result['tk_status']){
  89. //更新操作
  90. $sql = "update liedou_taoke_orders set tk_status={$orderDetail['tk_status']} WHERE trade_id = '".$orderDetail['trade_id']."' and num_iid = '".$orderDetail['num_iid']."'";
  91. $stmt = $_PDO->prepare($sql);
  92. $stmt->execute();
  93. $res = $stmt->rowCount();
  94. if($res){
  95. echo "\n 更新成功 +1";
  96. $res_count['update_num']++;
  97. }else{
  98. echo "\n 更新失败 +1";
  99. $res_count['fail_num']++;
  100. }
  101. }else{
  102. echo "\n 状态未变,不做处理 +1";
  103. $res_count['nshoud_update_num']++;
  104. }
  105. }else{
  106. if(!isset($orderDetail['earning_time'])) $orderDetail['earning_time'] = '2000-00-00 00:00:00';
  107. if(!isset($orderDetail['click_time'])) $orderDetail['click_time'] = $orderDetail['create_time'];
  108. if(!isset($orderDetail['special_id'])) $orderDetail['special_id'] = 0;
  109. if(!isset($orderDetail['relation_id'])) $orderDetail['relation_id'] = 0;
  110. if(!isset($orderDetail['total_commission_fee'])) $orderDetail['total_commission_fee'] = 0;
  111. if(!isset($orderDetail['subsidy_fee'])) $orderDetail['subsidy_fee'] = 0;
  112. if(!isset($orderDetail['pay_price'])) $orderDetail['pay_price'] = 0;
  113. if(!isset($orderDetail['commission'])) $orderDetail['commission'] = 0;
  114. if(!isset($orderDetail['subsidy_type'])) $orderDetail['subsidy_type'] = 0;
  115. if(!isset($orderDetail['tk3rd_type'])) $orderDetail['tk3rd_type'] = '--';
  116. if(!isset($orderDetail['site_name'])) $orderDetail['site_name'] = '';
  117. if(!isset($orderDetail['adzone_name'])) $orderDetail['adzone_name'] = '';
  118. if(!isset($orderDetail['pub_share_pre_fee'])) $orderDetail['pub_share_pre_fee'] = 0;
  119. if(!isset($orderDetail['alipay_total_price'])) $orderDetail['alipay_total_price'] = 0;
  120. //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
  121. $res = insertOrder($orderDetail, $res_count);
  122. }
  123. echo "\n/ ** order{$res_count['total_num']}-End ** /";
  124. echo "\n\n\n";
  125. }
  126. echo "\n失效订单:";
  127. var_dump($res_count);
  128. }
  129. function insertOrder($orderDetail, &$res_count){
  130. $orderDetail['item_title'] = addslashes($orderDetail['item_title']);
  131. $orderDetail['seller_nick'] = addslashes($orderDetail['seller_nick']);
  132. $orderDetail['seller_shop_title'] = addslashes($orderDetail['seller_shop_title']);
  133. if(!isset($orderDetail['special_id'])) $orderDetail['special_id'] = null;
  134. if(!isset($orderDetail['relation_id'])) $orderDetail['relation_id'] = null;
  135. $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']."')";
  136. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  137. $stmt = $_PDO->prepare($sql);
  138. $stmt->execute();
  139. $res = $_PDO->lastinsertid();
  140. if($res){
  141. echo "\n 插入成功 +1";
  142. $res_count['insert_num']++;
  143. }else{
  144. echo "\n 插入失败 +1";
  145. $res_count['fail_num']++;
  146. }
  147. return $res;
  148. }