Merge branch 'develop'

master
taylor.dang 6 years ago
commit de643f867a

@ -15,7 +15,7 @@ public interface ActRedPackService {
void sendActRedPackets(JSONObject order) throws RedPackException;
void doSendActLuckyMoney(String open_id, String lock, String actName, String sendName, String wishing) throws RedPackException;
void doSendWechatActLuckyMoney(String open_id, String lock, String actName, String sendName, String wishing) throws RedPackException;
void setRedpackConfg(String act_id, JSONObject config);

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

@ -24,7 +24,7 @@ import java.util.List;
* Created by wangning on 08/12/2016.
*/
@Service
public class CustomerLMServiceImp implements CustomerLMService {
public class CustomerLMServiceImpl implements CustomerLMService {
@Resource
private ActRedPacketsCustomerMapper actRedPacketsCustomerMapper;
@ -50,22 +50,22 @@ public class CustomerLMServiceImp implements CustomerLMService {
private String mpSupportAuthCode;
@Override
public JSONObject getActDetail(String act_id) {
JSONObject res = actRedPacketsCustomerMapper.findOne(act_id);
public JSONObject getActDetail(String actId) {
JSONObject res = actRedPacketsCustomerMapper.findOne(actId);
if (res == null) {
throw new NotFoundException("Activity Not Found");
}
List<JSONObject> priceTypes = actPrizeTypeCustomerMapper.listPrizeTypes(act_id);
List<JSONObject> priceTypes = actPrizeTypeCustomerMapper.listPrizeTypes(actId);
res.put("prize_type_list", priceTypes);
return res;
}
@Override
@Transactional
public void updateActivity(String act_id, JSONObject act) throws Exception {
JSONObject actInfo = actRedPacketsCustomerMapper.findOne(act_id);
public void updateActivity(String actId, JSONObject act) throws Exception {
JSONObject actInfo = actRedPacketsCustomerMapper.findOne(actId);
Assert.notNull(actInfo);
actRedPackService.setRedpackConfg(act_id, act);
actRedPackService.setRedpackConfg(actId, act);
}
@Override
@ -74,22 +74,22 @@ public class CustomerLMServiceImp implements CustomerLMService {
}
@Override
public void addClientApply(String act_id, String client_moniker, JSONObject params) throws Exception {
JSONObject actRedpacket = actRedPackService.getById(act_id);
public void addClientApply(String actId, String clientMoniker, JSONObject params) throws Exception {
JSONObject actRedpacket = actRedPackService.getById(actId);
if (actRedpacket == null) {
throw new NotFoundException("Please check the activity information");
}
JSONObject client = clientMapper.findClientByMoniker(client_moniker);
JSONObject client = clientMapper.findClientByMoniker(clientMoniker);
if (client == null) {
throw new NotFoundException("Please check the partner information");
}
JSONObject actClientApply = actClientApplyMapper.findActivity(act_id, client.getIntValue("client_id"));
JSONObject actClientApply = actClientApplyMapper.findActivity(actId, client.getIntValue("client_id"));
JSONObject record = new JSONObject();
if (actClientApply != null) {
record.put("id", actClientApply.getString("id"));
}
record.put("client_id", client.getString("client_id"));
record.put("act_id", act_id);
record.put("act_id", actId);
record.put("send_name", params.getString("send_name"));
record.put("act_name", params.getString("act_name"));
record.put("wishing", params.getString("wishing"));

@ -350,7 +350,8 @@
transform: rotate(-45deg);
}
.points-dialog .dialog-content{
width: 100%;
margin: auto;
width: 90%;
display: block;
position: relative;
margin-top: 130px;
@ -385,8 +386,8 @@
}
.points-content .coin{
width: 150px;
height: 150px;
width: 100px;
height: 100px;
position: relative;
background: url(/static/images/star.png) no-repeat;
background-size: contain;

Loading…
Cancel
Save