From 17ecf44ff7641c191b51cc201b2790af394f86c4 Mon Sep 17 00:00:00 2001 From: xhxu Date: Wed, 8 Jun 2022 14:50:16 +0800 Subject: [PATCH] //tt product --- .../controller/market/WxCouponController.java | 16 + .../V2022060700001__coupon_product.sql | 2 +- .../domain/po/TtCouponChannelPoi.java | 5 +- .../java/com/iformall/domain/po/WxCoupon.java | 8 +- .../douyin/web/bean/GoodsTemplateGet.java | 4 +- .../iformall/enums/EnumCouponChannelType.java | 1 + .../service/TtGoodsCategoryService.java | 5 + .../service/WxCouponChannelService.java | 3 + .../com/iformall/service/WxCouponService.java | 1 + .../impl/TtGoodsCategoryServiceImpl.java | 312 +++++++++++++++++- .../impl/WxCouponChannelServiceImpl.java | 4 + .../service/impl/WxCouponServiceImpl.java | 157 ++++++++- 12 files changed, 494 insertions(+), 24 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java index 125a9496d..077097a05 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java @@ -609,4 +609,20 @@ public class WxCouponController extends BaseController { } + @ApiOperation("提交审核") + @PostMapping("/goods/product/save") + @SystemControllerLog(description = "提交审核") + public ResultData productSave(@RequestBody WxCoupon wxCoupon) { + if (wxCoupon.getId() == null) { + return new ResultData(ResultData.ERROR, "缺少id"); + } + WxCoupon coupon = wxCouponService.getById(wxCoupon.getId(), getTenantInfo().getTenantId()); + if(coupon == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + + ResultData result = wxCouponService.productSave(coupon); + return result; + } + } diff --git a/mallinkAdmin/src/main/resources/db/migration/V2022060700001__coupon_product.sql b/mallinkAdmin/src/main/resources/db/migration/V2022060700001__coupon_product.sql index cde68d781..c7592f2d4 100644 --- a/mallinkAdmin/src/main/resources/db/migration/V2022060700001__coupon_product.sql +++ b/mallinkAdmin/src/main/resources/db/migration/V2022060700001__coupon_product.sql @@ -1,5 +1,5 @@ ALTER TABLE `mallink`.`tt_coupon_channel_poi` -ADD COLUMN `coupon_id` bigint(20) NOT NULL AFTER `parent_tenant_id`; +ADD COLUMN `coupon_channel_id` bigint(20) NOT NULL AFTER `parent_tenant_id`; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/TtCouponChannelPoi.java b/mallinkService/src/main/java/com/iformall/domain/po/TtCouponChannelPoi.java index cdd8c0eba..183a0cf3e 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/TtCouponChannelPoi.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/TtCouponChannelPoi.java @@ -17,7 +17,10 @@ import java.util.Date; @EqualsAndHashCode(callSuper = true) public class TtCouponChannelPoi extends TenantEntity { - protected Long id;//coupon_channel_id + protected Long id;//coupon_id + + @io.swagger.annotations.ApiModelProperty(value="couponChannelId",name="couponChannelId") + private Long couponChannelId; @io.swagger.annotations.ApiModelProperty(value="spuId",name="spuId") private String spuId; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java index e3edd1448..4cd44e360 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java @@ -261,8 +261,8 @@ public class WxCoupon extends TenantEntity { try{ List productAttrs = JSONObject.parseArray(this.productAttrs, GoodsTemplateGet.ProductAttrs.class); for (GoodsTemplateGet.ProductAttrs attr:productAttrs) { - if(StringUtils.isNotBlank(attr.getValue())){ - productAttrKeyValueMap.put(attr.getKey(),attr.getValue()); + if(StringUtils.isNotBlank(attr.getData())){ + productAttrKeyValueMap.put(attr.getKey(),attr.getData()); } } }catch(Exception e){ @@ -284,8 +284,8 @@ public class WxCoupon extends TenantEntity { try{ List skuAttrs = JSONObject.parseArray(this.skuAttrs, GoodsTemplateGet.ProductAttrs.class); for (GoodsTemplateGet.ProductAttrs attr:skuAttrs) { - if(StringUtils.isNotBlank(attr.getValue())){ - skuAttrKeyValueMap.put(attr.getKey(),attr.getValue()); + if(StringUtils.isNotBlank(attr.getData())){ + skuAttrKeyValueMap.put(attr.getKey(),attr.getData()); } } }catch(Exception e){ diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/bean/GoodsTemplateGet.java b/mallinkService/src/main/java/com/iformall/douyin/web/bean/GoodsTemplateGet.java index abd678b96..0f8c0e633 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/bean/GoodsTemplateGet.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/bean/GoodsTemplateGet.java @@ -83,8 +83,8 @@ public class GoodsTemplateGet implements Serializable { @SerializedName(value = "value_type") private String valueType; - @SerializedName(value = "value") - private String value; + @SerializedName(value = "data") + private String data; } diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumCouponChannelType.java b/mallinkService/src/main/java/com/iformall/enums/EnumCouponChannelType.java index 37868742c..d60cea909 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumCouponChannelType.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumCouponChannelType.java @@ -16,6 +16,7 @@ public enum EnumCouponChannelType { COUPON_CHANNEL_ID_CREDIT(50, "积分商城"), COUPON_CHANNEL_ID_H5(100, "DSP的H5页面"), + COUPON_CHANNEL_ID_DOUYIN_SAVE_LIST(11, "抖音商品库审核列表"), COUPON_CHANNEL_ID_DOUYIN_LIST(101, "抖音列表"), COUPON_CHANNEL_ID_WXLIVE_LIST(102, "微信直播列表") diff --git a/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java b/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java index de4e0555a..4366fa472 100644 --- a/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java +++ b/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java @@ -28,4 +28,9 @@ public interface TtGoodsCategoryService { * @param temp */ void handTemplate(GoodsTemplateGet temp, WxCoupon coupon); + + /** + * 处理系统属性和默认属性 + */ + void handDefaultAttr(WxCoupon coupon,List productAttrs,List skuAttrs); } diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java index bc66a3a06..9aaf26858 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java @@ -6,6 +6,7 @@ import com.iformall.domain.po.base.TenantEntity; import com.iformall.domain.po.WxCoupon; import com.iformall.domain.po.WxCouponChannel; import com.iformall.domain.vo.WxCouponCVo; +import com.iformall.domain.vo.WxCouponChannelAddVo; import com.iformall.domain.vo.WxCouponChannelVo; import java.util.Date; @@ -53,6 +54,8 @@ public interface WxCouponChannelService { ResultData addBatch(String type,String[] ids, String[] channelId, TenantEntity tenantEntity, Date showBeginTime, Date beginTime, Date endTime,Integer channelPrice,Integer channelStock); + WxCouponChannelAddVo addCouponChannel(Long couponid, Integer channelId, TenantEntity tenantEntity, Date showBeginTime, Date beginTime, Date endTime, Integer channelPrice, Integer channelStock); + void updateStatusByCouponId(Long couponId,TenantEntity tenantEntity,int status); ResultData change(WxCouponChannel wxCouponChannel); diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponService.java index dd5aa8aa4..a20127341 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponService.java @@ -273,4 +273,5 @@ public interface WxCouponService { List getCouponMerchantList(TenantEntity tenantInfo, Long couponId); + ResultData productSave(WxCoupon coupon); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java index 68c21aadb..5913ebb8d 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java @@ -1,10 +1,16 @@ package com.iformall.service.impl; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.iformall.domain.po.TtGoodsCategory; import com.iformall.domain.po.WxCoupon; import com.iformall.douyin.web.bean.GoodsTemplateGet; +import com.iformall.enums.EnumCouponValidType; import com.iformall.mapper.TtGoodsCategoryMapper; import com.iformall.service.TtGoodsCategoryService; +import com.iformall.utils.DataUtil; +import com.iformall.utils.DateUtils; +import me.chanjar.weixin.common.util.DataUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,8 +56,8 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { private List getProductAdminIsNotShowKey(){ List keyList = new ArrayList<>(); -// keyList.add("appointment"); //预约信息 默认不可预约 -// keyList.add("auto_renew"); //是否开启自动延期 默认不开启 + keyList.add("appointment"); //预约信息 默认不可预约 + keyList.add("auto_renew"); //是否开启自动延期 默认不开启 // keyList.add("bring_out_meal"); //是否可以外带餐食 默认否 keyList.add("can_no_use_date");//不可使用日期 默认无 keyList.add("customer_reserved_info");//留资规则 非必填 @@ -75,10 +81,10 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { // keyList.add("rec_person_num_max");//最多使用人数 keyList.add("RefundPolicy");//退款政策 keyList.add("refund_need_merchant_confirm");//退款是否需商家审核 默认否 - keyList.add("show_channel");//投放渠道 默认1-不限制 +// keyList.add("show_channel");//投放渠道 默认1-不限制 keyList.add("SortWeight");//排序权重 非必填 // keyList.add("superimposed_discounts");//可以享受店内其他优惠 -// keyList.add("TagList");//标签列表 非必填 + keyList.add("TagList");//标签列表 非必填 keyList.add("use_date");//使用日期 对应券有效期 keyList.add("use_time");//使用时间 默认全天可用 return keyList; @@ -125,7 +131,7 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { for (GoodsTemplateGet.ProductAttrs attr: temp.getProductAttrs()) { String value = coupon.getProductAttrKeyValueMap().get(attr.getKey()); if(StringUtils.isNotBlank(value)){ - attr.setValue(value); + attr.setData(value); } } } @@ -133,10 +139,304 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { for (GoodsTemplateGet.ProductAttrs attr: temp.getProductAttrs()) { String value = coupon.getSkuAttrKeyValueMap().get(attr.getKey()); if(StringUtils.isNotBlank(value)){ - attr.setValue(value); + attr.setData(value); } } } } + @Override + public void handDefaultAttr(WxCoupon coupon, List productAttrs, List skuAttrs) { + for (GoodsTemplateGet.ProductAttrs attr: productAttrs) { + //预约信息 默认不可预约 + if("appointment".equals(attr.getKey())){ + JSONObject jsonObject = new JSONObject(); + jsonObject.put("need_appointment",false); + jsonObject.put("ahead_day_num",0); + attr.setData(jsonObject.toJSONString()); + } + //是否开启自动延期 默认不开启 + else if("auto_renew".equals(attr.getKey())){ + attr.setData("false"); + } + //是否可以外带餐食 默认否------页面填写 +// else if("bring_out_meal".equals(attr.getKey())){ +// attr.setValue("false"); +// } + //不可使用日期 默认不开启 + else if("can_no_use_date".equals(attr.getKey())){ + JSONObject jsonObject = new JSONObject(); + jsonObject.put("enable",false); + attr.setData(jsonObject.toJSONString()); + } + + /** + * 留资规则 ---暂无 + * "struct CustomerReservedInfoStruct { + * 1: required bool allow //是否留资 + * 2: optional bool allow_tel //可以留电话 + * 3: optional bool allow_name // 可以留姓名 + * 4: optional bool allow_identity // 可以留身份证 + * 5: optional bool require_for_tel //手机号是否必传 【默认非必传】 + * 10: optional bool need_for_all // 是否每张券都需要留资 + * }" + */ +// else if("customer_reserved_info".equals(attr.getKey())){ +// JSONObject jsonObject = new JSONObject(); +// +// attr.setValue(jsonObject.toJSONString()); +// } + + /** + * 其他说明信息 默认无------页面填写 + * "enum OtherNoteTypeEnum { + * TEXT = 1 // 文本 + * IMG = 2 // 图片 + * } + * + * struct NoteStruct { + * 1: optional OtherNoteTypeEnum note_type + * 2: optional string content + * }" + */ +// else if("description_rich_text".equals(attr.getKey())){ +// JSONArray jsonArray = new JSONArray(); +// +// attr.setValue(jsonArray.toJSONString()); +// } + /** + * 长图 默认无------页面填写 + * "struct ImageStruct { + * 1: optional string name + * 3: optional string url + * }" + */ +// else if("detail_image_list".equals(attr.getKey())){ +// JSONArray jsonArray = new JSONArray(); +// +// attr.setValue(jsonArray.toJSONString()); +// } + /** + * 菜品图 默认无------页面填写 + * "struct ImageStruct { + * 1: optional string name + * 3: optional string url + * }" + */ +// else if("dishes_image_list".equals(attr.getKey())){ +// JSONArray jsonArray = new JSONArray(); +// +// attr.setValue(jsonArray.toJSONString()); +// } + //入口类型 默认小程序 1:H5 2:小程序 3:抖音 4:lynx + else if("EntryType".equals(attr.getKey())){ + if(StringUtils.isBlank(attr.getData())){ + attr.setData("2"); + } + } + /** + * 环境图 默认无------页面填写 + * "struct ImageStruct { + * 1: optional string name + * 3: optional string url + * }" + */ +// else if("environment_image_list".equals(attr.getKey())){ +// JSONArray jsonArray = new JSONArray(); +// +// attr.setValue(jsonArray.toJSONString()); +// } + //是否可以打包 默认不开启-------页面填写 + else if("free_pack".equals(attr.getKey())){ + if(StringUtils.isBlank(attr.getData())){ + attr.setData("false"); + } + } + /** + * 前台品类标签 ----页面填写 + * - 门票 + * - 项目 + * - 团购 + * - 一日游 + * - 多日游 + * - 旅行跟拍 + * - 含房套餐 + * - 美食套餐 + * - 美食单品 + * - 单景区门票 + * - 单景区套票 + * - 多景区联票 + * - 游玩项目票 + * - 门店项目票 + * - 门店服务 + * - 代金券 + * - 日历房 + * - 单房型 + * - 其他 + * - 测试 + */ +// else if("FrontCategoryTag".equals(attr.getKey())){ +// JSONArray jsonArray = new JSONArray(); +// jsonArray.add() +// attr.setValue(jsonArray.toJSONString()); +// } + /** + * 封面图 系统对应 + * "struct ImageStruct { + * 1: optional string name + * 3: optional string url + * }" + */ + else if("image_list".equals(attr.getKey())){ + JSONArray jsonArray = new JSONArray(); + List strings = JSONArray.parseArray(coupon.getCoverPicture(), String.class); + for (String url: strings) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("url",url); + jsonArray.add(jsonObject); + } + attr.setData(jsonArray.toJSONString()); + } + /** + * 商品行业类型(IndustryType)的枚举 -- 默认无 + * 传指定的中文字符串: + * - 门票 + * - 一日游 + * - 多日游 + * - 旅拍 + * - 其他 + */ +// else if("IndustryType".equals(attr.getKey())){ +// attr.setValue(); +// } + //是否立即确认 默认无 +// else if("IsConfirmImme".equals(attr.getKey())){ +// attr.setValue("false"); +// } + //小程序资源id 默认无 +// else if("MpResourceID".equals(attr.getKey())){ +// attr.setValue(""); +// } + //小程序分账类型 默认无 +// else if("MpSettleType".equals(attr.getKey())){ +// attr.setValue(""); +// } + //使用规则 页面填写 +// else if("Notification".equals(attr.getKey())){ +// attr.setValue("[]"); +// } + //是否可以使用包间 页面填写 + else if("private_room".equals(attr.getKey())){ + if(StringUtils.isBlank(attr.getData())){ + attr.setData("false"); + } + } + //实名信息 默认无 +// else if("real_name_info".equals(attr.getKey())){ +// JSONObject jsonObject = new JSONObject(); +// jsonObject.put("enable",false); +// jsonObject.put("scene",0); +// attr.setData(jsonObject.toJSONString()); +// } + //推荐语 默认无 页面填写 +// else if("RecommendWord".equals(attr.getKey())){ +// attr.setData(""); +// } + //建议使用人数 页面填写 +// else if("rec_person_num".equals(attr.getKey())){ +// attr.setData(""); +// } + //最多使用人数 页面填写 +// else if("rec_person_num_max".equals(attr.getKey())){ +// attr.setData(""); +// } + //退款政策 默认1 1-允许退款 2-不可退款 3-有条件退 + else if("RefundPolicy".equals(attr.getKey())){ + if(StringUtils.isBlank(attr.getData())){ + attr.setData("1"); + } + } + //退款是否需商家审核 默认false + else if("refund_need_merchant_confirm".equals(attr.getKey())){ + if(StringUtils.isBlank(attr.getData())){ + attr.setData("false"); + } + } + //投放渠道 默认1 1-不限制 2-仅直播间可见 ----页面填写 + else if("show_channel".equals(attr.getKey())){ + if(StringUtils.isBlank(attr.getData())){ + attr.setData("1"); + } + } + //排序权重 默认无 +// else if("SortWeight".equals(attr.getKey())){ +// attr.setData("1"); +// } + //可以享受店内其他优惠 ----页面填写 +// else if("superimposed_discounts".equals(attr.getKey())){ +// attr.setData("false"); +// } + //标签列表 默认无 +// else if("TagList".equals(attr.getKey())){ +// attr.setData(""); +// } + //小程序提单页跳转 默认无 +// else if("trade_url".equals(attr.getKey())){ +// attr.setData(""); +// } + //使用日期 ----对应券有效期 + else if("use_date".equals(attr.getKey())){ + JSONObject jsonObject = new JSONObject(); + if(EnumCouponValidType.BETWEEN_TWO_TIME.getCode().equals(coupon.getValidType())){ + jsonObject.put("use_date_type",1); + jsonObject.put("use_start_date",DateUtils.date2String(coupon.getValidStartDate(),"yyyy-MM-dd")); + jsonObject.put("use_end_date",DateUtils.date2String(coupon.getValidEndDate(),"yyyy-MM-dd")); + }else if(EnumCouponValidType.DAYS_AFTER_RECEIVING.getCode().equals(coupon.getValidType())){ + jsonObject.put("use_date_type",2); + jsonObject.put("day_duration",coupon.getValidDays()); + } + + attr.setData(jsonObject.toJSONString()); + } + //使用日期 ----默认全天 + else if("use_date".equals(attr.getKey())){ + JSONObject jsonObject = new JSONObject(); + jsonObject.put("use_time_type",1); + attr.setData(jsonObject.toJSONString()); + } + + } + + for (GoodsTemplateGet.ProductAttrs attr: skuAttrs) { + //券码生成方式 默认2 1-抖音码 2-三方码 3-预导码 + if("code_source_type".equals(attr.getKey())){ + attr.setData("2"); + } + //菜品搭配 页面填写 + else if("commodity".equals(attr.getKey())){ + + } + //限制购买 系统对应 + else if("limit_rule".equals(attr.getKey())){ + JSONObject jsonObject = new JSONObject(); + jsonObject.put("is_limit",true); + jsonObject.put("total_buy_num",coupon.getUseLimitQuantity()); + attr.setData(jsonObject.toJSONString()); + } + //市场价 系统对应 非必填 +// else if("market_price".equals(attr.getKey())){ +// attr.setData(coupon.getPrice().toString()); +// } + //收款方式 测试一下1-总店结算 2-分店结算 + else if("settle_type".equals(attr.getKey())){ + attr.setData("1"); + } + //团购使用方式 1-到店核销 + else if("use_type".equals(attr.getKey())){ + attr.setData("1"); + } + + } + } + } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java index e238863e5..003b027a2 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java @@ -546,6 +546,7 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { return false; } + @Override public WxCouponChannelAddVo addCouponChannel(Long couponid,Integer channelId, TenantEntity tenantEntity,Date showBeginTime,Date beginTime,Date endTime,Integer channelPrice,Integer channelStock){ WxCouponChannelAddVo vo = new WxCouponChannelAddVo(); @@ -603,10 +604,13 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { // 投放渠道 if(channelId.equals(EnumCouponChannelType.COUPON_CHANNEL_ID_LIST.getCode()) || // 列表 + channelId.equals(EnumCouponChannelType.COUPON_CHANNEL_ID_CARD.getCode()) || // 卡频道 channelId.equals(EnumCouponChannelType.COUPON_CHANNEL_ID_PRESS.getCode()) || // 砍价 channelId.equals(EnumCouponChannelType.COUPON_CHANNEL_ID_ORDER_GROUP.getCode()) || // 拼团 channelId.equals(EnumCouponChannelType.COUPON_CHANNEL_ID_CREDIT.getCode()) || // 积分商城 + channelId.equals(EnumCouponChannelType.COUPON_CHANNEL_ID_DOUYIN_SAVE_LIST.getCode()) || + channelId.equals(EnumCouponChannelType.COUPON_CHANNEL_ID_DOUYIN_LIST.getCode()) || channelId.equals(EnumCouponChannelType.COUPON_CHANNEL_ID_WXLIVE_LIST.getCode()) //微信直播列表 ){ // 默认投放结束时间为有效时间之后 diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java index d6ff57a49..98f627467 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -19,6 +19,9 @@ import com.iformall.domain.vo.*; import com.iformall.domain.vo.excel.WxCardData; import com.iformall.domain.vo.excel.WxCouponData; import com.iformall.domain.vo.excel.WxPressData; +import com.iformall.douyin.web.api.TtWebService; +import com.iformall.douyin.web.bean.GoodsTemplateGet; +import com.iformall.douyin.web.bean.Product; import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.mapper.*; @@ -28,6 +31,8 @@ import com.iformall.service.excel.WxCardDataExporter; import com.iformall.service.excel.WxCouponDataExporter; import com.iformall.service.excel.WxPressDataExporter; +import com.iformall.utils.Constant; +import me.chanjar.weixin.common.error.WxErrorException; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -123,6 +128,15 @@ public class WxCouponServiceImpl implements WxCouponService { @Autowired WxProfitSharingReceiverMapper wxProfitSharingReceiverMapper; + @Autowired + private TtMerchantPoiService ttMerchantPoiService; + + @Autowired + private TtGoodsCategoryService ttGoodsCategoryService; + + @Autowired + TtCouponChannelPoiMapper ttCouponChannelPoiMapper; + @Autowired private MqBaseProducer mqBaseProducer; @@ -349,16 +363,16 @@ public class WxCouponServiceImpl implements WxCouponService { if (StringUtils.isNotEmpty(record.getSubsidyNumStr())) { record.setSubsidyNum(new BigDecimal(record.getSubsidyNumStr()).multiply(new BigDecimal(100)).intValue()); } - if (EnumCouponType.COUPON_DOUYIN.getCode().equals(record.getType())){ - if(StringUtils.isBlank(record.getItemGroup())){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"团购详情不能为"); - } - try{ - JSON.parseArray(record.getItemGroup()); - }catch(Exception e){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"团购详情格式不正确"); - } - } +// if (EnumCouponType.COUPON_DOUYIN.getCode().equals(record.getType())){ +// if(StringUtils.isBlank(record.getItemGroup())){ +// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"团购详情不能为"); +// } +// try{ +// JSON.parseArray(record.getItemGroup()); +// }catch(Exception e){ +// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"团购详情格式不正确"); +// } +// } if (StringUtils.isBlank(record.getCoverPicture())) { List strList = new ArrayList(); if (StringUtils.isNotBlank(record.getCoverImg())) { @@ -644,6 +658,30 @@ public class WxCouponServiceImpl implements WxCouponService { @Override public ResultData updateTtProduct(WxCoupon record) { + if(StringUtils.isBlank(record.getProductAttrs()) || StringUtils.isBlank(record.getSkuAttrs())){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); + } + try{ + List productAttrs = JSONObject.parseArray(record.getProductAttrs(), GoodsTemplateGet.ProductAttrs.class); + List skuAttrs = JSONObject.parseArray(record.getSkuAttrs(), GoodsTemplateGet.ProductAttrs.class); + ttGoodsCategoryService.handDefaultAttr(record,productAttrs,skuAttrs); + for (GoodsTemplateGet.ProductAttrs attr:productAttrs) { + attr.setIsShow(null); + if(attr.getIsRequired() && StringUtils.isBlank(attr.getData())){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"product属性" +attr.getName()+" 为空"); + } + } + record.setProductAttrs(JSONObject.toJSONString(productAttrs)); + for (GoodsTemplateGet.ProductAttrs attr:skuAttrs) { + attr.setIsShow(null); + if(attr.getIsRequired() && StringUtils.isBlank(attr.getData())){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"sku属性 "+attr.getName()+" 为空"); + } + } + record.setSkuAttrs(JSONObject.toJSONString(skuAttrs)); + }catch(Exception e){ + return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR); + } WxCoupon coupon = new WxCoupon(); coupon.setId(record.getId()); coupon.updateTenantInfo(record); @@ -1153,5 +1191,104 @@ public class WxCouponServiceImpl implements WxCouponService { return merchantList; } + @Override + @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) + public ResultData productSave(WxCoupon coupon) { + if(coupon.getProductType() == null || coupon.getCategoryId() == null + || coupon.getProductAttrKeyValueMap().isEmpty() + || coupon.getSkuAttrKeyValueMap().isEmpty()){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"该券缺少必要属性"); + } + //添加到审核渠道 + WxCouponChannelAddVo wxCouponChannelAddVo = wxCouponChannelService.addCouponChannel(coupon.getId(), EnumCouponChannelType.COUPON_CHANNEL_ID_DOUYIN_SAVE_LIST.getCode(), + coupon, null, null, null, null, null); + + //提交审核 + try { + List couponMerchantList = getCouponMerchantList(coupon, coupon.getId()); + List merchantList = couponMerchantList.stream().sorted(Comparator.comparing(m -> m.getTtPoi(), Comparator.nullsLast(String::compareTo))).collect(toList()); + + TtWebService ttWebService = ttMerchantPoiService.getTtWebService(coupon); + Product product = new Product(); + Product.ProductStruct prostruct = new Product.ProductStruct(); + prostruct.setOutId(coupon.getId().toString()); + prostruct.setProductName(coupon.getTitle()); + prostruct.setCategoryId(coupon.getCategoryId()); + prostruct.setProductType(coupon.getProductType()); + prostruct.setBizLine(5);//默认小程序 + prostruct.setAccountName(merchantList.get(0).getMerchantName()); + // prostruct.setSoldStartTime(); + // prostruct.setSoldEndTime(); + prostruct.setOutUrl(getGoodsEntrySchema(ttWebService.getTtWebConfig().getAppid(),wxCouponChannelAddVo.getId())); + List poiList = new ArrayList(); + for (WxMerchantVo mvo:merchantList){ + Product.PoiStruct poiStruct = new Product.PoiStruct(); + poiStruct.setSupplierExtId(mvo.getId().toString()); + poiList.add(poiStruct); + } + prostruct.setPoiList(poiList); + prostruct.setAttrKeyValueMap(coupon.getProductAttrKeyValueMap()); + product.setProduct(prostruct); + + Product.SkuStruct skuStruct = new Product.SkuStruct(); + skuStruct.setSkuName(coupon.getTitle()); + skuStruct.setOriginAmount(coupon.getPrice()); + skuStruct.setActualAmount(coupon.getSalePrice()); + Product.StockStruct stockStruct = new Product.StockStruct(); + stockStruct.setLimitType(1); + stockStruct.setStockQty(coupon.getInventory()); + skuStruct.setStock(stockStruct); + skuStruct.setStatus(1); + skuStruct.setAttrKeyValueMap(coupon.getSkuAttrKeyValueMap()); + product.setSku(skuStruct); + + String productId = ttWebService.getGoodsService().productSave(product); + syncCouponChannelPoi(coupon,wxCouponChannelAddVo.getId(),productId); + return new ResultData(); + + } catch (WxErrorException e) { + logger.error(e.getMessage()); + return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); + } catch (Exception e){ + logger.error(e.getMessage()); + return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); + } + } + + private void syncCouponChannelPoi(WxCoupon coupon,Long couponChannelId,String productId){ + TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(coupon.getId()); + Date date = new Date(); + if(ttCouponChannelPoi != null){ + ttCouponChannelPoi.setCouponChannelId(couponChannelId); + ttCouponChannelPoi.setSpuId(productId); + ttCouponChannelPoi.setStatus(EnumSpuSyncStatus.sync_auditing.getCode()); + ttCouponChannelPoi.setLastStatus(EnumSpuSyncStatus.sync_auditing.getCode()); + ttCouponChannelPoi.setLastStatusDesc(""); + ttCouponChannelPoi.setUpdateDate(date); + ttCouponChannelPoiMapper.updateById(ttCouponChannelPoi); + }else{ + ttCouponChannelPoi = new TtCouponChannelPoi(); + ttCouponChannelPoi.setId(coupon.getId()); + ttCouponChannelPoi.updateTenantInfo(coupon); + ttCouponChannelPoi.setCouponChannelId(couponChannelId); + ttCouponChannelPoi.setSpuId(productId); + ttCouponChannelPoi.setStatus(EnumSpuSyncStatus.sync_auditing.getCode()); + ttCouponChannelPoi.setLastStatus(EnumSpuSyncStatus.sync_auditing.getCode()); + ttCouponChannelPoi.setCreateDate(date); + ttCouponChannelPoi.setUpdateDate(date); + ttCouponChannelPoiMapper.insert(ttCouponChannelPoi); + } + } + + private String getGoodsEntrySchema(String appid,Long couponChannelId){ + Map map = new HashMap<>(); + map.put("app_id",appid); + map.put("path", Constant.mainPageUrl); + Map paramMap = new HashMap<>(); + paramMap.put("type","cd"); + paramMap.put("couponChannelId",couponChannelId); + map.put("params",JSON.toJSONString(paramMap)); + return JSON.toJSONString(map); + } }