|  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.doumee.biz.system.SystemDictDataBiz; | 
|---|
|  |  |  | import com.doumee.config.wx.SendWxMessage; | 
|---|
|  |  |  | import com.doumee.config.wx.WxMiniConfig; | 
|---|
|  |  |  | import com.doumee.config.wx.WxMiniUtilService; | 
|---|
|  |  |  | import com.doumee.core.constants.Constants; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.doumee.dao.business.model.*; | 
|---|
|  |  |  | import com.doumee.dao.dto.*; | 
|---|
|  |  |  | import com.doumee.dao.vo.OrderReleaseVO; | 
|---|
|  |  |  | import com.doumee.service.business.AliSmsService; | 
|---|
|  |  |  | import com.doumee.service.business.OrdersService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.wechat.pay.java.service.refund.model.RefundNotification; | 
|---|
|  |  |  | import jodd.util.StringUtil; | 
|---|
|  |  |  | import lombok.With; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import nonapi.io.github.classgraph.json.Id; | 
|---|
|  |  |  | import org.apache.poi.sl.image.ImageHeaderEMF; | 
|---|
|  |  |  | import org.checkerframework.checker.units.qual.A; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.math.RoundingMode; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.concurrent.TimeUnit; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 订单信息记录Service实现 | 
|---|
|  |  |  | * @author 江蹄蹄 | 
|---|
|  |  |  | * @date 2025/07/09 12:00 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class OrdersServiceImpl implements OrdersService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WxMiniUtilService wxMiniUtilService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SendWxMessage sendWxMessage; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AliSmsService aliSmsService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private RedisTemplate<String,Object> redisTemplate; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | OrderReleaseVO orderReleaseVO = new OrderReleaseVO(); | 
|---|
|  |  |  | Object objects = null; | 
|---|
|  |  |  | this.initVerification(orders); | 
|---|
|  |  |  | Member member = memberMapper.selectById(orders.getMember().getId()); | 
|---|
|  |  |  | if(Objects.isNull(member)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户信息异常"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orders.setCreateTime(new Date()); | 
|---|
|  |  |  | orders.setUpdateTime(orders.getUpdateTime()); | 
|---|
|  |  |  | orders.setPayStatus(Constants.ZERO); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //用餐订单 | 
|---|
|  |  |  | if(Constants.equalsInteger(orders.getType(),Constants.TWO)){ | 
|---|
|  |  |  | orders.setPayAccount(orders.getEstimatedAccount()); | 
|---|
|  |  |  | Long tcje = Long.valueOf(new BigDecimal(orders.getPayAccount().toString()).multiply(orders.getPlatformRata()).intValue()); | 
|---|
|  |  |  | orders.setReceiveAccount(orders.getPayAccount() - tcje); | 
|---|
|  |  |  | orders.setStatus(Constants.ordersStatus.waitPay.getKey()); | 
|---|
|  |  |  | orders.setOutTradeNo(UUID.randomUUID().toString().replace("-","")); | 
|---|
|  |  |  | orders.setPayAccount(orders.getEstimatedAccount()); | 
|---|
|  |  |  | //唤起支付业务 | 
|---|
|  |  |  | objects = this.getWxPayResponse(orders,orders.getMember().getOpenid()); | 
|---|
|  |  |  | objects = this.getWxPayResponse(orders,member.getOpenid()); | 
|---|
|  |  |  | orderReleaseVO.setObject(objects); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | orders.setStatus(Constants.ordersStatus.wait.getKey()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orders.setOriginPriceNum1(orders.getPriceNum1()); | 
|---|
|  |  |  | orders.setOriginPriceNum2(orders.getPriceNum2()); | 
|---|
|  |  |  | orders.setOriginEstimatedAccount(orders.getOriginEstimatedAccount()); | 
|---|
|  |  |  | orders.setConfirmOtherFee(0l); | 
|---|
|  |  |  | ordersMapper.insert(orders); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderReleaseVO.setId(orders.getId()); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(orders.getMultifileList())){ | 
|---|
|  |  |  | List<Multifile> multifileList = orders.getMultifileList(); | 
|---|
|  |  |  | 
|---|
|  |  |  | multifileMapper.insert(multifileList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //更新用户发单量 | 
|---|
|  |  |  | memberMapper.update(new UpdateWrapper<Member>().lambda().setSql(" receive_num =  ( receive_num + 1 )").eq(Member::getId,orders.getMember().getId())); | 
|---|
|  |  |  | memberMapper.update(new UpdateWrapper<Member>().lambda().setSql(" PUBLISH_NUM =  ( ifnull(PUBLISH_NUM,0) + 1 )").eq(Member::getId,orders.getMember().getId())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //创建操作日志 | 
|---|
|  |  |  | Constants.OrdersLog ordersLog = Constants.OrdersLog.UPLOAD; | 
|---|
|  |  |  | 
|---|
|  |  |  | request.setSpAppid(WxMiniConfig.wxProperties.getAppId()); | 
|---|
|  |  |  | request.setSubMchid(WxMiniConfig.wxProperties.getSubMchId()); | 
|---|
|  |  |  | request.setSubAppid(WxMiniConfig.wxProperties.getSubAppId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Payer payer = new Payer(); | 
|---|
|  |  |  | payer.setSubOpenid(openid); | 
|---|
|  |  |  | request.setPayer(payer); | 
|---|
|  |  |  | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if( (Constants.equalsInteger(orders.getType(),Constants.ZERO) && Constants.equalsInteger(orders.getWorkType(),Constants.TWO) && | 
|---|
|  |  |  | ( Constants.equalsInteger(orders.getCarType(),Constants.ZERO) || Constants.equalsInteger(orders.getCarType(),Constants.ONE) )) | 
|---|
|  |  |  | || (Constants.equalsInteger(orders.getType(),Constants.ZERO) && Constants.equalsInteger(orders.getWorkType(),Constants.ONE)) | 
|---|
|  |  |  | if( (Constants.equalsInteger(orders.getType(),Constants.ZERO) | 
|---|
|  |  |  | && Constants.equalsInteger(orders.getWorkType(),Constants.TWO) && | 
|---|
|  |  |  | ( Constants.equalsInteger(orders.getCarType(),Constants.ZERO) | 
|---|
|  |  |  | || Constants.equalsInteger(orders.getCarType(),Constants.ONE) )) | 
|---|
|  |  |  | || (Constants.equalsInteger(orders.getType(),Constants.ZERO) | 
|---|
|  |  |  | && Constants.equalsInteger(orders.getWorkType(),Constants.ONE)) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | if(Objects.isNull(orders.getPriceNum2())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orders.setWayInfo(JSONObject.toJSONString(orders.getWayInfoDTOList())); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | List<Category> categoryList = categoryMapper.selectList(new QueryWrapper<Category>().lambda().eq(Category::getDeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(Category::getType,Constants.TWO) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(CollectionUtils.isEmpty(categoryList)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"餐标信息错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //用餐订单 | 
|---|
|  |  |  | if(CollectionUtils.isEmpty(orders.getCateringDTOList())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"用餐标准数据错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //餐标信息 | 
|---|
|  |  |  | List<Category> categories = categoryList.stream().filter(i->Constants.equalsInteger(i.getId(),cateringDTO.getId())).collect(Collectors.toList()); | 
|---|
|  |  |  | if(CollectionUtils.isEmpty(categories)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"用餐标准数据错误,请刷新重试"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Category category = categories.get(Constants.ZERO); | 
|---|
|  |  |  | List<String> priceList = JSONArray.parseArray(category.getDetail(),String.class  ); | 
|---|
|  |  |  | if(CollectionUtils.isEmpty(priceList)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"用餐标准数据错误,请刷新重试"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(priceList.stream().filter(i->((Long.valueOf(i)*100)+"").equals((cateringDTO.getPrice()+""))).collect(Collectors.toList()).size()==Constants.ZERO){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"用餐标准数据错误,请刷新重试"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | sumPrice = sumPrice + (cateringDTO.getPrice() * cateringDTO.getNum()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!sumPrice.equals(orders.getPrice())){ | 
|---|
|  |  |  | if(new BigDecimal(sumPrice.toString()).compareTo(orders.getPrice())!=Constants.ZERO){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"单价计算错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orders.setWayInfo(JSONObject.toJSONString(orders.getCateringDTOList())); | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"订单已修改,待接单方确认,无法进行该操作"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!Constants.equalsInteger(model.getType(),Constants.TWO)){ | 
|---|
|  |  |  | if(Constants.equalsInteger(model.getStatus(),Constants.ZERO)||Constants.equalsInteger(model.getStatus(),Constants.ONE)){ | 
|---|
|  |  |  | if(Constants.equalsInteger(model.getStatus(),Constants.ZERO) | 
|---|
|  |  |  | ||Constants.equalsInteger(model.getStatus(),Constants.ONE)){ | 
|---|
|  |  |  | this.updateById(orders); | 
|---|
|  |  |  | }else if(Constants.equalsInteger(model.getStatus(),Constants.TWO)){ | 
|---|
|  |  |  | this.updOrderData(orders,model); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | multifileMapper.insert(multifileList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orders.setOriginPriceNum1(orders.getPriceNum1()); | 
|---|
|  |  |  | orders.setOriginPriceNum2(orders.getPriceNum2()); | 
|---|
|  |  |  | orders.setOriginEstimatedAccount(orders.getOriginEstimatedAccount()); | 
|---|
|  |  |  | orders.setConfirmOtherFee(0l); | 
|---|
|  |  |  | ordersMapper.updateById(orders); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(orderLogList)){ | 
|---|
|  |  |  | for (OrderLog orderLog:orderLogList) { | 
|---|
|  |  |  | if(Constants.equalsInteger(orderLog.getOptUserType(),Constants.ZERO)){ | 
|---|
|  |  |  | if(Constants.equalsInteger(orderLog.getOptUserType(),Constants.ZERO)&& org.apache.commons.lang3.StringUtils.isNotBlank(orders.getReleaseName())){ | 
|---|
|  |  |  | orderLog.setLogInfo(orderLog.getLogInfo().replace("{userName}",orders.getReleaseName())); | 
|---|
|  |  |  | }else if(Constants.equalsInteger(orderLog.getOptUserType(),Constants.ONE)){ | 
|---|
|  |  |  | }else if(Constants.equalsInteger(orderLog.getOptUserType(),Constants.ONE)&& org.apache.commons.lang3.StringUtils.isNotBlank(orders.getAcceptName())){ | 
|---|
|  |  |  | orderLog.setLogInfo(orderLog.getLogInfo().replace("{userName}",orders.getAcceptName())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | //查询用户是否有对应身份 | 
|---|
|  |  |  | if(Constants.equalsInteger(orders.getType(),Constants.ZERO)){ | 
|---|
|  |  |  | if(!Constants.equalsInteger(member.getWorkerIdentity(),Constants.TWO)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"身份信息异常,请前往个人中心进行身份认证!"); | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"您还未注册该服务,请前往个人信息中提交申请。"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else if(Constants.equalsInteger(orders.getType(),Constants.ONE)){ | 
|---|
|  |  |  | if(!Constants.equalsInteger(member.getDriverIdentity(),Constants.TWO)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"身份信息异常,请前往个人中心进行身份认证!"); | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"您还未注册该服务,请前往个人信息中提交申请。"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | if(!Constants.equalsInteger(member.getChefIdentity(),Constants.TWO)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"身份信息异常,请前往个人中心进行身份认证!"); | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"您还未注册该服务,请前往个人信息中提交申请。"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | .set(Orders::getStatus,Constants.ordersStatus.accept.getKey()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新接单量 | 
|---|
|  |  |  | memberMapper.update(new UpdateWrapper<Member>().lambda().setSql(" publish_num = (publish_num + 1 )").eq(Member::getId,member.getId())); | 
|---|
|  |  |  | memberMapper.update(new UpdateWrapper<Member>().lambda().setSql(" RECEIVE_NUM = (ifnull(RECEIVE_NUM,0) + 1 )").eq(Member::getId,member.getId())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //创建操作日志 | 
|---|
|  |  |  | Constants.OrdersLog ordersLog = Constants.OrdersLog.RECEIVE; | 
|---|
|  |  |  | this.saveOrderLog(orders,ordersLog, | 
|---|
|  |  |  | ordersLog.getInfo(),member.getId(),null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //TODO 微信公众号提醒 已接单提醒 | 
|---|
|  |  |  | IdentityInfo wokerIdentityInfo = identityInfoMapper.selectOne(new QueryWrapper<IdentityInfo>().lambda() | 
|---|
|  |  |  | .eq(IdentityInfo::getMemberId,member.getId()) | 
|---|
|  |  |  | .eq(IdentityInfo::getType,orders.getType()) | 
|---|
|  |  |  | .eq(IdentityInfo::getAuditStatus,Constants.TWO) | 
|---|
|  |  |  | .last("limit 1") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | Member releaseMember = memberMapper.selectById(orders.getReleaseMemberId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(Objects.nonNull(releaseMember)){ | 
|---|
|  |  |  | if(org.apache.commons.lang3.StringUtils.isNotBlank(releaseMember.getOpenid())&&Objects.nonNull(wokerIdentityInfo)){ | 
|---|
|  |  |  | //发送微信通知 | 
|---|
|  |  |  | sendWxMessage.acceptMessage(releaseMember.getOpenid(),orders,wokerIdentityInfo.getLinkName(),wokerIdentityInfo.getTelephone()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(org.apache.commons.lang3.StringUtils.isNotBlank(orders.getLinkPhone())){ | 
|---|
|  |  |  | //短信通知 | 
|---|
|  |  |  | aliSmsService.businessSendSms(Constants.smsContent.accept.getKey(),orders.getLinkPhone(),orders,null, | 
|---|
|  |  |  | wokerIdentityInfo,categoryMapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | .set(Orders::getIsUpdateTime,new Date()) | 
|---|
|  |  |  | .set(Orders::getUpdateTime,new Date()) | 
|---|
|  |  |  | .set(Orders::getEstimatedAccount,total) | 
|---|
|  |  |  | .set(Orders::getOriginEstimatedAccount,total) | 
|---|
|  |  |  | .eq(Orders::getId,orders.getId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //创建操作日志 | 
|---|
|  |  |  | 
|---|
|  |  |  | this.saveOrderLog(model,ordersLog, | 
|---|
|  |  |  | ordersLog.getInfo(),orders.getMember().getId(),null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //TODO 通知接单人 订单发生变更 | 
|---|
|  |  |  | //通知接单人 订单发生变更 | 
|---|
|  |  |  | Member member = memberMapper.selectById(model.getAcceptMemberId()); | 
|---|
|  |  |  | if(Objects.nonNull(member)){ | 
|---|
|  |  |  | if(org.apache.commons.lang3.StringUtils.isNotBlank(member.getOpenid())){ | 
|---|
|  |  |  | model.setStartDate(orders.getStartDate()); | 
|---|
|  |  |  | model.setEndDate(orders.getEndDate()); | 
|---|
|  |  |  | //发送微信通知 | 
|---|
|  |  |  | sendWxMessage.orderUpdMessage(member.getOpenid(),model); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | IdentityInfo wokerIdentityInfo = identityInfoMapper.selectOne(new QueryWrapper<IdentityInfo>().lambda() | 
|---|
|  |  |  | .eq(IdentityInfo::getMemberId,member.getId()) | 
|---|
|  |  |  | .eq(IdentityInfo::getType,orders.getType()) | 
|---|
|  |  |  | .eq(IdentityInfo::getAuditStatus,Constants.TWO) | 
|---|
|  |  |  | .last("limit 1") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(Objects.nonNull(wokerIdentityInfo)){ | 
|---|
|  |  |  | //短信通知 | 
|---|
|  |  |  | aliSmsService.businessSendSms(Constants.smsContent.orderUpd.getKey(),wokerIdentityInfo.getTelephone(),orders,null, | 
|---|
|  |  |  | null,categoryMapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if( | 
|---|
|  |  |  | (Constants.equalsInteger(orders.getType(),Constants.ZERO) && Constants.equalsInteger(orders.getWorkType(),Constants.ZERO )) | 
|---|
|  |  |  | || Constants.equalsInteger(orders.getType(),Constants.ONE) | 
|---|
|  |  |  | (Constants.equalsInteger(orders.getType(),Constants.ZERO) | 
|---|
|  |  |  | && Constants.equalsInteger(orders.getWorkType(),Constants.ZERO )) | 
|---|
|  |  |  | || Constants.equalsInteger(orders.getType(),Constants.ONE) | 
|---|
|  |  |  | || Constants.equalsInteger(orders.getType(),Constants.TWO) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | orders.setPriceNum2(Constants.ONE); | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return orders.getPrice() * orders.getPriceNum1() * orders.getPriceNum2(); | 
|---|
|  |  |  | BigDecimal bigDecimalPrice = orders.getPrice(). | 
|---|
|  |  |  | multiply(new BigDecimal(orders.getPriceNum1().toString())) | 
|---|
|  |  |  | .multiply(new BigDecimal(orders.getPriceNum2().toString())); | 
|---|
|  |  |  | return bigDecimalPrice.divide(new BigDecimal("1"),0,BigDecimal.ROUND_HALF_UP).longValue();//orders.getPrice() * orders.getPriceNum1() * orders.getPriceNum2(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 接单方确认订单费用 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | public void  confirmFee(ConfirmFeeOrderDTO confirmUpdOrderDTO){ | 
|---|
|  |  |  | if(Objects.isNull(confirmUpdOrderDTO) | 
|---|
|  |  |  | || Objects.isNull(confirmUpdOrderDTO.getOrderId()) | 
|---|
|  |  |  | || Objects.isNull(confirmUpdOrderDTO.getPriceNum1())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Orders orders = ordersMapper.selectById(confirmUpdOrderDTO.getOrderId()); | 
|---|
|  |  |  | if(Objects.isNull(orders)||Constants.equalsInteger(orders.getDeleted(),Constants.ONE)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!Constants.equalsInteger(orders.getAcceptMemberId(),confirmUpdOrderDTO.getMember().getId())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非您的订单无法进行该操作"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!Constants.equalsInteger(orders.getStatus(),Constants.ordersStatus.doing.getKey())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"订单状态已流转,无法进行该操作"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //类型:0=用工;1=运货;2=订餐 | 
|---|
|  |  |  | if(Constants.equalsInteger(orders.getType(),Constants.ZERO)){ | 
|---|
|  |  |  | //用工类型:0=采摘工;1=分拣工;2=包装工;(用工订单) | 
|---|
|  |  |  | if(Constants.equalsInteger(orders.getWorkType(),Constants.ONE)){ | 
|---|
|  |  |  | //1=分拣工 | 
|---|
|  |  |  | if( Objects.isNull(confirmUpdOrderDTO.getPriceNum2())){//必须有用工数量(人) | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else if(Constants.equalsInteger(orders.getWorkType(),Constants.TWO)){ | 
|---|
|  |  |  | //包装工 用车类型(用工包装/运货使用):0=天;1=次/小时;2=重量 | 
|---|
|  |  |  | if( !Constants.equalsInteger(orders.getCarType(),Constants.TWO) | 
|---|
|  |  |  | && Objects.isNull(confirmUpdOrderDTO.getPriceNum2())){ | 
|---|
|  |  |  | //不是按重量计费的,必须有用工数量(人) | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else  if(Constants.equalsInteger(orders.getType(),Constants.ONE)){ | 
|---|
|  |  |  | //运货订单 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该订单不支持该操作,请返回刷新重试!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orders.setPriceNum1(confirmUpdOrderDTO.getPriceNum1()); | 
|---|
|  |  |  | orders.setPriceNum2(confirmUpdOrderDTO.getPriceNum2()); | 
|---|
|  |  |  | Long totalFee = this.getTotal(orders);//重新计算费用 | 
|---|
|  |  |  | Long payFee = totalFee+Constants.formatLongNum(confirmUpdOrderDTO.getConfirmOtherFee());//重新计算费用 | 
|---|
|  |  |  | BigDecimal recFee = new BigDecimal(payFee).multiply((new BigDecimal(1).subtract(Constants.formatBigDecimal(orders.getPlatformRata())))).setScale(0, RoundingMode.HALF_UP) ; | 
|---|
|  |  |  | ordersMapper.update(new UpdateWrapper<Orders>().lambda() | 
|---|
|  |  |  | .set(Orders::getPriceNum1,confirmUpdOrderDTO.getPriceNum1()) | 
|---|
|  |  |  | .set(Orders::getPriceNum2,confirmUpdOrderDTO.getPriceNum2()) | 
|---|
|  |  |  | .set(Orders::getConfirmFeeRemark,confirmUpdOrderDTO.getConfirmFeeRemark()) | 
|---|
|  |  |  | .set(Orders::getConfirmOtherFee,confirmUpdOrderDTO.getConfirmOtherFee()) | 
|---|
|  |  |  | .set(Orders::getEstimatedAccount,totalFee) | 
|---|
|  |  |  | .set(Orders::getStatus,Constants.ordersStatus.feeconfirm.getKey()) | 
|---|
|  |  |  | .set(Orders::getPayAccount,payFee) | 
|---|
|  |  |  | .set(Orders::getReceiveAccount,recFee.longValue()) | 
|---|
|  |  |  | .set(Orders::getUpdateTime,new Date()) | 
|---|
|  |  |  | .eq(Orders::getId,orders.getId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //记录同意修改的日志 | 
|---|
|  |  |  | Constants.OrdersLog ordersLog = Constants.OrdersLog.FEE_CONFIRM; | 
|---|
|  |  |  | this.saveOrderLog(orders,ordersLog, | 
|---|
|  |  |  | ordersLog.getInfo(),confirmUpdOrderDTO.getMember().getId(),null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 接单方处理订单修改 | 
|---|
|  |  |  | 
|---|
|  |  |  | Constants.OrdersLog ordersLog = Constants.OrdersLog.UPD_DISAGREE; | 
|---|
|  |  |  | this.saveOrderLog(orders,ordersLog, | 
|---|
|  |  |  | ordersLog.getInfo(),confirmUpdOrderDTO.getMember().getId(),null); | 
|---|
|  |  |  | //TODO 发送不同意变更通知 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //短信通知 | 
|---|
|  |  |  | aliSmsService.businessSendSms(!Constants.equalsInteger(confirmUpdOrderDTO.getStatus(),Constants.ONE)? | 
|---|
|  |  |  | Constants.smsContent.agreeUpd.getKey():Constants.smsContent.disAgreeUpd.getKey() | 
|---|
|  |  |  | ,orders.getLinkPhone(),null,null, | 
|---|
|  |  |  | null,categoryMapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非您的订单无法进行该操作"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | .eq(Orders::getReleaseMemberId,member.getId())); | 
|---|
|  |  |  | //查询取消次数 | 
|---|
|  |  |  | if(totalCancelTimes<=cancelTimes){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"今日订单主动取消次数已超出"+totalCancelTimes+"次,无法取消订单,如需处理请联系客服"); | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"今日订单主动取消次数已超出"+totalCancelTimes+"次,无法取消订单"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer cancelTimeHour = Integer.valueOf(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.RELEASE_CANCEL_TIME).getCode()); | 
|---|
|  |  |  | Long hours = DateUtil.getBetweenHours(new Date(),orders.getStartDate()); | 
|---|
|  |  |  | if(hours < cancelTimeHour){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"距离订单开始时间不足"+cancelTimeHour+"小时,无法取消订单,如需处理请联系客服"); | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"距离订单开始时间不足"+cancelTimeHour+"小时,无法取消订单"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return  "今日还可主动取消"+(totalCancelTimes-cancelTimes)+"次,是否确认取消"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | //退款业务 | 
|---|
|  |  |  | WithdrawalOrders  withdrawalOrders = new WithdrawalOrders(); | 
|---|
|  |  |  | withdrawalOrders.setCreateTime(new Date()); | 
|---|
|  |  |  | withdrawalOrders.setDeleted(Constants.ZERO); | 
|---|
|  |  |  | withdrawalOrders.setMemberId(orders.getReleaseMemberId()); | 
|---|
|  |  |  | withdrawalOrders.setAmount(orders.getPayAccount()); | 
|---|
|  |  |  | withdrawalOrders.setStatus(Constants.ZERO); | 
|---|
|  |  |  | 
|---|
|  |  |  | .set(Orders::getCancelType,Constants.ONE) | 
|---|
|  |  |  | .eq(Orders::getId,orders.getId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //TODO 发单方取消订单通知接单方 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //减少接单量 | 
|---|
|  |  |  | memberMapper.update(new UpdateWrapper<Member>().lambda().setSql("receive_num = (receive_num - 1) ").eq(Member::getId,orders.getAcceptMemberId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | this.saveOrderLog(orders,ordersLog, | 
|---|
|  |  |  | ordersLog.getInfo(),member.getId(),null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Member> members = memberMapper.selectList(new QueryWrapper<Member>().lambda() | 
|---|
|  |  |  | .and(i->i.eq(Member::getId,orders.getReleaseMemberId()).or().eq(Member::getId,orders.getAcceptMemberId())) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(members)){ | 
|---|
|  |  |  | List<String> openIdList = members.stream().map(i->i.getOpenid()).collect(Collectors.toList()); | 
|---|
|  |  |  | //发送微信通知 | 
|---|
|  |  |  | sendWxMessage.cancelMessage(openIdList,orders,Constants.ONE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | IdentityInfo wokerIdentityInfo = identityInfoMapper.selectOne(new QueryWrapper<IdentityInfo>().lambda() | 
|---|
|  |  |  | .eq(IdentityInfo::getMemberId,orders.getAcceptMemberId()) | 
|---|
|  |  |  | .eq(IdentityInfo::getType,orders.getType()) | 
|---|
|  |  |  | .eq(IdentityInfo::getAuditStatus,Constants.TWO) | 
|---|
|  |  |  | .last("limit 1") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(Objects.nonNull(wokerIdentityInfo)){ | 
|---|
|  |  |  | //短信通知 | 
|---|
|  |  |  | aliSmsService.businessSendSms(Constants.smsContent.releaseCancel.getKey(),wokerIdentityInfo.getTelephone(),orders,null, | 
|---|
|  |  |  | null,categoryMapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | this.saveOrderLog(orders,ordersLog, | 
|---|
|  |  |  | ordersLog.getInfo(),member.getId(),null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //TODO 接单方取消订单通知 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Member> members = memberMapper.selectList(new QueryWrapper<Member>().lambda() | 
|---|
|  |  |  | .and(i->i.eq(Member::getId,orders.getReleaseMemberId()).or().eq(Member::getId,orders.getAcceptMemberId())) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(members)){ | 
|---|
|  |  |  | List<String> openIdList = members.stream().map(i->i.getOpenid()).collect(Collectors.toList()); | 
|---|
|  |  |  | //发送微信通知 | 
|---|
|  |  |  | sendWxMessage.cancelMessage(openIdList,orders,Constants.TWO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //短信通知 | 
|---|
|  |  |  | aliSmsService.businessSendSms(Constants.smsContent.receiveCancel.getKey(),member.getTelephone(),orders,null, | 
|---|
|  |  |  | null,categoryMapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | if(!Constants.equalsInteger(orders.getReleaseMemberId(),doneOrderDTO.getMember().getId())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非您的订单无法进行该操作"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Member payMember = memberMapper.selectById(doneOrderDTO.getMember().getId()); | 
|---|
|  |  |  | if(Objects.isNull(payMember)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户信息异常"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OrderReleaseVO orderReleaseVO = new OrderReleaseVO(); | 
|---|
|  |  |  | orderReleaseVO.setId(orders.getId()); | 
|---|
|  |  |  | Object object = null; | 
|---|
|  |  |  | 
|---|
|  |  |  | if(!Constants.equalsInteger(orders.getType(),Constants.TWO)){ | 
|---|
|  |  |  | orders.setPayAccount(doneOrderDTO.getAmount()); | 
|---|
|  |  |  | //提成金额 | 
|---|
|  |  |  | Long tcje = Long.valueOf(new BigDecimal(orders.getPayAccount().toString()).multiply(orders.getPlatformRata()).intValue()); | 
|---|
|  |  |  | Long tcje =  (new BigDecimal(orders.getPayAccount().toString()).multiply(Constants.formatBigDecimal(orders.getPlatformRata())).setScale(0,RoundingMode.HALF_UP).longValue()); | 
|---|
|  |  |  | orders.setReceiveAccount(orders.getPayAccount() - tcje); | 
|---|
|  |  |  | orders.setOutTradeNo(UUID.randomUUID().toString().replace("-","")); | 
|---|
|  |  |  | ordersMapper.updateById(orders); | 
|---|
|  |  |  | //唤起支付业务 | 
|---|
|  |  |  | object = this.getWxPayResponse(orders,doneOrderDTO.getMember().getOpenid()); | 
|---|
|  |  |  | object = this.getWxPayResponse(orders,payMember.getOpenid()); | 
|---|
|  |  |  | orderReleaseVO.setObject(object); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | orders.setStatus(Constants.ordersStatus.done.getKey()); | 
|---|
|  |  |  | 
|---|
|  |  |  | Constants.OrdersLog ordersLog = Constants.OrdersLog.DONE; | 
|---|
|  |  |  | this.saveOrderLog(orders,ordersLog, | 
|---|
|  |  |  | ordersLog.getInfo(),doneOrderDTO.getMember().getId(),null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | sendWxMessage.revenueMessage(member.getOpenid(),orders); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //短信通知接单方 | 
|---|
|  |  |  | if(Objects.nonNull(orders.getAcceptMemberId())){ | 
|---|
|  |  |  | IdentityInfo wokerIdentityInfo = identityInfoMapper.selectOne(new QueryWrapper<IdentityInfo>().lambda() | 
|---|
|  |  |  | .eq(IdentityInfo::getMemberId,orders.getAcceptMemberId()) | 
|---|
|  |  |  | .eq(IdentityInfo::getType,orders.getType()) | 
|---|
|  |  |  | .eq(IdentityInfo::getAuditStatus,Constants.TWO) | 
|---|
|  |  |  | .last("limit 1") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(Objects.nonNull(wokerIdentityInfo)){ | 
|---|
|  |  |  | aliSmsService.businessSendSms(Constants.smsContent.pay.getKey(),wokerIdentityInfo.getTelephone(),orders,null, | 
|---|
|  |  |  | null,categoryMapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return orderReleaseVO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | Constants.OrdersLog ordersLog = Constants.OrdersLog.SYSTEM_CANCEL; | 
|---|
|  |  |  | this.saveOrderLog(orders,ordersLog, | 
|---|
|  |  |  | ordersLog.getInfo(),null,loginUserInfo.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Member> members = memberMapper.selectList(new QueryWrapper<Member>().lambda() | 
|---|
|  |  |  | .and(i->i.eq(Member::getId,orders.getReleaseMemberId()).or().eq(Member::getId,orders.getAcceptMemberId())) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(members)){ | 
|---|
|  |  |  | List<String> openIdList = members.stream().map(i->i.getOpenid()).collect(Collectors.toList()); | 
|---|
|  |  |  | orders.setCancelTime(new Date()); | 
|---|
|  |  |  | //发送微信通知 | 
|---|
|  |  |  | sendWxMessage.cancelMessage(openIdList,orders,Constants.ZERO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //短信通知发单方 | 
|---|
|  |  |  | aliSmsService.businessSendSms(Constants.smsContent.platformCancel.getKey(),orders.getLinkPhone(),orders,null, | 
|---|
|  |  |  | null,categoryMapper); | 
|---|
|  |  |  | //短信通知接单方 | 
|---|
|  |  |  | if(Objects.nonNull(orders.getAcceptMemberId())){ | 
|---|
|  |  |  | IdentityInfo wokerIdentityInfo = identityInfoMapper.selectOne(new QueryWrapper<IdentityInfo>().lambda() | 
|---|
|  |  |  | .eq(IdentityInfo::getMemberId,orders.getAcceptMemberId()) | 
|---|
|  |  |  | .eq(IdentityInfo::getType,orders.getType()) | 
|---|
|  |  |  | .eq(IdentityInfo::getAuditStatus,Constants.TWO) | 
|---|
|  |  |  | .last("limit 1") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(Objects.nonNull(wokerIdentityInfo)){ | 
|---|
|  |  |  | aliSmsService.businessSendSms(Constants.smsContent.platformCancel2.getKey(),wokerIdentityInfo.getTelephone(),orders,null, | 
|---|
|  |  |  | null,categoryMapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | .eq(Orders::getId,orders.getId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | memberMapper.update(new UpdateWrapper<Member>().lambda() | 
|---|
|  |  |  | .setSql(" score =  ( total_score +" + commentDTO.getLevel() + " ) / (score_order_num + 1 )") | 
|---|
|  |  |  | .setSql(" total_score =  total_score +" + commentDTO.getLevel()) | 
|---|
|  |  |  | .setSql(" score_order_num = score_order_num + 1 " ).eq(Member::getId,orders.getAcceptMemberId()) | 
|---|
|  |  |  | .setSql(" score =  ( ifnull(total_score,0) +" + commentDTO.getLevel() + " ) / (ifnull(score_order_num,0) + 1 )") | 
|---|
|  |  |  | .setSql(" total_score =  ifnull(total_score,0) +" + commentDTO.getLevel()) | 
|---|
|  |  |  | .setSql(" score_order_num = ifnull(score_order_num,0) + 1 " ) | 
|---|
|  |  |  | .eq(Member::getId,orders.getAcceptMemberId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //日志存储 | 
|---|
|  |  |  | Constants.OrdersLog ordersLog = Constants.OrdersLog.COMMENT; | 
|---|
|  |  |  | 
|---|
|  |  |  | this.saveOrderLog(orders,ordersLog, | 
|---|
|  |  |  | ordersLog.getInfo(),orders.getReleaseMemberId(),null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //TODO 通知接单方 款项已到账 | 
|---|
|  |  |  | // 通知接单方 款项已到账 | 
|---|
|  |  |  | sendWxMessage.revenueMessage(member.getOpenid(),orders); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //短信通知接单方 | 
|---|
|  |  |  | if(Objects.nonNull(orders.getAcceptMemberId())){ | 
|---|
|  |  |  | IdentityInfo wokerIdentityInfo = identityInfoMapper.selectOne(new QueryWrapper<IdentityInfo>().lambda() | 
|---|
|  |  |  | .eq(IdentityInfo::getMemberId,orders.getAcceptMemberId()) | 
|---|
|  |  |  | .eq(IdentityInfo::getType,orders.getType()) | 
|---|
|  |  |  | .eq(IdentityInfo::getAuditStatus,Constants.TWO) | 
|---|
|  |  |  | .last("limit 1") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(Objects.nonNull(wokerIdentityInfo)){ | 
|---|
|  |  |  | aliSmsService.businessSendSms(Constants.smsContent.pay.getKey(),wokerIdentityInfo.getTelephone(),orders,null, | 
|---|
|  |  |  | null,categoryMapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orders.setStatusName(Constants.ordersStatus.getName(orders.getStatus())); | 
|---|
|  |  |  | orders.setCancelStatus(Constants.ZERO); | 
|---|
|  |  |  | if(Constants.equalsInteger(orders.getStatus(),Constants.ordersStatus.accept.getKey())&&Constants.equalsInteger(orders.getIsUpdate(),Constants.ONE)){ | 
|---|
|  |  |  | orders.setConfirmCountdown(DateUtil.getXMinuteAfterDate(orders.getIsUpdateTime(),60).getTime() - System.currentTimeMillis()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.getPriceUnit(orders); | 
|---|
|  |  |  | if(orders.getStatus() <= Constants.ordersStatus.accept.getKey()){ | 
|---|
|  |  |  | if(Constants.equalsInteger(orders.getReleaseMemberId(),member.getId())){ | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void autoGrabOrders(){ | 
|---|
|  |  |  | String autoConfirmTime = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.AUTO_DISPATCH).getCode(); | 
|---|
|  |  |  | List<Orders> ordersList = ordersMapper.selectList(new QueryWrapper<Orders>().lambda() | 
|---|
|  |  |  | List<Orders> ordersList = ordersMapper.selectList(new QueryWrapper<Orders>().lambda().eq(Orders::getDeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(Orders::getStatus,Constants.ONE).eq(Orders::getCommentStatus,Constants.ZERO) | 
|---|
|  |  |  | .apply(" DATE_ADD(create_time, INTERVAL "+autoConfirmTime+" MINUTE) < now() ") | 
|---|
|  |  |  | .last("limit 100") | 
|---|
|  |  |  | 
|---|
|  |  |  | BigDecimal lat = orders.getLat(); | 
|---|
|  |  |  | BigDecimal lgt = orders.getLgt(); | 
|---|
|  |  |  | //查询范围内的会员 | 
|---|
|  |  |  | List<Member> memberList = memberMapper.selectList(new MPJLambdaWrapper<Member>().selectAll(Member.class) | 
|---|
|  |  |  | .select(" ifnull((select r.level from receive_weight r where r.RECEIVE_MAX > t.RECEIVE_NUM and t.RECEIVE_NUM > r.RECEIVE_MIN limit 1  ),0) " ,Member::getLevel) | 
|---|
|  |  |  | .select(  " ifnull( (select CONVERT( ST_Distance_Sphere ( POINT ( ii.lgt, ii.lat ), POINT ( "+lgt+", "+lat+" )) /1000,DECIMAL(15,2)) from identity_info ii where ii.AUDIT_STATUS = 2 and type = 0 and ii.member_id = t.ID limit  1 ),0) ",Member::getDistance ) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | .apply(" id in (" + | 
|---|
|  |  |  | " select ii.member_id from identity_info ii where ii.AUDIT_STATUS = 2 and type = '"+orders.getType()+"' " + | 
|---|
|  |  |  | " and ( CONVERT( ST_Distance_Sphere ( POINT ( ii.lgt, ii.lat ), POINT ( "+lgt+", "+lat+" )) /1000,DECIMAL(15,2))) < 100 " + | 
|---|
|  |  |  | ") ") | 
|---|
|  |  |  | .orderByDesc(Member::getLevel) | 
|---|
|  |  |  | .orderByDesc(Member::getScore) | 
|---|
|  |  |  | .orderByAsc(Member::getDistance) | 
|---|
|  |  |  | .last(" limit 1 ") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | List<Member> memberList = memberMapper.getList(lgt,lat,orders.getType()); | 
|---|
|  |  |  | //                    memberMapper.selectList(new MPJLambdaWrapper<Member>() | 
|---|
|  |  |  | //                    .select(Member::getId,Member::getScore) | 
|---|
|  |  |  | //                            .select(" ifnull((select r.level from receive_weight r where r.RECEIVE_MAX > RECEIVE_NUM and RECEIVE_NUM > r.RECEIVE_MIN limit 1  ),0) " ,Member::getLevel) | 
|---|
|  |  |  | //                            .select(  " ifnull( (select CONVERT( ST_Distance_Sphere ( POINT ( ii.lgt, ii.lat ), POINT ( "+lgt+", "+lat+" )) /1000,DECIMAL(15,2)) from identity_info ii where ii.AUDIT_STATUS = 2 and type = 0 and ii.member_id = ID limit  1 ),0) ",Member::getDistance ) | 
|---|
|  |  |  | //// | 
|---|
|  |  |  | //                    .apply(" id in (" + | 
|---|
|  |  |  | //                            " select ii.member_id from identity_info ii where ii.AUDIT_STATUS = 2 and type = '"+orders.getType()+"' " + | 
|---|
|  |  |  | //                            " and ( CONVERT( ST_Distance_Sphere ( POINT ( ii.lgt, ii.lat ), POINT ( "+lgt+", "+lat+" )) /1000,DECIMAL(15,2))) < 100 " + | 
|---|
|  |  |  | //                            ") ") | 
|---|
|  |  |  | //                    .orderByDesc(" level , score ") | 
|---|
|  |  |  | //                    .orderByAsc(Member::getDistance) | 
|---|
|  |  |  | //                    .last(" limit 1 ") | 
|---|
|  |  |  | //            ); | 
|---|
|  |  |  | if(CollectionUtils.isEmpty(memberList)){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Member member = memberList.get(Constants.ZERO); | 
|---|
|  |  |  | Member releaseMember = memberMapper.selectById(orders.getReleaseMemberId()); | 
|---|
|  |  |  | //自动派单 | 
|---|
|  |  |  | Orders model = ordersMapper.selectById(orders.getStatus()); | 
|---|
|  |  |  | if(!Constants.equalsInteger(model.getStatus(),Constants.ONE)){ | 
|---|
|  |  |  | Orders model = ordersMapper.selectById(orders.getId()); | 
|---|
|  |  |  | if(!Constants.equalsInteger(model.getStatus(),Constants.ONE) || Constants.equalsInteger(model.getId(),model.getReleaseMemberId())){ | 
|---|
|  |  |  | //如果订单已删除 并且非发布方 | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ordersMapper.update(new UpdateWrapper<Orders>().lambda().eq(Orders::getId,model.getId()) | 
|---|
|  |  |  | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新接单量 | 
|---|
|  |  |  | memberMapper.update(new UpdateWrapper<Member>().lambda().setSql(" publish_num = (publish_num + 1 )").eq(Member::getId,member.getId())); | 
|---|
|  |  |  | memberMapper.update(new UpdateWrapper<Member>().lambda().setSql(" RECEIVE_NUM = (ifnull(RECEIVE_NUM,0) + 1 )").eq(Member::getId,member.getId())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //创建操作日志 | 
|---|
|  |  |  | Constants.OrdersLog ordersLog = Constants.OrdersLog.AUTO; | 
|---|
|  |  |  | this.saveOrderLog(orders,ordersLog, | 
|---|
|  |  |  | ordersLog.getInfo(),member.getId(),null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | IdentityInfo wokerIdentityInfo = identityInfoMapper.selectOne(new QueryWrapper<IdentityInfo>().lambda() | 
|---|
|  |  |  | .eq(IdentityInfo::getMemberId,member.getId()) | 
|---|
|  |  |  | .eq(IdentityInfo::getType,orders.getType()) | 
|---|
|  |  |  | .eq(IdentityInfo::getAuditStatus,Constants.TWO) | 
|---|
|  |  |  | .last("limit 1") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //通知发单方 | 
|---|
|  |  |  | if(org.apache.commons.lang3.StringUtils.isNotBlank(releaseMember.getOpenid())&&Objects.nonNull(wokerIdentityInfo)){ | 
|---|
|  |  |  | //发送微信通知 | 
|---|
|  |  |  | sendWxMessage.acceptMessage(releaseMember.getOpenid(),orders,wokerIdentityInfo.getLinkName(),wokerIdentityInfo.getTelephone()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //通知接单方 | 
|---|
|  |  |  | sendWxMessage.autoDispatchMessage(member.getOpenid(),orders,GeoUtils.haversineDistance( | 
|---|
|  |  |  | orders.getLgt().doubleValue(), orders.getLat().doubleValue(), | 
|---|
|  |  |  | wokerIdentityInfo.getLgt().doubleValue(), | 
|---|
|  |  |  | wokerIdentityInfo.getLat().doubleValue() | 
|---|
|  |  |  | )); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | aliSmsService.businessSendSms(Constants.smsContent.dispatch.getKey(),orders.getLinkPhone(),orders,null, | 
|---|
|  |  |  | null,categoryMapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|