Skip to content

Commit

Permalink
fix issue linlinjava#516
Browse files Browse the repository at this point in the history
  • Loading branch information
860560622 committed Oct 30, 2023
1 parent 47ea5c7 commit 0e3ee0b
Show file tree
Hide file tree
Showing 3 changed files with 306 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
package org.linlinjava.litemall.db.domain;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
* 临时数据传输结构
* 在原有LitemallCart属性上增加一个库存信息
* */


public class LitemallCartData {
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_cart
*
* @mbg.generated
*/
public static final Boolean IS_DELETED = LitemallCart.Deleted.IS_DELETED.value();

/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_cart
*
* @mbg.generated
*/
public static final Boolean NOT_DELETED = LitemallCart.Deleted.NOT_DELETED.value();

/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_cart.id
*
* @mbg.generated
*/
private Integer id;

/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_cart.user_id
*
* @mbg.generated
*/
private Integer userId;

/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_cart.goods_id
*
* @mbg.generated
*/
private Integer goodsId;

/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_cart.goods_sn
*
* @mbg.generated
*/
private String goodsSn;

/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_cart.goods_name
*
* @mbg.generated
*/
private String goodsName;

/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_cart.product_id
*
* @mbg.generated
*/
private Integer productId;

/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_cart.price
*
* @mbg.generated
*/
private BigDecimal price;

/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_cart.number
*
* @mbg.generated
*/
private Short number;

/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_cart.specifications
*
* @mbg.generated
*/
private String[] specifications;

/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_cart.checked
*
* @mbg.generated
*/
private Boolean checked;

/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_cart.pic_url
*
* @mbg.generated
*/
private String picUrl;

/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_cart.add_time
*
* @mbg.generated
*/
private LocalDateTime addTime;

/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_cart.update_time
*
* @mbg.generated
*/
private LocalDateTime updateTime;

/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_cart.deleted
*
* @mbg.generated
*/
private Boolean deleted;

private Short stock;//库存

public LitemallCartData(LitemallCart litemallCart,Short stock) {
this.stock = stock;
this.addTime = litemallCart.getAddTime();
this.deleted = litemallCart.getDeleted();
this.id = litemallCart.getId();
this.number = litemallCart.getNumber();
this.checked = litemallCart.getChecked();
this.goodsId = litemallCart.getGoodsId();
this.goodsName = litemallCart.getGoodsName();
this.goodsSn = litemallCart.getGoodsSn();
this.picUrl = litemallCart.getPicUrl();
this.price = litemallCart.getPrice();
this.specifications = litemallCart.getSpecifications();
this.productId = litemallCart.getProductId(); //商品id
this.updateTime = litemallCart.getUpdateTime();
this.userId = litemallCart.getUserId();
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public Integer getUserId() {
return userId;
}

public void setUserId(Integer userId) {
this.userId = userId;
}

public Integer getGoodsId() {
return goodsId;
}

public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}

public String getGoodsSn() {
return goodsSn;
}

public void setGoodsSn(String goodsSn) {
this.goodsSn = goodsSn;
}

public String getGoodsName() {
return goodsName;
}

public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}

public Integer getProductId() {
return productId;
}

public void setProductId(Integer productId) {
this.productId = productId;
}

public BigDecimal getPrice() {
return price;
}

public void setPrice(BigDecimal price) {
this.price = price;
}

public Short getNumber() {
return number;
}

public void setNumber(Short number) {
this.number = number;
}

public String[] getSpecifications() {
return specifications;
}

public void setSpecifications(String[] specifications) {
this.specifications = specifications;
}

public Boolean getChecked() {
return checked;
}

public void setChecked(Boolean checked) {
this.checked = checked;
}

public String getPicUrl() {
return picUrl;
}

public void setPicUrl(String picUrl) {
this.picUrl = picUrl;
}

public LocalDateTime getAddTime() {
return addTime;
}

public void setAddTime(LocalDateTime addTime) {
this.addTime = addTime;
}

public LocalDateTime getUpdateTime() {
return updateTime;
}

public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}

public Boolean getDeleted() {
return deleted;
}

public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}

public Short getStock() {
return stock;
}

public void setStock(Short stock) {
this.stock = stock;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public Object index(@LoginUser Integer userId) {
if (userId == null) {
return ResponseUtil.unlogin();
}

//根据用户id查找购物车内容
List<LitemallCart> list = cartService.queryByUid(userId);
List<LitemallCart> cartList = new ArrayList<>();
List<LitemallCartData> cartList = new ArrayList<>();
// TODO
// 如果系统检查商品已删除或已下架,则系统自动删除。
// 更好的效果应该是告知用户商品失效,允许用户点击按钮来清除失效商品。
Expand All @@ -70,15 +70,16 @@ public Object index(@LoginUser Integer userId) {
logger.debug("系统自动删除失效购物车商品 goodsId=" + cart.getGoodsId() + " productId=" + cart.getProductId());
}
else{
cartList.add(cart);
Short stock = productService.findById(cart.getProductId()).getNumber().shortValue();//获取库存
cartList.add(new LitemallCartData(cart,stock));//创建传输流数据
}
}

Integer goodsCount = 0;
BigDecimal goodsAmount = new BigDecimal(0.00);
Integer checkedGoodsCount = 0;
BigDecimal checkedGoodsAmount = new BigDecimal(0.00);
for (LitemallCart cart : cartList) {
for (LitemallCartData cart : cartList) {
goodsCount += cart.getNumber();
goodsAmount = goodsAmount.add(cart.getPrice().multiply(new BigDecimal(cart.getNumber())));
if (cart.getChecked()) {
Expand Down
9 changes: 7 additions & 2 deletions litemall-wx/pages/cart/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,14 @@ Page({
},
addNumber: function(event) {
let itemIndex = event.target.dataset.itemIndex;
let cartItem = this.data.cartGoods[itemIndex];
let cartItem = this.data.cartGoods[itemIndex]; //LitemallCartData类
let number = cartItem.number + 1;
cartItem.number = number;
if(number > cartItem.stock){
// 创建一个警告弹窗
alert("库存不足");
}else {
cartItem.number = number;
}
this.setData({
cartGoods: this.data.cartGoods
});
Expand Down

0 comments on commit 0e3ee0b

Please sign in to comment.