国家区域前端功能更新

This commit is contained in:
wangjinlei
2023-11-15 14:52:46 +08:00
parent 618639af70
commit 08654ffb7e
6 changed files with 106 additions and 86 deletions

View File

@@ -59,6 +59,7 @@ public class ShiroConfig {
filterMap.put("/pay/aliPay/notify","anon"); // 支付宝回调接口 filterMap.put("/pay/aliPay/notify","anon"); // 支付宝回调接口
filterMap.put("/pay/payNotify","anon"); // 微信回调接口 filterMap.put("/pay/payNotify","anon"); // 微信回调接口
filterMap.put("/weChat/**","anon"); filterMap.put("/weChat/**","anon");
filterMap.put("/book/baseArea/getAllBaseArea","anon");//登录前获取全部区域
// filterMap.put("/book/bookchaptercontent/**","anon"); // filterMap.put("/book/bookchaptercontent/**","anon");
filterMap.put("/book/user/**","anon"); filterMap.put("/book/user/**","anon");
filterMap.put("/webjars/**", "anon"); filterMap.put("/webjars/**", "anon");

View File

@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map; import java.util.Map;
@RestController @RestController
@@ -66,5 +67,15 @@ public class BaseAreaController {
return R.ok().put("page",baseAreas); return R.ok().put("page",baseAreas);
} }
/**
* 获取全部国家领域
* @return
*/
@RequestMapping("/getAllBaseArea")
public R getAllBaseArea(){
List<BaseAreaEntity> list = baseAreaService.list();
return R.ok().put("baseAreas",list);
}
} }

View File

@@ -165,86 +165,88 @@ public class BuyOrderController {
@RequestMapping("/buySave") @RequestMapping("/buySave")
@Transactional @Transactional
public R buySave(@RequestBody BuyOrder buyOrder) throws IOException { public R buySave(@RequestBody BuyOrder buyOrder) throws IOException {
return R.error("app版本太低请升级后再购买");
// 获取订单详情 // 获取订单详情
List<BuyOrderDetail> buyOrderDetails = buyOrder.getProducts(); // List<BuyOrderDetail> buyOrderDetails = buyOrder.getProducts();
// 订单总金额 // // 订单总金额
BigDecimal totalPrice = new BigDecimal(0); // BigDecimal totalPrice = new BigDecimal(0);
// 遍历商品总价计算 // // 遍历商品总价计算
for (BuyOrderDetail buyOrderDetail : buyOrderDetails) { // for (BuyOrderDetail buyOrderDetail : buyOrderDetails) {
Integer productId = buyOrderDetail.getProductId(); // Integer productId = buyOrderDetail.getProductId();
int quantity = buyOrderDetail.getQuantity(); // int quantity = buyOrderDetail.getQuantity();
ShopProduct product = shopProductService.getById(productId); // ShopProduct product = shopProductService.getById(productId);
BigDecimal price = getRealPrice(product); // BigDecimal price = getRealPrice(product);
if (!handleStock(buyOrderDetail, product)) { // if (!handleStock(buyOrderDetail, product)) {
return R.error(500, "库存不足"); // return R.error(500, "库存不足");
} // }
totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity))); // totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity)));
buyOrderDetail.setProductName(product.getProductName()); // buyOrderDetail.setProductName(product.getProductName());
buyOrderDetail.setProductPrice(product.getPrice()); // buyOrderDetail.setProductPrice(product.getPrice());
int originWeight = product.getWeight(); // int originWeight = product.getWeight();
int originWeightIntValue = originWeight / 100; // int originWeightIntValue = originWeight / 100;
int originWeightDecimalValue = originWeightIntValue % 100; // int originWeightDecimalValue = originWeightIntValue % 100;
buyOrderDetail.setWeight(BigDecimal.valueOf(originWeightIntValue).add(BigDecimal.valueOf(originWeightDecimalValue).divide(new BigDecimal(100), // buyOrderDetail.setWeight(BigDecimal.valueOf(originWeightIntValue).add(BigDecimal.valueOf(originWeightDecimalValue).divide(new BigDecimal(100),
MathContext.DECIMAL64))); // MathContext.DECIMAL64)));
buyOrderDetail.setProductUrl(product.getProductImages()); // buyOrderDetail.setProductUrl(product.getProductImages());
buyOrderDetail.setOrderStatus(Constants.ORDER_STATUS_TO_BE_PAID); // buyOrderDetail.setOrderStatus(Constants.ORDER_STATUS_TO_BE_PAID);
} // }
//
totalPrice = totalPrice.subtract(useCouponAmount(buyOrder)); // totalPrice = totalPrice.subtract(useCouponAmount(buyOrder));
totalPrice = totalPrice.add(getShoppingAmount(buyOrder)); // totalPrice = totalPrice.add(getShoppingAmount(buyOrder));
String orderSn = IdWorker.getTimeId().substring(0, 32); // String orderSn = IdWorker.getTimeId().substring(0, 32);
buyOrder.setOrderSn(orderSn); // buyOrder.setOrderSn(orderSn);
buyOrder.setPaymentDate(new Date()); // buyOrder.setPaymentDate(new Date());
QueryWrapper<UserAddress> queryWrapper = new QueryWrapper<>(); // QueryWrapper<UserAddress> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", buyOrder.getAddressId()); // queryWrapper.eq("id", buyOrder.getAddressId());
UserAddress userAddress = userAddressService.getOne(queryWrapper); // UserAddress userAddress = userAddressService.getOne(queryWrapper);
UserAddressVo vo = new UserAddressVo(); // UserAddressVo vo = new UserAddressVo();
vo = userAddressService.getAddressName(vo, userAddress.getRegionCode()); // vo = userAddressService.getAddressName(vo, userAddress.getRegionCode());
buyOrder.setProvince(vo.getProvince()); // buyOrder.setProvince(vo.getProvince());
buyOrder.setCity(vo.getCity()); // buyOrder.setCity(vo.getCity());
buyOrder.setDistrict(vo.getCounty()); // buyOrder.setDistrict(vo.getCounty());
buyOrder.setAddress(vo.getDetailAddress()); // buyOrder.setAddress(vo.getDetailAddress());
buyOrderService.save(buyOrder); // buyOrderService.save(buyOrder);
//
for (BuyOrderDetail buyOrderDetail : buyOrderDetails) { // for (BuyOrderDetail buyOrderDetail : buyOrderDetails) {
buyOrderDetail.setOrderId(buyOrder.getOrderId()); // buyOrderDetail.setOrderId(buyOrder.getOrderId());
buyOrderDetail.setUserId(buyOrder.getUserId()); // buyOrderDetail.setUserId(buyOrder.getUserId());
if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) { // if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) {
handleBuyCart(buyOrder, buyOrderDetail); // handleBuyCart(buyOrder, buyOrderDetail);
} // }
} // }
buyOrderDetailService.saveBatch(buyOrderDetails); // buyOrderDetailService.saveBatch(buyOrderDetails);
// 1. 虚拟币支付 // // 1. 虚拟币支付
if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) { // if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) {
buyOrder.setOrderStatus(Constants.ORDER_STATUS_TO_BE_SHIPPED); // buyOrder.setOrderStatus(Constants.ORDER_STATUS_TO_BE_SHIPPED);
MyUserEntity user = this.myUserService.getById(buyOrder.getUserId()); // MyUserEntity user = this.myUserService.getById(buyOrder.getUserId());
if (usePeanutCoin(user, totalPrice)) { // if (usePeanutCoin(user, totalPrice)) {
// 更新订单状态 // // 更新订单状态
buyOrderService.updateOrderStatus(user.getId(), buyOrder.getOrderSn(), "0"); // buyOrderService.updateOrderStatus(user.getId(), buyOrder.getOrderSn(), "0");
recordTransaction(buyOrder, user, totalPrice); // recordTransaction(buyOrder, user, totalPrice);
addEbookToUser(buyOrderDetails, buyOrder); // addEbookToUser(buyOrderDetails, buyOrder);
} else { // } else {
return R.error(500, "花生币余额不足!"); // return R.error(500, "花生币余额不足!");
} // }
} // }
// 2. 微信支付 // // 2. 微信支付
if (Constants.PAYMENT_METHOD_WECHAT_PAY.equals(buyOrder.getPaymentMethod())) { // if (Constants.PAYMENT_METHOD_WECHAT_PAY.equals(buyOrder.getPaymentMethod())) {
rabbitTemplate.convertAndSend( // rabbitTemplate.convertAndSend(
DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE, // DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE,
DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY, // DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY,
buyOrder.getOrderId(), // buyOrder.getOrderId(),
messagePostProcessor() // messagePostProcessor()
); // );
WechatPaymentInfo paymentInfo = new WechatPaymentInfo(); // WechatPaymentInfo paymentInfo = new WechatPaymentInfo();
paymentInfo.setOrderSn(orderSn); // paymentInfo.setOrderSn(orderSn);
paymentInfo.setBuyOrderId(buyOrder.getOrderId()); // paymentInfo.setBuyOrderId(buyOrder.getOrderId());
paymentInfo.setTotalAmount(totalPrice); // paymentInfo.setTotalAmount(totalPrice);
wxpayService.prepay(paymentInfo); // wxpayService.prepay(paymentInfo);
} // }
Map<String, Object> result = new HashMap<>(); // Map<String, Object> result = new HashMap<>();
result.put("orderSn", buyOrder.getOrderSn()); // result.put("orderSn", buyOrder.getOrderSn());
result.put("money", totalPrice); // result.put("money", totalPrice);
return R.ok(result); // return R.ok(result);
} }
/** /**

View File

@@ -166,7 +166,7 @@ public class MyUserController {
* 常规注册 发短信验证码 * 常规注册 发短信验证码
*/ */
@RequestMapping("/sms/sendcode") @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); String redisCode = redisTemplate.opsForValue().get("RegistCode" + phone);
@@ -192,7 +192,7 @@ public class MyUserController {
redisTemplate.opsForValue().set("RegistCode"+phone,code,5, TimeUnit.MINUTES); redisTemplate.opsForValue().set("RegistCode"+phone,code,5, TimeUnit.MINUTES);
//发送 //发送
userService.sendCodeForRegister(phone,code); userService.sendCodeForRegister(phone,code,areaCode);
return R.ok(); return R.ok();
} }

View File

@@ -24,7 +24,7 @@ public interface MyUserService extends IService<MyUserEntity> {
PageUtils queryPage(Map<String, Object> params); PageUtils queryPage(Map<String, Object> 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); boolean bookAuthenticate(Integer bookId,Integer userId);

View File

@@ -70,9 +70,9 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
} }
@Override @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]; String scode = code.split("_")[0];
sendCode(phone,scode); sendCode(phone,scode,areaCode);
} }
@Override @Override
@@ -392,9 +392,15 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> 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()); 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() SendSmsRequest sendSmsRequest = new SendSmsRequest()
.setSignName(smsConfig.getSingName()) .setSignName(smsConfig.getSingName())
.setTemplateCode(tem) .setTemplateCode(tem)