CartData.php
21.3 KB
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
<?php
namespace LibModels\Web\Home;
use Api\Sign;
use Api\Yohobuy;
use LibModels\Web\Product\SearchData;
/**
* 购物车的数据模型
*
* @name CartData
* @package LibModels/Web/Home
* @copyright yoho.inc
* @version 1.0 (2016-02-17 14:12:32)
* @author fei.hong <fei.hong@yoho.cn>
*/
class CartData
{
/**
* 加入购物车接口
*
* @param int $productSku 商品SKU
* @param int $buyNumber 购买数量
* @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品
* @param int $isEdit 是否是编辑商品SKU,0表示不是编辑
* @param null|int $promotionId 促销id,默认null(加价购有关)
* @param null|int $uid 用户UID,可以不传
* @param string $shoppingKey 未登录用户唯一识别码,可以不传
* @return array 加入购物车接口返回的数据
*/
public static function addToCart($productSku, $buyNumber, $goodsType, $isEdit = 0, $promotionId = null, $uid = null, $shoppingKey = null)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.add';
$param['product_sku'] = $productSku;
$param['buy_number'] = intval($buyNumber);
$param['goods_type'] = $goodsType;
$param['edit_product_sku'] = $isEdit;
$param['selected'] = 'Y';
$param['promotion_id'] = $promotionId;
if (!empty($uid)) {
$param['uid'] = $uid;
}
if (!empty($shoppingKey)) {
$param['shopping_key'] = $shoppingKey;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 购物车商品选择与取消接口
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param string $shoppingKey 未登录用户唯一识别码
* @param bool $hasPromotion 是否有促销ID
* @return array 购物车接口返回的数据
*/
public static function selectGoods($uid, $sku, $shoppingKey, $hasPromotion = false)
{
$param = Yohobuy::param();
$param['method'] = $hasPromotion ? 'app.Shopping.selectedAndCart' : 'app.Shopping.selected';
$param['product_sku_list'] = $sku;
if (!empty($uid)) {
$param['uid'] = $uid;
}
if (!empty($shoppingKey)) {
$param['shopping_key'] = $shoppingKey;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 购物车数据
*
* @param int $uid 用户ID
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 购物车接口返回的数据
*/
public static function cartData($uid, $shoppingKey)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.cart';
if (!empty($uid)) {
$param['uid'] = $uid;
}
if (!empty($shoppingKey)) {
$param['shopping_key'] = $shoppingKey;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 移出购物车
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param string $shoppingKey 未登录用户唯一识别码
* @param bool $hasPromotion 是否有促销ID
* @return array 接口返回的数据
*/
public static function removeFromCart($uid, $sku, $shoppingKey, $hasPromotion = false)
{
$param = Yohobuy::param();
$param['method'] = $hasPromotion ? 'app.Shopping.removeAndCart' : 'app.Shopping.remove';
$param['product_sku_list'] = $sku;
if (!empty($uid)) {
$param['uid'] = $uid;
}
if (!empty($shoppingKey)) {
$param['shopping_key'] = $shoppingKey;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 移入收藏夹
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param bool $hasPromotion 是否有促销ID
* @return array 接口返回的数据
*/
public static function addToFav($uid, $sku, $hasPromotion = false)
{
$param = Yohobuy::param();
$param['method'] = $hasPromotion ? 'app.Shopping.addfavoriteAndCart' : 'app.Shopping.addfavorite';
$param['product_sku_list'] = $sku;
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 获取购物车商品详情数据
*
* @param int $uid 用户ID
* @param int $skn 商品skn
* @return array 接口返回的数据
*/
public static function cartProductData($uid, $skn)
{
$param = Yohobuy::param();
$param['method'] = 'app.product.data';
$param['product_skn'] = $skn;
$param['showcomment'] = 'N';
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 获取加价购商品详情数据
*
* @param int $skn 商品skn
* @param int $promotionId 加价购商品促销ID
* @return array 接口返回的数据
*/
public static function giftProductData($skn, $promotionId)
{
$param = Yohobuy::param();
$param['method'] = 'app.product.gift';
$param['product_skn'] = $skn;
$param['promotion_id'] = $promotionId;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 增减购物车商品数量
*
* @param int $uid 用户ID
* @param string $sku 商品SKU
* @param int $increaseNum 增加的数目
* @param int $decreaseNum 减少的数目
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 接口返回的数据
*/
public static function modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey)
{
$param = Yohobuy::param();
$param['product_sku'] = $sku;
// 增加
if (!empty($increaseNum)) {
$param['method'] = 'app.Shopping.increase';
$param['increase_number'] = intval($increaseNum);
}
// 减少
if (!empty($decreaseNum)) {
$param['method'] = 'app.Shopping.decrease';
$param['decrease_number'] = intval($decreaseNum);
}
if (!empty($uid)) {
$param['uid'] = $uid;
}
if (!empty($shoppingKey)) {
$param['shopping_key'] = $shoppingKey;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 修改购物车商品数据
*
* @param int $uid 用户ID
* @param string $swapData 商品数据
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 接口返回的数据
*/
public static function modifyCartProduct($uid, $swapData, $shoppingKey)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.swap';
$param['swap_data'] = $swapData;
if (!empty($uid)) {
$param['uid'] = $uid;
}
if (!empty($shoppingKey)) {
$param['shopping_key'] = $shoppingKey;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 购物车结算
*
* @param int $uid 用户ID
* @param string $cartType 购物车类型,ordinary表示普通, advance表示预售
* @param int $isUseYohoCoin 是否使用有货币,默认0不使用, 1使用
* @return array 接口返回的数据
*/
public static function cartPay($uid, $cartType, $isUseYohoCoin = 0)
{
if (in_array($cartType, array('ordinary', 'advance')) === FALSE) {
return array('code' => 400, 'message' => '购物车参数类型有误!', 'data' => array());
}
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.payment';
$param['cart_type'] = $cartType;
$param['yoho_coin_mode'] = $isUseYohoCoin;
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get('http://192.168.102.205:8080/gateway/', $param);
}
/**
* 购物车结算--支付方式和配送方式选择
*
* @param int $uid 用户ID
* @param string $cartType 购物车类型,ordinary表示普通, advance表示预售
* @param int $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运
* @param int $paymentType 支付方式,1表示在线支付,2表示货到付款
* @param string $couponCode 优惠券码
* @param string $promotionCode 优惠码
* @param mixed $yohoCoin 使用的有货币数量
* @param int $redEnvelopes 红包
* @return array 接口返回的数据
*/
public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode,$promotionCode,$yohoCoin, $redEnvelopes)
{
if (in_array($cartType, array('ordinary', 'advance')) === FALSE) {
return array('code' => 400, 'message' => '购物车参数类型有误!', 'data' => array());
}
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.compute';
$param['cart_type'] = $cartType;
$param['delivery_way'] = $deliveryWay;
$param['payment_type'] = $paymentType;
if (!empty($couponCode)) {
$param['coupon_code'] = $couponCode;
}
if (!empty($promotionCode)) {
$param['promotion_code'] = $promotionCode;
}
if (!empty($yohoCoin)) {
$param['use_yoho_coin'] = $yohoCoin;
}
if (!empty($redEnvelopes)) {
$param['use_red_envelopes'] = $redEnvelopes;
}
// 控制是否判断有货币超出订单金额
$param['check_yohocoin_amount'] = 'Y';
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get('http://192.168.102.205:8080/gateway/', $param);
}
/**
* 购物车结算--使用优惠券
*
* @param int $uid 用户ID
* @param string $couponCode 优惠券代码
* @return array 接口返回的数据
*/
public static function searchCoupon($uid, $couponCode)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.useCoupon';
$param['coupon_code'] = $couponCode;
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 购物车结算--获取优惠券列表
*
* @param int $uid 用户ID
* @return array 接口返回的数据
*/
public static function getCouponList($uid, $limit = 10)
{
$param = Yohobuy::param();
$param['method'] = 'app.coupons.lists';
$param['type'] = 'notuse';
$param['page'] = 1;
$param['limit'] = $limit;
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 购物车结算--获取用户可用和不可用的优惠券列表
*
* @param int $uid 用户ID
* @return array 接口返回的数据
*/
public static function getListCoupon($uid)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.listCoupon';
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 购物车结算--提交结算信息
*
* @param int $uid 用户ID
* @param int $addressId 地址ID
* @param string $cartType 购物车类型,ordinary表示普通, advance表示预售
* @param int $deliveryTime 寄送时间ID
* @param int $deliveryWay 寄送方式ID
* @param int $invoiceType 发票类型 1:纸质,2:电子
* @param string $invoiceTitle 发票抬头
* @param int $invoiceContent 发票内容
* @param string $receiverMobile 发票接收人电话
* @param int $paymentId 支付方式ID
* @param int $paymentType 支付类型ID
* @param string $remark 留言
* @param string $couponCode 优惠券码
* @param string $promotionCode 优惠码
* @param mixed $yohoCoin 使用的有货币数量或为空
* @param int $isPreContact 送货前是否联系
* @param int $isPrintPrice 是否打印价格
* @param string $unionKey 联盟Key
* @param string|null $userAgent 联盟过来用户下单时需要的User-Agent信息
* @param int $redEnvelopes 红包
* @return array 接口返回的数据
*/
public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceType, $invoiceTitle, $invoiceContent, $receiverMobile,
$paymentId, $paymentType, $remark,$couponCode,$promotionCode, $yohoCoin, $isPreContact, $isPrintPrice, $unionKey,$userAgent, $redEnvelopes)
{
if (in_array($cartType, array('ordinary', 'advance')) === FALSE) {
return array('code' => 400, 'message' => '购物车参数类型有误!', 'data' => array());
}
$param = Yohobuy::param();
$param['debug'] = 'Y';
$param['client_type'] = 'web'; // 需要ERP统计PC的下单量
$param['private_key'] = Yohobuy::$privateKeyList['web']; // PC默认使用Android的私钥
$param['method'] = 'app.Shopping.submit';
$param['address_id'] = $addressId;
$param['cart_type'] = $cartType;
$param['delivery_time'] = $deliveryTime;
$param['delivery_way'] = $deliveryWay;
$param['uid'] = $uid;
if (!empty($invoiceType)) {
$param['invoices_type'] = $invoiceType;
}
if (!empty($invoiceTitle)) {
$param['invoices_title'] = $invoiceTitle;
}
if (!empty($invoiceContent)) {
$param['invoice_content'] = $invoiceContent;
}
if (!empty($receiverMobile)) {
$param['receiverMobile'] = $receiverMobile;
}
if (!empty($redEnvelopes)) {
$param['use_red_envelopes'] = $redEnvelopes;
}
$param['payment_id'] = $paymentId;
$param['payment_type'] = $paymentType;
if (!empty($couponCode)) {
$param['coupon_code'] = $couponCode;
}
if (!empty($promotionCode)) {
$param['promotion_code'] = $promotionCode;
}
if (!empty($yohoCoin)) {
$param['use_yoho_coin'] = $yohoCoin;
}
if (!empty($isPreContact) && $isPreContact == 'true') {
$param['is_pre_contact'] = 'Y';
}
if (!empty($isPrintPrice) && $isPrintPrice == 'true') {
$param['is_print_price'] = 'Y';
}
// 友盟有关信息的传递
if (!empty($unionKey)) {
$param['qhy_union'] = $unionKey;
}
$param['remark'] = $remark;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param, false, false, 10, $userAgent);
}
/**
* 购物车数量
*
* @param int $uid 用户ID
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 购物车接口返回的数据
*/
public static function cartCount($uid, $shoppingKey)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.count';
if (!empty($uid)) {
$param['uid'] = $uid;
}
if (!empty($shoppingKey)) {
$param['shopping_key'] = $shoppingKey;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 凑单商品
*
* @param int $page 分页页码
* @return array
*/
public static function togetherProduct($page)
{
$param = Yohobuy::param();
$param['method'] = 'web.product.together';
$param['client_type'] = 'web';
$param['private_key'] = Yohobuy::$privateKeyList['web'];
$param['page'] = $page;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 浏览记录数据
*
* @param int $uid 用户ID
* @param int $udid 客户端唯一标识
* @param int $page 第几页,默认为1
* @param int $limit 限制多少条,默认100
* @return array 接口返回的数据
*/
public static function browseRecord($uid, $udid, $page = 1, $limit = 10)
{
$param = Yohobuy::param();
$param['method'] = 'app.browse.product';
$param['uid'] = $uid;
$param['udid'] = $udid;
$param['page'] = $page;
$param['limit'] = $limit;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 通过搜索查询商品信息
*
* 备注:因默认的搜索方法会有过滤, 浏览记录不需要过滤
*
* @param string $query 查询的条件
* @param int $limit 查询的限制数
* @return array
*/
public static function browseRecordFromSearch($query, $limit = 10)
{
$param = array();
$param['order'] = 'shelve_time:desc';
$param['page'] = 1;
$param['viewNum'] = $limit;
$param['query'] = $query;
return Yohobuy::get(SearchData::getUrl('search'), $param);
}
/**
* 选择支付,校验时间间隔,插入数据
* @param string $uid
* @param string $orderCode
* @param int $payment 14:银联手机支付 15:支付宝手机 18:支付宝wap(wap) 19:微信支付 22:微信wap(wap) 26:QQ钱包手机支付
* @return type
*/
public static function savePrePayInfo($uid, $orderCode, $payment)
{
$param = Yohobuy::param();
$param['method'] = 'app.order.savePrePayInfo';
$param['uid'] = $uid;
$param['orderCode'] = $orderCode;
$param['payment'] = $payment;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 电子票添加和查询
* @param int $uid 用户ID
* @param type int $productSku 产品sku
* @param type int $buyNumber 购买数量,范围1-4
* @param type int $yohoCoin 有货币
* @return type []
*/
public static function addTicket($uid, $productSku, $buyNumber, $yohoCoin = 0)
{
$param = Yohobuy::param();
$param['method'] = 'app.shopping.ticket';
$param['uid'] = intval($uid);
$param['product_sku'] = intval($productSku);
$param['buy_number'] = intval($buyNumber);
//有货币转换成元,1有货币等于一分钱
if (isset($yohoCoin) && $yohoCoin > 0) {
$param['use_yoho_coin'] = $yohoCoin / 100;
}
$param['client_secret'] = Sign::getSign($param);
$data = Yohobuy::get(API_URL, $param);
//展览票不显示区域,上面要求的。@高扬、@徐洪云,2016/7/6
if (isset($data['data']) && !empty($data['data']['goods_list'])) {
foreach ($data['data']['goods_list'] as $key => $val) {
$val['size_name'] = ($val['product_skn'] * 1 === EXHIBITION_TICKET ? '' : $val['size_name']);
$data['data']['goods_list'][$key] = $val;
}
}
return $data;
}
/**
* 电子票下单
* @param type int $uid 用户ID
* @param type int $productSku 产品sku
* @param type int $buyNumber 购买数量,范围1-4
* @param type string $mobile 手机号码
* @param type int $yohoCoin 有货币
* @return type []
*/
public static function submitTicket($uid, $productSku, $buyNumber, $mobile, $yohoCoin = 0)
{
$param = Yohobuy::param();
$param['method'] = 'app.shopping.submitTicket';
$param['uid'] = intval($uid);
$param['product_sku'] = intval($productSku);
$param['buy_number'] = intval($buyNumber);
$param['mobile'] = $mobile;
//有货币转换成元,1有货币等于一分钱
if (isset($yohoCoin) && $yohoCoin > 0) {
$param['use_yoho_coin'] = $yohoCoin / 100;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 根据订单号获取电子票二维码
* @param type $orderCode
* @return type
*/
public static function getQrByOrderCode($orderCode)
{
$param = Yohobuy::param();
$param['method'] = 'app.SpaceOrders.getQrByOrderCode';
$param['order_code'] = intval($orderCode);
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
}