|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.yxt.yyth.biz.lpkgiftcard; |
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
@ -13,6 +14,7 @@ import com.yxt.yyth.api.lpkgiftbaggoods.LpkGiftBagGoodsVo; |
|
|
|
import com.yxt.yyth.api.lpkgiftcard.*; |
|
|
|
import com.yxt.yyth.api.lpkreserveordergoods.LpkReserveOrderGoods; |
|
|
|
import com.yxt.yyth.api.lpkstore.StoreSelect; |
|
|
|
import com.yxt.yyth.biz.lpkgiftcard.generateRule.UniqueIdGenerator; |
|
|
|
import com.yxt.yyth.biz.lpkreserveordergoods.LpkReserveOrderGoodsService; |
|
|
|
import com.yxt.yyth.biz.lpkstore.LpkStoreService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -22,6 +24,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Random; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author wangpengfei |
|
|
@ -38,11 +41,11 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp |
|
|
|
@Autowired |
|
|
|
LpkStoreService lpkStoreService; |
|
|
|
|
|
|
|
public ResultBean bindCard( BindCardDto bindCardDto) { |
|
|
|
ResultBean rb=new ResultBean().fail(); |
|
|
|
LpkGiftCard lpkGiftCard=baseMapper.selectOne(new QueryWrapper<LpkGiftCard>().eq("code",bindCardDto.getCode()) |
|
|
|
.eq("codeKey",bindCardDto.getCodeKey()).eq("state","2")); |
|
|
|
if(null==lpkGiftCard){ |
|
|
|
public ResultBean bindCard(BindCardDto bindCardDto) { |
|
|
|
ResultBean rb = new ResultBean().fail(); |
|
|
|
LpkGiftCard lpkGiftCard = baseMapper.selectOne(new QueryWrapper<LpkGiftCard>().eq("code", bindCardDto.getCode()) |
|
|
|
.eq("codeKey", bindCardDto.getCodeKey()).eq("state", "2")); |
|
|
|
if (null == lpkGiftCard) { |
|
|
|
return rb.setMsg("请核对卡号和密钥"); |
|
|
|
} |
|
|
|
lpkGiftCard.setCustomerSid(bindCardDto.getCustomerSid()); |
|
|
@ -50,44 +53,46 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp |
|
|
|
baseMapper.updateById(lpkGiftCard); |
|
|
|
return rb.success().setMsg("绑定成功"); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean getGifCardByCustomerSid(PagerQuery<LpkGiftCardQuery> pq) { |
|
|
|
ResultBean rb=new ResultBean().fail(); |
|
|
|
ResultBean rb = new ResultBean().fail(); |
|
|
|
LpkGiftCardQuery query = pq.getParams(); |
|
|
|
QueryWrapper<LpkGiftCard> qw = new QueryWrapper<>(); |
|
|
|
if (StringUtils.isNotBlank(query.getCustomerSid())) { |
|
|
|
qw.like("customerSid", query.getCustomerSid()); |
|
|
|
} |
|
|
|
IPage<LpkGiftCard> page = PagerUtil.queryToPage(pq); |
|
|
|
IPage<AppletVo> list=baseMapper.getGifCardByCustomerSid(page,qw); |
|
|
|
IPage<AppletVo> list = baseMapper.getGifCardByCustomerSid(page, qw); |
|
|
|
PagerVo<AppletVo> p = PagerUtil.pageToVo(list, null); |
|
|
|
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
return rb.success().setData(p); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean getGifCardBySid(String sid) { |
|
|
|
ResultBean rb=new ResultBean().fail(); |
|
|
|
AppletVo vo=baseMapper.getGifCardBySid(sid); |
|
|
|
List<LpkGiftBagGoodsVo> list=LpkGiftBagGoodsService.getGoodsByBagSid(vo.getGiftbagSid()); |
|
|
|
List<GoodsVo> goodsVos=new ArrayList<>(); |
|
|
|
list.forEach(s->{ |
|
|
|
if(vo.getState().equals("失效")){ |
|
|
|
GoodsVo goodsVo=new GoodsVo(); |
|
|
|
ResultBean rb = new ResultBean().fail(); |
|
|
|
AppletVo vo = baseMapper.getGifCardBySid(sid); |
|
|
|
List<LpkGiftBagGoodsVo> list = LpkGiftBagGoodsService.getGoodsByBagSid(vo.getGiftbagSid()); |
|
|
|
List<GoodsVo> goodsVos = new ArrayList<>(); |
|
|
|
list.forEach(s -> { |
|
|
|
if (vo.getState().equals("失效")) { |
|
|
|
GoodsVo goodsVo = new GoodsVo(); |
|
|
|
goodsVo.setGoods(s.getGoodsName()); |
|
|
|
goodsVo.setNum(s.getGoodsNumber()); |
|
|
|
goodsVo.setPic(urlPrefix+s.getPicUrl()); |
|
|
|
goodsVo.setPic(urlPrefix + s.getPicUrl()); |
|
|
|
goodsVo.setLNum(0); |
|
|
|
goodsVos.add(goodsVo); |
|
|
|
}else if(!vo.isShowBtn()){ |
|
|
|
GoodsVo goodsVo=new GoodsVo(); |
|
|
|
} else if (!vo.isShowBtn()) { |
|
|
|
GoodsVo goodsVo = new GoodsVo(); |
|
|
|
goodsVo.setGoods(s.getGoodsName()); |
|
|
|
goodsVo.setNum(s.getGoodsNumber()); |
|
|
|
goodsVo.setPic(urlPrefix+s.getPicUrl()); |
|
|
|
goodsVo.setPic(urlPrefix + s.getPicUrl()); |
|
|
|
goodsVo.setLNum(0); |
|
|
|
goodsVos.add(goodsVo); |
|
|
|
}else{ |
|
|
|
GoodsVo goodsVo=new GoodsVo(); |
|
|
|
} else { |
|
|
|
GoodsVo goodsVo = new GoodsVo(); |
|
|
|
goodsVo.setGoods(s.getGoodsName()); |
|
|
|
goodsVo.setNum(s.getGoodsNumber()); |
|
|
|
goodsVo.setPic(urlPrefix+s.getPicUrl()); |
|
|
|
goodsVo.setPic(urlPrefix + s.getPicUrl()); |
|
|
|
goodsVo.setLNum(s.getGoodsNumber()); |
|
|
|
goodsVos.add(goodsVo); |
|
|
|
} |
|
|
@ -103,26 +108,27 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp |
|
|
|
vo.setGoodsVos(goodsVos); |
|
|
|
return rb.success().setData(vo); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean getReservationBySid(String sid) { |
|
|
|
ResultBean rb=new ResultBean().fail(); |
|
|
|
AppletVo vo=baseMapper.getGifCardBySid(sid); |
|
|
|
List<LpkGiftBagGoodsVo> list=LpkGiftBagGoodsService.getGoodsByBagSid(vo.getGiftbagSid()); |
|
|
|
List<StoreSelect> l=lpkStoreService.getAllStore().getData(); |
|
|
|
ResultBean rb = new ResultBean().fail(); |
|
|
|
AppletVo vo = baseMapper.getGifCardBySid(sid); |
|
|
|
List<LpkGiftBagGoodsVo> list = LpkGiftBagGoodsService.getGoodsByBagSid(vo.getGiftbagSid()); |
|
|
|
List<StoreSelect> l = lpkStoreService.getAllStore().getData(); |
|
|
|
|
|
|
|
List<GoodsVo> goodsVos=new ArrayList<>(); |
|
|
|
list.forEach(s->{ |
|
|
|
LpkReserveOrderGoods goods=lpkReserveOrderGoodsService.getReserveByCardSid(vo.getSid(),s.getGoodsSid()).getData(); |
|
|
|
GoodsVo goodsVo=new GoodsVo(); |
|
|
|
List<GoodsVo> goodsVos = new ArrayList<>(); |
|
|
|
list.forEach(s -> { |
|
|
|
LpkReserveOrderGoods goods = lpkReserveOrderGoodsService.getReserveByCardSid(vo.getSid(), s.getGoodsSid()).getData(); |
|
|
|
GoodsVo goodsVo = new GoodsVo(); |
|
|
|
goodsVo.setGoods(s.getGoodsName()); |
|
|
|
goodsVo.setNum(s.getGoodsNumber()); |
|
|
|
goodsVo.setGoodsSid(s.getGoodsSid()); |
|
|
|
goodsVo.setPic(urlPrefix+s.getPicUrl()); |
|
|
|
if(null!=goods){ |
|
|
|
if(goods.getGoodsNumber()!=s.getGoodsNumber()){ |
|
|
|
goodsVo.setLNum(s.getGoodsNumber()-goods.getGoodsNumber()); |
|
|
|
goodsVo.setPic(urlPrefix + s.getPicUrl()); |
|
|
|
if (null != goods) { |
|
|
|
if (goods.getGoodsNumber() != s.getGoodsNumber()) { |
|
|
|
goodsVo.setLNum(s.getGoodsNumber() - goods.getGoodsNumber()); |
|
|
|
goodsVos.add(goodsVo); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
goodsVo.setLNum(s.getGoodsNumber()); |
|
|
|
goodsVos.add(goodsVo); |
|
|
|
} |
|
|
@ -132,4 +138,39 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp |
|
|
|
return rb.success().setData(vo); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean generateCard(LpkGiftCardDto dto) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
if (StringUtils.isBlank(dto.getGiftbagSid())) { |
|
|
|
return rb.setMsg("请添加礼包"); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(dto.getNum())) { |
|
|
|
return rb.setMsg("请输入生成卡片的数量"); |
|
|
|
} |
|
|
|
int i = Integer.parseInt(dto.getNum()); |
|
|
|
for (int j = 0; j < i; j++) { |
|
|
|
LpkGiftCard card = new LpkGiftCard(); |
|
|
|
card.setState("1"); |
|
|
|
card.setCreateTime(new DateTime()); |
|
|
|
card.setGiftbagSid(dto.getGiftbagSid()); |
|
|
|
int randomNumber = new Random().nextInt(900000) + 100000; |
|
|
|
card.setCodeKey(String.valueOf(randomNumber)); |
|
|
|
card.setCode(UniqueIdGenerator.generateUniqueID()); |
|
|
|
String maxSerNum = baseMapper.selctMaxSerNum(); |
|
|
|
if (StringUtils.isBlank(maxSerNum)) { |
|
|
|
card.setSerialNumber("00000001"); |
|
|
|
} else { |
|
|
|
int i1 = Integer.parseInt(maxSerNum); |
|
|
|
int finNum = i1 + 1; |
|
|
|
int length = String.valueOf(finNum).length(); |
|
|
|
int len = 8 - length; |
|
|
|
String num = String.valueOf(finNum); |
|
|
|
for (int a = 0; a < len; a++) { |
|
|
|
num = "0" + num; |
|
|
|
} |
|
|
|
card.setSerialNumber(num); |
|
|
|
} |
|
|
|
baseMapper.insert(card); |
|
|
|
} |
|
|
|
return rb.success(); |
|
|
|
} |
|
|
|
} |
|
|
|