|
|
|
@ -15,13 +15,15 @@ import au.com.royalpay.payment.tools.connections.mpsupport.beans.WechatRedpack;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.NotFoundException;
|
|
|
|
|
import au.com.royalpay.payment.tools.utils.PageListUtils;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
|
|
|
|
|
import com.github.miemiedev.mybatis.paginator.domain.PageList;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
@ -30,7 +32,6 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Date;
|
|
|
|
@ -39,6 +40,8 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by wangning on 2017/8/10.
|
|
|
|
|
*/
|
|
|
|
@ -129,9 +132,17 @@ public class ActRedPackServiceImpl implements ActRedPackService {
|
|
|
|
|
int getTotalCounts = getRedPacketsByOpenid(open_id, new Date(), actId);
|
|
|
|
|
int ruleMaxNum = redpackCustomerActivity.getIntValue("rule_max_num");
|
|
|
|
|
if (getTotalCounts >= ruleMaxNum) {
|
|
|
|
|
logger.error("open_id:" + open_id + "当日红包发送数量已到达" + ruleMaxNum + "!跳过");
|
|
|
|
|
logger.debug("open_id:" + open_id + "已达到本次活动发送最大次数" + ruleMaxNum + "!跳过");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getDailyTotalCounts = getRedPacketsByOpenid(open_id, new Date(), actId);
|
|
|
|
|
int ruleMaxNumLimit = redpackCustomerActivity.getIntValue("rule_max_num_limit");
|
|
|
|
|
if (getDailyTotalCounts >= ruleMaxNumLimit) {
|
|
|
|
|
logger.debug("open_id:" + open_id + "已达当日发送最大次数" + ruleMaxNumLimit + "!跳过");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
takeRedpack(actId, orderId, client_id, clientApply, currencyAmount, open_id, 0);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -141,6 +152,12 @@ public class ActRedPackServiceImpl implements ActRedPackService {
|
|
|
|
|
if (tryTimes > 5) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int random = (int) (Math.random() * 100);
|
|
|
|
|
if (random > 80) {
|
|
|
|
|
logger.info("未达到触发概率当前概率为:" + random);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<JSONObject> prizeTypes = actPrizeTypeCustomerMapper.listAvailableTypes(actId);
|
|
|
|
|
Collections.shuffle(prizeTypes);
|
|
|
|
|
int totalWeight = 0;
|
|
|
|
@ -153,8 +170,8 @@ public class ActRedPackServiceImpl implements ActRedPackService {
|
|
|
|
|
ran -= prizeType.getIntValue("weight");
|
|
|
|
|
if (ran < 0) {
|
|
|
|
|
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, currencyAmount,
|
|
|
|
|
new Date());
|
|
|
|
|
int lockedCount = actRedPacketsCustomerOrdersMapper.lockPrize(actId, lock, prizeType.getString("type_id"), open_id, client_id, orderId,
|
|
|
|
|
currencyAmount, new Date());
|
|
|
|
|
if (lockedCount > 0) {
|
|
|
|
|
doSendActLuckyMoney(open_id, lock, clientApply.getString("act_name"), clientApply.getString("send_name"), clientApply.getString("wishing"));
|
|
|
|
|
break;
|
|
|
|
@ -277,7 +294,8 @@ public class ActRedPackServiceImpl implements ActRedPackService {
|
|
|
|
|
pool.execute(() -> {
|
|
|
|
|
JSONObject clientApply = actClientApplyMapper.findActivity(actId, redpack.getIntValue("client_id"));
|
|
|
|
|
try {
|
|
|
|
|
doSendActLuckyMoney(redpack.getString("open_id"), redpack.getString("lock"), clientApply.getString("act_name"), clientApply.getString("send_name"), clientApply.getString("wishing"));
|
|
|
|
|
doSendActLuckyMoney(redpack.getString("open_id"), redpack.getString("lock"), clientApply.getString("act_name"),
|
|
|
|
|
clientApply.getString("send_name"), clientApply.getString("wishing"));
|
|
|
|
|
} catch (RedPackException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|