22 changed files with 595 additions and 11 deletions
@ -0,0 +1,61 @@ |
|||
package com.yxt.yythmall.api.appletgiftbag; |
|||
|
|||
import cn.hutool.core.util.NumberUtil; |
|||
import cn.hutool.core.util.StrUtil; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @author wangpengfei |
|||
* @date 2024/1/16 12:07 |
|||
*/ |
|||
@Data |
|||
public class GiftBagGoodss { |
|||
private String goodsSid; |
|||
private String goodsNumber = "0";//份数
|
|||
private String name; //商品名
|
|||
private String unitName; //单位
|
|||
private String price; //商品单价
|
|||
private String iconUrl;//图片
|
|||
private String remark; //备注
|
|||
private String weight; //每份的重量
|
|||
private String jPrice; //每斤单价
|
|||
private String specificationUnit; //规格单位
|
|||
private String totalValue; //总价值
|
|||
private String spec; //总价值
|
|||
private String count="0"; //总价值
|
|||
private String mefenPrice="0"; |
|||
private boolean showCart=false; |
|||
|
|||
|
|||
|
|||
public String getSubtotal() { |
|||
double dj = 0.0; |
|||
if (StrUtil.isNotBlank(price)) { |
|||
try { |
|||
dj = Double.parseDouble(price); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
int js = 1; |
|||
if (StrUtil.isNotBlank(weight)) { |
|||
try { |
|||
js = Integer.parseInt(weight); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
int fs = 1; |
|||
if (StrUtil.isNotBlank(goodsNumber)) { |
|||
try { |
|||
fs = Integer.parseInt(goodsNumber); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
double mfjg = dj * js * fs; |
|||
int m=(int)mfjg; |
|||
// return NumberUtil.decimalFormatMoney(mfjg);
|
|||
return String.valueOf(m); |
|||
} |
|||
} |
@ -0,0 +1,16 @@ |
|||
package com.yxt.yythmall.api.appletgiftbag; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author wangpengfei |
|||
* @date 2024/1/17 10:18 |
|||
*/ |
|||
@Data |
|||
public class GoodsV { |
|||
private String weight; |
|||
private String price; |
|||
private List<GiftBagGoodss> giftBagGoodssList; |
|||
} |
@ -0,0 +1,23 @@ |
|||
package com.yxt.yythmall.api.appletgiftbag; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @author wangpengfei |
|||
* @date 2024/1/18 8:50 |
|||
*/ |
|||
@Data |
|||
public class MyGoodsVo { |
|||
private String goodsSid; |
|||
private String name; //商品名
|
|||
private String goodsNumber ;//份数
|
|||
private String residue ;//剩余
|
|||
private String iconUrl;//图片
|
|||
private String weight; //每份的重量
|
|||
private String remark; //备注
|
|||
private String type; //0 百姓菜窖 1 精品菜窖 2 企业菜窖
|
|||
private String specificationUnit; //规格单位
|
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,13 @@ |
|||
package com.yxt.yythmall.api.lpkgiftcard; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @author wangpengfei |
|||
* @date 2024/1/15 15:06 |
|||
*/ |
|||
@Data |
|||
public class GoodsTypeVo { |
|||
private String name; |
|||
private String sid; |
|||
} |
@ -0,0 +1,29 @@ |
|||
package com.yxt.yythmall.api.shoppingcart; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import lombok.Data; |
|||
|
|||
import java.util.Date; |
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* @author wangpengfei |
|||
* @date 2023/12/8 9:10 |
|||
*/ |
|||
@Data |
|||
public class ShoppingCart { |
|||
private String id; |
|||
private String sid= UUID.randomUUID().toString(); |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
|||
private Date createTime; |
|||
private String isEnable; |
|||
private String goodsSid; |
|||
private String goodsName; |
|||
private String goodsNumber; |
|||
private String affiliation; |
|||
private String price; |
|||
private String customerSid; |
|||
private String weight; //每份重量
|
|||
|
|||
|
|||
} |
@ -0,0 +1,28 @@ |
|||
package com.yxt.yythmall.api.shoppingcart; |
|||
|
|||
import com.yxt.common.core.dto.Dto; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @author wangpengfei |
|||
* @date 2023/12/8 9:11 |
|||
*/ |
|||
@Data |
|||
public class ShoppingCartDto implements Dto { |
|||
|
|||
|
|||
|
|||
private String id; |
|||
private String sid; |
|||
private String createTime; |
|||
private String remarks; |
|||
private String isEnable; |
|||
private String goodsSid;//商品sid
|
|||
private String goodsName;//商品名称
|
|||
private String goodsNumber;//商品数量
|
|||
private String affiliation;//所属菜窖 1百姓菜窖 2 精品菜窖 3企业菜窖
|
|||
private String price;//价格
|
|||
private String customerSid; //客户sid
|
|||
private String weight; //每份重量
|
|||
|
|||
} |
@ -0,0 +1,15 @@ |
|||
package com.yxt.yythmall.api.shoppingcart; |
|||
|
|||
import com.yxt.common.core.query.Query; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @author wangpengfei |
|||
* @date 2023/12/8 9:11 |
|||
*/ |
|||
@Data |
|||
public class ShoppingCartQuery implements Query { |
|||
private String customerSid; //客户
|
|||
private String affiliation; //类型
|
|||
|
|||
} |
@ -0,0 +1,34 @@ |
|||
package com.yxt.yythmall.api.shoppingcart; |
|||
|
|||
import com.yxt.common.core.vo.Vo; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @author wangpengfei |
|||
* @date 2023/12/8 9:11 |
|||
*/ |
|||
@Data |
|||
public class ShoppingCartVo implements Vo { |
|||
private String id; |
|||
private String sid; |
|||
private String createTime; |
|||
private String remarks; |
|||
private String isEnable; |
|||
private String goodsSid;//商品sid
|
|||
private String goodsName;//商品名称
|
|||
private String goodsNumber;//商品数量
|
|||
private String affiliation;//所属菜窖 1百姓菜窖 2 精品菜窖 3企业菜窖
|
|||
private String price;//价格
|
|||
private String jPrice;//价格
|
|||
private String customerSid; //客户sid
|
|||
|
|||
private String weight; //每份重量
|
|||
private String totalPrice; //总价格
|
|||
private String totalWeight; |
|||
|
|||
private String unitName; |
|||
private String iconUrl; |
|||
private String specificationUnit; |
|||
|
|||
|
|||
} |
@ -0,0 +1,8 @@ |
|||
package com.yxt.yythmall.api.shoppingcart; |
|||
|
|||
/** |
|||
* @author wangpengfei |
|||
* @date 2024/1/17 14:03 |
|||
*/ |
|||
public class ShoppingGoodsVo { |
|||
} |
@ -0,0 +1,23 @@ |
|||
package com.yxt.yythmall.biz.shoppingcart; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.core.toolkit.Constants; |
|||
import com.yxt.yythmall.api.empcardbuildrecord.EmpCardBuildRecord; |
|||
import com.yxt.yythmall.api.empcardbuildrecord.EmpCardBuildRecordVo; |
|||
import com.yxt.yythmall.api.shoppingcart.ShoppingCart; |
|||
import com.yxt.yythmall.api.shoppingcart.ShoppingCartVo; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Param; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author wangpengfei |
|||
* @date 2023/12/8 9:19 |
|||
*/ |
|||
@Mapper |
|||
public interface ShoppingCartMapper extends BaseMapper<ShoppingCart> { |
|||
List<ShoppingCartVo> ShoppingCartList(@Param("customerSid")String customerSid,@Param("affiliation")String affiliation); |
|||
} |
@ -0,0 +1,21 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.yxt.yythmall.biz.shoppingcart.ShoppingCartMapper"> |
|||
<!-- <where> ${ew.sqlSegment} </where>--> |
|||
<!-- ${ew.customSqlSegment} --> |
|||
|
|||
|
|||
<select id="ShoppingCartList" resultType="com.yxt.yythmall.api.shoppingcart.ShoppingCartVo"> |
|||
select |
|||
r.*,s.unitName, |
|||
s.price as jPrice, |
|||
s.picUrl as iconUrl, |
|||
s.specificationUnit, |
|||
s.content as remarks |
|||
from shopping_cart as r |
|||
left join lpk_goods s on s.sid=r.goodsSid |
|||
<where> |
|||
r.customerSid =#{customerSid} and r.affiliation=#{affiliation} |
|||
</where> |
|||
</select> |
|||
</mapper> |
@ -0,0 +1,54 @@ |
|||
package com.yxt.yythmall.biz.shoppingcart; |
|||
|
|||
import com.yxt.common.core.query.PagerQuery; |
|||
import com.yxt.common.core.result.ResultBean; |
|||
import com.yxt.common.core.vo.PagerVo; |
|||
import com.yxt.yythmall.api.empcardbuildrecord.EmpCardBuildRecordQuery; |
|||
import com.yxt.yythmall.api.empcardbuildrecord.EmpCardBuildRecordVo; |
|||
import com.yxt.yythmall.api.lpkgiftcard.LpkGiftCardQuery; |
|||
import com.yxt.yythmall.api.shoppingcart.ShoppingCartDto; |
|||
import com.yxt.yythmall.api.shoppingcart.ShoppingCartQuery; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
/** |
|||
* @author wangpengfei |
|||
* @date 2023/12/8 9:19 |
|||
*/ |
|||
@Api(tags = "购物车") |
|||
@RestController |
|||
@RequestMapping("shoppingcart") |
|||
public class ShoppingCartRest { |
|||
@Autowired |
|||
ShoppingCartService shoppingCartService; |
|||
|
|||
|
|||
@ApiOperation("加入购物车") |
|||
@PostMapping("/addShoppingCart") |
|||
public ResultBean save(@RequestBody ShoppingCartDto dto) { |
|||
return shoppingCartService.save(dto); |
|||
} |
|||
@ApiOperation("减购物车") |
|||
@PostMapping("/minusShoppingCart") |
|||
public ResultBean minusShoppingCart(@RequestBody ShoppingCartDto dto) { |
|||
return shoppingCartService.minusShoppingCart(dto); |
|||
} |
|||
@ApiOperation("购物车列表") |
|||
@PostMapping("/shoppingCartList") |
|||
public ResultBean shoppingCartList(@RequestBody ShoppingCartQuery query) { |
|||
return shoppingCartService.shoppingCartList(query); |
|||
} |
|||
|
|||
@ApiOperation("删除购物车商品") |
|||
@PostMapping("/delShoppingCart/{sid}") |
|||
public ResultBean delShoppingCart(@PathVariable("sid") String sid) { |
|||
return shoppingCartService.delShoppingCart(sid); |
|||
} |
|||
@ApiOperation("计算购物车价格和重量") |
|||
@PostMapping("/getGoodsWeight") |
|||
public ResultBean getGoodsWeight(@RequestBody ShoppingCartQuery query) { |
|||
return shoppingCartService.getGoodsWeight(query); |
|||
} |
|||
} |
@ -0,0 +1,107 @@ |
|||
package com.yxt.yythmall.biz.shoppingcart; |
|||
|
|||
import cn.hutool.core.bean.BeanUtil; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.yxt.common.base.config.component.FileUploadComponent; |
|||
import com.yxt.common.base.service.MybatisBaseService; |
|||
import com.yxt.common.base.utils.PagerUtil; |
|||
import com.yxt.common.base.utils.StringUtils; |
|||
import com.yxt.common.core.query.PagerQuery; |
|||
import com.yxt.common.core.result.ResultBean; |
|||
import com.yxt.common.core.vo.PagerVo; |
|||
import com.yxt.yythmall.api.empcardbuildrecord.EmpCardBuildRecord; |
|||
import com.yxt.yythmall.api.empcardbuildrecord.EmpCardBuildRecordQuery; |
|||
import com.yxt.yythmall.api.empcardbuildrecord.EmpCardBuildRecordVo; |
|||
import com.yxt.yythmall.api.lpkgiftcard.LpkGiftCardQuery; |
|||
import com.yxt.yythmall.api.shoppingcart.ShoppingCart; |
|||
import com.yxt.yythmall.api.shoppingcart.ShoppingCartDto; |
|||
import com.yxt.yythmall.api.shoppingcart.ShoppingCartQuery; |
|||
import com.yxt.yythmall.api.shoppingcart.ShoppingCartVo; |
|||
import com.yxt.yythmall.biz.empcard.EmpCardService; |
|||
import org.springframework.beans.BeanUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author wangpengfei |
|||
* @date 2023/12/8 9:19 |
|||
*/ |
|||
@Service |
|||
public class ShoppingCartService extends MybatisBaseService<ShoppingCartMapper, ShoppingCart> { |
|||
@Autowired |
|||
private FileUploadComponent fileUploadComponent; |
|||
|
|||
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){ |
|||
// 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{ |
|||
list.get(0).setGoodsNumber(dto.getGoodsNumber()); |
|||
baseMapper.updateById(list.get(0)); |
|||
} |
|||
return rb.success().setMsg("成功"); |
|||
} |
|||
BeanUtil.copyProperties(dto, entity, "id", "sid"); |
|||
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.getAffiliation()); |
|||
list.forEach(s->{ |
|||
s.setTotalPrice(String.valueOf((int)(Double.valueOf(s.getPrice())* 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(); |
|||
// 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()))); |
|||
baseMapper.updateById(list.get(0)); |
|||
return rb.success().setMsg("成功"); |
|||
} |
|||
// BeanUtil.copyProperties(dto, entity, "id", "sid");
|
|||
// 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)); |
|||
return rb.success().setMsg("成功"); |
|||
} |
|||
public ResultBean getGoodsWeight(ShoppingCartQuery query) { |
|||
ResultBean rb=new ResultBean().fail(); |
|||
List<ShoppingCartVo> list= baseMapper.ShoppingCartList(query.getCustomerSid(),query.getAffiliation()); |
|||
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; |
|||
} |
|||
ShoppingCartVo vo =new ShoppingCartVo(); |
|||
vo.setTotalPrice(String.valueOf((int) price)); |
|||
vo.setTotalWeight(String.valueOf((int)weight)); |
|||
return rb.success().setData(vo); |
|||
} |
|||
} |
Loading…
Reference in new issue