| @@ -0,0 +1,158 @@ | |||
| package com.iformall.controller.market; | |||
| import com.iformall.annotation.SystemControllerLog; | |||
| import com.iformall.annotation.TenantIgnore; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.vo.TtCouponChannelVo; | |||
| import com.iformall.domain.vo.TtCouponVo; | |||
| import com.iformall.domain.vo.WxCouponChannelVo; | |||
| import com.iformall.douyin.web.bean.GoodsTemplateGet; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.service.*; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| 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.*; | |||
| @RestController | |||
| @RequestMapping("ttgoods") | |||
| @Api(description = "抖音商品库") | |||
| public class TtCouponGoodsController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxCouponService wxCouponService; | |||
| @Autowired | |||
| private TtCouponGoodsService ttCouponGoodsService; | |||
| @Autowired | |||
| private TtMerchantPoiService ttMerchantPoiService; | |||
| @Autowired | |||
| private TtGoodsCategoryService ttGoodsCategoryService; | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("couponList") | |||
| @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 couponList(@ModelAttribute TtCouponVo ttCouponVo, Integer pageNum, Integer pageSize) { | |||
| logger.debug("[" + getIpAddr() + "] WxCouponController::couponList"); | |||
| if (ttCouponVo == null) ttCouponVo = new TtCouponVo(); | |||
| ttCouponVo.updateTenantInfo(getTenantInfo()); | |||
| ttCouponVo.setType(EnumCouponType.COUPON_DOUYIN.getCode()); | |||
| if(StringUtils.isNotBlank(ttCouponVo.getSortColumn())){ | |||
| String coryColumn = "c."+ttCouponVo.getSortColumns(); | |||
| ttCouponVo.setSortColumns(coryColumn); | |||
| ttCouponVo.setSortColumn(null); | |||
| } | |||
| if (ttCouponVo.getStatus() != null && ttCouponVo.getStatus() == -1) | |||
| ttCouponVo.setStatus(null); | |||
| return ttCouponGoodsService.couponList(ttCouponVo, pageNum, pageSize); | |||
| } | |||
| // @ApiOperation("分页列表接口") | |||
| // @GetMapping("channelList") | |||
| // @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 channelList(@ModelAttribute TtCouponChannelVo ttChannelVo, Integer pageNum, Integer pageSize) { | |||
| // logger.debug("[" + getIpAddr() + "] WxCouponController::channelList"); | |||
| // if (ttChannelVo == null) ttChannelVo = new TtCouponChannelVo(); | |||
| // if (ttChannelVo.getStatus() != null && ttChannelVo.getStatus() == -1) { | |||
| // ttChannelVo.setStatus(null); | |||
| // } | |||
| // ttChannelVo.updateTenantInfo(getTenantInfo()); | |||
| // ttCouponVo.setType(EnumCouponType.COUPON_DOUYIN.getCode()); | |||
| // if(StringUtils.isNotBlank(ttCouponVo.getSortColumn())){ | |||
| // String coryColumn = "c."+ttCouponVo.getSortColumns(); | |||
| // ttCouponVo.setSortColumns(coryColumn); | |||
| // ttCouponVo.setSortColumn(null); | |||
| // } | |||
| // if (ttCouponVo.getStatus() != null && ttCouponVo.getStatus() == -1) | |||
| // ttCouponVo.setStatus(null); | |||
| // return ttCouponGoodsService.channelList(ttCouponVo, pageNum, pageSize); | |||
| // } | |||
| @ApiOperation("根据类目获取商品模板") | |||
| @GetMapping("getTemplate") | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| @SystemControllerLog(description = "根据类目获取商品模板") | |||
| public ResultData getGoodsTemplate(Long couponId,Integer categoryId,Integer productType) { | |||
| logger.debug("[" + getIpAddr() + "] WxCouponController::getGoodsTemplate"); | |||
| if(productType == null){ | |||
| productType = 1; | |||
| } | |||
| if(couponId == null){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| WxCoupon coupon = wxCouponService.getAttrsById(couponId, getTenantInfo().getTenantId()); | |||
| if(coupon == null){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| try { | |||
| GoodsTemplateGet goodsTemplateGet = ttMerchantPoiService.getTtWebService(getTenantInfo()).getGoodsService().templateGet(categoryId, productType); | |||
| ttGoodsCategoryService.adminIsShow(goodsTemplateGet); | |||
| ttGoodsCategoryService.handTemplate(goodsTemplateGet,coupon); | |||
| return new ResultData(goodsTemplateGet); | |||
| } catch (WxErrorException e) { | |||
| e.printStackTrace(); | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| @ApiOperation("提交审核") | |||
| @PostMapping("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); | |||
| } | |||
| try { | |||
| return ttCouponGoodsService.productSave(coupon); | |||
| } catch (Exception e) { | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| @ApiOperation("实时查询审核状态") | |||
| @GetMapping("product/draft") | |||
| @SystemControllerLog(description = "实时查询审核状态") | |||
| public ResultData productDraft(Long id) { | |||
| if (id == null) { | |||
| return new ResultData(ResultData.ERROR, "缺少id"); | |||
| } | |||
| return ttCouponGoodsService.productDraftGet(id); | |||
| } | |||
| @ApiOperation("实时查询线上商品状态") | |||
| @GetMapping("product/online") | |||
| @SystemControllerLog(description = "实时查询审核状态") | |||
| public ResultData productOnline(Long id) { | |||
| if (id == null) { | |||
| return new ResultData(ResultData.ERROR, "缺少id"); | |||
| } | |||
| return ttCouponGoodsService.productOnlineGet(id); | |||
| } | |||
| } | |||
| @@ -59,38 +59,12 @@ public class WxCouponController extends BaseController { | |||
| @Autowired | |||
| private WxMallService wxMallService; | |||
| @Autowired | |||
| private TtMerchantPoiService ttMerchantPoiService; | |||
| @Autowired | |||
| private TtGoodsCategoryService ttGoodsCategoryService; | |||
| @Autowired | |||
| RedisLock redisLock; | |||
| @Autowired | |||
| @Qualifier("objectCommonRedisTemplate") | |||
| RedisTemplate<String, Object> redisTemplate; | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("ttgoodslist") | |||
| @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 ttgoodslist(@ModelAttribute TtCouponVo ttCouponVo, Integer pageNum, Integer pageSize) { | |||
| logger.debug("[" + getIpAddr() + "] WxCouponController::ttgoodslist"); | |||
| if (ttCouponVo == null) ttCouponVo = new TtCouponVo(); | |||
| ttCouponVo.updateTenantInfo(getTenantInfo()); | |||
| ttCouponVo.setType(EnumCouponType.COUPON_DOUYIN.getCode()); | |||
| if(StringUtils.isNotBlank(ttCouponVo.getSortColumn())){ | |||
| String coryColumn = "c."+ttCouponVo.getSortColumns(); | |||
| ttCouponVo.setSortColumns(coryColumn); | |||
| ttCouponVo.setSortColumn(null); | |||
| } | |||
| if (ttCouponVo.getStatus() != null && ttCouponVo.getStatus() == -1) | |||
| ttCouponVo.setStatus(null); | |||
| return wxCouponService.ttgoodslist(ttCouponVo, pageNum, pageSize); | |||
| } | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @@ -607,72 +581,4 @@ public class WxCouponController extends BaseController { | |||
| return result; | |||
| } | |||
| @ApiOperation("根据类目获取商品模板") | |||
| @GetMapping("/goods/getTemplate") | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| @SystemControllerLog(description = "根据类目获取商品模板") | |||
| public ResultData getGoodsTemplate(Long couponId,Integer categoryId,Integer productType) { | |||
| logger.debug("[" + getIpAddr() + "] WxCouponController::getGoodsTemplate"); | |||
| if(productType == null){ | |||
| productType = 1; | |||
| } | |||
| if(couponId == null){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| WxCoupon coupon = wxCouponService.getAttrsById(couponId, getTenantInfo().getTenantId()); | |||
| if(coupon == null){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| try { | |||
| GoodsTemplateGet goodsTemplateGet = ttMerchantPoiService.getTtWebService(getTenantInfo()).getGoodsService().templateGet(categoryId, productType); | |||
| ttGoodsCategoryService.adminIsShow(goodsTemplateGet); | |||
| ttGoodsCategoryService.handTemplate(goodsTemplateGet,coupon); | |||
| return new ResultData(goodsTemplateGet); | |||
| } catch (WxErrorException e) { | |||
| e.printStackTrace(); | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| @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); | |||
| } | |||
| try { | |||
| return wxCouponService.productSave(coupon); | |||
| } catch (Exception e) { | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| @ApiOperation("实时查询审核状态") | |||
| @GetMapping("/goods/product/draft") | |||
| @SystemControllerLog(description = "实时查询审核状态") | |||
| public ResultData productDraft(Long id) { | |||
| if (id == null) { | |||
| return new ResultData(ResultData.ERROR, "缺少id"); | |||
| } | |||
| return wxCouponService.productDraftGet(id); | |||
| } | |||
| @ApiOperation("实时查询线上商品状态") | |||
| @GetMapping("/goods/product/online") | |||
| @SystemControllerLog(description = "实时查询审核状态") | |||
| public ResultData productOnline(Long id) { | |||
| if (id == null) { | |||
| return new ResultData(ResultData.ERROR, "缺少id"); | |||
| } | |||
| return wxCouponService.productOnlineGet(id); | |||
| } | |||
| } | |||
| @@ -1,14 +1,12 @@ | |||
| package com.iformall.controller.callback; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.TtCouponChannelPoi; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.enums.EnumSpuSyncStatus; | |||
| import com.iformall.service.MailService; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.WxCouponChannelService; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.DateUtils; | |||
| import me.chanjar.weixin.common.util.crypto.SHA1; | |||
| import org.slf4j.Logger; | |||
| @@ -38,7 +36,7 @@ public class TtWebController extends BaseController { | |||
| private WxAppinfoService wxAppinfoService; | |||
| @Autowired | |||
| private WxCouponService wxCouponService; | |||
| private TtCouponGoodsService ttCouponGoodsService; | |||
| /** | |||
| * { | |||
| @@ -63,7 +61,6 @@ public class TtWebController extends BaseController { | |||
| resultMap.put("err_tips","error"); | |||
| return resultMap; | |||
| } | |||
| Map<String,Object> content = (HashMap) parameterMap.get("content"); | |||
| String header = request.getHeader("X-Douyin-Signature"); | |||
| String sha1gen = SHA1.gen(appInfo.getSecret(), JSON.toJSONString(parameterMap)); | |||
| @@ -80,14 +77,21 @@ public class TtWebController extends BaseController { | |||
| //发送邮件 | |||
| mailService.sendSimpleMail(receivers, "抖音开放平台通知", sb.toString()); | |||
| String content = (String) parameterMap.get("content"); | |||
| JSONObject jsonObject = JSON.parseObject(content); | |||
| if("verify_webhook".equals(event)){ | |||
| String challenge = (String) content.get("challenge"); | |||
| String challenge = jsonObject.getString("challenge"); | |||
| // String challenge = (String) content.get("challenge"); | |||
| resultMap.put("challenge",challenge); | |||
| return resultMap; | |||
| }else if("life_goods_audit".equals(event)){ | |||
| String product_id = content.get("product_id").toString(); | |||
| String reason = (String) content.get("reason"); | |||
| String status = (String) content.get("status"); | |||
| String product_id = jsonObject.getString("product_id"); | |||
| String reason = jsonObject.getString("reason"); | |||
| String status = jsonObject.getString("status"); | |||
| // String product_id = content.get("product_id").toString(); | |||
| // String reason = (String) content.get("reason"); | |||
| // String status = (String) content.get("status"); | |||
| TtCouponChannelPoi couponChannelPoi = new TtCouponChannelPoi(); | |||
| couponChannelPoi.updateTenantInfo(appInfo); | |||
| @@ -105,7 +109,7 @@ public class TtWebController extends BaseController { | |||
| resultMap.put("err_tips","error"); | |||
| return resultMap; | |||
| } | |||
| wxCouponService.handlerTtGoodsAudit(couponChannelPoi); | |||
| ttCouponGoodsService.handlerTtGoodsAudit(couponChannelPoi); | |||
| resultMap.put("err_code",0); | |||
| resultMap.put("err_tips","success"); | |||
| return resultMap; | |||
| @@ -0,0 +1,204 @@ | |||
| package com.iformall.domain.vo; | |||
| import com.baomidou.mybatisplus.annotation.TableField; | |||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| import java.io.Serializable; | |||
| import java.math.BigDecimal; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| /** | |||
| * Created by syf on 2018/8/22. | |||
| */ | |||
| @JsonIgnoreProperties(value = {"handler"}) | |||
| @Data | |||
| @ToString(callSuper = true) | |||
| @EqualsAndHashCode(callSuper = true) | |||
| public class TtCouponChannelVo extends WxCouponChannel implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @TableField(exist = false) | |||
| private Integer activityStatus; | |||
| @io.swagger.annotations.ApiModelProperty(value="总库存",name="inventory") | |||
| private Integer inventory; | |||
| @io.swagger.annotations.ApiModelProperty(value="剩余库存",name="remainInventory") | |||
| private Integer remainInventory; | |||
| @io.swagger.annotations.ApiModelProperty(value="封面图",name="coverImg") | |||
| private String coverImg; | |||
| @io.swagger.annotations.ApiModelProperty(value="券名称",name="title") | |||
| private String title; | |||
| @io.swagger.annotations.ApiModelProperty(value="副标题",name="subTitle") | |||
| private String subTitle; | |||
| @io.swagger.annotations.ApiModelProperty(value="售价(适用于类型2,3,4,5)",name="salePrice") | |||
| private Integer salePrice; | |||
| @io.swagger.annotations.ApiModelProperty(value="使用条件金额(适用于类型1,2,3,4)",name="usePrice") | |||
| private Integer usePrice; | |||
| @io.swagger.annotations.ApiModelProperty(value="面额",name="price") | |||
| private Integer price; | |||
| @io.swagger.annotations.ApiModelProperty(value="尾款(适用于类型9)",name="tailPrice") | |||
| private Integer tailPrice; | |||
| @io.swagger.annotations.ApiModelProperty(value="原价(适用于类型9)",name="origPrice") | |||
| private Integer origPrice; | |||
| @io.swagger.annotations.ApiModelProperty(value="单位0:钱分,1:小时",name="unit") | |||
| private Integer unit; | |||
| //EnumCouponUseLimitRule | |||
| @io.swagger.annotations.ApiModelProperty(value="限领规则",name="useLimitRule") | |||
| private Integer useLimitRule; | |||
| @io.swagger.annotations.ApiModelProperty(value="限领张数",name="useLimitQuantity") | |||
| private Integer useLimitQuantity; | |||
| @io.swagger.annotations.ApiModelProperty(value="1.主动领取2.定向投放",name="sendType") | |||
| private Integer sendType; | |||
| @io.swagger.annotations.ApiModelProperty(value="过期退款(0:正常,1不退)",name="autoRefund") | |||
| private Integer autoRefund; | |||
| @io.swagger.annotations.ApiModelProperty(value="有效时间类型1.时间范围(valid_start_date,valid_end_date). 2领取后几日有效(valid_days)",name="validType") | |||
| private Integer validType; | |||
| @io.swagger.annotations.ApiModelProperty(value="有效日期-开始",name="validStartDate") | |||
| private Date validStartDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="有效日期-结束",name="validEndDate") | |||
| private Date validEndDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="自领取之日几日有效,(停车券当天有效)",name="validDays") | |||
| private Integer validDays; | |||
| @io.swagger.annotations.ApiModelProperty(value="有效日期-开始",name="pickStartDate") | |||
| private Date pickStartDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="有效日期-结束",name="pickEndDate") | |||
| private Date pickEndDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="积分售价(适用于类型10,11)",name="creditPrice") | |||
| private Integer creditPrice; | |||
| @io.swagger.annotations.ApiModelProperty(value="领取条件",name="condition") | |||
| private String conditions; | |||
| @io.swagger.annotations.ApiModelProperty(value="内容类型(0:小程序页面类型,1:富文本类型)",name="contentType") | |||
| private Integer contentType; | |||
| @TableField(exist = false) | |||
| private String detail; | |||
| @TableField(exist = false) | |||
| private String salePriceStr; | |||
| @TableField(exist = false) | |||
| private String usePriceStr; | |||
| @TableField(exist = false) | |||
| private String priceStr; | |||
| @TableField(exist = false) | |||
| private String tailPriceStr; | |||
| @TableField(exist = false) | |||
| private String origPriceStr; | |||
| @TableField(exist = false) | |||
| private String qrCode; | |||
| @io.swagger.annotations.ApiModelProperty(value="商户列表",name="merchantVoList") | |||
| private List<WxMerchantVo> merchantVoList; | |||
| @TableField(exist = false) | |||
| private Integer gameWeight; | |||
| @io.swagger.annotations.ApiModelProperty(value = "是否可转赠", name = "supportTransfer") | |||
| private Integer supportTransfer; | |||
| @io.swagger.annotations.ApiModelProperty(value = "砍价/拼团人数", name = "pressLimitNum") | |||
| private Integer pressLimitNum; | |||
| @Override | |||
| public String getSalePriceStr() { | |||
| if(salePrice!=null) { | |||
| salePriceStr = new BigDecimal(salePrice).divide(new BigDecimal(100)).toString(); | |||
| } | |||
| return salePriceStr; | |||
| } | |||
| @Override | |||
| public String getUsePriceStr() { | |||
| if(usePrice!=null) { | |||
| usePriceStr = new BigDecimal(usePrice).divide(new BigDecimal(100)).toString(); | |||
| } | |||
| return usePriceStr; | |||
| } | |||
| @Override | |||
| public String getPriceStr() { | |||
| if(price!=null) { | |||
| priceStr = new BigDecimal(price).divide(new BigDecimal(100)).toString(); | |||
| } | |||
| return priceStr; | |||
| } | |||
| public String getTailPriceStr() { | |||
| if(tailPrice!=null) { | |||
| tailPriceStr = new BigDecimal(tailPrice).divide(new BigDecimal(100)).toString(); | |||
| } | |||
| return tailPriceStr; | |||
| } | |||
| public String getOrigPriceStr() { | |||
| if(origPrice!=null) { | |||
| origPriceStr = new BigDecimal(origPrice).divide(new BigDecimal(100)).toString(); | |||
| } | |||
| return origPriceStr; | |||
| } | |||
| @Override | |||
| public String getTitle() { | |||
| return title; | |||
| } | |||
| @Override | |||
| public void setTitle(String title) { | |||
| this.title = title; | |||
| } | |||
| /** | |||
| * 可能字段不全, 使用时先确认 | |||
| * @param c | |||
| */ | |||
| public void setWxCoupon(WxCoupon c){ | |||
| if(c != null){ | |||
| this.setRemainInventory(c.getRemainInventory()); | |||
| this.setSalePrice(c.getSalePrice()); | |||
| this.setInventory(c.getInventory()); | |||
| this.setCoverImg(c.getCoverImg()); | |||
| this.setSubTitle(c.getSubTitle()); | |||
| this.setUsePrice(c.getUsePrice()); | |||
| this.setPrice(c.getPrice()); | |||
| this.setTailPrice(c.getTailPrice()); | |||
| this.setOrigPrice(c.getOrigPrice()); | |||
| this.setUnit(c.getUnit()); | |||
| this.setUseLimitRule(c.getUseLimitRule()); | |||
| this.setUseLimitQuantity(c.getUseLimitQuantity()); | |||
| this.setSendType(c.getSendType()); | |||
| this.setSupportTransfer(c.getSupportTransfer()); | |||
| this.setPressLimitNum(c.getPressLimitNum()); | |||
| this.setAutoRefund(c.getAutoRefund()); | |||
| this.setConditions(c.getConditions()); | |||
| this.setValidType(c.getValidType()); | |||
| this.setValidStartDate(c.getValidStartDate()); | |||
| this.setValidEndDate(c.getValidEndDate()); | |||
| this.setPickStartDate(c.getPickStartDate()); | |||
| this.setPickEndDate(c.getPickEndDate()); | |||
| this.setValidDays(c.getValidDays()); | |||
| this.setCreditPrice(c.getCreditPrice()); | |||
| this.setContentType(c.getContentType()); | |||
| this.setSourceType(c.getSourceType()); | |||
| } | |||
| } | |||
| } | |||
| @@ -122,5 +122,5 @@ public interface WxCouponMapper extends CommonMapper<WxCoupon, Long> { | |||
| List<Long> findIdsListHasConditons(WxCoupon couponQ); | |||
| List<TtCouponVo> ttgoodslist(TtCouponVo ttCouponVo); | |||
| List<TtCouponVo> ttCouponList(TtCouponVo ttCouponVo); | |||
| } | |||
| @@ -0,0 +1,21 @@ | |||
| package com.iformall.service; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.TtCouponChannelPoi; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.vo.TtCouponVo; | |||
| public interface TtCouponGoodsService { | |||
| ResultData couponList(TtCouponVo ttCouponVo, Integer pageNum, Integer pageSize); | |||
| ResultData productSave(WxCoupon coupon) throws Exception; | |||
| int handlerTtGoodsAudit(TtCouponChannelPoi couponChannelPoi); | |||
| ResultData productDraftGet(Long id); | |||
| ResultData productOnlineGet(Long id); | |||
| } | |||
| @@ -17,8 +17,6 @@ import com.iformall.domain.vo.WxMerchantVo; | |||
| public interface WxCouponService { | |||
| ResultData ttgoodslist(TtCouponVo ttCouponVo, Integer pageNum, Integer pageSize); | |||
| ResultData list(TenantEntity tenantEntity,WxCoupon wxCoupon, Integer pageNum, Integer pageSize); | |||
| List<WxCoupon> list(WxCoupon wxCoupon); | |||
| @@ -277,13 +275,4 @@ public interface WxCouponService { | |||
| List<WxMerchantVo> getCouponMerchantList(TenantEntity tenantInfo, Long couponId); | |||
| ResultData productSave(WxCoupon coupon) throws Exception; | |||
| int handlerTtGoodsAudit(TtCouponChannelPoi couponChannelPoi); | |||
| ResultData productDraftGet(Long id); | |||
| ResultData productOnlineGet(Long id); | |||
| } | |||
| @@ -0,0 +1,319 @@ | |||
| package com.iformall.service.impl; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.*; | |||
| import com.iformall.douyin.web.api.TtWebService; | |||
| import com.iformall.douyin.web.bean.Product; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.Constant; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Isolation; | |||
| import org.springframework.transaction.annotation.Propagation; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import java.util.*; | |||
| import java.util.stream.Collectors; | |||
| import static java.util.stream.Collectors.toList; | |||
| @Service | |||
| public class TtCouponGoodsServiceImpl implements TtCouponGoodsService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| WxCouponMapper wxCouponMapper; | |||
| @Autowired | |||
| WxCouponService wxCouponService; | |||
| @Autowired | |||
| WxCouponChannelMapper wxCouponChannelMapper; | |||
| @Autowired | |||
| private TtMerchantPoiService ttMerchantPoiService; | |||
| @Autowired | |||
| TtCouponChannelPoiMapper ttCouponChannelPoiMapper; | |||
| @Autowired | |||
| WxAppinfoService wxAppinfoService; | |||
| @Override | |||
| public ResultData couponList(TtCouponVo ttCouponVo, Integer pageNum, Integer pageSize) { | |||
| if(StringUtils.isBlank(ttCouponVo.getSortColumns())){ | |||
| ttCouponVo.setSortColumns(BaseEntity.SortField.CCreateDate_DESC, BaseEntity.SortField.CId_DESC); | |||
| } | |||
| PageInfo<TtCouponVo> pageInfo = PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCouponMapper.ttCouponList(ttCouponVo)); | |||
| List<TtCouponVo> couponList = pageInfo.getList(); | |||
| if(!couponList.isEmpty()){ | |||
| List<Long> ids = couponList.stream().map(p -> p.getId()).collect(toList()); | |||
| WxCouponChannel wxCouponChannel = new WxCouponChannel(); | |||
| wxCouponChannel.updateTenantInfo(ttCouponVo); | |||
| wxCouponChannel.setCouponIds(ids); | |||
| wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); | |||
| //上架状态 | |||
| List<WxCouponChannel> list = wxCouponChannelMapper.findList(wxCouponChannel); | |||
| if (!list.isEmpty()) { | |||
| Map<Long, List<WxCouponChannel>> groupBy = list.stream().collect(Collectors.groupingBy(WxCouponChannel::getCouponId)); | |||
| for (TtCouponVo temp : couponList) { | |||
| if (groupBy.get(temp.getId()) != null) { | |||
| List<Integer> channels = new ArrayList<>(); | |||
| for (WxCouponChannel tempchannel : groupBy.get(temp.getId())) { | |||
| if (!channels.contains(tempchannel.getTargetAd())) { | |||
| channels.add(tempchannel.getTargetAd()); | |||
| } | |||
| } | |||
| String sss = JSON.toJSONString(channels); | |||
| temp.setChannels(sss); | |||
| } else { | |||
| temp.setChannels(""); | |||
| } | |||
| } | |||
| } else { | |||
| for (TtCouponVo temp : couponList) { | |||
| temp.setChannels(""); | |||
| } | |||
| } | |||
| } | |||
| return new ResultData(pageInfo); | |||
| } | |||
| @Override | |||
| @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) | |||
| public ResultData productSave(WxCoupon coupon) throws Exception { | |||
| WxCoupon ttattrs = wxCouponService.getAttrsById(coupon.getId(), coupon.getTenantId()); | |||
| if(ttattrs.getProductType() == null || ttattrs.getCategoryId() == null | |||
| || ttattrs.getProductAttrKeyValueMap().isEmpty() | |||
| || ttattrs.getSkuAttrKeyValueMap().isEmpty()){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"该券缺少必要属性"); | |||
| } | |||
| if(coupon.getStatus() != EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()) { | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_INVALID); | |||
| } | |||
| //获取门店 | |||
| List<WxMerchantVo> couponMerchantList = wxCouponService.getCouponMerchantList(coupon, coupon.getId()); | |||
| List<Product.PoiStruct> poiList = new ArrayList(); | |||
| for (WxMerchantVo mvo:couponMerchantList){ | |||
| if(StringUtils.isNotBlank(mvo.getSupplierExtId())){ | |||
| Product.PoiStruct poiStruct = new Product.PoiStruct(); | |||
| poiStruct.setSupplierExtId(mvo.getSupplierExtId()); | |||
| poiList.add(poiStruct); | |||
| } | |||
| } | |||
| if(poiList.isEmpty()){ | |||
| return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"未找到poi门店"); | |||
| } | |||
| //查询是否有上架的 | |||
| WxCouponChannel wxCouponChannelQuery = new WxCouponChannel(); | |||
| wxCouponChannelQuery.updateTenantInfo(coupon); | |||
| wxCouponChannelQuery.setCouponId(coupon.getId()); | |||
| wxCouponChannelQuery.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_DOUYIN_LIST.getCode()); | |||
| wxCouponChannelQuery.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); | |||
| List<WxCouponChannel> wxCouponChannels = wxCouponChannelMapper.findList(wxCouponChannelQuery); | |||
| if(wxCouponChannels.size() > 0){ | |||
| return new ResultData(ErrorCode.COUPON_CHANNEL_IS_EXISTED); | |||
| } | |||
| //预审核的作废掉 重新投放 | |||
| wxCouponChannelQuery.setStatus(EnumCouponChannelStatus.STATUS_BEFORE.getCode()); | |||
| WxCouponChannel updCouponChannel = new WxCouponChannel(); | |||
| updCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_AFTER.getCode()); | |||
| updCouponChannel.setUpdateDate(new Date()); | |||
| wxCouponChannelMapper.update(updCouponChannel,new QueryWrapper<>(wxCouponChannelQuery)); | |||
| //投放预审核 | |||
| WxCouponChannel wxCouponChannel = new WxCouponChannel(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| wxCouponChannel.setId(idWorker.nextId()); | |||
| wxCouponChannel.updateTenantInfo(coupon); | |||
| wxCouponChannel.setShowBeginTime(new Date()); | |||
| wxCouponChannel.setBeginTime(new Date()); | |||
| wxCouponChannel.setEndTime(coupon.getValidEndDate()); | |||
| wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_AFTER.getCode()); | |||
| wxCouponChannel.setCouponId(coupon.getId()); | |||
| wxCouponChannel.setType(coupon.getType()); | |||
| wxCouponChannel.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_DOUYIN_LIST.getCode()); | |||
| wxCouponChannel.setBusiness(coupon.getBusiness()); | |||
| wxCouponChannel.setSubBusiness(coupon.getSubBusiness()); | |||
| wxCouponChannel.setTitle(coupon.getTitle()); | |||
| wxCouponChannelMapper.insert(wxCouponChannel); | |||
| //提交审核 | |||
| try { | |||
| 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(ttattrs.getCategoryId()); | |||
| prostruct.setProductType(ttattrs.getProductType()); | |||
| prostruct.setBizLine(5);//默认小程序 | |||
| prostruct.setAccountName(couponMerchantList.get(0).getMerchantName()); | |||
| // prostruct.setSoldStartTime(); | |||
| // prostruct.setSoldEndTime(); | |||
| prostruct.setOutUrl(getGoodsEntrySchema(coupon,wxCouponChannel.getId())); | |||
| prostruct.setPoiList(poiList); | |||
| prostruct.setAttrKeyValueMap(ttattrs.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(ttattrs.getSkuAttrKeyValueMap()); | |||
| product.setSku(skuStruct); | |||
| String productId = ttWebService.getGoodsService().productSave(product); | |||
| syncCouponChannelPoi(coupon,wxCouponChannel.getId(),productId); | |||
| return new ResultData(); | |||
| } catch (WxErrorException e) { | |||
| throw new Exception(e.getMessage()); | |||
| // logger.error(e.getMessage()); | |||
| // return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } catch (Exception e){ | |||
| throw e; | |||
| // logger.error(e.getMessage()); | |||
| // return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| @Override | |||
| public int handlerTtGoodsAudit(TtCouponChannelPoi couponChannelPoi) { | |||
| return ttCouponChannelPoiMapper.updateBySpuId(couponChannelPoi); | |||
| } | |||
| @Override | |||
| public ResultData productDraftGet(Long id) { | |||
| TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(id); | |||
| if(ttCouponChannelPoi == null){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"该商品未提交审核"); | |||
| } | |||
| try { | |||
| TtWebService ttWebService = ttMerchantPoiService.getTtWebService(ttCouponChannelPoi); | |||
| List<Product> products = ttWebService.getGoodsService().productDraftGet(null, ttCouponChannelPoi.getId().toString()); | |||
| if(products.size() > 0){ | |||
| Product product = products.get(0); | |||
| if(product.getDraftStatus().intValue() == 12 && !EnumSpuSyncStatus.sync_audit_rejection.getCode().equals(ttCouponChannelPoi.getLastStatus())){ | |||
| ttCouponChannelPoi.setLastStatus(EnumSpuSyncStatus.sync_audit_rejection.getCode()); | |||
| ttCouponChannelPoi.setLastStatusDesc(product.getAuditMsg()); | |||
| ttCouponChannelPoi.setUpdateDate(new Date()); | |||
| ttCouponChannelPoiMapper.updateById(ttCouponChannelPoi); | |||
| }else if(product.getDraftStatus().intValue() == 1 && !EnumSpuSyncStatus.sync_audit_pass.getCode().equals(ttCouponChannelPoi.getLastStatus())){ | |||
| ttCouponChannelPoi.setLastStatus(EnumSpuSyncStatus.sync_audit_pass.getCode()); | |||
| ttCouponChannelPoi.setLastStatusDesc(""); | |||
| ttCouponChannelPoi.setUpdateDate(new Date()); | |||
| ttCouponChannelPoiMapper.updateById(ttCouponChannelPoi); | |||
| } | |||
| return new ResultData(product); | |||
| }else{ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到审核数据"); | |||
| } | |||
| } catch (WxErrorException e) { | |||
| e.printStackTrace(); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| @Override | |||
| public ResultData productOnlineGet(Long id) { | |||
| TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(id); | |||
| if(ttCouponChannelPoi == null){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"该商品未提交审核"); | |||
| } | |||
| try { | |||
| TtWebService ttWebService = ttMerchantPoiService.getTtWebService(ttCouponChannelPoi); | |||
| List<Product> products = ttWebService.getGoodsService().productOnlineGet(null, ttCouponChannelPoi.getId().toString()); | |||
| if(products.size() > 0){ | |||
| Product product = products.get(0); | |||
| if(product.getOnlineStatus().intValue() == 1 && !EnumSpuSyncStatus.sync_put_on.getCode().equals(ttCouponChannelPoi.getStatus())){ | |||
| ttCouponChannelPoi.setStatus(EnumSpuSyncStatus.sync_put_on.getCode()); | |||
| ttCouponChannelPoi.setUpdateDate(new Date()); | |||
| ttCouponChannelPoiMapper.updateById(ttCouponChannelPoi); | |||
| }else if(product.getOnlineStatus().intValue() == 2 && !EnumSpuSyncStatus.sync_pull_off.getCode().equals(ttCouponChannelPoi.getStatus())){ | |||
| ttCouponChannelPoi.setStatus(EnumSpuSyncStatus.sync_pull_off.getCode()); | |||
| ttCouponChannelPoi.setUpdateDate(new Date()); | |||
| ttCouponChannelPoiMapper.updateById(ttCouponChannelPoi); | |||
| }else if(product.getOnlineStatus().intValue() == 3 && !EnumSpuSyncStatus.sync_audit_disable.getCode().equals(ttCouponChannelPoi.getStatus())){ | |||
| ttCouponChannelPoi.setStatus(EnumSpuSyncStatus.sync_audit_disable.getCode()); | |||
| ttCouponChannelPoi.setUpdateDate(new Date()); | |||
| ttCouponChannelPoiMapper.updateById(ttCouponChannelPoi); | |||
| } | |||
| return new ResultData(product); | |||
| }else{ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到在线数据"); | |||
| } | |||
| } catch (WxErrorException e) { | |||
| e.printStackTrace(); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_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(TenantEntity tenantEntity,Long couponChannelId){ | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(tenantEntity, EnumAppPlat.TOUTIAO); | |||
| Map<String,String> map = new HashMap<>(); | |||
| map.put("app_id",cAppInfo.getAppId()); | |||
| map.put("path", Constant.mainPageUrl); | |||
| Map<String,Object> paramMap = new HashMap<>(); | |||
| paramMap.put("type","cd"); | |||
| paramMap.put("couponChannelId",couponChannelId); | |||
| map.put("params",JSON.toJSONString(paramMap)); | |||
| return JSON.toJSONString(map); | |||
| } | |||
| } | |||
| @@ -19,9 +19,7 @@ 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.*; | |||
| @@ -31,8 +29,6 @@ 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; | |||
| @@ -128,14 +124,9 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| @Autowired | |||
| WxProfitSharingReceiverMapper wxProfitSharingReceiverMapper; | |||
| @Autowired | |||
| private TtMerchantPoiService ttMerchantPoiService; | |||
| @Autowired | |||
| private TtGoodsCategoryService ttGoodsCategoryService; | |||
| @Autowired | |||
| TtCouponChannelPoiMapper ttCouponChannelPoiMapper; | |||
| @Autowired | |||
| WxAppinfoService wxAppinfoService; | |||
| @@ -143,49 +134,6 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| @Override | |||
| public ResultData ttgoodslist(TtCouponVo ttCouponVo, Integer pageNum, Integer pageSize) { | |||
| if(StringUtils.isBlank(ttCouponVo.getSortColumns())){ | |||
| ttCouponVo.setSortColumns(BaseEntity.SortField.CCreateDate_DESC, BaseEntity.SortField.CId_DESC); | |||
| } | |||
| PageInfo<TtCouponVo> pageInfo = PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCouponMapper.ttgoodslist(ttCouponVo)); | |||
| List<TtCouponVo> couponList = pageInfo.getList(); | |||
| if(!couponList.isEmpty()){ | |||
| List<Long> ids = couponList.stream().map(p -> p.getId()).collect(toList()); | |||
| WxCouponChannel wxCouponChannel = new WxCouponChannel(); | |||
| wxCouponChannel.updateTenantInfo(ttCouponVo); | |||
| wxCouponChannel.setCouponIds(ids); | |||
| wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); | |||
| //上架状态 | |||
| List<WxCouponChannel> list = wxCouponChannelMapper.findList(wxCouponChannel); | |||
| if (!list.isEmpty()) { | |||
| Map<Long, List<WxCouponChannel>> groupBy = list.stream().collect(Collectors.groupingBy(WxCouponChannel::getCouponId)); | |||
| for (TtCouponVo temp : couponList) { | |||
| if (groupBy.get(temp.getId()) != null) { | |||
| List<Integer> channels = new ArrayList<>(); | |||
| for (WxCouponChannel tempchannel : groupBy.get(temp.getId())) { | |||
| if (!channels.contains(tempchannel.getTargetAd())) { | |||
| channels.add(tempchannel.getTargetAd()); | |||
| } | |||
| } | |||
| String sss = JSON.toJSONString(channels); | |||
| temp.setChannels(sss); | |||
| } else { | |||
| temp.setChannels(""); | |||
| } | |||
| } | |||
| } else { | |||
| for (TtCouponVo temp : couponList) { | |||
| temp.setChannels(""); | |||
| } | |||
| } | |||
| } | |||
| return new ResultData(pageInfo); | |||
| } | |||
| @Override | |||
| public ResultData list(TenantEntity tenantEntity,WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | |||
| if (null == wxCoupon) wxCoupon = new WxCoupon(); | |||
| @@ -1244,221 +1192,4 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| return merchantList; | |||
| } | |||
| @Override | |||
| @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) | |||
| public ResultData productSave(WxCoupon coupon) throws Exception { | |||
| WxCoupon ttattrs = this.getAttrsById(coupon.getId(), coupon.getTenantId()); | |||
| if(ttattrs.getProductType() == null || ttattrs.getCategoryId() == null | |||
| || ttattrs.getProductAttrKeyValueMap().isEmpty() | |||
| || ttattrs.getSkuAttrKeyValueMap().isEmpty()){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"该券缺少必要属性"); | |||
| } | |||
| if(coupon.getStatus() != EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()) { | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_INVALID); | |||
| } | |||
| //获取门店 | |||
| List<WxMerchantVo> couponMerchantList = getCouponMerchantList(coupon, coupon.getId()); | |||
| List<Product.PoiStruct> poiList = new ArrayList(); | |||
| for (WxMerchantVo mvo:couponMerchantList){ | |||
| if(StringUtils.isNotBlank(mvo.getSupplierExtId())){ | |||
| Product.PoiStruct poiStruct = new Product.PoiStruct(); | |||
| poiStruct.setSupplierExtId(mvo.getSupplierExtId()); | |||
| poiList.add(poiStruct); | |||
| } | |||
| } | |||
| if(poiList.isEmpty()){ | |||
| return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"未找到poi门店"); | |||
| } | |||
| //查询是否有上架的 | |||
| WxCouponChannel wxCouponChannelQuery = new WxCouponChannel(); | |||
| wxCouponChannelQuery.updateTenantInfo(coupon); | |||
| wxCouponChannelQuery.setCouponId(coupon.getId()); | |||
| wxCouponChannelQuery.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_DOUYIN_LIST.getCode()); | |||
| wxCouponChannelQuery.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); | |||
| List<WxCouponChannel> wxCouponChannels = wxCouponChannelMapper.findList(wxCouponChannelQuery); | |||
| if(wxCouponChannels.size() > 0){ | |||
| return new ResultData(ErrorCode.COUPON_CHANNEL_IS_EXISTED); | |||
| } | |||
| //预审核的作废掉 重新投放 | |||
| wxCouponChannelQuery.setStatus(EnumCouponChannelStatus.STATUS_BEFORE.getCode()); | |||
| WxCouponChannel updCouponChannel = new WxCouponChannel(); | |||
| updCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_AFTER.getCode()); | |||
| updCouponChannel.setUpdateDate(new Date()); | |||
| wxCouponChannelMapper.update(updCouponChannel,new QueryWrapper<>(wxCouponChannelQuery)); | |||
| //投放预审核 | |||
| WxCouponChannel wxCouponChannel = new WxCouponChannel(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| wxCouponChannel.setId(idWorker.nextId()); | |||
| wxCouponChannel.updateTenantInfo(coupon); | |||
| wxCouponChannel.setShowBeginTime(new Date()); | |||
| wxCouponChannel.setBeginTime(new Date()); | |||
| wxCouponChannel.setEndTime(coupon.getValidEndDate()); | |||
| wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_AFTER.getCode()); | |||
| wxCouponChannel.setCouponId(coupon.getId()); | |||
| wxCouponChannel.setType(coupon.getType()); | |||
| wxCouponChannel.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_DOUYIN_LIST.getCode()); | |||
| wxCouponChannel.setBusiness(coupon.getBusiness()); | |||
| wxCouponChannel.setSubBusiness(coupon.getSubBusiness()); | |||
| wxCouponChannel.setTitle(coupon.getTitle()); | |||
| wxCouponChannelMapper.insert(wxCouponChannel); | |||
| //提交审核 | |||
| try { | |||
| 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(ttattrs.getCategoryId()); | |||
| prostruct.setProductType(ttattrs.getProductType()); | |||
| prostruct.setBizLine(5);//默认小程序 | |||
| prostruct.setAccountName(couponMerchantList.get(0).getMerchantName()); | |||
| // prostruct.setSoldStartTime(); | |||
| // prostruct.setSoldEndTime(); | |||
| prostruct.setOutUrl(getGoodsEntrySchema(coupon,wxCouponChannel.getId())); | |||
| prostruct.setPoiList(poiList); | |||
| prostruct.setAttrKeyValueMap(ttattrs.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(ttattrs.getSkuAttrKeyValueMap()); | |||
| product.setSku(skuStruct); | |||
| String productId = ttWebService.getGoodsService().productSave(product); | |||
| syncCouponChannelPoi(coupon,wxCouponChannel.getId(),productId); | |||
| return new ResultData(); | |||
| } catch (WxErrorException e) { | |||
| throw new Exception(e.getMessage()); | |||
| // logger.error(e.getMessage()); | |||
| // return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } catch (Exception e){ | |||
| throw e; | |||
| // logger.error(e.getMessage()); | |||
| // return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| @Override | |||
| public int handlerTtGoodsAudit(TtCouponChannelPoi couponChannelPoi) { | |||
| return ttCouponChannelPoiMapper.updateBySpuId(couponChannelPoi); | |||
| } | |||
| @Override | |||
| public ResultData productDraftGet(Long id) { | |||
| TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(id); | |||
| if(ttCouponChannelPoi == null){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"该商品未提交审核"); | |||
| } | |||
| try { | |||
| TtWebService ttWebService = ttMerchantPoiService.getTtWebService(ttCouponChannelPoi); | |||
| List<Product> products = ttWebService.getGoodsService().productDraftGet(null, ttCouponChannelPoi.getId().toString()); | |||
| if(products.size() > 0){ | |||
| Product product = products.get(0); | |||
| if(product.getDraftStatus().intValue() == 12 && !EnumSpuSyncStatus.sync_audit_rejection.getCode().equals(ttCouponChannelPoi.getLastStatus())){ | |||
| ttCouponChannelPoi.setLastStatus(EnumSpuSyncStatus.sync_audit_rejection.getCode()); | |||
| ttCouponChannelPoi.setLastStatusDesc(product.getAuditMsg()); | |||
| ttCouponChannelPoi.setUpdateDate(new Date()); | |||
| ttCouponChannelPoiMapper.updateById(ttCouponChannelPoi); | |||
| }else if(product.getDraftStatus().intValue() == 1 && !EnumSpuSyncStatus.sync_audit_pass.getCode().equals(ttCouponChannelPoi.getLastStatus())){ | |||
| ttCouponChannelPoi.setLastStatus(EnumSpuSyncStatus.sync_audit_pass.getCode()); | |||
| ttCouponChannelPoi.setLastStatusDesc(""); | |||
| ttCouponChannelPoi.setUpdateDate(new Date()); | |||
| ttCouponChannelPoiMapper.updateById(ttCouponChannelPoi); | |||
| } | |||
| return new ResultData(product); | |||
| }else{ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到审核数据"); | |||
| } | |||
| } catch (WxErrorException e) { | |||
| e.printStackTrace(); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| @Override | |||
| public ResultData productOnlineGet(Long id) { | |||
| TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(id); | |||
| if(ttCouponChannelPoi == null){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"该商品未提交审核"); | |||
| } | |||
| try { | |||
| TtWebService ttWebService = ttMerchantPoiService.getTtWebService(ttCouponChannelPoi); | |||
| List<Product> products = ttWebService.getGoodsService().productOnlineGet(null, ttCouponChannelPoi.getId().toString()); | |||
| if(products.size() > 0){ | |||
| Product product = products.get(0); | |||
| if(product.getOnlineStatus().intValue() == 1 && !EnumSpuSyncStatus.sync_put_on.getCode().equals(ttCouponChannelPoi.getStatus())){ | |||
| ttCouponChannelPoi.setStatus(EnumSpuSyncStatus.sync_put_on.getCode()); | |||
| ttCouponChannelPoi.setUpdateDate(new Date()); | |||
| ttCouponChannelPoiMapper.updateById(ttCouponChannelPoi); | |||
| }else if(product.getOnlineStatus().intValue() == 2 && !EnumSpuSyncStatus.sync_pull_off.getCode().equals(ttCouponChannelPoi.getStatus())){ | |||
| ttCouponChannelPoi.setStatus(EnumSpuSyncStatus.sync_pull_off.getCode()); | |||
| ttCouponChannelPoi.setUpdateDate(new Date()); | |||
| ttCouponChannelPoiMapper.updateById(ttCouponChannelPoi); | |||
| }else if(product.getOnlineStatus().intValue() == 3 && !EnumSpuSyncStatus.sync_audit_disable.getCode().equals(ttCouponChannelPoi.getStatus())){ | |||
| ttCouponChannelPoi.setStatus(EnumSpuSyncStatus.sync_audit_disable.getCode()); | |||
| ttCouponChannelPoi.setUpdateDate(new Date()); | |||
| ttCouponChannelPoiMapper.updateById(ttCouponChannelPoi); | |||
| } | |||
| return new ResultData(product); | |||
| }else{ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到在线数据"); | |||
| } | |||
| } catch (WxErrorException e) { | |||
| e.printStackTrace(); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_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(TenantEntity tenantEntity,Long couponChannelId){ | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(tenantEntity, EnumAppPlat.TOUTIAO); | |||
| Map<String,String> map = new HashMap<>(); | |||
| map.put("app_id",cAppInfo.getAppId()); | |||
| map.put("path", Constant.mainPageUrl); | |||
| Map<String,Object> paramMap = new HashMap<>(); | |||
| paramMap.put("type","cd"); | |||
| paramMap.put("couponChannelId",couponChannelId); | |||
| map.put("params",JSON.toJSONString(paramMap)); | |||
| return JSON.toJSONString(map); | |||
| } | |||
| } | |||
| @@ -1362,7 +1362,7 @@ | |||
| </resultMap> | |||
| <select id="ttgoodslist" parameterType="com.iformall.domain.vo.TtCouponVo" resultMap="TtCouponVoResultMap"> | |||
| <select id="ttCouponList" parameterType="com.iformall.domain.vo.TtCouponVo" resultMap="TtCouponVoResultMap"> | |||
| select c.`id`,c.`tenant_id`,c.`parent_tenant_id`,c.`type`,c.`cover_img`, | |||
| c.`title`,c.`sub_title`,c.`sale_price`,c.`freight_price`,c.`send_type`, | |||
| c.`valid_type`,c.`valid_start_date`,c.`valid_end_date`,c.pick_start_date,c.pick_end_date, | |||