微信支付宝退款
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.peanut.modules.pay.refund.controller;
|
||||
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.pay.refund.service.PayRefundOrderService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/refund")
|
||||
@Slf4j
|
||||
public class RefundController {
|
||||
|
||||
@Autowired
|
||||
private PayRefundOrderService refundOrderService;
|
||||
|
||||
/**
|
||||
* 花生币退款
|
||||
*/
|
||||
@RequestMapping("/refundPeanutCoin")
|
||||
public R pay(@RequestBody Map<String,Object> map) {
|
||||
return refundOrderService.refundPeanutCoin(map);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.peanut.modules.pay.refund.dao;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.peanut.modules.pay.refund.entity.PayRefundOrder;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface PayRefundOrderDao extends MPJBaseMapper<PayRefundOrder> {
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.peanut.modules.pay.refund.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 退款信息
|
||||
*/
|
||||
@Data
|
||||
@TableName("pay_refund_order")
|
||||
public class PayRefundOrder implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@TableId
|
||||
private Integer refundId;
|
||||
|
||||
/**
|
||||
* 支付方式 1微信,2支付宝,3虚拟币
|
||||
*/
|
||||
private String payType;
|
||||
|
||||
/**
|
||||
* BuyOrder
|
||||
*/
|
||||
private Integer orderId;
|
||||
|
||||
/**
|
||||
* 微信支付宝订单号
|
||||
*/
|
||||
private String tradeNo;
|
||||
|
||||
/**
|
||||
* 商户订单号
|
||||
*/
|
||||
private String outTradeNo;
|
||||
|
||||
/**
|
||||
* 退款总金额
|
||||
*/
|
||||
private String refundFee;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)//创建注解
|
||||
private Date createTime;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.peanut.modules.pay.refund.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.book.entity.BuyOrder;
|
||||
import com.peanut.modules.pay.refund.entity.PayRefundOrder;
|
||||
import java.util.Map;
|
||||
|
||||
public interface PayRefundOrderService extends IService<PayRefundOrder> {
|
||||
|
||||
R refundPeanutCoin(Map<String,Object> map);
|
||||
|
||||
void businessOpt(BuyOrder order);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
package com.peanut.modules.pay.refund.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.book.entity.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.pay.refund.dao.PayRefundOrderDao;
|
||||
import com.peanut.modules.pay.refund.entity.PayRefundOrder;
|
||||
import com.peanut.modules.pay.refund.service.PayRefundOrderService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PayRefundOrderServiceImpl extends ServiceImpl<PayRefundOrderDao, PayRefundOrder> implements PayRefundOrderService {
|
||||
|
||||
@Autowired
|
||||
private BuyOrderService buyOrderService;
|
||||
|
||||
@Autowired
|
||||
private CouponHistoryService couponHistoryService;
|
||||
|
||||
@Autowired
|
||||
private BuyOrderProductService buyOrderProductService;
|
||||
|
||||
@Autowired
|
||||
private ShopProductService shopProductService;
|
||||
|
||||
@Autowired
|
||||
private UserEbookBuyService userEbookBuyService;
|
||||
|
||||
@Autowired
|
||||
private MyUserService userService;
|
||||
|
||||
@Autowired
|
||||
private PayRefundOrderService refundOrderService;
|
||||
|
||||
@Autowired
|
||||
private TransactionDetailsService transactionDetailsService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public R refundPeanutCoin(Map<String,Object> map) {
|
||||
log.info(">>>>>>>>>>>花生币退款<<<<<<<<<<<<<");
|
||||
MPJLambdaWrapper<BuyOrder> w = new MPJLambdaWrapper();
|
||||
w.eq("order_id",map.get("orderId"));
|
||||
BuyOrder order = buyOrderService.getOne(w);
|
||||
//退款详细
|
||||
PayRefundOrder refund = new PayRefundOrder();
|
||||
refund.setPayType("3");
|
||||
refund.setOrderId(order.getOrderId());
|
||||
refund.setRefundFee(map.get("refundFee").toString());
|
||||
refundOrderService.save(refund);
|
||||
//权限回退
|
||||
refundOrderService.businessOpt(order);
|
||||
//修改用户花生币
|
||||
MyUserEntity byId = userService.getById(order.getUserId());
|
||||
int i = byId.getPeanutCoin().intValue() + Integer.valueOf(map.get("refundFee").toString());
|
||||
byId.setPeanutCoin(new BigDecimal(i));
|
||||
userService.updateById(byId);
|
||||
//插入花生比交易明细
|
||||
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
|
||||
transactionDetailsEntity.setUserId(order.getUserId());
|
||||
transactionDetailsEntity.setOrderType("退款");
|
||||
transactionDetailsEntity.setTel(byId.getTel());
|
||||
transactionDetailsEntity.setUserName(byId.getNickname());
|
||||
transactionDetailsEntity.setNote(map.get("note").toString());
|
||||
transactionDetailsEntity.setChangeAmount(new BigDecimal(map.get("refundFee").toString()));
|
||||
transactionDetailsEntity.setRemark("退款");
|
||||
BigDecimal balance = new BigDecimal(i);
|
||||
transactionDetailsEntity.setUserBalance(balance);
|
||||
transactionDetailsService.save(transactionDetailsEntity);
|
||||
log.info(">>>>>>>>>>>花生币退款成功<<<<<<<<<<<<<");
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void businessOpt(BuyOrder order) {
|
||||
//优惠卷回滚
|
||||
if (order.getCouponId() != null) {
|
||||
Integer couponId = order.getCouponId();
|
||||
CouponHistoryEntity couponHistory = couponHistoryService.getById(couponId);
|
||||
couponHistory.setUseStatus(0);
|
||||
couponHistoryService.updateById(couponHistory);
|
||||
}
|
||||
//查询订单所有商品
|
||||
QueryWrapper<BuyOrderProduct> w1 = new QueryWrapper<>();
|
||||
w1.eq("order_id", order.getOrderId());
|
||||
List<BuyOrderProduct> buyOrderProductList = buyOrderProductService.list(w1);
|
||||
for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
|
||||
//查询用户之前是否拥有书籍,如没有删除电子书
|
||||
QueryWrapper<ShopProduct> w2 = new QueryWrapper<>();
|
||||
w2.eq("product_id",buyOrderProduct.getProductId());
|
||||
ShopProduct sp = shopProductService.getOne(w2);
|
||||
if (sp!=null){
|
||||
if (!"".equals(sp.getBookId())) {
|
||||
String bookids[] = sp.getBookId().split(",");
|
||||
if (bookids.length > 0){
|
||||
for (int i=0;i < bookids.length; i++){
|
||||
//查询这本书在哪些商品里
|
||||
QueryWrapper<ShopProduct> w3 = new QueryWrapper<>();
|
||||
w3.eq("book_ids",bookids[i])
|
||||
.or().like("book_ids",","+bookids[i]+",")
|
||||
.or().likeLeft("book_ids",","+bookids[i])
|
||||
.or().likeRight("book_ids",bookids[i]+",");
|
||||
List<ShopProduct> list = shopProductService.list(w3);
|
||||
//查询此用户之前是否买过这些商品,并且剔除当前订单
|
||||
if (list.size() > 0){
|
||||
int flag = 0;
|
||||
for (ShopProduct item : list) {
|
||||
String arr[] = {item.getProductId().toString()};
|
||||
if (isBought(order,arr)){
|
||||
flag++;
|
||||
}
|
||||
}
|
||||
//如果用户之前没买过此书,删除电子书权限
|
||||
if (flag==0){
|
||||
QueryWrapper<UserEbookBuyEntity> w5 = new QueryWrapper<>();
|
||||
w5.eq("book_id",bookids[i]);
|
||||
w5.eq("user_id",order.getUserId());
|
||||
userEbookBuyService.remove(w5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//查询用户之前是否拥有权限
|
||||
//脉穴的权限0无权,1有权
|
||||
MyUserEntity userInfo = userService.getById(order.getUserId());
|
||||
if (buyOrderProduct.getProductId()==128||buyOrderProduct.getProductId()==129 ||buyOrderProduct.getProductId()==130
|
||||
||buyOrderProduct.getProductId()==131||buyOrderProduct.getProductId()==136){
|
||||
String arr[] = {"128","129","130","131","136"};
|
||||
if (!isBought(order,arr)){
|
||||
userInfo.setPointPower(0);
|
||||
userService.updateById(userInfo);
|
||||
}
|
||||
}
|
||||
//时辰取穴权限 0没有1有
|
||||
if (buyOrderProduct.getProductId()==133||buyOrderProduct.getProductId()==134
|
||||
||buyOrderProduct.getProductId()==135){
|
||||
String arr[] = {"133","134","135"};
|
||||
if (!isBought(order,arr)){
|
||||
userInfo.setTgdzPower(0);
|
||||
userService.updateById(userInfo);
|
||||
}
|
||||
}
|
||||
//五运六气的权限0无权1有权
|
||||
if (buyOrderProduct.getProductId()==39||buyOrderProduct.getProductId()==62
|
||||
||buyOrderProduct.getProductId()==123||buyOrderProduct.getProductId()==127){
|
||||
String arr[] = {"39","62","123","127"};
|
||||
if (!isBought(order, arr)){
|
||||
userInfo.setWylqPower(0);
|
||||
userService.updateById(userInfo);
|
||||
}
|
||||
}
|
||||
//库存回滚
|
||||
Integer productId = buyOrderProduct.getProductId();
|
||||
ShopProduct product = shopProductService.getById(productId);
|
||||
product.setProductStock(product.getProductStock() + buyOrderProduct.getQuantity());
|
||||
shopProductService.updateById(product);
|
||||
}
|
||||
//订单设置交易失败状态并删除
|
||||
order.setOrderStatus("4");
|
||||
buyOrderService.saveOrUpdate(order);
|
||||
buyOrderService.removeById(order.getOrderId());
|
||||
}
|
||||
|
||||
//本订单的用户之前是否买过当前商品
|
||||
public boolean isBought(BuyOrder order,String[] productId){
|
||||
MPJLambdaWrapper<BuyOrder> w4 = new MPJLambdaWrapper<>();
|
||||
w4.selectAll(BuyOrder.class);
|
||||
w4.leftJoin(BuyOrderProduct.class,BuyOrderProduct::getOrderId,BuyOrder::getOrderId);
|
||||
w4.in(BuyOrderProduct::getProductId,productId);
|
||||
w4.eq(BuyOrder::getUserId,order.getUserId());
|
||||
w4.ne(BuyOrder::getOrderId,order.getOrderId());
|
||||
w4.in(BuyOrder::getOrderStatus,"1","2","3");
|
||||
return buyOrderService.list(w4).size() > 0 ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user