| | |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.oying.exception.BadRequestException; |
| | | import com.oying.modules.hwc.domain.HwcResponse; |
| | | import com.oying.modules.hwc.service.SwiftPassService; |
| | | import com.oying.modules.pc.product.domain.Product; |
| | | import com.oying.modules.pc.product.domain.enums.ProductStatusEnum; |
| | | import com.oying.modules.pc.product.service.ProductService; |
| | | import com.oying.modules.pc.store.domain.Store; |
| | | import com.oying.modules.pc.store.service.StoreService; |
| | | import com.oying.modules.sh.domain.Order; |
| | | import com.oying.modules.sh.domain.OrderProductSnapshot; |
| | | import com.oying.modules.sh.domain.request.GeneratorOrder; |
| | |
| | | import com.oying.modules.sh.service.UserAddressService; |
| | | import com.oying.utils.*; |
| | | import com.oying.utils.enums.GenerateEnum; |
| | | import com.oying.utils.enums.OrderStatusEnum; |
| | | import com.oying.utils.enums.PayStateEnum; |
| | | import com.oying.utils.enums.PayTypeEnum; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | private final SwiftPassService swiftPassService; |
| | | private final OrderProductSnapshotService productSnapshotService; |
| | | private final RedisUtils redisUtils; |
| | | private final StoreService storeService; |
| | | private final static String DESCRIBE = "哦应:"; |
| | | |
| | | @Override |
| | | public PageResult<Order> queryAll(OrderQueryCriteria criteria, Page<Object> page) { |
| | |
| | | snapshot.setPayState(PayStateEnum.NOTPAY.getKey()); |
| | | snapshots.add(snapshot); |
| | | } |
| | | Timestamp now = DateUtil.getTimeStamp(); |
| | | // 下单后30分钟失效 |
| | | Timestamp time = DateUtil.addMinute(DateUtil.getTimeStamp(), 30); |
| | | Timestamp time = DateUtil.addMinute(now, 30); |
| | | String expire = DateUtil.localDateTimeFormat(time.toLocalDateTime(), DateUtil.SDF_YMDHMS); |
| | | swiftPassService.pay(StringUtils.getIp(request), BigDecimalUtils.yuanToCents(amount).toString(), expire,SecurityUtils.getCurrentUserId()); |
| | | String openid = SecurityUtils.getCurrentOpenid(); |
| | | if (openid == null || openid.isEmpty()) { |
| | | throw new BadRequestException("OPENID错误"); |
| | | } |
| | | // 订单信息 |
| | | Order order = new Order(); |
| | | order.setOrderNum(orderNum); |
| | | order.setOrderStatus(OrderStatusEnum.ZERO.getKey()); |
| | | order.setOrderStatusDescribe(OrderStatusEnum.ZERO.getValue()); |
| | | order.setUserId(SecurityUtils.getCurrentUserId()); |
| | | order.setUsername(SecurityUtils.getCurrentUsername()); |
| | | Store store = storeService.getById(submit.getStoreId()); |
| | | order.setStoreId(submit.getStoreId()); |
| | | order.setStoreName(store.getStoreName()); |
| | | order.setStoreLogo(store.getLogoImageUrl()); |
| | | order.setOrderDescribe(DESCRIBE + submit.getStoreId()); |
| | | order.setOriginalPrice(amount); |
| | | order.setPaidPrice(amount); |
| | | order.setActuallyPayPrice(amount); |
| | | order.setOpenid(openid); |
| | | order.setPayType(submit.getPayType().getKey()); |
| | | order.setExpireTime(expire); |
| | | order.setOpenid(openid); |
| | | Long total = BigDecimalUtils.yuanToCents(amount); |
| | | if (total > 0) { |
| | | HwcResponse response = swiftPassService.pay(StringUtils.getIp(request), total.toString(), expire, |
| | | DESCRIBE + submit.getStoreId(), openid, orderNum, submit.getPayType()); |
| | | //微信支付下单放回值 |
| | | order.setAppId(response.getAppId()); |
| | | order.setTimestamp(response.getTimeStamp()); |
| | | order.setNonceStr(response.getNonceStr()); |
| | | order.setPackageVal(response.getPackageVal()); |
| | | order.setSignType(response.getSignType()); |
| | | order.setPaySign(response.getPaySign()); |
| | | order.setPayState(PayStateEnum.NOTPAY.getKey()); |
| | | order.setPayMessage(PayStateEnum.NOTPAY.getValue()); |
| | | order.setPayTime(null); |
| | | } else { |
| | | order.setPayState(PayStateEnum.SUCCESS.getKey()); |
| | | order.setPayMessage(PayStateEnum.SUCCESS.getValue()); |
| | | order.setPayTime(DateUtil.localDateTimeFormat(now.toLocalDateTime(), DateUtil.SDF_YMDHMS)); |
| | | } |
| | | orderMapper.insert(order); |
| | | productSnapshotService.saveBatch(snapshots); |
| | | return null; |
| | | return order; |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (product == null) { |
| | | throw new BadRequestException("商品不存在"); |
| | | } |
| | | if (product.getStoreId().equals(criteria.getStoreId())) { |
| | | if (!product.getStoreId().equals(criteria.getStoreId())) { |
| | | throw new BadRequestException("不支持跨门店下单"); |
| | | } |
| | | if (!product.getStatus().equals(ProductStatusEnum.AVAILABLE.getValue())) { |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Order getByOrderNum(String orderNum) { |
| | | return orderMapper.getByOrderNum(orderNum); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void paySuccess(Order order) { |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updatePayStatus(String orderNum, PayStateEnum payState, String payMessage, String payTime) { |
| | | orderMapper.updatePayStatus(orderNum, payState.getKey(), payMessage, payTime); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void closeOrder(String orderNum) { |
| | | Order order = getByOrderNum(orderNum); |
| | | if (order == null) { |
| | | throw new BadRequestException("订单不存在"); |
| | | } |
| | | PayTypeEnum anEnum = PayTypeEnum.find(order.getPayType()); |
| | | switch (anEnum) { |
| | | case HWC: |
| | | case HWC2: |
| | | JSONObject object = swiftPassService.query(orderNum, anEnum); |
| | | if (object.getString("trade_state").equals(PayStateEnum.SUCCESS.getKey())) { |
| | | throw new BadRequestException("订单已支付"); |
| | | } |
| | | if (object.getString("trade_state").equals(PayStateEnum.CLOSED.getKey())) { |
| | | throw new BadRequestException("订单已关闭"); |
| | | } |
| | | swiftPassService.closeOrder(orderNum, anEnum); |
| | | break; |
| | | } |
| | | orderMapper.updateCloseStatus(orderNum, PayStateEnum.CLOSED.getKey()); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void create(Order resources) { |
| | | orderMapper.insert(resources); |
| | | } |