Преглед на файлове

Merge branch 'release'

master
wanghaoran преди 11 месеца
родител
ревизия
537bf4b097
променени са 6 файла, в които са добавени 158 реда и са изтрити 13 реда
  1. +15
    -0
      tuoheng-api/src/main/java/com/tuoheng/api/controller/GoodsController.java
  2. +21
    -7
      tuoheng-api/src/main/java/com/tuoheng/api/entity/domain/UserPointsDetail.java
  3. +24
    -0
      tuoheng-api/src/main/java/com/tuoheng/api/entity/request/ExchangeRequest.java
  4. +3
    -0
      tuoheng-api/src/main/java/com/tuoheng/api/service/IGoodsService.java
  5. +74
    -0
      tuoheng-api/src/main/java/com/tuoheng/api/service/impl/GoodsServiceImpl.java
  6. +21
    -6
      tuoheng-api/src/main/java/com/tuoheng/api/service/impl/UserPointsDetailServiceImpl.java

+ 15
- 0
tuoheng-api/src/main/java/com/tuoheng/api/controller/GoodsController.java Целия файл

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);
}


} }

+ 21
- 7
tuoheng-api/src/main/java/com/tuoheng/api/entity/domain/UserPointsDetail.java Целия файл

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;
} }

+ 24
- 0
tuoheng-api/src/main/java/com/tuoheng/api/entity/request/ExchangeRequest.java Целия файл

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;
}

+ 3
- 0
tuoheng-api/src/main/java/com/tuoheng/api/service/IGoodsService.java Целия файл





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);
} }

+ 74
- 0
tuoheng-api/src/main/java/com/tuoheng/api/service/impl/GoodsServiceImpl.java Целия файл

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();
}

} }

+ 21
- 6
tuoheng-api/src/main/java/com/tuoheng/api/service/impl/UserPointsDetailServiceImpl.java Целия файл

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);
} }


} }

Loading…
Отказ
Запис