|
|
@ -15,6 +15,7 @@ import com.yxt.yythmall.api.empcardbuildrecord.EmpCardBuildRecordQuery; |
|
|
|
import com.yxt.yythmall.api.empcardbuildrecord.EmpCardBuildRecordVo; |
|
|
|
import com.yxt.yythmall.api.lpkcustomer.LpkCustomer; |
|
|
|
import com.yxt.yythmall.api.lpkgiftcard.LpkGiftCardQuery; |
|
|
|
import com.yxt.yythmall.api.lpkgoods.LpkGoods; |
|
|
|
import com.yxt.yythmall.api.ordorder.OrdOrderDto; |
|
|
|
import com.yxt.yythmall.api.ordorderdetails.OrdOrderDetailVo; |
|
|
|
import com.yxt.yythmall.api.shoppingcart.ShoppingCart; |
|
|
@ -23,6 +24,7 @@ import com.yxt.yythmall.api.shoppingcart.ShoppingCartQuery; |
|
|
|
import com.yxt.yythmall.api.shoppingcart.ShoppingCartVo; |
|
|
|
import com.yxt.yythmall.biz.empcard.EmpCardService; |
|
|
|
import com.yxt.yythmall.biz.lpkcustomer.LpkCustomerService; |
|
|
|
import com.yxt.yythmall.biz.lpkgoods.LpkGoodsService; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@ -41,20 +43,22 @@ public class ShoppingCartService extends MybatisBaseService<ShoppingCartMapper, |
|
|
|
private FileUploadComponent fileUploadComponent; |
|
|
|
@Autowired |
|
|
|
LpkCustomerService lpkCustomerService; |
|
|
|
@Autowired |
|
|
|
private LpkGoodsService lpkGoodsService; |
|
|
|
|
|
|
|
public ResultBean save(ShoppingCartDto dto) { |
|
|
|
public ResultBean save(ShoppingCartDto dto) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
ShoppingCart entity=new ShoppingCart(); |
|
|
|
List<ShoppingCart> list= baseMapper.selectList(new QueryWrapper<ShoppingCart>().eq("customerSid",dto.getCustomerSid()) |
|
|
|
.eq("goodsSid",dto.getGoodsSid()) |
|
|
|
.eq("affiliation",dto.getAffiliation())); |
|
|
|
if(list.size()>0){ |
|
|
|
ShoppingCart entity = new ShoppingCart(); |
|
|
|
List<ShoppingCart> list = baseMapper.selectList(new QueryWrapper<ShoppingCart>().eq("customerSid", dto.getCustomerSid()) |
|
|
|
.eq("goodsSid", dto.getGoodsSid()) |
|
|
|
.eq("affiliation", dto.getAffiliation())); |
|
|
|
if (list.size() > 0) { |
|
|
|
// list.get(0).setGoodsNumber(String.valueOf(Double.valueOf(dto.getGoodsNumber())+Double.valueOf(list.get(0).getGoodsNumber())));
|
|
|
|
if(dto.getGoodsNumber().equals("0")){ |
|
|
|
baseMapper.delete(new QueryWrapper<ShoppingCart>().eq("customerSid",dto.getCustomerSid()) |
|
|
|
.eq("goodsSid",dto.getGoodsSid()) |
|
|
|
.eq("affiliation",dto.getAffiliation())); |
|
|
|
}else{ |
|
|
|
if (dto.getGoodsNumber().equals("0")) { |
|
|
|
baseMapper.delete(new QueryWrapper<ShoppingCart>().eq("customerSid", dto.getCustomerSid()) |
|
|
|
.eq("goodsSid", dto.getGoodsSid()) |
|
|
|
.eq("affiliation", dto.getAffiliation())); |
|
|
|
} else { |
|
|
|
list.get(0).setGoodsNumber(dto.getGoodsNumber()); |
|
|
|
baseMapper.updateById(list.get(0)); |
|
|
|
} |
|
|
@ -64,26 +68,28 @@ public class ShoppingCartService extends MybatisBaseService<ShoppingCartMapper, |
|
|
|
baseMapper.insert(entity); |
|
|
|
return rb.success().setMsg("成功"); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<List<ShoppingCartVo>> shoppingCartList(ShoppingCartQuery query) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
ShoppingCart entity=new ShoppingCart(); |
|
|
|
List<ShoppingCartVo> list= baseMapper.ShoppingCartList(query.getCustomerSid(),query.getBrandId()); |
|
|
|
list.forEach(s->{ |
|
|
|
s.setTotalPrice(removeZeros(String.valueOf((Double.valueOf(s.getJPrice())* Double.valueOf(s.getGoodsNumber()))))); |
|
|
|
s.setIconUrl(fileUploadComponent.getUrlPrefix() +s.getIconUrl()); |
|
|
|
ShoppingCart entity = new ShoppingCart(); |
|
|
|
List<ShoppingCartVo> list = baseMapper.ShoppingCartList(query.getCustomerSid(), query.getBrandId()); |
|
|
|
list.forEach(s -> { |
|
|
|
s.setTotalPrice(removeZeros(String.valueOf((Double.valueOf(s.getJPrice()) * Double.valueOf(s.getGoodsNumber()))))); |
|
|
|
s.setIconUrl(fileUploadComponent.getUrlPrefix() + s.getIconUrl()); |
|
|
|
}); |
|
|
|
|
|
|
|
return rb.success().setData(list).setMsg("成功"); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean minusShoppingCart(ShoppingCartDto dto) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
ShoppingCart entity=new ShoppingCart(); |
|
|
|
ShoppingCart entity = new ShoppingCart(); |
|
|
|
// List<ShoppingCart> list= baseMapper.selectList(new QueryWrapper<ShoppingCart>().eq("sid",dto.getSid()));
|
|
|
|
List<ShoppingCart> list= baseMapper.selectList(new QueryWrapper<ShoppingCart>().eq("customerSid",dto.getCustomerSid()) |
|
|
|
.eq("goodsSid",dto.getGoodsSid()) |
|
|
|
.eq("affiliation",dto.getAffiliation())); |
|
|
|
if(list.size()>0){ |
|
|
|
list.get(0).setGoodsNumber(String.valueOf(Double.valueOf(list.get(0).getGoodsNumber())-Double.valueOf(dto.getGoodsNumber()))); |
|
|
|
List<ShoppingCart> list = baseMapper.selectList(new QueryWrapper<ShoppingCart>().eq("customerSid", dto.getCustomerSid()) |
|
|
|
.eq("goodsSid", dto.getGoodsSid()) |
|
|
|
.eq("affiliation", dto.getAffiliation())); |
|
|
|
if (list.size() > 0) { |
|
|
|
list.get(0).setGoodsNumber(String.valueOf(Double.valueOf(list.get(0).getGoodsNumber()) - Double.valueOf(dto.getGoodsNumber()))); |
|
|
|
baseMapper.updateById(list.get(0)); |
|
|
|
return rb.success().setMsg("成功"); |
|
|
|
} |
|
|
@ -91,22 +97,42 @@ public class ShoppingCartService extends MybatisBaseService<ShoppingCartMapper, |
|
|
|
// baseMapper.insert(entity);
|
|
|
|
return rb.success().setMsg("成功"); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean delShoppingCart(String sid) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
ShoppingCart entity=new ShoppingCart(); |
|
|
|
baseMapper.delete(new QueryWrapper<ShoppingCart>().eq("sid ",sid)); |
|
|
|
ShoppingCart entity = new ShoppingCart(); |
|
|
|
baseMapper.delete(new QueryWrapper<ShoppingCart>().eq("sid ", sid)); |
|
|
|
return rb.success().setMsg("成功"); |
|
|
|
} |
|
|
|
public ResultBean getGoodsWeight(ShoppingCartQuery query) { |
|
|
|
ResultBean rb=new ResultBean().fail(); |
|
|
|
List<ShoppingCartVo> list= baseMapper.ShoppingCartList(query.getCustomerSid(),query.getBrandId()); |
|
|
|
double price =0; |
|
|
|
double weight =0; |
|
|
|
for(ShoppingCartVo vo:list){ |
|
|
|
price=Double.valueOf(vo.getPrice())*Double.valueOf(vo.getGoodsNumber())+price; |
|
|
|
weight=Double.valueOf(vo.getWeight())*Double.valueOf(vo.getGoodsNumber())+weight; |
|
|
|
|
|
|
|
public ResultBean getGoodsWeight(ShoppingCartQuery query) { |
|
|
|
ResultBean rb = new ResultBean().fail(); |
|
|
|
List<ShoppingCartVo> list = baseMapper.ShoppingCartList(query.getCustomerSid(), query.getBrandId()); |
|
|
|
double price = 0; |
|
|
|
double weight = 0; |
|
|
|
for (ShoppingCartVo vo : list) { |
|
|
|
LpkGoods lpkGoods = lpkGoodsService.fetchBySid(vo.getGoodsSid()); |
|
|
|
String stepWeight = lpkGoods.getStepWeight(); |
|
|
|
String stepPrice = lpkGoods.getStepPrice(); |
|
|
|
if (new BigDecimal(stepPrice).compareTo(BigDecimal.ZERO) == 0) { |
|
|
|
stepPrice = vo.getJPrice(); |
|
|
|
} |
|
|
|
if ("北京3号白菜".equals(vo.getGoodsName()) |
|
|
|
|| "玲珑黄白菜".equals(vo.getGoodsName()) |
|
|
|
|| "V7土豆".equals(vo.getGoodsName()) |
|
|
|
|| "黄金薯土豆".equals(vo.getGoodsName())) { |
|
|
|
BigDecimal weightW = new BigDecimal(vo.getWeight()); |
|
|
|
if (weightW.compareTo(new BigDecimal(stepWeight)) >= 0) { |
|
|
|
price = Double.valueOf(stepPrice) * Double.valueOf(vo.getGoodsNumber()) + price; |
|
|
|
weight = Double.valueOf(vo.getWeight()) * Double.valueOf(vo.getGoodsNumber()) + price; |
|
|
|
} |
|
|
|
} else { |
|
|
|
price = Double.valueOf(vo.getPrice()) * Double.valueOf(vo.getGoodsNumber()) + price; |
|
|
|
weight = Double.valueOf(vo.getWeight()) * Double.valueOf(vo.getGoodsNumber()) + weight; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
ShoppingCartVo vo =new ShoppingCartVo(); |
|
|
|
ShoppingCartVo vo = new ShoppingCartVo(); |
|
|
|
// vo.setText("1.20斤起订量。\n" +
|
|
|
|
// "2.新用户正好20斤5折。\n" +
|
|
|
|
// "3.20-100斤加10%附加额。\n" +
|
|
|
@ -114,27 +140,28 @@ public class ShoppingCartService extends MybatisBaseService<ShoppingCartMapper, |
|
|
|
vo.setCustomerSid(query.getCustomerSid()); |
|
|
|
vo.setTotalPrice(removeZeros(String.valueOf(price))); |
|
|
|
vo.setTotalWeight(removeZeros(String.valueOf(weight))); |
|
|
|
vo=price(vo); |
|
|
|
vo = price(vo); |
|
|
|
return rb.success().setData(vo); |
|
|
|
} |
|
|
|
private ShoppingCartVo price(ShoppingCartVo vo){ |
|
|
|
int weight=Integer.parseInt(vo.getTotalWeight()); |
|
|
|
LpkCustomer lpkCustomer=lpkCustomerService.getOne(new QueryWrapper<LpkCustomer>().eq("sid",vo.getCustomerSid())); |
|
|
|
|
|
|
|
private ShoppingCartVo price(ShoppingCartVo vo) { |
|
|
|
int weight = Integer.parseInt(vo.getTotalWeight()); |
|
|
|
LpkCustomer lpkCustomer = lpkCustomerService.getOne(new QueryWrapper<LpkCustomer>().eq("sid", vo.getCustomerSid())); |
|
|
|
vo.setRemarks("已减免附加额"); |
|
|
|
if(weight<=99){ |
|
|
|
if(weight<20){ |
|
|
|
if (weight <= 99) { |
|
|
|
if (weight < 20) { |
|
|
|
vo.setRemarks("不足20斤"); |
|
|
|
}else{ |
|
|
|
double a =1.1; |
|
|
|
double d=Double.valueOf(vo.getTotalPrice()); |
|
|
|
double t=Double.valueOf(vo.getTotalPrice())*a; |
|
|
|
} else { |
|
|
|
double a = 1.1; |
|
|
|
double d = Double.valueOf(vo.getTotalPrice()); |
|
|
|
double t = Double.valueOf(vo.getTotalPrice()) * a; |
|
|
|
BigDecimal bg = new BigDecimal(t); |
|
|
|
vo.setTotalPrice(String.valueOf(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())); |
|
|
|
// String c =String.valueOf(Double.valueOf(vo.getTotalPrice())-d);
|
|
|
|
double f=Double.valueOf(vo.getTotalPrice())-d; |
|
|
|
double f = Double.valueOf(vo.getTotalPrice()) - d; |
|
|
|
BigDecimal bgd = new BigDecimal(f); |
|
|
|
String c =String.valueOf(bgd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); |
|
|
|
vo.setRemarks("含附加额"+removeZeros(c)+"元"); |
|
|
|
String c = String.valueOf(bgd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); |
|
|
|
vo.setRemarks("含附加额" + removeZeros(c) + "元"); |
|
|
|
} |
|
|
|
// if(weight==20){
|
|
|
|
// if(lpkCustomer.getIsPurchase().equals("1")){
|
|
|
@ -167,22 +194,24 @@ public class ShoppingCartService extends MybatisBaseService<ShoppingCartMapper, |
|
|
|
// vo.setRemarks("包含附加费"+removeZeros(c)+"元");
|
|
|
|
// }
|
|
|
|
|
|
|
|
}else if(weight>=100 && weight<=199){ |
|
|
|
double a =1.05; |
|
|
|
double d=Double.valueOf(vo.getTotalPrice()); |
|
|
|
double t=Double.valueOf(vo.getTotalPrice())*a; |
|
|
|
} else if (weight >= 100 && weight <= 199) { |
|
|
|
double a = 1.05; |
|
|
|
double d = Double.valueOf(vo.getTotalPrice()); |
|
|
|
double t = Double.valueOf(vo.getTotalPrice()) * a; |
|
|
|
BigDecimal bg = new BigDecimal(t); |
|
|
|
vo.setTotalPrice(String.valueOf(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())); |
|
|
|
// String c =String.valueOf(Double.valueOf(vo.getTotalPrice())-d);
|
|
|
|
double f=Double.valueOf(vo.getTotalPrice())-d; |
|
|
|
double f = Double.valueOf(vo.getTotalPrice()) - d; |
|
|
|
BigDecimal bgd = new BigDecimal(f); |
|
|
|
String c =String.valueOf(bgd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); |
|
|
|
vo.setRemarks("含附加额"+removeZeros(c)+"元"); |
|
|
|
String c = String.valueOf(bgd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); |
|
|
|
vo.setRemarks("含附加额" + removeZeros(c) + "元"); |
|
|
|
} |
|
|
|
return vo; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 去除多余.0 |
|
|
|
* |
|
|
|
* @param num |
|
|
|
* @return |
|
|
|
*/ |
|
|
|