|
@@ -1,15 +1,21 @@
|
|
|
package com.cyksj.web.controller.cps;
|
|
package com.cyksj.web.controller.cps;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.EnvCommonService;
|
|
import com.cyksj.common.EnvCommonService;
|
|
|
import com.cyksj.common.annotation.NoSubmit;
|
|
import com.cyksj.common.annotation.NoSubmit;
|
|
|
import com.cyksj.dto.Result;
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
|
|
+import com.cyksj.mapper.DistributePopularizeClickRecordMapper;
|
|
|
|
|
+import com.cyksj.mapper.GoodsDonMapper;
|
|
|
|
|
+import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
|
|
+import com.cyksj.mapper.UserDistributePosterRecordMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponDistributePopularizeMapper;
|
|
import com.cyksj.mapper.manage.coupon.CouponDistributePopularizeMapper;
|
|
|
-import com.cyksj.model.entity.GoodsDon;
|
|
|
|
|
-import com.cyksj.model.entity.User;
|
|
|
|
|
-import com.cyksj.model.entity.UserDistributePopularize;
|
|
|
|
|
|
|
+import com.cyksj.mapper.manage.distribute.*;
|
|
|
|
|
+import com.cyksj.model.entity.*;
|
|
|
|
|
+import com.cyksj.model.views.DistributePosterGoodsCpsView;
|
|
|
import com.cyksj.model.views.UserDistributePopularizeView;
|
|
import com.cyksj.model.views.UserDistributePopularizeView;
|
|
|
|
|
+import com.cyksj.model.views.UserDistributePosterOrderDetailView;
|
|
|
import com.cyksj.service.cps.CpsPopularizeService;
|
|
import com.cyksj.service.cps.CpsPopularizeService;
|
|
|
import com.cyksj.service.user.UserService;
|
|
import com.cyksj.service.user.UserService;
|
|
|
import com.cyksj.web.util.StpCpsManageUser;
|
|
import com.cyksj.web.util.StpCpsManageUser;
|
|
@@ -19,6 +25,7 @@ import com.ejlchina.searcher.param.Operator;
|
|
|
import com.ejlchina.searcher.util.MapBuilder;
|
|
import com.ejlchina.searcher.util.MapBuilder;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -48,17 +55,50 @@ public class CpsPopularizeController {
|
|
|
|
|
|
|
|
private final UserService userService;
|
|
private final UserService userService;
|
|
|
|
|
|
|
|
|
|
+ private final GoodsDonMapper goodsDonMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final DistributePopularizeClickRecordMapper distributePopularizeClickRecordMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final UserDistributeMapper userDistributeMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final UserPlatDistributeRateMapper userPlatDistributeRateMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final GoodsDonSkuMapper skuMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final UserPlatSkuDistributeRateMapper userPlatSkuDistributeRateMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final DistributeGeneralSkuRateMapper distributeGeneralSkuRateMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final UserDistributePosterRecordMapper userDistributePosterRecordMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final DistributePosterGoodsMapper distributePosterGoodsMapper;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 渠道推广链接列表
|
|
* 渠道推广链接列表
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/get")
|
|
@GetMapping("/get")
|
|
|
- public Result<SearchResult<UserDistributePopularizeView>> getList() {
|
|
|
|
|
|
|
+ public Result<SearchResult<UserDistributePopularizeView>> getList(String start, String end) {
|
|
|
long cpsUserId = StpCpsManageUser.getLoginIdAsLong();
|
|
long cpsUserId = StpCpsManageUser.getLoginIdAsLong();
|
|
|
MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
|
|
MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
builder.put("userId", String.format("and user_id = %s", cpsUserId));
|
|
builder.put("userId", String.format("and user_id = %s", cpsUserId));
|
|
|
|
|
+ String time = null;
|
|
|
|
|
+ if (start != null) {
|
|
|
|
|
+ time += String.format(" and od.created_time >= '%s'", start);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (end != null) {
|
|
|
|
|
+ time += String.format(" and od.created_time < '%s'", end);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isNotBlank(time)) {
|
|
|
|
|
+ builder.put("time", time);
|
|
|
|
|
+ }
|
|
|
SearchResult<UserDistributePopularizeView> search = beanSearcher.search(UserDistributePopularizeView.class, builder.build());
|
|
SearchResult<UserDistributePopularizeView> search = beanSearcher.search(UserDistributePopularizeView.class, builder.build());
|
|
|
search.getDataList().forEach(data -> {
|
|
search.getDataList().forEach(data -> {
|
|
|
data.setPopularizeLink(String.format(envCommonService.DISTRIBUTE_DEFAULT_URL_PREFIX, data.getCode()));
|
|
data.setPopularizeLink(String.format(envCommonService.DISTRIBUTE_DEFAULT_URL_PREFIX, data.getCode()));
|
|
|
|
|
+ Optional.ofNullable(goodsDonMapper.selectById(data.getGoodsId())).ifPresent(goods -> {
|
|
|
|
|
+ data.setTitle(goods.getTitle());
|
|
|
|
|
+ data.setLogo(goods.getLogo());
|
|
|
|
|
+ });
|
|
|
|
|
+ data.setClickNum(distributePopularizeClickRecordMapper.selectCount(Wrappers.lambdaQuery(DistributePopularizeClickRecord.class).eq(DistributePopularizeClickRecord::getPopularizeId, data.getId())));
|
|
|
});
|
|
});
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
}
|
|
@@ -67,10 +107,10 @@ public class CpsPopularizeController {
|
|
|
* 默认链接详情
|
|
* 默认链接详情
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/get/default")
|
|
@GetMapping("/get/default")
|
|
|
- public Result<UserDistributePopularizeView> getDefaultDetail() {
|
|
|
|
|
|
|
+ public Result<UserDistributePopularizeView> getDefaultDetail(String start, String end) {
|
|
|
long cpsUserId = StpCpsManageUser.getLoginIdAsLong();
|
|
long cpsUserId = StpCpsManageUser.getLoginIdAsLong();
|
|
|
User user = userService.getById(cpsUserId);
|
|
User user = userService.getById(cpsUserId);
|
|
|
- UserDistributePopularizeView view = Optional.ofNullable(cpsPopularizeService.getDefaultPopularizeDetail(cpsUserId)).orElseGet(() -> {
|
|
|
|
|
|
|
+ UserDistributePopularizeView view = Optional.ofNullable(cpsPopularizeService.getDefaultPopularizeDetail(cpsUserId, start, end)).orElseGet(() -> {
|
|
|
UserDistributePopularizeView newPopularizeView = new UserDistributePopularizeView();
|
|
UserDistributePopularizeView newPopularizeView = new UserDistributePopularizeView();
|
|
|
newPopularizeView.setOrders(0);
|
|
newPopularizeView.setOrders(0);
|
|
|
newPopularizeView.setOrdersMoney(BigDecimal.ZERO);
|
|
newPopularizeView.setOrdersMoney(BigDecimal.ZERO);
|
|
@@ -84,6 +124,7 @@ public class CpsPopularizeController {
|
|
|
view.setPopularizeLink(String.format(envCommonService.DISTRIBUTE_DEFAULT_URL_PREFIX, user.getShowId()));
|
|
view.setPopularizeLink(String.format(envCommonService.DISTRIBUTE_DEFAULT_URL_PREFIX, user.getShowId()));
|
|
|
//优惠码
|
|
//优惠码
|
|
|
view.setCouponCode(couponDistributePopularizeMapper.getCouponCodeByUid(cpsUserId));
|
|
view.setCouponCode(couponDistributePopularizeMapper.getCouponCodeByUid(cpsUserId));
|
|
|
|
|
+ view.setClickNum(distributePopularizeClickRecordMapper.selectCount(Wrappers.lambdaQuery(DistributePopularizeClickRecord.class).eq(DistributePopularizeClickRecord::getShowId, user.getShowId())));
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(view);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(view);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -136,7 +177,7 @@ public class CpsPopularizeController {
|
|
|
} else {
|
|
} else {
|
|
|
conditionSql = "(special_type is null or special_type != 'giftCard')";
|
|
conditionSql = "(special_type is null or special_type != 'giftCard')";
|
|
|
}
|
|
}
|
|
|
- conditionSql += " and exists (select id from goods_don_sku sku where sku.goods_id = g.id limit 1)";
|
|
|
|
|
|
|
+ conditionSql += " and exists (select id from goods_don_sku sku where sku.goods_id = g.id limit 1) and exist (select 1 from )";
|
|
|
List<GoodsDon> goodsDons = beanSearcher.searchAll(GoodsDon.class, mapBuilder
|
|
List<GoodsDon> goodsDons = beanSearcher.searchAll(GoodsDon.class, mapBuilder
|
|
|
.put("condition", conditionSql)
|
|
.put("condition", conditionSql)
|
|
|
.field(GoodsDon::getType, 1)
|
|
.field(GoodsDon::getType, 1)
|
|
@@ -155,4 +196,134 @@ public class CpsPopularizeController {
|
|
|
long cpsUserId = StpCpsManageUser.getLoginIdAsLong();
|
|
long cpsUserId = StpCpsManageUser.getLoginIdAsLong();
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(cpsPopularizeService.getServiceCodeUrl(cpsUserId));
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(cpsPopularizeService.getServiceCodeUrl(cpsUserId));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 推广平台海报列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/get/ds/poster/goods")
|
|
|
|
|
+ public Result<List<DistributePosterGoodsCpsView>> getPosterGoods(String start, String end) {
|
|
|
|
|
+ long cpsUserId = StpCpsManageUser.getLoginIdAsLong();
|
|
|
|
|
+ UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class)
|
|
|
|
|
+ .eq(UserDistribute::getUserId, cpsUserId)
|
|
|
|
|
+ .eq(UserDistribute::getDeleted, 1)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
|
|
+ StringBuilder time = new StringBuilder();
|
|
|
|
|
+ if (start != null) {
|
|
|
|
|
+ time.append(String.format(" and od.created_time >= '%s'", start));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (end != null) {
|
|
|
|
|
+ time.append(String.format(" and od.created_time < '%s'", end));
|
|
|
|
|
+ }
|
|
|
|
|
+ List<DistributePosterGoodsCpsView> searchAll = beanSearcher.searchAll(DistributePosterGoodsCpsView.class, builder.build());
|
|
|
|
|
+ searchAll.forEach(e -> {
|
|
|
|
|
+ if (userDistribute != null) {
|
|
|
|
|
+ UserPlatDistributeRate userPlatDistributeRate = userPlatDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatDistributeRate.class)
|
|
|
|
|
+ .eq(UserPlatDistributeRate::getDistributeId, userDistribute.getId())
|
|
|
|
|
+ .eq(UserPlatDistributeRate::getGoodsId, e.getGoodsId())
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (userPlatDistributeRate != null) {
|
|
|
|
|
+ e.setRate(userPlatDistributeRate.getRate());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (e.getIsSkuRate()) {
|
|
|
|
|
+ GoodsDonSku sku = skuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class)
|
|
|
|
|
+ .eq(GoodsDonSku::getGoodsId, e.getGoodsId())
|
|
|
|
|
+ .eq(GoodsDonSku::getStatus, 1)
|
|
|
|
|
+ .orderByAsc(GoodsDonSku::getPrice)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ //先获取价格最低的规格对应的 比例
|
|
|
|
|
+ //渠道
|
|
|
|
|
+ if (userDistribute != null) {
|
|
|
|
|
+ UserPlatSkuDistributeRate minPriceSkuRate = userPlatSkuDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatSkuDistributeRate.class)
|
|
|
|
|
+ .eq(UserPlatSkuDistributeRate::getDistributeId, userDistribute.getId())
|
|
|
|
|
+ .eq(UserPlatSkuDistributeRate::getGoodsId, e.getGoodsId())
|
|
|
|
|
+ .eq(UserPlatSkuDistributeRate::getSkuId, sku.getId())
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (minPriceSkuRate != null && minPriceSkuRate.getRate() != 0) {
|
|
|
|
|
+ e.setRate(minPriceSkuRate.getRate());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ UserPlatSkuDistributeRate userPlatSkuDistributeRate = userPlatSkuDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatSkuDistributeRate.class)
|
|
|
|
|
+ .eq(UserPlatSkuDistributeRate::getDistributeId, userDistribute.getId())
|
|
|
|
|
+ .eq(UserPlatSkuDistributeRate::getGoodsId, e.getGoodsId())
|
|
|
|
|
+ .ne(UserPlatSkuDistributeRate::getRate, 0)
|
|
|
|
|
+ //上架
|
|
|
|
|
+ .apply("exists (select 1 from goods_don_sku sku where sku.id = sku_id and sku.status is true limit 1)")
|
|
|
|
|
+ .orderByAsc(UserPlatSkuDistributeRate::getRate)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (userPlatSkuDistributeRate != null) {
|
|
|
|
|
+ e.setRate(userPlatSkuDistributeRate.getRate());
|
|
|
|
|
+ sku = skuMapper.selectById(userPlatSkuDistributeRate.getSkuId());
|
|
|
|
|
+ e.setPrice(sku.getPrice());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //普通
|
|
|
|
|
+ DistributeGeneralSkuRate minPriceRate = distributeGeneralSkuRateMapper.selectOne(Wrappers.lambdaQuery(DistributeGeneralSkuRate.class)
|
|
|
|
|
+ .eq(DistributeGeneralSkuRate::getGoodsId, e.getGoodsId())
|
|
|
|
|
+ .eq(DistributeGeneralSkuRate::getSkuId, sku.getId())
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (minPriceRate != null && minPriceRate.getRate() > 0) {
|
|
|
|
|
+ e.setRate(minPriceRate.getRate());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ DistributeGeneralSkuRate distributeGeneralSkuRate = distributeGeneralSkuRateMapper.selectOne(Wrappers.lambdaQuery(DistributeGeneralSkuRate.class)
|
|
|
|
|
+ .eq(DistributeGeneralSkuRate::getGoodsId, e.getGoodsId())
|
|
|
|
|
+ .apply("exists (select 1 from goods_don_sku sku where sku.id = sku_id and sku.status is true limit 1)")
|
|
|
|
|
+ .ne(DistributeGeneralSkuRate::getRate, 0)
|
|
|
|
|
+ .orderByAsc(DistributeGeneralSkuRate::getRate)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (distributeGeneralSkuRate != null) {
|
|
|
|
|
+ e.setRate(distributeGeneralSkuRate.getRate());
|
|
|
|
|
+ sku = skuMapper.selectById(distributeGeneralSkuRate.getSkuId());
|
|
|
|
|
+ e.setPrice(sku.getPrice());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //用户推广海报订单详情
|
|
|
|
|
+ MapBuilder posterOrderBuilder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
|
|
+ if (time.length() > 0) {
|
|
|
|
|
+ posterOrderBuilder.put("time", time.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ UserDistributePosterOrderDetailView distributePosterOrderDetailView = beanSearcher.searchFirst(UserDistributePosterOrderDetailView.class, posterOrderBuilder.put("condition", String.format(String.format(" where user_id = %s and poster_id = %s", cpsUserId, e.getId()))).build());
|
|
|
|
|
+ if (distributePosterOrderDetailView != null) {
|
|
|
|
|
+ distributePosterOrderDetailView.setClickNum(distributePopularizeClickRecordMapper.selectCount(Wrappers.lambdaQuery(DistributePopularizeClickRecord.class)
|
|
|
|
|
+ .eq(DistributePopularizeClickRecord::getRid, distributePosterOrderDetailView.getId())));
|
|
|
|
|
+ }
|
|
|
|
|
+ e.setUserDistributePosterOrderDetailView(distributePosterOrderDetailView);
|
|
|
|
|
+
|
|
|
|
|
+ UserDistributePosterRecord distributePosterRecord = userDistributePosterRecordMapper.selectOne(Wrappers.lambdaQuery(UserDistributePosterRecord.class)
|
|
|
|
|
+ .eq(UserDistributePosterRecord::getPosterId, e.getId())
|
|
|
|
|
+ .eq(UserDistributePosterRecord::getUserId, cpsUserId)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (distributePosterRecord != null) {
|
|
|
|
|
+ e.setRid(distributePosterRecord.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(searchAll);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 用户下载海报记录
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/poster/record/{posterId}")
|
|
|
|
|
+ public Result<String> posterRecord(@PathVariable Long posterId) {
|
|
|
|
|
+ long cpsUserId = StpCpsManageUser.getLoginIdAsLong();
|
|
|
|
|
+ DistributePosterGoods distributePosterGoods = distributePosterGoodsMapper.selectById(posterId);
|
|
|
|
|
+ if (distributePosterGoods == null) {
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
|
|
+ UserDistributePosterRecord distributePosterRecord = new UserDistributePosterRecord();
|
|
|
|
|
+ distributePosterRecord.setPosterId(posterId);
|
|
|
|
|
+ distributePosterRecord.setUserId(cpsUserId);
|
|
|
|
|
+ try {
|
|
|
|
|
+ userDistributePosterRecordMapper.insert(distributePosterRecord);
|
|
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
|
|
+ }
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|