From 08654ffb7e7bce13eed82be041a615e6a32e3d9f Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Wed, 15 Nov 2023 14:52:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BD=E5=AE=B6=E5=8C=BA=E5=9F=9F=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E5=8A=9F=E8=83=BD=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/peanut/config/ShiroConfig.java | 1 + .../book/controller/BaseAreaController.java | 11 ++ .../book/controller/BuyOrderController.java | 160 +++++++++--------- .../book/controller/MyUserController.java | 4 +- .../modules/book/service/MyUserService.java | 2 +- .../book/service/impl/MyUserServiceImpl.java | 14 +- 6 files changed, 106 insertions(+), 86 deletions(-) diff --git a/src/main/java/com/peanut/config/ShiroConfig.java b/src/main/java/com/peanut/config/ShiroConfig.java index da30f515..72408404 100644 --- a/src/main/java/com/peanut/config/ShiroConfig.java +++ b/src/main/java/com/peanut/config/ShiroConfig.java @@ -59,6 +59,7 @@ public class ShiroConfig { filterMap.put("/pay/aliPay/notify","anon"); // 支付宝回调接口 filterMap.put("/pay/payNotify","anon"); // 微信回调接口 filterMap.put("/weChat/**","anon"); + filterMap.put("/book/baseArea/getAllBaseArea","anon");//登录前获取全部区域 // filterMap.put("/book/bookchaptercontent/**","anon"); filterMap.put("/book/user/**","anon"); filterMap.put("/webjars/**", "anon"); diff --git a/src/main/java/com/peanut/modules/book/controller/BaseAreaController.java b/src/main/java/com/peanut/modules/book/controller/BaseAreaController.java index f48942a1..3dd51d18 100644 --- a/src/main/java/com/peanut/modules/book/controller/BaseAreaController.java +++ b/src/main/java/com/peanut/modules/book/controller/BaseAreaController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; import java.util.Map; @RestController @@ -66,5 +67,15 @@ public class BaseAreaController { return R.ok().put("page",baseAreas); } + /** + * 获取全部国家领域 + * @return + */ + @RequestMapping("/getAllBaseArea") + public R getAllBaseArea(){ + List list = baseAreaService.list(); + return R.ok().put("baseAreas",list); + } + } diff --git a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java index 6128a343..4ec5687b 100644 --- a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java +++ b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java @@ -165,86 +165,88 @@ public class BuyOrderController { @RequestMapping("/buySave") @Transactional public R buySave(@RequestBody BuyOrder buyOrder) throws IOException { + + return R.error("app版本太低请升级后再购买!!"); // 获取订单详情 - List buyOrderDetails = buyOrder.getProducts(); - // 订单总金额 - BigDecimal totalPrice = new BigDecimal(0); - // 遍历商品总价计算 - for (BuyOrderDetail buyOrderDetail : buyOrderDetails) { - Integer productId = buyOrderDetail.getProductId(); - int quantity = buyOrderDetail.getQuantity(); - ShopProduct product = shopProductService.getById(productId); - BigDecimal price = getRealPrice(product); - if (!handleStock(buyOrderDetail, product)) { - return R.error(500, "库存不足"); - } - totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity))); - buyOrderDetail.setProductName(product.getProductName()); - buyOrderDetail.setProductPrice(product.getPrice()); - int originWeight = product.getWeight(); - int originWeightIntValue = originWeight / 100; - int originWeightDecimalValue = originWeightIntValue % 100; - buyOrderDetail.setWeight(BigDecimal.valueOf(originWeightIntValue).add(BigDecimal.valueOf(originWeightDecimalValue).divide(new BigDecimal(100), - MathContext.DECIMAL64))); - buyOrderDetail.setProductUrl(product.getProductImages()); - buyOrderDetail.setOrderStatus(Constants.ORDER_STATUS_TO_BE_PAID); - } - - totalPrice = totalPrice.subtract(useCouponAmount(buyOrder)); - totalPrice = totalPrice.add(getShoppingAmount(buyOrder)); - String orderSn = IdWorker.getTimeId().substring(0, 32); - buyOrder.setOrderSn(orderSn); - buyOrder.setPaymentDate(new Date()); - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("id", buyOrder.getAddressId()); - UserAddress userAddress = userAddressService.getOne(queryWrapper); - UserAddressVo vo = new UserAddressVo(); - vo = userAddressService.getAddressName(vo, userAddress.getRegionCode()); - buyOrder.setProvince(vo.getProvince()); - buyOrder.setCity(vo.getCity()); - buyOrder.setDistrict(vo.getCounty()); - buyOrder.setAddress(vo.getDetailAddress()); - buyOrderService.save(buyOrder); - - for (BuyOrderDetail buyOrderDetail : buyOrderDetails) { - buyOrderDetail.setOrderId(buyOrder.getOrderId()); - buyOrderDetail.setUserId(buyOrder.getUserId()); - if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) { - handleBuyCart(buyOrder, buyOrderDetail); - } - } - buyOrderDetailService.saveBatch(buyOrderDetails); - // 1. 虚拟币支付 - if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) { - buyOrder.setOrderStatus(Constants.ORDER_STATUS_TO_BE_SHIPPED); - MyUserEntity user = this.myUserService.getById(buyOrder.getUserId()); - if (usePeanutCoin(user, totalPrice)) { - // 更新订单状态 - buyOrderService.updateOrderStatus(user.getId(), buyOrder.getOrderSn(), "0"); - recordTransaction(buyOrder, user, totalPrice); - addEbookToUser(buyOrderDetails, buyOrder); - } else { - return R.error(500, "花生币余额不足!"); - } - } - // 2. 微信支付 - if (Constants.PAYMENT_METHOD_WECHAT_PAY.equals(buyOrder.getPaymentMethod())) { - rabbitTemplate.convertAndSend( - DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE, - DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY, - buyOrder.getOrderId(), - messagePostProcessor() - ); - WechatPaymentInfo paymentInfo = new WechatPaymentInfo(); - paymentInfo.setOrderSn(orderSn); - paymentInfo.setBuyOrderId(buyOrder.getOrderId()); - paymentInfo.setTotalAmount(totalPrice); - wxpayService.prepay(paymentInfo); - } - Map result = new HashMap<>(); - result.put("orderSn", buyOrder.getOrderSn()); - result.put("money", totalPrice); - return R.ok(result); +// List buyOrderDetails = buyOrder.getProducts(); +// // 订单总金额 +// BigDecimal totalPrice = new BigDecimal(0); +// // 遍历商品总价计算 +// for (BuyOrderDetail buyOrderDetail : buyOrderDetails) { +// Integer productId = buyOrderDetail.getProductId(); +// int quantity = buyOrderDetail.getQuantity(); +// ShopProduct product = shopProductService.getById(productId); +// BigDecimal price = getRealPrice(product); +// if (!handleStock(buyOrderDetail, product)) { +// return R.error(500, "库存不足"); +// } +// totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity))); +// buyOrderDetail.setProductName(product.getProductName()); +// buyOrderDetail.setProductPrice(product.getPrice()); +// int originWeight = product.getWeight(); +// int originWeightIntValue = originWeight / 100; +// int originWeightDecimalValue = originWeightIntValue % 100; +// buyOrderDetail.setWeight(BigDecimal.valueOf(originWeightIntValue).add(BigDecimal.valueOf(originWeightDecimalValue).divide(new BigDecimal(100), +// MathContext.DECIMAL64))); +// buyOrderDetail.setProductUrl(product.getProductImages()); +// buyOrderDetail.setOrderStatus(Constants.ORDER_STATUS_TO_BE_PAID); +// } +// +// totalPrice = totalPrice.subtract(useCouponAmount(buyOrder)); +// totalPrice = totalPrice.add(getShoppingAmount(buyOrder)); +// String orderSn = IdWorker.getTimeId().substring(0, 32); +// buyOrder.setOrderSn(orderSn); +// buyOrder.setPaymentDate(new Date()); +// QueryWrapper queryWrapper = new QueryWrapper<>(); +// queryWrapper.eq("id", buyOrder.getAddressId()); +// UserAddress userAddress = userAddressService.getOne(queryWrapper); +// UserAddressVo vo = new UserAddressVo(); +// vo = userAddressService.getAddressName(vo, userAddress.getRegionCode()); +// buyOrder.setProvince(vo.getProvince()); +// buyOrder.setCity(vo.getCity()); +// buyOrder.setDistrict(vo.getCounty()); +// buyOrder.setAddress(vo.getDetailAddress()); +// buyOrderService.save(buyOrder); +// +// for (BuyOrderDetail buyOrderDetail : buyOrderDetails) { +// buyOrderDetail.setOrderId(buyOrder.getOrderId()); +// buyOrderDetail.setUserId(buyOrder.getUserId()); +// if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) { +// handleBuyCart(buyOrder, buyOrderDetail); +// } +// } +// buyOrderDetailService.saveBatch(buyOrderDetails); +// // 1. 虚拟币支付 +// if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) { +// buyOrder.setOrderStatus(Constants.ORDER_STATUS_TO_BE_SHIPPED); +// MyUserEntity user = this.myUserService.getById(buyOrder.getUserId()); +// if (usePeanutCoin(user, totalPrice)) { +// // 更新订单状态 +// buyOrderService.updateOrderStatus(user.getId(), buyOrder.getOrderSn(), "0"); +// recordTransaction(buyOrder, user, totalPrice); +// addEbookToUser(buyOrderDetails, buyOrder); +// } else { +// return R.error(500, "花生币余额不足!"); +// } +// } +// // 2. 微信支付 +// if (Constants.PAYMENT_METHOD_WECHAT_PAY.equals(buyOrder.getPaymentMethod())) { +// rabbitTemplate.convertAndSend( +// DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE, +// DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY, +// buyOrder.getOrderId(), +// messagePostProcessor() +// ); +// WechatPaymentInfo paymentInfo = new WechatPaymentInfo(); +// paymentInfo.setOrderSn(orderSn); +// paymentInfo.setBuyOrderId(buyOrder.getOrderId()); +// paymentInfo.setTotalAmount(totalPrice); +// wxpayService.prepay(paymentInfo); +// } +// Map result = new HashMap<>(); +// result.put("orderSn", buyOrder.getOrderSn()); +// result.put("money", totalPrice); +// return R.ok(result); } /** diff --git a/src/main/java/com/peanut/modules/book/controller/MyUserController.java b/src/main/java/com/peanut/modules/book/controller/MyUserController.java index 4a5a2596..15da37de 100644 --- a/src/main/java/com/peanut/modules/book/controller/MyUserController.java +++ b/src/main/java/com/peanut/modules/book/controller/MyUserController.java @@ -166,7 +166,7 @@ public class MyUserController { * 常规注册 发短信验证码 */ @RequestMapping("/sms/sendcode") - public R registerSms(@RequestParam("phone") String phone) throws Exception { + public R registerSms(@RequestParam("phone") String phone,@RequestParam Integer areaCode) throws Exception { //验证一分钟内是否已经发过 String redisCode = redisTemplate.opsForValue().get("RegistCode" + phone); @@ -192,7 +192,7 @@ public class MyUserController { redisTemplate.opsForValue().set("RegistCode"+phone,code,5, TimeUnit.MINUTES); //发送 - userService.sendCodeForRegister(phone,code); + userService.sendCodeForRegister(phone,code,areaCode); return R.ok(); } diff --git a/src/main/java/com/peanut/modules/book/service/MyUserService.java b/src/main/java/com/peanut/modules/book/service/MyUserService.java index 993788ed..f2eaeb7b 100644 --- a/src/main/java/com/peanut/modules/book/service/MyUserService.java +++ b/src/main/java/com/peanut/modules/book/service/MyUserService.java @@ -24,7 +24,7 @@ public interface MyUserService extends IService { PageUtils queryPage(Map params); - void sendCodeForRegister(String phone, String code) throws Exception; + void sendCodeForRegister(String phone, String code,Integer areaCode) throws Exception; //电子书鉴权 boolean bookAuthenticate(Integer bookId,Integer userId); diff --git a/src/main/java/com/peanut/modules/book/service/impl/MyUserServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/MyUserServiceImpl.java index 56a431b9..d482b345 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/MyUserServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/MyUserServiceImpl.java @@ -70,9 +70,9 @@ public class MyUserServiceImpl extends ServiceImpl impl } @Override - public void sendCodeForRegister(String phone, String code) throws Exception { + public void sendCodeForRegister(String phone, String code,Integer areaCode) throws Exception { String scode = code.split("_")[0]; - sendCode(phone,scode); + sendCode(phone,scode,areaCode); } @Override @@ -392,9 +392,15 @@ public class MyUserServiceImpl extends ServiceImpl impl } - private void sendCode(String phone, String code) throws Exception { + private void sendCode(String phone, String code,Integer areaCode) throws Exception { com.aliyun.dysmsapi20170525.Client client = Sample.createClient(smsConfig.getAccessKeyId(),smsConfig.getAccessKeySecret()); - String tem = TelUtil.isPhone(phone)?smsConfig.getTemplateCode():smsConfig.getSTemplateCode();//通过手机号判断是否为国内手机号,并设置模版 + String tem; + if(areaCode!=null&&areaCode>0&&areaCode!=86){ + tem = smsConfig.getSTemplateCode(); + phone = areaCode+phone; + }else{ + tem = smsConfig.getTemplateCode(); + } SendSmsRequest sendSmsRequest = new SendSmsRequest() .setSignName(smsConfig.getSingName()) .setTemplateCode(tem)