无忧付支付订单
This commit is contained in:
parent
2e6ffef10a
commit
1c5bae5118
|
|
@ -30,6 +30,6 @@ public interface InviteService {
|
||||||
|
|
||||||
PageUtils inviteAnalysis(int page,int limit, String time, Integer flag);
|
PageUtils inviteAnalysis(int page,int limit, String time, Integer flag);
|
||||||
|
|
||||||
Map updateInvite(UserEntity userEntity, String format, Long userId, BigDecimal price);
|
Map<String,Object> updateInvite(UserEntity userEntity, String format, Long userId, BigDecimal price);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ public class InviteServiceImpl extends ServiceImpl<InviteDao, Invite> implements
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map updateInvite(UserEntity userEntity, String format, Long userId, BigDecimal price) {
|
public Map<String,Object> updateInvite(UserEntity userEntity, String format, Long userId, BigDecimal price) {
|
||||||
Map<String,Object> result=new HashMap<>();
|
Map<String,Object> result=new HashMap<>();
|
||||||
if (userEntity != null && userId != null && price != null) {
|
if (userEntity != null && userId != null && price != null) {
|
||||||
Invite invite1 = inviteDao.selectInviteByUser(userEntity.getUserId(), userId,1);
|
Invite invite1 = inviteDao.selectInviteByUser(userEntity.getUserId(), userId,1);
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ public class Orders implements Serializable {
|
||||||
private Integer diamond;
|
private Integer diamond;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付方式 1微信app 2微信公众号 3微信小程序 4支付宝 5会员免费 6金豆 7抖音 8快手
|
* 支付方式 1微信app 2微信公众号 3微信小程序 4支付宝 5会员免费 6金豆 7抖音 8快手 9无忧付(支付宝)
|
||||||
*/
|
*/
|
||||||
private Integer payWay;
|
private Integer payWay;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -217,9 +217,13 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
//查询会员信息
|
//查询会员信息
|
||||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
if (courseId == null) {
|
||||||
|
return Result.error("短剧的id不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
//订单模板对象
|
//订单模板对象
|
||||||
Orders orders = new Orders();
|
Orders orders = new Orders();
|
||||||
if (courseId != null) {
|
|
||||||
//根据短剧id去查询短剧相关信息 来填充订单模板
|
//根据短剧id去查询短剧相关信息 来填充订单模板
|
||||||
QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("is_delete", 0);
|
queryWrapper.eq("is_delete", 0);
|
||||||
|
|
@ -260,9 +264,7 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
|
||||||
} else {
|
} else {
|
||||||
return Result.error("生成订单失败!");
|
return Result.error("生成订单失败!");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return Result.error("短剧的id不能为空");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
log.error("生成商品订单错误!!!" + e.getMessage());
|
log.error("生成商品订单错误!!!" + e.getMessage());
|
||||||
|
|
@ -543,5 +545,4 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,28 @@
|
||||||
package com.sqx.modules.pay.controller.app;
|
package com.sqx.modules.pay.controller.app;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.amazonaws.services.dynamodbv2.xspec.M;
|
import com.sqx.common.utils.DateUtils;
|
||||||
|
import com.sqx.common.utils.Result;
|
||||||
|
import com.sqx.modules.app.entity.UserEntity;
|
||||||
|
import com.sqx.modules.app.service.UserService;
|
||||||
|
import com.sqx.modules.invite.service.InviteService;
|
||||||
|
import com.sqx.modules.orders.entity.Orders;
|
||||||
|
import com.sqx.modules.orders.service.OrdersService;
|
||||||
|
import com.sqx.modules.pay.dao.PayDetailsDao;
|
||||||
|
import com.sqx.modules.pay.entity.PayDetails;
|
||||||
|
import com.sqx.modules.pay.wuyou.BaseResp;
|
||||||
import com.sqx.modules.pay.wuyou.Encrypt;
|
import com.sqx.modules.pay.wuyou.Encrypt;
|
||||||
import com.sqx.modules.pay.wuyou.NotifyDto;
|
import com.sqx.modules.pay.wuyou.NotifyDto;
|
||||||
|
import com.sqx.modules.pay.wuyou.WuyouPay;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -24,6 +35,57 @@ import java.util.Map;
|
||||||
@RequestMapping("/app/wuyou")
|
@RequestMapping("/app/wuyou")
|
||||||
public class WuyouController {
|
public class WuyouController {
|
||||||
|
|
||||||
|
private final OrdersService ordersService;
|
||||||
|
private final PayDetailsDao payDetailsDao;
|
||||||
|
private final UserService userService;
|
||||||
|
private final InviteService inviteService;
|
||||||
|
|
||||||
|
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
WuyouController(OrdersService ordersService, PayDetailsDao payDetailsDao, UserService userService, InviteService inviteService) {
|
||||||
|
this.ordersService = ordersService;
|
||||||
|
this.payDetailsDao = payDetailsDao;
|
||||||
|
this.userService = userService;
|
||||||
|
this.inviteService = inviteService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("支付订单")
|
||||||
|
@PostMapping("/payOrder")
|
||||||
|
public Result payOrder(HttpServletRequest request, @RequestBody Long orderId, @RequestAttribute("userId") Long userId) {
|
||||||
|
Orders order = ordersService.getById(orderId);
|
||||||
|
if (order == null) {
|
||||||
|
return Result.error("订单不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (order.getStatus() != 0) {
|
||||||
|
return Result.error("订单已支付");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!order.getUserId().equals(userId)) {
|
||||||
|
return Result.error("订单不属于当前用户");
|
||||||
|
}
|
||||||
|
|
||||||
|
PayDetails payDetails = payDetailsDao.selectByOrderId(order.getOrdersNo());
|
||||||
|
if (payDetails == null) {
|
||||||
|
payDetails = new PayDetails();
|
||||||
|
payDetails.setState(0);
|
||||||
|
payDetails.setCreateTime(sdf.format(new Date()));
|
||||||
|
payDetails.setOrderId(order.getOrdersNo());
|
||||||
|
payDetails.setUserId(order.getUserId());
|
||||||
|
payDetails.setMoney(order.getPayMoney().doubleValue());
|
||||||
|
payDetails.setType(1);
|
||||||
|
payDetails.setClassify(9);
|
||||||
|
payDetailsDao.insert(payDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseResp baseResp = WuyouPay.payOrder(order.getOrdersNo(), order.getPayMoney().toString(), request.getHeader("User-Agent"));
|
||||||
|
if (baseResp.getCode() != 200) {
|
||||||
|
return Result.error(baseResp.getMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.success().put("data", baseResp.getData());
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/notify")
|
@PostMapping("/notify")
|
||||||
public String notify(HttpServletRequest request, @RequestBody NotifyDto notifyDto) {
|
public String notify(HttpServletRequest request, @RequestBody NotifyDto notifyDto) {
|
||||||
log.info("无忧支付回调");
|
log.info("无忧支付回调");
|
||||||
|
|
@ -41,6 +103,51 @@ public class WuyouController {
|
||||||
|
|
||||||
log.info("无忧支付回调成功, 参数: {}", JSONObject.toJSONString(notifyDto));
|
log.info("无忧支付回调成功, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||||
|
|
||||||
|
Orders order = ordersService.selectOrderByOrdersNo(notifyDto.getOutTradeNo());
|
||||||
|
if (order == null) {
|
||||||
|
log.error("无忧支付回调订单不存在, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||||
|
return "订单不存在";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (order.getStatus() != 0) {
|
||||||
|
log.error("无忧支付回调订单已支付, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||||
|
return "订单已支付";
|
||||||
|
}
|
||||||
|
|
||||||
|
PayDetails payDetails = payDetailsDao.selectByOrderId(notifyDto.getOutTradeNo());
|
||||||
|
|
||||||
|
if (payDetails.getState() != 0) {
|
||||||
|
log.info("订单表信息丢失!");
|
||||||
|
}
|
||||||
|
|
||||||
|
String format = sdf.format(new Date());
|
||||||
|
payDetailsDao.updateState(payDetails.getId(), 1, format, notifyDto.getOutTradeNo());
|
||||||
|
|
||||||
|
order.setPayWay(9);
|
||||||
|
order.setStatus(1);
|
||||||
|
order.setPayTime(DateUtils.format(new Date()));
|
||||||
|
|
||||||
|
UserEntity user = userService.selectUserById(order.getUserId());
|
||||||
|
UserEntity byUser = userService.queryByInvitationCode(user.getInviterCode());
|
||||||
|
Map<String, Object> map = inviteService.updateInvite(byUser, format, user.getUserId(), order.getPayMoney());
|
||||||
|
Object oneUserId = map.get("oneUserId");
|
||||||
|
if (oneUserId != null) {
|
||||||
|
order.setOneUserId(Long.parseLong(String.valueOf(oneUserId)));
|
||||||
|
order.setOneMoney(new BigDecimal(String.valueOf(map.get("oneMoney"))));
|
||||||
|
}
|
||||||
|
Object twoUserId = map.get("twoUserId");
|
||||||
|
if (twoUserId != null) {
|
||||||
|
order.setTwoUserId(Long.parseLong(String.valueOf(twoUserId)));
|
||||||
|
order.setTwoMoney(new BigDecimal(String.valueOf(map.get("twoMoney"))));
|
||||||
|
}
|
||||||
|
Object sysUserId = map.get("sysUserId");
|
||||||
|
if (sysUserId != null) {
|
||||||
|
order.setSysUserId(Long.parseLong(String.valueOf(sysUserId)));
|
||||||
|
order.setQdMoney(new BigDecimal(String.valueOf(map.get("qdMoney"))));
|
||||||
|
}
|
||||||
|
ordersService.updateById(order);
|
||||||
|
ordersService.insertOrders(order);
|
||||||
|
|
||||||
return "success";
|
return "success";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue