|
|
@ -80,14 +80,12 @@ public class ActRedPackServiceImpl implements ActRedPackService {
|
|
|
|
return actRedPacketsCustomerMapper.findOne(actId);
|
|
|
|
return actRedPacketsCustomerMapper.findOne(actId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendActRedPackets(JSONObject order) throws RedPackException {
|
|
|
|
public void sendActRedPackets(JSONObject order) throws RedPackException {
|
|
|
|
String orderId = order.getString("order_id");
|
|
|
|
String orderId = order.getString("order_id");
|
|
|
|
int client_id = order.getIntValue("client_id");
|
|
|
|
int clientId = order.getIntValue("client_id");
|
|
|
|
String channel = order.getString("channel");
|
|
|
|
String channel = order.getString("channel");
|
|
|
|
String currency = order.getString("currency");
|
|
|
|
String currency = order.getString("currency");
|
|
|
|
logger.info("======================sendActRedPackets====================");
|
|
|
|
|
|
|
|
logger.info("======================orderId:" + orderId + ";client_id:" + client_id + "====================");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<JSONObject> currentActivities = actRedPacketsCustomerMapper.findCurrentActivity();
|
|
|
|
List<JSONObject> currentActivities = actRedPacketsCustomerMapper.findCurrentActivity();
|
|
|
|
if (currentActivities.isEmpty()) {
|
|
|
|
if (currentActivities.isEmpty()) {
|
|
|
|
logger.info("当前没有可用活动");
|
|
|
|
logger.info("当前没有可用活动");
|
|
|
@ -96,11 +94,12 @@ public class ActRedPackServiceImpl implements ActRedPackService {
|
|
|
|
JSONObject redpackCustomerActivity = currentActivities.get(0);
|
|
|
|
JSONObject redpackCustomerActivity = currentActivities.get(0);
|
|
|
|
String actId = redpackCustomerActivity.getString("act_id");
|
|
|
|
String actId = redpackCustomerActivity.getString("act_id");
|
|
|
|
String actName = redpackCustomerActivity.getString("act_name");
|
|
|
|
String actName = redpackCustomerActivity.getString("act_name");
|
|
|
|
JSONObject clientApply = actClientApplyMapper.findActivity(actId, client_id);
|
|
|
|
JSONObject clientApply = actClientApplyMapper.findActivity(actId, clientId);
|
|
|
|
if (clientApply == null) {
|
|
|
|
if (clientApply == null) {
|
|
|
|
logger.info("未检索到商户申请信息");
|
|
|
|
logger.info("未检索到商户申请信息");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info("<<<======== [{}]红包发送检查--商户[{}]--订单编号:{} ========>>>",actName,clientId,orderId);
|
|
|
|
String actChannel = redpackCustomerActivity.getString("channel");
|
|
|
|
String actChannel = redpackCustomerActivity.getString("channel");
|
|
|
|
if (!StringUtils.isEmpty(actChannel)) {
|
|
|
|
if (!StringUtils.isEmpty(actChannel)) {
|
|
|
|
if (!actChannel.equals(channel)) {
|
|
|
|
if (!actChannel.equals(channel)) {
|
|
|
@ -129,27 +128,27 @@ public class ActRedPackServiceImpl implements ActRedPackService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String open_id = order.getString("customer_id");
|
|
|
|
String customerId = order.getString("customer_id");
|
|
|
|
|
|
|
|
|
|
|
|
int getTotalCounts = getRedPacketsByOpenid(open_id, new Date(), actId);
|
|
|
|
int getTotalCounts = getRedPacketsByOpenid(customerId, new Date(), actId);
|
|
|
|
int ruleMaxNum = redpackCustomerActivity.getIntValue("rule_max_num");
|
|
|
|
int ruleMaxNum = redpackCustomerActivity.getIntValue("rule_max_num");
|
|
|
|
if (getTotalCounts >= ruleMaxNum) {
|
|
|
|
if (getTotalCounts >= ruleMaxNum) {
|
|
|
|
logger.debug("open_id:" + open_id + "已达到本次活动发送最大次数" + ruleMaxNum + "!跳过");
|
|
|
|
logger.debug("customerId:" + customerId + "已达到本次活动发送最大次数" + ruleMaxNum + "!跳过");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int getDailyTotalCounts = getRedPacketsByOpenid(open_id, new Date(), actId);
|
|
|
|
int getDailyTotalCounts = getRedPacketsByOpenid(customerId, new Date(), actId);
|
|
|
|
int ruleMaxNumLimit = redpackCustomerActivity.getIntValue("rule_max_num_limit");
|
|
|
|
int ruleMaxNumLimit = redpackCustomerActivity.getIntValue("rule_max_num_limit");
|
|
|
|
if (getDailyTotalCounts >= ruleMaxNumLimit) {
|
|
|
|
if (getDailyTotalCounts >= ruleMaxNumLimit) {
|
|
|
|
logger.debug("open_id:" + open_id + "已达当日发送最大次数" + ruleMaxNumLimit + "!跳过");
|
|
|
|
logger.debug("customerId:" + customerId + "已达当日发送最大次数" + ruleMaxNumLimit + "!跳过");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
takeRedpack(actId, orderId, client_id, clientApply, currencyAmount, open_id, 0);
|
|
|
|
takeRedpack(actId, orderId, clientId, clientApply, currencyAmount, customerId, 0);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void takeRedpack(String actId, String orderId, int client_id, JSONObject clientApply, BigDecimal currencyAmount, String open_id, int tryTimes)
|
|
|
|
private void takeRedpack(String actId, String orderId, int clientId, JSONObject clientApply, BigDecimal currencyAmount, String customerId, int tryTimes)
|
|
|
|
throws RedPackException {
|
|
|
|
throws RedPackException {
|
|
|
|
if (tryTimes > 5) {
|
|
|
|
if (tryTimes > 5) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -172,29 +171,36 @@ public class ActRedPackServiceImpl implements ActRedPackService {
|
|
|
|
ran -= prizeType.getIntValue("weight");
|
|
|
|
ran -= prizeType.getIntValue("weight");
|
|
|
|
if (ran < 0) {
|
|
|
|
if (ran < 0) {
|
|
|
|
String lock = Long.toString(System.currentTimeMillis(), 36) + RandomStringUtils.random(5, true, true);
|
|
|
|
String lock = Long.toString(System.currentTimeMillis(), 36) + RandomStringUtils.random(5, true, true);
|
|
|
|
int lockedCount = actRedPacketsCustomerOrdersMapper.lockPrize(actId, lock, prizeType.getString("type_id"), open_id, client_id, orderId,
|
|
|
|
int lockedCount = actRedPacketsCustomerOrdersMapper.lockPrize(actId, lock, prizeType.getString("type_id"), customerId, clientId, orderId,
|
|
|
|
currencyAmount, new Date());
|
|
|
|
currencyAmount, new Date());
|
|
|
|
if (lockedCount > 0) {
|
|
|
|
if (lockedCount > 0) {
|
|
|
|
doSendActLuckyMoney(open_id, lock, clientApply.getString("act_name"), clientApply.getString("send_name"), clientApply.getString("wishing"));
|
|
|
|
doSendWechatActLuckyMoney(customerId, lock, clientApply.getString("act_name"), clientApply.getString("send_name"), clientApply.getString("wishing"));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
takeRedpack(actId, orderId, client_id, clientApply, currencyAmount, open_id, tryTimes + 1);
|
|
|
|
takeRedpack(actId, orderId, clientId, clientApply, currencyAmount, customerId, tryTimes + 1);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void doSendActLuckyMoney(String open_id, String lock, String actName, String sendName, String wishing) throws RedPackException {
|
|
|
|
@Override
|
|
|
|
JSONObject prizeDetail = actRedPacketsCustomerOrdersMapper.findLockedPrize(lock, open_id);
|
|
|
|
public void doSendWechatActLuckyMoney(String paymentOpenId, String lock, String actName, String sendName, String wishing) throws RedPackException {
|
|
|
|
|
|
|
|
JSONObject prizeDetail = actRedPacketsCustomerOrdersMapper.findLockedPrize(lock, paymentOpenId);
|
|
|
|
BigDecimal luckyMoeny = prizeDetail.getBigDecimal("red_packet_amount");
|
|
|
|
BigDecimal luckyMoeny = prizeDetail.getBigDecimal("red_packet_amount");
|
|
|
|
String red_packet_order_id = prizeDetail.getString("red_packet_order_id");
|
|
|
|
String redPackOrderId = prizeDetail.getString("red_packet_order_id");
|
|
|
|
BigDecimal totalAmount = luckyMoeny.multiply(CommonConsts.HUNDRED);
|
|
|
|
BigDecimal totalAmount = luckyMoeny.multiply(CommonConsts.HUNDRED);
|
|
|
|
String notifyUrl = "https://mpay.royalpay.com.au/sys/lucky_money/customer/redpacks/" + red_packet_order_id + "/notify";
|
|
|
|
String notifyUrl = "https://mpay.royalpay.com.au/sys/lucky_money/customer/redpacks/" + redPackOrderId + "/notify";
|
|
|
|
JSONObject customerRelation = customerMapper.findCustomerByOpenId(open_id);
|
|
|
|
JSONObject customerRelation = customerMapper.findCustomerByOpenId(paymentOpenId);
|
|
|
|
MpWechatApi redpackApi = mpWechatApiProvider.getApi("Redpack");
|
|
|
|
if (customerRelation == null) {
|
|
|
|
if (customerRelation == null || customerRelation.getString(redpackApi.getOpenIdKey()) == null) {
|
|
|
|
customerRelation = customerMapper.findCustomerGlobalpayByOpenId(paymentOpenId);
|
|
|
|
throw new RedPackException("ServerError", "Customer openid for redpack not available!");
|
|
|
|
if (customerRelation == null) {
|
|
|
|
|
|
|
|
throw new NotFoundException("Customer openid for redpack not available!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
MpWechatApi redpackApi = mpWechatApiProvider.getApi("redpack");
|
|
|
|
|
|
|
|
if (customerRelation.getString(redpackApi.getOpenIdKey()) == null) {
|
|
|
|
|
|
|
|
throw new RedPackException("Server Error", "Red envelope service temporarily unavailable!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String rpOpenId = customerRelation.getString(redpackApi.getOpenIdKey());
|
|
|
|
String rpOpenId = customerRelation.getString(redpackApi.getOpenIdKey());
|
|
|
|
WechatRedpack wechatRedpack = new WechatRedpack();
|
|
|
|
WechatRedpack wechatRedpack = new WechatRedpack();
|
|
|
@ -204,7 +210,7 @@ public class ActRedPackServiceImpl implements ActRedPackService {
|
|
|
|
wechatRedpack.setOpenId(rpOpenId);
|
|
|
|
wechatRedpack.setOpenId(rpOpenId);
|
|
|
|
wechatRedpack.setSendName(sendName);
|
|
|
|
wechatRedpack.setSendName(sendName);
|
|
|
|
wechatRedpack.setWishing(wishing);
|
|
|
|
wechatRedpack.setWishing(wishing);
|
|
|
|
wechatRedpack.setRemark("开业红包活动");
|
|
|
|
wechatRedpack.setRemark(sendName);
|
|
|
|
logger.info("==============Send RedPacket Service:" + wechatRedpack.toString() + "=========");
|
|
|
|
logger.info("==============Send RedPacket Service:" + wechatRedpack.toString() + "=========");
|
|
|
|
String redPacketId = redpackApi.sendRedpack(wechatRedpack).getString("out_biz_no");
|
|
|
|
String redPacketId = redpackApi.sendRedpack(wechatRedpack).getString("out_biz_no");
|
|
|
|
prizeDetail.put("red_packet_id", redPacketId);
|
|
|
|
prizeDetail.put("red_packet_id", redPacketId);
|
|
|
@ -213,32 +219,32 @@ public class ActRedPackServiceImpl implements ActRedPackService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void setRedpackConfg(String act_id, JSONObject config) {
|
|
|
|
public void setRedpackConfg(String actId, JSONObject config) {
|
|
|
|
Date prizeDate = new Date();
|
|
|
|
Date prizeDate = new Date();
|
|
|
|
List<JSONObject> prize_type_list = (List<JSONObject>) config.get("prize_type_list");
|
|
|
|
List<JSONObject> prizeTypeList = (List<JSONObject>) config.get("prize_type_list");
|
|
|
|
JSONObject act = actRedPacketsCustomerMapper.findOne(act_id);
|
|
|
|
JSONObject act = actRedPacketsCustomerMapper.findOne(actId);
|
|
|
|
Assert.notNull(act);
|
|
|
|
Assert.notNull(act);
|
|
|
|
config.put("act_id", act_id);
|
|
|
|
config.put("act_id", actId);
|
|
|
|
actRedPacketsCustomerMapper.update(config);
|
|
|
|
actRedPacketsCustomerMapper.update(config);
|
|
|
|
|
|
|
|
|
|
|
|
for (JSONObject prize_type : prize_type_list) {
|
|
|
|
for (JSONObject prizeType : prizeTypeList) {
|
|
|
|
actPrizeTypeCustomerMapper.update(prize_type);
|
|
|
|
actPrizeTypeCustomerMapper.update(prizeType);
|
|
|
|
String type_id = prize_type.getString("type_id");
|
|
|
|
String typeId = prizeType.getString("type_id");
|
|
|
|
BigDecimal amountFrom = prize_type.getBigDecimal("price_value_from");
|
|
|
|
BigDecimal amountFrom = prizeType.getBigDecimal("price_value_from");
|
|
|
|
BigDecimal amountTo = prize_type.getBigDecimal("price_value_to");
|
|
|
|
BigDecimal amountTo = prizeType.getBigDecimal("price_value_to");
|
|
|
|
int redpack_counts = prize_type.getIntValue("redpack_counts");
|
|
|
|
int redpackCounts = prizeType.getIntValue("redpack_counts");
|
|
|
|
if (redpack_counts > 0) {
|
|
|
|
if (redpackCounts > 0) {
|
|
|
|
for (int i = 0; i < redpack_counts; i++) {
|
|
|
|
for (int i = 0; i < redpackCounts; i++) {
|
|
|
|
BigDecimal amount = amountFrom.equals(amountTo) ? amountFrom
|
|
|
|
BigDecimal amount = amountFrom.equals(amountTo) ? amountFrom
|
|
|
|
: amountFrom.add(BigDecimal.valueOf(RandomUtils.nextInt(0, amountTo.subtract(amountFrom).multiply(CommonConsts.HUNDRED).intValue()))
|
|
|
|
: amountFrom.add(BigDecimal.valueOf(RandomUtils.nextInt(0, amountTo.subtract(amountFrom).multiply(CommonConsts.HUNDRED).intValue()))
|
|
|
|
.divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_DOWN));
|
|
|
|
.divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_DOWN));
|
|
|
|
JSONObject prize = new JSONObject();
|
|
|
|
JSONObject prize = new JSONObject();
|
|
|
|
String prefix = DateFormatUtils.format(new Date(), "yyyyMMddHHmmssSSS");
|
|
|
|
String prefix = DateFormatUtils.format(new Date(), "yyyyMMddHHmmssSSS");
|
|
|
|
String red_packet_order_id = prefix + RandomStringUtils.random(28 - prefix.length(), true, true);
|
|
|
|
String redpackOrderId = prefix + RandomStringUtils.random(28 - prefix.length(), true, true);
|
|
|
|
prize.put("red_packet_customer_order_id", red_packet_order_id);
|
|
|
|
prize.put("red_packet_customer_order_id", redpackOrderId);
|
|
|
|
prize.put("act_id", act_id);
|
|
|
|
prize.put("act_id", actId);
|
|
|
|
prize.put("red_packet_amount", amount);
|
|
|
|
prize.put("red_packet_amount", amount);
|
|
|
|
prize.put("red_pack_type_id", type_id);
|
|
|
|
prize.put("red_pack_type_id", typeId);
|
|
|
|
prize.put("create_time", prizeDate);
|
|
|
|
prize.put("create_time", prizeDate);
|
|
|
|
actRedPacketsCustomerOrdersMapper.saveLog(prize);
|
|
|
|
actRedPacketsCustomerOrdersMapper.saveLog(prize);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -296,7 +302,7 @@ public class ActRedPackServiceImpl implements ActRedPackService {
|
|
|
|
pool.execute(() -> {
|
|
|
|
pool.execute(() -> {
|
|
|
|
JSONObject clientApply = actClientApplyMapper.findActivity(actId, redpack.getIntValue("client_id"));
|
|
|
|
JSONObject clientApply = actClientApplyMapper.findActivity(actId, redpack.getIntValue("client_id"));
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
doSendActLuckyMoney(redpack.getString("open_id"), redpack.getString("lock"), clientApply.getString("act_name"),
|
|
|
|
doSendWechatActLuckyMoney(redpack.getString("open_id"), redpack.getString("lock"), clientApply.getString("act_name"),
|
|
|
|
clientApply.getString("send_name"), clientApply.getString("wishing"));
|
|
|
|
clientApply.getString("send_name"), clientApply.getString("wishing"));
|
|
|
|
} catch (RedPackException e) {
|
|
|
|
} catch (RedPackException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
@ -307,9 +313,9 @@ public class ActRedPackServiceImpl implements ActRedPackService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<JSONObject> getCustomerRedpackAnalysis(String act_id, RedpackQuery redpackQuery) {
|
|
|
|
public List<JSONObject> getCustomerRedpackAnalysis(String actId, RedpackQuery redpackQuery) {
|
|
|
|
JSONObject params = redpackQuery.params();
|
|
|
|
JSONObject params = redpackQuery.params();
|
|
|
|
params.put("act_id", act_id);
|
|
|
|
params.put("act_id", actId);
|
|
|
|
return actRedPacketsCustomerOrdersMapper.getCustomerRedpackAnalysis(params);
|
|
|
|
return actRedPacketsCustomerOrdersMapper.getCustomerRedpackAnalysis(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|