| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.utils.OrderNos; |
| | | import com.ruoyi.system.dto.CreateOrderDto; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | |
| | | order.setPartnerOrderId(createOrderVo.getPartnerOrderId()); |
| | | order.setOrderPrice(new BigDecimal(createOrderVo.getOrderAmount()).setScale(2, BigDecimal.ROUND_HALF_UP)); |
| | | |
| | | // 获取票价 |
| | | BigDecimal ticketPrice = order.getOrderPrice().divide(new BigDecimal(dto.getQuantity()), 2, BigDecimal.ROUND_HALF_UP); |
| | | order.setTicketPrice(ticketPrice); |
| | | |
| | | |
| | | String result = dto.getVisitPersons().stream() |
| | | .map(String::valueOf) // Integer 转 String |
| | |
| | | |
| | | order.setTicketInfo(dto.getProductName()); |
| | | boolean save = this.save(order); |
| | | |
| | | |
| | | return save; |
| | | } |
| | | |
| | | @Override |
| | | public boolean refundOrder(TTicketOrder order) throws Exception { |
| | | String nowTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | // 查询未使用的票 |
| | | String visitPersons = order.getVisitPersons(); |
| | | JSONArray jsonArray = JSONArray.parseArray(visitPersons); |
| | | List<String> ticketIds = new ArrayList<>(); |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | JSONObject jsonObject = jsonArray.getJSONObject(i); |
| | | Integer status = jsonObject.getInteger("status"); |
| | | if(status==null || status==0){ |
| | | String ticketId = jsonObject.getString("ticketId"); |
| | | ticketIds.add(ticketId); |
| | | } |
| | | } |
| | | if(ticketIds.isEmpty()){ |
| | | throw new RuntimeException("无未使用的票"); |
| | | } |
| | | boolean refund = ticketUtil.cannelTicket(order.getOrderNo(), order.getPartnerOrderId(), ticketIds); |
| | | if(refund){ |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | JSONObject jsonObject = jsonArray.getJSONObject(i); |
| | | Integer status = jsonObject.getInteger("status"); |
| | | if(status==null || status==0){ |
| | | jsonObject.put("status",2); |
| | | jsonObject.put("refundTime",System.currentTimeMillis()); |
| | | } |
| | | } |
| | | |
| | | // jsonArray 转换为字符串 |
| | | String result = jsonArray.toJSONString(); |
| | | order.setVisitPersons(result); |
| | | order.setStatus(4); |
| | | order.setRefundMoney(order.getTicketPrice().multiply(new BigDecimal(ticketIds.size()))); |
| | | boolean update = this.updateById(order); |
| | | return update; |
| | | } |
| | | return false; |
| | | } |
| | | } |