SendCouponHelper.java
4.32 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
/**
*
*/
package com.yoho.unions.helper;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.promotion.CouponForm;
import com.yoho.service.model.request.YohoCoinCostReqBO;
import com.yoho.service.model.request.YohoCoinLogReqBO;
import com.yoho.service.model.request.YohoCoinRecordReq;
import com.yoho.service.model.response.CommonRspBO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @author ping.huang 2016年8月27日
*/
@Component
public class SendCouponHelper {
Logger log = LoggerFactory.getLogger(getClass());
@Resource
ServiceCaller serviceCaller;
/**
* 发送优惠券
*
* @param couponId
* @param uid
*/
public String sendCoupon(String couponId, int uid) throws ServiceException {
log.info("start with sendCoupon. couponId is {}, uid is {}", couponId, uid);
if (StringUtils.isEmpty(couponId) || "0".equals(couponId)) {
return "0";
}
CouponForm form = new CouponForm();
form.setCouponId(couponId);
form.setUid(String.valueOf(uid));
String couponCode = "";
try {
couponCode = serviceCaller.call("promotion.sendCoupon", form, String.class);
} catch (Exception e) {
log.error("sendCoupon failed, ex: {}", e.getMessage());
}
log.info("end with sendCoupon. couponCode is {}", couponCode);
return couponCode;
}
/**
* 发送有货币
*
* @param uid
* @param num
* @return
*/
public boolean sendYOHOBi(int uid, int num) {
YohoCoinRecordReq req = buildYohoCoinCostReq(uid, num);
final String serviceName = "users.addRecord";
boolean result = false;
try {
log.info("BrandActivityServiceImpl sendYOHOBi req------ is {}", req);
CommonRspBO rspBO = serviceCaller.call(serviceName, req, CommonRspBO.class);
log.info("BrandActivityServiceImpl sendYOHOBi result----- is {}", rspBO);
if (rspBO != null && rspBO.getCode() == 200) {
result = true;
}
} catch (Exception e) {
log.warn("in method sendYOHOBIEvent ,invoke {} occurs error,detail is {}", serviceName, e);
}
return result;
}
/**
* 发送有货币
*
* @param uid
* @param num
* @return
*/
public boolean sendYOHOBi(int uid, int num, int type) {
YohoCoinRecordReq req = buildYohoCoinCostReq(uid, num, type);
final String serviceName = "users.addRecord";
boolean result = false;
try {
log.info("BrandActivityServiceImpl sendYOHOBi req------ is {}", req);
CommonRspBO rspBO = serviceCaller.call(serviceName, req, CommonRspBO.class);
if (rspBO != null && rspBO.getCode() == 200) {
result = true;
}
} catch (Exception e) {
log.warn("in method sendYOHOBIEvent ,invoke {} occurs error,detail is {}", serviceName, e);
}
return result;
}
// 构造参数
private YohoCoinRecordReq buildYohoCoinCostReq(int uid, int num) {
YohoCoinRecordReq req = new YohoCoinRecordReq();
YohoCoinCostReqBO yohoCoinCostReq = new YohoCoinCostReqBO();
yohoCoinCostReq.setUid(uid);
yohoCoinCostReq.setNum(num);
yohoCoinCostReq.setType(Byte.valueOf(String.valueOf(6)));// 抽奖送币
yohoCoinCostReq.setParams("{}");
yohoCoinCostReq.setOrderCode("0");
req.setCost(yohoCoinCostReq);
YohoCoinLogReqBO yohoCoinLogReqBO = new YohoCoinLogReqBO();
yohoCoinLogReqBO.setUid(uid);
yohoCoinLogReqBO.setChangeNum(Short.valueOf(String.valueOf(num)));
yohoCoinLogReqBO.setChangeType(Byte.valueOf(String.valueOf(6)));
yohoCoinLogReqBO.setChangeParams("{}");
req.setHistory(yohoCoinLogReqBO);
return req;
}
// 构造参数
private YohoCoinRecordReq buildYohoCoinCostReq(int uid, int num, int type) {
YohoCoinRecordReq req = new YohoCoinRecordReq();
YohoCoinCostReqBO yohoCoinCostReq = new YohoCoinCostReqBO();
yohoCoinCostReq.setUid(uid);
yohoCoinCostReq.setNum(num);
yohoCoinCostReq.setType(Byte.valueOf(String.valueOf(type)));// 抽奖送币
yohoCoinCostReq.setParams("{}");
yohoCoinCostReq.setOrderCode("0");
req.setCost(yohoCoinCostReq);
YohoCoinLogReqBO yohoCoinLogReqBO = new YohoCoinLogReqBO();
yohoCoinLogReqBO.setUid(uid);
yohoCoinLogReqBO.setChangeNum(Short.valueOf(String.valueOf(num)));
yohoCoinLogReqBO.setChangeType(Byte.valueOf(String.valueOf(type)));
yohoCoinLogReqBO.setChangeParams("{}");
req.setHistory(yohoCoinLogReqBO);
return req;
}
}