优惠券订单及其他脚本

TBK.class.php 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. include_once 'alisdk/top/ResultSet.php';
  3. include_once 'alisdk/top/TopLogger.php';
  4. include_once 'alisdk/top/RequestCheckUtil.php';
  5. include_once 'alisdk/top/TopClient.php';
  6. include_once 'alisdk/top/request/TbkItemInfoGetRequest.php';
  7. include_once 'alisdk/top/request/TbkDgMaterialOptionalRequest.php';
  8. include_once 'alisdk/top/request/TbkOrderGetRequest.php';
  9. include_once 'alisdk/top/request/TbkOrderDetailsGetRequest.php';
  10. include_once 'alisdk/top/request/TbkRelationRefundRequest.php';
  11. include_once 'alisdk/top/domain/TopApiRefundRptOption.php';
  12. if(!defined('TOP_SDK_WORK_DIR')) define("TOP_SDK_WORK_DIR", "./");
  13. class TBK{
  14. //private static $appkey = '25234720';
  15. //private static $secret = '4c8f81ac36da80ba927807f783169344';
  16. private static $appkey = '25635230';
  17. private static $secret = '10664e125d07b017a354638d8e224756';
  18. private static $site_id = '328150381';
  19. private static $adzone_id = '91654600032';
  20. public function __Construct(){
  21. }
  22. public static function tbkItemInfoGet( $params ){
  23. try{
  24. $c = new TopClient;
  25. $c->appkey = self::$appkey;
  26. $c->secretKey = self::$secret;
  27. $req = new TbkItemInfoGetRequest;
  28. $req->setNumIids((string)$params['goods_id']);
  29. //$req->setFields("num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url");
  30. $req->setPlatform("2");
  31. $resp = $c->execute($req);
  32. if(!isset($resp->code)) {
  33. $goods = $resp->results->n_tbk_item[0];
  34. return $goods;
  35. }else{
  36. return false;
  37. }
  38. }
  39. catch(Exception $e){
  40. echo $e->getMessage();
  41. return false;
  42. }
  43. }
  44. public static function search($keyword){
  45. try{
  46. $c = new TopClient;
  47. $c->appkey = self::$appkey;
  48. $c->secretKey = self::$secret;
  49. $req = new TbkDgMaterialOptionalRequest;
  50. $req->setPageSize("1");
  51. $req->setPageNo("1");
  52. $req->setPlatform("2");
  53. $req->setStartPrice("0");
  54. $req->setQ($keyword);
  55. $req->setMaterialId('20564');
  56. $req->setAdzoneId(self::$adzone_id);
  57. $resp = $c->execute($req);
  58. if(!isset($resp->code)) {
  59. $data = $resp->result_list->map_data;
  60. return $data[0];
  61. }
  62. return false;
  63. }
  64. catch(Exception $e){
  65. return false;
  66. }
  67. }
  68. public static function syncOrder($page,$stime,$time=120,$tk_status=1,$time_type='create_time',$order_count_type=1,$order_scene=1){
  69. try{
  70. $c = new TopClient;
  71. $c->appkey = self::$appkey;
  72. $c->secretKey = self::$secret;
  73. $req = new TbkOrderGetRequest;
  74. $req->setFields("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");
  75. $req->setStartTime($stime); //开始时间
  76. if($tk_status != 13) $req->setSpan($time);//订单查询时间范围,最小60,最大1200,默认60,仅当查询常规订单,及三方订单时需要设置此参数
  77. $req->setPageNo($page);
  78. $req->setPageSize("100");
  79. $req->setTkStatus($tk_status); //订单状态,1: 全部订单,3:订单结算,12:订单付款, 13:订单失效,14:订单成功;
  80. $req->setOrderQueryType($time_type); //订单查询类型,创建时间“create_time”,或结算时间“settle_time”
  81. $req->setOrderScene($order_scene); //1常规订单包含淘宝客所有的订单数据,含渠道,及会员运营订单,但不包含3方分成,及维权订单
  82. $req->setOrderCountType($order_count_type); //订单数据统计类型,1: 2方订单,2: 3方订单,如果不设置,或者设置为1,表示2方订单
  83. $resp = $c->execute($req);
  84. if(isset($resp->results->n_tbk_order) && !empty($resp->results->n_tbk_order)) {
  85. $data = $resp->results;
  86. $data = json_decode(json_encode($data),true);
  87. if(isset($data['n_tbk_order']['trade_id'])){
  88. $data['n_tbk_order'] = [0=>$data['n_tbk_order']];
  89. }
  90. return $data['n_tbk_order'];
  91. }
  92. return false;
  93. }
  94. catch(Exception $e){
  95. return false;
  96. }
  97. }
  98. /**
  99. * 新订单同步, +付款时间拉取
  100. */
  101. public static function syncOrderNew($page, $stime, $etime, $time_type=2, $tk_status, $order_scene=1, $position_index=''){
  102. try{
  103. $c = new TopClient;
  104. $c->appkey = self::$appkey;
  105. $c->secretKey = self::$secret;
  106. $req = new TbkOrderDetailsGetRequest;
  107. $req->setQueryType($time_type); //1:按照订单淘客创建时间查询,2:按照订单淘客付款时间查询,3:按照订单淘客结算时间查询
  108. if($position_index) $req->setPositionIndex($position_index);
  109. $req->setPageSize("100");
  110. //$req->setMemberType("2"); //2:二方,3:三方,不传,表示所有角色
  111. if($tk_status>0) $req->setTkStatus($tk_status); //12-付款,13-关闭,14-确认收货,15-结算成功;不传,表示所有状态
  112. $req->setEndTime($etime);
  113. $req->setStartTime($stime);
  114. $req->setJumpType("1"); //-1: 向前翻页,1:向后翻页
  115. $req->setPageNo($page);
  116. $req->setOrderScene($order_scene);//1:常规订单,2:渠道订单,3:会员运营订单,默认为1
  117. $resp = $c->execute($req);
  118. $result = array();
  119. if(isset($resp->data->results->publisher_order_dto)){
  120. $data = json_decode(json_encode($resp->data), true);
  121. $result['position_index'] = $data['position_index'];
  122. if(isset($data['results']['publisher_order_dto']['item_id'])){
  123. $result['data'][0] = $data['results']['publisher_order_dto'];
  124. }else{
  125. $result['data'] = $data['results']['publisher_order_dto'];
  126. }
  127. }else{
  128. //echo "\n没数据了~";
  129. }
  130. return $result;
  131. }
  132. catch(Exception $e){
  133. return false;
  134. }
  135. }
  136. public static function syncVqOrder($page, $start_time, $order_count_type=1, $biz_type=1){
  137. try{
  138. $c = new TopClient;
  139. $c->appkey = self::$appkey;
  140. $c->secretKey = self::$secret;
  141. $req = new TbkRelationRefundRequest;
  142. $search_option = new TopApiRefundRptOption;
  143. $search_option->page_size="100";
  144. $search_option->search_type="3"; //1-维权发起时间,2-订单结算时间(正向订单),3-维权完成时间,4-订单创建时间
  145. $search_option->refund_type=$order_count_type; //1 表示2方,2表示3方
  146. $search_option->start_time=$start_time;
  147. $search_option->page_no=$page;
  148. $search_option->biz_type=$biz_type; //1代表渠道关系id,2代表会员关系id
  149. $req->setSearchOption(json_encode($search_option));
  150. $resp = $c->execute($req);
  151. if(isset($resp->result->data->results) && !empty($resp->result->data->results)){
  152. $data = $resp->result->data->results;
  153. $data = json_decode(json_encode($data),true);
  154. return $data['result'];
  155. }else{
  156. return false;
  157. }
  158. }
  159. catch(Exception $e){
  160. return false;
  161. }
  162. }
  163. }