优惠券订单及其他脚本

sync_order_up.php 7.0KB

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. # 同步一天内的订单 3小时执行一次
  9. $_time = 1200;
  10. $now = time();
  11. sync_orders($_time, $now);
  12. /**
  13. * 同步新订单
  14. */
  15. function sync_orders($_time, $now){
  16. //同步订单脚本
  17. # 1.同步N分钟内所有订单
  18. //$now = strtotime('2019-01-21 16:54:00');
  19. //$time = date("Y-m-d H:i:s", strtotime('-27 hour'));
  20. $time = "2019-07-05 00:00:00";
  21. echo "\n\nCreate_time:".$time;
  22. $orderResult = array();
  23. for($x=0;$x<288;$x++){
  24. $dstr = $time.' '.($x*20).' minutes';
  25. $stime = date("Y-m-d H:i:s",strtotime($dstr));
  26. //二方
  27. for($i=1;$i<100;$i++){
  28. $res1 = TBK::syncOrder($i,$stime,$_time,1,'create_time',1,1); //$page,$stime,$time,$tk_status,$time_type,$order_count_type,$order_scene
  29. if(empty($res1)){
  30. break;
  31. }
  32. $orderResult = array_merge($orderResult, $res1);
  33. }
  34. //三方
  35. for($i=1;$i<100;$i++){
  36. $res3 = TBK::syncOrder($i,$stime,$_time,1,'create_time',2,1); //$page,$stime,$time,$tk_status,$time_type,$order_count_type,$order_scene
  37. if(empty($res3)){
  38. break;
  39. }
  40. $orderResult = array_merge($orderResult, $res3);
  41. }
  42. }
  43. # 统计
  44. $res_count = array(
  45. 'total_num' => 0,
  46. 'insert_num' => 0,
  47. 'fail_num' => 0,
  48. 'update_num' => 0,
  49. 'nshoud_update_num' =>0 ,
  50. );
  51. #初始化pdo
  52. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  53. foreach($orderResult as $k=>$orderDetail){
  54. $res_count['total_num']++;
  55. echo "/ ************************ order{$res_count['total_num']}-Start ************************* / \n";
  56. if(!isset($orderDetail['earning_time'])) $orderDetail['earning_time'] = '2000-00-00 00:00:00';
  57. if(!isset($orderDetail['click_time'])) $orderDetail['click_time'] = $orderDetail['create_time'];
  58. if(!isset($orderDetail['special_id'])) $orderDetail['special_id'] = 0;
  59. if(!isset($orderDetail['relation_id'])) $orderDetail['relation_id'] = 0;
  60. if(!isset($orderDetail['total_commission_fee'])) $orderDetail['total_commission_fee'] = 0;
  61. if(!isset($orderDetail['subsidy_fee'])) $orderDetail['subsidy_fee'] = 0;
  62. if(!isset($orderDetail['pay_price'])) $orderDetail['pay_price'] = 0;
  63. if(!isset($orderDetail['commission'])) $orderDetail['commission'] = 0;
  64. if(!isset($orderDetail['subsidy_type'])) $orderDetail['subsidy_type'] = 0;
  65. if(!isset($orderDetail['tk3rd_type'])) $orderDetail['tk3rd_type'] = '--';
  66. if(!isset($orderDetail['site_name'])) $orderDetail['site_name'] = '';
  67. if(!isset($orderDetail['adzone_name'])) $orderDetail['adzone_name'] = '';
  68. if(!isset($orderDetail['pub_share_pre_fee'])) $orderDetail['pub_share_pre_fee'] = 0;
  69. if(!isset($orderDetail['alipay_total_price'])) $orderDetail['alipay_total_price'] = 0;
  70. echo 'order_id:'.$orderDetail['trade_id'].'|| goods_id:'.$orderDetail['num_iid'].'|| orderstatus:'.$orderDetail['tk_status'].'|| order_balance_at:'.$orderDetail['earning_time'].'|| order_create_time:'.$orderDetail['create_time'];
  71. if( DETAILDEBUG == 1){
  72. echo 'orderDetail:';
  73. var_dump($orderDetail);
  74. }
  75. $sql = "select id,tk_status from zbds_taoke_orders where trade_id = '".$orderDetail['trade_id']."' and num_iid = '".$orderDetail['num_iid']."' limit 1";
  76. $stmt = $_PDO->prepare($sql);
  77. $stmt->execute();
  78. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  79. if(!empty($result)){
  80. echo "\n 该订单已存在,更新操作";
  81. if($orderDetail['tk_status'] != $result['tk_status']){
  82. //更新操作
  83. $sql = "update zbds_taoke_orders set tk_status={$orderDetail['tk_status']},earning_time='".$orderDetail['earning_time']."' WHERE trade_id = '".$orderDetail['trade_id']."' and num_iid = '".$orderDetail['num_iid']."'";
  84. $stmt = $_PDO->prepare($sql);
  85. $stmt->execute();
  86. $res = $stmt->rowCount();
  87. if($res){
  88. echo "\n 更新成功 +1";
  89. $res_count['update_num']++;
  90. }else{
  91. echo "\n 更新失败 +1";
  92. $res_count['fail_num']++;
  93. }
  94. }else{
  95. echo "\n 状态未变,不做处理 +1";
  96. $res_count['nshoud_update_num']++;
  97. }
  98. }else{
  99. //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
  100. $res = insertOrder($orderDetail,$res_count);
  101. }
  102. echo "\n/ ** order{$res_count['total_num']}-End ** /";
  103. }
  104. echo "\n同步订单:";
  105. var_dump($res_count);
  106. }
  107. function insertOrder($orderDetail, &$res_count){
  108. $orderDetail['item_title'] = addslashes($orderDetail['item_title']);
  109. $orderDetail['seller_nick'] = addslashes($orderDetail['seller_nick']);
  110. $orderDetail['seller_shop_title'] = addslashes($orderDetail['seller_shop_title']);
  111. $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['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']."')";
  112. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  113. $stmt = $_PDO->prepare($sql);
  114. $stmt->execute();
  115. $res = $_PDO->lastinsertid();
  116. if($res){
  117. echo "\n 插入成功 +1";
  118. $res_count['insert_num']++;
  119. }else{
  120. echo "\n 插入失败 +1";
  121. $res_count['fail_num']++;
  122. }
  123. return $res;
  124. }