| @@ -106,7 +106,7 @@ public class WxMerchantController extends BaseController { | |||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::saveOrUpdate"); | |||
| if (null == wxMerchantRelation) wxMerchantRelation = new WxMerchantRelation(); | |||
| wxMerchantRelation.updateTenantInfo(getTenantInfo()); | |||
| return wxMerchantRelationService.saveOrUpdate(wxMerchantRelation.getRegionMerchantId(),wxMerchantRelation.getMerchantIds(),wxMerchantRelation.getType(),wxMerchantRelation.getTenantId()); | |||
| return wxMerchantRelationService.saveOrUpdate(wxMerchantRelation.getRegionMerchantId(),wxMerchantRelation.getMerchantIds(),wxMerchantRelation.getType(),getTenantInfo()); | |||
| } | |||
| @ApiOperation("区域商户删除普通商户") | |||
| @@ -131,11 +131,16 @@ public class WxMerchantController extends BaseController { | |||
| @ApiOperation("子商户列表查询") | |||
| @GetMapping("/subMerchantList") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| @SystemControllerLog(description = "子商户列表查询") | |||
| public ResultData subMerchantList() { | |||
| public ResultData subMerchantList(@ModelAttribute WxMerchant wxMerchant, Integer pageNum, Integer pageSize) { | |||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::subMerchantList"); | |||
| List<WxMerchant> merchants = wxMerchantService.subMerchantList(); | |||
| return new ResultData(merchants); | |||
| if (null == wxMerchant) wxMerchant = new WxMerchant(); | |||
| wxMerchant.setSortColumns(BaseEntity.SortField.TopTime_DESC); | |||
| PageInfo<WxMerchant> pageInfo = wxMerchantService.subMerchantList(wxMerchant, pageNum, pageSize); | |||
| return new ResultData(pageInfo); | |||
| } | |||
| @ApiOperation("分页列表接口") | |||
| @@ -341,52 +341,24 @@ public class WxCouponOrderController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| WxCouponOrderCVo wxCouponOrderCVo = null; | |||
| String couponTenantId = paramMap.get("couponTenantId"); | |||
| TenantEntity couponOrderTenantEntity = getCouponOrderTenantEntity(couponTenantId); | |||
| wxCouponOrderCVo = wxCouponOrderService.detailCUserVo(couponOrderIdStr,couponOrderTenantEntity); | |||
| if (wxCouponOrderCVo == null) | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(wxCouponOrderCVo.getcUserId(),wxCouponOrderCVo.getFinalTenantId()); | |||
| if (wxCUserBasicInfo != null && EnumCreditLockedStatus.CLOSE.getCode().equals(wxCUserBasicInfo.getStatus())) { | |||
| return new ResultData(ErrorCode.MEMBER_IS_LOCKED); | |||
| } | |||
| Date now = new Date(); | |||
| if (wxCouponOrderCVo.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())){ | |||
| // && !wxCouponOrderCVo.getType().equals(EnumCouponType.COUPON_PREORDER.getCode())) { | |||
| if (wxCouponOrderCVo.getValidStartDate().after(now)) { | |||
| logger.error("此券有效期未开始:" + couponOrderIdStr); | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE); | |||
| } | |||
| if (wxCouponOrderCVo.getValidEndDate().before(now)) { | |||
| logger.error("此券有效期已结束:" + couponOrderIdStr); | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_LATER_THAN_VALIDDATE); | |||
| } | |||
| } else if(wxCouponOrderCVo.getValidType().equals(EnumCouponValidType.DAYS_AFTER_RECEIVING.getCode())){ | |||
| if (wxCouponOrderCVo.getExpiredTime().before(now)) { | |||
| logger.error("此券已过期:" + couponOrderIdStr); | |||
| return new ResultData(ErrorCode.COUPON_IS_EXPIRED); | |||
| } | |||
| } | |||
| WxCouponOrder wxCouponOrder = wxCouponOrderService.getById(couponOrderId,couponOrderTenantEntity.getTenantId()); | |||
| if (wxCouponOrder == null) { | |||
| logger.error("券ID不存在:" + couponOrderId); | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| } | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(wxCouponOrder.getcUserId(),wxCouponOrder.getFinalTenantId()); | |||
| if (wxCUserBasicInfo != null && EnumCreditLockedStatus.CLOSE.getCode().equals(wxCUserBasicInfo.getStatus())) { | |||
| return new ResultData(ErrorCode.MEMBER_IS_LOCKED); | |||
| } | |||
| WxMerchantBUser wxMerchantBUser = getLoginBUser(); | |||
| if (wxMerchantBUser == null) { | |||
| logger.error("核销员ID不存在:" + getLoginBUser().getId()); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), "核销员ID不存在或者无权限"); | |||
| } | |||
| Long bUserId = getWxBuserId(); | |||
| if (null != bUserId) { | |||
| wxMerchantBUser.setBuserId(bUserId); | |||
| } | |||
| WxCouponOrder couponOrder = null; | |||
| try { | |||
| @@ -1,21 +1,31 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.annotation.TenantIgnore; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCouponOrderReservation; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.enums.EnumCouponOrderReservationStatus; | |||
| import com.iformall.service.WxCouponOrderReservationService; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.WxCouponOrderCVo; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.DateUtils; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @RestController | |||
| @RequestMapping("/api/wxCouponOrderReservation") | |||
| @Api(description = "查询预约接口") | |||
| @@ -25,6 +35,18 @@ public class WxCouponOrderReservationController extends BaseController { | |||
| @Autowired | |||
| private WxCouponOrderReservationService wxCouponOrderReservationService; | |||
| @Autowired | |||
| private WxMerchantService wxMerchantService; | |||
| @Autowired | |||
| private WxMerchantRelationService wxMerchantRelationService; | |||
| @Autowired | |||
| private WxCouponOrderService wxCouponOrderService; | |||
| @Autowired | |||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @@ -117,5 +139,76 @@ public class WxCouponOrderReservationController extends BaseController { | |||
| return new ResultData(); | |||
| } | |||
| /** | |||
| * 预约单核销 | |||
| * @param reservation | |||
| * @return | |||
| */ | |||
| @ApiOperation(value = "核销接口", notes = "{\"couponOrderId\":\"string\",\"couponTenantId\":\"string\"}") | |||
| @PostMapping("verify") | |||
| public ResultData verify(@RequestBody WxCouponOrderReservation reservation) { | |||
| logger.info("WxCouponOrderReservationController.verify:"); | |||
| WxMerchantBUser loginBUser = getLoginBUser(); | |||
| if(reservation.getId() == null){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"id is null"); | |||
| } | |||
| WxCouponOrderReservation sortReservation = wxCouponOrderReservationService.getSortById(reservation.getId(), reservation.getTenantId()); | |||
| if(sortReservation == null){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"id is error"); | |||
| } | |||
| if(EnumCouponOrderReservationStatus.getReservationFinish().contains(sortReservation.getStatus())){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"预约单已完成"); | |||
| } | |||
| // if(!EnumCouponOrderReservationStatus.getReservationIng().contains(sortReservation.getStatus())){ | |||
| // return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"预约单状态不支持核销"); | |||
| // } | |||
| if(sortReservation.getReservationMerchantId() == null){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"预约门店未找到"); | |||
| } | |||
| //登陆商户 | |||
| Long merchantId = loginBUser.getMerchantId(); | |||
| //核销商户 | |||
| WxMerchant merchant = null; | |||
| if(!sortReservation.getReservationMerchantId().equals(merchantId)){ | |||
| WxMerchant loginMerchant = wxMerchantService.selectById(merchantId); | |||
| if(!EnumMerchantAdmin.REGIONAL.getCode().equals(loginMerchant.getIsAdmin())){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"非区域商户,核销失败"); | |||
| } | |||
| List<Long> subMerchantIds = wxMerchantRelationService.getRelationByRegionId(merchant.getId()); | |||
| if(!subMerchantIds.contains(sortReservation.getReservationMerchantId())){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"区域门店不匹配,核销失败"); | |||
| } | |||
| merchant = wxMerchantService.selectById(sortReservation.getReservationMerchantId()); | |||
| } | |||
| WxCouponOrder wxCouponOrder = wxCouponOrderService.getById(sortReservation.getCouponOrderId(),sortReservation.getTenantId()); | |||
| if (wxCouponOrder == null) { | |||
| logger.error("券ID不存在:" + sortReservation.getCouponOrderId()); | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| } | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(wxCouponOrder.getcUserId(),wxCouponOrder.getFinalTenantId()); | |||
| if (wxCUserBasicInfo != null && EnumCreditLockedStatus.CLOSE.getCode().equals(wxCUserBasicInfo.getStatus())) { | |||
| return new ResultData(ErrorCode.MEMBER_IS_LOCKED); | |||
| } | |||
| WxCouponOrder couponOrder = null; | |||
| try { | |||
| wxCouponOrder.setVerifyRemark(EnumCouponVerifyType.VERIFY_B_13.getMessage()); | |||
| couponOrder = wxCouponOrderService.verify(wxCouponOrder, merchant, EnumCouponVerifyType.VERIFY_B,loginBUser); | |||
| } catch (MallinkException e) { | |||
| logger.error("核销异常: " + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error("核销异常: " + e.getMessage()); | |||
| return new ResultData(ErrorCode.VERIFY_ERROR, e.getMessage()); | |||
| } | |||
| if (couponOrder != null) { | |||
| wxCouponOrderService.sendInsideCouponVerifyMsg(couponOrder.getId(), couponOrder, couponOrder.getBMerchantId(), loginBUser); | |||
| } | |||
| return new ResultData(couponOrder); | |||
| } | |||
| } | |||
| @@ -515,11 +515,6 @@ public class WxCouponOrderController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| WxCouponOrderCVo wxCouponOrderCVo = wxCouponOrderService.detailCUserVo(couponOrderIdStr,getTenantInfo()); | |||
| if (wxCouponOrderCVo == null) | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| WxCUserBasicInfo member; | |||
| try { | |||
| member = getCacheMember(); | |||
| @@ -527,25 +522,6 @@ public class WxCouponOrderController extends BaseController { | |||
| return new ResultData(Result.ERROR,e.getMessage()); | |||
| } | |||
| Date now = new Date(); | |||
| if (wxCouponOrderCVo.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())){ | |||
| // && !wxCouponOrderCVo.getType().equals(EnumCouponType.COUPON_PREORDER.getCode())) { | |||
| if (wxCouponOrderCVo.getValidStartDate().after(now)) { | |||
| logger.error("此券有效期未开始:" + couponOrderIdStr); | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE); | |||
| } | |||
| if (wxCouponOrderCVo.getValidEndDate().before(now)) { | |||
| logger.error("此券有效期已结束:" + couponOrderIdStr); | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_LATER_THAN_VALIDDATE); | |||
| } | |||
| } else if(wxCouponOrderCVo.getValidType().equals(EnumCouponValidType.DAYS_AFTER_RECEIVING.getCode())){ | |||
| if (wxCouponOrderCVo.getExpiredTime().before(now)) { | |||
| logger.error("此券已过期:" + couponOrderIdStr); | |||
| return new ResultData(ErrorCode.COUPON_IS_EXPIRED); | |||
| } | |||
| } | |||
| WxCouponOrder wxCouponOrder = wxCouponOrderService.getById(couponOrderId,getTenantInfo().getTenantId()); | |||
| if (wxCouponOrder == null) { | |||
| logger.error("券ID不存在:" + couponOrderId); | |||
| @@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @TableName(value = "wx_coupon_order_reservation") | |||
| @Data | |||
| @@ -79,6 +80,12 @@ public class WxCouponOrderReservation extends TenantEntity { | |||
| @TableField(exist = false) | |||
| private Date serchEndDate; | |||
| @TableField(exist = false) | |||
| private List<Integer> statusList; | |||
| @TableField(exist = false) | |||
| private List<Long> reservationMerchantIdList; | |||
| public Long getcUserId() { | |||
| return cUserId; | |||
| @@ -428,5 +428,7 @@ public class WxMerchant extends TenantEntity { | |||
| private Integer hasCarVendor; | |||
| @TableField(exist = false) | |||
| private Integer noCarVendor; | |||
| @TableField(exist = false) | |||
| private List<Long> merchantIds; | |||
| } | |||
| @@ -25,16 +25,6 @@ public class WxMerchantRelation extends TenantEntity { | |||
| */ | |||
| private Long id; | |||
| /** | |||
| * 租户ID | |||
| */ | |||
| private String tenantId; | |||
| /** | |||
| * 父租户ID | |||
| */ | |||
| private String parentTenantId; | |||
| /** | |||
| * 区域商户id | |||
| */ | |||
| @@ -11,6 +11,7 @@ public enum EnumCouponVerifyType { | |||
| VERIFY_B_10(10,"B端收银核销"), | |||
| VERIFY_B_11(11,"B端券码核销"), | |||
| VERIFY_B_12(12,"B端扫码核销"), | |||
| VERIFY_B_13(13,"B端预约单核销"), | |||
| VERIFY_POS_INDEPENDENT(1, "POS独立核销"), | |||
| VERIFY_POS_PAY(2, "POS交易核销"), | |||
| @@ -4,9 +4,6 @@ import com.iformall.common.CommonMapper; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.domain.dto.WxMerchantDto; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.WxMerchantTradeDetailVo; | |||
| import com.iformall.domain.vo.WxMerchantTradeVo; | |||
| import com.iformall.domain.vo.WxMerchantVo; | |||
| import org.apache.ibatis.annotations.Param; | |||
| import java.util.HashMap; | |||
| @@ -61,5 +58,4 @@ public interface WxMerchantMapper extends CommonMapper<WxMerchant, Long> { | |||
| List<WxMerchant> getMerchantListByIds(@Param("relationIds") List<Long> relationIds); | |||
| List<WxMerchant> getSubMerchantListByIds(@Param("merchantIds") List<Long> merchantIds); | |||
| } | |||
| @@ -10,15 +10,13 @@ import java.util.List; | |||
| public interface WxMerchantRelationMapper extends CommonMapper<WxMerchantRelation, Long> { | |||
| Integer selectByIds(@Param("ids") List<Long> ids); | |||
| void updateByReginId(@Param("regionId") Long regionId); | |||
| void insertBatch(List<WxMerchantRelation> list); | |||
| List<WxMerchantRelation> selectByReginId(@Param("regionId") Long regionId, @Param("ids") List<Long> ids); | |||
| void updateByMerchantIds(@Param("merchantIds") List<Long> merchantIds); | |||
| void updateByMerchantIds(@Param("merchantIds") List<Long> merchantIds,@Param("regionId") Long regionId); | |||
| void deleteByMerchantId(@Param("merchantId") Long merchantId); | |||
| @@ -2,12 +2,13 @@ package com.iformall.service; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import java.util.List; | |||
| public interface WxMerchantRelationService { | |||
| ResultData saveOrUpdate(Long regionId, List<Long> ids, Integer type, String tenantId); | |||
| ResultData saveOrUpdate(Long regionId, List<Long> ids, Integer type, TenantEntity tenantEntity); | |||
| void deleteByMerchantId(Long id); | |||
| @@ -218,6 +218,6 @@ public interface WxMerchantService { | |||
| List<WxMerchant> relationList(Long regionId); | |||
| List<WxMerchant> subMerchantList(); | |||
| PageInfo<WxMerchant> subMerchantList(WxMerchant wxMerchant, Integer pageNum, Integer pageSize); | |||
| } | |||
| @@ -7,11 +7,13 @@ import com.iformall.domain.po.*; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.*; | |||
| import org.apache.commons.collections.CollectionUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.*; | |||
| import java.util.stream.Collectors; | |||
| @Service | |||
| public class WxCouponOrderReservationServiceImpl implements WxCouponOrderReservationService { | |||
| @@ -39,8 +41,23 @@ public class WxCouponOrderReservationServiceImpl implements WxCouponOrderReserva | |||
| @Autowired | |||
| WxMerchantMapper wxMerchantMapper; | |||
| @Autowired | |||
| WxMerchantRelationService wxMerchantRelationService; | |||
| @Override | |||
| public PageInfo<WxCouponOrderReservation> listAsPage(WxCouponOrderReservation record, Integer pageIndex, Integer pageSize) { | |||
| if(record.getReservationMerchantId() != null){ | |||
| //区域商户查询下面所有子商户的信息 | |||
| WxMerchant merchant = wxMerchantMapper.selectById(record.getReservationMerchantId()); | |||
| if(EnumMerchantAdmin.REGIONAL.getCode().equals(merchant.getIsAdmin())){ | |||
| //通过区域商户id查询所有子商户 | |||
| List<Long> collect = wxMerchantRelationService.getRelationByRegionId(merchant.getId()); | |||
| if (!CollectionUtils.isEmpty(collect)){ | |||
| record.setReservationMerchantIdList(collect); | |||
| } | |||
| record.setReservationMerchantId(null); | |||
| } | |||
| } | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponOrderReservationMapper.findList(record)); | |||
| } | |||
| @@ -1402,7 +1402,24 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| logger.error("券: coupon-" + wxCoupon.getId() + "不存在" + "couponOrder-" + couponOrder.getId()); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| } | |||
| Date now = new Date(); | |||
| if (wxCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())){ | |||
| // && !wxCouponOrderCVo.getType().equals(EnumCouponType.COUPON_PREORDER.getCode())) { | |||
| if (wxCoupon.getValidStartDate().after(now)) { | |||
| logger.error("此券有效期未开始:" + couponOrder.getId()); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE); | |||
| } | |||
| if (wxCoupon.getValidEndDate().before(now)) { | |||
| logger.error("此券有效期已结束:" + couponOrder.getId()); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_LATER_THAN_VALIDDATE); | |||
| } | |||
| } | |||
| // 3. 券包状态检查 | |||
| if(couponOrder.getExpiredTime() != null && couponOrder.getExpiredTime().before(now)){ | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_LATER_THAN_VALIDDATE); | |||
| } | |||
| if (couponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_OVER_TIME.getCode()) { | |||
| logger.error("已过期: couponOrder-" + couponOrder.getId()); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_OVER_TIME); | |||
| @@ -1483,14 +1500,12 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| couponOrder.setBMerchantId(merchantId==null?0l:merchantId); | |||
| couponOrder.setBTenantId(mallTenantEntity.getTenantId()); | |||
| couponOrder.setVerifyType(couponVerifyType.getCode()); | |||
| if(EnumCouponVerifyType.VERIFY_B.equals(couponVerifyType) | |||
| && StringUtils.isNotBlank(couponOrder.getVerifyRemark())){ | |||
| if(couponOrder.getVerifyRemark().equals(EnumCouponVerifyType.VERIFY_B_11.getCode().toString())){ | |||
| couponOrder.setVerifyRemark(EnumCouponVerifyType.VERIFY_B_11.getMessage()); | |||
| }else if(couponOrder.getVerifyRemark().equals(EnumCouponVerifyType.VERIFY_B_12.getCode().toString())){ | |||
| couponOrder.setVerifyRemark(EnumCouponVerifyType.VERIFY_B_12.getMessage()); | |||
| } | |||
| } | |||
| if(EnumCouponVerifyType.VERIFY_B.equals(couponVerifyType) && StringUtils.isNotBlank(couponOrder.getVerifyRemark())){ | |||
| try{ | |||
| int subVerifyType = Integer.parseInt(couponOrder.getVerifyRemark()); | |||
| couponOrder.setVerifyRemark(EnumCouponVerifyType.getEnum(subVerifyType).getMessage()); | |||
| }catch(Exception e){} | |||
| } | |||
| if(EnumOrderShopingType.SELF_MENTION.getCode().equals(couponOrder.getShippingType())){ | |||
| couponOrder.setShippingStatus(EnumOrderShopingStatus.ALREADY_SELF_MENTION.getCode()); | |||
| }else if(EnumOrderShopingType.DISTRIBUTION.getCode().equals(couponOrder.getShippingType())){ | |||
| @@ -1551,37 +1566,16 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| TenantEntity tenantEntity = new TenantEntity(); | |||
| tenantEntity.setTenantId(tenantId); | |||
| tenantEntity.setParentTenantId(parentTenantId); | |||
| WxCouponOrder wxCouponOrder = this.getById(couponOrderId,tenantEntity.getTenantId()); | |||
| if (wxCouponOrder == null) { | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| } | |||
| WxCouponOrderCVo wxCouponOrderCVo = this.detailCUserVo(String.valueOf(couponOrderId),tenantEntity); | |||
| if (wxCouponOrderCVo == null) { | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| } | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(wxCouponOrderCVo.getcUserId(),wxCouponOrderCVo.getFinalTenantId()); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(wxCouponOrder.getcUserId(),wxCouponOrder.getFinalTenantId()); | |||
| if (wxCUserBasicInfo != null && EnumCreditLockedStatus.CLOSE.getCode().equals(wxCUserBasicInfo.getStatus())) { | |||
| throw new MallinkException(ErrorCode.MEMBER_IS_LOCKED); | |||
| } | |||
| Date now = new Date(); | |||
| if (wxCouponOrderCVo.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())){ | |||
| // && !wxCouponOrderCVo.getType().equals(EnumCouponType.COUPON_PREORDER.getCode())) { | |||
| if (wxCouponOrderCVo.getValidStartDate().after(now)) { | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE); | |||
| } | |||
| if (wxCouponOrderCVo.getValidEndDate().before(now)) { | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_LATER_THAN_VALIDDATE); | |||
| } | |||
| } else if(wxCouponOrderCVo.getValidType().equals(EnumCouponValidType.DAYS_AFTER_RECEIVING.getCode())){ | |||
| if (wxCouponOrderCVo.getExpiredTime().before(now)) { | |||
| throw new MallinkException(ErrorCode.COUPON_IS_EXPIRED); | |||
| } | |||
| } | |||
| WxCouponOrder wxCouponOrder = this.getById(couponOrderId,tenantEntity.getTenantId()); | |||
| if (wxCouponOrder == null) { | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| } | |||
| SysConfig sysConfig = sysConfigService.getByKey(SysConfigConstant.default_merchant_b_user, tenantEntity); | |||
| if (null == sysConfig) { | |||
| @@ -5,6 +5,7 @@ import com.iformall.common.IdWorker; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxMerchantRelation; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.mapper.WxMerchantRelationMapper; | |||
| import com.iformall.service.WxMerchantRelationService; | |||
| import com.iformall.service.WxMerchantService; | |||
| @@ -14,7 +15,6 @@ import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.stream.Collectors; | |||
| @@ -30,7 +30,7 @@ public class WxMerchantRelationServiceImpl implements WxMerchantRelationService | |||
| @Transactional(rollbackFor = {Exception.class}) | |||
| @Override | |||
| public ResultData saveOrUpdate(Long regionId, List<Long> ids, Integer type, String tenantId) { | |||
| public ResultData saveOrUpdate(Long regionId, List<Long> ids, Integer type, TenantEntity tenantEntity) { | |||
| if (regionId == null) { | |||
| return new ResultData(Result.ERROR, "区域商户id不能为空"); | |||
| } | |||
| @@ -43,48 +43,41 @@ public class WxMerchantRelationServiceImpl implements WxMerchantRelationService | |||
| //先去查询是否存在,如果存在再去排除这个id去进行查询是否存在 | |||
| List<WxMerchantRelation> infByIds = wxMerchantRelationMapper.getInfByIds(ids); | |||
| List<Long> list = new ArrayList<>(); | |||
| List<Long> updateList = new ArrayList<>(); | |||
| if (!CollectionUtils.isEmpty(infByIds)) { | |||
| list = infByIds.parallelStream().map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); | |||
| //判断子商户是否已经被选了 | |||
| Integer integer = wxMerchantRelationMapper.selectByIds(list); | |||
| if (integer > 0) { | |||
| List<Long> alreadyList = infByIds.parallelStream().filter(x -> x.getIsDel() == 0).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); | |||
| //如果已经存在就返回 | |||
| if (!CollectionUtils.isEmpty(alreadyList)){ | |||
| return new ResultData(Result.ERROR, "存在子商户在其他区域商户下"); | |||
| } | |||
| } | |||
| List<Long> finalList = list; | |||
| List<Long> collected = ids.parallelStream().filter(x -> !finalList.contains(x)).collect(Collectors.toList()); | |||
| //1-新增 2-修改 | |||
| if (type == 1) { | |||
| //选择就插入 | |||
| insertInfo(regionId, ids, tenantId); | |||
| return new ResultData(Result.SUCCESS, "新增成功", null); | |||
| } else if (type == 2) { | |||
| wxMerchantRelationMapper.updateByMerchantIds(list); | |||
| if (!CollectionUtils.isEmpty(collected)){ | |||
| insertInfo(regionId, collected, tenantId); | |||
| //如果存在且是同一个区域商户下就 修改 是否删除字段 | |||
| List<Long> delList = infByIds.parallelStream().filter(x -> x.getIsDel() == 1 && x.getRegionMerchantId().equals(regionId)).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); | |||
| if (!CollectionUtils.isEmpty(delList)){ | |||
| updateList = delList; | |||
| } | |||
| return new ResultData(Result.SUCCESS, "编辑成功", null); | |||
| } | |||
| return null; | |||
| } | |||
| public void insertInfo(Long regionId, List<Long> ids, String tenantId) { | |||
| List<WxMerchantRelation> list = new ArrayList<>(); | |||
| for (Long id : ids) { | |||
| WxMerchantRelation relation = new WxMerchantRelation(); | |||
| relation.setId(IdWorker.get().nextId()); | |||
| relation.setMerchantId(id); | |||
| relation.setRegionMerchantId(regionId); | |||
| relation.setIsDel(0); | |||
| relation.setTenantId(tenantId); | |||
| list.add(relation); | |||
| List<Long> finalList = updateList; | |||
| List<Long> insertList = ids.parallelStream().filter(x -> !finalList.contains(x)).collect(Collectors.toList()); | |||
| if (!CollectionUtils.isEmpty(updateList)) { | |||
| wxMerchantRelationMapper.updateByMerchantIds(updateList,regionId); | |||
| } | |||
| wxMerchantRelationMapper.insertBatch(list); | |||
| if (!CollectionUtils.isEmpty(insertList)) { | |||
| List<WxMerchantRelation> list = new ArrayList<>(); | |||
| for (Long id : ids) { | |||
| WxMerchantRelation relation = new WxMerchantRelation(); | |||
| relation.setId(IdWorker.get().nextId()); | |||
| relation.setMerchantId(id); | |||
| relation.setRegionMerchantId(regionId); | |||
| relation.setTenantId(tenantEntity.getTenantId()); | |||
| relation.setParentTenantId(tenantEntity.getParentTenantId()); | |||
| list.add(relation); | |||
| } | |||
| wxMerchantRelationMapper.insertBatch(list); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "成功", null); | |||
| } | |||
| @Override | |||
| public void deleteByMerchantId(Long merchantId) { | |||
| wxMerchantRelationMapper.deleteByMerchantId(merchantId); | |||
| @@ -2084,9 +2084,11 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||
| * 查询剩余子商户 | |||
| */ | |||
| @Override | |||
| public List<WxMerchant> subMerchantList() { | |||
| public PageInfo<WxMerchant> subMerchantList(WxMerchant wxMerchant, Integer pageNum, Integer pageSize) { | |||
| //查询已经被选择了的子商户 | |||
| List<Long> merchantIds = wxMerchantRelationService.getRelationByRegionId(null); | |||
| return wxMerchantMapper.getSubMerchantListByIds(merchantIds); | |||
| wxMerchant.setMerchantIds(merchantIds); | |||
| PageInfo<WxMerchant> pageInfo = PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxMerchantMapper.findList(wxMerchant)); | |||
| return pageInfo; | |||
| } | |||
| } | |||
| @@ -157,20 +157,6 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| return null; | |||
| } | |||
| private int getMallSumRate(TenantEntity tenantEntity,Long orderId){ | |||
| WxOrder o = wxOrderMapper.selectById(orderId, tenantEntity.getTenantId()); | |||
| if(!EnumOrderType.COUPON.getCode().equals(o.getType())){ | |||
| return 0; | |||
| } | |||
| Long couponId = wxCouponChannelMapper.findCouponIdById(o.getCouponChannelId(), o.getTenantId()); | |||
| TtPoiTakeRate ttPoiTakeRate = ttPoiTakeRateMapper.selectByCoupon(tenantEntity.getTenantId(), couponId, EnumCpsPlanType.ALL.getCode()); | |||
| if(ttPoiTakeRate != null){ | |||
| return ttPoiTakeRate.getTakeRate(); | |||
| }else{ | |||
| return 0; | |||
| } | |||
| } | |||
| @Override | |||
| // @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) | |||
| public ResultData redoSharingOrder(WxProfitSharingOrder sharingOrder,WxPayOrder payOrder) { | |||
| @@ -178,8 +164,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| if(!EnumProfitSharingOrderStatus.shareStatus().contains(sharingOrder.getSharingStatus())){ | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"分账状态不允许"); | |||
| } | |||
| //核销商户 | |||
| WxMerchant merchant = wxMerchantService.selectById(sharingOrder.getMerchantId()); | |||
| Date currentDate = new Date(); | |||
| @@ -188,19 +173,6 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| PayShareResult shareResult = null; | |||
| //获取达人佣金 | |||
| int cpsCommission = payShareAdapterService.getCPSCommission(sharingOrder,sharingOrder.getSingleOrderId()); | |||
| if(cpsCommission < 0){ | |||
| WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); | |||
| updSharingOrder.updateTenantInfo(sharingOrder); | |||
| updSharingOrder.setId(sharingOrder.getId()); | |||
| updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); | |||
| updSharingOrder.setErrorMsg("未获取到达人佣金"); | |||
| updSharingOrder.setUpdateTime(currentDate); | |||
| wxProfitSharingOrderMapper.updateById(updSharingOrder); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"未获取到达人佣金");//等待重试 | |||
| } | |||
| JSONArray receivers = new JSONArray();//分账参数json | |||
| EnumPayWay enumPayWay = EnumPayWay.getEnum(payOrder.getPayVendor()); | |||
| EnumAppPlat enumPlat = enumPayWay.getPlat(); | |||
| @@ -216,113 +188,85 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| }else{ | |||
| wxComposeChildOrderShare = payOrder.getSingleChildOrderShare(); | |||
| } | |||
| wxComposeChildOrderShare.setCpsCommission(cpsCommission); | |||
| //官方手续费---千6 | |||
| int realRate = serviceFeeService.getRealRate(payAccount); | |||
| int realRateAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), realRate, true); | |||
| wxComposeChildOrderShare.setRealRateAmount(realRateAmount); | |||
| //官方平台抽佣 | |||
| int rate = serviceFeeService.getOfficialCommissionByOrder(wxComposeChildOrderShare.getOrderId(),payAccount); | |||
| int commissionAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), rate, true); | |||
| wxComposeChildOrderShare.setCommissionAmount(commissionAmount); | |||
| int surplus = 0;//无法获取到各分账帐号时,计入收款帐号 | |||
| //只有抖音才有抽成 | |||
| //微信缺少流程(分账帐号绑定) 无法抽成 | |||
| if(EnumPayWay.PAY_WAY_TT.getCode().equals(payOrder.getPayVendor()) | |||
| && EnumYesOrNo.YES.getCode().equals(payAccount.getIsCommission())){ | |||
| //销售抽点+系统抽点 | |||
| int systemCommission = serviceFeeService.getSystemCommissionByOrder(wxComposeChildOrderShare.getOrderId(), payAccount); | |||
| int sellCommission = serviceFeeService.getSellCommission(payAccount); | |||
| int selSysAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), systemCommission+sellCommission, false); | |||
| //销售抽点 | |||
| int sellerAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), sellCommission, false); | |||
| wxComposeChildOrderShare.setSellerAmount(sellerAmount); | |||
| boolean isSeller = false; | |||
| if(sellerAmount > 0){ | |||
| WxProfitSharingReceiver receiver = getByMerchantAdmin(sharingOrder,payShareAdapterService,wxComposeChildOrderShare.getMerchantId(),EnumMerchantAdmin.PRIVATE_SELL,payOrder.getTtPayWay(), payOrder.getMchType()); | |||
| if(receiver != null){ | |||
| try{ | |||
| //处理所有的佣金 | |||
| boolean flag = serviceFeeService.handleShareServiceAmount(cAppInfo, payAccount, payOrder,wxComposeChildOrderShare); | |||
| if(!flag){ | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"未获取到服务费"); | |||
| } | |||
| //微信缺少流程(分账帐号绑定) 无法抽成 | |||
| if(EnumYesOrNo.YES.getCode().equals(payAccount.getIsCommission())){ | |||
| //系统 | |||
| if(wxComposeChildOrderShare.getSystemAmount() > 0){ | |||
| WxProfitSharingReceiver receiver = getByMerchantAdmin(sharingOrder,payShareAdapterService,wxComposeChildOrderShare.getMerchantId(),EnumMerchantAdmin.PRIVATE_SYSTEM,payOrder.getTtPayWay(), payOrder.getMchType()); | |||
| if(receiver == null){ | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"未获取到系统帐号2"); | |||
| } | |||
| JSONObject jo = new JSONObject(); | |||
| jo.put("type",EnumProfitPaymentReceiverType.getEnum(receiver.getReceiverType()).getMessage()); | |||
| jo.put("account",receiver.getReceiverAccount()); | |||
| jo.put("amount", sellerAmount); | |||
| jo.put("amount", wxComposeChildOrderShare.getSystemAmount()); | |||
| jo.put("merchantId",receiver.getMerchantId()); | |||
| jo.put("bTenantId",receiver.getTenantId()); | |||
| jo.put("description",receiver.getId()); | |||
| jo.put("isPrivate",EnumYesOrNo.YES.getCode()); | |||
| receivers.add(jo); | |||
| }else{ | |||
| isSeller = true; | |||
| } | |||
| } | |||
| //系统抽成 | |||
| // int systemAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), payAccount.getSystemRate(), false); | |||
| int systemAmount = selSysAmount - sellerAmount; | |||
| wxComposeChildOrderShare.setSystemAmount(systemAmount); | |||
| if(isSeller){//未找到销售帐号时转入到系统帐号中 | |||
| systemAmount += sellerAmount; | |||
| } | |||
| boolean isSystem = false; | |||
| if(systemAmount > 0){ | |||
| WxProfitSharingReceiver receiver = getByMerchantAdmin(sharingOrder,payShareAdapterService,wxComposeChildOrderShare.getMerchantId(),EnumMerchantAdmin.PRIVATE_SYSTEM,payOrder.getTtPayWay(), payOrder.getMchType()); | |||
| if(receiver != null){ | |||
| //销售 | |||
| if(wxComposeChildOrderShare.getSellerAmount() > 0){ | |||
| WxProfitSharingReceiver receiver = getByMerchantAdmin(sharingOrder,payShareAdapterService,wxComposeChildOrderShare.getMerchantId(),EnumMerchantAdmin.PRIVATE_SELL,payOrder.getTtPayWay(), payOrder.getMchType()); | |||
| if(receiver == null){ | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"未获取到系统帐号3"); | |||
| } | |||
| JSONObject jo = new JSONObject(); | |||
| jo.put("type",EnumProfitPaymentReceiverType.getEnum(receiver.getReceiverType()).getMessage()); | |||
| jo.put("account",receiver.getReceiverAccount()); | |||
| jo.put("amount", systemAmount); | |||
| jo.put("amount", wxComposeChildOrderShare.getSellerAmount()); | |||
| jo.put("merchantId",receiver.getMerchantId()); | |||
| jo.put("bTenantId",receiver.getTenantId()); | |||
| jo.put("description",receiver.getId()); | |||
| jo.put("isPrivate",EnumYesOrNo.YES.getCode()); | |||
| receivers.add(jo); | |||
| }else{ | |||
| isSystem = true; | |||
| } | |||
| } | |||
| //总分佣 | |||
| int mallRate = getMallSumRate(payOrder,wxComposeChildOrderShare.getOrderId()); | |||
| int serviceAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), mallRate, true); | |||
| wxComposeChildOrderShare.setServiceAmount(serviceAmount); | |||
| //商场分成 | |||
| int mallAmount = wxComposeChildOrderShare.getRateAmount(); | |||
| if(isSystem){//未找到系统帐号时转入商管商户中 | |||
| mallAmount += systemAmount; | |||
| } | |||
| boolean isMall = false; | |||
| if(mallAmount > 0){ | |||
| WxProfitSharingReceiver receiver = getByMerchantAdmin(sharingOrder,payShareAdapterService,wxComposeChildOrderShare.getMerchantId(),EnumMerchantAdmin.PUBLIC_ADMIN,payOrder.getTtPayWay(), payOrder.getMchType()); | |||
| if(receiver != null){ | |||
| //商管 | |||
| if(wxComposeChildOrderShare.getRateAmount() > 0){ | |||
| WxProfitSharingReceiver receiver = getByMerchantAdmin(sharingOrder,payShareAdapterService,wxComposeChildOrderShare.getMerchantId(),EnumMerchantAdmin.PUBLIC_ADMIN,payOrder.getTtPayWay(), payOrder.getMchType()); | |||
| if(receiver == null){ | |||
| throw new MallinkException(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"未获取到商管帐号"); | |||
| } | |||
| JSONObject jo = new JSONObject(); | |||
| jo.put("type",EnumProfitPaymentReceiverType.getEnum(receiver.getReceiverType()).getMessage()); | |||
| jo.put("account",receiver.getReceiverAccount()); | |||
| jo.put("amount", mallAmount); | |||
| jo.put("amount", wxComposeChildOrderShare.getRateAmount()); | |||
| jo.put("merchantId",receiver.getMerchantId()); | |||
| jo.put("bTenantId",receiver.getTenantId()); | |||
| jo.put("description",receiver.getId()); | |||
| jo.put("isPrivate",EnumYesOrNo.YES.getCode()); | |||
| receivers.add(jo); | |||
| }else{ | |||
| isMall = true; | |||
| } | |||
| } | |||
| if(isMall){ | |||
| surplus += mallAmount; | |||
| } | |||
| }else{ | |||
| wxComposeChildOrderShare.setServiceAmount(null); | |||
| }catch(Exception e){ | |||
| WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); | |||
| updSharingOrder.updateTenantInfo(sharingOrder); | |||
| updSharingOrder.setId(sharingOrder.getId()); | |||
| updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); | |||
| updSharingOrder.setErrorMsg(e.getMessage()); | |||
| updSharingOrder.setUpdateTime(currentDate); | |||
| wxProfitSharingOrderMapper.updateById(updSharingOrder); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),e.getMessage()); | |||
| } | |||
| //商户所得 | |||
| int shareAmount = wxComposeChildOrderShare.getShareAmount(); | |||
| boolean isCallSharing = false;//是否调用分账 | |||
| boolean isCreateSubsidy = false;//是否需要记账 | |||
| boolean isSharingResult = false;//是否需要记录Result | |||
| boolean isSharingResult = false;//是否需要记录Result 解冻给收款方 | |||
| if(EnumPayWay.PAY_WAY_WECHAT.getCode().equals(payOrder.getPayVendor()) | |||
| && DateUtils.daysBetween(payOrder.getCreateTime(),currentDate) > 30){ | |||
| isCallSharing = false; | |||
| if(EnumPayShare.YES.getCode().equals(payOrder.getShare())){ | |||
| if(!sharingOrder.getMerchantId().equals(wxComposeChildOrderShare.getMerchantId())){ | |||
| isCreateSubsidy = true; | |||
| } | |||
| isSharingResult = true; | |||
| @@ -356,9 +300,11 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| receivers.add(jo); | |||
| }else if(EnumPayMchType.DIRECT.getCode().equals(payOrder.getMchType()) | |||
| && !sharingOrder.getMerchantId().equals(wxComposeChildOrderShare.getMerchantId())){ | |||
| //微信 直连 多商户 分不了账 记账 | |||
| isCreateSubsidy = true; | |||
| isSharingResult = true; | |||
| }else{ | |||
| //总分不分账 已经记过账了 | |||
| isSharingResult = true; | |||
| } | |||
| } | |||
| @@ -413,7 +359,6 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| if(isCreateSubsidy){ | |||
| try { | |||
| // 微信超过30天无法分账的, | |||
| WxOrder order = wxOrderMapper.selectById(sharingOrder.getSingleOrderId(), sharingOrder.getTenantId()); | |||
| wxCouponOrderService.recordAfterVerified(order, merchant); | |||
| } catch (Exception e) { | |||
| @@ -422,13 +367,12 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| } | |||
| if(isSharingResult){ | |||
| int sharingSubsidyAmount = shareAmount+surplus; | |||
| if(EnumPayMchType.TOTAL.getCode().equals(payOrder.getMchType())){ | |||
| //解冻给收款方(广场) +抽成没抽过去的。surplus | |||
| JSONObject jo = new JSONObject(); | |||
| // jo.put("type",EnumProfitPaymentReceiverType.wx_special_merchant_number.getMessage()); | |||
| jo.put("account",payAccount.getSubMchId()); | |||
| jo.put("amount", sharingSubsidyAmount); | |||
| jo.put("amount", shareAmount); | |||
| jo.put("merchantId",0); | |||
| jo.put("bTenantId",payOrder.getTenantId()); | |||
| jo.put("description",0); | |||
| @@ -440,13 +384,13 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| if(receiver != null && receiver.getReceiverAccount().equals(wxComposeChildOrderShare.getMerchantUid())){ | |||
| jo.put("type",EnumProfitPaymentReceiverType.getEnum(receiver.getReceiverType()).getMessage()); | |||
| jo.put("account",receiver.getReceiverAccount()); | |||
| jo.put("amount", sharingSubsidyAmount); | |||
| jo.put("amount", shareAmount); | |||
| jo.put("merchantId",receiver.getMerchantId()); | |||
| jo.put("bTenantId",receiver.getTenantId()); | |||
| jo.put("description",receiver.getId()); | |||
| }else{ | |||
| jo.put("account",wxComposeChildOrderShare.getMerchantUid()); | |||
| jo.put("amount", sharingSubsidyAmount); | |||
| jo.put("amount", shareAmount); | |||
| jo.put("merchantId",wxComposeChildOrderShare.getMerchantId()); | |||
| jo.put("bTenantId",payOrder.getTenantId()); | |||
| jo.put("description",0); | |||
| @@ -72,30 +72,36 @@ public class WxComposeChildOrderShare { | |||
| private String merchantUid;//收款商户 | |||
| public void setServiceAmount(Integer serviceAmount){ | |||
| if(this.realPayMent == null){ | |||
| return; | |||
| } | |||
| if(this.realRateAmount == null){ | |||
| return; | |||
| } | |||
| int sumAmount = this.realRateAmount.intValue();//支付通道费 | |||
| int sumAmount = 0; | |||
| if(this.realRateAmount != null){ | |||
| sumAmount += this.realRateAmount;//支付通道费 | |||
| } | |||
| if(this.commissionAmount != null){ | |||
| sumAmount += this.commissionAmount.intValue();//平台服务费 | |||
| sumAmount += this.commissionAmount;//平台服务费 | |||
| } | |||
| if(this.cpsCommission != null){ | |||
| sumAmount += this.cpsCommission.intValue();//达人佣金 | |||
| } | |||
| if(this.systemAmount != null){ | |||
| sumAmount += this.systemAmount;//系统扣点 | |||
| sumAmount += this.cpsCommission;//达人佣金 | |||
| } | |||
| if(this.sellerAmount != null){ | |||
| sumAmount += this.sellerAmount;//销售扣点 | |||
| } | |||
| if(this.systemAmount != null){ | |||
| sumAmount += this.systemAmount;//系统扣点 | |||
| } | |||
| if(serviceAmount == null || serviceAmount.intValue() < sumAmount){ | |||
| if(serviceAmount == null || serviceAmount < sumAmount){ | |||
| this.serviceAmount = sumAmount; | |||
| }else{ | |||
| this.serviceAmount = serviceAmount;//一笔订单总扣除手续费 | |||
| } | |||
| this.rateAmount = this.serviceAmount.intValue() - sumAmount;//剩下的就是给商场的 | |||
| this.shareAmount = this.realPayMent.intValue() - this.serviceAmount.intValue();//这就是给商户的 | |||
| this.rateAmount = this.serviceAmount - sumAmount;//剩下的就是给商场的 | |||
| this.shareAmount = this.realPayMent - this.serviceAmount;//这就是给商户的 | |||
| } | |||
| } | |||
| @@ -3,7 +3,9 @@ package com.iformall.service.pay.service.fee; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxCashOut; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.service.order.entity.WxComposeChildOrderShare; | |||
| import com.iformall.service.pay.service.cashout.entity.CashOutAdapterResult; | |||
| /** | |||
| @@ -49,7 +51,10 @@ public interface ServiceFeeAdapterService { | |||
| * 获取所有的总抽佣费率 | |||
| * 如过设置了就返回,没设置返回0 | |||
| */ | |||
| public int getAllCommission(Long couponId, WxPayAccount payAccount); | |||
| public int getAllCommission(TenantEntity tenantEntity, Long orderId); | |||
| boolean handleShareServiceAmount(WxAppinfo cAppInfo, WxPayAccount payAccount, WxPayOrder payOrder, WxComposeChildOrderShare wxComposeChildOrderShare); | |||
| /** | |||
| * 获取商场抽佣费率 | |||
| @@ -1,11 +1,10 @@ | |||
| package com.iformall.service.pay.service.fee; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.TtPoiTakeRate; | |||
| import com.iformall.domain.po.WxMallVersion; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.douyin.pay.DouYinPayHelper; | |||
| import com.iformall.douyin.pay.orderQuery.QueryUnsettleAmount; | |||
| import com.iformall.enums.EnumCpsPlanType; | |||
| import com.iformall.enums.EnumDouyinApplicationVersion; | |||
| import com.iformall.enums.EnumOrderType; | |||
| @@ -19,6 +18,8 @@ import com.iformall.service.TtMallGoodsCategoryService; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.WxMallService; | |||
| import com.iformall.service.order.entity.WxComposeChildOrderShare; | |||
| import com.iformall.utils.PayUtils; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.context.annotation.Lazy; | |||
| @@ -104,16 +105,45 @@ public class TtServiceFeeService implements ServiceFeeAdapterService{ | |||
| // } | |||
| @Override | |||
| public int getAllCommission(Long couponId, WxPayAccount payAccount) { | |||
| int allRate = 0; | |||
| if(EnumYesOrNo.YES.getCode().equals(payAccount.getIsCommission())){ | |||
| TtPoiTakeRate ttPoiTakeRate = ttPoiTakeRateMapper.selectByCoupon(payAccount.getTenantId(), couponId, EnumCpsPlanType.ALL.getCode()); | |||
| if(ttPoiTakeRate != null && ttPoiTakeRate.getTakeRate() != null){ | |||
| allRate = ttPoiTakeRate.getTakeRate().intValue(); | |||
| } | |||
| public int getAllCommission(TenantEntity tenantEntity, Long orderId) { | |||
| WxOrder o = wxOrderMapper.selectById(orderId, tenantEntity.getTenantId()); | |||
| if(!EnumOrderType.COUPON.getCode().equals(o.getType())){ | |||
| return 0; | |||
| } | |||
| TtPoiTakeRate ttPoiTakeRate = ttPoiTakeRateMapper.selectByCoupon(tenantEntity.getTenantId(), o.getProductId(), EnumCpsPlanType.ALL.getCode()); | |||
| if(ttPoiTakeRate != null){ | |||
| return ttPoiTakeRate.getTakeRate(); | |||
| }else{ | |||
| return 0; | |||
| } | |||
| } | |||
| return allRate; | |||
| @Override | |||
| public boolean handleShareServiceAmount(WxAppinfo cAppInfo, WxPayAccount payAccount,WxPayOrder payOrder, WxComposeChildOrderShare wxComposeChildOrderShare) { | |||
| QueryUnsettleAmount queryUnsettleAmount = DouYinPayHelper.unsettleAmount(cAppInfo.getAppId(), payAccount.getMerchantApiKey(), payOrder.getOrderId().toString(), null); | |||
| if(queryUnsettleAmount == null){ | |||
| return false; | |||
| } | |||
| wxComposeChildOrderShare.setRealRateAmount(queryUnsettleAmount.getPaymentRake()); | |||
| wxComposeChildOrderShare.setCommissionAmount(queryUnsettleAmount.getLifeRake()); | |||
| wxComposeChildOrderShare.setCpsCommission(queryUnsettleAmount.getCommission()); | |||
| //销售 | |||
| int sellCommission = getSellCommission(payAccount); | |||
| int sellerAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), sellCommission, false); | |||
| wxComposeChildOrderShare.setSellerAmount(sellerAmount); | |||
| //系统 先计算销售+系统 然后再减去销售 | |||
| int systemCommission = getSystemCommission(null, payAccount); | |||
| int selSysAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), systemCommission+sellCommission, false); | |||
| int systemAmount = selSysAmount - sellerAmount; | |||
| wxComposeChildOrderShare.setSystemAmount(systemAmount); | |||
| //商品设置的总分佣率 | |||
| int allCommission = getAllCommission(payAccount,wxComposeChildOrderShare.getOrderId()); | |||
| int serviceAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), allCommission, true); | |||
| wxComposeChildOrderShare.setServiceAmount(serviceAmount); | |||
| return true; | |||
| } | |||
| // @Override | |||
| @@ -1,35 +1,13 @@ | |||
| package com.iformall.service.pay.service.fee; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxAppinfoMapper; | |||
| import com.iformall.mapper.WxPayAccountMapper; | |||
| import com.iformall.mapper.WxPayOrderMapper; | |||
| import com.iformall.pay.*; | |||
| import com.iformall.service.WxProfitPaymentReceiverService; | |||
| import com.iformall.service.WxProfitSharingReceiverService; | |||
| import com.iformall.service.pay.service.share.PayShareBaseAdapterService; | |||
| import com.iformall.service.pay.service.share.entity.PayShareQueryResult; | |||
| import com.iformall.service.pay.service.share.entity.PayShareResult; | |||
| import com.iformall.service.pay.service.share.entity.ShareAccountResult; | |||
| import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; | |||
| import com.iformall.utils.BeanUtils; | |||
| import com.iformall.utils.Utility; | |||
| import com.iformall.utils.XmlUtil; | |||
| import com.iformall.service.order.entity.WxComposeChildOrderShare; | |||
| import com.iformall.utils.PayUtils; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.text.ParseException; | |||
| import java.util.*; | |||
| @Slf4j | |||
| @Service | |||
| public class WxServiceFeeService implements ServiceFeeAdapterService{ | |||
| @@ -87,12 +65,40 @@ public class WxServiceFeeService implements ServiceFeeAdapterService{ | |||
| // } | |||
| @Override | |||
| public int getAllCommission(Long couponId, WxPayAccount payAccount) { | |||
| public int getAllCommission(TenantEntity tenantEntity, Long orderId) { | |||
| return 0; | |||
| } | |||
| @Override | |||
| public boolean handleShareServiceAmount(WxAppinfo cAppInfo, WxPayAccount payAccount, WxPayOrder payOrder, WxComposeChildOrderShare wxComposeChildOrderShare) { | |||
| int realRate = getRealRate(payAccount); | |||
| int payRate = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), realRate, true); | |||
| wxComposeChildOrderShare.setRealRateAmount(payRate); | |||
| wxComposeChildOrderShare.setCommissionAmount(0); | |||
| wxComposeChildOrderShare.setCpsCommission(0); | |||
| //销售 | |||
| int sellCommission = getSellCommission(payAccount); | |||
| int sellerAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), sellCommission, false); | |||
| wxComposeChildOrderShare.setSellerAmount(sellerAmount); | |||
| //系统 先计算销售+系统 然后再减去销售 | |||
| int systemCommission = getSystemCommission(null, payAccount); | |||
| int selSysAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), systemCommission+sellCommission, false); | |||
| int systemAmount = selSysAmount - sellerAmount; | |||
| wxComposeChildOrderShare.setSystemAmount(systemAmount); | |||
| //商品设置的总分佣率 | |||
| int allCommission = getAllCommission(payAccount,wxComposeChildOrderShare.getOrderId()); | |||
| int serviceAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), allCommission, true); | |||
| wxComposeChildOrderShare.setServiceAmount(serviceAmount); | |||
| return true; | |||
| } | |||
| // @Override | |||
| // public int getMallCommission(Long couponId, WxPayAccount payAccount) { | |||
| // return 0; | |||
| // } | |||
| } | |||
| @@ -22,7 +22,7 @@ public class PayUtils { | |||
| Double dBaseAmount = 5.0D * 1000 / rate; | |||
| // 基础分 千分之6 83分 | |||
| if (isReal) { | |||
| // 小于基础分,四舍五入 | |||
| //四舍五入 | |||
| Double dPayRate = 1.0D * payAmount * rate / 10000; | |||
| long dChargeFee = Math.round(dPayRate); | |||
| return Long.valueOf(dChargeFee).intValue(); | |||
| @@ -85,6 +85,13 @@ | |||
| and `reservation_merchant_id` = #{reservationMerchantId} | |||
| </if> | |||
| <if test=" null != reservationMerchantIdList and reservationMerchantIdList.size > 0 "> | |||
| and `reservation_merchant_id` in | |||
| <foreach collection="reservationMerchantIdList" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != reservationMerchantName and '' != reservationMerchantName"> | |||
| and `reservation_merchant_name` like concat('%', #{reservationMerchantName},'%') | |||
| </if> | |||
| @@ -99,6 +106,12 @@ | |||
| <if test=" null != status "> | |||
| and `status` = #{status} | |||
| </if> | |||
| <if test=" null != statusList and statusList.size > 0 "> | |||
| and `status` in | |||
| <foreach collection="statusList" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != btenantId and '' != btenantId"> | |||
| and `btenant_id` = #{btenantId} | |||
| @@ -157,13 +170,13 @@ | |||
| </select> | |||
| <select id="getSortById" parameterType="java.util.HashMap" resultMap="BaseResultMap"> | |||
| select `id`,`tenant_id`,`parent_tenant_id`,`reservation_merchant_id`,`status` | |||
| select `id`,`tenant_id`,`parent_tenant_id`,`coupon_order_id`,`reservation_merchant_id`,`status` | |||
| from wx_coupon_order_reservation | |||
| where `id` = #{id} and tenant_id=#{tenantId} | |||
| </select> | |||
| <select id="getSortByCouponOrder" parameterType="java.util.HashMap" resultMap="BaseResultMap"> | |||
| select `id`,`tenant_id`,`parent_tenant_id`,`reservation_merchant_id`,`status` | |||
| select `id`,`tenant_id`,`parent_tenant_id`,`coupon_order_id`,`reservation_merchant_id`,`status` | |||
| from wx_coupon_order_reservation | |||
| where `coupon_order_id` = #{couponOrderId} and tenant_id=#{tenantId} | |||
| </select> | |||
| @@ -180,6 +180,12 @@ | |||
| #{notInIdItem} | |||
| </foreach> | |||
| </if> | |||
| <if test="merchantIds != null and merchantIds.size > 0"> | |||
| and m.id NOT IN | |||
| <foreach collection="merchantIds" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != sortColumns">order by ${sortColumns}</if> | |||
| </sql> | |||
| @@ -453,7 +459,8 @@ | |||
| <select id="getMerchantListByIds" resultType="com.iformall.domain.po.WxMerchant"> | |||
| select <include refid="allColumns"/> | |||
| from wx_merchant m | |||
| where m.is_del=0 and m.is_admin=4 | |||
| where m.is_del=0 | |||
| <!-- and m.is_admin=0 --> | |||
| <if test="relationIds != null and relationIds.size > 0"> | |||
| and m.id in | |||
| <foreach collection="relationIds" index="index" item="idItem" open="(" separator="," close=")"> | |||
| @@ -462,16 +469,4 @@ | |||
| </if> | |||
| </select> | |||
| <select id="getSubMerchantListByIds" resultType="com.iformall.domain.po.WxMerchant"> | |||
| select <include refid="allColumns"/> | |||
| from wx_merchant m | |||
| where m.is_del=0 and m.is_admin=4 | |||
| <if test="merchantIds != null and merchantIds.size > 0"> | |||
| and m.id NOT IN | |||
| <foreach collection="merchantIds" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| </select> | |||
| </mapper> | |||
| @@ -17,16 +17,6 @@ | |||
| `id`,`tenant_id`,`parent_tenant_id`,`merchant_id`,`region_merchant_id`,`is_del`,`create_date`,`update_date` | |||
| </sql> | |||
| <select id="selectByIds" resultType="java.lang.Integer"> | |||
| select | |||
| count(1) | |||
| from wx_merchant_relation | |||
| where is_del = 0 and merchant_id not in | |||
| <foreach collection="ids" index="index" item="id" open="(" separator="," close=")"> | |||
| #{id} | |||
| </foreach> | |||
| </select> | |||
| <update id="updateByReginId"> | |||
| update wx_merchant_relation | |||
| set is_del = 1, update_date = now() | |||
| @@ -34,13 +24,14 @@ | |||
| </update> | |||
| <insert id="insertBatch" parameterType="java.util.List"> | |||
| insert into wx_merchant_relation (id, tenant_id,merchant_id,region_merchant_id ) | |||
| insert into wx_merchant_relation (id, tenant_id,merchant_id,region_merchant_id,parent_tenant_id) | |||
| values | |||
| <foreach collection="list" item="item" index="index" separator=","> | |||
| (#{item.id}, | |||
| #{item.tenantId}, | |||
| #{item.merchantId}, | |||
| #{item.regionMerchantId}) | |||
| #{item.regionMerchantId}, | |||
| #{item.parentTenantId}) | |||
| </foreach> | |||
| </insert> | |||
| @@ -58,7 +49,7 @@ | |||
| update wx_merchant_relation | |||
| set is_del = 0, | |||
| update_date = now() | |||
| where merchant_id in | |||
| where region_merchant_id = #{regionId} and merchant_id in | |||
| <foreach collection="merchantIds" index="index" item="id" open="(" separator="," close=")"> | |||
| #{id} | |||
| </foreach> | |||