|  |  |  | 
|---|
|  |  |  | import com.doumee.dao.business.model.MemberRides; | 
|---|
|  |  |  | import com.doumee.dao.business.vo.GoodsorderExportVO; | 
|---|
|  |  |  | import com.doumee.dao.business.vo.GoodsorderTotalDataVO; | 
|---|
|  |  |  | import com.doumee.dao.business.web.request.BikeRepairDTO; | 
|---|
|  |  |  | import com.doumee.dao.business.web.request.GoodsorderCanBanlanceDTO; | 
|---|
|  |  |  | import com.doumee.dao.business.web.request.MemberRidesQuery; | 
|---|
|  |  |  | import com.doumee.dao.business.web.request.RefundDTO; | 
|---|
|  |  |  | 
|---|
|  |  |  | IPage<Goodsorder> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|---|
|  |  |  | pageWrap.getModel().setPayStatus(Constants.ONE); //只查询支付成功的 | 
|---|
|  |  |  | MPJLambdaWrapper<Goodsorder> queryWrapper = initQueryParamByModel(pageWrap.getModel()); | 
|---|
|  |  |  | return PageData.from(goodsorderJoinMapper.selectJoinPage(page, GoodsorderExportVO.class,queryWrapper)); | 
|---|
|  |  |  | IPage<GoodsorderExportVO> goodsorderExportVOIPage = goodsorderJoinMapper.selectJoinPage(page, GoodsorderExportVO.class, queryWrapper); | 
|---|
|  |  |  | if (!CollectionUtils.isEmpty(goodsorderExportVOIPage.getRecords())){ | 
|---|
|  |  |  | goodsorderExportVOIPage.getRecords().forEach(s->{ | 
|---|
|  |  |  | s.setMoney(Constants.translateMoney(s.getMoney())); | 
|---|
|  |  |  | s.setRefundMoney(Constants.translateMoney(s.getRefundMoney())); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return PageData.from(goodsorderExportVOIPage); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public   List<GoodsorderExportVO> findExportAccountDetailPage(Goodsorder model){ | 
|---|
|  |  |  | model.setPayStatus(Constants.ONE); //只查询支付成功的 | 
|---|
|  |  |  | MPJLambdaWrapper<Goodsorder> queryWrapper = initQueryParamByModel(model); | 
|---|
|  |  |  | List<GoodsorderExportVO> goodsorderList = goodsorderJoinMapper.selectJoinList(GoodsorderExportVO.class,queryWrapper); | 
|---|
|  |  |  | if (!CollectionUtils.isEmpty(goodsorderList)){ | 
|---|
|  |  |  | goodsorderList.forEach(s->{ | 
|---|
|  |  |  | s.setMoney(Constants.translateMoney(s.getMoney())); | 
|---|
|  |  |  | s.setCloseMoney(Constants.translateMoney(s.getCloseMoney())); | 
|---|
|  |  |  | s.setRefundMoney(Constants.translateMoney(s.getRefundMoney())); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /*   List<GoodsorderExportVO> list = new ArrayList<>(); | 
|---|
|  |  |  | if(goodsorderList!=null){ | 
|---|
|  |  |  | for(Goodsorder order : goodsorderList){ | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Objects.nonNull(model.getEndDate())){ | 
|---|
|  |  |  | queryWrapper.le( Goodsorder::getPayDate, Utils.Date.getEnd(model.getEndDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | queryWrapper.eq(model.getPayStatus() !=null,Goodsorder::getPayStatus,model.getPayStatus()); | 
|---|
|  |  |  | queryWrapper.like(model.getCode() !=null,Goodsorder::getCode,model.getCode()); | 
|---|
|  |  |  | queryWrapper.like(model.getId() !=null,Goodsorder::getId,model.getId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | IPage<Goodsorder> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|---|
|  |  |  | MPJLambdaWrapper<Goodsorder> queryWrapper = initQueryParamByModel(pageWrap.getModel()); | 
|---|
|  |  |  | queryWrapper.select("(select  er.status from member_rides  er  where er.ordre_id=t.id order by er.create_date limit 1) as memberRidesStatus"); | 
|---|
|  |  |  | if(Objects.nonNull(pageWrap.getModel().getCloseStatus()) && pageWrap.getModel().getCloseStatus().equals(Constants.ZERO)){ | 
|---|
|  |  |  | queryWrapper.ne(Goodsorder::getStatus,Constants.GOODSORDER_STATUS.CLOSE.getKey()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Objects.nonNull(pageWrap.getModel().getCloseStatus()) && pageWrap.getModel().getCloseStatus().equals(Constants.ONE)){ | 
|---|
|  |  |  | queryWrapper.eq(Goodsorder::getStatus,Constants.GOODSORDER_STATUS.CLOSE.getKey()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | IPage<Goodsorder> goodsorderIPage = goodsorderJoinMapper.selectJoinPage(page, Goodsorder.class, queryWrapper); | 
|---|
|  |  |  | if (!CollectionUtils.isEmpty(goodsorderIPage.getRecords())){ | 
|---|
|  |  |  | goodsorderIPage.getRecords().forEach(s->{ | 
|---|
|  |  |  | 
|---|
|  |  |  | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void closeGoodsorder( Goodsorder goodsorder ,int type ) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // | 
|---|
|  |  |  | List<MemberRides> memberRides = getMemberRidesForClose(goodsorder.getId()); | 
|---|
|  |  |  | //默认结算为押金金额 | 
|---|
|  |  |  | BigDecimal closeMoney = new BigDecimal(0.00); | 
|---|
|  |  |  | 
|---|
|  |  |  | if(Constants.REFUND_TYPE.PLAT_FORCE.getKey() == type){ | 
|---|
|  |  |  | //如果是强制结算 | 
|---|
|  |  |  | update.setCloseType(Constants.ONE); | 
|---|
|  |  |  | LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  | update.setEditor(principal.getId()); | 
|---|
|  |  |  | }else  if(Constants.REFUND_TYPE.NORMAL.getKey() == type){ | 
|---|
|  |  |  | //如果是自行結算 | 
|---|
|  |  |  | update.setCloseType(Constants.ZERO); | 
|---|
|  |  |  | 
|---|
|  |  |  | refundDTO.setTotalAmount(goodsorder.getMoney()); | 
|---|
|  |  |  | refundDTO.setMemberId(goodsorder.getMemberId()); | 
|---|
|  |  |  | refundDTO.setReason(Constants.REFUND_TYPE.get(type).getName()); | 
|---|
|  |  |  | refundDTO.setCreator(update.getEditor()); | 
|---|
|  |  |  | refundDTO.setType(type); | 
|---|
|  |  |  | Refund refund = wxMiniUtilService.wxRefund(refundDTO); | 
|---|
|  |  |  | update.setCloseId(refund.getId()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MPJLambdaWrapper<MemberRides> wrapper = new MPJLambdaWrapper<>(); | 
|---|
|  |  |  | wrapper.eq(MemberRides::getOrdreId,id); | 
|---|
|  |  |  | wrapper.ne(MemberRides::getStatus,Constants.MEMBER_RIDES_STATUS.LOCKING_DEFEAT.getKey()); | 
|---|
|  |  |  | wrapper.selectAll(MemberRides.class).selectAs(BaseParam::getName, MemberRides::getParamName); | 
|---|
|  |  |  | wrapper.leftJoin(BaseParam.class, BaseParam::getId, MemberRides::getParamId); | 
|---|
|  |  |  | wrapper.orderByDesc(BaseParam::getSortnum);//取最高车型作为计价方案 | 
|---|
|  |  |  | wrapper.orderByDesc(BaseParam::getSortnum); | 
|---|
|  |  |  | //取最高车型作为计价方案 | 
|---|
|  |  |  | //查询所有骑行记录 | 
|---|
|  |  |  | List<MemberRides> memberRides = memberRidesJoinMapper.selectList(wrapper); | 
|---|
|  |  |  | return memberRides; | 
|---|
|  |  |  | 
|---|
|  |  |  | wrapper.select("sum(money) as money").last(" limit 1"); | 
|---|
|  |  |  | Refund total = refundMapper.selectOne(wrapper); | 
|---|
|  |  |  | BigDecimal refundMoney = total == null?new BigDecimal(0):Constants.formatDecimalNum(total.getMoney()); | 
|---|
|  |  |  | BigDecimal canBalance =Constants.formatDecimalNum(goodsorder.getMoney()).subtract(money); | 
|---|
|  |  |  | if(canBalance.compareTo(money) > Constants.ZERO){ | 
|---|
|  |  |  | //可退剩余 单位元 | 
|---|
|  |  |  | BigDecimal canBalance =Constants.translateMoney(Constants.formatDecimalNum(goodsorder.getMoney()).subtract(refundMoney)); | 
|---|
|  |  |  | if(canBalance.compareTo(money) >= Constants.ZERO){ | 
|---|
|  |  |  | RefundDTO refundDTO = new RefundDTO(); | 
|---|
|  |  |  | refundDTO.setOrderId(orderId); | 
|---|
|  |  |  | refundDTO.setCanBalance(canBalance); | 
|---|
|  |  |  | refundDTO.setRefundAmount(money); | 
|---|
|  |  |  | refundDTO.setRefundAmount(money.multiply(new BigDecimal(100))); | 
|---|
|  |  |  | refundDTO.setTotalAmount(goodsorder.getMoney()); | 
|---|
|  |  |  | refundDTO.setMemberId(goodsorder.getMemberId()); | 
|---|
|  |  |  | refundDTO.setCreator(principal.getId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | refundDTO.setType(Constants.REFUND_TYPE.BACK.getKey()); | 
|---|
|  |  |  | Refund refund = wxMiniUtilService.wxRefund(refundDTO); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,退款金额不允许超过"+canBalance); | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,退款金额不允许超过"+canBalance+"元"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | goodsorderCanBanlanceDTO.setCloseMoney(Constants.translateMoney(goodsorder.getCloseMoney())); | 
|---|
|  |  |  | BigDecimal reduce =  total!=null?Constants.formatDecimalNum(total.getMoney()):new BigDecimal(0); | 
|---|
|  |  |  | goodsorderCanBanlanceDTO.setHasRefundMoney(Constants.translateMoney(reduce)); | 
|---|
|  |  |  | goodsorderCanBanlanceDTO.setCanBanlanceMoney(Constants.translateMoney(goodsorder.getMoney()).subtract(goodsorderCanBanlanceDTO.getHasRefundMoney())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal subtract = Constants.translateMoney(goodsorder.getMoney()).subtract(goodsorderCanBanlanceDTO.getHasRefundMoney()); | 
|---|
|  |  |  | goodsorderCanBanlanceDTO.setCanBanlanceMoney(subtract.compareTo(new BigDecimal("0")) > 0 ? subtract : new BigDecimal("0")); | 
|---|
|  |  |  | return goodsorderCanBanlanceDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | model.setPayNum(0); | 
|---|
|  |  |  | model.setRefundNum(0); | 
|---|
|  |  |  | QueryWrapper<Goodsorder> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.lambda().ge(param.getStartDate() !=null,Goodsorder::getPayDate,DateUtil.getShortDateStr(param.getStartDate())); | 
|---|
|  |  |  | queryWrapper.lambda().le(param.getEndDate() !=null,Goodsorder::getPayDate,DateUtil.getShortDateStr(param.getEndDate())); | 
|---|
|  |  |  | if(Objects.nonNull(param.getStartDate())){ | 
|---|
|  |  |  | queryWrapper.lambda().ge(param.getStartDate() !=null,Goodsorder::getPayDate, Utils.Date.getStart(param.getStartDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Objects.nonNull(param.getEndDate())) { | 
|---|
|  |  |  | queryWrapper.lambda().le(param.getEndDate() != null, Goodsorder::getPayDate, Utils.Date.getEnd(param.getEndDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | queryWrapper.lambda().eq(Goodsorder::getPayStatus, Constants.ONE);//已支付 | 
|---|
|  |  |  | queryWrapper.lambda().eq(Goodsorder::getIsdeleted, Constants.ZERO); | 
|---|
|  |  |  | queryWrapper.lambda().groupBy(Goodsorder::getStatus); | 
|---|
|  |  |  | queryWrapper.select( "count(id) as count_num" | 
|---|
|  |  |  | ,"sum(money) as money" ); | 
|---|
|  |  |  | queryWrapper.select( "status ","count(id) as count_num" | 
|---|
|  |  |  | ,"sum(money) as money","sum(close_money) as close_money" ); | 
|---|
|  |  |  | //按订单状态分组统计 | 
|---|
|  |  |  | List<Goodsorder> detailList = goodsorderMapper.selectList(queryWrapper); | 
|---|
|  |  |  | for(Goodsorder goodsorder : detailList){ | 
|---|
|  |  |  | if(Constants.formatIntegerNum(goodsorder.getStatus()) == Constants.GOODSORDER_STATUS.CLOSE.getKey()){ | 
|---|
|  |  |  | //已结算 | 
|---|
|  |  |  | model.setClosedNum(model.getClosedNum()+goodsorder.getCountNum()); | 
|---|
|  |  |  | model.setClosedMoney(model.getClosedMoney().add(Constants.formatDecimalNum(goodsorder.getCloseMoney()))); | 
|---|
|  |  |  | model.setClosedMoney(model.getClosedMoney().add(Constants.translateMoney(goodsorder.getCloseMoney()))); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | model.setPayNum(model.getPayNum()+goodsorder.getCountNum()); | 
|---|
|  |  |  | model.setPayMoney(model.getPayMoney().add(Constants.formatDecimalNum(goodsorder.getMoney()))); | 
|---|
|  |  |  | model.setPayMoney(model.getPayMoney().add(Constants.translateMoney(goodsorder.getMoney()))); | 
|---|
|  |  |  | }else  if(Constants.formatIntegerNum(goodsorder.getStatus()) == Constants.GOODSORDER_STATUS.HAVING_PAY.getKey()){ | 
|---|
|  |  |  | //已支付未结算 | 
|---|
|  |  |  | model.setUnClosedNum(model.getUnClosedNum()+goodsorder.getCountNum()); | 
|---|
|  |  |  | model.setUnClosedMoney(model.getUnClosedMoney().add(Constants.formatDecimalNum(goodsorder.getMoney()))); | 
|---|
|  |  |  | model.setUnClosedMoney(model.getUnClosedMoney().add(Constants.translateMoney(goodsorder.getMoney()))); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | model.setPayNum(model.getPayNum()+goodsorder.getCountNum()); | 
|---|
|  |  |  | model.setPayMoney(model.getPayMoney().add(Constants.formatDecimalNum(goodsorder.getMoney()))); | 
|---|
|  |  |  | model.setPayMoney(model.getPayMoney().add(Constants.translateMoney(goodsorder.getMoney()))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | QueryWrapper<Refund> queryWrapper2 = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper2.lambda().ge(param.getStartDate() !=null,Refund::getDoneDate,DateUtil.getShortDateStr(param.getStartDate())); | 
|---|
|  |  |  | queryWrapper2.lambda().le(param.getEndDate() !=null,Refund::getDoneDate,DateUtil.getShortDateStr(param.getEndDate())); | 
|---|
|  |  |  | if(Objects.nonNull(param.getStartDate())) { | 
|---|
|  |  |  | queryWrapper2.lambda().ge(Refund::getDoneDate, Utils.Date.getStart(param.getStartDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Objects.nonNull(param.getEndDate())) { | 
|---|
|  |  |  | queryWrapper2.lambda().le(Refund::getDoneDate, Utils.Date.getEnd(param.getEndDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | queryWrapper2.lambda().eq(Refund::getIsdeleted, Constants.ZERO); | 
|---|
|  |  |  | queryWrapper2.select( "count(id) as count_num" | 
|---|
|  |  |  | ,"sum(money) as money" ); | 
|---|
|  |  |  | 
|---|
|  |  |  | Refund  refund = refundMapper.selectOne(queryWrapper2.last("limit 1")); | 
|---|
|  |  |  | if(refund !=null){ | 
|---|
|  |  |  | model.setRefundNum(Constants.formatIntegerNum(refund.getCountNum())); | 
|---|
|  |  |  | model.setRefundMoney( Constants.formatDecimalNum(refund.getMoney())); | 
|---|
|  |  |  | model.setRefundMoney(Constants.translateMoney(Constants.formatDecimalNum(refund.getMoney()))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return  model; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | if(goodsorder ==null){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.DATA_EMPTY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<MemberRides> memberRides = getMemberRidesForClose(id); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<MemberRides> memberRides = memberRidesJoinMapper.selectJoinList(MemberRides.class,new MPJLambdaWrapper<MemberRides>() | 
|---|
|  |  |  | .selectAll(MemberRides.class) | 
|---|
|  |  |  | .selectAs(BaseParam::getName,MemberRides::getParamName) | 
|---|
|  |  |  | .leftJoin(BaseParam.class,BaseParam::getId,MemberRides::getParamId) | 
|---|
|  |  |  | .eq(MemberRides::getOrdreId,id) | 
|---|
|  |  |  | .in(MemberRides::getStatus,Constants.MEMBER_RIDES_STATUS.RIDES_RUNNING.getKey(),Constants.MEMBER_RIDES_STATUS.BACK_CYCLING.getKey()) | 
|---|
|  |  |  | .orderByDesc(MemberRides::getCreateDate)); | 
|---|
|  |  |  | if (!CollectionUtils.isEmpty(memberRides)){ | 
|---|
|  |  |  | //预计结算价格和计算时长 | 
|---|
|  |  |  | int freeTime = 0; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Boolean checkTemporaryStop(){ | 
|---|
|  |  |  | if(systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.IS_STOP_SERVE).getCode().equals(Constants.ONE)){ | 
|---|
|  |  |  | if(systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.IS_STOP_SERVE).getCode().equals(Constants.ONE.toString())){ | 
|---|
|  |  |  | String stopServeStartTime = systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.STOP_SERVE_STARTTIME).getCode(); | 
|---|
|  |  |  | String stopServeEndTime = systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.STOP_SERVE_ENDTIME).getCode(); | 
|---|
|  |  |  | //查询当前时间是否在停止中 | 
|---|