From f4a0f2acc63d7785eab108419a4e16f5f688cb95 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期六, 18 一月 2020 12:06:27 +0800 Subject: [PATCH] 用户注册信息 --- fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java | 156 ++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 134 insertions(+), 22 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java index e2099b1..16202d2 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.yeshi.utils.NumberUtil; import org.yeshi.utils.exception.WXOrderException; import com.aliyun.openservices.ons.api.Message; @@ -15,14 +16,24 @@ import com.google.gson.Gson; import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum; import com.yeshi.fanli.dto.mq.order.body.BanLiShopOrderMQMsg; +import com.yeshi.fanli.dto.msg.MsgRedPackUseContentDTO; +import com.yeshi.fanli.entity.bus.msg.MsgMoneyDetail.MsgTypeMoneyTypeEnum; +import com.yeshi.fanli.entity.common.AdminUser; +import com.yeshi.fanli.entity.common.Config; import com.yeshi.fanli.entity.redpack.RedPackDetail; import com.yeshi.fanli.entity.shop.BanLiShopGoods; import com.yeshi.fanli.entity.shop.BanLiShopGoodsClass; import com.yeshi.fanli.entity.shop.BanLiShopGoodsSets; import com.yeshi.fanli.entity.shop.BanLiShopOrder; +import com.yeshi.fanli.entity.shop.ChargeTypeEnum; +import com.yeshi.fanli.entity.system.ConfigKeyEnum; import com.yeshi.fanli.exception.redpack.RedPackBalanceException; import com.yeshi.fanli.exception.redpack.RedPackDetailException; import com.yeshi.fanli.exception.shop.BanLiShopOrderException; +import com.yeshi.fanli.exception.shop.FuLuChargeException; +import com.yeshi.fanli.service.AdminUserService; +import com.yeshi.fanli.service.inter.config.ConfigService; +import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService; import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService; import com.yeshi.fanli.service.inter.redpack.RedPackDetailService; import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsClassService; @@ -30,7 +41,13 @@ import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsSetService; import com.yeshi.fanli.service.inter.shop.BanLiShopOrderPayService; import com.yeshi.fanli.service.inter.shop.BanLiShopOrderService; +import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.StringUtil; +import com.yeshi.fanli.util.ThreadUtil; +import com.yeshi.fanli.util.charge.FuLuChargeApiUtil; +import com.yeshi.fanli.util.email.MailSenderUtil; import com.yeshi.fanli.util.factory.RedPackDetailFactory; +import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory; import com.yeshi.fanli.util.rocketmq.MQTopicName; import com.yeshi.fanli.util.wx.BanLiShopWXPayUtil; @@ -54,10 +71,19 @@ @Resource private RedPackDetailService redPackDetailService; + @Resource + private UserMoneyMsgNotificationService userMoneyMsgNotificationService; + + @Resource + private ConfigService configService; + + @Resource + private AdminUserService adminUserService; + @Resource(name = "producer") private Producer producer; - @Transactional + @Transactional(rollbackFor = Exception.class) @Override public void payOrderByHongBao(Long orderId) throws BanLiShopOrderException, RedPackBalanceException { BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId); @@ -96,14 +122,17 @@ || order.getBalancePaymentState() == BanLiShopOrder.PAY_STATE_PAID) && (order.getMoneyPaymentState() == null || order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_PAID))// 鍏朵粬寰呮敮浠橀」宸茬粡鏀粯 + { update.setState(BanLiShopOrder.STATE_PAID); + update.setStateDesc("鏀粯鎴愬姛"); + } banLiShopOrderService.udpateSelectiveByPrimaryKey(update); if (update.getState() != null && update.getState() == BanLiShopOrder.STATE_PAID) { paySuccess(order); } } - @Transactional + @Transactional(rollbackFor=Exception.class) @Override public void payOrderByMoney(Long orderId, BigDecimal money) throws BanLiShopOrderException { BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId); @@ -132,7 +161,10 @@ || order.getBalancePaymentState() == BanLiShopOrder.PAY_STATE_PAID) && (order.getHongBaoPaymentState() == null || order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID))// 鍏朵粬寰呮敮浠橀」宸茬粡鏀粯 + { update.setState(BanLiShopOrder.STATE_PAID); + update.setStateDesc("鏀粯鎴愬姛"); + } banLiShopOrderService.udpateSelectiveByPrimaryKey(update); if (update.getState() != null && update.getState() == BanLiShopOrder.STATE_PAID) { paySuccess(order); @@ -143,21 +175,27 @@ * 鏀粯鎴愬姛 */ private void paySuccess(BanLiShopOrder order) { - // 灏嗙孩鍖呮槑缁嗗鏄� - RedPackDetail detail = null; - try { - detail = RedPackDetailFactory.createUseByShopOrder(order.getId(), order.getUid(), "", "", - order.getHongBaoPayment()); - } catch (RedPackDetailException e) { - e.printStackTrace(); - } - - if (detail != null) { - redPackDetailService.changeDisplayByIdentifyCode(detail.getIdentifyCode(), true); - } + ThreadUtil.run(new Runnable() { + + @Override + public void run() { + long[] targetUids = new long[] { 3L, 4L }; + Config config = configService.getConfig(ConfigKeyEnum.extractCodeEmailFrom.getKey()); + String[] sts = config.getValue().split(","); + String account = sts[0]; + String pwd = sts[1]; + for (long adminId : targetUids) { + AdminUser adminUser = adminUserService.selectByPrimaryKey(adminId); + String msg = "鏈夋柊鐨勭孩鍖呭晢鍩庤鍗�"; + boolean isS = MailSenderUtil.sendEmail(adminUser.getEmail(), account, pwd, "鏈夋柊鐨勭孩鍖呭晢鍩庤鍗�", msg); + } + } + }); + + } - @Transactional + @Transactional(rollbackFor=Exception.class) @Override public void refund(Long orderId) throws BanLiShopOrderException { // 璁㈠崟閫�娆� @@ -165,7 +203,8 @@ BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId); if (order == null) throw new BanLiShopOrderException(1, "璁㈠崟涓嶅瓨鍦�"); - if (order.getState() != BanLiShopOrder.STATE_REJECT) + if (order.getState() == BanLiShopOrder.STATE_REJECT_REFUND_FAIL + || order.getState() == BanLiShopOrder.STATE_REJECT_REFUND_SUCCESS) throw new BanLiShopOrderException(2, "璁㈠崟鏈鎷掔粷/璁㈠崟宸查��娆�"); BanLiShopOrder update = new BanLiShopOrder(); @@ -203,9 +242,9 @@ order.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_REFUNDING); // 鍙戦�侀��娆炬秷鎭� BanLiShopOrderMQMsg msg = new BanLiShopOrderMQMsg(order.getId(), order.getUid()); - Message message = new Message(MQTopicName.TOPIC_ORDER.name(), - OrderTopicTagEnum.banLiShopOrderRefund.name(), new Gson().toJson(msg).getBytes()); - message.setStartDeliverTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24L);// 寤舵椂24灏忔椂閫氱煡妫�娴嬪井淇¢��娆剧姸鎬� + Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, + OrderTopicTagEnum.banLiShopOrderRefund, msg); + message.setStartDeliverTime(System.currentTimeMillis() + 1000 * 60 * 5L);// 寤舵椂24灏忔椂閫氱煡妫�娴嬪井淇¢��娆剧姸鎬� SendResult result = producer.send(message); if (result == null) { throw new BanLiShopOrderException(8, "娑堟伅鍙戦�佸け璐�"); @@ -216,10 +255,9 @@ throw new BanLiShopOrderException(6, "寰俊鏀粯閫�娆惧け璐�"); } } - // 妫�鏌� 鏄惁閫�娆炬垚鍔� - if (update.getMoneyPaymentState() != null - && update.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_REFUNDING) { + if (order.getMoneyPaymentState() != null + && order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_REFUNDING) { try { boolean isS = BanLiShopWXPayUtil.isRefundSuccess(order.getOrderNo()); if (isS) { @@ -280,4 +318,78 @@ } } + @Transactional(rollbackFor = Exception.class) + @Override + public void charge(Long orderId) throws BanLiShopOrderException { + BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKey(orderId); + if (order == null) + throw new BanLiShopOrderException(1, "璁㈠崟涓嶅瓨鍦�"); + if (order.getState() != BanLiShopOrder.STATE_PAID) { + throw new BanLiShopOrderException(100, "璁㈠崟涓嶆槸澶勪簬浠樻鐘舵��"); + } + if (order.getChargeAccountType() == ChargeTypeEnum.phone) { + if (!StringUtil.isMobile(order.getChargeAccount())) { + throw new BanLiShopOrderException(101, "鐢佃瘽鍙风爜鏍煎紡涓嶆纭�"); + } + } else if (order.getChargeAccountType() == ChargeTypeEnum.qq) { + if (!NumberUtil.isNumeric(order.getChargeAccount())) { + throw new BanLiShopOrderException(101, "QQ鍙锋牸寮忛敊璇�"); + } + } else { + throw new BanLiShopOrderException(102, "闈炲厖鍊煎晢鍝�"); + } + // 鑾峰彇绂忕鐨勫椁� + BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId()); + if (set == null) { + throw new BanLiShopOrderException(104, "鍟嗗搧濂楅宸蹭笅绾�"); + } + + if (StringUtil.isNullOrEmpty(set.getChargeFuLuNum())) { + throw new BanLiShopOrderException(105, "绂忕鍏呭�糏D涓虹┖"); + } + + // 鏀瑰彉鐘舵�佷负鎴愬姛 + BanLiShopOrder update = new BanLiShopOrder(order.getId()); + update.setState(BanLiShopOrder.STATE_SUCCESS); + update.setStateDesc("鍏呭�兼垚鍔�"); + update.setUpdateTime(new Date()); + update.setSuccessTime(new Date()); + banLiShopOrderService.udpateSelectiveByPrimaryKey(update); + + if (order.getHongBaoPayment() != null && order.getHongBaoPayment().compareTo(new BigDecimal(0)) > 0) { + // 灏嗙孩鍖呮槑缁嗗鏄� + RedPackDetail detail = null; + try { + detail = RedPackDetailFactory.createUseByShopOrder(order.getId(), order.getUid(), "", "", + order.getHongBaoPayment()); + } catch (RedPackDetailException e) { + e.printStackTrace(); + } + + if (detail != null) { + redPackDetailService.changeDisplayByIdentifyCode(detail.getIdentifyCode(), true); + } + } + + // 娑堟伅鍙戦�� + MsgRedPackUseContentDTO dto = new MsgRedPackUseContentDTO(); + dto.setGoodsSetName(order.getOrderGoods().getSetName()); + dto.setHongBao(order.getHongBaoPayment()); + dto.setMoney(order.getMoneyPayment()); + dto.setTime(new Date()); + userMoneyMsgNotificationService.redPackMsg(order.getUid(), MsgTypeMoneyTypeEnum.redPackUseSuccess, + new Gson().toJson(dto), null); + + try { + if (Constant.IS_TEST) { + FuLuChargeApiUtil.shaXiangCharge(set.getChargeFuLuNum(), "banlishop" + order.getOrderNo(), + order.getChargeAccount()); + } else + FuLuChargeApiUtil.charge(set.getChargeFuLuNum(), "banlishop" + order.getOrderNo(), + order.getChargeAccount()); + } catch (FuLuChargeException e) { + throw new BanLiShopOrderException(e.getCode(), e.getMsg()); + } + } + } -- Gitblit v1.8.0