Bläddra i källkod

我的兑换

pull/22/head
wanghaoran 1 år sedan
förälder
incheckning
e3c37c616a
6 ändrade filer med 104 tillägg och 17 borttagningar
  1. +17
    -0
      tuoheng-api/src/main/java/com/tuoheng/api/controller/GoodsController.java
  2. +4
    -11
      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. +54
    -0
      tuoheng-api/src/main/java/com/tuoheng/api/service/impl/GoodsServiceImpl.java
  6. +2
    -6
      tuoheng-api/src/main/java/com/tuoheng/api/service/impl/UserPointsDetailServiceImpl.java

+ 17
- 0
tuoheng-api/src/main/java/com/tuoheng/api/controller/GoodsController.java Visa fil

@@ -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,19 @@ 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);
}


}

+ 4
- 11
tuoheng-api/src/main/java/com/tuoheng/api/entity/domain/UserPointsDetail.java Visa fil

@@ -68,20 +68,13 @@ public class UserPointsDetail extends BaseEntity implements Serializable {
private String changeName;

/**
* 商铺名称
* 核销标识,0待核销,1已核销
*/
@TableField(exist = false)
private String shopsName;

/**
* 商铺图片
*/
@TableField(exist = false)
private String shopsImage;
private Integer exchangeFlag;

/**
* 区域名称
* 商铺信息
*/
@TableField(exist = false)
private String areaName;
private Merchant merchant;
}

+ 24
- 0
tuoheng-api/src/main/java/com/tuoheng/api/entity/request/ExchangeRequest.java Visa fil

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

/**
* 商品id
*/
private Integer goodsCount;
}

+ 3
- 0
tuoheng-api/src/main/java/com/tuoheng/api/service/IGoodsService.java Visa fil

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

+ 54
- 0
tuoheng-api/src/main/java/com/tuoheng/api/service/impl/GoodsServiceImpl.java Visa fil

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

}

+ 2
- 6
tuoheng-api/src/main/java/com/tuoheng/api/service/impl/UserPointsDetailServiceImpl.java Visa fil

@@ -57,9 +57,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 +65,9 @@ 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.setShopsName(merchant.getShopsName());
record.setAreaName(merchant.getAreaName());
record.setMerchant(merchant);
}

}

Laddar…
Avbryt
Spara