ticket-service.js
2.4 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
/**
* Created by TaoHuang on 2017/6/22.
*/
const TicketApi = require('./ticket-api');
const _ = require('lodash');
const helpers = global.yoho.helpers;
const OrderEnsureHandle = require('./order-ensure-handle');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
_handleGoodsList(list) {
return list.map((i) => {
i.linkToGoods = helpers.getUrlBySkc(i.product_skn);
i.productPrice = i.sales_price;
return i;
});
}
_handleAmount(info) {
return _.get(info, 'data.shopping_cart_data.last_order_amount', 0);
}
addTicket(uid, sku, count, yohoCoin) {
return new TicketApi(this.ctx).add(uid, sku, count, yohoCoin).then(ticketInfo => {
let result = {};
if (_.isEmpty(ticketInfo)) {
return {
last_order_amount: 0,
error: '人太多啦,稍后再试!'
};
}
if (ticketInfo.code !== 200) {
return {
last_order_amount: 0,
error: ticketInfo.message
};
}
result.virtualGood = true;
result.goodsList = this._handleGoodsList(_.get(ticketInfo, 'data.goods_list', []));
result.last_order_amount = this._handleAmount(ticketInfo);
Object.assign(result, new OrderEnsureHandle(this.ctx).handleUseYohoCoin(
_.get(ticketInfo, 'data.shopping_cart_data', {}
)));
return result;
});
}
submitTicket(uid, sku, count, mobile, yohoCoin) {
return new TicketApi(this.ctx).submit(uid, sku, count, mobile, yohoCoin).then(result => {
if (_.isEmpty(result)) {
return {
code: 500,
message: '人太多啦,稍后再试!'
};
}
if (result.code !== 200) {
return {
code: result.code,
message: result.message
};
}
return {
code: 200,
message: '提交成功',
data: {
refer: helpers.urlFormat('/shopping/newpay', {
ordercode: result.data.order_code
})
}
};
});
}
};