| @@ -55,6 +55,8 @@ public class WxCouponController extends BaseController { | |||
| @Autowired | |||
| private WxMallService wxMallService; | |||
| @Autowired | |||
| private WxCouponMallService wxCouponMallService; | |||
| @Autowired | |||
| RedisLock redisLock; | |||
| @Autowired | |||
| @@ -573,5 +575,57 @@ public class WxCouponController extends BaseController { | |||
| CouponCacheUtils.removeCouponCache(redisTemplate, wxCoupon.getId()); | |||
| return result; | |||
| } | |||
| @ApiOperation("集团查询:查询平台券商场列表") | |||
| @GetMapping("/getPlatMallList") | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| public ResultData getPlatMallList(@RequestParam Long id) { | |||
| WxCouponMall wxCouponMall = new WxCouponMall(); | |||
| wxCouponMall.updateTenantInfo(getTenantInfo()); | |||
| wxCouponMall.setProductId(id); | |||
| return new ResultData(wxCouponMallService.list(wxCouponMall)); | |||
| } | |||
| @ApiOperation("商场查询:平台券列表") | |||
| @GetMapping("/couponMalls") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "ids", value = "ids[]", dataType = "Long", paramType = "query", required = true)}) | |||
| public ResultData getMallList(Long[] ids) { | |||
| if (null == ids || ids.length <= 0 ) { | |||
| return new ResultData(ResultData.ERROR, "缺少参数ids"); | |||
| } | |||
| WxCouponMall wxCouponMall = new WxCouponMall(); | |||
| TenantEntity tenantEntity = getTenantInfo(); | |||
| if (null == tenantEntity.getParentTenantId()) { | |||
| wxCouponMall.updateTenantInfo(tenantEntity); | |||
| }else { | |||
| wxCouponMall.setTenantId(tenantEntity.getParentTenantId()); | |||
| } | |||
| //一个商场,每个平台券只有一条记录 | |||
| wxCouponMall.setMallTenantId(tenantEntity.getTenantId()); | |||
| wxCouponMall.setProductIds(Arrays.asList(ids)); | |||
| List<WxCouponMall> mallList= wxCouponMallService.list(wxCouponMall); | |||
| if (null == mallList || mallList.size() <= 0 ) { | |||
| return new ResultData(); | |||
| } | |||
| Map<Long,WxCouponMall> productMallMap = new HashMap<Long,WxCouponMall>(); | |||
| for (int i = 0 ; i < mallList.size(); i ++) { | |||
| WxCouponMall cm = mallList.get(i); | |||
| productMallMap.put(cm.getProductId(), cm); | |||
| } | |||
| return new ResultData(productMallMap); | |||
| } | |||
| @ApiOperation("商场设置平台券商户") | |||
| @PostMapping("/setMerchants") | |||
| public ResultData setMerchant(@RequestBody WxCoupon wxCoupon) { | |||
| wxCoupon.updateTenantInfo(getTenantInfo()); | |||
| try { | |||
| wxCouponService.setCouponMerchants(wxCoupon); | |||
| } catch (Exception e) { | |||
| return new ResultData(Result.ERROR,e.getMessage()); | |||
| } | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,113 @@ | |||
| CREATE TABLE `wx_coupon_mall` ( | |||
| `id` bigint(20) NOT NULL, | |||
| `tenant_id` varchar(5) NOT NULL, | |||
| `parent_tenant_id` varchar(5) DEFAULT NULL, | |||
| `product_id` bigint(20) NOT NULL, | |||
| `mall_tenant_id` varchar(5) NOT NULL, | |||
| `create_date` datetime DEFAULT NULL, | |||
| `update_date` datetime DEFAULT NULL, | |||
| `status` int(1) NOT NULL DEFAULT '0' COMMENT '0-未就绪,1-已就绪', | |||
| PRIMARY KEY (`id`), | |||
| UNIQUE KEY `UNIQUE_P_M` (`product_id`,`mall_tenant_id`) | |||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; | |||
| create table wx_coupon_mall_0 like wx_coupon_mall; | |||
| create table wx_coupon_mall_1 like wx_coupon_mall; | |||
| create table wx_coupon_mall_2 like wx_coupon_mall; | |||
| create table wx_coupon_mall_3 like wx_coupon_mall; | |||
| create table wx_coupon_mall_4 like wx_coupon_mall; | |||
| create table wx_coupon_mall_5 like wx_coupon_mall; | |||
| create table wx_coupon_mall_6 like wx_coupon_mall; | |||
| create table wx_coupon_mall_7 like wx_coupon_mall; | |||
| create table wx_coupon_mall_8 like wx_coupon_mall; | |||
| create table wx_coupon_mall_9 like wx_coupon_mall; | |||
| create table wx_coupon_mall_10 like wx_coupon_mall; | |||
| create table wx_coupon_mall_11 like wx_coupon_mall; | |||
| create table wx_coupon_mall_12 like wx_coupon_mall; | |||
| create table wx_coupon_mall_13 like wx_coupon_mall; | |||
| create table wx_coupon_mall_14 like wx_coupon_mall; | |||
| create table wx_coupon_mall_15 like wx_coupon_mall; | |||
| create table wx_coupon_mall_16 like wx_coupon_mall; | |||
| create table wx_coupon_mall_17 like wx_coupon_mall; | |||
| create table wx_coupon_mall_18 like wx_coupon_mall; | |||
| create table wx_coupon_mall_19 like wx_coupon_mall; | |||
| create table wx_coupon_mall_20 like wx_coupon_mall; | |||
| create table wx_coupon_mall_21 like wx_coupon_mall; | |||
| create table wx_coupon_mall_22 like wx_coupon_mall; | |||
| create table wx_coupon_mall_23 like wx_coupon_mall; | |||
| create table wx_coupon_mall_24 like wx_coupon_mall; | |||
| create table wx_coupon_mall_25 like wx_coupon_mall; | |||
| create table wx_coupon_mall_26 like wx_coupon_mall; | |||
| create table wx_coupon_mall_27 like wx_coupon_mall; | |||
| create table wx_coupon_mall_28 like wx_coupon_mall; | |||
| create table wx_coupon_mall_29 like wx_coupon_mall; | |||
| create table wx_coupon_mall_30 like wx_coupon_mall; | |||
| create table wx_coupon_mall_31 like wx_coupon_mall; | |||
| create table wx_coupon_mall_32 like wx_coupon_mall; | |||
| create table wx_coupon_mall_33 like wx_coupon_mall; | |||
| create table wx_coupon_mall_34 like wx_coupon_mall; | |||
| create table wx_coupon_mall_35 like wx_coupon_mall; | |||
| create table wx_coupon_mall_36 like wx_coupon_mall; | |||
| create table wx_coupon_mall_37 like wx_coupon_mall; | |||
| create table wx_coupon_mall_38 like wx_coupon_mall; | |||
| create table wx_coupon_mall_39 like wx_coupon_mall; | |||
| create table wx_coupon_mall_40 like wx_coupon_mall; | |||
| create table wx_coupon_mall_41 like wx_coupon_mall; | |||
| create table wx_coupon_mall_42 like wx_coupon_mall; | |||
| create table wx_coupon_mall_43 like wx_coupon_mall; | |||
| create table wx_coupon_mall_44 like wx_coupon_mall; | |||
| create table wx_coupon_mall_45 like wx_coupon_mall; | |||
| create table wx_coupon_mall_46 like wx_coupon_mall; | |||
| create table wx_coupon_mall_47 like wx_coupon_mall; | |||
| create table wx_coupon_mall_48 like wx_coupon_mall; | |||
| create table wx_coupon_mall_49 like wx_coupon_mall; | |||
| create table wx_coupon_mall_50 like wx_coupon_mall; | |||
| create table wx_coupon_mall_51 like wx_coupon_mall; | |||
| create table wx_coupon_mall_52 like wx_coupon_mall; | |||
| create table wx_coupon_mall_53 like wx_coupon_mall; | |||
| create table wx_coupon_mall_54 like wx_coupon_mall; | |||
| create table wx_coupon_mall_55 like wx_coupon_mall; | |||
| create table wx_coupon_mall_56 like wx_coupon_mall; | |||
| create table wx_coupon_mall_57 like wx_coupon_mall; | |||
| create table wx_coupon_mall_58 like wx_coupon_mall; | |||
| create table wx_coupon_mall_59 like wx_coupon_mall; | |||
| create table wx_coupon_mall_60 like wx_coupon_mall; | |||
| create table wx_coupon_mall_61 like wx_coupon_mall; | |||
| create table wx_coupon_mall_62 like wx_coupon_mall; | |||
| create table wx_coupon_mall_63 like wx_coupon_mall; | |||
| create table wx_coupon_mall_64 like wx_coupon_mall; | |||
| create table wx_coupon_mall_65 like wx_coupon_mall; | |||
| create table wx_coupon_mall_66 like wx_coupon_mall; | |||
| create table wx_coupon_mall_67 like wx_coupon_mall; | |||
| create table wx_coupon_mall_68 like wx_coupon_mall; | |||
| create table wx_coupon_mall_69 like wx_coupon_mall; | |||
| create table wx_coupon_mall_70 like wx_coupon_mall; | |||
| create table wx_coupon_mall_71 like wx_coupon_mall; | |||
| create table wx_coupon_mall_72 like wx_coupon_mall; | |||
| create table wx_coupon_mall_73 like wx_coupon_mall; | |||
| create table wx_coupon_mall_74 like wx_coupon_mall; | |||
| create table wx_coupon_mall_75 like wx_coupon_mall; | |||
| create table wx_coupon_mall_76 like wx_coupon_mall; | |||
| create table wx_coupon_mall_77 like wx_coupon_mall; | |||
| create table wx_coupon_mall_78 like wx_coupon_mall; | |||
| create table wx_coupon_mall_79 like wx_coupon_mall; | |||
| create table wx_coupon_mall_80 like wx_coupon_mall; | |||
| create table wx_coupon_mall_81 like wx_coupon_mall; | |||
| create table wx_coupon_mall_82 like wx_coupon_mall; | |||
| create table wx_coupon_mall_83 like wx_coupon_mall; | |||
| create table wx_coupon_mall_84 like wx_coupon_mall; | |||
| create table wx_coupon_mall_85 like wx_coupon_mall; | |||
| create table wx_coupon_mall_86 like wx_coupon_mall; | |||
| create table wx_coupon_mall_87 like wx_coupon_mall; | |||
| create table wx_coupon_mall_88 like wx_coupon_mall; | |||
| create table wx_coupon_mall_89 like wx_coupon_mall; | |||
| create table wx_coupon_mall_90 like wx_coupon_mall; | |||
| create table wx_coupon_mall_91 like wx_coupon_mall; | |||
| create table wx_coupon_mall_92 like wx_coupon_mall; | |||
| create table wx_coupon_mall_93 like wx_coupon_mall; | |||
| create table wx_coupon_mall_94 like wx_coupon_mall; | |||
| create table wx_coupon_mall_95 like wx_coupon_mall; | |||
| create table wx_coupon_mall_96 like wx_coupon_mall; | |||
| create table wx_coupon_mall_97 like wx_coupon_mall; | |||
| create table wx_coupon_mall_98 like wx_coupon_mall; | |||
| create table wx_coupon_mall_99 like wx_coupon_mall; | |||
| @@ -323,6 +323,13 @@ public class BaseMyBatisConfiguration { | |||
| wxPressBatchItemSharding.setRule(EnumShardingRule.HASH.getCode()); | |||
| shardingList.add(wxPressBatchItemSharding); | |||
| ShardingSphere wxCouponMallSharding = new ShardingSphere(); | |||
| wxCouponMallSharding.setColumn("tenant_id"); | |||
| wxCouponMallSharding.setTableName("wx_coupon_mall"); | |||
| wxCouponMallSharding.setCount(100); | |||
| wxCouponMallSharding.setRule(EnumShardingRule.HASH.getCode()); | |||
| shardingList.add(wxCouponMallSharding); | |||
| //初始化 | |||
| shardingSpherePlugin.setShardingSpheres(shardingList); | |||
| Properties properties = new Properties(); | |||
| @@ -0,0 +1,33 @@ | |||
| package com.iformall.domain.po; | |||
| import com.baomidou.mybatisplus.annotation.TableField; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @TableName(value = "wx_coupon_mall") | |||
| @Data | |||
| @EqualsAndHashCode(callSuper = true) | |||
| public class WxCouponMall extends TenantEntity { | |||
| private static final long serialVersionUID = -2285755324480617990L; | |||
| protected Long id; | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="productId") | |||
| private Long productId; | |||
| @TableField(exist = false) | |||
| private List<Long> productIds; | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="mallTenantId") | |||
| private String mallTenantId; | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||
| private Date createDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="修改时间",name="updateDate") | |||
| private Date updateDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="状态",name="status") | |||
| private Integer status; | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| package com.iformall.mapper; | |||
| import com.iformall.common.CommonMapper; | |||
| import com.iformall.domain.po.WxCouponMall; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| 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); | |||
| } | |||
| @@ -0,0 +1,27 @@ | |||
| package com.iformall.service; | |||
| import java.util.*; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.TtCouponChannelPoi; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxCouponMall; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.TtCouponVo; | |||
| import com.iformall.domain.vo.WxCouponCVo; | |||
| import com.iformall.domain.vo.WxCouponStatisVo; | |||
| import com.iformall.domain.vo.WxMerchantVo; | |||
| public interface WxCouponMallService { | |||
| PageInfo<WxCouponMall> listAsPage(WxCouponMall record, Integer pageIndex, Integer pageSize); | |||
| List<WxCouponMall> list(WxCouponMall wxCouponMall); | |||
| } | |||
| @@ -287,4 +287,6 @@ public interface WxCouponService { | |||
| * @return | |||
| */ | |||
| ResultData disable(TenantEntity tenantInfo, Long couponId); | |||
| void setCouponMerchants(WxCoupon wxCoupon) throws Exception; | |||
| } | |||
| @@ -0,0 +1,31 @@ | |||
| package com.iformall.service.impl; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.*; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.*; | |||
| @Service | |||
| public class WxCouponMallServiceImpl implements WxCouponMallService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| WxCouponMallMapper wxCouponMallMapper; | |||
| @Override | |||
| public List<WxCouponMall> list(WxCouponMall wxCouponMall){ | |||
| return wxCouponMallMapper.findList(wxCouponMall); | |||
| } | |||
| @Override | |||
| public PageInfo<WxCouponMall> listAsPage(WxCouponMall record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponMallMapper.findList(record)); | |||
| } | |||
| } | |||
| @@ -440,19 +440,13 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| if(Result.SUCCESS != giftResult.code){ | |||
| return giftResult; | |||
| } | |||
| ResultData receiverResult = checkCouponMerchantReceiver(record); | |||
| if(Result.SUCCESS != receiverResult.code){ | |||
| return receiverResult; | |||
| } | |||
| List<WxMerchant> merchantList = (List<WxMerchant>) receiverResult.data; | |||
| if(merchantList.size() > 1){ | |||
| record.setBusiness(EnumBusiness.BUSINESS_ID6.getCode()); | |||
| }else{ | |||
| record.setBusiness(merchantList.get(0).getBusinessId()); | |||
| record.setSubBusiness(merchantList.get(0).getSubBusinessId()); | |||
| } | |||
| try { | |||
| checkCouponMerchantReceiverAndUpdate(record); | |||
| }catch(Exception e) { | |||
| return new ResultData(Result.ERROR,e.getMessage()); | |||
| } | |||
| List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); | |||
| @@ -500,41 +494,7 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| record.setInventory(oldCoupon.getInventory() + record.getRemainInventory() - oldCoupon.getRemainInventory()); | |||
| } | |||
| } | |||
| WxCouponMerchant cmParam = new WxCouponMerchant(); | |||
| cmParam.updateTenantInfo(record); | |||
| cmParam.setProductId(record.getId()); | |||
| List<WxCouponMerchant> oldList = wxCouponMerchantMapper.findList(cmParam); | |||
| merchantParamList.stream().forEach(merchantParam -> { | |||
| WxCouponMerchant cm = new WxCouponMerchant(); | |||
| WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); | |||
| cm.updateTenantInfo(record); | |||
| cm.setMerchantId(wxCouponMerchantDto.getMerchantId()); | |||
| cm.setProductId(record.getId()); | |||
| WxCouponMerchant rcm = wxCouponMerchantMapper.selectOne(new QueryWrapper<>(cm)); | |||
| if (rcm != null) { | |||
| rcm.setParameter(wxCouponMerchantDto.getParameter()); | |||
| rcm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | |||
| rcm.setUpdateDate(new Date()); | |||
| wxCouponMerchantMapper.updateById(rcm); | |||
| }else { | |||
| cm.setId(idWorker.nextId()); | |||
| cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | |||
| cm.setParameter(wxCouponMerchantDto.getParameter()); | |||
| cm.setCreateDate(new Date()); | |||
| cm.setUpdateDate(new Date()); | |||
| wxCouponMerchantMapper.insert(cm); | |||
| } | |||
| oldList.removeIf( | |||
| old->old.getProductId().equals(record.getId()) && | |||
| old.getMerchantId().equals(wxCouponMerchantDto.getMerchantId())); | |||
| }); | |||
| oldList.stream().forEach(old->{ | |||
| old.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_INVALID.getCode()); | |||
| old.setUpdateDate(new Date()); | |||
| wxCouponMerchantMapper.updateById(old); | |||
| }); | |||
| updateCouponMerchants(record,merchantParamList,idWorker); | |||
| record.setUpdateDate(new Date()); | |||
| wxCouponMapper.updateById(record); | |||
| @@ -545,11 +505,62 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| return new ResultData(record.getId()); | |||
| } | |||
| private ResultData checkCouponMerchantReceiver(WxCoupon record){ | |||
| private void updateCouponMerchants(WxCoupon record,List<JSONObject> merchantParamList,final IdWorker idWorker) { | |||
| WxCouponMerchant cmParam = new WxCouponMerchant(); | |||
| cmParam.updateTenantInfo(record); | |||
| cmParam.setProductId(record.getId()); | |||
| List<WxCouponMerchant> oldList = wxCouponMerchantMapper.findList(cmParam); | |||
| merchantParamList.stream().forEach(merchantParam -> { | |||
| WxCouponMerchant cm = new WxCouponMerchant(); | |||
| WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); | |||
| cm.updateTenantInfo(record); | |||
| cm.setMerchantId(wxCouponMerchantDto.getMerchantId()); | |||
| cm.setProductId(record.getId()); | |||
| WxCouponMerchant rcm = wxCouponMerchantMapper.selectOne(new QueryWrapper<>(cm)); | |||
| if (rcm != null) { | |||
| rcm.setParameter(wxCouponMerchantDto.getParameter()); | |||
| rcm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | |||
| rcm.setUpdateDate(new Date()); | |||
| wxCouponMerchantMapper.updateById(rcm); | |||
| }else { | |||
| cm.setId(idWorker.nextId()); | |||
| cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | |||
| cm.setParameter(wxCouponMerchantDto.getParameter()); | |||
| cm.setCreateDate(new Date()); | |||
| cm.setUpdateDate(new Date()); | |||
| wxCouponMerchantMapper.insert(cm); | |||
| } | |||
| oldList.removeIf( | |||
| old->old.getProductId().equals(record.getId()) && | |||
| old.getMerchantId().equals(wxCouponMerchantDto.getMerchantId())); | |||
| }); | |||
| oldList.stream().forEach(old->{ | |||
| old.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_INVALID.getCode()); | |||
| old.setUpdateDate(new Date()); | |||
| wxCouponMerchantMapper.updateById(old); | |||
| }); | |||
| } | |||
| private void checkCouponMerchantReceiverAndUpdate(WxCoupon wxCoupon) throws Exception{ | |||
| try { | |||
| List<WxMerchant> merchantList = checkCouponMerchantReceiver(wxCoupon); | |||
| if(merchantList.size() > 1){ | |||
| wxCoupon.setBusiness(EnumBusiness.BUSINESS_ID6.getCode()); | |||
| }else{ | |||
| wxCoupon.setBusiness(merchantList.get(0).getBusinessId()); | |||
| wxCoupon.setSubBusiness(merchantList.get(0).getSubBusinessId()); | |||
| } | |||
| }catch (Exception e) { | |||
| throw e; | |||
| } | |||
| } | |||
| private List<WxMerchant> checkCouponMerchantReceiver(WxCoupon record) throws Exception{ | |||
| List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); | |||
| if(merchantParamList == null || merchantParamList.isEmpty()){ | |||
| return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); | |||
| throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); | |||
| } | |||
| List<Long> merchantIds = new ArrayList<>(); | |||
| for (JSONObject o:merchantParamList) { | |||
| @@ -560,12 +571,12 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| merchantQ.setIds(merchantIds); | |||
| List<WxMerchant> merchantList = wxMerchantService.findList(merchantQ); | |||
| if(merchantList.size() != merchantParamList.size()){ | |||
| return new ResultData(ErrorCode.MERCHANT_INFO_NOT_EQUAL.getCode(),"所属商户信息异常"); | |||
| throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_EQUAL.getCode(),"所属商户信息异常"); | |||
| } | |||
| List<WxMerchant> badMerchant = merchantList.stream().filter(m -> !EnumMerchantStatus.VALID.getCode().equals(m.getStatus())).collect(toList()); | |||
| if(badMerchant != null && !badMerchant.isEmpty()){ | |||
| List<String> badNames = badMerchant.stream().map(WxMerchant::getName).collect(toList()); | |||
| return new ResultData(ErrorCode.MERCHANT_INFO_NOT_VALID.getCode(),JSONArray.toJSONString(badNames)+"被停用"); | |||
| throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID.getCode(),JSONArray.toJSONString(badNames)+"被停用"); | |||
| } | |||
| if(record.getSalePrice() != null && record.getSalePrice() > 0) { | |||
| @@ -573,11 +584,11 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| EnumPayWay payWay = EnumAppPlat.getPayWay(plat); | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(record,plat); | |||
| if (cAppInfo == null) { | |||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||
| throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| WxPayAccount payAccount = payAccountMapper.selectById(cAppInfo.getPayId()); | |||
| if (payAccount == null) { | |||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||
| throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| //判断商户是否匹配poi | |||
| @@ -590,7 +601,7 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| } | |||
| } | |||
| if(!badPoiNames.isEmpty()){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), JSONArray.toJSONString(badPoiNames)+"未匹配poi"); | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), JSONArray.toJSONString(badPoiNames)+"未匹配poi"); | |||
| } | |||
| } | |||
| @@ -607,9 +618,9 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| }else{ | |||
| List<WxMerchant> adminMerchant = merchantList.stream().filter(m -> EnumMerchantAdmin.PUBLIC_ADMIN.getCode().equals(m.getIsAdmin())).collect(toList()); | |||
| if(adminMerchant == null || adminMerchant.isEmpty()){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "多门店券需包含一个商管商户"); | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "多门店券需包含一个商管商户"); | |||
| }else if(adminMerchant.size() > 1){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "多门店券只能包含一个商管商户"); | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "多门店券只能包含一个商管商户"); | |||
| } | |||
| record.setMerchantType(EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode()); | |||
| makeMerchant = adminMerchant.get(0); | |||
| @@ -619,13 +630,13 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, makeMerchant.getId(), null, payMchType.getCode()); | |||
| if (receiver == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); | |||
| 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())) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); | |||
| } | |||
| } | |||
| } else if (EnumPayShare.YES.equals(isShare)) { | |||
| @@ -643,7 +654,7 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| if(!EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) | |||
| && !EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) | |||
| && !EnumYesOrNo.YES.getCode().equals(openPayResult.getHz())){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "分账模式未设置开通支付渠道"); | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "分账模式未设置开通支付渠道"); | |||
| } | |||
| if(EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) | |||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())){ | |||
| @@ -663,11 +674,11 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| } | |||
| } | |||
| if(!badNames.isEmpty()){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), JSONArray.toJSONString(badNames)+"未配置分账账户"); | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), JSONArray.toJSONString(badNames)+"未配置分账账户"); | |||
| } | |||
| } | |||
| } | |||
| return new ResultData(merchantList); | |||
| return merchantList; | |||
| } | |||
| @Override | |||
| @@ -1320,4 +1331,17 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| return new ResultData(); | |||
| } | |||
| @Override | |||
| public void setCouponMerchants(WxCoupon wxCoupon) throws Exception { | |||
| try { | |||
| checkCouponMerchantReceiverAndUpdate(wxCoupon); | |||
| List<JSONObject> merchantParamList = JSONObject.parseArray(wxCoupon.getMerchantParams(), JSONObject.class); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| updateCouponMerchants(wxCoupon,merchantParamList,idWorker); | |||
| }catch(Exception e) { | |||
| throw e; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,87 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.iformall.mapper.WxCouponMallMapper"> | |||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCouponMall"> | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||
| <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId"/> | |||
| <result column="product_id" jdbcType="BIGINT" property="productId" /> | |||
| <result column="mall_tenant_id" jdbcType="VARCHAR" property="mallTenantId" /> | |||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | |||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | |||
| <result column="status" jdbcType="INTEGER" property="status" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`parent_tenant_id`,`product_id`,`mall_tenant_id`,`create_date`,`update_date`,`status` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1 = 1 | |||
| <if test=" null != id "> | |||
| and `id` = #{id} | |||
| </if> | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != parentTenantId and '' != parentTenantId"> | |||
| and `parent_tenant_id` = #{parentTenantId} | |||
| </if> | |||
| <if test=" null != productId "> | |||
| and `product_id` = #{productId} | |||
| </if> | |||
| <if test=" null != mallTenantId "> | |||
| and `mall_tenant_id` = #{mallTenantId} | |||
| </if> | |||
| <if test=" null != createDate "> | |||
| and `create_date` = #{createDate} | |||
| </if> | |||
| <if test=" null != updateDate "> | |||
| and `update_date` = #{updateDate} | |||
| </if> | |||
| <if test=" null != status "> | |||
| and `status` = #{status} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != productIds "> | |||
| and product_id in | |||
| <foreach collection="productIds" index="index" item="productIdItem" open="(" separator="," close=")"> | |||
| #{productIdItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||
| </sql> | |||
| <select id="findList" parameterType="com.iformall.domain.po.WxCouponMall" resultMap="BaseResultMap"> | |||
| select | |||
| <include refid="allColumns"/> | |||
| 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> | |||
| </mapper> | |||