zhaojs
2023-07-06 1a8d87ee2e142203e16c90f050c7b05e1315a8cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?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;
    }
    
    
}