format code
This commit is contained in:
@@ -28,7 +28,6 @@ import com.peanut.common.utils.PageUtils;
|
|||||||
import com.peanut.common.utils.R;
|
import com.peanut.common.utils.R;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单表
|
* 订单表
|
||||||
*
|
*
|
||||||
@@ -85,6 +84,31 @@ public class BuyOrderController {
|
|||||||
* 订单状态 - 待收货
|
* 订单状态 - 待收货
|
||||||
*/
|
*/
|
||||||
private static final String ORDER_STATUS_TO_BE_RECEIVED = "2";
|
private static final String ORDER_STATUS_TO_BE_RECEIVED = "2";
|
||||||
|
/**
|
||||||
|
* 支付方式 - 支付宝
|
||||||
|
*/
|
||||||
|
private static final String PAYMENT_METHOD_ALI_PAY = "1";
|
||||||
|
/**
|
||||||
|
* 支付方式
|
||||||
|
*/
|
||||||
|
private static final String PAYMENT_METHOD_WECHAT_PAY = "2";
|
||||||
|
/**
|
||||||
|
* 支付方式
|
||||||
|
*/
|
||||||
|
private static final String PAYMENT_METHOD_IOS = "3";
|
||||||
|
/**
|
||||||
|
* 支付方式
|
||||||
|
*/
|
||||||
|
private static final String PAYMENT_METHOD_VIRTUAL = "4";
|
||||||
|
/**
|
||||||
|
* 购买方式 - 直接购买
|
||||||
|
*/
|
||||||
|
private static final String BUY_TYPE_REDIRECT = "0";
|
||||||
|
/**
|
||||||
|
* 购买方式 - 购物车
|
||||||
|
*/
|
||||||
|
private static final String BUY_TYPE_CART = "1";
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ShopProudictBookService shopProudictBookService;
|
private ShopProudictBookService shopProudictBookService;
|
||||||
@@ -93,7 +117,6 @@ public class BuyOrderController {
|
|||||||
* 列表
|
* 列表
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/list")
|
@RequestMapping("/list")
|
||||||
// @RequiresPermissions("book:buyorder:list")
|
|
||||||
public R list(@RequestParam Map<String, Object> params) throws Exception {
|
public R list(@RequestParam Map<String, Object> params) throws Exception {
|
||||||
|
|
||||||
if ("all".equals(params.get("orderStatus"))) {
|
if ("all".equals(params.get("orderStatus"))) {
|
||||||
@@ -105,14 +128,12 @@ public class BuyOrderController {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param params
|
* @param params
|
||||||
* @return 听书未购买页面展示
|
* @return 听书未购买页面展示
|
||||||
* (销量最多的书,最先放最前面展示。最新上线的书,预售的书,放最前面展示
|
* (销量最多的书,最先放最前面展示。最新上线的书,预售的书,放最前面展示
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/lists")
|
@RequestMapping("/lists")
|
||||||
// @RequiresPermissions("book:buyorder:list")
|
|
||||||
public R lists(@RequestParam Map<String, Object> params) throws Exception {
|
public R lists(@RequestParam Map<String, Object> params) throws Exception {
|
||||||
|
|
||||||
if ("all".equals(params.get("orderStatus"))) {
|
if ("all".equals(params.get("orderStatus"))) {
|
||||||
@@ -123,15 +144,10 @@ public class BuyOrderController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 信息
|
* 信息
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/info/{orderId}")
|
@RequestMapping("/info/{orderId}")
|
||||||
// @RequiresPermissions("book:buyorder:info")
|
|
||||||
public R info(@PathVariable("orderId") Integer orderId) {
|
public R info(@PathVariable("orderId") Integer orderId) {
|
||||||
BuyOrderEntity buyOrder = buyOrderService.getById(orderId);
|
BuyOrderEntity buyOrder = buyOrderService.getById(orderId);
|
||||||
|
|
||||||
@@ -142,45 +158,37 @@ public class BuyOrderController {
|
|||||||
/**
|
/**
|
||||||
* 下单
|
* 下单
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/buysave")
|
@RequestMapping("/buySave")
|
||||||
@Transactional
|
@Transactional
|
||||||
public R buysave(@RequestBody BuyOrderEntity buyOrder){
|
public R buySave(@RequestBody BuyOrderEntity buyOrder) {
|
||||||
BigDecimal realMoney = new BigDecimal(0);
|
BigDecimal realMoney;
|
||||||
Lock l = new ReentrantLock();
|
|
||||||
l.lock();
|
|
||||||
try {
|
|
||||||
// 根据订单获取订单详情
|
// 根据订单获取订单详情
|
||||||
List<BuyOrderDetailEntity> products = buyOrder.getProducts();
|
List<BuyOrderDetailEntity> products = buyOrder.getProducts();
|
||||||
BigDecimal bigDecimal1 = new BigDecimal(0);
|
// ?
|
||||||
ArrayList<BuyOrderDetailEntity> list = new ArrayList<>();
|
BigDecimal totalPrice = new BigDecimal(0);
|
||||||
|
List<BuyOrderDetailEntity> list = new ArrayList<>();
|
||||||
// 遍历商品 查询价格
|
// 遍历商品 查询价格
|
||||||
for (BuyOrderDetailEntity buyOrderDetail : products) {
|
for (BuyOrderDetailEntity buyOrderDetail : products) {
|
||||||
BuyOrderDetailEntity buyOrderDetailEntity = new BuyOrderDetailEntity();
|
BuyOrderDetailEntity buyOrderDetailEntity = new BuyOrderDetailEntity();
|
||||||
Integer productId = buyOrderDetail.getProductId();
|
Integer productId = buyOrderDetail.getProductId();
|
||||||
ShopProductEntity product = shopProductService.getById(productId);
|
ShopProductEntity product = shopProductService.getById(productId);
|
||||||
BigDecimal activityPrice = product.getActivityPrice();
|
BigDecimal activityPrice = product.getActivityPrice();
|
||||||
BigDecimal big = new BigDecimal(0);
|
// 实际执行价格
|
||||||
BigDecimal price=null;
|
BigDecimal price;
|
||||||
|
if (activityPrice == null || activityPrice.equals(BigDecimal.ZERO)) {
|
||||||
//activityPrice等于 0,则原价
|
|
||||||
if (activityPrice.equals(big)||activityPrice==null) {
|
|
||||||
price = product.getPrice();
|
price = product.getPrice();
|
||||||
} else {
|
} else {
|
||||||
price = product.getActivityPrice();
|
price = product.getActivityPrice();
|
||||||
}
|
}
|
||||||
|
int quantity = buyOrderDetail.getQuantity();
|
||||||
|
totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity)));
|
||||||
|
|
||||||
Integer quantity = buyOrderDetail.getQuantity();
|
if (product.getProductStock() - quantity < 0) {
|
||||||
BigDecimal bigDecimal = new BigDecimal(price.doubleValue() * quantity);
|
|
||||||
System.out.println("bigDecimal=================bigDecimal======================"+bigDecimal);
|
|
||||||
bigDecimal1 = bigDecimal1.add(bigDecimal);
|
|
||||||
|
|
||||||
if (product.getProductStock() - buyOrderDetail.getQuantity() < 0 ){
|
|
||||||
return R.error(500, "库存不足");
|
return R.error(500, "库存不足");
|
||||||
}
|
}
|
||||||
// 改写 商品库存
|
// 更新商品库存
|
||||||
product.setProductStock(product.getProductStock() - buyOrderDetail.getQuantity());
|
product.setProductStock(product.getProductStock() - quantity);
|
||||||
product.setSumSales(product.getSumSales() + buyOrderDetail.getQuantity());
|
product.setSumSales(product.getSumSales() + quantity);
|
||||||
shopProductService.updateById(product);
|
shopProductService.updateById(product);
|
||||||
|
|
||||||
BeanUtils.copyProperties(buyOrderDetail, buyOrderDetailEntity);
|
BeanUtils.copyProperties(buyOrderDetail, buyOrderDetailEntity);
|
||||||
@@ -188,31 +196,30 @@ public class BuyOrderController {
|
|||||||
buyOrderDetailEntity.setProductPrice(product.getPrice());
|
buyOrderDetailEntity.setProductPrice(product.getPrice());
|
||||||
buyOrderDetailEntity.setAddressId(buyOrder.getAddressId());
|
buyOrderDetailEntity.setAddressId(buyOrder.getAddressId());
|
||||||
buyOrderDetailEntity.setProductUrl(product.getProductImages());
|
buyOrderDetailEntity.setProductUrl(product.getProductImages());
|
||||||
buyOrderDetailEntity.setOrderStatus("0");
|
buyOrderDetailEntity.setOrderStatus(ORDER_STATUS_TO_BE_PAID);
|
||||||
list.add(buyOrderDetailEntity);
|
list.add(buyOrderDetailEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer couponId = buyOrder.getCouponId();
|
Integer couponId = buyOrder.getCouponId();
|
||||||
|
|
||||||
if (couponId != null) {
|
if (couponId != null) {
|
||||||
CouponHistoryEntity byId = couponHistoryService.getById(couponId);
|
CouponHistoryEntity couponHistory = couponHistoryService.getById(couponId);
|
||||||
CouponEntity coupon = couponService.getById(byId.getCouponId());
|
CouponEntity coupon = couponService.getById(couponHistory.getCouponId());
|
||||||
BigDecimal amount = coupon.getCouponAmount();
|
BigDecimal amount = coupon.getCouponAmount();
|
||||||
bigDecimal1 = bigDecimal1.subtract(amount);
|
totalPrice = totalPrice.subtract(amount);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buyOrder.getShippingMoney() != null) {
|
if (buyOrder.getShippingMoney() != null) {
|
||||||
bigDecimal1 = bigDecimal1.add(buyOrder.getShippingMoney());
|
totalPrice = totalPrice.add(buyOrder.getShippingMoney());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 减去优惠券金额
|
// 减去优惠券金额
|
||||||
realMoney = buyOrder.getRealMoney();
|
realMoney = buyOrder.getRealMoney();
|
||||||
if (bigDecimal1.compareTo(realMoney) == 0) {
|
if (totalPrice.compareTo(realMoney) == 0) {
|
||||||
//特定格式的时间ID
|
//特定格式的时间ID
|
||||||
String timeId = IdWorker.getTimeId().substring(0, 32);
|
String timeId = IdWorker.getTimeId().substring(0, 32);
|
||||||
buyOrder.setOrderSn(timeId);
|
buyOrder.setOrderSn(timeId);
|
||||||
if("4".equals(buyOrder.getPaymentMethod())){
|
if (PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) {
|
||||||
buyOrder.setOrderStatus(ORDER_STATUS_TO_BE_SHIPPED);
|
buyOrder.setOrderStatus(ORDER_STATUS_TO_BE_SHIPPED);
|
||||||
}
|
}
|
||||||
buyOrder.setPaymentDate(new Date());
|
buyOrder.setPaymentDate(new Date());
|
||||||
@@ -221,20 +228,17 @@ public class BuyOrderController {
|
|||||||
for (BuyOrderDetailEntity buyOrderDetailEntity : list) {
|
for (BuyOrderDetailEntity buyOrderDetailEntity : list) {
|
||||||
buyOrderDetailEntity.setOrderId(buyOrder.getOrderId());
|
buyOrderDetailEntity.setOrderId(buyOrder.getOrderId());
|
||||||
buyOrderDetailEntity.setUserId(buyOrder.getUserId());
|
buyOrderDetailEntity.setUserId(buyOrder.getUserId());
|
||||||
|
// 判断结算状态
|
||||||
// 判断结算状态 下单 位置 0- 商品页直接下单 1- 购物车结算
|
|
||||||
String buyType = buyOrder.getBuyType();
|
String buyType = buyOrder.getBuyType();
|
||||||
|
if (buyType.equals(BUY_TYPE_CART)) {
|
||||||
if (buyType.equals("1")) {
|
|
||||||
// 更改购物车 状态
|
// 更改购物车 状态
|
||||||
List<OrderCartEntity> list1 = orderCartService.getBaseMapper().selectList(new QueryWrapper<OrderCartEntity>()
|
List<OrderCartEntity> orderCartList = orderCartService.getBaseMapper().selectList(new QueryWrapper<OrderCartEntity>()
|
||||||
.eq("user_id", buyOrder.getUserId()).eq("product_id", buyOrderDetailEntity.getProductId()));
|
.eq("user_id", buyOrder.getUserId()).eq("product_id", buyOrderDetailEntity.getProductId()));
|
||||||
if (list1.size() > 0){
|
if (orderCartList.size() > 0) {
|
||||||
List<Integer> collect = list1.stream().map(orderCartEntity -> {
|
List<Integer> collect = orderCartList.stream().map(orderCartEntity -> {
|
||||||
Integer cartId = orderCartEntity.getCartId();
|
Integer cartId = orderCartEntity.getCartId();
|
||||||
return cartId;
|
return cartId;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
orderCartService.removeByIds(collect);
|
orderCartService.removeByIds(collect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,278 +285,10 @@ public class BuyOrderController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}finally {
|
|
||||||
l.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
return R.ok().put("orderSn", buyOrder.getOrderSn()).put("money", realMoney);
|
return R.ok().put("orderSn", buyOrder.getOrderSn()).put("money", realMoney);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改购买书籍(赠送电子书,加鉴权)
|
|
||||||
* @param buyOrder 订单表
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@RequestMapping("/buysave1")
|
|
||||||
@Transactional
|
|
||||||
public R buysave1(@RequestBody BuyOrderEntity buyOrder) {
|
|
||||||
|
|
||||||
BigDecimal realMoney = new BigDecimal(0);
|
|
||||||
|
|
||||||
Lock l = new ReentrantLock();
|
|
||||||
l.lock();
|
|
||||||
try {
|
|
||||||
|
|
||||||
List<BuyOrderDetailEntity> products = buyOrder.getProducts();
|
|
||||||
|
|
||||||
|
|
||||||
BigDecimal bigDecimal1 = new BigDecimal(0);
|
|
||||||
|
|
||||||
ArrayList<BuyOrderDetailEntity> list = new ArrayList<>();
|
|
||||||
|
|
||||||
// 遍历商品 查询价格
|
|
||||||
for (BuyOrderDetailEntity buyOrderDetail : products) {
|
|
||||||
BuyOrderDetailEntity buyOrderDetailEntity = new BuyOrderDetailEntity();
|
|
||||||
Integer productId = buyOrderDetail.getProductId();
|
|
||||||
ShopProductEntity product = shopProductService.getById(productId);
|
|
||||||
// BigDecimal price = product.getPrice();
|
|
||||||
Integer quantity = buyOrderDetail.getQuantity();
|
|
||||||
BigDecimal activityPrice = product.getActivityPrice();
|
|
||||||
BigDecimal big = new BigDecimal(0);
|
|
||||||
BigDecimal price=null;
|
|
||||||
//activityPrice等于0,则原价
|
|
||||||
if (activityPrice == big) {
|
|
||||||
price = product.getPrice();
|
|
||||||
|
|
||||||
}else {
|
|
||||||
price = product.getActivityPrice();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//价格*数量 = 单价*购买数量赋值给bigDecimal1
|
|
||||||
BigDecimal bigDecimal = new BigDecimal(price.doubleValue() * quantity);
|
|
||||||
System.out.println("bigDecimal========bigDecimal=========bigDecimal======================"+bigDecimal);
|
|
||||||
bigDecimal1 = bigDecimal1.add(bigDecimal);
|
|
||||||
|
|
||||||
if (product.getProductStock() - buyOrderDetail.getQuantity() < 0) {
|
|
||||||
return R.error(500, "库存不足");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 改写 商品库存
|
|
||||||
product.setProductStock(product.getProductStock() - buyOrderDetail.getQuantity());
|
|
||||||
product.setSumSales(product.getSumSales() + buyOrderDetail.getQuantity());
|
|
||||||
shopProductService.updateById(product);
|
|
||||||
//buyOrderDetail 对象中的属性值复制到 buyOrderDetailEntity 对象中的属性值中
|
|
||||||
BeanUtils.copyProperties(buyOrderDetail, buyOrderDetailEntity);
|
|
||||||
buyOrderDetailEntity.setProductName(product.getProductName());
|
|
||||||
buyOrderDetailEntity.setProductPrice(product.getPrice());
|
|
||||||
buyOrderDetailEntity.setAddressId(buyOrder.getAddressId());
|
|
||||||
buyOrderDetailEntity.setProductUrl(product.getProductImages());
|
|
||||||
buyOrderDetailEntity.setOrderStatus("0");
|
|
||||||
list.add(buyOrderDetailEntity);
|
|
||||||
}
|
|
||||||
//优惠券Id couponId
|
|
||||||
Integer couponId = buyOrder.getCouponId();
|
|
||||||
|
|
||||||
if (couponId != null) {
|
|
||||||
CouponHistoryEntity byId = couponHistoryService.getById(couponId);
|
|
||||||
CouponEntity coupon = couponService.getById(byId.getCouponId());
|
|
||||||
BigDecimal amount = coupon.getCouponAmount();
|
|
||||||
bigDecimal1 = bigDecimal1.subtract(amount);
|
|
||||||
}
|
|
||||||
if (buyOrder.getShippingMoney() != null) {
|
|
||||||
bigDecimal1 = bigDecimal1.add(buyOrder.getShippingMoney());
|
|
||||||
}
|
|
||||||
// 减去优惠券金额
|
|
||||||
realMoney = buyOrder.getRealMoney();
|
|
||||||
if (bigDecimal1.compareTo(realMoney) == 0) {
|
|
||||||
//特定格式的时间ID
|
|
||||||
String timeId = IdWorker.getTimeId().substring(0, 32);
|
|
||||||
|
|
||||||
buyOrder.setOrderSn(timeId);
|
|
||||||
if ("4".equals(buyOrder.getPaymentMethod())) {
|
|
||||||
buyOrder.setOrderStatus("1");
|
|
||||||
|
|
||||||
}
|
|
||||||
//todo 增加结束时间
|
|
||||||
buyOrder.setPaymentDate(new Date());
|
|
||||||
buyOrderService.save(buyOrder);
|
|
||||||
|
|
||||||
for (BuyOrderDetailEntity buyetailEntity : list) {
|
|
||||||
|
|
||||||
buyetailEntity.setOrderId(buyOrder.getOrderId());
|
|
||||||
buyetailEntity.setUserId(buyOrder.getUserId());
|
|
||||||
|
|
||||||
// 判断结算状态 下单 位置 0- 商品页直接下单 1- 购物车结算
|
|
||||||
String buyType = buyOrder.getBuyType();
|
|
||||||
if (buyType.equals("1")) {
|
|
||||||
// 更改购物车 状态
|
|
||||||
List<OrderCartEntity> list1 = orderCartService.getBaseMapper().selectList(new QueryWrapper<OrderCartEntity>()
|
|
||||||
.eq("user_id", buyOrder.getUserId()).eq("product_id", buyetailEntity.getProductId()));
|
|
||||||
//将购物车列表转换为流,并从中提取每个购物车的 cartId。removeByIds() 方法从数据库中删除这些购物车记录。
|
|
||||||
if (list1.size() > 0) {
|
|
||||||
List<Integer> collect = list1.stream().map(orderCartEntity -> {
|
|
||||||
Integer cartId = orderCartEntity.getCartId();
|
|
||||||
return cartId;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
|
|
||||||
orderCartService.removeByIds(collect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
buyOrderDetailService.saveBatch(list);
|
|
||||||
if (couponId != null) {
|
|
||||||
//更改优惠券状态
|
|
||||||
CouponHistoryEntity one = couponHistoryService.getById(couponId);
|
|
||||||
one.setUseStatus(1);
|
|
||||||
one.setUseTime(new Date());
|
|
||||||
one.setOrderId(Long.valueOf(buyOrder.getOrderId()));
|
|
||||||
one.setOrderSn(buyOrder.getOrderSn());
|
|
||||||
couponHistoryService.updateById(one);
|
|
||||||
|
|
||||||
}
|
|
||||||
// 购买书籍直接赠送电子书听书
|
|
||||||
TransactionDetailsEntity transaction = new TransactionDetailsEntity();
|
|
||||||
|
|
||||||
//避免重复购买
|
|
||||||
TransactionDetailsEntity entity = transactionDetailsService.getBaseMapper().selectOne(new QueryWrapper<TransactionDetailsEntity>().eq("user_id", transaction.getUserId())
|
|
||||||
.eq("relation_id", transaction.getRelationId()));
|
|
||||||
if (entity != null) {
|
|
||||||
return R.error("余额不足,请充值!!!!!!!!!!!!!!!!");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<BuyOrderDetailEntity> produ = buyOrder.getProducts();
|
|
||||||
// 遍历商品 查询价格
|
|
||||||
for (BuyOrderDetailEntity buyOrdr : produ) {
|
|
||||||
Integer pId = buyOrdr.getProductId();
|
|
||||||
ShopProductEntity product1 = shopProductService.getById(pId);
|
|
||||||
String productName = product1.getProductName();
|
|
||||||
// 如果是虚拟币购买 减少用户的虚拟币数量
|
|
||||||
if ("4".equals(buyOrder.getPaymentMethod())) {
|
|
||||||
MyUserEntity user = this.myUserService.getById(buyOrder.getUserId());
|
|
||||||
if (user.getPeanutCoin().compareTo(realMoney) >= 0) {
|
|
||||||
user.setPeanutCoin(user.getPeanutCoin().subtract(realMoney));
|
|
||||||
this.myUserService.updateById(user);
|
|
||||||
// 添加消费信息
|
|
||||||
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
|
|
||||||
transactionDetailsEntity.setRemark("购买健康超市用品!订单编号为《 " + buyOrder.getOrderSn() + "》");
|
|
||||||
transactionDetailsEntity.setUserId(user.getId());
|
|
||||||
transactionDetailsEntity.setUserName(user.getNickname());
|
|
||||||
transactionDetailsEntity.setChangeAmount(realMoney.negate());
|
|
||||||
transactionDetailsEntity.setUserBalance(user.getPeanutCoin());
|
|
||||||
transactionDetailsEntity.setTel(user.getTel());
|
|
||||||
transactionDetailsEntity.setOrderType("购买《"+productName+"》赠送本书听书功能");
|
|
||||||
transactionDetailsService.save(transactionDetailsEntity);
|
|
||||||
} else {
|
|
||||||
return R.error("余额不足!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
for (BuyOrderDetailEntity buyOrderDetail : products) {
|
|
||||||
Integer productId = buyOrderDetail.getProductId();
|
|
||||||
ShopProductEntity product = shopProductService.getById(productId);
|
|
||||||
// 如果不等于空 则进行往下走
|
|
||||||
String authorName = "";
|
|
||||||
String bookId = product.getBookId();
|
|
||||||
if(null != bookId && !"".equals(bookId)){
|
|
||||||
List<String> bkids = new ArrayList<String>();
|
|
||||||
if(bookId.indexOf(",") == -1){
|
|
||||||
bkids.add(bookId);
|
|
||||||
}else {
|
|
||||||
for(String idObj : bookId.split(",")){
|
|
||||||
bkids.add(idObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(String b_id : bkids){
|
|
||||||
if (b_id != null) {
|
|
||||||
List<BookEntity> book = bookService.getBaseMapper().selectList(new QueryWrapper<BookEntity>().eq("id", b_id));
|
|
||||||
for (BookEntity bo : book) {
|
|
||||||
Integer id = bo.getId();
|
|
||||||
String name = bo.getName();
|
|
||||||
String images = bo.getImages();
|
|
||||||
String authorId = bo.getAuthorId();
|
|
||||||
if (book != null) {
|
|
||||||
UserEbookBuyEntity userEbookBuyEntity = new UserEbookBuyEntity();
|
|
||||||
userEbookBuyEntity.setUserId(Integer.valueOf(buyOrder.getUserId()));
|
|
||||||
userEbookBuyEntity.setBookId(Integer.valueOf(id));
|
|
||||||
String[] authorIds = authorId.split(",");
|
|
||||||
List<String> authorList = Arrays.asList(authorIds);
|
|
||||||
List<AuthorEntity> authorEntities = authorService.getBaseMapper().selectList(new QueryWrapper<AuthorEntity>().in("id", authorList));
|
|
||||||
//购买书籍表 userId bookName 商品订单详情表 userId productName
|
|
||||||
List<UserEbookBuyEntity> userId = userEbookBuyService.getBaseMapper().selectList(new QueryWrapper<UserEbookBuyEntity>()
|
|
||||||
.eq("user_Id", buyOrder.getUserId())
|
|
||||||
.eq("book_id", id));
|
|
||||||
for (AuthorEntity authorEntity : authorEntities) {
|
|
||||||
authorName += "," + authorEntity.getAuthorName();
|
|
||||||
}
|
|
||||||
|
|
||||||
//查询dengyu,则往下执行赠送电子书详情
|
|
||||||
if (userId != null && !userId.isEmpty()) {
|
|
||||||
// 如果userId不等于空则不赠送图书不执行任何方法
|
|
||||||
// return R.ok("此书已存在于您的书架");
|
|
||||||
} else {
|
|
||||||
authorName = authorName.startsWith(",") ? authorName.substring(1) : authorName;
|
|
||||||
userEbookBuyEntity.setAuthor(authorName);
|
|
||||||
userEbookBuyEntity.setImage(images);
|
|
||||||
userEbookBuyEntity.setPayStatus("赠送成功");
|
|
||||||
//这里后期需要修改字段内容
|
|
||||||
userEbookBuyEntity.setPayType("point");
|
|
||||||
userEbookBuyEntity.setPayTime(new Date());
|
|
||||||
userEbookBuyEntity.setBookName(name);
|
|
||||||
userEbookBuyService.save(userEbookBuyEntity);
|
|
||||||
//判断是否加入书架如果没有就加入听书书架
|
|
||||||
Integer integer = bookShelfService.getBaseMapper().selectCount(new QueryWrapper<BookShelfEntity>()
|
|
||||||
.eq("book_id", id)
|
|
||||||
.eq("user_id", userId));
|
|
||||||
//如果integer<0代表数据库没有这条数据,则添加,有就不执行下面操作
|
|
||||||
if (integer < 0) {
|
|
||||||
//保存到书架表中
|
|
||||||
BookShelfEntity bookShelfEntity = new BookShelfEntity();
|
|
||||||
bookShelfEntity.setBookId(id);
|
|
||||||
bookShelfEntity.setBookName(name);
|
|
||||||
bookShelfEntity.setUserId(buyOrder.getUserId());
|
|
||||||
bookShelfEntity.setCreateTime(new Date());
|
|
||||||
bookShelfService.save(bookShelfEntity);
|
|
||||||
}
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// return R.error().put("赠送失败",buyOrder.getOrderSn());
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}finally {
|
|
||||||
l.unlock();
|
|
||||||
}
|
|
||||||
return R.ok().put("orderSn",buyOrder.getOrderSn()).put("money",realMoney);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改
|
* 修改
|
||||||
*/
|
*/
|
||||||
@@ -659,7 +395,6 @@ public class BuyOrderController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 充值专用订单生成接口
|
* 充值专用订单生成接口
|
||||||
*/
|
*/
|
||||||
@@ -675,10 +410,6 @@ public class BuyOrderController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 信息
|
* 信息
|
||||||
*/
|
*/
|
||||||
@@ -707,8 +438,6 @@ public class BuyOrderController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<BuyOrderDetailEntity> resultOrder = new ArrayList<BuyOrderDetailEntity>();
|
List<BuyOrderDetailEntity> resultOrder = new ArrayList<BuyOrderDetailEntity>();
|
||||||
Set<String> sn_no = new HashSet<String>();
|
Set<String> sn_no = new HashSet<String>();
|
||||||
for (BuyOrderDetailEntity buyOrderDetailEntity : orderDetail) {
|
for (BuyOrderDetailEntity buyOrderDetailEntity : orderDetail) {
|
||||||
@@ -727,20 +456,16 @@ public class BuyOrderController {
|
|||||||
.last("LIMIT 1"));
|
.last("LIMIT 1"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Integer id = null;
|
Integer id = null;
|
||||||
if (userRecordEntity != null) {
|
if (userRecordEntity != null) {
|
||||||
id = userRecordEntity.getId();
|
id = userRecordEntity.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
buyOrder.setProducts(resultOrder);
|
buyOrder.setProducts(resultOrder);
|
||||||
Date createDate = buyOrder.getCreateTime();
|
Date createDate = buyOrder.getCreateTime();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return R.ok().put("buyOrder", buyOrder).put("CreateTime", createDate).put("userRecordid", id);
|
return R.ok().put("buyOrder", buyOrder).put("CreateTime", createDate).put("userRecordid", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -763,6 +488,7 @@ public class BuyOrderController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 后台发货按钮
|
* 后台发货按钮
|
||||||
|
*
|
||||||
* @Param shipperCode 快递公司编码
|
* @Param shipperCode 快递公司编码
|
||||||
* @Param sendType 0:订单列表发货 1:商品列表发货
|
* @Param sendType 0:订单列表发货 1:商品列表发货
|
||||||
* @Param type 合并发货/拆分发货
|
* @Param type 合并发货/拆分发货
|
||||||
@@ -777,9 +503,6 @@ public class BuyOrderController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 及时查询快递信息
|
* 及时查询快递信息
|
||||||
*/
|
*/
|
||||||
@@ -803,6 +526,7 @@ public class BuyOrderController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查可合并的订单信息
|
* 检查可合并的订单信息
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/checkOrder")
|
@RequestMapping("/checkOrder")
|
||||||
@@ -812,9 +536,7 @@ public class BuyOrderController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* 检查传来的orderId 是否有可合并的其他订单信息
|
* 检查传来的orderId 是否有可合并的其他订单信息
|
||||||
*
|
*
|
||||||
* @param orderIds
|
* @param orderIds
|
||||||
@@ -828,7 +550,6 @@ public class BuyOrderController {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* 批量发货功能
|
* 批量发货功能
|
||||||
*
|
*
|
||||||
* @param orderDetailIds 订单详情
|
* @param orderDetailIds 订单详情
|
||||||
@@ -844,7 +565,6 @@ public class BuyOrderController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 后台取消订单接口
|
* 后台取消订单接口
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
package com.peanut.modules.book.entity;
|
package com.peanut.modules.book.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品表
|
* 商品表
|
||||||
@@ -165,10 +163,4 @@ public class ShopProductEntity implements Serializable {
|
|||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private List<String> shoproudLabels;
|
private List<String> shoproudLabels;
|
||||||
|
|
||||||
|
|
||||||
// private Object bookidsimages;
|
|
||||||
//
|
|
||||||
//e
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ public class WechatPayConfig implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 支付通知回调地址
|
* 支付通知回调地址
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private String notifyUrl;
|
private String notifyUrl;
|
||||||
/**
|
/**
|
||||||
* 退款回调地址
|
* 退款回调地址
|
||||||
|
|||||||
@@ -109,7 +109,8 @@ public class WeChatPayController {
|
|||||||
// 订单编号
|
// 订单编号
|
||||||
paramMap.put("out_trade_no", order.getOrderSn());
|
paramMap.put("out_trade_no", order.getOrderSn());
|
||||||
// paramMap.put("attach",""); //自定义数据 支付完成后才能显示 在查询API和支付通知中原样返回,可作为自定义参数使用
|
// paramMap.put("attach",""); //自定义数据 支付完成后才能显示 在查询API和支付通知中原样返回,可作为自定义参数使用
|
||||||
paramMap.put("notify_url", wechatPayConfig.getNotifyUrl());
|
//paramMap.put("notify_url", wechatPayConfig.getNotifyUrl());
|
||||||
|
paramMap.put("notify_url","https://testapi.nuttyreading.com/pay/payNotify");
|
||||||
|
|
||||||
// paramMap.put("time_expire",afterString);
|
// paramMap.put("time_expire",afterString);
|
||||||
// 实收金额0.38乘100=38
|
// 实收金额0.38乘100=38
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.peanut.modules.pay.weChatPay.util;
|
package com.peanut.modules.pay.weChatPay.util;
|
||||||
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder;
|
import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder;
|
||||||
import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
|
import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
FROM shop_proudict_book spb
|
FROM shop_proudict_book spb
|
||||||
LEFT JOIN buy_order_detail bod ON spb.proudict_id = bod.product_id
|
LEFT JOIN buy_order_detail bod ON spb.proudict_id = bod.product_id
|
||||||
LEFT JOIN buy_order bo ON bo.order_id = bod.order_id
|
LEFT JOIN buy_order bo ON bo.order_id = bod.order_id
|
||||||
WHERE bo.order_sn = #{orderSn}
|
WHERE bo.order_sn = #{orderSn} AND del_flag != -1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ wxpay.baseUrl: https://api.mch.weixin.qq.com/v3
|
|||||||
#po9k1ezoyexk.ngrok.xiaomiqiu123.top # ????????
|
#po9k1ezoyexk.ngrok.xiaomiqiu123.top # ????????
|
||||||
#wxpay.notifyUrl: http://101.201.146.165:9100
|
#wxpay.notifyUrl: http://101.201.146.165:9100
|
||||||
|
|
||||||
wxpay.notifyUrl: http://59.110.212.44:9100/pb/pay/payNotify
|
wxpay.notifyUrl: http://59.110.212.44:9200/pb/pay/payNotify
|
||||||
|
|
||||||
# ??????
|
# ??????
|
||||||
wxpay.refundNotifyUrl: http://pjm6m9.natappfree.cc/pay/refundNotify
|
wxpay.refundNotifyUrl: http://pjm6m9.natappfree.cc/pay/refundNotify
|
||||||
|
|||||||
Reference in New Issue
Block a user