| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.panzhihua.common.model.dtos.equipment.UnionExchangeRecordDto; |
| | | import com.panzhihua.common.model.dtos.equipment.UnionIntegralRecordDto; |
| | | import com.panzhihua.common.model.dtos.equipment.UnionIntegralSummarizeDto; |
| | | import com.panzhihua.common.model.dtos.equipment.UnionStoreDto; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.utlis.Snowflake; |
| | | import com.panzhihua.common.utlis.StringUtils; |
| | | import com.panzhihua.service_equipment.dao.UnionExchangeRecordMapper; |
| | | import com.panzhihua.service_equipment.model.dos.UnionExchangeRecord; |
| | | import com.panzhihua.service_equipment.model.dos.UnionIntegralSummarize; |
| | | import com.panzhihua.service_equipment.model.dos.UnionStore; |
| | | import com.panzhihua.service_equipment.service.UnionExchangeRecordService; |
| | | import com.panzhihua.service_equipment.service.UnionIntegralRecordService; |
| | | import com.panzhihua.service_equipment.service.UnionIntegralSummarizeService; |
| | | import com.panzhihua.service_equipment.service.UnionStoreService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | |
| | | @Service |
| | |
| | | public class UnionExchangeRecordServiceImpl extends ServiceImpl<UnionExchangeRecordMapper, UnionExchangeRecord> |
| | | implements UnionExchangeRecordService |
| | | { |
| | | @Resource |
| | | private UnionStoreService unionStoreService; |
| | | |
| | | @Resource |
| | | private UnionIntegralSummarizeService unionIntegralSummarizeService; |
| | | |
| | | @Resource |
| | | private UnionIntegralRecordService unionIntegralRecordService; |
| | | |
| | | @Override |
| | | public R getList(int pageNum,int pageSize, String communityId, String userId) |
| | |
| | | @Override |
| | | public R insert(UnionExchangeRecordDto item) |
| | | { |
| | | if(StringUtils.isEmpty(item.getConsignee())) |
| | | { |
| | | return R.fail("收货信息不能为空"); |
| | | } |
| | | |
| | | R<UnionIntegralSummarize> unionIntegralSummarizeR=unionIntegralSummarizeService.getUserData(item.getUserId(),null); |
| | | //设置站点id |
| | | item.setCommunityId(unionIntegralSummarizeR.getData().getCommunityId()); |
| | | |
| | | R<UnionStore> unionStoreR = unionStoreService.getData(item.getGoodsId()); |
| | | //库存 |
| | | int stock = Integer.valueOf(unionStoreR.getData().getStock()); |
| | | //购买数量 |
| | | int goodNum = Integer.valueOf(item.getGoodsNum()); |
| | | //单价 |
| | | int conversionPrice = Integer.valueOf(unionStoreR.getData().getConversionPrice()); |
| | | |
| | | if (stock<goodNum) |
| | | { |
| | | return R.fail("商品库存不足!"); |
| | | } |
| | | |
| | | int allPrice=goodNum*conversionPrice; |
| | | |
| | | if(Integer.valueOf(unionIntegralSummarizeR.getData().getAllIntegral())<allPrice) |
| | | { |
| | | return R.fail("用户积分不足!"); |
| | | } |
| | | |
| | | //扣除用户积分 |
| | | int num1=Integer.valueOf(unionIntegralSummarizeR.getData().getAllIntegral())-allPrice; |
| | | UnionIntegralSummarizeDto dto=new UnionIntegralSummarizeDto(); |
| | | dto.setId(unionIntegralSummarizeR.getData().getId()); |
| | | dto.setAllIntegral(num1+""); |
| | | unionIntegralSummarizeService.update(dto); |
| | | |
| | | |
| | | //修改商品库存 |
| | | UnionStoreDto unionStoreDto=new UnionStoreDto(); |
| | | unionStoreDto.setId(unionStoreR.getData().getId()); |
| | | stock=stock-goodNum; |
| | | unionStoreDto.setStock(stock+""); |
| | | unionStoreService.update(unionStoreDto); |
| | | |
| | | //新增积分明细记录 |
| | | UnionIntegralRecordDto unionIntegralRecordDto=new UnionIntegralRecordDto(); |
| | | unionIntegralRecordDto.setIntegral(allPrice+""); |
| | | unionIntegralRecordDto.setIntegralType("2"); |
| | | unionIntegralRecordDto.setUserId(item.getUserId()); |
| | | unionIntegralRecordDto.setCommunityId(unionIntegralSummarizeR.getData().getCommunityId()); |
| | | unionIntegralRecordDto.setType("0"); |
| | | unionIntegralRecordService.insert(unionIntegralRecordDto); |
| | | |
| | | |
| | | item.setOrderNum(Snowflake.getId()+""); |
| | | item.setOrderType("1"); |
| | | item.setPlayIntegral(allPrice+""); |
| | | |
| | | int num= baseMapper.insert(item); |
| | | if(num>0) |
| | | { |
| | |
| | | @Override |
| | | public R delete(String id) |
| | | { |
| | | UnionExchangeRecord unionExchangeRecord=baseMapper.getData(id); |
| | | |
| | | if(StringUtils.equals("3",unionExchangeRecord.getOrderType()) |
| | | || StringUtils.equals("4",unionExchangeRecord.getOrderType()) ) |
| | | { |
| | | return R.fail("订单不能删除"); |
| | | } |
| | | |
| | | int num= baseMapper.delete(id); |
| | | if(num>0) |
| | | { |