Переглянути джерело

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 Переглянути файл

@@ -1,5 +1,7 @@
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.service.IGoodsService;
import com.tuoheng.common.utils.JsonResult;
@@ -41,4 +43,17 @@ public class GoodsController {
public JsonResult merchantInfo(GoodsQuery 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 Переглянути файл

@@ -68,20 +68,34 @@ public class UserPointsDetail extends BaseEntity implements Serializable {
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)
private String shopsImage;
private Merchant merchant;

/**
* 区域名称
* 商品信息
*/
@TableField(exist = false)
private String areaName;
private Goods goods;
}

+ 24
- 0
tuoheng-api/src/main/java/com/tuoheng/api/entity/request/ExchangeRequest.java Переглянути файл

@@ -0,0 +1,24 @@
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 Переглянути файл

@@ -2,6 +2,7 @@ package com.tuoheng.api.service;


import com.tuoheng.api.entity.domain.Goods;
import com.tuoheng.api.entity.request.ExchangeRequest;
import com.tuoheng.api.entity.request.GoodsQuery;
import com.tuoheng.common.common.IBaseService;
import com.tuoheng.common.utils.JsonResult;
@@ -10,4 +11,6 @@ public interface IGoodsService extends IBaseService<Goods> {
JsonResult queryPage(GoodsQuery goodsQuery);

JsonResult merchantInfo(GoodsQuery goodsQuery);

JsonResult exchange(ExchangeRequest exchangeRequest);
}

+ 74
- 0
tuoheng-api/src/main/java/com/tuoheng/api/service/impl/GoodsServiceImpl.java Переглянути файл

@@ -6,18 +6,27 @@ 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.api.utils.PointsTitleConstants;
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;

import java.util.Date;

@Service
@Slf4j
public class GoodsServiceImpl extends BaseServiceImpl<GoodsMapper, Goods> implements IGoodsService {
@@ -28,6 +37,12 @@ public class GoodsServiceImpl extends BaseServiceImpl<GoodsMapper, Goods> implem
@Autowired
private MerchantMapper merchantMapper;

@Autowired
private UserPointsDetailMapper userPointsDetailMapper;

@Autowired
private WestreamUserMapper westreamUserMapper;



@Override
@@ -75,4 +90,63 @@ 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("用户积分不足!");
}

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 Переглянути файл

@@ -4,9 +4,11 @@ import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.request.UserPointsDetailQuery;
import com.tuoheng.api.mapper.GoodsMapper;
import com.tuoheng.api.mapper.MerchantMapper;
import com.tuoheng.api.mapper.UserPointsDetailMapper;
import com.tuoheng.api.service.IUserPointsDetailService;
@@ -35,6 +37,9 @@ public class UserPointsDetailServiceImpl extends BaseServiceImpl<UserPointsDetai
@Autowired
MerchantMapper merchantMapper;

@Autowired
GoodsMapper goodsMapper;

@Override
public JsonResult exchange(UserPointsDetailQuery query) {
if (null == query.getPage() || null == query.getLimit()) {
@@ -57,9 +62,6 @@ public class UserPointsDetailServiceImpl extends BaseServiceImpl<UserPointsDetai
.orderByDesc(UserPointsDetail::getCreateTime));

for (UserPointsDetail record : pageData.getRecords()) {
if(StringUtils.isNotEmpty(record.getOperatorName())){
record.setShopsName(record.getOperatorName());
}
if(null != record.getOperatorId()){
//查询商铺信息
Merchant merchant = merchantMapper.selectOne(new LambdaQueryWrapper<Merchant>()
@@ -68,10 +70,23 @@ public class UserPointsDetailServiceImpl extends BaseServiceImpl<UserPointsDetai

if(ObjectUtil.isNotNull(merchant)){
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);
}

}

Завантаження…
Відмінити
Зберегти