|  |  |  | 
|---|
|  |  |  | package com.matrix.system.activity.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cn.hutool.core.collection.CollUtil; | 
|---|
|  |  |  | import cn.hutool.core.date.DateUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.ObjectUtil; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.matrix.system.activity.vo.ZjrVo; | 
|---|
|  |  |  | import com.matrix.system.common.bean.SysUsers; | 
|---|
|  |  |  | import com.matrix.system.common.bean.SystemDictionary; | 
|---|
|  |  |  | import com.matrix.system.common.constance.AppConstance; | 
|---|
|  |  |  | import com.matrix.system.common.dao.SystemDictionaryDao; | 
|---|
|  |  |  | import com.matrix.system.hive.action.util.QueryUtil; | 
|---|
|  |  |  | import com.matrix.system.hive.dao.SysVipInfoDao; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.service.WxShopLogisticsQueryService; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopActivities; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopDeliveryInfo; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopLogisticsInfo; | 
|---|
|  |  |  | 
|---|
|  |  |  | ShopDeliveryInfoDao shopDeliveryInfoDao; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | ShopLogisticsInfoDao shopLogisticsInfoDao; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WxShopLogisticsQueryService wxShopLogisticsQueryService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public IPage<SignWriteoffListVo> findSignWriteoffList(Page<SignWriteoffListVo> page, | 
|---|
|  |  |  | SignWriteoffListDto signWriteoffListDto) { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //物流跟踪 | 
|---|
|  |  |  | Integer logisticsId = activitySignWriteoffLogistics.getLogisticsId(); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(logisticsId)) { | 
|---|
|  |  |  | List<ShopLogisticsInfo> shopLogisticsInfos = shopLogisticsInfoDao.selectByDelieryId(logisticsId); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(shopLogisticsInfos)) { | 
|---|
|  |  |  | ArrayList<LogisticsVo> logisticsVos = new ArrayList<>(); | 
|---|
|  |  |  | for(ShopLogisticsInfo shopLogistics : shopLogisticsInfos) { | 
|---|
|  |  |  | LogisticsVo logisticsVo = new LogisticsVo(); | 
|---|
|  |  |  | logisticsVo.setContent(shopLogistics.getDescribe()); | 
|---|
|  |  |  | logisticsVo.setTimestamp(shopLogistics.getLogisticsTime()); | 
|---|
|  |  |  | logisticsVos.add(logisticsVo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | signWriteoffVo.setActivities(logisticsVos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ShopDeliveryInfo shopDeliveryInfo = shopDeliveryInfoDao.selectById(logisticsId); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(shopDeliveryInfo)){ | 
|---|
|  |  |  | signWriteoffVo.setLogisticsNum(shopDeliveryInfo.getWaybillNo()); | 
|---|
|  |  |  | signWriteoffVo.setLogisticsCompany(shopDeliveryInfo.getLogisticsCompany()); | 
|---|
|  |  |  | //查看物流信息 | 
|---|
|  |  |  | wxShopLogisticsQueryService.selectLogisticsInfo(shopDeliveryInfo); | 
|---|
|  |  |  | List<ShopLogisticsInfo> shopLogisticsInfos = shopLogisticsInfoDao.selectByDelieryId(shopDeliveryInfo.getId()); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(shopLogisticsInfos)) { | 
|---|
|  |  |  | ArrayList<LogisticsVo> logisticsVos = new ArrayList<>(); | 
|---|
|  |  |  | for(ShopLogisticsInfo shopLogistics : shopLogisticsInfos) { | 
|---|
|  |  |  | LogisticsVo logisticsVo = new LogisticsVo(); | 
|---|
|  |  |  | logisticsVo.setContent(shopLogistics.getDescribe()); | 
|---|
|  |  |  | logisticsVo.setTimestamp(shopLogistics.getLogisticsTime()); | 
|---|
|  |  |  | logisticsVos.add(logisticsVo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | signWriteoffVo.setActivities(logisticsVos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | result.putInMap("signWriteoffVo", signWriteoffVo); | 
|---|
|  |  |  | 
|---|
|  |  |  | String writeOffCode = writeoffCodeSubmitDto.getWriteOffCode(); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 验证核销码是不是匹配 | 
|---|
|  |  |  | * 只能核销一次 | 
|---|
|  |  |  | * 更新核销记录 | 
|---|
|  |  |  | * 更新领取记录 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | //验证核销码是不是匹配 | 
|---|
|  |  |  | ActivitySignWriteoff activitySignWriteoff = activitySignWriteoffDao.selectById(writeoffId); | 
|---|
|  |  |  | if(ActivitySignWriteoff.STATE_ONE != activitySignWriteoff.getState()){ | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "兑奖码已失效"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(activitySignWriteoff)) { | 
|---|
|  |  |  | String writeoffCodeReal = activitySignWriteoff.getWriteoffCode(); | 
|---|
|  |  |  | if(!writeoffCodeReal.equals(writeOffCode)) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "兑奖码无效"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //更新核销记录 | 
|---|
|  |  |  | //线下兑换失效 | 
|---|
|  |  |  | Long awardId = activitySignWriteoff.getAwardId(); | 
|---|
|  |  |  | ActivitySignAwardSet activitySignAwardSet = activitySignAwardSetDao.selectById(awardId); | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDWAY_ONE == activitySignAwardSet.getAwardWay() | 
|---|
|  |  |  | || ActivitySignAwardSet.AWARDWAY_THREE == activitySignAwardSet.getAwardWay()){ | 
|---|
|  |  |  | Date prizeStartTime = activitySignAwardSet.getPrizeStartTime(); | 
|---|
|  |  |  | if(DateUtil.date().getTime() < prizeStartTime.getTime()){ | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "兑奖还没开始呢!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Date prizeEndTime = activitySignAwardSet.getPrizeEndTime(); | 
|---|
|  |  |  | if(DateUtil.date().getTime() > prizeEndTime.getTime()){ | 
|---|
|  |  |  | Long receiveId = activitySignWriteoff.getReceiveId(); | 
|---|
|  |  |  | ActivitySignReceiveRecord activitySignReceiveRecord = activitySignReceiveRecordDao.selectById(receiveId); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(activitySignReceiveRecord)){ | 
|---|
|  |  |  | activitySignReceiveRecord.setState(ActivitySignReceiveRecord.STATE_FIVE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | activitySignReceiveRecordDao.updateById(activitySignReceiveRecord); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | activitySignWriteoff.setState(ActivitySignWriteoff.STATE_FOUR); | 
|---|
|  |  |  | activitySignWriteoffDao.updateById(activitySignWriteoff); | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "已超出兑奖结束时间!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //更新核销记录 | 
|---|
|  |  |  | activitySignWriteoff.setState(ActivitySignWriteoff.STATE_THREE); | 
|---|
|  |  |  | activitySignWriteoff.setWriteoffTime(new Date()); | 
|---|
|  |  |  | activitySignWriteoff.setWriteoffUser(sysUsers.getSuName()); | 
|---|
|  |  |  | 
|---|
|  |  |  | shopDeliveryInfo.setLogisticsCompany(systemDictionary.getName()); | 
|---|
|  |  |  | shopDeliveryInfo.setLogisticsCompanyCode(systemDictionary.getCode()); | 
|---|
|  |  |  | shopDeliveryInfo.setDeliveryWay("物流配送"); | 
|---|
|  |  |  | shopDeliveryInfo.setLogisticsStatus(AppConstance.LOGISTICS_STATUS_OF_RECEIVE); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shopDeliveryInfo.setWaybillNo(logisticsSubmitDto.getKddh()); | 
|---|
|  |  |  | shopDeliveryInfo.setUpdateBy(sysUsers.getSuName()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shopDeliveryInfo.setDeliveryTime(new Date()); | 
|---|
|  |  |  | shopDeliveryInfoDao.insert(shopDeliveryInfo); | 
|---|
|  |  |  | //      Integer id = shopDeliveryInfo.getId(); | 
|---|
|  |  |  | //      if(ObjectUtil.isNotEmpty(id)) { | 
|---|
|  |  |  | //         List<ShopLogisticsInfo> shopLogisticsList = new ArrayList<ShopLogisticsInfo>(); | 
|---|
|  |  |  | //           AjaxResult result = new AjaxResult(); | 
|---|
|  |  |  | //           Map<String, String> logisticsInfo = new HashMap<String, String>(); | 
|---|
|  |  |  | //           try { | 
|---|
|  |  |  | //               if (shopDeliveryInfo == null) { | 
|---|
|  |  |  | //                   return new AjaxResult(AjaxResult.STATUS_FAIL, "找不到发货信息"); | 
|---|
|  |  |  | //               } | 
|---|
|  |  |  | //               if (!StringUtils.isNotBlank(shopDeliveryInfo.getWaybillNo()) || !StringUtils.isNotBlank(shopDeliveryInfo.getLogisticsCompanyCode())) { | 
|---|
|  |  |  | //                   return new AjaxResult(AjaxResult.STATUS_FAIL, "物流公司信息为空"); | 
|---|
|  |  |  | //               } | 
|---|
|  |  |  | //               logisticsInfo.put("logisticsCompany", shopDeliveryInfo.getLogisticsCompany()); | 
|---|
|  |  |  | //               logisticsInfo.put("waybillNo", shopDeliveryInfo.getWaybillNo()); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //               //如果已经签收直接查数据库 | 
|---|
|  |  |  | //               if (AppConstance.LOGISTICS_STATUS_OF_SIGN_FOR.equals(shopDeliveryInfo.getLogisticsStatus())) { | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                   List<ShopLogisticsInfo> shopLogisticsInfos = shopLogisticsInfoDao.selectByDelieryId(shopDeliveryInfo.getId()); | 
|---|
|  |  |  | //                   logisticsInfo.put("logisticsStatus", String.valueOf(AppConstance.LOGISTICS_STATUS_OF_SIGN_FOR)); | 
|---|
|  |  |  | //                   result.setStatus(AjaxResult.STATUS_SUCCESS); | 
|---|
|  |  |  | //                   result.setRows(shopLogisticsInfos); | 
|---|
|  |  |  | //                   result.putInMap("logisticsInfo", logisticsInfo); | 
|---|
|  |  |  | //                   return result; | 
|---|
|  |  |  | //               } | 
|---|
|  |  |  | //               Map<String, String> param = new HashMap<String, String>(); | 
|---|
|  |  |  | //               param.put("ShipperCode", shopDeliveryInfo.getLogisticsCompanyCode()); | 
|---|
|  |  |  | //               param.put("LogisticCode", shopDeliveryInfo.getWaybillNo()); | 
|---|
|  |  |  | //               Map<String, String> paramsUrl = getparams(param); | 
|---|
|  |  |  | //               LogUtil.info("物流查询参数" + paramsUrl); | 
|---|
|  |  |  | //               String logisticsResult = HttpCurlUtil.sendPost(logisticsUrl, paramsUrl); | 
|---|
|  |  |  | //               LogUtil.info("查询物流返回信息" + logisticsResult); | 
|---|
|  |  |  | //               LogisticsInfoVo logisticsInfoVo = JSON.parseObject(logisticsResult, LogisticsInfoVo.class); | 
|---|
|  |  |  | //               if (logisticsInfoVo.isSuccess()) { | 
|---|
|  |  |  | //                   ShopDeliveryInfo shopDelivery = new ShopDeliveryInfo(); | 
|---|
|  |  |  | //                   shopDelivery.setLogisticsStatus(Integer.valueOf(logisticsInfoVo.getState())); | 
|---|
|  |  |  | //                   shopDelivery.setId(shopDeliveryInfo.getId()); | 
|---|
|  |  |  | //                   logisticsInfo.put("logisticsStatus", logisticsInfoVo.getState()); | 
|---|
|  |  |  | //                   //更新物流状态 | 
|---|
|  |  |  | //                   shopDeliveryInfoDao.updateByModel(shopDelivery); | 
|---|
|  |  |  | //                   if (CollectionUtils.isNotEmpty(logisticsInfoVo.getTraces())) { | 
|---|
|  |  |  | //                       List<Map<String, String>> mapTraces = logisticsInfoVo.getTraces(); | 
|---|
|  |  |  | //                       for (int i = 0; i < mapTraces.size(); i++) { | 
|---|
|  |  |  | //                           ShopLogisticsInfo shopLogisticsInfo = new ShopLogisticsInfo(); | 
|---|
|  |  |  | //                           shopLogisticsInfo.setCreateBy(AppConstance.SYSTEM_USER); | 
|---|
|  |  |  | //                           shopLogisticsInfo.setUpdateBy(AppConstance.SYSTEM_USER); | 
|---|
|  |  |  | //                           shopLogisticsInfo.setLogisticsTime(mapTraces.get(i).get("AcceptTime")); | 
|---|
|  |  |  | //                           String acceptStation = mapTraces.get(i).get("AcceptStation"); | 
|---|
|  |  |  | //                           shopLogisticsInfo.setDescribe(acceptStation); | 
|---|
|  |  |  | //                           shopLogisticsInfo.setDelieryId(shopDeliveryInfo.getId()); | 
|---|
|  |  |  | //                           if (acceptStation.indexOf(AppConstance.KDN_IS_SIGN) != -1) { | 
|---|
|  |  |  | //                               shopLogisticsInfo.setState(AppConstance.LOGISTICS_STATUS_OF_SIGN_FOR); | 
|---|
|  |  |  | //                           } else if (acceptStation.indexOf(AppConstance.KDN_IS_RECEIVE) != -1) { | 
|---|
|  |  |  | //                               shopLogisticsInfo.setState(AppConstance.LOGISTICS_STATUS_OF_RECEIVE); | 
|---|
|  |  |  | //                           } else if (acceptStation.indexOf(AppConstance.KDN_IS_ON_WAY) != -1) { | 
|---|
|  |  |  | //                               shopLogisticsInfo.setState(AppConstance.LOGISTICS_STATUS_OF_ON_WAY); | 
|---|
|  |  |  | //                           } else if (acceptStation.indexOf(AppConstance.KDN_IS_MISTAKE) != -1) { | 
|---|
|  |  |  | //                               shopLogisticsInfo.setState(AppConstance.LOGISTICS_STATUS_OF_MISTAKE); | 
|---|
|  |  |  | //                           } else { | 
|---|
|  |  |  | //                               shopLogisticsInfo.setState(AppConstance.LOGISTICS_STATUS_OF_NONE); | 
|---|
|  |  |  | //                           } | 
|---|
|  |  |  | //                           shopLogisticsList.add(shopLogisticsInfo); | 
|---|
|  |  |  | //                       } | 
|---|
|  |  |  | //                       shopLogisticsInfoDao.deleteByDelieryId(shopDeliveryInfo.getId()); | 
|---|
|  |  |  | //                       if (CollectionUtils.isNotEmpty(shopLogisticsList)) { | 
|---|
|  |  |  | //                           shopLogisticsInfoDao.batchInsert(shopLogisticsList); | 
|---|
|  |  |  | //                       } | 
|---|
|  |  |  | //                   } | 
|---|
|  |  |  | //               } else { | 
|---|
|  |  |  | //                   throw new GlobleException(logisticsInfoVo.getReason()); | 
|---|
|  |  |  | //               } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //           } catch (Exception e) { | 
|---|
|  |  |  | //               throw new GlobleException("物流信息查询失败"); | 
|---|
|  |  |  | //           } | 
|---|
|  |  |  | //更新核销记录 | 
|---|
|  |  |  | activitySignWriteoff.setState(ActivitySignWriteoff.STATE_THREE); | 
|---|
|  |  |  | activitySignWriteoff.setWriteoffTime(new Date()); | 
|---|
|  |  |  | activitySignWriteoff.setWriteoffUser(sysUsers.getSuName()); | 
|---|
|  |  |  | activitySignWriteoff.setWriteoffUserid(sysUsers.getSuId()); | 
|---|
|  |  |  | activitySignWriteoff.setLogisticsId(shopDeliveryInfo.getId()); | 
|---|
|  |  |  | activitySignWriteoffDao.updateById(activitySignWriteoff); | 
|---|
|  |  |  | //更新领取记录 | 
|---|
|  |  |  | ActivitySignReceiveRecord activitySignReceiveRecord = activitySignReceiveRecordDao.selectById(receiveId); | 
|---|
|  |  |  | activitySignReceiveRecord.setState(ActivitySignReceiveRecord.STATE_THREE); | 
|---|
|  |  |  | activitySignReceiveRecord.setConsignee(logisticsSubmitDto.getShr()); | 
|---|
|  |  |  | activitySignReceiveRecord.setConsigneeAddress(logisticsSubmitDto.getShdz()); | 
|---|
|  |  |  | activitySignReceiveRecord.setConsigneePhone(logisticsSubmitDto.getLxdh()); | 
|---|
|  |  |  | activitySignReceiveRecordDao.updateById(activitySignReceiveRecord); | 
|---|
|  |  |  | //      } | 
|---|
|  |  |  | //更新核销记录 | 
|---|
|  |  |  | activitySignWriteoff.setState(ActivitySignWriteoff.STATE_THREE); | 
|---|
|  |  |  | activitySignWriteoff.setWriteoffTime(new Date()); | 
|---|
|  |  |  | activitySignWriteoff.setWriteoffUser(sysUsers.getSuName()); | 
|---|
|  |  |  | activitySignWriteoff.setWriteoffUserid(sysUsers.getSuId()); | 
|---|
|  |  |  | activitySignWriteoff.setLogisticsId(shopDeliveryInfo.getId()); | 
|---|
|  |  |  | activitySignWriteoffDao.updateById(activitySignWriteoff); | 
|---|
|  |  |  | //更新领取记录 | 
|---|
|  |  |  | ActivitySignReceiveRecord activitySignReceiveRecord = activitySignReceiveRecordDao.selectById(receiveId); | 
|---|
|  |  |  | activitySignReceiveRecord.setState(ActivitySignReceiveRecord.STATE_FOUR); | 
|---|
|  |  |  | activitySignReceiveRecord.setConsignee(logisticsSubmitDto.getShr()); | 
|---|
|  |  |  | activitySignReceiveRecord.setConsigneeAddress(logisticsSubmitDto.getShdz()); | 
|---|
|  |  |  | activitySignReceiveRecord.setConsigneePhone(logisticsSubmitDto.getLxdh()); | 
|---|
|  |  |  | activitySignReceiveRecordDao.updateById(activitySignReceiveRecord); | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_SUCCESS, "发货成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|