红包活动

master
taylor.dang 6 years ago
parent 08ec9840c5
commit 23249eea35

@ -123,7 +123,7 @@ public class ActRedPackServiceImpl implements ActRedPackService {
} }
if (ruleOrderTotal != null) { if (ruleOrderTotal != null) {
if (!(currencyAmount.compareTo(ruleOrderTotal) >= 0)) { if (!(currencyAmount.compareTo(ruleOrderTotal) >= 0)) {
logger.info("订单金额不满足活动要求金额"); logger.info("订单金额不满足 [{}] 红包活动要求金额",actName);
return; return;
} }
} }
@ -133,29 +133,29 @@ public class ActRedPackServiceImpl implements ActRedPackService {
int getTotalCounts = getRedPacketsByOpenid(customerId, 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("customerId:" + customerId + "已达到本次活动发送最大次数" + ruleMaxNum + "!跳过"); logger.debug("customerId:" + customerId + "已达到本次 [{}] 红包活动发送最大次数" + ruleMaxNum + "!跳过",actName);
return; return;
} }
int getDailyTotalCounts = getRedPacketsByOpenid(customerId, 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("customerId:" + customerId + "已达当日发送最大次数" + ruleMaxNumLimit + "!跳过"); logger.debug("customerId:" + customerId + "已达 [{}] 红包活动当日发送最大次数" + ruleMaxNumLimit + "!跳过",actName);
return; return;
} }
takeRedpack(actId, orderId, clientId, clientApply, currencyAmount, customerId, 0); takeRedpack(actId, orderId, clientId, clientApply, currencyAmount, customerId,actName, 0);
} }
private void takeRedpack(String actId, String orderId, int clientId, JSONObject clientApply, BigDecimal currencyAmount, String customerId, int tryTimes) private void takeRedpack(String actId, String orderId, int clientId, JSONObject clientApply, BigDecimal currencyAmount, String customerId, String actName, int tryTimes)
throws RedPackException { throws RedPackException {
if (tryTimes > 5) { if (tryTimes > 5) {
return; return;
} }
int random = (int) (Math.random() * 100); int random = (int) (Math.random() * 100);
if (random > 80) { if (random > 80) {
logger.info("未达到触发概率当前概率为:" + random); logger.info("未达到 [{}] 红包活动触发概率,当前概率为:" + random, actName);
return; return;
} }
@ -177,7 +177,7 @@ public class ActRedPackServiceImpl implements ActRedPackService {
doSendWechatActLuckyMoney(customerId, 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, clientId, clientApply, currencyAmount, customerId, tryTimes + 1); takeRedpack(actId, orderId, clientId, clientApply, currencyAmount, customerId, actName, tryTimes + 1);
break; break;
} }
} }
@ -186,6 +186,7 @@ public class ActRedPackServiceImpl implements ActRedPackService {
@Override @Override
public void doSendWechatActLuckyMoney(String paymentOpenId, String lock, String actName, String sendName, String wishing) throws RedPackException { public void doSendWechatActLuckyMoney(String paymentOpenId, String lock, String actName, String sendName, String wishing) throws RedPackException {
logger.info("开始给支付用户 [{}] 发送 [{}--{}]红包", paymentOpenId, actName, lock);
JSONObject prizeDetail = actRedPacketsCustomerOrdersMapper.findLockedPrize(lock, paymentOpenId); JSONObject prizeDetail = actRedPacketsCustomerOrdersMapper.findLockedPrize(lock, paymentOpenId);
BigDecimal luckyMoeny = prizeDetail.getBigDecimal("red_packet_amount"); BigDecimal luckyMoeny = prizeDetail.getBigDecimal("red_packet_amount");
String redPackOrderId = prizeDetail.getString("red_packet_order_id"); String redPackOrderId = prizeDetail.getString("red_packet_order_id");
@ -216,6 +217,7 @@ public class ActRedPackServiceImpl implements ActRedPackService {
prizeDetail.put("red_packet_id", redPacketId); prizeDetail.put("red_packet_id", redPacketId);
prizeDetail.put("status", 1); prizeDetail.put("status", 1);
actRedPacketsCustomerOrdersMapper.update(prizeDetail); actRedPacketsCustomerOrdersMapper.update(prizeDetail);
logger.info("支付用户 [{}] 发送 [{}--{}] 红包结束", paymentOpenId, actName, lock);
} }
@Override @Override

@ -16,7 +16,7 @@ import javax.annotation.Resource;
* Created by yishuqian on 01/02/2017. * Created by yishuqian on 01/02/2017.
*/ */
@Component @Component
@ConditionalOnProperty(value = "app.run-tasks", havingValue = "false") @ConditionalOnProperty(value = "app.run-tasks", havingValue = "true")
public class RedPackTaskManager { public class RedPackTaskManager {
private Logger logger = LoggerFactory.getLogger(getClass()); private Logger logger = LoggerFactory.getLogger(getClass());
@ -32,7 +32,7 @@ public class RedPackTaskManager {
synchronizedScheduler.executeProcess("manage_task:updateRedpackStatus", 120_000, () -> redpackService.updateRedPacketsStatus("3")); synchronizedScheduler.executeProcess("manage_task:updateRedpackStatus", 120_000, () -> redpackService.updateRedPacketsStatus("3"));
} }
@Scheduled(cron = "0 0/10 * * * ?") // @Scheduled(cron = "0 0/10 * * * ?")
public void updateAlipayRedPackStatus() { public void updateAlipayRedPackStatus() {
synchronizedScheduler.executeProcess("manage_task:updateAlipayRedpackStatus", 120_000, () -> redpackService.updateAlipayRedPacketsStatus("3")); synchronizedScheduler.executeProcess("manage_task:updateAlipayRedpackStatus", 120_000, () -> redpackService.updateAlipayRedPacketsStatus("3"));
} }
@ -40,6 +40,8 @@ public class RedPackTaskManager {
@Scheduled(cron = "0 0/3 * * * *") @Scheduled(cron = "0 0/3 * * * *")
public void resendFailedRedpack() { public void resendFailedRedpack() {
logger.info("auto resend Redpack Task Fired");
synchronizedScheduler.executeProcess("manage_task:resendFailedRedpack", 120_000, () -> actRedPackService.resendFailed()); synchronizedScheduler.executeProcess("manage_task:resendFailedRedpack", 120_000, () -> actRedPackService.resendFailed());
logger.info("auto resend Redpack Task End");
} }
} }

Loading…
Cancel
Save