优惠券订单及其他脚本

sync_order_vq.php 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. require_once 'DB_PDO.class.php';
  3. require_once 'TBK.class.php';
  4. require_once 'confv2.class.php';
  5. require_once 'PHPExcel-1.8/Classes/PHPExcel.php';
  6. require_once 'PHPExcel-1.8/Classes/PHPExcel/IOFactory.php';
  7. require_once 'PHPExcel-1.8/Classes/PHPExcel/Reader/Excel5.php';
  8. # 定义下载订单时间段
  9. //define("END_TIME", date('Y-m-d%20H:i:s', strtotime('2019-01-15 00:00:00')) );
  10. //define("START_TIME", date('Y-m-d%20H:i:s', strtotime('2018-12-01 00:00:00')) );
  11. define("DETAILDEBUG", 0);//打印流程详细信息,如有需要,设为1
  12. //define("LIMIT_NUM", 0);//限制导入条数,0不限制,方便测试,上线设为0
  13. /**
  14. * 导入及更新 order_rebate 维权订单数据
  15. */
  16. #设置时区
  17. date_default_timezone_set('PRC');
  18. set_time_limit(0);
  19. ini_set('memory_limit','1024M');
  20. error_reporting(1);
  21. function readDataFromDb(){
  22. # 遍历订单
  23. # 统计
  24. $res_count = array(
  25. 'total_num' => 0,
  26. 'generalupdate_num' => 0,
  27. 'fail_update_num' => 0,
  28. );
  29. #初始化pdo
  30. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  31. $time = date("Y-m-d H:i:s", time()-600);
  32. $sql = "SELECT * FROM taoke_refunds where update_time >= '{$time}' ";
  33. echo "\n\n".$sql."\n";
  34. $stmt = $_PDO->prepare($sql);
  35. $stmt->execute();
  36. $vqOrders = $stmt->fetchAll(PDO::FETCH_ASSOC);
  37. $orderList = array();
  38. //循环读取excel文件,读取一条,插入一条
  39. foreach($vqOrders as $k=>$orderDetail){
  40. if($orderDetail['earningTime']<'2018-12-01') continue; //只处理12月之后结算的
  41. $res_count['total_num']++;
  42. echo "/ ************************ order{$res_count['total_num']}-Start ************************* / \n";
  43. if( DETAILDEBUG == 1){
  44. echo 'orderDetail:';
  45. var_dump($orderDetail);
  46. }
  47. //0淘宝订单编号 1淘宝子订单编号 2商品名称 3维权退款金额 4应返还金额 5维权状态 6订单结算时间 7维权创建时间 8维权完成时间
  48. $order_id=$orderDetail['tbTradeParentId'];
  49. if($orderDetail['showRefundStatus'] == '维权创建' || $orderDetail['showRefundStatus'] == '等待处理' ){
  50. $maintain_power = 1;
  51. }elseif($orderDetail['showRefundStatus'] == '维权失败'){
  52. $maintain_power = 2;
  53. }elseif($orderDetail['showRefundStatus'] == '维权成功'){
  54. $maintain_power = 3;
  55. }
  56. $power_create_at = $orderDetail['refundCreateTime'];
  57. $power_end_at = isset($orderDetail['refundFinishTime']) ? $orderDetail['refundFinishTime'] : null;
  58. echo 'order_id:'.$order_id.'|| goods_name:'.$orderDetail['tbAuctionTitle'].'|| maintain_power:'.$maintain_power.'|| power_create_at:'.$power_create_at;
  59. echo "\n";
  60. try{
  61. $_PDO->beginTransaction();
  62. //更新order_rebate
  63. $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";
  64. 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";
  65. $stmt = $_PDO->prepare($sql);
  66. $stmt->execute(array(':maintain_power'=>$maintain_power,':power_create_at'=>$power_create_at,':power_end_at'=>$power_end_at,':order_id'=>$order_id));
  67. $res = $stmt->rowCount();
  68. echo "更新order_rebate:".$res."\n";
  69. //更新order_rebate_profit
  70. $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";
  71. 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";
  72. $stmt = $_PDO->prepare($sql);
  73. $stmt->execute(array(':maintain_power'=>$maintain_power,':power_create_at'=>$power_create_at,':power_end_at'=>$power_end_at,':order_id'=>$order_id));
  74. $res = $stmt->rowCount();
  75. echo "更新order_rebate_profit:".$res."\n";
  76. if($res){
  77. $res_count['generalupdate_num']++;
  78. }else{
  79. $res_count['fail_update_num']++;
  80. }
  81. $_PDO->commit();
  82. }catch(Exception $e){
  83. echo 'err_msg'.$e->getMessage()."\n";
  84. $_PDO->rollback();
  85. }
  86. echo "/ ***order{$res_count['total_num']}-End *** / \n";
  87. }
  88. echo "<pre>";
  89. print_r($res_count);
  90. }
  91. # curl调用接口push
  92. function curl_post($url, $params){
  93. $ch = curl_init();
  94. curl_setopt($ch, CURLOPT_URL, $url);
  95. curl_setopt($ch, CURLOPT_HEADER, 0);
  96. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  97. curl_setopt($ch, CURLOPT_POST, 1);
  98. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  99. $response = curl_exec($ch);
  100. curl_close($ch);
  101. return $response;
  102. }
  103. # 下载excel订单文件
  104. function down_excel(){
  105. $str_cookie = 'cna=gGnDEwQLQAACATqEyYplpj5I; account-path-guide-s1=true; 209580064_yxjh-filter-1=true; undefined_yxjh-filter-1=true; t=8c549c3cedcac7891a2c3c7f36ca91f4; l=bBEoP2SHvN8ixwV1BOfgcuIJcTbOWBOjCsPzw4TZ1ICPOWW91RJ1WZgLeCtpC3GVa6GHR3Wc5ILBBDYm8yUIg; cookie2=15a20b1fd27c84e51094f4c723192cf1; v=0; _tb_token_=117bd3eafd3e; alimamapwag=TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzY5LjAuMzQ5Ny4xMDAgU2FmYXJpLzUzNy4zNg%3D%3D; cookie32=2d2dbd51714bd91fa4e604f2e1050dd6; alimamapw=FnABFCAlFCZcQ3dVHXF2FncCFnF5FCAlFCFWQ3YjHXBxFnAEFnF7FCEgFCFXQ3BRHXFxFnd3FnEB%0AFCIhFCYmQ3YkMQICVwcEUgQPAQFWBlxWBVJRWwEAAABQAgQJV1dSVQAG; cookie31=OTk1MDYxNzMsJUU0JUI4JThBJUU5JUE1JUI2JUU1JUI4JTgyJUU1JTkwJTg4JUU0JUI4JTgwJUU3JUE3JTkxJUU2JThBJTgwJUU2JTlDJTg5JUU5JTk5JTkwJUU1JTg1JUFDJUU1JThGJUI4LGppYW5nbmFuQGZhbnRvdXRpYW8uY29tLFRC; login=UtASsssmOIJ0bQ%3D%3D; JSESSIONID=018F7419C637C160FB8FAF00FFF5EA82; apush848645ac0bf07b717f88c18a7e296d1e=%7B%22ts%22%3A1547610379990%2C%22parentId%22%3A1547610320224%7D; isg=BFJSBj1kWtMR26EtN5ueyw4Foxj0y0I3Zk3l-xyrpYXwL_MpBPOPDNoJm8u2X86V';
  106. $nowTime = END_TIME;
  107. $pastTime = START_TIME;
  108. //$url = "https://pub.alimama.com/report/getTbkPaymentDetails.json?DownloadID=DOWNLOAD_REPORT_INCOME_NEW&queryType=1&payStatus=&startTime=".$pastTime."&endTime=".$nowTime;
  109. $url = "https://pub.alimama.com/report/getNewTbkRefundPaymentDetails.json?spm=a219t.7664554.1998457203.54.1ef735d9aJK7cQ&refundType=1&searchType=1&DownloadID=DOWNLOAD_EXPORT_CPSPAYMENT_REFUND_OVERVIEW&startTime=".$pastTime."&endTime=".$nowTime;;
  110. echo $url."\n";
  111. $ch = curl_init($url);
  112. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  113. curl_setopt($ch, CURLOPT_COOKIE, $str_cookie); //使用上面获取的cookies
  114. $response = curl_exec($ch);
  115. curl_close($ch);
  116. if( $response ){
  117. $file = fopen("./order_excel_vq.csv", "w+");
  118. $a = fputs($file, $response);
  119. fclose($file);
  120. return './order_excel_vq.csv';
  121. }
  122. else{
  123. return false;
  124. }
  125. }
  126. readDataFromDb();