package com.panzhihua.service_community.service.impl;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.panzhihua.common.model.vos.LoginUserInfoVO;
|
import com.panzhihua.common.model.vos.R;
|
import com.panzhihua.common.model.vos.community.VolunteerCreditsExchangeVO;
|
import com.panzhihua.common.model.vos.community.VolunteerIntegralMerchantVO;
|
import com.panzhihua.common.model.vos.community.VolunteerTypeVO;
|
import com.panzhihua.common.service.user.UserService;
|
import com.panzhihua.common.utlis.Snowflake;
|
import com.panzhihua.common.utlis.StringUtils;
|
import com.panzhihua.service_community.dao.VolunteerCreditsExchangeDao;
|
import com.panzhihua.service_community.dao.VolunteerTypeDao;
|
import com.panzhihua.service_community.entity.VolunteerActivity;
|
import com.panzhihua.service_community.entity.VolunteerCreditsExchange;
|
import com.panzhihua.service_community.entity.VolunteerIntegralMerchant;
|
import com.panzhihua.service_community.entity.VolunteerType;
|
import com.panzhihua.service_community.service.VolunteerCreditsExchangeService;
|
import com.panzhihua.service_community.service.VolunteerIntegralMerchantService;
|
import com.panzhihua.service_community.service.VolunteerTypeService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
|
|
@Slf4j
|
@Service
|
public class VolunteerCreditsExchangeServiceImpl extends ServiceImpl<VolunteerCreditsExchangeDao,
|
VolunteerCreditsExchange> implements VolunteerCreditsExchangeService {
|
|
@Resource
|
private VolunteerIntegralMerchantService goodsService;
|
|
@Resource
|
private UserService userService;
|
|
@Override
|
public R getList(int pageNum, int pageSize, String goodsId, String orderNumber,
|
String goodsName, String condition, String userName,String communityId,String userId) {
|
|
Page page=new Page<VolunteerCreditsExchange>(pageNum,pageSize);
|
return R.ok(baseMapper.getList(page,goodsId,orderNumber,goodsName,condition,userName,communityId,userId));
|
}
|
|
@Override
|
public R getData(String id) {
|
return R.ok(baseMapper.getData(id));
|
}
|
|
@Override
|
public R insertData(VolunteerCreditsExchangeVO item)
|
{
|
if (item==null)
|
{
|
return R.fail("参数不能为空");
|
}
|
|
if(StringUtils.isEmpty(item.getGoodsId()))
|
{
|
return R.fail("商品id不能为空");
|
}
|
|
VolunteerIntegralMerchant goods=goodsService.queryById(item.getGoodsId());
|
if(goods==null)
|
{
|
return R.fail("商品不存在");
|
}
|
|
if(StringUtils.isEmpty(goods.getGoodNum()))
|
{
|
return R.fail("商品库存不足");
|
}
|
else
|
{
|
int goodNum=Integer.valueOf(goods.getGoodNum());
|
if(goodNum<=0)
|
{
|
return R.fail("商品库存不足");
|
}
|
|
goodNum--;
|
|
VolunteerIntegralMerchantVO vo=new VolunteerIntegralMerchantVO();
|
vo.setId(goods.getId());
|
vo.setGoodNum(goodNum+"");
|
goodsService.updateById(vo);
|
}
|
|
|
LoginUserInfoVO loginUserInfoVOR=userService.getUserInfoByUserId(item.getUserId()).getData();
|
|
int integral=0;
|
if(!StringUtils.isEmpty(loginUserInfoVOR.getLoveIntegral()))
|
{
|
integral=Integer.valueOf(loginUserInfoVOR.getLoveIntegral());
|
}
|
|
if(integral<Integer.valueOf(goods.getIntegral()))
|
{
|
return R.fail("剩余积分不足!无法下单兑换");
|
}
|
|
item.setNeedScore(goods.getIntegral());
|
|
if(StringUtils.isEmpty(item.getUserId()))
|
{
|
return R.fail("兑换用户id不能为空");
|
}
|
|
int num1=integral-Integer.valueOf(goods.getIntegral());
|
loginUserInfoVOR.setLoveIntegral(num1+"");
|
userService.putUser(loginUserInfoVOR);
|
|
//设置订单号
|
item.setOrderNumber(Snowflake.getId()+"");
|
int num= baseMapper.insertData(item);
|
if(num>0)
|
{
|
return R.ok();
|
}
|
return R.fail("操作失败");
|
}
|
|
@Override
|
public R update(VolunteerCreditsExchangeVO item)
|
{
|
if (item==null)
|
{
|
return R.fail("参数不能为空");
|
}
|
|
if(StringUtils.isEmpty(item.getGoodsId()))
|
{
|
return R.fail("商品id不能为空");
|
}
|
|
if(StringUtils.isEmpty(item.getNeedScore()))
|
{
|
return R.fail("所需积分不能为空");
|
}
|
|
if(StringUtils.isEmpty(item.getUserId()))
|
{
|
return R.fail("兑换用户id不能为空");
|
}
|
int num= baseMapper.update(item);
|
if(num>0)
|
{
|
return R.ok();
|
}
|
return R.fail("操作失败");
|
}
|
|
@Override
|
public R delete(String id) {
|
if(StringUtils.isEmpty(id))
|
{
|
return R.fail("删除订单id不能为空");
|
}
|
|
|
int num= baseMapper.delete(id);
|
if(num>0)
|
{
|
return R.ok();
|
}
|
return R.fail("操作失败");
|
}
|
|
@Override
|
public R conditionData(String id)
|
{
|
if(StringUtils.isEmpty(id))
|
{
|
return R.fail("核销订单id不能为空");
|
}
|
|
int num= baseMapper.conditionData(id);
|
if(num>0)
|
{
|
return R.ok();
|
}
|
return R.fail("操作失败");
|
}
|
}
|