<?php
|
namespace app\api\logic\taoke\device;
|
|
use app\api\logic\taoke\Parser;
|
use think\facade\Cache;
|
|
class Jutuike extends Parser
|
{
|
protected $appkey,$config,$pub_id;
|
protected $appSecret = '';
|
protected $timeout = 10;
|
|
|
const request_url = [
|
'chain_url' => "http://api.jutuike.com/union/act",
|
'province_url' => "http://api.act.jutuike.com/mtfx/province_all",
|
'province_city_url' => "http://api.act.jutuike.com/mtfx/province_cities",
|
'city_cate_url' => "http://api.act.jutuike.com/mtfx/city_categories",
|
'search_deals_url' => "http://api.act.jutuike.com/mtfx/search_deals",
|
'meituan_url' => 'http://api.jutuike.com/Meituan/act',
|
'ele_act_url' => 'http://api.jutuike.com/Ele/act',
|
'seckill_showinfo_url' => 'http://api.act.jutuike.com/mtfx/seckill_showinfo',
|
'seckill_list_url' => 'http://api.act.jutuike.com/mtfx/seckill_list',
|
'union_order_url' => 'http://api.jutuike.com/union/orders',
|
'ele_store_url' => 'http://api.jutuike.com/ele/store_list'
|
];
|
|
|
public function __construct()
|
{
|
parent::__construct();
|
|
$this->config = config('site.jutuike');
|
|
$this->appkey = $this->config['apikey'];
|
|
$this->pub_id = $this->config['pub_id'];
|
|
if(empty($this->appkey)) return fault('配置信息错误');
|
}
|
|
|
/**
|
* 饿了么单店推广店铺列表 https://www.jutuike.com/doc/113
|
*
|
* @return void
|
*/
|
public function getEleStoreList($longitude,$latitude,$sid,$pageSize,$session_id = "")
|
{
|
$send_data = [
|
'apikey' => $this->appkey,
|
'longitude' => $longitude,
|
'latitude' => $latitude,
|
'pageSize' => $pageSize,
|
'sid' => $sid,
|
'session_id' => $session_id,
|
];
|
$result = send_get(self::request_url['ele_store_url'],$send_data);
|
if(empty($result) || $result['code'] == 0) fault('数据获取失败');
|
if(empty($result['data']['records'])) return ['list'=>[],'session_id'=>""];
|
$list = $result['data']['records']['store_promotion_dto'];
|
|
foreach($list as $key => &$value){
|
$value['commission_rate'] = bcmul($value['commission_rate'],self::$userRate*100,2)."%";
|
if(isset($list[$key]['commission'])) unset($list[$key]['commission']);
|
}
|
return ['list'=>$list,'session_id'=>$result['data']['session_id']];
|
}
|
|
|
/**
|
* 订单数据接口 https://www.jutuike.com/doc/37
|
*
|
* @param [type] $query_type 1: 按支付时间 2:按更新时间 3:创建时间 ,默认:3
|
* @param [type] $start_time 开始时间
|
* @param [type] $end_time 结束时间
|
* @param [type] $page
|
* @param integer $pageSize
|
* @return void
|
*/
|
public function unionOrder($query_type,$start_time,$end_time,$page,$pageSize=50)
|
{
|
$send_data = [
|
'apikey' => $this->appkey,
|
'pub_id' => $this->pub_id,
|
'query_type' => $query_type,
|
'start_time' => $start_time,
|
'end_time' => $end_time,
|
'page' => $page,
|
'pageSize' => $pageSize
|
|
];
|
$result = send_get(self::request_url['union_order_url'],$send_data);
|
if(empty($result) || $result['code'] == 0)return ['status'=>true,'info'=>'数据为空','list'=>[],'total' => 0,'hasMore' => false];
|
if(isset($result['data']['data']) && empty($result['data']['data']))return ['status'=>true,'info'=>'数据为空','list'=>[],'total' => 0,'hasMore' => false];
|
return ['status'=>true,'info'=>'接口请求成功','list'=>$result['data']['data'],'total' => $result['data']['total'],'hasMore' => $result['data']['total'] == $pageSize ? true : false];
|
|
}
|
|
/**
|
* 秒杀团单列表信息 https://www.jutuike.com/doc/47
|
*
|
* @return void
|
*/
|
public function seckillList($cityId,$sid,$showId,$lat,$lng,$page = 1)
|
{
|
$send_data = [
|
'apikey' => $this->appkey,
|
'pub_id' => $this->pub_id,
|
'cityId' => $cityId,
|
'sid' => $sid,
|
'showId' => $showId,
|
'phone' => '15000000000',
|
'os' => MOBILE_INFO == 'IOS' ? 2 : 1,
|
'lat' => $lat,
|
'lng' => $lng,
|
'page' => $page
|
|
];
|
$result = send_get(self::request_url['seckill_list_url'],$send_data);
|
if(empty($result) || $result['code'] == 0) fault('数据获取失败');
|
if(empty($result['data'])) return [];
|
return $result['data']['poiList'];
|
}
|
|
|
|
/**
|
* 秒杀场次信息接口 https://www.jutuike.com/doc/46
|
*
|
* @return void
|
*/
|
public function getSeckillShowinfo($cityId)
|
{
|
$send_data = [
|
'apikey' => $this->appkey,
|
'pub_id' => $this->pub_id,
|
'cityId' => $cityId
|
];
|
$result = send_get(self::request_url['seckill_showinfo_url'],$send_data);
|
if(empty($result) || $result['code'] == 0) fault('数据获取失败');
|
if(empty($result['data'])) return [];
|
$info = $result['data'];
|
foreach($info as &$item){
|
$item['endTimeStr'] = date('H:i',$item['endTime'] / 1000);
|
$item['startTimeStr'] = date('H:i',$item['startTime'] / 1000);
|
$item['tomorrow'] = date('Y-m-d',$item['startTime'] / 1000) == date('Y-m-d') ? 0 : 1;
|
}
|
return $info;
|
}
|
|
|
|
|
/**
|
* 统一活动转链 https://www.jutuike.com/doc/48
|
*
|
* @return void
|
*/
|
public function unionAact($act_id,$sid)
|
{
|
$send_data = [
|
'apikey' => $this->appkey,
|
'sid' => $sid,
|
'act_id' => $act_id,
|
'relation_flag_name' => 'xgzappxgz'
|
];
|
$result = send_get(self::request_url['chain_url'],$send_data);
|
if(empty($result) || $result['code'] == 0) fault('数据获取失败');
|
return $result['data'];
|
}
|
|
|
|
/**
|
* 美团联盟外卖/闪购/酒店/优选红包活动转链接口
|
*/
|
public function meituanAct($type,$sid)
|
{
|
$send_data = [
|
'apikey' => $this->appkey,
|
'sid' => $sid,
|
'type' => $type,
|
'relation_flag_name' => 'xgzappxgz'
|
];
|
$result = send_get(self::request_url['meituan_url'],$send_data);
|
if(empty($result) || $result['code'] == 0) fault('数据获取失败');
|
return self::initUnion($result['data']);
|
}
|
|
/**
|
* 饿了么外卖/生鲜红包活动转链接口
|
*
|
* @param [type] $type 红包类型 3-饿了么外卖微信活动(不支持推广链接,只支持小程序推广) 4-饿了么外卖活动 5-饿了么生鲜
|
* @param [type] $sid
|
* @return void
|
*/
|
public function eleAct($type,$sid)
|
{
|
$send_data = [
|
'apikey' => $this->appkey,
|
'sid' => $sid,
|
'type' => $type,
|
'relation_flag_name' => 'xgzappxgz'
|
];
|
$result = send_get(self::request_url['ele_act_url'],$send_data);
|
if(empty($result) || $result['code'] == 0) fault('数据获取失败');
|
return self::initUnion($result['data']);
|
}
|
|
|
/**
|
* 获取省份信息 https://www.jutuike.com/doc/27
|
*
|
* @return void
|
*/
|
public function getProvince()
|
{
|
$send_data = [
|
'apikey' => $this->appkey,
|
'pub_id' => $this->pub_id
|
];
|
$result = send_get(self::request_url['province_url'],$send_data);
|
if(empty($result) || $result['code'] == 0) fault('数据获取失败');
|
if(empty($result['data'])) return [];
|
return $result['data'];
|
}
|
|
|
/**
|
* 获取城市信息 https://www.jutuike.com/doc/28
|
*
|
* @return void
|
*/
|
public function getCity($province_id)
|
{
|
$send_data = [
|
'apikey' => $this->appkey,
|
'pub_id' => $this->pub_id,
|
'provinceId' => $province_id
|
];
|
$result = send_get(self::request_url['province_city_url'],$send_data);
|
if(empty($result) || $result['code'] == 0) fault('数据获取失败');
|
if(empty($result['data'])) return [];
|
return $result['data'];
|
}
|
|
|
/**
|
* 获取某个城市的一级类目包含的二级类目信息
|
*
|
* @param [type] $cityId
|
* @return void
|
*/
|
public function getCityCategories($cityId,$cat0Id="")
|
{
|
$send_data = [
|
'apikey' => $this->appkey,
|
'pub_id' => $this->pub_id,
|
'cityId' => $cityId,
|
'cat0Id' => $cat0Id
|
];
|
$result = send_get(self::request_url['city_cate_url'],$send_data);
|
if(empty($result) || $result['code'] == 0) fault('数据获取失败');
|
if(empty($result['data'])) return [];
|
$arr = [];
|
foreach($result['data']['categories'] as $key => $value){
|
$arr[] = [
|
'key' => (string)$key,
|
'value' => $value
|
];
|
}
|
return $arr;
|
}
|
|
|
/**
|
* 团单查询接口 https://www.jutuike.com/doc/31
|
*
|
* @param [type] $cateId 一级类目
|
* @param [type] $cateSecIds 二级类目
|
* @param [type] $lng 经度
|
* @param [type] $lat 纬度
|
* @param [type] $cityId 城市ID
|
* @param [type] $sid 渠道方用户唯一标识
|
* @param [type] $keywords 关键词
|
* @return void
|
*/
|
public function searchDeals($del_repeat,$cateId,$cateSecIds,$lng,$lat,$cityId,$sid,$sortType,$keywords,$page,$pageSize,$cat1Ids,$radii,$shopId)
|
{
|
$send_data = [
|
'apikey' => $this->appkey,
|
'pub_id' => $this->pub_id,
|
'cityId' => $cityId,
|
'cat0Id' => $cateId,
|
'cateSecIds' => $cateSecIds,
|
'del_repeat' => $del_repeat,
|
'sortType' => $sortType,
|
'cat1Ids' => $cat1Ids,
|
'keyWords' => $keywords,
|
'page' => $page,
|
'size' =>$pageSize,
|
'lng' => $lng,
|
'lat' => $lat,
|
'sid' => $sid,
|
'radii' => $radii,
|
'shopIds' => $shopId
|
];
|
$result = send_get(self::request_url['search_deals_url'],$send_data);
|
if(empty($result) || $result['code'] == 0){
|
fault('数据获取失败');
|
}
|
if(empty($result['data'])) return [];
|
$list = $result['data']['records'];
|
if(empty($list)) return [];
|
return $list;
|
}
|
|
|
/**
|
* 团单详情
|
*
|
* @param [type] $cateId
|
* @param [type] $lng
|
* @param [type] $lat
|
* @param [type] $sid
|
* @param [type] $shopIds
|
* @return void
|
*/
|
public function dealsDetail($list,$cateId,$cateSecIds,$lng,$lat,$cityId,$common_relation_id,$sortType,$keywords,$page,$pageSize,$cat1Ids,$radii){
|
if(empty($list)) return [];
|
foreach($list as &$item){
|
$sub_list = $this->searchDeals(1,$cateId,$cateSecIds,$lng,$lat,$cityId,$common_relation_id,'','','','','','',$item['shopInfo']['shopId']);
|
if(!empty($sub_list)){
|
foreach($sub_list as $key => $value){
|
$item['subset'][] = [
|
'couponInfo' => $value['couponInfo'],
|
'dealBaseInfo' => $value['dealBaseInfo']
|
];
|
}
|
}
|
}
|
return $list;
|
}
|
|
|
|
|
|
|
|
/**
|
* 格式化转链
|
* @return void
|
*/
|
private static function initUnion($data)
|
{
|
if(empty($data)) return [];
|
$init_data = self::unionField();
|
$init_data['h5'] = isset($data['h5']) ? $data['h5'] : '';
|
$init_data['we_app_info'] = isset($data['we_app_info']) ? $data['we_app_info'] : [];
|
$init_data['act_name'] = isset($data['act_name']) ? $data['act_name'] : "";
|
$init_data['long_h5'] = isset($data['long_h5']) ? $data['long_h5'] : "";
|
$init_data['deeplink'] = isset($data['deeplink']) ? $data['deeplink'] :"";
|
if(!empty($init_data['we_app_info']) && !isset($init_data['we_app_info']['miniCode'])) $init_data['we_app_info']['miniCode'] = '';
|
return $init_data;
|
}
|
|
|
}
|