| @@ -571,7 +571,7 @@ public class WxCouponController extends BaseController { | |||
| return new ResultData(wxCouponMallService.list(wxCouponMall)); | |||
| } | |||
| @ApiOperation("商场查询:平台券列表") | |||
| @ApiOperation("商场查询:平台券商场列表") | |||
| @GetMapping("/couponMalls") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "ids", value = "ids[]", dataType = "Long", paramType = "query", required = true)}) | |||
| @@ -612,5 +612,57 @@ public class WxCouponController extends BaseController { | |||
| } | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("券商户是否自动分账") | |||
| @PostMapping("/couponMerchantAutoShare") | |||
| public ResultData couponMerchantAutoShare(@RequestBody WxCoupon wxCoupon) { | |||
| wxCoupon.updateTenantInfo(getTenantInfo()); | |||
| try { | |||
| Map<Long, Boolean> map = wxCouponService.couponMerchantAutoShare(wxCoupon); | |||
| return new ResultData(map); | |||
| } catch (Exception e) { | |||
| return new ResultData(Result.ERROR,e.getMessage()); | |||
| } | |||
| } | |||
| @ApiOperation("商场设置平台券已完成") | |||
| @PostMapping("/setPlatCouponFinished") | |||
| public ResultData setPlatCouponFinished(@RequestBody WxCoupon wxCoupon) { | |||
| try { | |||
| TenantEntity tenantEntity = getTenantInfo(); | |||
| String mallTenantId = tenantEntity.getTenantId(); | |||
| String tenantId = tenantEntity.getTenantId(); | |||
| if (null != tenantEntity.getParentTenantId()) { | |||
| tenantId = tenantEntity.getParentTenantId(); | |||
| } | |||
| wxCouponMallService.finised(tenantId, wxCoupon.getId(), mallTenantId); | |||
| return new ResultData(); | |||
| } catch (Exception e) { | |||
| return new ResultData(Result.ERROR,e.getMessage()); | |||
| } | |||
| } | |||
| @ApiOperation("商场设置平台券已完成") | |||
| @PostMapping("/setPlatCouponUnFinished") | |||
| public ResultData setPlatCouponUnFinished(@RequestBody WxCoupon wxCoupon) { | |||
| try { | |||
| if (null == wxCoupon.getType()) { | |||
| return new ResultData(Result.ERROR,"缺少参数"); | |||
| } | |||
| TenantEntity tenantEntity = getTenantInfo(); | |||
| String mallTenantId = tenantEntity.getTenantId(); | |||
| String tenantId = tenantEntity.getTenantId(); | |||
| if (null != tenantEntity.getParentTenantId()) { | |||
| tenantId = tenantEntity.getParentTenantId(); | |||
| } | |||
| wxCouponMallService.unfinised(tenantId, wxCoupon.getId(),wxCoupon.getType(), mallTenantId); | |||
| return new ResultData(); | |||
| } catch (Exception e) { | |||
| return new ResultData(Result.ERROR,e.getMessage()); | |||
| } | |||
| } | |||
| } | |||
| @@ -32,7 +32,7 @@ public class TtCouponChannelPoi extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="描述",name="statusDesc") | |||
| private String statusDesc; | |||
| @io.swagger.annotations.ApiModelProperty(value="状态:0-审核中,1-上架,2-下架,3-审核拒绝 4-审核通过",name="lastStatus") | |||
| @io.swagger.annotations.ApiModelProperty(value="EnumSpuSyncStatus状态:0-审核中,1-上架,2-下架,3-审核拒绝 4-审核通过",name="lastStatus") | |||
| private Integer lastStatus; | |||
| @io.swagger.annotations.ApiModelProperty(value="描述",name="lastStatusDesc") | |||
| @@ -388,6 +388,9 @@ public class WxCoupon extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value = "是否删除1是0否", name = "isDel") | |||
| private Integer isDel; | |||
| @TableField(exist = false) | |||
| private Long[] merchantIds; | |||
| public String getSalePriceStr() { | |||
| if(salePrice!=null) { | |||
| @@ -0,0 +1,36 @@ | |||
| package com.iformall.enums; | |||
| /** | |||
| * Created by Stormeye on 2018/08/09. | |||
| */ | |||
| public enum EnumCouponMallStatus { | |||
| UNFINISED(0, "未设置完成"), | |||
| FINISED(1, "已设置完成") | |||
| ; | |||
| public static EnumCouponMallStatus getEnum(Integer code) { | |||
| for (EnumCouponMallStatus value : values()) { | |||
| if (value.getCode().equals(code)) { | |||
| return value; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| private Integer code; | |||
| private String message; | |||
| EnumCouponMallStatus(Integer code, String message) { | |||
| this.code = code; | |||
| this.message = message; | |||
| } | |||
| public Integer getCode() { | |||
| return code; | |||
| } | |||
| public String getMessage() { | |||
| return message; | |||
| } | |||
| } | |||
| @@ -38,4 +38,15 @@ public enum EnumSpuSyncStatus { | |||
| public String getMessage() { | |||
| return message; | |||
| } | |||
| public static boolean isValid(Integer code) { | |||
| if (code == sync_auditing.getCode()) { | |||
| return true; | |||
| }else if (code == sync_put_on.getCode()) { | |||
| return true; | |||
| }else if (code == sync_audit_pass.getCode()) { | |||
| return true; | |||
| } | |||
| return false; | |||
| } | |||
| } | |||
| @@ -3,6 +3,7 @@ package com.iformall.mapper; | |||
| import com.iformall.common.CommonMapper; | |||
| import com.iformall.domain.po.WxCouponMall; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @@ -11,6 +12,6 @@ import org.apache.ibatis.annotations.Param; | |||
| public interface WxCouponMallMapper extends CommonMapper<WxCouponMall, Long> { | |||
| List<WxCouponMall> findList(WxCouponMall wxCouponMerchant); | |||
| List<WxCouponMall> findMerchantListByProduct(@Param("productId")Long productId,@Param("tenantId")String tenantId); | |||
| List<WxCouponMall> findList(WxCouponMall wxCouponMall); | |||
| void updateStatus(WxCouponMall wxCouponMall); | |||
| } | |||
| @@ -24,4 +24,7 @@ public interface WxCouponMallService { | |||
| List<WxCouponMall> list(WxCouponMall wxCouponMall); | |||
| void finised(String tenantId,Long couponId,String mallTenantId); | |||
| void unfinised(String tenantId, Long couponId,Integer couponType, String mallTenantId) throws Exception; | |||
| } | |||
| @@ -289,4 +289,6 @@ public interface WxCouponService { | |||
| ResultData disable(TenantEntity tenantInfo, Long couponId); | |||
| void setCouponMerchants(WxCoupon wxCoupon) throws Exception; | |||
| Map<Long,Boolean> couponMerchantAutoShare(WxCoupon wxCoupon) throws Exception; | |||
| } | |||
| @@ -2,7 +2,15 @@ package com.iformall.service.impl; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumAppPlat; | |||
| import com.iformall.enums.EnumCouponChannelStatus; | |||
| import com.iformall.enums.EnumCouponMallStatus; | |||
| import com.iformall.enums.EnumCouponType; | |||
| import com.iformall.enums.EnumSpuSyncStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.*; | |||
| import org.slf4j.Logger; | |||
| @@ -17,6 +25,10 @@ public class WxCouponMallServiceImpl implements WxCouponMallService { | |||
| @Autowired | |||
| WxCouponMallMapper wxCouponMallMapper; | |||
| @Autowired | |||
| TtCouponChannelPoiMapper ttCouponChannelPoiMapper; | |||
| @Autowired | |||
| WxCouponChannelMapper wxCouponChannelMapper; | |||
| @Override | |||
| public List<WxCouponMall> list(WxCouponMall wxCouponMall){ | |||
| @@ -28,4 +40,40 @@ public class WxCouponMallServiceImpl implements WxCouponMallService { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponMallMapper.findList(record)); | |||
| } | |||
| @Override | |||
| public void finised(String tenantId, Long couponId, String mallTenantId) { | |||
| WxCouponMall couponMall = new WxCouponMall(); | |||
| couponMall.setTenantId(tenantId); | |||
| couponMall.setMallTenantId(mallTenantId); | |||
| couponMall.setProductId(couponId); | |||
| couponMall.setStatus(EnumCouponMallStatus.FINISED.getCode()); | |||
| wxCouponMallMapper.updateStatus(couponMall); | |||
| } | |||
| @Override | |||
| public void unfinised(String tenantId, Long couponId,Integer couponType, String mallTenantId) throws Exception{ | |||
| //抖音平台查询的是未提交抖音审核的,微信是未上架的 | |||
| EnumAppPlat plat = EnumCouponType.getAppPlat(couponType); | |||
| if (plat == EnumAppPlat.TOUTIAO) { | |||
| TtCouponChannelPoi poi = ttCouponChannelPoiMapper.selectById(tenantId, couponId); | |||
| if (null != poi &&( EnumSpuSyncStatus.isValid(poi.getLastStatus()))) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"券已在抖音审核流程中,无法修改。"); | |||
| } | |||
| }else if (plat == EnumAppPlat.WX) { | |||
| WxCouponChannel couponChannel = new WxCouponChannel(); | |||
| couponChannel.setTenantId(tenantId); | |||
| couponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); | |||
| List<WxCouponChannel> clist = wxCouponChannelMapper.findList(couponChannel); | |||
| if (null != clist && clist.size() > 0 ) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"券已投放且上架,无法修改。"); | |||
| } | |||
| } | |||
| WxCouponMall couponMall = new WxCouponMall(); | |||
| couponMall.setTenantId(tenantId); | |||
| couponMall.setMallTenantId(mallTenantId); | |||
| couponMall.setProductId(couponId); | |||
| couponMall.setStatus(EnumCouponMallStatus.UNFINISED.getCode()); | |||
| wxCouponMallMapper.updateStatus(couponMall); | |||
| } | |||
| } | |||
| @@ -709,46 +709,29 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| if (receiver == null) { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); | |||
| } | |||
| //如果是直连,抖音,多商户券必须只配置支付宝 | |||
| if (EnumAppPlat.TOUTIAO.equals(plat)) { | |||
| if (!MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())) { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); | |||
| } | |||
| if (merchantList.size() > 1 ) { | |||
| if (MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) && | |||
| !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) ) { | |||
| }else { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]配置收款账户错误,多商户券主收款账户不能配置微信."); | |||
| } | |||
| }else { | |||
| if (!MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())) { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); | |||
| } | |||
| } | |||
| } | |||
| } else if (EnumPayShare.YES.equals(isShare)) { | |||
| List<String> badNames = new ArrayList(); | |||
| for (WxMerchant merchant:merchantList) { | |||
| WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchant.getId(), null, payMchType.getCode()); | |||
| if (receiver == null) { | |||
| badNames.add(merchant.getName()); | |||
| continue; | |||
| } | |||
| if (EnumAppPlat.TOUTIAO.equals(plat)) { | |||
| QueryMerchantResult openPayResult = payAccount.getOpenPayResult(); | |||
| if(!EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) | |||
| && !EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) | |||
| && !EnumYesOrNo.YES.getCode().equals(openPayResult.getHz())){ | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "分账模式未设置开通支付渠道"); | |||
| } | |||
| if(EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())){ | |||
| badNames.add(merchant.getName()); | |||
| continue; | |||
| } | |||
| if(EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus())){ | |||
| badNames.add(merchant.getName()); | |||
| continue; | |||
| } | |||
| if(EnumYesOrNo.YES.getCode().equals(openPayResult.getHz()) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())){ | |||
| badNames.add(merchant.getName()); | |||
| continue; | |||
| } | |||
| } | |||
| boolean isBad = toTalPayMchTypeMerchantIsBad(payShareServie,payAccount,merchant.getName(),merchant.getId(),payMchType,plat); | |||
| if (isBad) { | |||
| badNames.add(merchant.getName()); | |||
| } | |||
| } | |||
| if(!badNames.isEmpty()){ | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), JSONArray.toJSONString(badNames)+"未配置分账账户"); | |||
| @@ -757,6 +740,37 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| } | |||
| return merchantList; | |||
| } | |||
| //总分模式下不能分账的商户 | |||
| private boolean toTalPayMchTypeMerchantIsBad(PayShareAdapterService payShareServie,WxPayAccount payAccount, | |||
| String merchantName,Long merchantId,EnumPayMchType payMchType,EnumAppPlat plat) throws Exception { | |||
| WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchantId, null, payMchType.getCode()); | |||
| if (receiver == null) { | |||
| return true; | |||
| } | |||
| if (EnumAppPlat.TOUTIAO.equals(plat)) { | |||
| QueryMerchantResult openPayResult = payAccount.getOpenPayResult(); | |||
| if(!EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) | |||
| && !EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) | |||
| && !EnumYesOrNo.YES.getCode().equals(openPayResult.getHz())){ | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "分账模式未设置开通支付渠道"); | |||
| } | |||
| if(EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())){ | |||
| return true; | |||
| } | |||
| if(EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus())){ | |||
| return true; | |||
| } | |||
| if(EnumYesOrNo.YES.getCode().equals(openPayResult.getHz()) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())){ | |||
| return true; | |||
| } | |||
| } | |||
| return false; | |||
| } | |||
| @Override | |||
| public ResultData updateTtProduct(WxCoupon record) { | |||
| @@ -1419,6 +1433,79 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| throw e; | |||
| } | |||
| } | |||
| private Map<Long, Boolean> generateMerchantAutoShareAll(Long[] merchantIds,boolean auto) { | |||
| Map<Long,Boolean> merchantAutoShareMap = new HashMap<Long,Boolean>(); | |||
| for (Long mid:merchantIds) { | |||
| merchantAutoShareMap.put(mid, auto); | |||
| } | |||
| return merchantAutoShareMap; | |||
| } | |||
| @Override | |||
| public Map<Long, Boolean> couponMerchantAutoShare(WxCoupon wxCoupon) throws Exception { | |||
| if (null == wxCoupon.getMerchantIds() || null == wxCoupon.getId() || null == wxCoupon.getType() || null == wxCoupon.getMerchantType()) { | |||
| throw new MallinkException(Result.ERROR,"缺少参数"); | |||
| } | |||
| EnumAppPlat plat = EnumCouponType.getAppPlat(wxCoupon.getType()); | |||
| EnumPayWay payWay = EnumAppPlat.getPayWay(plat); | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(wxCoupon,plat); | |||
| if (cAppInfo == null) { | |||
| throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| WxPayAccount payAccount = payAccountMapper.selectById(cAppInfo.getPayId()); | |||
| if (payAccount == null) { | |||
| throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| EnumPayMchType payMchType = EnumPayMchType.getEnum(payAccount.getMchType()); | |||
| EnumPayShare isShare = EnumPayShare.getEnum(payAccount.getShare()); | |||
| PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); | |||
| //直连模式,如果是单商户券,则都可以;如果是多商户券,抖音则只要开通了支付宝就可以,微信则不行。 | |||
| if (payMchType == EnumPayMchType.DIRECT) { | |||
| if (EnumCouponMerchantType.ONE_MERCHANT.getCode() == wxCoupon.getMerchantType()) { | |||
| return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),true); | |||
| }else { | |||
| if (plat == EnumAppPlat.TOUTIAO) { | |||
| Map<Long,Boolean> merchantAutoShareMap = new HashMap<Long,Boolean>(); | |||
| for (Long mid:wxCoupon.getMerchantIds()) { | |||
| //开通了支付宝就可以 | |||
| WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, mid, null, payMchType.getCode()); | |||
| if (MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())) { | |||
| merchantAutoShareMap.put(mid, true); | |||
| }else { | |||
| merchantAutoShareMap.put(mid, false); | |||
| } | |||
| } | |||
| return merchantAutoShareMap; | |||
| }else if (plat == EnumAppPlat.WX){ | |||
| return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),false); | |||
| }else { | |||
| return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),false); | |||
| } | |||
| } | |||
| }else { | |||
| //总分模式,分账开启,微信平台则认为是100%分账,抖音则只要开通了支付宝就可以。 | |||
| if (isShare == EnumPayShare.YES) { | |||
| if (plat == EnumAppPlat.WX) { | |||
| return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),true); | |||
| }else if (plat == EnumAppPlat.TOUTIAO) { | |||
| Map<Long,Boolean> merchantAutoShareMap = new HashMap<Long,Boolean>(); | |||
| for (Long mid:wxCoupon.getMerchantIds()) { | |||
| boolean isBad = toTalPayMchTypeMerchantIsBad(payShareServie,payAccount,String.valueOf(mid),mid,payMchType,plat); | |||
| if (isBad) { | |||
| merchantAutoShareMap.put(mid, false); | |||
| }else { | |||
| merchantAutoShareMap.put(mid, true); | |||
| } | |||
| } | |||
| return merchantAutoShareMap; | |||
| }else { | |||
| return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),true); | |||
| } | |||
| }else { | |||
| return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),false); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -76,12 +76,10 @@ | |||
| from wx_coupon_mall | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| <select id="findMerchantIdListByProduct" parameterType="java.util.Map" resultType="Long"> | |||
| select distinct cm.merchant_id | |||
| from wx_coupon_merchant cm | |||
| where cm.status = 0 | |||
| and cm.product_id = #{productId} and cm.tenant_id = #{tenantId} | |||
| </select> | |||
| <update id = "updateStatus" parameterType="com.iformall.domain.po.WxCouponMall"> | |||
| update wx_coupon_mall set status = #{status} where `product_id` = #{productId} | |||
| and `tenant_id` = #{tenantId} and `mall_tenant_id` = #{mallTenantId} | |||
| </update> | |||
| </mapper> | |||