苍穹外卖--处理支付功能的操作
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
|
||||
import com.sky.dto.OrdersPaymentDTO;
|
||||
import com.sky.dto.OrdersSubmitDTO;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.OrderService;
|
||||
import com.sky.vo.OrderPaymentVO;
|
||||
import com.sky.vo.OrderSubmitVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@@ -32,4 +31,21 @@ public class OrderController {
|
||||
OrderSubmitVO orderSubmitVO = orderService.submit(ordersSubmitDTO);
|
||||
return Result.success(orderSubmitVO);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订单支付
|
||||
* 返回支付参数给小程序,让小程序端能调起微信支付 (第8步)
|
||||
* @param ordersPaymentDTO
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/payment")
|
||||
@ApiOperation("订单支付")
|
||||
public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
|
||||
log.info("订单支付:{}", ordersPaymentDTO);
|
||||
OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
|
||||
log.info("生成预支付交易单:{}", orderPaymentVO);
|
||||
return Result.success(orderPaymentVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import com.sky.entity.Orders;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Mapper
|
||||
public interface OrderMapper {
|
||||
@@ -16,4 +19,8 @@ public interface OrderMapper {
|
||||
"#{deliveryStatus}, #{packAmount}, #{tablewareNumber}, #{tablewareStatus})")
|
||||
@Options(useGeneratedKeys = true,keyProperty = "id")
|
||||
void insert(Orders orders);
|
||||
|
||||
//处理支付pem问题
|
||||
@Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus},checkout_time = #{checkOutTime} where id = #{id}")
|
||||
void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime checkOutTime, Long id);
|
||||
}
|
||||
|
||||
@@ -18,4 +18,7 @@ public interface UserMapper {
|
||||
"values (#{openid},#{name},#{phone},#{sex},#{idNumber},#{avatar},#{createTime})")
|
||||
@Options(useGeneratedKeys = true,keyProperty = "id")//主键回显,得到新用户的主键id
|
||||
void insert(User user);
|
||||
|
||||
@Select("select * from user where id = #{id} ")
|
||||
User getById(Long id);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.OrdersPaymentDTO;
|
||||
import com.sky.dto.OrdersSubmitDTO;
|
||||
import com.sky.vo.OrderPaymentVO;
|
||||
import com.sky.vo.OrderSubmitVO;
|
||||
|
||||
public interface OrderService {
|
||||
@@ -10,4 +12,11 @@ public interface OrderService {
|
||||
* @return
|
||||
*/
|
||||
OrderSubmitVO submit(OrdersSubmitDTO ordersSubmitDTO);
|
||||
|
||||
/**
|
||||
* 支付功能
|
||||
* @param ordersPaymentDTO
|
||||
* @return
|
||||
*/
|
||||
OrderPaymentVO payment(OrdersPaymentDTO ordersPaymentDTO) throws Exception;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.dto.OrdersPaymentDTO;
|
||||
import com.sky.dto.OrdersSubmitDTO;
|
||||
import com.sky.entity.AddressBook;
|
||||
import com.sky.entity.OrderDetail;
|
||||
import com.sky.entity.Orders;
|
||||
import com.sky.entity.ShoppingCart;
|
||||
import com.sky.entity.*;
|
||||
import com.sky.exception.AddressBookBusinessException;
|
||||
import com.sky.exception.ShoppingCartBusinessException;
|
||||
import com.sky.mapper.AddressBookMapper;
|
||||
import com.sky.mapper.OrderDetailMapper;
|
||||
import com.sky.mapper.OrderMapper;
|
||||
import com.sky.mapper.ShoppingCartMapper;
|
||||
import com.sky.mapper.*;
|
||||
import com.sky.service.OrderService;
|
||||
import com.sky.vo.OrderPaymentVO;
|
||||
import com.sky.vo.OrderSubmitVO;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -39,6 +37,11 @@ public class OrderServiceImpl implements OrderService {
|
||||
@Autowired
|
||||
private OrderDetailMapper orderDetailMapper;
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
private Orders orders;//用来记录对应要支付的订单
|
||||
|
||||
/**
|
||||
* 用户下单
|
||||
* @param ordersSubmitDTO
|
||||
@@ -73,6 +76,8 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
orderMapper.insert(orders);
|
||||
|
||||
this.orders = orders;
|
||||
|
||||
//3.向订单明细表插入N条商品明细记录
|
||||
ArrayList<OrderDetail> orderDetails = new ArrayList<>();//订单明细集合
|
||||
for (ShoppingCart shoppingCart : cartList) {
|
||||
@@ -97,4 +102,26 @@ public class OrderServiceImpl implements OrderService {
|
||||
.orderTime(orders.getOrderTime()).build();
|
||||
return submitVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单支付
|
||||
*
|
||||
* @param ordersPaymentDTO
|
||||
* @return
|
||||
*/
|
||||
public OrderPaymentVO payment(OrdersPaymentDTO ordersPaymentDTO) throws Exception {
|
||||
// 当前登录用户id
|
||||
Long userId = BaseContext.getCurrentId();
|
||||
User user = userMapper.getById(userId);
|
||||
//处理支付pem问题
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("code", "ORDERPAID");
|
||||
OrderPaymentVO vo = jsonObject.toJavaObject(OrderPaymentVO.class);
|
||||
vo.setPackageStr(jsonObject.getString("package"));
|
||||
Integer OrderPaidStatus = Orders.PAID; //支付状态,已支付
|
||||
Integer OrderStatus = Orders.TO_BE_CONFIRMED; //订单状态,待接单
|
||||
LocalDateTime check_out_time = LocalDateTime.now(); //更新支付时间
|
||||
orderMapper.updateStatus(OrderStatus, OrderPaidStatus, check_out_time, this.orders.getId());
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,11 @@ sky:
|
||||
database: 10 #不配置的话,默认是0号数据库(redis一共有0~15,16个数据库)
|
||||
wechat:
|
||||
appid: wx3a8ed8d8e9c9552a
|
||||
secret: 8ada060abc5326be3a446a75df4c77b3
|
||||
secret: 8ada060abc5326be3a446a75df4c77b3
|
||||
mchid: 1561414331
|
||||
mchSerialNo: 4B3B3DC35414AD50B1B755BAF8DE9CC7CF407606
|
||||
apiV3Key: CZBK51236435wxpay435434323FFDuv3
|
||||
#通知程序支付成功接口
|
||||
notifyUrl: https://393bae3e.r12.vip.cpolar.cn/notify/paySuccess
|
||||
#通知程序退款成功接口
|
||||
refundNotifyUrl: https://393bae3e.r12.vip.cpolar.cn/notify/refundSuccess
|
||||
@@ -52,3 +52,8 @@ sky:
|
||||
wechat:
|
||||
appid: ${sky.wechat.appid}
|
||||
secret: ${sky.wechat.secret}
|
||||
mchid: ${sky.wechat.mchid}
|
||||
mchSerialNo: ${sky.wechat.mchSerialNo}
|
||||
apiV3Key: ${sky.wechat.apiV3Key}
|
||||
notifyUrl: ${sky.wechat.notifyUrl}
|
||||
refundNotifyUrl: ${sky.wechat.refundNotifyUrl}
|
||||
|
||||
Reference in New Issue
Block a user