diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponBatchController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponBatchController.java new file mode 100644 index 000000000..7ba5c04bd --- /dev/null +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponBatchController.java @@ -0,0 +1,285 @@ +package com.iformall.controller.market; + +import com.github.pagehelper.PageInfo; +import com.iformall.annotation.SystemControllerLog; +import com.iformall.common.ErrorCode; +import com.iformall.common.Result; +import com.iformall.common.ResultData; +import com.iformall.controller.base.BaseController; +import com.iformall.domain.po.AliBusinessCircleOrder; +import com.iformall.domain.po.WxBusinessCircleOrder; +import com.iformall.domain.po.WxCoupon; +import com.iformall.domain.po.WxCouponBatch; +import com.iformall.domain.po.WxCouponBatchItem; +import com.iformall.domain.po.WxCouponChannel; +import com.iformall.domain.po.WxPressBatch; +import com.iformall.domain.po.WxPressBatchItem; +import com.iformall.domain.po.base.BaseEntity; +import com.iformall.domain.po.base.TenantEntity; +import com.iformall.enums.EnumCouponChannelStatus; +import com.iformall.enums.EnumCouponChannelType; +import com.iformall.enums.EnumCouponContentType; +import com.iformall.enums.EnumCouponSourceType; +import com.iformall.enums.EnumCouponType; +import com.iformall.enums.EnumRentContractAppStatus; +import com.iformall.service.AliBusinessCircleOrderService; +import com.iformall.service.WxCouponBatchService; +import com.iformall.service.WxCouponChannelService; +import com.iformall.service.WxCouponService; +import com.iformall.service.WxPressBatchService; +import com.iformall.utils.Constant; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@RestController +@RequestMapping("couponBatch") +public class WxCouponBatchController extends BaseController { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + WxCouponBatchService wxCouponBatchService; + + @Autowired + WxCouponService wxCouponService; + + @Autowired + WxCouponChannelService wxCouponChannelService; + + @ApiOperation("分页列表接口") + @GetMapping("list") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true),}) + public ResultData list(@ModelAttribute WxCouponBatch record, Integer pageNum, Integer pageSize) { + if (null == record) { + record = new WxCouponBatch(); + } + record.updateTenantInfo(getTenantInfo()); + record.setSortColumns(BaseEntity.SortField.UpdateDate_DESC); + final PageInfo page = wxCouponBatchService.listAsPage(record, pageNum, pageSize); + return new ResultData(page); + } + + @ApiOperation("新增&修改接口") + @PostMapping("saveOrUpdate") + public ResultData saveOrUpdate(@RequestBody WxCouponBatch record) { + TenantEntity tenantEntity = getTenantInfo(); + record.updateTenantInfo(tenantEntity); + wxCouponBatchService.saveOrUpdate(record); + return new ResultData(); + } + + @ApiOperation("详情接口") + @GetMapping("detail") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)}) + public ResultData detail(Long id) { + if (null == id) { + return new ResultData(Result.ERROR,"参数错误"); + } + WxCouponBatch order = wxCouponBatchService.getById(id, getTenantInfo().getTenantId()); + return new ResultData(order); + } + + @ApiOperation("砍价券接口") + @GetMapping("itemList") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true), + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) + public ResultData itemList(Long id, Integer pageNum, Integer pageSize) { + if (null == id) { + return new ResultData(Result.ERROR,"参数错误"); + } + TenantEntity tenantEntity = getTenantInfo(); + PageInfo itemPage = wxCouponBatchService.getItemPage(id, tenantEntity.getTenantId(),pageNum,pageSize); + List items = itemPage.getList(); + if (null != items && items.size() > 0 ) { + List couponIdList = wxCouponBatchService.getItemCouponIdList(id, tenantEntity.getTenantId()); + WxCoupon record = new WxCoupon(); + record.updateTenantInfo(getTenantInfo()); + if (null != couponIdList && couponIdList.size() > 0 ) { + record.setIds(couponIdList); + }else { + record.setId(0L); + } + List list = wxCouponService.list(record); + Map couponMap = new HashMap(); + if (null != list && list.size() > 0 ) { + for (WxCoupon c : list) { + couponMap.put(c.getId(), c); + } + } + for (WxCouponBatchItem pbi : items) { + WxCoupon coupon = couponMap.get(pbi.getCouponId()); + pbi.setCoupon(coupon); + } + } + return new ResultData(itemPage); + } + + @ApiOperation("删除接口") + @PostMapping("delete") + public ResultData delete(@RequestBody WxPressBatch record) { + if (null == record.getId()) { + return new ResultData(Result.ERROR,"参数错误"); + } + wxCouponBatchService.deleteBatch(record.getId(), getTenantInfo().getTenantId()); + return new ResultData(); + } + + @ApiOperation("已投放砍价券列表接口") + @GetMapping("couponList") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true),}) + public ResultData couponList(@ModelAttribute WxCoupon record, Integer pageNum, Integer pageSize) { + WxCouponChannel couponChannelQ = new WxCouponChannel(); + couponChannelQ.updateTenantInfo(getTenantInfo()); + List typeList = new ArrayList(); + typeList.add(EnumCouponType.COUPON_MANJIAN.getCode()); + typeList.add(EnumCouponType.COUPON_DAIJIN.getCode()); + typeList.add(EnumCouponType.COUPON_LIPIN.getCode()); + typeList.add(EnumCouponType.COUPON_MULTIMCH.getCode()); + couponChannelQ.setTypeList(typeList); + //couponChannelQ.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_PRESS.getCode()); + couponChannelQ.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); + List couponIds = wxCouponChannelService.findCouponIdList(couponChannelQ); + if (null == record) { + record = new WxCoupon(); + } + record.updateTenantInfo(couponChannelQ); + if (null != couponIds && couponIds.size() > 0 ) { + record.setIds(couponIds); + }else { + record.setId(0L); + } + PageInfo page = wxCouponService.simplelistAsPage(record, pageNum, pageSize); + return new ResultData(page); + } + + + @ApiOperation("新增items") + @PostMapping("addItems") + public ResultData addItems(@RequestBody WxCouponBatch record) { + TenantEntity tenantEntity = getTenantInfo(); + record.updateTenantInfo(tenantEntity); + if (null == record.getId()) { + return new ResultData(Result.ERROR,"参数错误"); + } + String cidstr = record.getCouponIds(); + if (StringUtils.isBlank(cidstr)) { + return new ResultData(Result.ERROR,"参数错误"); + } + String[] cids = cidstr.split(","); + if (null == cids || cids.length <= 0 ) { + return new ResultData(Result.ERROR,"请选择砍价券"); + } + List rcids = new ArrayList(); + for (String cid: cids) { + rcids.add(Long.parseLong(cid)); + } + //已经存在了的不能再加入 + List arrayCouponIds = wxCouponBatchService.getCouponIds(tenantEntity.getTenantId()); + if (null != arrayCouponIds && arrayCouponIds.size() > 0 ) { + if (arrayCouponIds.containsAll(rcids)) { + return new ResultData(Result.ERROR,"所选择的券已经加入了一个批次,不能再加"); + } + List extraCouponIds = new ArrayList(); + extraCouponIds.addAll(rcids); + extraCouponIds.removeAll(arrayCouponIds); + + List sameCouponIds = new ArrayList(); + sameCouponIds.addAll(rcids); + sameCouponIds.removeAll(extraCouponIds); + + if (sameCouponIds.size() > 0) { + WxCoupon couponQ = new WxCoupon(); + couponQ.updateTenantInfo(tenantEntity); + couponQ.setIds(sameCouponIds); + List couponList = wxCouponService.list(couponQ); + if (null == couponList || couponList.size() <= 0 ) { + return new ResultData(Result.ERROR,"未查询到这些券"); + } + + Map couponNameMap = new HashMap(); + for (WxCoupon c: couponList) { + couponNameMap.put(c.getId(),c.getTitle()); + } + + StringBuffer sb = new StringBuffer("已经存在一个批次的券:"); + for (Long _cid: sameCouponIds) { + sb.append(couponNameMap.get(_cid)).append(","); + } + return new ResultData(Result.ERROR,sb.toString()); + } + } + + List batchCids = wxCouponBatchService.getItemCouponIdList(record.getId(), tenantEntity.getTenantId()); + if (null != cids && cids.length > 0 ) { + + if (null != batchCids && batchCids.size() > 0 ) { + rcids.removeAll(batchCids); + } + WxCouponBatch order = wxCouponBatchService.getById(record.getId(), tenantEntity.getTenantId()); + wxCouponBatchService.saveItems(order, rcids); + } + return new ResultData(); + } + + @ApiOperation("详情接口") + @PostMapping("deleteItem") + public ResultData deleteItem(@RequestBody WxPressBatchItem record) { + if (null == record.getId()) { + return new ResultData(Result.ERROR,"参数错误"); + } + wxCouponBatchService.deleteItemById(record.getId(), getTenantInfo().getTenantId()); + return new ResultData(); + } + + @ApiOperation("详情接口") + @PostMapping("updateStatus") + public ResultData updateStatus(@RequestBody WxCouponBatch record) { + if (null == record.getId() || null == record.getStatus()) { + return new ResultData(Result.ERROR,"参数错误"); + } + record.updateTenantInfo(getTenantInfo()); + wxCouponBatchService.updateStatus(record); + return new ResultData(); + } + + @ApiOperation("详情接口") + @PostMapping("setRules") + public ResultData setRules(@RequestBody WxCouponBatch record) { + if (null == record.getId()) { + return new ResultData(Result.ERROR,"参数错误"); + } + WxCouponBatch record1 = wxCouponBatchService.getById(record.getId(), getTenantInfo().getTenantId()); + record1.setAllowCount(record.getAllowCount()); + wxCouponBatchService.saveOrUpdate(record1); + return new ResultData(); + } + + + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCouponChannel.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponChannel.java index ea03dff38..7b45f58c7 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCouponChannel.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponChannel.java @@ -46,6 +46,8 @@ public class WxCouponChannel extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value="券类型(1.满减券,2.代金券,3.团购券,4.礼品券,5.停车券)",name="type") private Integer type; + @TableField(exist = false) + protected List typeList; @io.swagger.annotations.ApiModelProperty(value="券名称",name="title") private String title; @io.swagger.annotations.ApiModelProperty(value="EnumCouponChannelType 投放频道位置(1.列表, 2.限时抢购)",name="targetAd") diff --git a/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml index 0035626c8..9d11cfccb 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml @@ -121,7 +121,12 @@ and cm.`merchant_id` = #{merchantId} - + + and cc.type in + + #{tidItem} + + and cc.id in