|
|
@@ -6,15 +6,21 @@ import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.tuoheng.api.entity.domain.Goods; |
|
|
|
import com.tuoheng.api.entity.domain.Merchant; |
|
|
|
import com.tuoheng.api.entity.domain.UserPointsDetail; |
|
|
|
import com.tuoheng.api.entity.domain.WestreamUser; |
|
|
|
import com.tuoheng.api.entity.request.ExchangeRequest; |
|
|
|
import com.tuoheng.api.entity.request.GoodsQuery; |
|
|
|
import com.tuoheng.api.mapper.GoodsMapper; |
|
|
|
import com.tuoheng.api.mapper.MerchantMapper; |
|
|
|
import com.tuoheng.api.mapper.UserPointsDetailMapper; |
|
|
|
import com.tuoheng.api.mapper.WestreamUserMapper; |
|
|
|
import com.tuoheng.api.service.IGoodsService; |
|
|
|
import com.tuoheng.common.common.BaseServiceImpl; |
|
|
|
import com.tuoheng.common.utils.CommonUtils; |
|
|
|
import com.tuoheng.common.utils.JsonResult; |
|
|
|
import com.tuoheng.common.utils.StringUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
@@ -28,6 +34,12 @@ public class GoodsServiceImpl extends BaseServiceImpl<GoodsMapper, Goods> implem |
|
|
|
@Autowired |
|
|
|
private MerchantMapper merchantMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private UserPointsDetailMapper userPointsDetailMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WestreamUserMapper westreamUserMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@@ -75,4 +87,46 @@ public class GoodsServiceImpl extends BaseServiceImpl<GoodsMapper, Goods> implem |
|
|
|
return JsonResult.success(merchant); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public JsonResult exchange(ExchangeRequest exchangeRequest) { |
|
|
|
if(StringUtils.isEmpty(exchangeRequest.getOpenid())){ |
|
|
|
return JsonResult.error("openid为空!"); |
|
|
|
} |
|
|
|
if(null == exchangeRequest.getTenantId()){ |
|
|
|
return JsonResult.error("租户ID为空!"); |
|
|
|
} |
|
|
|
if(null == exchangeRequest.getGoodsId()){ |
|
|
|
return JsonResult.error("商品ID为空!"); |
|
|
|
} |
|
|
|
if(null == exchangeRequest.getGoodsCount() || exchangeRequest.getGoodsCount()<1){ |
|
|
|
return JsonResult.error("商品数量为空!"); |
|
|
|
} |
|
|
|
Goods goods = goodsMapper.selectById(exchangeRequest.getGoodsId()); |
|
|
|
if(ObjectUtil.isNull(goods)){ |
|
|
|
return JsonResult.error("商品不存在!"); |
|
|
|
} |
|
|
|
|
|
|
|
WestreamUser westreamUser = westreamUserMapper.selectOne(new LambdaQueryWrapper<WestreamUser>() |
|
|
|
.eq(WestreamUser::getTenantId, exchangeRequest.getTenantId()) |
|
|
|
.eq(WestreamUser::getOpenid, exchangeRequest.getOpenid()) |
|
|
|
.eq(WestreamUser::getMark, 1).last("limit 1")); |
|
|
|
|
|
|
|
if(ObjectUtil.isNull(westreamUser)){ |
|
|
|
return JsonResult.error("用户不存在!"); |
|
|
|
} |
|
|
|
int exchangePoints = exchangeRequest.getGoodsCount().intValue()*goods.getGoodsPoints().intValue(); |
|
|
|
int mallPoints = westreamUser.getMallPoints().intValue(); |
|
|
|
int residuePoints = mallPoints - exchangePoints; |
|
|
|
if(residuePoints < 0){ |
|
|
|
return JsonResult.error("用户积分不足!"); |
|
|
|
} |
|
|
|
|
|
|
|
UserPointsDetail userPointsDetail = new UserPointsDetail(); |
|
|
|
userPointsDetail.setChangeName(goods.getGoodsName()+"*"+exchangeRequest.getGoodsCount()); |
|
|
|
|
|
|
|
BeanUtils.copyProperties(exchangeRequest,userPointsDetail); |
|
|
|
userPointsDetailMapper.insert(userPointsDetail); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
} |