苍穹外卖学习笔记(八)

一. 地址簿

1.查询地址列表

AddressBookController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.sky.controller.user;

import com.sky.context.BaseContext;
import com.sky.entity.AddressBook;
import com.sky.result.Result;
import com.sky.service.AddressBookService;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* @author Jie.
* @description: TODO
* @date 2024/10/8
* @version: 1.0
*/
@RestController
@RequestMapping("/user/addressBook")
@Api(tags = "通讯录")
@Slf4j
public class AddressBookController {

@Autowired
private AddressBookService addressBookService;

/**
* 通讯录列表
*/
@PostMapping("/list")
@ApiOperation(value = "通讯录列表")
public Result<List<AddressBook>> list() {
log.info("通讯录列表");
AddressBook addressBook = new AddressBook();
addressBook.setUserId(BaseContext.getCurrentId());
List<AddressBook> list = addressBookService.list(addressBook);
return Result.success(list);
}
}

AddressBookService

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.sky.service;

import com.sky.entity.AddressBook;

import java.util.List;

/**
* @author Jie.
* @description: TODO
* @date 2024/10/8
* @version: 1.0
*/
public interface AddressBookService {

/**
* 通讯录列表
*/
List<AddressBook> list(AddressBook addressBook);
}

AddressBookServiceImpl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.sky.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sky.entity.AddressBook;
import com.sky.mapper.AddressBookMapper;
import com.sky.service.AddressBookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Jie.
* @description: TODO
* @date 2024/10/8
* @version: 1.0
*/
@Service
@Slf4j
public class AddressBookServiceImpl implements AddressBookService {

@Autowired
private AddressBookMapper addressBookMapper;

/**
* 通讯录列表
*/
@Override
public List<AddressBook> list(AddressBook addressBook) {
LambdaQueryWrapper<AddressBook> queryWrapper = new LambdaQueryWrapper<>();
if (addressBook.getUserId() != null) {
queryWrapper.eq(AddressBook::getUserId, addressBook.getUserId());
}
if (addressBook.getPhone() != null) {
queryWrapper.eq(AddressBook::getPhone, addressBook.getPhone());
}
if (addressBook.getIsDefault() != null) {
queryWrapper.eq(AddressBook::getIsDefault, addressBook.getIsDefault());
}
return addressBookMapper.selectList(queryWrapper);
}
}

AddressBookMapper

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package com.sky.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Mapper;

/**
* @author Jie.
* @description: TODO
* @date 2024/10/8
* @version: 1.0
*/
@Mapper
public interface AddressBookMapper extends BaseMapper<AddressBook> {
}

2.新增地址

AddressBookController

1
2
3
4
5
6
7
8
9
10
/**
* 保存通讯录
*/
@GetMapping
@ApiOperation(value = "保存通讯录")
public Result save(@RequestBody AddressBook addressBook) {
log.info("保存通讯录:{}", addressBook);
addressBookService.save(addressBook);
return Result.success();
}

AddressBookService

1
2
3
4
5
/**
* 保存通讯录
*/
void save(AddressBook addressBook);
}

AddressBookServiceImpl

1
2
3
4
5
6
7
8
9
/**
* 保存通讯录
*/
@Override
public void save(AddressBook addressBook) {
addressBook.setUserId(BaseContext.getCurrentId());
addressBook.setIsDefault(0);
addressBookMapper.insert(addressBook);
}

3.修改地址

  1. 根据 id 查询地址

AddressBookController

1
2
3
4
5
6
7
8
9
10
/**
* 根据id查询通讯录
*/
@GetMapping("/{id}")
@ApiOperation(value = "根据id查询通讯录")
public Result<AddressBook> getById(@PathVariable Long id) {
log.info("根据id查询通讯录:{}", id);
AddressBook addressBook = addressBookService.getById(id);
return Result.success(addressBook);
}

AddressBookService

1
2
3
4
5
/**
* 根据id查询通讯录
*/
AddressBook getById(Long id);
}

AddressBookServiceImpl

1
2
3
4
5
6
7
/**
* 根据id查询通讯录
*/
@Override
public AddressBook getById(Long id) {
return addressBookMapper.selectById(id);
}
  1. 根据 id 修改地址

AddressBookController

1
2
3
4
5
6
7
8
9
10
/**
* 更新通讯录
*/
@PutMapping
@ApiOperation(value = "更新通讯录")
public Result update(@RequestBody AddressBook addressBook) {
log.info("更新通讯录:{}", addressBook);
addressBookService.updateById(addressBook);
return Result.success();
}

AddressBookService

1
2
3
4
/**
* 更新通讯录
*/
void updateById(AddressBook addressBook);

AddressBookServiceImpl

1
2
3
4
5
6
7
  /**
* 更新通讯录
*/
@Override
public void updateById(AddressBook addressBook) {
addressBookMapper.updateById(addressBook);
}

4.删除地址

AddressBookController

1
2
3
4
5
6
7
8
9
10
   /**
* 根据id删除通讯录
*/
@DeleteMapping
@ApiOperation(value = "根据id删除通讯录")
public Result delete(Long id) {
log.info("删除通讯录:{}", id);
addressBookService.removeById(id);
return Result.success();
}

AddressBookService

1
2
3
4
/**
* 根据id删除通讯录
*/
void removeById(Long id);

AddressBookServiceImpl

1
2
3
4
5
6
7
   /**
* 根据id删除通讯录
*/
@Override
public void removeById(Long id) {
addressBookMapper.deleteById(id);
}

5.设置默认地址

AddressBookController

1
2
3
4
5
6
7
8
9
  /**
* 设置默认地址
*/
@PutMapping("/default")
@ApiOperation("设置默认地址")
public Result setDefault(@RequestBody AddressBook addressBook) {
addressBookService.setDefault(addressBook);
return Result.success();
}

AddressBookService

1
2
3
4
/**
* 设置默认地址
*/
void setDefault(AddressBook addressBook);

AddressBookServiceImpl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 /**
* 设置默认地址
*/
@Override
public void setDefault(AddressBook addressBook) {
addressBook.setIsDefault(0);
addressBook.setUserId(BaseContext.getCurrentId());
LambdaQueryWrapper<AddressBook> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AddressBook::getUserId, BaseContext.getCurrentId());
addressBookMapper.update(addressBook, queryWrapper);

// 设置默认地址
addressBook.setIsDefault(1);
addressBookMapper.updateById(addressBook);
}

6.查询默认地址

AddressBookController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
* 获取默认地址
*/
@GetMapping("/default")
@ApiOperation("获取默认地址")
public Result<AddressBook> getDefault() {
AddressBook addressBook = new AddressBook();
addressBook.setIsDefault(1);
addressBook.setUserId(BaseContext.getCurrentId());
List<AddressBook> list = addressBookService.list(addressBook);

if (list != null && list.size() == 1) {
return Result.success(list.get(0));
}

return Result.error("没有查询到默认地址");
}

二. 用户下单

OrderController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.sky.controller.user;

import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.Result;
import com.sky.service.OrderService;
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;

/**
* @author Jie.
* @description: TODO
* @date 2024/10/10
* @version: 1.0
*/
@RestController
@RequestMapping("/user/order")
@Api(tags = "订单接口")
@Slf4j
public class OrderController {

@Autowired
private OrderService orderService;

/**
* 用户下单
*/
@PostMapping("/submit")
@ApiOperation(value = "用户下单")
public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
log.info("用户下单:{}", ordersSubmitDTO);
OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
return Result.success(orderSubmitVO);
}
}

OrderService

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package com.sky.service;

import com.sky.dto.OrdersSubmitDTO;
import com.sky.vo.OrderSubmitVO;

/**
* @author Jie.
* @description: TODO
* @date 2024/10/10
* @version: 1.0
*/
public interface OrderService {

/**
* 用户下单
*/
OrderSubmitVO submitOrder(OrdersSubmitDTO ordersSubmitDTO);
}

OrderMapper

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package com.sky.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;

/**
* @author Jie.
* @description: TODO
* @date 2024/10/10
* @version: 1.0
*/
@Mapper
public interface OrderMapper extends BaseMapper<Orders> {
}

OrderDetailMapper

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.sky.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.entity.OrderDetail;
import org.apache.ibatis.annotations.Mapper;

/**
* @author Jie.
* @description: TODO
* @date 2024/10/10
* @version: 1.0
*/
@Mapper
public interface OrderDetailMapper extends BaseMapper<OrderDetail> {
}
package com.sky.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.entity.OrderDetail;
import org.apache.ibatis.annotations.Mapper;

/**
* @author Jie.
* @description: TODO
* @date 2024/10/10
* @version: 1.0
*/
@Mapper
public interface OrderDetailMapper extends BaseMapper<OrderDetail> {
}

OrderServiceImpl

package com.sky.service.impl;

import com.baomidou.mybatisplus.core.batch.MybatisBatch;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sky.constant.MessageConstant;
import com.sky.context.BaseContext;
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.exception.AddressBookBusinessException;
import com.sky.mapper.AddressBookMapper;
import com.sky.mapper.OrderDetailMapper;
import com.sky.mapper.OrderMapper;
import com.sky.mapper.ShoppingCartMapper;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**

  • @author Jie.

  • @description: TODO

  • @date 2024/10/10

  • @version: 1.0
    */
    @Service
    @Slf4j
    public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private AddressBookMapper addressBookMapper;

    @Autowired
    private ShoppingCartMapper shoppingCartMapper;

    @Autowired
    private SqlSessionFactory sqlSessionFactory;

    /**

    • 用户下单
      */
      @Override
      public OrderSubmitVO submitOrder(OrdersSubmitDTO ordersSubmitDTO) {
      //处理各种业务异常(地址簿为空,购物车为空,商品库存不足等)
      AddressBook addressBook = addressBookMapper.selectById(ordersSubmitDTO.getAddressBookId());
      if (addressBook == null) {
      throw new AddressBookBusinessException(MessageConstant.ADDRESS_BOOK_IS_NULL);
      }

      Long currentId = BaseContext.getCurrentId();
      ShoppingCart shoppingCart = new ShoppingCart();
      shoppingCart.setUserId(currentId);
      List <ShoppingCart> ShoppingCartList = shoppingCartMapper.list(shoppingCart);
      if (ShoppingCartList == null || ShoppingCartList.isEmpty()) {
      throw new AddressBookBusinessException(MessageConstant.SHOPPING_CART_IS_NULL);
      }
      //向订单表插入 1 条数据
      Orders orders = new Orders();
      BeanUtils.copyProperties(ordersSubmitDTO, orders);
      orders.setOrderTime(LocalDateTime.now());
      orders.setPayStatus(Orders.UN_PAID);
      orders.setStatus(Orders.PENDING_PAYMENT);
      orders.setNumber(String.valueOf(System.currentTimeMillis()));
      orders.setPhone(addressBook.getPhone());
      orders.setConsignee(addressBook.getConsignee());
      orders.setUserId(currentId);

      orderMapper.insert(orders);

      List <OrderDetail> orderDetailList = new ArrayList<>();
      //向订单详情表插入多条数据
      ShoppingCartList.forEach(cart -> {
      OrderDetail orderDetail = new OrderDetail();
      BeanUtils.copyProperties(cart, orderDetail);
      orderDetail.setOrderId(orders.getId());
      orderDetailList.add(orderDetail);
      });
      MybatisBatch <OrderDetail> mybatisBatch = new MybatisBatch<>(sqlSessionFactory, orderDetailList);
      MybatisBatch.Method <OrderDetail> method = new MybatisBatch.Method<>(OrderDetailMapper.class);
      mybatisBatch.execute(method.insert());
      //如果下单成功,清空购物车数据
      LambdaQueryWrapper <ShoppingCart> queryWrapper = new LambdaQueryWrapper<>();
      queryWrapper.eq(ShoppingCart::getUserId, currentId);
      shoppingCartMapper.delete(queryWrapper);
      //封装返回数据
      OrderSubmitVO orderSubmitVO = OrderSubmitVO.builder()
      .id(orders.getId())
      .orderTime(orders.getOrderTime())
      .orderNumber(orders.getNumber())
      .orderAmount(orders.getAmount())
      .build();
      return orderSubmitVO;
      }
      }

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.sky.service.impl;

import com.baomidou.mybatisplus.core.batch.MybatisBatch;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sky.constant.MessageConstant;
import com.sky.context.BaseContext;
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.exception.AddressBookBusinessException;
import com.sky.mapper.AddressBookMapper;
import com.sky.mapper.OrderDetailMapper;
import com.sky.mapper.OrderMapper;
import com.sky.mapper.ShoppingCartMapper;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
* @author Jie.
* @description: TODO
* @date 2024/10/10
* @version: 1.0
*/
@Service
@Slf4j
public class OrderServiceImpl implements OrderService {

@Autowired
private OrderMapper orderMapper;

@Autowired
private AddressBookMapper addressBookMapper;

@Autowired
private ShoppingCartMapper shoppingCartMapper;

@Autowired
private SqlSessionFactory sqlSessionFactory;

/**
* 用户下单
*/
@Override
public OrderSubmitVO submitOrder(OrdersSubmitDTO ordersSubmitDTO) {
//处理各种业务异常(地址簿为空,购物车为空,商品库存不足等)
AddressBook addressBook = addressBookMapper.selectById(ordersSubmitDTO.getAddressBookId());
if (addressBook == null) {
throw new AddressBookBusinessException(MessageConstant.ADDRESS_BOOK_IS_NULL);
}

Long currentId = BaseContext.getCurrentId();
ShoppingCart shoppingCart = new ShoppingCart();
shoppingCart.setUserId(currentId);
List<ShoppingCart> ShoppingCartList = shoppingCartMapper.list(shoppingCart);
if (ShoppingCartList == null || ShoppingCartList.isEmpty()) {
throw new AddressBookBusinessException(MessageConstant.SHOPPING_CART_IS_NULL);
}
//向订单表插入1条数据
Orders orders = new Orders();
BeanUtils.copyProperties(ordersSubmitDTO, orders);
orders.setOrderTime(LocalDateTime.now());
orders.setPayStatus(Orders.UN_PAID);
orders.setStatus(Orders.PENDING_PAYMENT);
orders.setNumber(String.valueOf(System.currentTimeMillis()));
orders.setPhone(addressBook.getPhone());
orders.setConsignee(addressBook.getConsignee());
orders.setUserId(currentId);

orderMapper.insert(orders);

List<OrderDetail> orderDetailList = new ArrayList<>();
//向订单详情表插入多条数据
ShoppingCartList.forEach(cart -> {
OrderDetail orderDetail = new OrderDetail();
BeanUtils.copyProperties(cart, orderDetail);
orderDetail.setOrderId(orders.getId());
orderDetailList.add(orderDetail);
});
MybatisBatch<OrderDetail> mybatisBatch = new MybatisBatch<>(sqlSessionFactory, orderDetailList);
MybatisBatch.Method<OrderDetail> method = new MybatisBatch.Method<>(OrderDetailMapper.class);
mybatisBatch.execute(method.insert());
//如果下单成功,清空购物车数据
LambdaQueryWrapper<ShoppingCart> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(ShoppingCart::getUserId, currentId);
shoppingCartMapper.delete(queryWrapper);
//封装返回数据
OrderSubmitVO orderSubmitVO = OrderSubmitVO.builder()
.id(orders.getId())
.orderTime(orders.getOrderTime())
.orderNumber(orders.getNumber())
.orderAmount(orders.getAmount())
.build();
return orderSubmitVO;
}
}

三. 订单支付

20241011105016

OrderController

1
2
3
4
5
6
7
8
9
10
11
12
/**
* 订单支付
*/
@PutMapping("/payment")
@ApiOperation("订单支付")
public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
log.info("订单支付:{}", ordersPaymentDTO);
OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
log.info("生成预支付交易单:{}", orderPaymentVO);
orderService.paySuccess(ordersPaymentDTO.getOrderNumber());
return Result.success(orderPaymentVO);
}

OrderService

1
2
3
4
5
6
7
8
9
/**
* 订单支付
*/
OrderPaymentVO payment(OrdersPaymentDTO ordersPaymentDTO) throws Exception;

/**
* 支付成功,修改订单状态
*/
void paySuccess(String outTradeNo);

OrderServiceImpl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package com.sky.service.impl;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.batch.MybatisBatch;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sky.constant.MessageConstant;
import com.sky.context.BaseContext;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.*;
import com.sky.exception.AddressBookBusinessException;
import com.sky.exception.OrderBusinessException;
import com.sky.mapper.*;
import com.sky.service.OrderService;
import com.sky.utils.WeChatPayUtil;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
* @author Jie.
* @description: TODO
* @date 2024/10/10
* @version: 1.0
*/
@Service
@Slf4j
public class OrderServiceImpl implements OrderService {

@Autowired
private OrderMapper orderMapper;

@Autowired
private AddressBookMapper addressBookMapper;

@Autowired
private ShoppingCartMapper shoppingCartMapper;

@Autowired
private SqlSessionFactory sqlSessionFactory;

@Autowired
private UserMapper userMapper;

@Autowired
private WeChatPayUtil weChatPayUtil;

/**
* 用户下单
*/
@Override
public OrderSubmitVO submitOrder(OrdersSubmitDTO ordersSubmitDTO) {
//处理各种业务异常(地址簿为空,购物车为空,商品库存不足等)
AddressBook addressBook = addressBookMapper.selectById(ordersSubmitDTO.getAddressBookId());
if (addressBook == null) {
throw new AddressBookBusinessException(MessageConstant.ADDRESS_BOOK_IS_NULL);
}

Long currentId = BaseContext.getCurrentId();
ShoppingCart shoppingCart = new ShoppingCart();
shoppingCart.setUserId(currentId);
List<ShoppingCart> ShoppingCartList = shoppingCartMapper.list(shoppingCart);
if (ShoppingCartList == null || ShoppingCartList.isEmpty()) {
throw new AddressBookBusinessException(MessageConstant.SHOPPING_CART_IS_NULL);
}
//向订单表插入1条数据
Orders orders = new Orders();
BeanUtils.copyProperties(ordersSubmitDTO, orders);
orders.setOrderTime(LocalDateTime.now());
orders.setPayStatus(Orders.UN_PAID);
orders.setStatus(Orders.PENDING_PAYMENT);
orders.setNumber(String.valueOf(System.currentTimeMillis()));
orders.setPhone(addressBook.getPhone());
orders.setConsignee(addressBook.getConsignee());
orders.setUserId(currentId);

orderMapper.insert(orders);

List<OrderDetail> orderDetailList = new ArrayList<>();
//向订单详情表插入多条数据
ShoppingCartList.forEach(cart -> {
OrderDetail orderDetail = new OrderDetail();
BeanUtils.copyProperties(cart, orderDetail);
orderDetail.setOrderId(orders.getId());
orderDetailList.add(orderDetail);
});
MybatisBatch<OrderDetail> mybatisBatch = new MybatisBatch<>(sqlSessionFactory, orderDetailList);
MybatisBatch.Method<OrderDetail> method = new MybatisBatch.Method<>(OrderDetailMapper.class);
mybatisBatch.execute(method.insert());
//如果下单成功,清空购物车数据
LambdaQueryWrapper<ShoppingCart> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(ShoppingCart::getUserId, currentId);
shoppingCartMapper.delete(queryWrapper);
//封装返回数据
OrderSubmitVO orderSubmitVO = OrderSubmitVO.builder()
.id(orders.getId())
.orderTime(orders.getOrderTime())
.orderNumber(orders.getNumber())
.orderAmount(orders.getAmount())
.build();
return orderSubmitVO;
}

/**
* 订单支付
*/
@Override
public OrderPaymentVO payment(OrdersPaymentDTO ordersPaymentDTO) throws Exception {
// 当前登录用户id
Long userId = BaseContext.getCurrentId();
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(User::getId, userId);
User user = userMapper.selectOne(queryWrapper);

//调用微信支付接口,生成预支付交易单
// JSONObject jsonObject = weChatPayUtil.pay(
// ordersPaymentDTO.getOrderNumber(), //商户订单号
// new BigDecimal("0.01"), //支付金额,单位 元
// "苍穹外卖订单", //商品描述
// user.getOpenid() //微信用户的openid
// );
JSONObject jsonObject = new JSONObject();

if (jsonObject.getString("code") != null && jsonObject.getString("code").equals("ORDERPAID")) {
throw new OrderBusinessException("该订单已支付");
}

OrderPaymentVO vo = jsonObject.toJavaObject(OrderPaymentVO.class);
vo.setPackageStr(jsonObject.getString("package"));

return vo;
}

/**
* 支付成功,修改订单状态
*/
@Override
public void paySuccess(String outTradeNo) {

// 根据订单号查询订单
LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Orders::getNumber, outTradeNo);
Orders ordersDB = orderMapper.selectOne(queryWrapper);

// 根据订单id更新订单的状态、支付方式、支付状态、结账时间
Orders orders = Orders.builder()
.id(ordersDB.getId())
.status(Orders.TO_BE_CONFIRMED)
.payStatus(Orders.PAID)
.checkoutTime(LocalDateTime.now())
.build();
orderMapper.updateById(orders);
}
}

PayNotifyController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.sky.controller.notify;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sky.properties.WeChatProperties;
import com.sky.service.OrderService;
import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.entity.ContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;

/**
* 支付回调相关接口
*/
@RestController
@RequestMapping("/notify")
@Slf4j
public class PayNotifyController {
@Autowired
private OrderService orderService;
@Autowired
private WeChatProperties weChatProperties;

/**
* 支付成功回调
*
* @param request
*/
@RequestMapping("/paySuccess")
public void paySuccessNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
//读取数据
String body = readData(request);
log.info("支付成功回调:{}", body);

//数据解密
String plainText = decryptData(body);
log.info("解密后的文本:{}", plainText);

JSONObject jsonObject = JSON.parseObject(plainText);
String outTradeNo = jsonObject.getString("out_trade_no");//商户平台订单号
String transactionId = jsonObject.getString("transaction_id");//微信支付交易号

log.info("商户平台订单号:{}", outTradeNo);
log.info("微信支付交易号:{}", transactionId);

//业务处理,修改订单状态、来单提醒
orderService.paySuccess(outTradeNo);

//给微信响应
responseToWeixin(response);
}

/**
* 读取数据
*
* @param request
* @return
* @throws Exception
*/
private String readData(HttpServletRequest request) throws Exception {
BufferedReader reader = request.getReader();
StringBuilder result = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
if (result.length() > 0) {
result.append("\n");
}
result.append(line);
}
return result.toString();
}

/**
* 数据解密
*
* @param body
* @return
* @throws Exception
*/
private String decryptData(String body) throws Exception {
JSONObject resultObject = JSON.parseObject(body);
JSONObject resource = resultObject.getJSONObject("resource");
String ciphertext = resource.getString("ciphertext");
String nonce = resource.getString("nonce");
String associatedData = resource.getString("associated_data");

AesUtil aesUtil = new AesUtil(weChatProperties.getApiV3Key().getBytes(StandardCharsets.UTF_8));
//密文解密
String plainText = aesUtil.decryptToString(associatedData.getBytes(StandardCharsets.UTF_8),
nonce.getBytes(StandardCharsets.UTF_8),
ciphertext);

return plainText;
}

/**
* 给微信响应
* @param response
*/
private void responseToWeixin(HttpServletResponse response) throws Exception{
response.setStatus(200);
HashMap<Object, Object> map = new HashMap<>();
map.put("code", "SUCCESS");
map.put("message", "SUCCESS");
response.setHeader("Content-type", ContentType.APPLICATION_JSON.toString());
response.getOutputStream().write(JSONUtils.toJSONString(map).getBytes(StandardCharsets.UTF_8));
response.flushBuffer();
}
}

pay wx index.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
(global["webpackJsonp"] = global["webpackJsonp"] || []).push([
["pages/pay/index"],
{
/***/ 56:
/*!************************************************************************************!*\
!*** D:/project/project-rjwm-weixin-uniapp/main.js?{"page":"pages%2Fpay%2Findex"} ***!
\************************************************************************************/
/*! no static exports found */
/***/ function (module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */ (function (createPage) {
__webpack_require__(/*! uni-pages */ 5);

var _vue = _interopRequireDefault(__webpack_require__(/*! vue */ 4));
var _index = _interopRequireDefault(
__webpack_require__(/*! ./pages/pay/index.vue */ 57)
);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
} // @ts-ignore
wx.__webpack_require_UNI_MP_PLUGIN__ = __webpack_require__;
createPage(_index.default);
/* WEBPACK VAR INJECTION */
}).call(
this,
__webpack_require__(
/*! ./node_modules/@dcloudio/uni-mp-weixin/dist/index.js */ 1
)["createPage"]
);

/***/
},

/***/ 57:
/*!*****************************************************************!*\
!*** D:/project/project-rjwm-weixin-uniapp/pages/pay/index.vue ***!
\*****************************************************************/
/*! no static exports found */
/***/ function (module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _index_vue_vue_type_template_id_32f2f1fc_scoped_true___WEBPACK_IMPORTED_MODULE_0__ =
__webpack_require__(
/*! ./index.vue?vue&type=template&id=32f2f1fc&scoped=true& */ 58
);
/* harmony import */ var _index_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_1__ =
__webpack_require__(/*! ./index.vue?vue&type=script&lang=js& */ 60);
/* harmony reexport (unknown) */ for (var __WEBPACK_IMPORT_KEY__ in _index_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_1__)
if (__WEBPACK_IMPORT_KEY__ !== "default")
(function (key) {
__webpack_require__.d(__webpack_exports__, key, function () {
return _index_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_1__[
key
];
});
})(__WEBPACK_IMPORT_KEY__);
/* harmony import */ var _common_Navbar_navbar_scss_vue_type_style_index_0_id_32f2f1fc_lang_scss_scoped_true___WEBPACK_IMPORTED_MODULE_2__ =
__webpack_require__(
/*! ./../common/Navbar/navbar.scss?vue&type=style&index=0&id=32f2f1fc&lang=scss&scoped=true& */ 62
);
/* harmony import */ var _order_style_scss_vue_type_style_index_1_lang_scss___WEBPACK_IMPORTED_MODULE_3__ =
__webpack_require__(
/*! ./../order/style.scss?vue&type=style&index=1&lang=scss& */ 54
);
/* harmony import */ var _F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_runtime_componentNormalizer_js__WEBPACK_IMPORTED_MODULE_4__ =
__webpack_require__(
/*! ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/runtime/componentNormalizer.js */ 11
);

var renderjs;

/* normalize component */

var component = Object(
_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_runtime_componentNormalizer_js__WEBPACK_IMPORTED_MODULE_4__[
"default"
]
)(
_index_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_1__[
"default"
],
_index_vue_vue_type_template_id_32f2f1fc_scoped_true___WEBPACK_IMPORTED_MODULE_0__[
"render"
],
_index_vue_vue_type_template_id_32f2f1fc_scoped_true___WEBPACK_IMPORTED_MODULE_0__[
"staticRenderFns"
],
false,
null,
"32f2f1fc",
null,
false,
_index_vue_vue_type_template_id_32f2f1fc_scoped_true___WEBPACK_IMPORTED_MODULE_0__[
"components"
],
renderjs
);

component.options.__file = "pages/pay/index.vue";
/* harmony default export */ __webpack_exports__["default"] =
component.exports;

/***/
},

/***/ 58:
/*!************************************************************************************************************!*\
!*** D:/project/project-rjwm-weixin-uniapp/pages/pay/index.vue?vue&type=template&id=32f2f1fc&scoped=true& ***!
\************************************************************************************************************/
/*! exports provided: render, staticRenderFns, recyclableRender, components */
/***/ function (module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_loaders_templateLoader_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_16_0_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_template_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_uni_app_loader_page_meta_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_index_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_style_js_index_vue_vue_type_template_id_32f2f1fc_scoped_true___WEBPACK_IMPORTED_MODULE_0__ =
__webpack_require__(
/*! -!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader??ref--16-0!./node_modules/@dcloudio/webpack-uni-mp-loader/lib/template.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-uni-app-loader/page-meta.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib??vue-loader-options!./node_modules/@dcloudio/webpack-uni-mp-loader/lib/style.js!./index.vue?vue&type=template&id=32f2f1fc&scoped=true& */ 59
);
/* harmony reexport (safe) */ __webpack_require__.d(
__webpack_exports__,
"render",
function () {
return _F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_loaders_templateLoader_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_16_0_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_template_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_uni_app_loader_page_meta_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_index_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_style_js_index_vue_vue_type_template_id_32f2f1fc_scoped_true___WEBPACK_IMPORTED_MODULE_0__[
"render"
];
}
);

/* harmony reexport (safe) */ __webpack_require__.d(
__webpack_exports__,
"staticRenderFns",
function () {
return _F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_loaders_templateLoader_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_16_0_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_template_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_uni_app_loader_page_meta_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_index_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_style_js_index_vue_vue_type_template_id_32f2f1fc_scoped_true___WEBPACK_IMPORTED_MODULE_0__[
"staticRenderFns"
];
}
);

/* harmony reexport (safe) */ __webpack_require__.d(
__webpack_exports__,
"recyclableRender",
function () {
return _F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_loaders_templateLoader_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_16_0_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_template_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_uni_app_loader_page_meta_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_index_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_style_js_index_vue_vue_type_template_id_32f2f1fc_scoped_true___WEBPACK_IMPORTED_MODULE_0__[
"recyclableRender"
];
}
);

/* harmony reexport (safe) */ __webpack_require__.d(
__webpack_exports__,
"components",
function () {
return _F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_loaders_templateLoader_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_16_0_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_template_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_uni_app_loader_page_meta_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_index_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_style_js_index_vue_vue_type_template_id_32f2f1fc_scoped_true___WEBPACK_IMPORTED_MODULE_0__[
"components"
];
}
);

/***/
},

/***/ 59:
/*!************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\
!*** ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader??ref--16-0!./node_modules/@dcloudio/webpack-uni-mp-loader/lib/template.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-uni-app-loader/page-meta.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib??vue-loader-options!./node_modules/@dcloudio/webpack-uni-mp-loader/lib/style.js!D:/project/project-rjwm-weixin-uniapp/pages/pay/index.vue?vue&type=template&id=32f2f1fc&scoped=true& ***!
\************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
/*! exports provided: render, staticRenderFns, recyclableRender, components */
/***/ function (module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(
__webpack_exports__,
"render",
function () {
return render;
}
);
/* harmony export (binding) */ __webpack_require__.d(
__webpack_exports__,
"staticRenderFns",
function () {
return staticRenderFns;
}
);
/* harmony export (binding) */ __webpack_require__.d(
__webpack_exports__,
"recyclableRender",
function () {
return recyclableRender;
}
);
/* harmony export (binding) */ __webpack_require__.d(
__webpack_exports__,
"components",
function () {
return components;
}
);
var components;
var render = function () {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
};
var recyclableRender = false;
var staticRenderFns = [];
render._withStripped = true;

/***/
},

/***/ 60:
/*!******************************************************************************************!*\
!*** D:/project/project-rjwm-weixin-uniapp/pages/pay/index.vue?vue&type=script&lang=js& ***!
\******************************************************************************************/
/*! no static exports found */
/***/ function (module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_babel_loader_lib_index_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_12_1_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_script_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_index_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_style_js_index_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0__ =
__webpack_require__(
/*! -!./node_modules/babel-loader/lib!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader??ref--12-1!./node_modules/@dcloudio/webpack-uni-mp-loader/lib/script.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib??vue-loader-options!./node_modules/@dcloudio/webpack-uni-mp-loader/lib/style.js!./index.vue?vue&type=script&lang=js& */ 61
);
/* harmony import */ var _F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_babel_loader_lib_index_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_12_1_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_script_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_index_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_style_js_index_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0___default =
/*#__PURE__*/ __webpack_require__.n(
_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_babel_loader_lib_index_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_12_1_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_script_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_index_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_style_js_index_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0__
);
/* harmony reexport (unknown) */ for (var __WEBPACK_IMPORT_KEY__ in _F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_babel_loader_lib_index_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_12_1_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_script_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_index_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_style_js_index_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0__)
if (__WEBPACK_IMPORT_KEY__ !== "default")
(function (key) {
__webpack_require__.d(__webpack_exports__, key, function () {
return _F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_babel_loader_lib_index_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_12_1_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_script_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_index_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_style_js_index_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0__[
key
];
});
})(__WEBPACK_IMPORT_KEY__);
/* harmony default export */ __webpack_exports__["default"] =
_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_babel_loader_lib_index_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_12_1_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_script_js_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_vue_loader_lib_index_js_vue_loader_options_F_HBuilderX_2_2_2_20190816_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_style_js_index_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0___default.a;

/***/
},

/***/ 61:
/*!*************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\
!*** ./node_modules/babel-loader/lib!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader??ref--12-1!./node_modules/@dcloudio/webpack-uni-mp-loader/lib/script.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib??vue-loader-options!./node_modules/@dcloudio/webpack-uni-mp-loader/lib/style.js!D:/project/project-rjwm-weixin-uniapp/pages/pay/index.vue?vue&type=script&lang=js& ***!
\*************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
/*! no static exports found */
/***/ function (module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */ (function (uni) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = void 0;

var _vuex = __webpack_require__(/*! vuex */ 13);
var _api = __webpack_require__(/*! @/pages/api/api.js */ 24);
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly)
symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(
object,
sym
).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(
target,
Object.getOwnPropertyDescriptors(source)
);
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(
target,
key,
Object.getOwnPropertyDescriptor(source, key)
);
});
}
}
return target;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true,
});
} else {
obj[key] = value;
}
return obj;
}
var _default = {
data: function data() {
return {
timeout: false,
rocallTime: "",
orderId: null,
orderDataInfo: {},
activeRadio: 0,
payMethodList: ["微信支付"],
times: null,
};
},
created: function created() {
this.orderDataInfo = this.orderData();
// this.getBaseData(this.orderId)
},
mounted: function mounted() {
this.runTimeBack();
},
onLoad: function onLoad(options) {
this.orderId = options.orderId;
},
methods: _objectSpread(
_objectSpread({}, (0, _vuex.mapState)(["orderData"])),
{},
{
// 支付详情
handleSave: function handleSave() {
var _this = this;
if (this.timeout) {
(0, _api.cancelOrder)(this.orderId).then(function (res) {});
uni.redirectTo({
url: "/pages/details/index?orderId=" + this.orderId,
});
} else {
// 如果支付成功进入成功页
clearTimeout(this.times);
var params = {
orderNumber: this.orderDataInfo.orderNumber,
payMethod: this.activeRadio === 0 ? 1 : 2,
};

(0, _api.paymentOrder)(params).then(function (res) {
if (res.code === 1) {
wx.showModal({
title: "提示",
content: "支付成功",
success: function () {
uni.redirectTo({
url:
"/pages/success/index?orderId=" + _this.orderId,
});
},
});
console.log("支付成功!");
// wx.requestPayment({
// nonceStr: res.data.nonceStr,
// package: res.data.packageStr,
// paySign: res.data.paySign,
// timeStamp: res.data.timeStamp,
// signType: res.data.signType,
// success:function(res){
// }
// })

//uni.redirectTo({url: '/pages/success/index?orderId=' + _this.orderId });
} else {
wx.showModal({
title: "提示",
content: res.msg,
});
}
});
}
},
// // 订单倒计时
runTimeBack: function runTimeBack() {
var end = Date.parse(
this.orderDataInfo.orderTime.replace(/-/g, "/")
);
var now = Date.parse(new Date());
var m15 = 15 * 60 * 1000;
var msec = m15 - (now - end);
if (msec < 0) {
this.timeout = true;
clearTimeout(this.times);
} else {
var min = parseInt((msec / 1000 / 60) % 60);
var sec = parseInt((msec / 1000) % 60);
if (min < 10) {
min = "0" + min;
} else {
min = min;
}
if (sec < 10) {
sec = "0" + sec;
} else {
sec = sec;
}
this.rocallTime = min + ":" + sec;
var that = this;
if (min >= 0 && sec >= 0) {
if (min === 0 && sec === 0) {
this.timeout = true;
clearTimeout(this.times);
return;
}
this.times = setTimeout(function () {
that.runTimeBack();
}, 1000);
}
}
},
}
),
};
exports.default = _default;
/* WEBPACK VAR INJECTION */
}).call(
this,
__webpack_require__(
/*! ./node_modules/@dcloudio/uni-mp-weixin/dist/index.js */ 1
)["default"]
);

/***/
},
},
[[56, "common/runtime", "common/vendor"]],
]);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/pay/index.js.map