package com.tuoheng.api.controller; | package com.tuoheng.api.controller; | ||||
import com.tuoheng.api.entity.domain.IdentityApply; | |||||
import com.tuoheng.api.entity.request.ExchangeRequest; | |||||
import com.tuoheng.api.entity.request.GoodsQuery; | import com.tuoheng.api.entity.request.GoodsQuery; | ||||
import com.tuoheng.api.service.IGoodsService; | import com.tuoheng.api.service.IGoodsService; | ||||
import com.tuoheng.common.utils.JsonResult; | import com.tuoheng.common.utils.JsonResult; | ||||
public JsonResult merchantInfo(GoodsQuery goodsQuery) { | public JsonResult merchantInfo(GoodsQuery goodsQuery) { | ||||
return goodsService.merchantInfo(goodsQuery); | return goodsService.merchantInfo(goodsQuery); | ||||
} | } | ||||
/** | |||||
* 立即兑换 | |||||
* | |||||
* @param exchangeRequest | |||||
* @return | |||||
*/ | |||||
@PostMapping("/exchange") | |||||
public JsonResult submit(@RequestBody ExchangeRequest exchangeRequest){ | |||||
return goodsService.exchange(exchangeRequest); | |||||
} | |||||
} | } |
private String changeName; | private String changeName; | ||||
/** | /** | ||||
* 商铺名称 | |||||
* 核销标识,0待核销,1已核销 | |||||
*/ | */ | ||||
@TableField(exist = false) | |||||
private String shopsName; | |||||
private Integer exchangeFlag; | |||||
/** | |||||
* 商品ID | |||||
*/ | |||||
private Integer goodsId; | |||||
/** | |||||
* 商品积分 | |||||
*/ | |||||
private Integer goodsPoints; | |||||
/** | |||||
* 商品数量 | |||||
*/ | |||||
private Integer goodsCount; | |||||
/** | /** | ||||
* 商铺图片 | |||||
* 商铺信息 | |||||
*/ | */ | ||||
@TableField(exist = false) | @TableField(exist = false) | ||||
private String shopsImage; | |||||
private Merchant merchant; | |||||
/** | /** | ||||
* 区域名称 | |||||
* 商品信息 | |||||
*/ | */ | ||||
@TableField(exist = false) | @TableField(exist = false) | ||||
private String areaName; | |||||
private Goods goods; | |||||
} | } |
package com.tuoheng.api.entity.request; | |||||
import lombok.Data; | |||||
@Data | |||||
public class ExchangeRequest { | |||||
private String openid; | |||||
/** | |||||
* 租户ID | |||||
*/ | |||||
private Integer tenantId; | |||||
/** | |||||
* 商品id | |||||
*/ | |||||
private Integer goodsId; | |||||
/** | |||||
* 商品数量 | |||||
*/ | |||||
private Integer goodsCount; | |||||
} |
import com.tuoheng.api.entity.domain.Goods; | import com.tuoheng.api.entity.domain.Goods; | ||||
import com.tuoheng.api.entity.request.ExchangeRequest; | |||||
import com.tuoheng.api.entity.request.GoodsQuery; | import com.tuoheng.api.entity.request.GoodsQuery; | ||||
import com.tuoheng.common.common.IBaseService; | import com.tuoheng.common.common.IBaseService; | ||||
import com.tuoheng.common.utils.JsonResult; | import com.tuoheng.common.utils.JsonResult; | ||||
JsonResult queryPage(GoodsQuery goodsQuery); | JsonResult queryPage(GoodsQuery goodsQuery); | ||||
JsonResult merchantInfo(GoodsQuery goodsQuery); | JsonResult merchantInfo(GoodsQuery goodsQuery); | ||||
JsonResult exchange(ExchangeRequest exchangeRequest); | |||||
} | } |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||||
import com.tuoheng.api.entity.domain.Goods; | import com.tuoheng.api.entity.domain.Goods; | ||||
import com.tuoheng.api.entity.domain.Merchant; | 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.entity.request.GoodsQuery; | ||||
import com.tuoheng.api.mapper.GoodsMapper; | import com.tuoheng.api.mapper.GoodsMapper; | ||||
import com.tuoheng.api.mapper.MerchantMapper; | 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.api.service.IGoodsService; | ||||
import com.tuoheng.api.utils.PointsTitleConstants; | |||||
import com.tuoheng.common.common.BaseServiceImpl; | import com.tuoheng.common.common.BaseServiceImpl; | ||||
import com.tuoheng.common.utils.CommonUtils; | import com.tuoheng.common.utils.CommonUtils; | ||||
import com.tuoheng.common.utils.JsonResult; | import com.tuoheng.common.utils.JsonResult; | ||||
import com.tuoheng.common.utils.StringUtils; | import com.tuoheng.common.utils.StringUtils; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.springframework.beans.BeanUtils; | |||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
import java.util.Date; | |||||
@Service | @Service | ||||
@Slf4j | @Slf4j | ||||
public class GoodsServiceImpl extends BaseServiceImpl<GoodsMapper, Goods> implements IGoodsService { | public class GoodsServiceImpl extends BaseServiceImpl<GoodsMapper, Goods> implements IGoodsService { | ||||
@Autowired | @Autowired | ||||
private MerchantMapper merchantMapper; | private MerchantMapper merchantMapper; | ||||
@Autowired | |||||
private UserPointsDetailMapper userPointsDetailMapper; | |||||
@Autowired | |||||
private WestreamUserMapper westreamUserMapper; | |||||
@Override | @Override | ||||
return JsonResult.success(merchant); | 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("用户积分不足!"); | |||||
} | |||||
Merchant merchant = merchantMapper.selectById(goods.getMerchantId()); | |||||
UserPointsDetail userPointsDetail = new UserPointsDetail(); | |||||
userPointsDetail.setNickname(westreamUser.getNickname()); | |||||
userPointsDetail.setChangeName(goods.getGoodsName()); | |||||
userPointsDetail.setPointsChange(exchangePoints); | |||||
userPointsDetail.setPointsTime(new Date()); | |||||
userPointsDetail.setType(2); | |||||
if(ObjectUtil.isNotNull(merchant)){ | |||||
userPointsDetail.setOperatorId(merchant.getUserId()); | |||||
userPointsDetail.setOperatorName(merchant.getShopsName()); | |||||
} | |||||
userPointsDetail.setCreateTime(new Date()); | |||||
userPointsDetail.setExchangeFlag(0); | |||||
userPointsDetail.setGoodsPoints(goods.getGoodsPoints()); | |||||
BeanUtils.copyProperties(exchangeRequest, userPointsDetail); | |||||
userPointsDetailMapper.insert(userPointsDetail); | |||||
//更新用户积分 | |||||
westreamUser.setMallPoints(residuePoints); | |||||
westreamUserMapper.updateById(westreamUser); | |||||
return JsonResult.success(); | |||||
} | |||||
} | } |
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||||
import com.baomidou.mybatisplus.core.metadata.IPage; | import com.baomidou.mybatisplus.core.metadata.IPage; | ||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 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.Merchant; | ||||
import com.tuoheng.api.entity.domain.UserPointsDetail; | import com.tuoheng.api.entity.domain.UserPointsDetail; | ||||
import com.tuoheng.api.entity.request.UserPointsDetailQuery; | import com.tuoheng.api.entity.request.UserPointsDetailQuery; | ||||
import com.tuoheng.api.mapper.GoodsMapper; | |||||
import com.tuoheng.api.mapper.MerchantMapper; | import com.tuoheng.api.mapper.MerchantMapper; | ||||
import com.tuoheng.api.mapper.UserPointsDetailMapper; | import com.tuoheng.api.mapper.UserPointsDetailMapper; | ||||
import com.tuoheng.api.service.IUserPointsDetailService; | import com.tuoheng.api.service.IUserPointsDetailService; | ||||
@Autowired | @Autowired | ||||
MerchantMapper merchantMapper; | MerchantMapper merchantMapper; | ||||
@Autowired | |||||
GoodsMapper goodsMapper; | |||||
@Override | @Override | ||||
public JsonResult exchange(UserPointsDetailQuery query) { | public JsonResult exchange(UserPointsDetailQuery query) { | ||||
if (null == query.getPage() || null == query.getLimit()) { | if (null == query.getPage() || null == query.getLimit()) { | ||||
.orderByDesc(UserPointsDetail::getCreateTime)); | .orderByDesc(UserPointsDetail::getCreateTime)); | ||||
for (UserPointsDetail record : pageData.getRecords()) { | for (UserPointsDetail record : pageData.getRecords()) { | ||||
if(StringUtils.isNotEmpty(record.getOperatorName())){ | |||||
record.setShopsName(record.getOperatorName()); | |||||
} | |||||
if(null != record.getOperatorId()){ | if(null != record.getOperatorId()){ | ||||
//查询商铺信息 | //查询商铺信息 | ||||
Merchant merchant = merchantMapper.selectOne(new LambdaQueryWrapper<Merchant>() | Merchant merchant = merchantMapper.selectOne(new LambdaQueryWrapper<Merchant>() | ||||
if(ObjectUtil.isNotNull(merchant)){ | if(ObjectUtil.isNotNull(merchant)){ | ||||
if(StringUtils.isNotEmpty(merchant.getShopsImage())){ | if(StringUtils.isNotEmpty(merchant.getShopsImage())){ | ||||
record.setShopsImage(CommonUtils.getMultipleUrl(merchant.getShopsImage())); | |||||
merchant.setShopsImage(CommonUtils.getMultipleUrl(merchant.getShopsImage())); | |||||
} | |||||
record.setMerchant(merchant); | |||||
} | |||||
} | |||||
if(null != record.getGoodsId()){ | |||||
//查询商品信息 | |||||
Goods goods = goodsMapper.selectById(record.getGoodsId()); | |||||
if(ObjectUtil.isNotNull(goods)){ | |||||
if(StringUtils.isNotEmpty(goods.getGoodsImage())){ | |||||
goods.setGoodsImage(CommonUtils.getMultipleUrl(goods.getGoodsImage())); | |||||
} | } | ||||
record.setShopsName(merchant.getShopsName()); | |||||
record.setAreaName(merchant.getAreaName()); | |||||
record.setGoods(goods); | |||||
} | } | ||||
} | } |