<?php
|
namespace app\api\logic\taoke\device;
|
|
use app\api\logic\taoke\Parser;
|
|
|
|
class Zhetaoke extends Parser
|
{
|
protected $app_key,$config;
|
|
protected $baseUrl = '';
|
|
const request_url = [
|
'zhuanlian_url' => "https://api.zhetaoke.com:10001/api/open_gaoyongzhuanlian_tkl.ashx",
|
'synchronize_order_url' => "https://api.zhetaoke.com:10001/api/open_dingdanchaxun2.ashx",
|
'day_synchronize_order_url' => 'https://api.zhetaoke.com:10001/api/open_dingdanchaxun2_piliang.ashx'
|
];
|
|
const shop_type = ["0"=>"淘宝","1"=>"天猫","3"=>"特价版"];
|
|
|
|
public function __construct()
|
{
|
parent::__construct();
|
|
$this->config = config('site.zhetaoke');
|
|
$this->app_key = $this->config['appkey'];
|
|
if(empty($this->app_key)) return fault('配置信息错误');
|
}
|
|
|
/**
|
* 同步订单接口 http://www.zhetaoke.com/user/open/open_dingdanchaxun2.aspx
|
*
|
* @param [type] $query_type 查询时间类型,1:按照订单淘客创建时间查询,2:按照订单淘客付款时间查询,3:按照订单淘客结算时间查询,4:按照订单更新时间查询;
|
* @param integer $order_scene 场景订单场景类型,1:常规订单,2:渠道订单,3:会员运营订单,默认为1
|
* @param string $position_index 位点,除第一页之外,都需要传递;前端原样返回。注意:从第二页开始,位点必须传递前一页返回的值,否则翻页无效。
|
* @param integer $page_no 第几页,默认1,1~100
|
* @param integer $page_size 页大小,默认20,1~100
|
* @param string $start_time 订单查询开始时间
|
* @param string $end_time 订单查询结束时间
|
* @return void
|
*/
|
public function synchronizeOrder($query_type,$start_time,$end_time,$order_scene = "2",$position_index="",$page_no = 1,$page_size=100,$step = 0,$tk_status="")
|
{
|
$send_data = [
|
'appkey' => $this->app_key,
|
'sid' => $this->config['sid'],
|
'query_type' => $query_type,
|
'position_index' => $position_index,
|
'page_size' => $page_size,
|
'page_no' => $page_no,
|
'order_scene' => $order_scene,
|
'start_time' => $start_time,
|
'end_time' => $end_time,
|
'tk_status' => $tk_status
|
];
|
$result = send_get(self::request_url['synchronize_order_url'],$send_data);
|
if(empty($result) || empty($result['url'])){//做处理
|
if($step == 2) return ['status'=>false,'info'=>$start_time.'--'.$end_time.'返回链接错误','position_index'=>'','list'=>[]];
|
$step++;
|
return $this->synchronizeOrder($query_type,$start_time,$end_time,$order_scene = 2,$position_index,$page_no,$page_size=100,$step);
|
}
|
$search_url = $result['url'];
|
$search_result = send_get($search_url);
|
if(isset($search_result['error_response'])){
|
if($step == 2) return ['status'=>false,'info'=>'接口请求错误','position_index'=>'','list'=>[]];
|
$step++;
|
return $this->synchronizeOrder($query_type,$start_time,$end_time,$order_scene = 2,$position_index,$page_no,$page_size=100,$step);
|
}
|
if(isset($search_result['tbk_sc_order_details_get_response'])){
|
$data = $search_result['tbk_sc_order_details_get_response'];
|
$order_list = isset($data['data']['results']['publisher_order_dto']) ? $data['data']['results']['publisher_order_dto'] : [];
|
if(empty($order_list))return ['status'=>true,'info'=>'请求成功','has_next'=>false,'total'=>0,'position_index'=>'','list'=>[]];
|
return ['status'=>true,'info'=>'请求成功','has_next'=>$data['data']['has_next'],'position_index'=>$data['data']['position_index'],'list'=>$order_list,'total'=>count($order_list)];
|
}else{
|
return ['status'=>false,'info'=>'接口请求失败','position_index'=>''];
|
}
|
}
|
|
|
/**
|
* 高佣专链 https://www.zhetaoke.com/user/open/open_gaoyongzhuanlian_tkl.aspx
|
*
|
*/
|
public function zhuanlian($goodsUrl,$is_turn=false,$relation_id="")
|
{
|
$send_data = [
|
'appkey' => $this->app_key,
|
'pid' => MOBILE_INFO == "IOS" ? config('site.taobao_pid')['ios_pid'] : config('site.taobao_pid')['android_pid'],
|
'sid' => $this->config['sid'],
|
'tkl' => urlencode($goodsUrl),
|
'relation_id' => $relation_id,
|
'signurl' => 5
|
];
|
$result = send_get(self::request_url['zhuanlian_url'],$send_data);
|
if(isset($result['error_response']) && !empty($result['error_response'])) return [];
|
if(empty($result) || $result['status'] != 200 || !isset($result['status']))return [];
|
$info = $result['content'][0];
|
if($is_turn){
|
$return_info = $info['title']."\n"
|
."原价:¥".$info['size']." 券后价:¥".$info['quanhou_jiage']."\n"
|
."0复.制文案.打.开桃.宝:".$info['tkl'];
|
return $return_info;
|
}else{
|
$goods = self::initGoods($info);
|
return $goods;
|
}
|
|
}
|
|
|
|
|
/**
|
* 格式化商品信息
|
*
|
* @param [type] $goods
|
* @return void
|
*/
|
private static function initGoods($goods)
|
{
|
if(empty($goods)) return [];
|
$init_goods = self::goodsField();
|
$init_goods['id'] = isset($goods['item_id']) ? $goods['item_id'] : '';
|
$init_goods['goodsId'] = isset($goods['tao_id']) ? $goods['tao_id'] : ''; //商品id
|
$init_goods['itemLink'] = isset($goods['taobao_url']) ? $goods['taobao_url'] : ''; //商品链接
|
$init_goods['title'] = isset($goods['tao_title']) ? $goods['tao_title'] : ''; //商品标题
|
$init_goods["dtitle"] = isset($goods['title']) ? $goods['title'] : ''; //短标题
|
$init_goods["actualPrice"] = isset($goods['quanhou_jiage']) ? $goods['quanhou_jiage'] : ''; //券后价
|
$init_goods["originalPrice"] = isset($goods['size']) ? $goods['size'] : ''; //商品原价
|
$init_goods["sellerId"] = isset($goods['seller_id']) ? $goods['seller_id'] : ''; //店铺Id
|
$init_goods["shopName"] = isset($goods['shop_title']) ? $goods['shop_title'] : ''; //店铺名称
|
$init_goods["couponPrice"] = isset($goods['coupon_info_money']) ? $goods['coupon_info_money'] : ''; //优惠券金额
|
$init_goods["monthSales"] = isset($goods['volume']) ? format_number($goods['volume']) : 0; //30天销量
|
$init_goods["mainPic"] = isset($goods['pict_url']) ? $goods['pict_url'] : ''; //商品主图
|
$init_goods["video"] = isset($goods['zhibo_url']) ? $goods['zhibo_url'] : ''; //商品视频
|
$init_goods['couponLink'] = isset($goods['coupon_click_url']) ? $goods['coupon_click_url'] : ''; //优惠券链接
|
$init_goods['couponEndTime'] = isset($goods['coupon_end_time']) && !empty($goods['coupon_end_time']) ? $goods['coupon_end_time'] : ''; //优惠券结束时间
|
$init_goods['couponStartTime'] = isset($goods['coupon_start_time']) && !empty($goods['coupon_start_time']) ? $goods['coupon_start_time'] : ''; //优惠券开始时间
|
$init_goods['shopType'] = isset(self::shop_type[$goods['user_type']]) ? self::shop_type[$goods['user_type']] : "未知"; //店铺类型
|
$init_goods['sourceType'] = "tb";
|
if(isset($goods['user_type']) && $goods['user_type'] == 1)$init_goods['sourceType'] = "tm";
|
if(isset($goods['shopType']) && $goods['user_type'] == 1)$init_goods['sourceType'] = "tm";
|
$init_goods['desc'] = isset($goods['item_description']) ? $goods['item_description'] : ''; //推广文案
|
$init_goods['imgs'] =[$goods['pict_url']];
|
$init_goods['labelImg'] = self::initSourse($init_goods['sourceType']);
|
$init_goods['isCollect'] = self::isCollect($init_goods);
|
if(empty($init_goods['detailPics']))$init_goods['detailPics'] = $init_goods['mainPic'];
|
$init_goods['fanli'] = self::rebate($init_goods["actualPrice"],$goods['tkrate3']/100);
|
$init_goods['topFanli'] = self::rebate($init_goods['actualPrice'],$goods['tkrate3']/100,self::$topFanliRate);
|
return $init_goods;
|
}
|
|
|
}
|