From 9ac1280729d0c776b2f19a08314c183a922a1956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E7=A3=8A?= <45566618@qq.com> Date: Fri, 21 Jun 2024 13:53:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E6=88=90=E5=BE=85=E8=A1=A5=E5=8D=95,?= =?UTF-8?q?=E9=80=80=E6=AC=BE=E5=BE=85=E8=A1=A5=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ArtificerController.java | 10 +- .../app/AppArtificerController.java | 11 +- .../artificer/service/ArtificerService.java | 2 +- .../artificer/service/OrdersService.java | 2 + .../service/impl/ArtificerServiceImpl.java | 6 +- .../service/impl/OrdersServiceImpl.java | 922 ++++++++++++++---- 6 files changed, 778 insertions(+), 175 deletions(-) diff --git a/src/main/java/com/sqx/modules/artificer/controller/ArtificerController.java b/src/main/java/com/sqx/modules/artificer/controller/ArtificerController.java index 0bf9ea0..8c37b96 100644 --- a/src/main/java/com/sqx/modules/artificer/controller/ArtificerController.java +++ b/src/main/java/com/sqx/modules/artificer/controller/ArtificerController.java @@ -117,9 +117,9 @@ public class ArtificerController { @ApiOperation("查询技师列表") public Result selectArtificerList(Integer page, Integer limit, Long massageTypeId, String artificerName, String longitude,String latitude,Integer sort,Integer authentication, - Integer by,String city,Long classifyId,String phone,Integer isStart){ + Integer by,String city,Long classifyId,String phone,Integer isStart,Integer technicianType){ return artificerService.selectArtificerList(page, limit, massageTypeId, artificerName,longitude,latitude, - sort,authentication,by,null,city,classifyId,phone,null,isStart); + sort,authentication,by,null,city,classifyId,phone,null,isStart,technicianType); } @GetMapping("/selectArtificer") @@ -228,6 +228,12 @@ public class ArtificerController { return ordersService.cancelOrders(null,ordersId); } + @PostMapping("/cancelSupplementOrders") + @ApiOperation("待补单处理及待补单全单退款") + public Result cancelSupplementOrders(Long ordersId,Integer isAuto,Integer type){ + return ordersService.cancelSupplementOrders(null,ordersId,isAuto,type); + } + @PostMapping("/updateOrders") @ApiOperation("修改订单") public Result updateOrders(@RequestBody Orders orders){ diff --git a/src/main/java/com/sqx/modules/artificer/controller/app/AppArtificerController.java b/src/main/java/com/sqx/modules/artificer/controller/app/AppArtificerController.java index 2d7e69f..81b7506 100644 --- a/src/main/java/com/sqx/modules/artificer/controller/app/AppArtificerController.java +++ b/src/main/java/com/sqx/modules/artificer/controller/app/AppArtificerController.java @@ -131,9 +131,9 @@ public class AppArtificerController { @ApiOperation("查询技师列表") public Result selectArtificerList(Integer page, Integer limit, Long massageTypeId, String artificerName, String longitude,String latitude,Integer sort,Integer authentication, - Integer by,String city,Long classifyId,String phone, Integer isStart){ + Integer by,String city,Long classifyId,String phone, Integer isStart,Integer technicianType){ return artificerService.selectArtificerList(page, limit, massageTypeId, artificerName,longitude,latitude, - sort,authentication,by,-1,city,classifyId,phone,1,isStart); + sort,authentication,by,-1,city,classifyId,phone,1,isStart,technicianType); } @@ -197,6 +197,13 @@ public class AppArtificerController { return ordersService.cancelOrders(userId,ordersId); } + @Login + @PostMapping("/cancelSupplementOrders") + @ApiOperation("变成待补单或全额退待补单") + public Result cancelSupplementOrders(@RequestAttribute Long userId,Long ordersId,Integer isAuto,Integer type){ + return ordersService.cancelSupplementOrders(userId,ordersId,isAuto,type); + } + @Login @GetMapping("/selectOrdersDetails") @ApiOperation("查询订单详情") diff --git a/src/main/java/com/sqx/modules/artificer/service/ArtificerService.java b/src/main/java/com/sqx/modules/artificer/service/ArtificerService.java index e332e8a..8222cc5 100644 --- a/src/main/java/com/sqx/modules/artificer/service/ArtificerService.java +++ b/src/main/java/com/sqx/modules/artificer/service/ArtificerService.java @@ -14,7 +14,7 @@ public interface ArtificerService extends IService { Result selectArtificerList(Integer page, Integer limit, Long massageTypeId, String artificerName, String longitude,String latitude,Integer sort,Integer authentication, - Integer by,Integer status,String city,Long classifyId,String phone,Integer user, Integer isStart); + Integer by,Integer status,String city,Long classifyId,String phone,Integer user, Integer isStart,Integer technicianType); Artificer selectArtificerById(Long userId,Long artificerId,String longitude,String latitude); diff --git a/src/main/java/com/sqx/modules/artificer/service/OrdersService.java b/src/main/java/com/sqx/modules/artificer/service/OrdersService.java index 39b5503..a11703b 100644 --- a/src/main/java/com/sqx/modules/artificer/service/OrdersService.java +++ b/src/main/java/com/sqx/modules/artificer/service/OrdersService.java @@ -20,6 +20,8 @@ public interface OrdersService extends IService { Result cancelOrders(Long userId,Long ordersId); + Result cancelSupplementOrders(Long userId, Long ordersId, Integer isAuto, Integer type); + Result removeOrders(Long ordersId); Result refundOrdersMoney(Long ordersId,BigDecimal refundMoney); diff --git a/src/main/java/com/sqx/modules/artificer/service/impl/ArtificerServiceImpl.java b/src/main/java/com/sqx/modules/artificer/service/impl/ArtificerServiceImpl.java index 6c33a07..7d36572 100644 --- a/src/main/java/com/sqx/modules/artificer/service/impl/ArtificerServiceImpl.java +++ b/src/main/java/com/sqx/modules/artificer/service/impl/ArtificerServiceImpl.java @@ -69,10 +69,10 @@ public class ArtificerServiceImpl extends ServiceImpl i @Override public Result selectArtificerList(Integer page, Integer limit, Long massageTypeId,String artificerName, String longitude,String latitude,Integer sort,Integer authentication, - Integer by,Integer status,String city,Long classifyId,String phone,Integer user, Integer isStart){ + Integer by,Integer status,String city,Long classifyId,String phone,Integer user, Integer isStart,Integer technicianType){ Page pages=new Page<>(page,limit); IPage artificerIPage = baseMapper.selectArtificerList(pages, massageTypeId, artificerName, - longitude, latitude, sort, authentication, by, status, city, classifyId,phone,user,isStart); + longitude, latitude, sort, authentication, by, status, city, classifyId,phone,user,isStart,technicianType); List records = artificerIPage.getRecords(); String value = commonInfoService.findOne(392).getValue(); if("30".equals(value)){ @@ -427,7 +427,7 @@ public class ArtificerServiceImpl extends ServiceImpl i public Result getHomeArtificerList(Integer page, Integer limit, Integer isStart,Integer status, String city, String longitude, String latitude){ Map map = new HashMap(); Page pages=new Page<>(page,limit); - IPage artificerIPage = baseMapper.selectArtificerList(pages, null, "",longitude, latitude, 1, 2, 1, status, city, null,"",1,isStart); + IPage artificerIPage = baseMapper.selectArtificerList(pages, null, "",longitude, latitude, 1, 2, 1, status, city, null,"",1,isStart,null); map.put("nearData",new PageUtils(artificerIPage)); map.put("startData",new PageUtils(baseMapper.getHomeStartArtificerList(pages,isStart,status,city))); return Result.success(map); diff --git a/src/main/java/com/sqx/modules/artificer/service/impl/OrdersServiceImpl.java b/src/main/java/com/sqx/modules/artificer/service/impl/OrdersServiceImpl.java index 2426434..173a779 100644 --- a/src/main/java/com/sqx/modules/artificer/service/impl/OrdersServiceImpl.java +++ b/src/main/java/com/sqx/modules/artificer/service/impl/OrdersServiceImpl.java @@ -330,6 +330,15 @@ public class OrdersServiceImpl extends ServiceImpl implements } orders.setVipRate(vipRate); + Artificer artificer = artificerService.getById(orders.getArtificerId()); + orders.setTechnicianType(artificer.getTechnicianType()); + BigDecimal artificerVipRate = BigDecimal.ZERO; + VipDetails artificerVipDetails = vipDetailsDao.selectOne(new QueryWrapper().eq("vip_name_type", artificer.getTechnicianType())); + if (artificerVipDetails != null) { + artificerVipRate = artificerVipDetails.getRate(); + } + orders.setTechnicianRate(artificerVipRate); + BigDecimal payMoney = BigDecimal.ZERO; List ordersMassageList = orders.getOrdersMassageList(); @@ -341,7 +350,8 @@ public class OrdersServiceImpl extends ServiceImpl implements for (OrdersMassage ordersMassage : ordersMassageList) { price = massageType.getPrice().multiply(BigDecimal.valueOf(ordersMassage.getNum())); - BigDecimal massagePrice = price.multiply(orders.getVipRate()); + BigDecimal massagePrice = price.multiply(orders.getTechnicianRate()).divide(new BigDecimal(100)).add(price);//技师等级加成金额 + massagePrice = massagePrice.multiply(orders.getVipRate()).divide(new BigDecimal(100));//会员优惠后金额 massageTypeName = massageType.getTitle(); payMoney = massagePrice.add(payMoney); @@ -355,10 +365,14 @@ public class OrdersServiceImpl extends ServiceImpl implements orders.setEntryName(massageTypeName); //判断金额是否满足代金券金额最少消费额度 - if(couponMinMoney.compareTo(couponMinMoney) < 0){ + if(payMoney.compareTo(couponMinMoney) < 0){ return Result.error("当前应付总金额不满足优惠券使用的最小额度,请重新选择优惠卷!"); } + //减去代金券的金额 + payMoney = payMoney.subtract(orders.getCouponMoney()); + orders.setMassageMoney(payMoney); + String value1 = commonInfoService.findOne(395).getValue(); int i = 0; //1.锁定本单服务时间问题 @@ -472,10 +486,7 @@ public class OrdersServiceImpl extends ServiceImpl implements } //加上车费 orders.setPayMoney(payMoney.add(taxiMoney)); - //减去代金券的金额 - orders.setPayMoney(orders.getPayMoney().subtract(orders.getCouponMoney())); - Artificer artificer = artificerService.getById(orders.getArtificerId()); //查询是否计算出租车扣费 String taxi = commonInfoService.findOne(394).getValue(); //计算技师出租车收益(按照技师表收益计算) @@ -504,8 +515,8 @@ public class OrdersServiceImpl extends ServiceImpl implements } //计算项目收益 - //去掉优惠卷金额的项目金额 - BigDecimal projectBenefits = price.subtract(orders.getCouponMoney()); + //获取项目应支付金额 + BigDecimal projectBenefits = orders.getMassageMoney(); //计算技师项目提成金额 orders.setProjectBenefits(projectBenefits.multiply(artificer.getRate()).setScale(2,BigDecimal.ROUND_HALF_UP)); @@ -627,6 +638,7 @@ public class OrdersServiceImpl extends ServiceImpl implements //保存现价 orders.setPrice(price); orders.setEntryName(massageTypeName); + orders.setMassageMoney(payMoney); String value1 = commonInfoService.findOne(395).getValue(); int i = 0; @@ -771,8 +783,10 @@ public class OrdersServiceImpl extends ServiceImpl implements } //计算项目收益 + //获取项目应支付金额 + BigDecimal projectBenefits = orders.getMassageMoney(); //计算技师项目提成金额 - orders.setProjectBenefits(packagePrice.multiply(artificer.getRate()).setScale(2,BigDecimal.ROUND_HALF_UP)); + orders.setProjectBenefits(projectBenefits.multiply(artificer.getRate()).setScale(2,BigDecimal.ROUND_HALF_UP)); orders.setArtificerMoney(artificerPrice); orders.setSumArtificerMoney(orders.getArtificerMoney()); @@ -1179,28 +1193,28 @@ public class OrdersServiceImpl extends ServiceImpl implements userMoneyDetails.setManipulateType(2); userMoneyDetails.setMoney(orders.getSumArtificerMoney()); userMoneyDetails.setUserId(artificerUser.getUserId()); - userMoneyDetails.setContent("订单号:" + orders.getOrdersNo() + ",订单取消!"); + userMoneyDetails.setTitle("订单号:" + orders.getOrdersNo() + ",订单取消!"); String value = commonInfoService.findOne(394).getValue(); if ("是".equals(value)) { if (orders.getShopUserId() != null) { - userMoneyDetails.setTitle("用户取消订单,总扣除:" + sumMoney + ",平台扣除:" + orders.getPingMoney() + + userMoneyDetails.setContent("用户取消订单,总扣除:" + sumMoney + ",平台扣除:" + orders.getPingMoney() + ",商家扣除:" + orders.getShopMoney() + ",用户代理扣除:" + orders.getOneUserMoney() + ",技师代理扣除:" + orders.getOneArtificerMoney() + ",打车费:" + orders.getTaxiMoney() + ",平台扣除打车费:" + orders.getPingTaxiMoney() + ",到账打车费:" + orders.getArtificerTaxiMoney() + ",到账总金额:" + orders.getSumArtificerMoney()); } else { - userMoneyDetails.setTitle("用户取消订单,总扣除:" + sumMoney + ",平台扣除:" + orders.getPingMoney() + + userMoneyDetails.setContent("用户取消订单,总扣除:" + sumMoney + ",平台扣除:" + orders.getPingMoney() + ",用户代理扣除:" + orders.getOneUserMoney() + ",技师代理扣除:" + orders.getOneArtificerMoney() + ",打车费:" + orders.getTaxiMoney() + ",平台扣除打车费:" + orders.getPingTaxiMoney() + ",到账打车费:" + orders.getArtificerTaxiMoney() + ",到账总金额:" + orders.getSumArtificerMoney()); } } else { if (orders.getShopUserId() != null) { - userMoneyDetails.setTitle("用户取消订单,总扣除:" + sumMoney + ",平台扣除:" + orders.getPingMoney() + + userMoneyDetails.setContent("用户取消订单,总扣除:" + sumMoney + ",平台扣除:" + orders.getPingMoney() + ",商家扣除:" + orders.getShopMoney() + ",用户代理扣除:" + orders.getOneUserMoney() + ",技师代理扣除:" + orders.getOneArtificerMoney() + ",打车费:" + orders.getTaxiMoney() + ",到账总金额:" + orders.getSumArtificerMoney()); } else { - userMoneyDetails.setTitle("用户取消订单,总扣除:" + sumMoney + ",平台扣除:" + orders.getPingMoney() + + userMoneyDetails.setContent("用户取消订单,总扣除:" + sumMoney + ",平台扣除:" + orders.getPingMoney() + ",用户代理扣除:" + orders.getOneUserMoney() + ",技师代理扣除:" + orders.getOneArtificerMoney() + ",打车费:" + orders.getTaxiMoney() + ",到账总金额:" + orders.getSumArtificerMoney()); @@ -1416,8 +1430,7 @@ public class OrdersServiceImpl extends ServiceImpl implements }else{ taxiMoneyDeduction = trafficDeduction; } - //项目总扣款数 - BigDecimal rate = BigDecimal.ZERO; + //退款金额 BigDecimal userMoney = orders.getTaxiMoney().subtract(taxiMoneyDeduction); @@ -1445,13 +1458,7 @@ public class OrdersServiceImpl extends ServiceImpl implements userMoneyDetails.setManipulateType(1); userMoneyDetails.setBlFlag(2); } else { - //暂无用 -// if (orders.getUserArtificerMoney() != null && orders.getUserArtificerMoney() == 1) { -// -// userMoneyArtificerService.updateMoney(1, orders.getUserId(), orders.getArtificerId(), userMoney.doubleValue()); -// } else { userMoneyService.updateMoney(1, orders.getUserId(), userMoney.doubleValue()); -// } //查询用户当前余额 UserMoney userNowMoney = userMoneyService.selectUserMoneyByUserId(orders.getUserId()); //插入余额 @@ -1473,11 +1480,10 @@ public class OrdersServiceImpl extends ServiceImpl implements //按照比例 将扣除的钱进行分佣 BigDecimal taxiMoney = taxiMoneyDeduction; - BigDecimal sumMoney = rate.add(taxiMoneyDeduction);//总扣费 + BigDecimal sumMoney = taxiMoneyDeduction;//总扣费 Artificer artificer = artificerService.getById(orders.getArtificerId()); BigDecimal artificerTaxiMoney = taxiMoneyDeduction;//扣车费 BigDecimal pingTaxiMoney = BigDecimal.ZERO; - BigDecimal artificerMoney = rate.multiply(artificer.getRate()); //技师获得扣款提成 String taxi = commonInfoService.findOne(394).getValue(); if ("是".equals(taxi)) { @@ -1485,51 +1491,16 @@ public class OrdersServiceImpl extends ServiceImpl implements pingTaxiMoney = taxiMoney.subtract(artificerTaxiMoney); } - UserEntity user = userService.selectUserById(orders.getUserId()); - - UserEntity oneUser = userService.queryByInvitationCode(user.getInviterCode()); - - BigDecimal oneUserMoney = BigDecimal.ZERO; - if (oneUser != null && oneUser.getIsAgency() != null && oneUser.getIsAgency() == 1) { - orders.setOneUserId(oneUser.getUserId()); - orders.setOneUserName(oneUser.getUserName()); - oneUserMoney = rate.multiply(oneUser.getUserRate()); - } - - UserEntity artificerUser = userService.selectUserById(artificer.getUserId()); - - UserEntity oneArtificerUser = userService.queryByInvitationCode(artificerUser.getInviterCode()); - - BigDecimal oneArtificerMoney = BigDecimal.ZERO; - if (oneArtificerUser != null && oneArtificerUser.getIsAgency() != null && oneArtificerUser.getIsAgency() == 1) { - orders.setOneArtificerUserId(oneArtificerUser.getUserId()); - orders.setOneArtificerUserName(oneArtificerUser.getUserName()); - oneArtificerMoney = rate.multiply(oneArtificerUser.getShopRate()); - } - - BigDecimal shopMoney = BigDecimal.ZERO; - if (artificerUser.getConsortiaId() != null) { - Consortia consortia = consortiaService.getById(artificerUser.getConsortiaId()); - if (consortia != null && consortia.getUserId() != null) { - UserEntity consortiaUser = userService.getById(consortia.getUserId()); - if (consortiaUser != null) { - shopMoney = rate.multiply(consortia.getRate()); - } - } - } - rate = rate.subtract(artificerMoney); - rate = rate.subtract(oneUserMoney); - rate = rate.subtract(shopMoney); - rate = rate.subtract(oneArtificerMoney).setScale(2, BigDecimal.ROUND_DOWN); - orders.setShopMoney(shopMoney.setScale(2, BigDecimal.ROUND_DOWN)); - orders.setArtificerMoney(artificerMoney.setScale(2, BigDecimal.ROUND_DOWN)); - orders.setSumArtificerMoney(artificerMoney.add(artificerTaxiMoney).setScale(2, BigDecimal.ROUND_DOWN)); - orders.setOneUserMoney(oneUserMoney.setScale(2, BigDecimal.ROUND_DOWN)); - orders.setOneArtificerMoney(oneArtificerMoney.setScale(2, BigDecimal.ROUND_DOWN)); - orders.setPingMoney(rate.setScale(2, BigDecimal.ROUND_DOWN)); + orders.setShopMoney(BigDecimal.ZERO); + orders.setArtificerMoney(BigDecimal.ZERO); + orders.setSumArtificerMoney(sumMoney.setScale(2, BigDecimal.ROUND_DOWN)); + orders.setOneUserMoney(BigDecimal.ZERO); + orders.setOneArtificerMoney(BigDecimal.ZERO); + orders.setPingMoney(BigDecimal.ZERO); orders.setArtificerTaxiMoney(artificerTaxiMoney.setScale(2, BigDecimal.ROUND_DOWN)); orders.setPingTaxiMoney(pingTaxiMoney.setScale(2, BigDecimal.ROUND_DOWN)); - //分账 + + UserEntity artificerUser = userService.selectUserById(artificer.getUserId()); userMoneyService.updateMoney(1, artificerUser.getUserId(), orders.getSumArtificerMoney().doubleValue()); userMoneyDetails = new UserMoneyDetails(); //查询用户当前余额 @@ -1540,109 +1511,17 @@ public class OrdersServiceImpl extends ServiceImpl implements userMoneyDetails.setManipulateType(2); userMoneyDetails.setMoney(orders.getSumArtificerMoney()); userMoneyDetails.setUserId(artificerUser.getUserId()); - userMoneyDetails.setContent("订单号:" + orders.getOrdersNo() + ",订单取消!"); - String value = commonInfoService.findOne(394).getValue(); - if ("是".equals(value)) { - if (orders.getShopUserId() != null) { - userMoneyDetails.setTitle("用户取消订单,总扣除:" + sumMoney + ",平台扣除:" + orders.getPingMoney() + - ",商家扣除:" + orders.getShopMoney() + ",用户代理扣除:" + orders.getOneUserMoney() + ",技师代理扣除:" + orders.getOneArtificerMoney() + - ",打车费:" + orders.getTaxiMoney() + ",平台扣除打车费:" + orders.getPingTaxiMoney() + ",到账打车费:" + orders.getArtificerTaxiMoney() + - ",到账总金额:" + orders.getSumArtificerMoney()); - } else { - userMoneyDetails.setTitle("用户取消订单,总扣除:" + sumMoney + ",平台扣除:" + orders.getPingMoney() + - ",用户代理扣除:" + orders.getOneUserMoney() + ",技师代理扣除:" + orders.getOneArtificerMoney() + - ",打车费:" + orders.getTaxiMoney() + ",平台扣除打车费:" + orders.getPingTaxiMoney() + ",到账打车费:" + orders.getArtificerTaxiMoney() + - ",到账总金额:" + orders.getSumArtificerMoney()); - } - } else { - if (orders.getShopUserId() != null) { - userMoneyDetails.setTitle("用户取消订单,总扣除:" + sumMoney + ",平台扣除:" + orders.getPingMoney() + - ",商家扣除:" + orders.getShopMoney() + ",用户代理扣除:" + orders.getOneUserMoney() + ",技师代理扣除:" + orders.getOneArtificerMoney() + - ",打车费:" + orders.getTaxiMoney() + - ",到账总金额:" + orders.getSumArtificerMoney()); - } else { - userMoneyDetails.setTitle("用户取消订单,总扣除:" + sumMoney + ",平台扣除:" + orders.getPingMoney() + - ",用户代理扣除:" + orders.getOneUserMoney() + ",技师代理扣除:" + orders.getOneArtificerMoney() + - ",打车费:" + orders.getTaxiMoney() + - ",到账总金额:" + orders.getSumArtificerMoney()); - } - } + userMoneyDetails.setTitle("订单号:" + orders.getOrdersNo() + ",订单取消!"); + userMoneyDetails.setContent("用户取消订单,总扣除:" + sumMoney + ",平台扣除:" + orders.getPingMoney() + + ",商家扣除:" + orders.getShopMoney() + ",用户代理扣除:" + orders.getOneUserMoney() + ",技师代理扣除:" + orders.getOneArtificerMoney() + + ",打车费:" + orders.getTaxiMoney() + ",平台扣除打车费:" + orders.getPingTaxiMoney() + ",到账打车费:" + orders.getArtificerTaxiMoney() + + ",到账总金额:" + orders.getSumArtificerMoney()); userMoneyDetails.setType(1); userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date())); userMoneyDetails.setBlRole(2); userMoneyDetails.setBlFlag(1); userMoneyDetailsService.save(userMoneyDetails); - if (oneUser != null && oneUser.getIsAgency() != null && oneUser.getIsAgency() == 1 && orders.getOneUserMoney().compareTo(BigDecimal.ZERO) !=0) { - userMoneyService.updateMoney(1, oneUser.getUserId(), orders.getOneUserMoney().doubleValue()); - userMoneyDetails = new UserMoneyDetails(); - //查询用户当前余额 - UserMoney userNowMoney3 = userMoneyService.selectUserMoneyByUserId(oneUser.getUserId()); - //插入余额 - userMoneyDetails.setBalance(userNowMoney3.getMoney()); - //插入操作类型为已操作用户余额 - userMoneyDetails.setManipulateType(2); - userMoneyDetails.setMoney(orders.getOneUserMoney()); - userMoneyDetails.setUserId(oneUser.getUserId()); - userMoneyDetails.setContent("订单号:" + orders.getOrdersNo() + ",订单取消!"); - userMoneyDetails.setTitle("推广用户收益"); - userMoneyDetails.setType(1); - userMoneyDetails.setClassify(5); - userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date())); - userMoneyDetails.setBlRole(1); - userMoneyDetails.setBlFlag(1); - userMoneyDetailsService.save(userMoneyDetails); - - orders.setOneUserId(oneUser.getUserId()); - orders.setOneUserName(oneUser.getUserName()); - } - - - if (oneArtificerUser != null && oneArtificerUser.getIsAgency() != null && oneArtificerUser.getIsAgency() == 1 && orders.getOneArtificerMoney().compareTo(BigDecimal.ZERO)!=0) { - userMoneyService.updateMoney(1, oneArtificerUser.getUserId(), orders.getOneArtificerMoney().doubleValue()); - userMoneyDetails = new UserMoneyDetails(); - //查询用户当前余额 - UserMoney userNowMoney4 = userMoneyService.selectUserMoneyByUserId(oneArtificerUser.getUserId()); - //插入余额 - userMoneyDetails.setBalance(userNowMoney4.getMoney()); - //插入操作类型为已操作用户余额 - userMoneyDetails.setManipulateType(2); - userMoneyDetails.setMoney(orders.getOneArtificerMoney()); - userMoneyDetails.setUserId(oneArtificerUser.getUserId()); - userMoneyDetails.setContent("订单号:" + orders.getOrdersNo() + ",订单取消!"); - userMoneyDetails.setTitle("推广师傅收益"); - userMoneyDetails.setType(1); - userMoneyDetails.setClassify(6); - userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date())); - userMoneyDetails.setBlRole(2); - userMoneyDetails.setBlFlag(1); - userMoneyDetailsService.save(userMoneyDetails); - - orders.setOneArtificerUserId(oneArtificerUser.getUserId()); - orders.setOneArtificerUserName(oneArtificerUser.getUserName()); - } - - if (orders.getShopUserId() != null && orders.getShopMoney().compareTo(BigDecimal.ZERO)!=0) { - userMoneyService.updateMoney(1, orders.getShopUserId(), orders.getShopMoney().doubleValue()); - userMoneyDetails = new UserMoneyDetails(); - //查询用户当前余额 - UserMoney userNowMoney5 = userMoneyService.selectUserMoneyByUserId(orders.getShopUserId()); - //插入余额 - userMoneyDetails.setBalance(userNowMoney5.getMoney()); - //插入操作类型为已操作用户余额 - userMoneyDetails.setManipulateType(2); - userMoneyDetails.setMoney(orders.getShopMoney()); - userMoneyDetails.setUserId(orders.getShopUserId()); - userMoneyDetails.setContent("订单号:" + orders.getOrdersNo() + ",订单取消!"); - userMoneyDetails.setTitle("商家收益"); - userMoneyDetails.setType(1); - userMoneyDetails.setClassify(7); - userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date())); - userMoneyDetails.setBlRole(3); - userMoneyDetails.setBlFlag(1); - userMoneyDetailsService.save(userMoneyDetails); - } - List ordersList = baseMapper.selectList(new QueryWrapper().isNotNull("pay_way").eq("parent_id", orders.getOrdersId())); for (Orders orders1 : ordersList) { @@ -1670,11 +1549,7 @@ public class OrdersServiceImpl extends ServiceImpl implements userMoneyDetails.setManipulateType(1); userMoneyDetails.setBlFlag(2); } else { -// if (orders1.getUserArtificerMoney() != null && orders1.getUserArtificerMoney() == 1) { -// userMoneyArtificerService.updateMoney(1, orders1.getUserId(), orders1.getArtificerId(), orders1.getPayMoney().doubleValue()); -// } else { userMoneyService.updateMoney(1, orders1.getUserId(), orders1.getPayMoney().doubleValue()); -// } //查询用户当前余额 UserMoney userNowMoney6 = userMoneyService.selectUserMoneyByUserId(orders1.getUserId()); //插入余额 @@ -1760,6 +1635,719 @@ public class OrdersServiceImpl extends ServiceImpl implements return Result.success(); } + /*** + * 待补单处理及待补单全单退款 + * @param userId + * @param isAuto 是否自动退款 1是 系统自动变成待补单,0否 用户点击操作变成待补单 + * @param type 是否全额退款,1车费 2项目费 3全部 + * @return + */ + @Override + public Result cancelSupplementOrders(Long userId, Long ordersId, Integer isAuto, Integer type) { + Orders orders = baseMapper.selectById(ordersId); + //状态 1待支付 2待服务 3待评论 4已取消 5已完成 6进行中 7技师出发 8技师到达 9用户已支付技师待接单 10待补单 + if (orders.getStatus() == 8 || orders.getStatus() == 9) { + if(orders.getUserPackageDetailId() !=null){ + return cancelSupplementPackageOrders(userId,orders,isAuto,type); + }else{ + return cancelSupplementMassageOrders(userId,orders,isAuto,type); + } + }else{ + return Result.error("不满足待补单条件!"); + } + } + + private Result cancelSupplementMassageOrders(Long userId, Orders orders, Integer isAuto, Integer type) { + if(type == 1){ + //退车费或扣车费,成为待补单 + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String time = simpleDateFormat.format(new Date()); + //退款金额 + BigDecimal userMoney = BigDecimal.ZERO; + UserMoneyDetails userMoneyDetails = new UserMoneyDetails(); + if(isAuto == 0){ + //退款车费 + userMoney = orders.getTaxiMoney(); + if (orders.getPayWay() == 1 || orders.getPayWay() == 2 || orders.getPayWay() == 3 || orders.getPayWay() == 4) { + boolean refund = wxService.refund(orders.getOrdersNo(), orders.getPayMoney(), userMoney, orders.getPayWay()); + if (!refund) { + return Result.error("退款失败,请联系客服!"); + } + userMoneyDetails.setManipulateType(1); + userMoneyDetails.setBlFlag(2); + } else if (orders.getPayWay() == 6) { + String data = aliPayController.alipayRefund(orders.getOrdersNo(), userMoney); + if (StringUtils.isNotBlank(data)) { + log.error(data); + JSONObject jsonObject = JSON.parseObject(data); + JSONObject alipay_trade_refund_response = jsonObject.getJSONObject("alipay_trade_refund_response"); + String code1 = alipay_trade_refund_response.getString("code"); + if (!"10000".equals(code1)) { + return Result.error("退款失败!" + alipay_trade_refund_response.getString("sub_msg")); + } + } else { + return Result.error("退款失败!"); + } + userMoneyDetails.setManipulateType(1); + userMoneyDetails.setBlFlag(2); + } else { + userMoneyService.updateMoney(1, orders.getUserId(), userMoney.doubleValue()); + //查询用户当前余额 + UserMoney userNowMoney = userMoneyService.selectUserMoneyByUserId(orders.getUserId()); + //插入余额 + userMoneyDetails.setBalance(userNowMoney.getMoney()); + //插入操作类型为已操作用户余额 + userMoneyDetails.setManipulateType(2); + userMoneyDetails.setBlFlag(1); + } + userMoneyDetails.setMoney(userMoney); + userMoneyDetails.setUserId(orders.getUserId()); + userMoneyDetails.setContent("订单号:" + orders.getOrdersNo() + ",车费已原路退款!"); + userMoneyDetails.setTitle("订单退款"); + userMoneyDetails.setType(1); + userMoneyDetails.setCreateTime(time); + userMoneyDetails.setArtificerId(orders.getArtificerId()); + userMoneyDetails.setBlRole(1); + userMoneyDetailsService.save(userMoneyDetails); + + Artificer artificer2 = artificerService.getById(orders.getArtificerId()); + if (userId != null && artificer2.getUserId().equals(userId)) { + BigDecimal newCreditScore = BigDecimal.ZERO; + MessageInfo messageInfo = new MessageInfo(); + messageInfo.setState("8"); + messageInfo.setUserId(String.valueOf(artificer2.getUserId())); + messageInfo.setTitle("转待补单订单:" + orders.getOrdersNo()); + String value1 = commonInfoService.findOne(384).getValue(); + BigDecimal creditScore = new BigDecimal(value1); + newCreditScore = artificer2.getCreditScore().subtract(creditScore); + messageInfo.setContent("扣除信誉分:" + creditScore); + artificer2.setCreditScore(newCreditScore); + String value2 = commonInfoService.findOne(385).getValue(); + BigDecimal minScore = new BigDecimal(value2); + if (artificer2.getCreditScore().doubleValue() < minScore.doubleValue()) { + artificer2.setStatus(2); + } + artificerService.updateById(artificer2); + messageService.saveBody(messageInfo); + } + + UserEntity userEntity = userService.selectUserById(orders.getUserId()); + //超过十个字 则截取 + String content = "订单:"+orders.getOrdersNo()+",转为待补单"; + //消息推送 + if (StringUtils.isNotEmpty(userEntity.getOpenId())) { + CommonInfo one = commonInfoService.findOne(248); + List msgList = new ArrayList<>(); + msgList.add(orders.getOrdersNo()); + msgList.add(content); + msgList.add("车费已原路退还!"); + SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), one.getValue(), msgList, 2); + } + + if (StringUtils.isNotEmpty(userEntity.getClientid())) { + userService.pushToSingle("订单通知", "订单已转为,车费已原路退还!", userEntity.getClientid()); + } + + if (StringUtils.isNotBlank(userEntity.getWxOpenId())) { + String apkey = commonInfoService.findOne(313).getValue(); + LinkedHashMap data = new LinkedHashMap<>(); + data.put("character_string12", new TemplateMessageItem(orders.getOrdersNo(), "#d71345")); + data.put("thing17", new TemplateMessageItem(content, "#d71345")); + data.put("time14", new TemplateMessageItem(DateUtils.format(new Date()), "#d71345")); + userService.sendWxMessage(apkey, data, userEntity.getWxOpenId()); + } + } + if(isAuto == 1){ + //按照比例 将扣除的车费钱 + BigDecimal taxiMoney = orders.getTaxiMoney(); + BigDecimal sumMoney = orders.getTaxiMoney();//总扣费 + Artificer artificer = artificerService.getById(orders.getArtificerId()); + BigDecimal artificerTaxiMoney = orders.getTaxiMoney();//扣车费 + BigDecimal pingTaxiMoney = BigDecimal.ZERO; + + String taxi = commonInfoService.findOne(394).getValue(); + if ("是".equals(taxi)) { + artificerTaxiMoney = taxiMoney.multiply(artificer.getRate()); + pingTaxiMoney = taxiMoney.subtract(artificerTaxiMoney); + } + UserEntity artificerUser = userService.selectUserById(artificer.getUserId()); + + orders.setShopMoney(BigDecimal.ZERO); + orders.setArtificerMoney(BigDecimal.ZERO); + orders.setSumArtificerMoney(sumMoney.setScale(2, BigDecimal.ROUND_DOWN)); + orders.setOneUserMoney(BigDecimal.ZERO); + orders.setOneArtificerMoney(BigDecimal.ZERO); + orders.setPingMoney(BigDecimal.ZERO); + orders.setArtificerTaxiMoney(artificerTaxiMoney.setScale(2, BigDecimal.ROUND_DOWN)); + orders.setPingTaxiMoney(pingTaxiMoney.setScale(2, BigDecimal.ROUND_DOWN)); + + userMoneyService.updateMoney(1, artificerUser.getUserId(), orders.getSumArtificerMoney().doubleValue()); + userMoneyDetails = new UserMoneyDetails(); + //查询用户当前余额 + UserMoney userNowMoney1 = userMoneyService.selectUserMoneyByUserId(artificerUser.getUserId()); + //插入余额 + userMoneyDetails.setBalance(userNowMoney1.getMoney()); + //插入操作类型为已操作用户余额 + userMoneyDetails.setManipulateType(2); + userMoneyDetails.setMoney(orders.getSumArtificerMoney()); + userMoneyDetails.setUserId(artificerUser.getUserId()); + userMoneyDetails.setTitle("订单号:" + orders.getOrdersNo() + ",订单超时转为待补单!"); + userMoneyDetails.setContent("用户订单超时转为待补单,总扣除:" + sumMoney + ",到账总金额:" + orders.getSumArtificerMoney()); + userMoneyDetails.setType(1); + userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date())); + userMoneyDetails.setBlRole(2); + userMoneyDetails.setBlFlag(1); + userMoneyDetailsService.save(userMoneyDetails); + } + orders.setRefusalContent(""); + orders.setStatus(10); + baseMapper.updateById(orders); + } + if(type == 2){ + //退项目费 + String couponIds = orders.getCouponId(); + if(orders.getCouponId() != null && couponIds.length()>0){ + String[] couponArr = couponIds.trim().split(","); + for(int i=0;i ordersMassageList = ordersMassageService.list(new QueryWrapper().eq("orders_id", orders.getOrdersId())); + MassageType massageType = massageTypeService.getById(ordersMassageList.get(0).getMassageId()); + //超过十个字 则截取 + String content = massageType.getTitle(); + if (content.length() >= 15) { + content = content.substring(0, 15) + "..."; + } + + //消息推送 + if (StringUtils.isNotEmpty(userEntity.getOpenId())) { + CommonInfo one = commonInfoService.findOne(248); + List msgList = new ArrayList<>(); + msgList.add(orders.getOrdersNo()); + msgList.add(content); + msgList.add("订单已取消,订单费已原路退还!"); + SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), one.getValue(), msgList, 2); + } + + if (StringUtils.isNotEmpty(userEntity.getClientid())) { + userService.pushToSingle("订单通知", "订单已取消,订单费已原路退还!", userEntity.getClientid()); + } + + if (StringUtils.isNotBlank(userEntity.getWxOpenId())) { + String apkey = commonInfoService.findOne(313).getValue(); + LinkedHashMap data = new LinkedHashMap<>(); + data.put("character_string12", new TemplateMessageItem(orders.getOrdersNo(), "#d71345")); + data.put("thing17", new TemplateMessageItem(content, "#d71345")); + data.put("time14", new TemplateMessageItem(DateUtils.format(new Date()), "#d71345")); + userService.sendWxMessage(apkey, data, userEntity.getWxOpenId()); + } + + } + if(type == 3){ + //全退 + String couponIds = orders.getCouponId(); + if(orders.getCouponId() != null && couponIds.length()>0){ + String[] couponArr = couponIds.trim().split(","); + for(int i=0;i ordersMassageList = ordersMassageService.list(new QueryWrapper().eq("orders_id", orders.getOrdersId())); + MassageType massageType = massageTypeService.getById(ordersMassageList.get(0).getMassageId()); + //超过十个字 则截取 + String content = massageType.getTitle(); + if (content.length() >= 15) { + content = content.substring(0, 15) + "..."; + } + + //消息推送 + if (StringUtils.isNotEmpty(userEntity.getOpenId())) { + CommonInfo one = commonInfoService.findOne(248); + List msgList = new ArrayList<>(); + msgList.add(orders.getOrdersNo()); + + msgList.add(content); + msgList.add("订单已取消,金额已原路退还!"); + SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), one.getValue(), msgList, 2); + } + + if (StringUtils.isNotEmpty(userEntity.getClientid())) { + userService.pushToSingle("订单通知", "订单已取消,金额已原路退还!", userEntity.getClientid()); + } + + if (StringUtils.isNotBlank(userEntity.getWxOpenId())) { + String apkey = commonInfoService.findOne(313).getValue(); + LinkedHashMap data = new LinkedHashMap<>(); + data.put("character_string12", new TemplateMessageItem(orders.getOrdersNo(), "#d71345")); + data.put("thing17", new TemplateMessageItem(content, "#d71345")); + data.put("time14", new TemplateMessageItem(DateUtils.format(new Date()), "#d71345")); + userService.sendWxMessage(apkey, data, userEntity.getWxOpenId()); + } + + if(orders.getOldOrdersId()!=null){ + cancelSupplementOrders(userId, orders.getOldOrdersId(), 0, 2);//退原单,原单的车费已被退/扣,所以只退项目 + } + } + return Result.success(); + } + + private Result cancelSupplementPackageOrders(Long userId, Orders orders, Integer isAuto, Integer type) { + if(type == 1){ + //退车费或扣车费,成为待补单 + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String time = simpleDateFormat.format(new Date()); + //退款金额 + BigDecimal userMoney = BigDecimal.ZERO; + UserMoneyDetails userMoneyDetails = new UserMoneyDetails(); + if(isAuto == 0){ + //退款车费 + userMoney = orders.getTaxiMoney(); + if (orders.getPayWay() == 1 || orders.getPayWay() == 2 || orders.getPayWay() == 3 || orders.getPayWay() == 4) { + boolean refund = wxService.refund(orders.getOrdersNo(), orders.getPayMoney(), userMoney, orders.getPayWay()); + if (!refund) { + return Result.error("退款失败,请联系客服!"); + } + userMoneyDetails.setManipulateType(1); + userMoneyDetails.setBlFlag(2); + } else if (orders.getPayWay() == 6) { + String data = aliPayController.alipayRefund(orders.getOrdersNo(), userMoney); + if (StringUtils.isNotBlank(data)) { + log.error(data); + JSONObject jsonObject = JSON.parseObject(data); + JSONObject alipay_trade_refund_response = jsonObject.getJSONObject("alipay_trade_refund_response"); + String code1 = alipay_trade_refund_response.getString("code"); + if (!"10000".equals(code1)) { + return Result.error("退款失败!" + alipay_trade_refund_response.getString("sub_msg")); + } + } else { + return Result.error("退款失败!"); + } + userMoneyDetails.setManipulateType(1); + userMoneyDetails.setBlFlag(2); + } else { + userMoneyService.updateMoney(1, orders.getUserId(), userMoney.doubleValue()); + //查询用户当前余额 + UserMoney userNowMoney = userMoneyService.selectUserMoneyByUserId(orders.getUserId()); + //插入余额 + userMoneyDetails.setBalance(userNowMoney.getMoney()); + //插入操作类型为已操作用户余额 + userMoneyDetails.setManipulateType(2); + userMoneyDetails.setBlFlag(1); + } + userMoneyDetails.setMoney(userMoney); + userMoneyDetails.setUserId(orders.getUserId()); + userMoneyDetails.setContent("订单号:" + orders.getOrdersNo() + ",车费已原路退款!"); + userMoneyDetails.setTitle("订单退款"); + userMoneyDetails.setType(1); + userMoneyDetails.setCreateTime(time); + userMoneyDetails.setArtificerId(orders.getArtificerId()); + userMoneyDetails.setBlRole(1); + userMoneyDetailsService.save(userMoneyDetails); + + Artificer artificer2 = artificerService.getById(orders.getArtificerId()); + if (userId != null && artificer2.getUserId().equals(userId)) { + BigDecimal newCreditScore = BigDecimal.ZERO; + MessageInfo messageInfo = new MessageInfo(); + messageInfo.setState("8"); + messageInfo.setUserId(String.valueOf(artificer2.getUserId())); + messageInfo.setTitle("转待补单订单:" + orders.getOrdersNo()); + String value1 = commonInfoService.findOne(384).getValue(); + BigDecimal creditScore = new BigDecimal(value1); + newCreditScore = artificer2.getCreditScore().subtract(creditScore); + messageInfo.setContent("扣除信誉分:" + creditScore); + artificer2.setCreditScore(newCreditScore); + String value2 = commonInfoService.findOne(385).getValue(); + BigDecimal minScore = new BigDecimal(value2); + if (artificer2.getCreditScore().doubleValue() < minScore.doubleValue()) { + artificer2.setStatus(2); + } + artificerService.updateById(artificer2); + messageService.saveBody(messageInfo); + } + + UserEntity userEntity = userService.selectUserById(orders.getUserId()); + //超过十个字 则截取 + String content = "订单:"+orders.getOrdersNo()+",转为待补单"; + //消息推送 + if (StringUtils.isNotEmpty(userEntity.getOpenId())) { + CommonInfo one = commonInfoService.findOne(248); + List msgList = new ArrayList<>(); + msgList.add(orders.getOrdersNo()); + msgList.add(content); + msgList.add("车费已原路退还!"); + SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), one.getValue(), msgList, 2); + } + + if (StringUtils.isNotEmpty(userEntity.getClientid())) { + userService.pushToSingle("订单通知", "订单已转为,车费已原路退还!", userEntity.getClientid()); + } + + if (StringUtils.isNotBlank(userEntity.getWxOpenId())) { + String apkey = commonInfoService.findOne(313).getValue(); + LinkedHashMap data = new LinkedHashMap<>(); + data.put("character_string12", new TemplateMessageItem(orders.getOrdersNo(), "#d71345")); + data.put("thing17", new TemplateMessageItem(content, "#d71345")); + data.put("time14", new TemplateMessageItem(DateUtils.format(new Date()), "#d71345")); + userService.sendWxMessage(apkey, data, userEntity.getWxOpenId()); + } + } + if(isAuto == 1){ + //按照比例 将扣除的车费钱 + BigDecimal taxiMoney = orders.getTaxiMoney(); + BigDecimal sumMoney = orders.getTaxiMoney();//总扣费 + Artificer artificer = artificerService.getById(orders.getArtificerId()); + BigDecimal artificerTaxiMoney = orders.getTaxiMoney();//扣车费 + BigDecimal pingTaxiMoney = BigDecimal.ZERO; + + String taxi = commonInfoService.findOne(394).getValue(); + if ("是".equals(taxi)) { + artificerTaxiMoney = taxiMoney.multiply(artificer.getRate()); + pingTaxiMoney = taxiMoney.subtract(artificerTaxiMoney); + } + UserEntity artificerUser = userService.selectUserById(artificer.getUserId()); + + orders.setShopMoney(BigDecimal.ZERO); + orders.setArtificerMoney(BigDecimal.ZERO); + orders.setSumArtificerMoney(sumMoney.setScale(2, BigDecimal.ROUND_DOWN)); + orders.setOneUserMoney(BigDecimal.ZERO); + orders.setOneArtificerMoney(BigDecimal.ZERO); + orders.setPingMoney(BigDecimal.ZERO); + orders.setArtificerTaxiMoney(artificerTaxiMoney.setScale(2, BigDecimal.ROUND_DOWN)); + orders.setPingTaxiMoney(pingTaxiMoney.setScale(2, BigDecimal.ROUND_DOWN)); + + userMoneyService.updateMoney(1, artificerUser.getUserId(), orders.getSumArtificerMoney().doubleValue()); + userMoneyDetails = new UserMoneyDetails(); + //查询用户当前余额 + UserMoney userNowMoney1 = userMoneyService.selectUserMoneyByUserId(artificerUser.getUserId()); + //插入余额 + userMoneyDetails.setBalance(userNowMoney1.getMoney()); + //插入操作类型为已操作用户余额 + userMoneyDetails.setManipulateType(2); + userMoneyDetails.setMoney(orders.getSumArtificerMoney()); + userMoneyDetails.setUserId(artificerUser.getUserId()); + userMoneyDetails.setTitle("订单号:" + orders.getOrdersNo() + ",订单超时转为待补单!"); + userMoneyDetails.setContent("用户订单超时转为待补单,总扣除:" + sumMoney + ",到账总金额:" + orders.getSumArtificerMoney()); + userMoneyDetails.setType(1); + userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date())); + userMoneyDetails.setBlRole(2); + userMoneyDetails.setBlFlag(1); + userMoneyDetailsService.save(userMoneyDetails); + } + orders.setRefusalContent(""); + orders.setStatus(10); + baseMapper.updateById(orders); + } + if(type == 2){ + //退项目费 + //释放 + UserPackageDetail userPackageDetail = new UserPackageDetail(); + userPackageDetail.setId(orders.getUserPackageDetailId()); + userPackageDetail.setStatus(0); + userPackageDetailService.updateById(userPackageDetail); + + orders.setStatus(4); + baseMapper.updateById(orders); + + UserEntity userEntity = userService.selectUserById(orders.getUserId()); + + List ordersMassageList = ordersMassageService.list(new QueryWrapper().eq("orders_id", orders.getOrdersId())); + MassageType massageType = massageTypeService.getById(ordersMassageList.get(0).getMassageId()); + //超过十个字 则截取 + String content = massageType.getTitle(); + if (content.length() >= 15) { + content = content.substring(0, 15) + "..."; + } + + //消息推送 + if (StringUtils.isNotEmpty(userEntity.getOpenId())) { + CommonInfo one = commonInfoService.findOne(248); + List msgList = new ArrayList<>(); + msgList.add(orders.getOrdersNo()); + msgList.add(content); + msgList.add("订单已取消,订单费已原路退还!"); + SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), one.getValue(), msgList, 2); + } + + if (StringUtils.isNotEmpty(userEntity.getClientid())) { + userService.pushToSingle("订单通知", "订单已取消,订单费已原路退还!", userEntity.getClientid()); + } + + if (StringUtils.isNotBlank(userEntity.getWxOpenId())) { + String apkey = commonInfoService.findOne(313).getValue(); + LinkedHashMap data = new LinkedHashMap<>(); + data.put("character_string12", new TemplateMessageItem(orders.getOrdersNo(), "#d71345")); + data.put("thing17", new TemplateMessageItem(content, "#d71345")); + data.put("time14", new TemplateMessageItem(DateUtils.format(new Date()), "#d71345")); + userService.sendWxMessage(apkey, data, userEntity.getWxOpenId()); + } + + }else if(type == 3){ + //全退 + //释放 + UserPackageDetail userPackageDetail = new UserPackageDetail(); + userPackageDetail.setId(orders.getUserPackageDetailId()); + userPackageDetail.setStatus(0); + userPackageDetailService.updateById(userPackageDetail); + + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String time = simpleDateFormat.format(new Date()); + //退款金额 + BigDecimal userMoney = orders.getTaxiMoney(); + + UserMoneyDetails userMoneyDetails = new UserMoneyDetails(); + + if (orders.getPayWay() == 1 || orders.getPayWay() == 2 || orders.getPayWay() == 3 || orders.getPayWay() == 4) { + boolean refund = wxService.refund(orders.getOrdersNo(), orders.getTaxiMoney(), userMoney, orders.getPayWay()); + if (!refund) { + return Result.error("退款失败,请联系客服!"); + } + userMoneyDetails.setManipulateType(1); + userMoneyDetails.setBlFlag(2); + } else if (orders.getPayWay() == 6) { + String data = aliPayController.alipayRefund(orders.getOrdersNo(), userMoney); + if (StringUtils.isNotBlank(data)) { + log.error(data); + JSONObject jsonObject = JSON.parseObject(data); + JSONObject alipay_trade_refund_response = jsonObject.getJSONObject("alipay_trade_refund_response"); + String code1 = alipay_trade_refund_response.getString("code"); + if (!"10000".equals(code1)) { + return Result.error("退款失败!" + alipay_trade_refund_response.getString("sub_msg")); + } + } else { + return Result.error("退款失败!"); + } + userMoneyDetails.setManipulateType(1); + userMoneyDetails.setBlFlag(2); + } else { + userMoneyService.updateMoney(1, orders.getUserId(), userMoney.doubleValue()); + //查询用户当前余额 + UserMoney userNowMoney = userMoneyService.selectUserMoneyByUserId(orders.getUserId()); + //插入余额 + userMoneyDetails.setBalance(userNowMoney.getMoney()); + //插入操作类型为已操作用户余额 + userMoneyDetails.setManipulateType(2); + userMoneyDetails.setBlFlag(1); + } + userMoneyDetails.setMoney(userMoney); + userMoneyDetails.setUserId(orders.getUserId()); + userMoneyDetails.setContent("订单号:" + orders.getOrdersNo() + ",已原路退款!"); + userMoneyDetails.setTitle("订单退款"); + userMoneyDetails.setType(1); + userMoneyDetails.setCreateTime(time); + userMoneyDetails.setArtificerId(orders.getArtificerId()); + userMoneyDetails.setBlRole(1); + userMoneyDetailsService.save(userMoneyDetails); + orders.setStatus(4); + baseMapper.updateById(orders); + + Artificer artificer2 = artificerService.getById(orders.getArtificerId()); + if (userId != null && artificer2.getUserId().equals(userId)) { + BigDecimal newCreditScore = BigDecimal.ZERO; + MessageInfo messageInfo = new MessageInfo(); + messageInfo.setState("8"); + messageInfo.setUserId(String.valueOf(artificer2.getUserId())); + messageInfo.setTitle("取消订单:" + orders.getOrdersNo()); + String value1 = commonInfoService.findOne(384).getValue(); + BigDecimal creditScore = new BigDecimal(value1); + newCreditScore = artificer2.getCreditScore().subtract(creditScore); + messageInfo.setContent("扣除信誉分:" + creditScore); + artificer2.setCreditScore(newCreditScore); + String value2 = commonInfoService.findOne(385).getValue(); + BigDecimal minScore = new BigDecimal(value2); + if (artificer2.getCreditScore().doubleValue() < minScore.doubleValue()) { + artificer2.setStatus(2); + } + artificerService.updateById(artificer2); + messageService.saveBody(messageInfo); + } + + UserEntity userEntity = userService.selectUserById(orders.getUserId()); + + List ordersMassageList = ordersMassageService.list(new QueryWrapper().eq("orders_id", orders.getOrdersId())); + MassageType massageType = massageTypeService.getById(ordersMassageList.get(0).getMassageId()); + //超过十个字 则截取 + String content = massageType.getTitle(); + if (content.length() >= 15) { + content = content.substring(0, 15) + "..."; + } + + //消息推送 + if (StringUtils.isNotEmpty(userEntity.getOpenId())) { + CommonInfo one = commonInfoService.findOne(248); + List msgList = new ArrayList<>(); + msgList.add(orders.getOrdersNo()); + + msgList.add(content); + msgList.add("订单已取消,金额已原路退还!"); + SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), one.getValue(), msgList, 2); + } + + if (StringUtils.isNotEmpty(userEntity.getClientid())) { + userService.pushToSingle("订单通知", "订单已取消,金额已原路退还!", userEntity.getClientid()); + } + + if (StringUtils.isNotBlank(userEntity.getWxOpenId())) { + String apkey = commonInfoService.findOne(313).getValue(); + LinkedHashMap data = new LinkedHashMap<>(); + data.put("character_string12", new TemplateMessageItem(orders.getOrdersNo(), "#d71345")); + data.put("thing17", new TemplateMessageItem(content, "#d71345")); + data.put("time14", new TemplateMessageItem(DateUtils.format(new Date()), "#d71345")); + userService.sendWxMessage(apkey, data, userEntity.getWxOpenId()); + } + + if(orders.getOldOrdersId()!=null){ + cancelSupplementOrders(userId, orders.getOldOrdersId(), 0, 2);//退原单,原单的车费已被退/扣,所以只退项目 + } + } + return Result.success(); + } + @Override public Result refundOrdersMoney(Long ordersId, BigDecimal refundMoney) { Orders orders = baseMapper.selectById(ordersId);