收货地址、首页接口完善

This commit is contained in:
macro 2020-06-27 10:33:25 +08:00
parent a3c557b7f4
commit 806c1d4580
4 changed files with 65 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package com.macro.mall.portal.service;
import com.macro.mall.model.UmsMemberReceiveAddress;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@ -25,6 +26,7 @@ public interface UmsMemberReceiveAddressService {
* @param id 地址表的id
* @param address 修改的收货地址信息
*/
@Transactional
int update(Long id, UmsMemberReceiveAddress address);
/**

View File

@ -43,7 +43,7 @@ public class HomeServiceImpl implements HomeService {
//获取首页广告
result.setAdvertiseList(getHomeAdvertiseList());
//获取推荐品牌
result.setBrandList(homeDao.getRecommendBrandList(0,4));
result.setBrandList(homeDao.getRecommendBrandList(0,6));
//获取秒杀信息
result.setHomeFlashPromotion(getHomeFlashPromotion());
//获取新品推荐

View File

@ -1,8 +1,8 @@
package com.macro.mall.portal.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.macro.mall.common.exception.Asserts;
import com.macro.mall.mapper.SmsCouponHistoryMapper;
import com.macro.mall.mapper.SmsCouponMapper;
import com.macro.mall.mapper.*;
import com.macro.mall.model.*;
import com.macro.mall.portal.dao.SmsCouponHistoryDao;
import com.macro.mall.portal.domain.CartPromotionItem;
@ -17,6 +17,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
/**
* 会员优惠券管理Service实现类
@ -32,6 +33,12 @@ public class UmsMemberCouponServiceImpl implements UmsMemberCouponService {
private SmsCouponHistoryMapper couponHistoryMapper;
@Autowired
private SmsCouponHistoryDao couponHistoryDao;
@Autowired
private SmsCouponProductRelationMapper couponProductRelationMapper;
@Autowired
private SmsCouponProductCategoryRelationMapper couponProductCategoryRelationMapper;
@Autowired
private PmsProductMapper productMapper;
@Override
public void add(Long couponId) {
UmsMember currentMember = memberService.getCurrentMember();
@ -93,7 +100,7 @@ public class UmsMemberCouponServiceImpl implements UmsMemberCouponService {
}
@Override
public List<SmsCouponHistory> list(Integer useStatus) {
public List<SmsCouponHistory> listHistory(Integer useStatus) {
UmsMember currentMember = memberService.getCurrentMember();
SmsCouponHistoryExample couponHistoryExample=new SmsCouponHistoryExample();
SmsCouponHistoryExample.Criteria criteria = couponHistoryExample.createCriteria();
@ -162,6 +169,48 @@ public class UmsMemberCouponServiceImpl implements UmsMemberCouponService {
}
}
@Override
public List<SmsCoupon> listByProduct(Long productId) {
List<Long> allCouponIds = new ArrayList<>();
//获取指定商品优惠券
SmsCouponProductRelationExample cprExample = new SmsCouponProductRelationExample();
cprExample.createCriteria().andProductIdEqualTo(productId);
List<SmsCouponProductRelation> cprList = couponProductRelationMapper.selectByExample(cprExample);
if(CollUtil.isNotEmpty(cprList)){
List<Long> couponIds = cprList.stream().map(SmsCouponProductRelation::getCouponId).collect(Collectors.toList());
allCouponIds.addAll(couponIds);
}
//获取指定分类优惠券
PmsProduct product = productMapper.selectByPrimaryKey(productId);
SmsCouponProductCategoryRelationExample cpcrExample = new SmsCouponProductCategoryRelationExample();
cpcrExample.createCriteria().andProductCategoryIdEqualTo(product.getProductCategoryId());
List<SmsCouponProductCategoryRelation> cpcrList = couponProductCategoryRelationMapper.selectByExample(cpcrExample);
if(CollUtil.isNotEmpty(cpcrList)){
List<Long> couponIds = cpcrList.stream().map(SmsCouponProductCategoryRelation::getCouponId).collect(Collectors.toList());
allCouponIds.addAll(couponIds);
}
if(CollUtil.isEmpty(allCouponIds)){
return new ArrayList<>();
}
//所有优惠券
SmsCouponExample couponExample = new SmsCouponExample();
couponExample.createCriteria().andEndTimeGreaterThan(new Date())
.andStartTimeLessThan(new Date())
.andUseTypeEqualTo(0);
couponExample.or(couponExample.createCriteria()
.andEndTimeGreaterThan(new Date())
.andStartTimeLessThan(new Date())
.andUseTypeNotEqualTo(0)
.andIdIn(allCouponIds));
return couponMapper.selectByExample(couponExample);
}
@Override
public List<SmsCoupon> list(Integer useStatus) {
UmsMember member = memberService.getCurrentMember();
return couponHistoryDao.getCouponList(member.getId(),useStatus);
}
private BigDecimal calcTotalAmount(List<CartPromotionItem> cartItemList) {
BigDecimal total = new BigDecimal("0");
for (CartPromotionItem item : cartItemList) {

View File

@ -43,6 +43,16 @@ public class UmsMemberReceiveAddressServiceImpl implements UmsMemberReceiveAddre
UmsMember currentMember = memberService.getCurrentMember();
UmsMemberReceiveAddressExample example = new UmsMemberReceiveAddressExample();
example.createCriteria().andMemberIdEqualTo(currentMember.getId()).andIdEqualTo(id);
if(address.getDefaultStatus()==1){
//先将原来的默认地址去除
UmsMemberReceiveAddress record= new UmsMemberReceiveAddress();
record.setDefaultStatus(0);
UmsMemberReceiveAddressExample updateExample = new UmsMemberReceiveAddressExample();
updateExample.createCriteria()
.andMemberIdEqualTo(currentMember.getId())
.andDefaultStatusEqualTo(1);
addressMapper.updateByExampleSelective(record,updateExample);
}
return addressMapper.updateByExampleSelective(address,example);
}