CartData.php
17.6 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
<?php
namespace LibModels\Wap\Home;
use Api\Sign;
use Api\Yohobuy;
use Plugin\Helpers;
/**
* 购物车的数据模型
*
* @name CartData
* @package LibModels/Wap/Home
* @copyright yoho.inc
* @version 1.0 (2015-11-09 13:58:27)
* @author Gtskk <tttt6399998@126.com>
*/
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 ($shoppingKey !== null) {
$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 未登录用户唯一识别码
* @return array 购物车接口返回的数据
*/
public static function selectGoods($uid, $sku, $shoppingKey)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.selectedAndCart';
$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 未登录用户唯一识别码
* @return array 接口返回的数据
*/
public static function removeFromCart($uid, $sku, $shoppingKey)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.removeAndCart';
$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列表
* @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['method'] = 'app.Shopping.increase';
$param['product_sku'] = $sku;
if (!empty($increaseNum)) {
$param['increase_number'] = intval($increaseNum);
}
if (!empty($decreaseNum)) {
$param['decrease_number'] = intval($decreaseNum);
}
if (!empty($uid)) {
$param['uid'] = $uid;
}
if ($shoppingKey !== null) {
$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 ($shoppingKey !== null) {
$param['shopping_key'] = $shoppingKey;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 购物车结算
*
* @param int $uid 用户ID
* @param string $cartType 购物车类型,ordinary表示普通购物车
* @param int $isUseYohoCoin 是否使用有货币,0不使用, 1使用
* @param string $skuList 购买限购商品时需要传递的参数
* @return array 接口返回的数据
*/
public static function cartPay($uid, $cartType, $isUseYohoCoin, $skuList)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.payment';
$param['enable_red_envelopes'] = 0; //h5不返回红包
$param['cart_type'] = $cartType;
$param['yoho_coin_mode'] = $isUseYohoCoin;
$param['uid'] = $uid;
// 购买限购商品时需要传递product_sku_list参数
if (!empty($skuList)) {
$param['product_sku_list'] = $skuList;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 购物车结算--支付方式和配送方式选择
*http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E8%AE%A2%E5%8D%95/shopping.md
* @param int $uid 用户ID
* @param string $cartType 购物车类型,ordinary表示普通购物车
* @param int $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运
* @param int $paymentType 支付方式,1表示在线支付,2表示货到付款
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的有货币数量
* @param string $skuList 购买限购商品时需要传递的参数
* @return array 接口返回的数据
*/
public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin, $skuList)
{
$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($yohoCoin)) {
$param['use_yoho_coin'] = $yohoCoin;
}
// 购买限购商品时需要传递product_sku_list参数
if (!empty($skuList)) {
$param['product_sku_list'] = $skuList;
}
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $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)
{
$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
* @return array 接口返回的数据
*/
public static function getValidCouponCount($uid)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.countUsableCoupon';
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 购物车结算--提交结算信息
*
* @param int $uid 用户ID
* @param int $addressId 地址ID
* @param int $cartType 购物车类型ID
* @param int $deliveryTime 寄送时间ID
* @param int $deliveryWay 寄送方式ID
* @param array $invoices 发票参数数组
* @param int $paymentId 支付方式ID
* @param int $paymentType 支付类型ID
* @param string $remark 留言
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的有货币数量或为空
* @param string $skuList 购买限购商品时需要传递的参数
* @param string $qhyUnion 友盟有关信息
* @param string|null $userAgent 联盟过来用户下单时需要的User-Agent信息
* @param $times
* @return array 接口返回的数据
*/
public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoices, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList, $qhyUnion, $userAgent, $times)
{
$param = Yohobuy::param();
$param['debug'] = 'Y';
$param['client_type'] = 'h5'; // 需要ERP统计WAP的下单量
if(Helpers::is_weixin()) {
$param['client_type'] = 'wechat';
}
$param['private_key'] = Yohobuy::$privateKeyList['android']; // H5默认使用Android的私钥
$param['method'] = 'app.Shopping.submit';
$param['address_id'] = $addressId;
$param['cart_type'] = $cartType;
$param['delivery_time'] = $deliveryTime;
$param['delivery_way'] = $deliveryWay;
/* tar add 161130 结算优化 */
if ($times === 2 || $times === '2') {
$param['is_continue_buy'] = 'Y';
} else {
$param['is_continue_buy'] = 'N';
}
if (!empty($invoices['invoices_type_id'])) {
//发票内容id--图书:1
$param['invoice_content'] = $invoices['invoices_type_id'];
}
if (!empty($invoices['invoices_type'])) {
//数字类型 发票类型 /**纸质 1 ,电子 2 */
$param['invoices_type'] = $invoices['invoices_type'];
}
if (!empty($invoices['receiverMobile'])) {
//发票人手机
$param['receiverMobile'] = $invoices['receiverMobile'];
}
if (!empty($invoices['invoices_title'])) {
//发票抬头 OR 填写单位名称,这二个是一个意思,只是叫法不一样
$param['invoices_title'] = $invoices['invoices_title'];
}
$param['payment_id'] = $paymentId;
$param['payment_type'] = $paymentType;
$param['remark'] = $remark;
if (!empty($couponCode)) {
$param['coupon_code'] = $couponCode;
}
if (!empty($yohoCoin)) {
$param['use_yoho_coin'] = $yohoCoin;
}
// 购买限购商品时需要传递product_sku_list参数
if (!empty($skuList)) {
$param['product_sku_list'] = $skuList;
}
// 友盟有关信息的传递
if (!empty($qhyUnion)) {
$param['qhy_union'] = $qhyUnion;
}
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
/* TODO TAR DELETE!!! */
// return array(
// 'code' => 200,
// 'data' => array(
// 'activityAmount' => 0,
// 'hintInfo' => array(
// 'lastLine' => '就能解决一切问题的',
// 'prefix' => '',
// 'suffix' => '得很复杂',
// 'productName' => '就能解决一切问题的。但是到了Node.js上貌似会变得很复杂'
// ),
// 'isOpenTicket' => 'N',
// 'is_hint' => 'Y',
// 'offline_submit_goods' => array(),
// 'shippingCost' => 0
// )
// );
return Yohobuy::get(API_URL, $param, false, false, 5, $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 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
* @param int $productSku
* @param int $buyNumber
* @param int $useYohoCoin
* @param int $yohoCoinMode 1:使用有货币;0:不使用有货币
* @author sefon 2016-7-2 18:12:30
* @return array
*/
public static function checkTickets ($uid, $productSku, $buyNumber, $useYohoCoin = 0, $yohoCoinMode = true)
{
$param = Yohobuy::param();
$param['method'] = 'app.shopping.ticket';
$param['uid'] = $uid;
$param['product_sku'] = $productSku;
$param['buy_number'] = $buyNumber;
if (!$yohoCoinMode) {
$param['yoho_coin_mode'] = 0;
}
$param['use_yoho_coin'] = $useYohoCoin;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
/**
* 电子票下单
* @param int $uid
* @param int $productSku
* @param int $buyNumber
* @param int $useYohoCoin
* @param int $qhyUnion
* @author sefon 2016-7-2 18:12:30
* @return array
*/
public static function submitTicket ($uid, $productSku, $buyNumber, $mobile, $useYohoCoin = 0, $qhyUnion = '')
{
$param = Yohobuy::param();
$param['method'] = 'app.shopping.submitTicket';
$param['uid'] = $uid;
$param['product_sku'] = $productSku;
$param['buy_number'] = $buyNumber;
$param['mobile'] = $mobile;
$param['use_yoho_coin'] = $useYohoCoin;
$param['qhy_union'] = $qhyUnion;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
}
}