| | |
| | | package com.ruoyi.order.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.feignClient.AppUserAddressClient; |
| | | import com.ruoyi.account.api.model.TAppUserAddress; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.order.api.model.TExchangeOrder; |
| | | import com.ruoyi.order.api.model.TShoppingOrder; |
| | | import com.ruoyi.order.api.query.TActivityStatisticsQuery; |
| | | import com.ruoyi.order.api.vo.TActivityStatisticslVO; |
| | | import com.ruoyi.order.api.vo.TActivityVO; |
| | | import com.ruoyi.order.dto.*; |
| | | import com.ruoyi.order.mapper.TShoppingOrderMapper; |
| | | import com.ruoyi.order.service.TShoppingOrderService; |
| | | import com.ruoyi.other.api.domain.TCoupon; |
| | | import com.ruoyi.other.api.domain.TGoods; |
| | | import com.ruoyi.other.api.feignClient.CouponClient; |
| | | import com.ruoyi.other.api.feignClient.GoodsClient; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Service |
| | | public class TShoppingOrderServiceImpl extends ServiceImpl<TShoppingOrderMapper, TShoppingOrder> implements TShoppingOrderService { |
| | | |
| | | @Resource |
| | | private TokenService tokenService; |
| | | |
| | | @Resource |
| | | private GoodsClient goodsClient; |
| | | |
| | | @Resource |
| | | private CouponClient couponClient; |
| | | |
| | | @Resource |
| | | private AppUserAddressClient appUserAddressClient; |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public TActivityVO activityStatistics(TActivityStatisticsQuery dto) { |
| | |
| | | res.setGrantVip(grantVip); |
| | | return res; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取小程序商城购买订单列表 |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<MyShoppingOrderList> getMyShoppingOrderList(GetMyShoppingOrderList query) { |
| | | Long userId = tokenService.getLoginUserApplet().getUserId(); |
| | | LambdaQueryWrapper<TShoppingOrder> wrapper = new LambdaQueryWrapper<TShoppingOrder>().eq(TShoppingOrder::getDelFlag, 0) |
| | | .eq(TShoppingOrder::getAppUserId, userId); |
| | | if(query.getStatus() != 0){ |
| | | wrapper.eq(TShoppingOrder::getStatus, query.getStatus()); |
| | | } |
| | | List<TShoppingOrder> list = this.list(wrapper.orderByDesc(TShoppingOrder::getCreateTime).last(" limit " + query.getPageCurr() + ", " + query.getPageSize())); |
| | | List<MyShoppingOrderList> pageList = new ArrayList<>(); |
| | | for (TShoppingOrder tShoppingOrder : list) { |
| | | MyShoppingOrderList myShoppingOrderList = new MyShoppingOrderList(); |
| | | myShoppingOrderList.setId(tShoppingOrder.getId().toString()); |
| | | String name = ""; |
| | | String imgUrl = ""; |
| | | if(tShoppingOrder.getOrderType() == 1){ |
| | | TGoods goods = goodsClient.getGoodsById(tShoppingOrder.getGoodsId()).getData(); |
| | | name = goods.getName(); |
| | | imgUrl = goods.getCoverPicture(); |
| | | }else{ |
| | | TCoupon coupon = couponClient.getCouponById1(tShoppingOrder.getGoodsId()).getData(); |
| | | name = coupon.getName(); |
| | | imgUrl = coupon.getCoverPicture(); |
| | | } |
| | | myShoppingOrderList.setName(name); |
| | | myShoppingOrderList.setImgUrl(imgUrl); |
| | | myShoppingOrderList.setStatus(tShoppingOrder.getStatus()); |
| | | BigDecimal unitPrice = tShoppingOrder.getPaymentAmount().divide(new BigDecimal(tShoppingOrder.getPurchaseQuantity())).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | myShoppingOrderList.setUnitPrice(unitPrice); |
| | | myShoppingOrderList.setNumber(tShoppingOrder.getPurchaseQuantity()); |
| | | myShoppingOrderList.setPaymentAmount(tShoppingOrder.getPaymentAmount()); |
| | | pageList.add(myShoppingOrderList); |
| | | } |
| | | return pageList; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取购买订单详情 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public MyShoppingOrderInfo getMyShoppingOrderInfo(String id) { |
| | | TShoppingOrder shoppingOrder = this.getById(id); |
| | | MyShoppingOrderInfo info = new MyShoppingOrderInfo(); |
| | | info.setId(id); |
| | | info.setStatus(shoppingOrder.getStatus()); |
| | | TAppUserAddress userAddress = appUserAddressClient.getAppUserAddressById(shoppingOrder.getAppUserAddressId()).getData(); |
| | | info.setConsignee(userAddress.getName()); |
| | | info.setPhone(userAddress.getPhone()); |
| | | info.setAddress(userAddress.getAddress()); |
| | | info.setExpressCompany(shoppingOrder.getExpressCompany()); |
| | | info.setExpressNumber(shoppingOrder.getExpressNumber()); |
| | | String name = ""; |
| | | String imgUrl = ""; |
| | | if(shoppingOrder.getOrderType() == 1){ |
| | | TGoods goods = goodsClient.getGoodsById(shoppingOrder.getGoodsId()).getData(); |
| | | name = goods.getName(); |
| | | imgUrl = goods.getCoverPicture(); |
| | | }else{ |
| | | TCoupon coupon = couponClient.getCouponById1(shoppingOrder.getGoodsId()).getData(); |
| | | info.setCouponType(coupon.getType()); |
| | | info.setDays(coupon.getDays()); |
| | | info.setEndTime(coupon.getEndTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | name = coupon.getName(); |
| | | imgUrl = coupon.getCoverPicture(); |
| | | } |
| | | info.setName(name); |
| | | info.setImgUrl(imgUrl); |
| | | info.setNumber(shoppingOrder.getPurchaseQuantity()); |
| | | BigDecimal unitPrice = shoppingOrder.getPaymentAmount().divide(new BigDecimal(shoppingOrder.getPurchaseQuantity())).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | info.setUnitPrice(unitPrice); |
| | | info.setCode(shoppingOrder.getCode()); |
| | | info.setCreateTime(shoppingOrder.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | info.setPaymentAmount(shoppingOrder.getPaymentAmount()); |
| | | info.setRemark(shoppingOrder.getRemark()); |
| | | info.setDeliveryTime(shoppingOrder.getConsignerTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | info.setFinishTime(shoppingOrder.getReceivingTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | return info; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 取消订单 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public AjaxResult cancelOrder(String id) { |
| | | TShoppingOrder shoppingOrder = this.getById(id); |
| | | if(shoppingOrder.getStatus() == 2){ |
| | | return AjaxResult.error("订单已发货,不能取消"); |
| | | } |
| | | if(shoppingOrder.getStatus() == 3){ |
| | | return AjaxResult.error("订单已完成,不能取消"); |
| | | } |
| | | if(shoppingOrder.getStatus() == 4){ |
| | | return AjaxResult.error("订单已取消,不能重复操作"); |
| | | } |
| | | //先查询第三方订单状态订单是否退款 |
| | | //支付方式(1=微信,2=支付宝) todo 待完善 |
| | | Integer paymentType = shoppingOrder.getPaymentType(); |
| | | if(1 == paymentType){ |
| | | |
| | | } |
| | | if(2 == paymentType){ |
| | | |
| | | } |
| | | //退款成功后需要判断商品库存类型后决定是否需要回退库存 |
| | | //加redis锁处理高并发 |
| | | |
| | | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取未开票的订单列表 |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<MyShoppingOrderList> getNoInvoicedOrder(GetNoInvoicedOrder query) { |
| | | Long userId = tokenService.getLoginUserApplet().getUserId(); |
| | | List<TShoppingOrder> list = this.baseMapper.getNoInvoicedOrder(userId, query.getMonth(), query.getPageCurr(), query.getPageSize()); |
| | | List<MyShoppingOrderList> pageList = new ArrayList<>(); |
| | | for (TShoppingOrder tShoppingOrder : list) { |
| | | MyShoppingOrderList myShoppingOrderList = new MyShoppingOrderList(); |
| | | myShoppingOrderList.setId(tShoppingOrder.getId().toString()); |
| | | String name = ""; |
| | | String imgUrl = ""; |
| | | if(tShoppingOrder.getOrderType() == 1){ |
| | | TGoods goods = goodsClient.getGoodsById(tShoppingOrder.getGoodsId()).getData(); |
| | | name = goods.getName(); |
| | | imgUrl = goods.getCoverPicture(); |
| | | }else{ |
| | | TCoupon coupon = couponClient.getCouponById1(tShoppingOrder.getGoodsId()).getData(); |
| | | name = coupon.getName(); |
| | | imgUrl = coupon.getCoverPicture(); |
| | | } |
| | | myShoppingOrderList.setName(name); |
| | | myShoppingOrderList.setImgUrl(imgUrl); |
| | | myShoppingOrderList.setStatus(tShoppingOrder.getStatus()); |
| | | BigDecimal unitPrice = tShoppingOrder.getPaymentAmount().divide(new BigDecimal(tShoppingOrder.getPurchaseQuantity())).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | myShoppingOrderList.setUnitPrice(unitPrice); |
| | | myShoppingOrderList.setNumber(tShoppingOrder.getPurchaseQuantity()); |
| | | myShoppingOrderList.setPaymentAmount(tShoppingOrder.getPaymentAmount()); |
| | | pageList.add(myShoppingOrderList); |
| | | } |
| | | return pageList; |
| | | } |
| | | } |