From f3d1c57f42c5a6835564ec37ac4ec64f940d8d7b Mon Sep 17 00:00:00 2001 From: hupeng Date: Sat, 14 Sep 2019 14:55:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E8=AE=A2=E5=8D=95=E5=AE=8C?= =?UTF-8?q?=E6=88=90,mall=E6=A8=A1=E5=9D=97=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/StoreCouponListMapper.java | 16 + .../persistence/dao/StoreCouponMapper.java | 26 + .../dao/StoreMemberAddressMapper.java | 16 + .../dao/StoreOrderGoodsMapper.java | 16 + .../persistence/dao/StoreOrderMapper.java | 2 +- .../dao/mapping/StoreCouponListMapper.xml | 19 + .../dao/mapping/StoreCouponMapper.xml | 24 + .../dao/mapping/StoreMemberAddressMapper.xml | 22 + .../dao/mapping/StoreOrderGoodsMapper.xml | 61 +- .../common/persistence/model/StoreCoupon.java | 242 +++++++ .../persistence/model/StoreCouponList.java | 170 +++++ .../persistence/model/StoreMemberAddress.java | 208 ++++++ .../common/persistence/model/StoreOrder.java | 17 +- .../persistence/model/StoreOrderGoods.java | 670 ++++++++---------- .../com/ruoyi/app/common/utils/OrderUtil.java | 34 + .../shop/controller/MallController.java | 21 +- .../shop/service/IOrderGoodsService.java | 12 + .../modular/shop/service/IOrderService.java | 23 + .../modular/shop/service/dto/CouponDTO.java | 21 + .../service/impl/OrderGoodsServiceImpl.java | 19 + .../shop/service/impl/OrderServiceImpl.java | 260 +++++++ .../app/modular/shop/service/vo/OrderVo.java | 27 + .../com/ruoyi/generator/EntityGenerator.java | 2 +- 23 files changed, 1529 insertions(+), 399 deletions(-) create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreCouponListMapper.java create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreCouponMapper.java create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreMemberAddressMapper.java create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreOrderGoodsMapper.java create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreCouponListMapper.xml create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreCouponMapper.xml create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreMemberAddressMapper.xml create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreCoupon.java create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreCouponList.java create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreMemberAddress.java create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/common/utils/OrderUtil.java create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/IOrderGoodsService.java create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/IOrderService.java create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/dto/CouponDTO.java create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/impl/OrderGoodsServiceImpl.java create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/impl/OrderServiceImpl.java create mode 100644 ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/vo/OrderVo.java diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreCouponListMapper.java b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreCouponListMapper.java new file mode 100644 index 0000000..e5f3e1f --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreCouponListMapper.java @@ -0,0 +1,16 @@ +package com.ruoyi.app.common.persistence.dao; + +import com.ruoyi.app.common.persistence.model.StoreCouponList; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 优惠券记录表 Mapper 接口 + *

+ * + * @author hupeng + * @since 2019-09-13 + */ +public interface StoreCouponListMapper extends BaseMapper { + +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreCouponMapper.java b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreCouponMapper.java new file mode 100644 index 0000000..b326548 --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreCouponMapper.java @@ -0,0 +1,26 @@ +package com.ruoyi.app.common.persistence.dao; + +import com.ruoyi.app.common.persistence.model.StoreCoupon; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ruoyi.app.modular.shop.service.dto.CouponDTO; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; + +/** + *

+ * 优惠券主表 Mapper 接口 + *

+ * + * @author hupeng + * @since 2019-09-13 + */ +public interface StoreCouponMapper extends BaseMapper { + + @Select("select s.id,c.money from store_coupon_list s left join store_coupon c " + + "on s.cid=c.id where s.id=#{id}") + CouponDTO findLog(int id); + + @Update("update store_coupon set use_num=use_num+1 where id=#{id}") + void incUserNum(int id); + +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreMemberAddressMapper.java b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreMemberAddressMapper.java new file mode 100644 index 0000000..3fae3eb --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreMemberAddressMapper.java @@ -0,0 +1,16 @@ +package com.ruoyi.app.common.persistence.dao; + +import com.ruoyi.app.common.persistence.model.StoreMemberAddress; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 商城会员收货地址 Mapper 接口 + *

+ * + * @author hupeng + * @since 2019-09-13 + */ +public interface StoreMemberAddressMapper extends BaseMapper { + +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreOrderGoodsMapper.java b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreOrderGoodsMapper.java new file mode 100644 index 0000000..67a3631 --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreOrderGoodsMapper.java @@ -0,0 +1,16 @@ +package com.ruoyi.app.common.persistence.dao; + +import com.ruoyi.app.common.persistence.model.StoreOrderGoods; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 订单商品表与订单主表关联 Mapper 接口 + *

+ * + * @author hupeng + * @since 2019-09-13 + */ +public interface StoreOrderGoodsMapper extends BaseMapper { + +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreOrderMapper.java b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreOrderMapper.java index 802a047..f6fe3b5 100644 --- a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreOrderMapper.java +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/StoreOrderMapper.java @@ -1,7 +1,7 @@ package com.ruoyi.app.common.persistence.dao; import com.ruoyi.app.common.persistence.model.StoreOrder; -import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; /** *

diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreCouponListMapper.xml b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreCouponListMapper.xml new file mode 100644 index 0000000..8a548f1 --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreCouponListMapper.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreCouponMapper.xml b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreCouponMapper.xml new file mode 100644 index 0000000..e7c221b --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreCouponMapper.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreMemberAddressMapper.xml b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreMemberAddressMapper.xml new file mode 100644 index 0000000..6c551a2 --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreMemberAddressMapper.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreOrderGoodsMapper.xml b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreOrderGoodsMapper.xml index fa5e6e0..4b9ab91 100644 --- a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreOrderGoodsMapper.xml +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/dao/mapping/StoreOrderGoodsMapper.xml @@ -1,32 +1,29 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreCoupon.java b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreCoupon.java new file mode 100644 index 0000000..e31eb30 --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreCoupon.java @@ -0,0 +1,242 @@ +package com.ruoyi.app.common.persistence.model; + + +import java.math.BigDecimal; +import java.util.Date; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import java.io.Serializable; + +/** + *

+ * 优惠券主表 + *

+ * + * @author hupeng + * @since 2019-09-13 + */ +@TableName("store_coupon") +public class StoreCoupon extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 表id + */ + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + /** + * 优惠券名字 + */ + private String name; + /** + * 发放类型 0下单赠送1 指定发放 2 免费领取 3线下发放 + */ + private Integer type; + /** + * 优惠券金额 + */ + private BigDecimal money; + /** + * 使用条件,满多少金额 + */ + private BigDecimal condition; + /** + * 发放数量 + */ + private Integer createnum; + /** + * 已领取数量 + */ + @TableField("send_num") + private Integer sendNum; + /** + * 已使用数量 + */ + @TableField("use_num") + private Integer useNum; + /** + * 发放开始时间 + */ + @TableField("send_start_time") + private Integer sendStartTime; + /** + * 发放结束时间 + */ + @TableField("send_end_time") + private Integer sendEndTime; + /** + * 使用开始时间 + */ + @TableField("use_start_time") + private Date useStartTime; + /** + * 使用结束时间 + */ + @TableField("use_end_time") + private Date useEndTime; + /** + * 添加时间 + */ + @TableField("add_time") + private Integer addTime; + /** + * 状态:1有效,2无效 + */ + private Integer status; + /** + * 使用范围:0全店通用1指定商品可用2指定分类商品可用 + */ + @TableField("use_type") + private Integer useType; + + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public BigDecimal getMoney() { + return money; + } + + public void setMoney(BigDecimal money) { + this.money = money; + } + + public BigDecimal getCondition() { + return condition; + } + + public void setCondition(BigDecimal condition) { + this.condition = condition; + } + + public Integer getCreatenum() { + return createnum; + } + + public void setCreatenum(Integer createnum) { + this.createnum = createnum; + } + + public Integer getSendNum() { + return sendNum; + } + + public void setSendNum(Integer sendNum) { + this.sendNum = sendNum; + } + + public Integer getUseNum() { + return useNum; + } + + public void setUseNum(Integer useNum) { + this.useNum = useNum; + } + + public Integer getSendStartTime() { + return sendStartTime; + } + + public void setSendStartTime(Integer sendStartTime) { + this.sendStartTime = sendStartTime; + } + + public Integer getSendEndTime() { + return sendEndTime; + } + + public void setSendEndTime(Integer sendEndTime) { + this.sendEndTime = sendEndTime; + } + + public Date getUseStartTime() { + return useStartTime; + } + + public void setUseStartTime(Date useStartTime) { + this.useStartTime = useStartTime; + } + + public Date getUseEndTime() { + return useEndTime; + } + + public void setUseEndTime(Date useEndTime) { + this.useEndTime = useEndTime; + } + + public Integer getAddTime() { + return addTime; + } + + public void setAddTime(Integer addTime) { + this.addTime = addTime; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public Integer getUseType() { + return useType; + } + + public void setUseType(Integer useType) { + this.useType = useType; + } + + @Override + protected Serializable pkVal() { + return this.id; + } + + @Override + public String toString() { + return "StoreCoupon{" + + ", id=" + id + + ", name=" + name + + ", type=" + type + + ", money=" + money + + ", condition=" + condition + + ", createnum=" + createnum + + ", sendNum=" + sendNum + + ", useNum=" + useNum + + ", sendStartTime=" + sendStartTime + + ", sendEndTime=" + sendEndTime + + ", useStartTime=" + useStartTime + + ", useEndTime=" + useEndTime + + ", addTime=" + addTime + + ", status=" + status + + ", useType=" + useType + + "}"; + } +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreCouponList.java b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreCouponList.java new file mode 100644 index 0000000..0a57cbc --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreCouponList.java @@ -0,0 +1,170 @@ +package com.ruoyi.app.common.persistence.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import java.io.Serializable; + +/** + *

+ * 优惠券记录表 + *

+ * + * @author hupeng + * @since 2019-09-13 + */ +@TableName("store_coupon_list") +public class StoreCouponList extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 表id + */ + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + /** + * 优惠券 对应coupon表id + */ + private Integer cid; + /** + * 发放类型 1 按订单发放 2 注册 3 邀请 4 按用户发放 + */ + private Integer type; + /** + * 用户id + */ + private Integer uid; + /** + * 订单id + */ + @TableField("order_id") + private Integer orderId; + /** + * 优惠券来自订单ID + */ + @TableField("get_order_id") + private Integer getOrderId; + /** + * 使用时间 + */ + @TableField("use_time") + private Integer useTime; + /** + * 优惠券兑换码 + */ + private String code; + /** + * 发放时间 + */ + @TableField("send_time") + private Integer sendTime; + /** + * 0未使用1已使用2已过期 + */ + private Integer status; + + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getCid() { + return cid; + } + + public void setCid(Integer cid) { + this.cid = cid; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public Integer getUid() { + return uid; + } + + public void setUid(Integer uid) { + this.uid = uid; + } + + public Integer getOrderId() { + return orderId; + } + + public void setOrderId(Integer orderId) { + this.orderId = orderId; + } + + public Integer getGetOrderId() { + return getOrderId; + } + + public void setGetOrderId(Integer getOrderId) { + this.getOrderId = getOrderId; + } + + public Integer getUseTime() { + return useTime; + } + + public void setUseTime(Integer useTime) { + this.useTime = useTime; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public Integer getSendTime() { + return sendTime; + } + + public void setSendTime(Integer sendTime) { + this.sendTime = sendTime; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + @Override + protected Serializable pkVal() { + return this.id; + } + + @Override + public String toString() { + return "StoreCouponList{" + + ", id=" + id + + ", cid=" + cid + + ", type=" + type + + ", uid=" + uid + + ", orderId=" + orderId + + ", getOrderId=" + getOrderId + + ", useTime=" + useTime + + ", code=" + code + + ", sendTime=" + sendTime + + ", status=" + status + + "}"; + } +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreMemberAddress.java b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreMemberAddress.java new file mode 100644 index 0000000..be3b4a3 --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreMemberAddress.java @@ -0,0 +1,208 @@ +package com.ruoyi.app.common.persistence.model; + + +import java.util.Date; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import java.io.Serializable; + +/** + *

+ * 商城会员收货地址 + *

+ * + * @author hupeng + * @since 2019-09-13 + */ +@TableName("store_member_address") +public class StoreMemberAddress extends Model { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + /** + * 会员ID + */ + private Long mid; + /** + * 收货人姓名 + */ + private String username; + /** + * 收货手机号 + */ + private String phone; + /** + * 收货地址省份 + */ + private String province; + /** + * 收货地址城市 + */ + private String city; + /** + * 收货地址区域 + */ + private String area; + /** + * 城市信息 + */ + @TableField("city_info") + private String cityInfo; + /** + * 收货详细地址 + */ + private String address; + /** + * 状态(0无效, 1新快递) + */ + private Integer status; + /** + * 默认收货地址 + */ + @TableField("is_default") + private Integer isDefault; + /** + * 删除状态(1删除,0未删除) + */ + @TableField("is_deleted") + private Long isDeleted; + /** + * 创建时间 + */ + @TableField("create_at") + private Date createAt; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getMid() { + return mid; + } + + public void setMid(Long mid) { + this.mid = mid; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getProvince() { + return province; + } + + public void setProvince(String province) { + this.province = province; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getArea() { + return area; + } + + public void setArea(String area) { + this.area = area; + } + + public String getCityInfo() { + return cityInfo; + } + + public void setCityInfo(String cityInfo) { + this.cityInfo = cityInfo; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public Integer getIsDefault() { + return isDefault; + } + + public void setIsDefault(Integer isDefault) { + this.isDefault = isDefault; + } + + public Long getIsDeleted() { + return isDeleted; + } + + public void setIsDeleted(Long isDeleted) { + this.isDeleted = isDeleted; + } + + public Date getCreateAt() { + return createAt; + } + + public void setCreateAt(Date createAt) { + this.createAt = createAt; + } + + @Override + protected Serializable pkVal() { + return this.id; + } + + @Override + public String toString() { + return "StoreMemberAddress{" + + ", id=" + id + + ", mid=" + mid + + ", username=" + username + + ", phone=" + phone + + ", province=" + province + + ", city=" + city + + ", area=" + area + + ", cityInfo=" + cityInfo + + ", address=" + address + + ", status=" + status + + ", isDefault=" + isDefault + + ", isDeleted=" + isDeleted + + ", createAt=" + createAt + + "}"; + } +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreOrder.java b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreOrder.java index fe8a025..8cb5a2d 100644 --- a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreOrder.java +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreOrder.java @@ -1,12 +1,11 @@ package com.ruoyi.app.common.persistence.model; -import com.baomidou.mybatisplus.enums.IdType; import java.math.BigDecimal; -import com.baomidou.mybatisplus.annotations.TableId; -import com.baomidou.mybatisplus.annotations.TableField; -import com.baomidou.mybatisplus.activerecord.Model; -import com.baomidou.mybatisplus.annotations.TableName; + +import com.baomidou.mybatisplus.annotation.*; +import com.baomidou.mybatisplus.extension.activerecord.Model; import java.io.Serializable; +import java.util.Date; /** *

@@ -194,8 +193,8 @@ public class StoreOrder extends Model { /** * 下单时间 */ - @TableField("add_time") - private Integer addTime; + @TableField(value = "add_time",fill = FieldFill.INSERT) + private Date addTime; /** * 最后新发货时间 */ @@ -599,11 +598,11 @@ public class StoreOrder extends Model { this.totalAmount = totalAmount; } - public Integer getAddTime() { + public Date getAddTime() { return addTime; } - public void setAddTime(Integer addTime) { + public void setAddTime(Date addTime) { this.addTime = addTime; } diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreOrderGoods.java b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreOrderGoods.java index b8a161e..9d19ce8 100644 --- a/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreOrderGoods.java +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/persistence/model/StoreOrderGoods.java @@ -1,355 +1,315 @@ -package com.ruoyi.app.common.persistence.model; - -import java.math.BigDecimal; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.extension.activerecord.Model; -import com.baomidou.mybatisplus.annotation.TableId; -import java.io.Serializable; - -/** - *

- * 订单商品表与订单主表关联 - *

- * - * @author hupeng - * @since 2019-06-26 - */ -public class StoreOrderGoods extends Model { - - private static final long serialVersionUID=1L; - - /** - * 表id自增 - */ - @TableId(value = "rec_id", type = IdType.AUTO) - private Integer recId; - - /** - * 订单id - */ - private Integer orderId; - - /** - * 商品id - */ - private Integer goodsId; - - /** - * 商品名称 - */ - private String goodsName; - - /** - * 商品货号 - */ - private String goodsSn; - - /** - * 购买数量 - */ - private Integer goodsNum; - - /** - * 市场价 - */ - private BigDecimal marketPrice; - - /** - * 本店价(供货价) - */ - private BigDecimal goodsPrice; - - /** - * 商品成本价 - */ - private BigDecimal costPrice; - - /** - * 会员折扣价 - */ - private BigDecimal memberGoodsPrice; - - /** - * 购买商品赠送积分 - */ - private Integer giveIntegral; - - /** - * 商品规格key - */ - private String specKey; - - /** - * 规格对应的中文名字 - */ - private String specKeyName; - - /** - * 条码 - */ - private String barCode; - - /** - * 是否评价 - */ - private Boolean isComment; - - /** - * 0 普通订单,1 限时抢购, 2 团购 , 3 促销优惠,4预售 - */ - private Boolean promType; - - /** - * 活动id - */ - private Integer promId; - - /** - * 0未支付1已支付 - */ - private Boolean payStatus; - - /** - * 0未发货,1已发货,2已换货,3已退货 - */ - private Boolean isSend; - - /** - * 发货单ID - */ - private Integer deliveryId; - - /** - * sku - */ - private String sku; - - /** - * 订单开始时间 - */ - private Integer startTime; - - /** - * 订单结束时间 - */ - private Integer endTime; - - - public Integer getRecId() { - return recId; - } - - public void setRecId(Integer recId) { - this.recId = recId; - } - - public Integer getOrderId() { - return orderId; - } - - public void setOrderId(Integer orderId) { - this.orderId = orderId; - } - - public Integer getGoodsId() { - return goodsId; - } - - public void setGoodsId(Integer goodsId) { - this.goodsId = goodsId; - } - - public String getGoodsName() { - return goodsName; - } - - public void setGoodsName(String goodsName) { - this.goodsName = goodsName; - } - - public String getGoodsSn() { - return goodsSn; - } - - public void setGoodsSn(String goodsSn) { - this.goodsSn = goodsSn; - } - - public Integer getGoodsNum() { - return goodsNum; - } - - public void setGoodsNum(Integer goodsNum) { - this.goodsNum = goodsNum; - } - - public BigDecimal getMarketPrice() { - return marketPrice; - } - - public void setMarketPrice(BigDecimal marketPrice) { - this.marketPrice = marketPrice; - } - - public BigDecimal getGoodsPrice() { - return goodsPrice; - } - - public void setGoodsPrice(BigDecimal goodsPrice) { - this.goodsPrice = goodsPrice; - } - - public BigDecimal getCostPrice() { - return costPrice; - } - - public void setCostPrice(BigDecimal costPrice) { - this.costPrice = costPrice; - } - - public BigDecimal getMemberGoodsPrice() { - return memberGoodsPrice; - } - - public void setMemberGoodsPrice(BigDecimal memberGoodsPrice) { - this.memberGoodsPrice = memberGoodsPrice; - } - - public Integer getGiveIntegral() { - return giveIntegral; - } - - public void setGiveIntegral(Integer giveIntegral) { - this.giveIntegral = giveIntegral; - } - - public String getSpecKey() { - return specKey; - } - - public void setSpecKey(String specKey) { - this.specKey = specKey; - } - - public String getSpecKeyName() { - return specKeyName; - } - - public void setSpecKeyName(String specKeyName) { - this.specKeyName = specKeyName; - } - - public String getBarCode() { - return barCode; - } - - public void setBarCode(String barCode) { - this.barCode = barCode; - } - - public Boolean getComment() { - return isComment; - } - - public void setComment(Boolean isComment) { - this.isComment = isComment; - } - - public Boolean getPromType() { - return promType; - } - - public void setPromType(Boolean promType) { - this.promType = promType; - } - - public Integer getPromId() { - return promId; - } - - public void setPromId(Integer promId) { - this.promId = promId; - } - - public Boolean getPayStatus() { - return payStatus; - } - - public void setPayStatus(Boolean payStatus) { - this.payStatus = payStatus; - } - - public Boolean getSend() { - return isSend; - } - - public void setSend(Boolean isSend) { - this.isSend = isSend; - } - - public Integer getDeliveryId() { - return deliveryId; - } - - public void setDeliveryId(Integer deliveryId) { - this.deliveryId = deliveryId; - } - - public String getSku() { - return sku; - } - - public void setSku(String sku) { - this.sku = sku; - } - - public Integer getStartTime() { - return startTime; - } - - public void setStartTime(Integer startTime) { - this.startTime = startTime; - } - - public Integer getEndTime() { - return endTime; - } - - public void setEndTime(Integer endTime) { - this.endTime = endTime; - } - - @Override - protected Serializable pkVal() { - return this.recId; - } - - @Override - public String toString() { - return "StoreOrderGoods{" + - "recId=" + recId + - ", orderId=" + orderId + - ", goodsId=" + goodsId + - ", goodsName=" + goodsName + - ", goodsSn=" + goodsSn + - ", goodsNum=" + goodsNum + - ", marketPrice=" + marketPrice + - ", goodsPrice=" + goodsPrice + - ", costPrice=" + costPrice + - ", memberGoodsPrice=" + memberGoodsPrice + - ", giveIntegral=" + giveIntegral + - ", specKey=" + specKey + - ", specKeyName=" + specKeyName + - ", barCode=" + barCode + - ", isComment=" + isComment + - ", promType=" + promType + - ", promId=" + promId + - ", payStatus=" + payStatus + - ", isSend=" + isSend + - ", deliveryId=" + deliveryId + - ", sku=" + sku + - ", startTime=" + startTime + - ", endTime=" + endTime + - "}"; - } -} +package com.ruoyi.app.common.persistence.model; + +import java.math.BigDecimal; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import java.io.Serializable; + +/** + *

+ * 订单商品表与订单主表关联 + *

+ * + * @author hupeng + * @since 2019-09-13 + */ +@TableName("store_order_goods") +public class StoreOrderGoods extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 表id自增 + */ + @TableId(value = "rec_id", type = IdType.AUTO) + private Integer recId; + /** + * 订单id + */ + @TableField("order_id") + private Integer orderId; + /** + * 商品id + */ + @TableField("goods_id") + private Integer goodsId; + /** + * 商品名称 + */ + @TableField("goods_name") + private String goodsName; + /** + * 商品货号 + */ + @TableField("goods_sn") + private String goodsSn; + /** + * 购买数量 + */ + @TableField("goods_num") + private Integer goodsNum; + /** + * 市场价 + */ + @TableField("market_price") + private BigDecimal marketPrice; + /** + * 本店价(供货价) + */ + @TableField("goods_price") + private BigDecimal goodsPrice; + /** + * 商品成本价 + */ + @TableField("cost_price") + private BigDecimal costPrice; + /** + * 会员折扣价 + */ + @TableField("member_goods_price") + private BigDecimal memberGoodsPrice; + /** + * 购买商品赠送积分 + */ + @TableField("give_integral") + private Integer giveIntegral; + /** + * 商品规格key + */ + @TableField("spec_key") + private String specKey; + /** + * 规格对应的中文名字 + */ + @TableField("spec_key_name") + private String specKeyName; + /** + * 条码 + */ + @TableField("bar_code") + private String barCode; + /** + * 是否评价 + */ + @TableField("is_comment") + private Integer isComment; + /** + * 0 普通订单,1 限时抢购, 2 团购 , 3 促销优惠,4预售 + */ + @TableField("prom_type") + private Integer promType; + /** + * 活动id + */ + @TableField("prom_id") + private Integer promId; + /** + * 0未发货,1已发货,2已换货,3已退货 + */ + @TableField("is_send") + private Integer isSend; + /** + * 发货单ID + */ + @TableField("delivery_id") + private Integer deliveryId; + /** + * sku + */ + private String sku; + + + public Integer getRecId() { + return recId; + } + + public void setRecId(Integer recId) { + this.recId = recId; + } + + public Integer getOrderId() { + return orderId; + } + + public void setOrderId(Integer orderId) { + this.orderId = orderId; + } + + public Integer getGoodsId() { + return goodsId; + } + + public void setGoodsId(Integer goodsId) { + this.goodsId = goodsId; + } + + public String getGoodsName() { + return goodsName; + } + + public void setGoodsName(String goodsName) { + this.goodsName = goodsName; + } + + public String getGoodsSn() { + return goodsSn; + } + + public void setGoodsSn(String goodsSn) { + this.goodsSn = goodsSn; + } + + public Integer getGoodsNum() { + return goodsNum; + } + + public void setGoodsNum(Integer goodsNum) { + this.goodsNum = goodsNum; + } + + public BigDecimal getMarketPrice() { + return marketPrice; + } + + public void setMarketPrice(BigDecimal marketPrice) { + this.marketPrice = marketPrice; + } + + public BigDecimal getGoodsPrice() { + return goodsPrice; + } + + public void setGoodsPrice(BigDecimal goodsPrice) { + this.goodsPrice = goodsPrice; + } + + public BigDecimal getCostPrice() { + return costPrice; + } + + public void setCostPrice(BigDecimal costPrice) { + this.costPrice = costPrice; + } + + public BigDecimal getMemberGoodsPrice() { + return memberGoodsPrice; + } + + public void setMemberGoodsPrice(BigDecimal memberGoodsPrice) { + this.memberGoodsPrice = memberGoodsPrice; + } + + public Integer getGiveIntegral() { + return giveIntegral; + } + + public void setGiveIntegral(Integer giveIntegral) { + this.giveIntegral = giveIntegral; + } + + public String getSpecKey() { + return specKey; + } + + public void setSpecKey(String specKey) { + this.specKey = specKey; + } + + public String getSpecKeyName() { + return specKeyName; + } + + public void setSpecKeyName(String specKeyName) { + this.specKeyName = specKeyName; + } + + public String getBarCode() { + return barCode; + } + + public void setBarCode(String barCode) { + this.barCode = barCode; + } + + public Integer getIsComment() { + return isComment; + } + + public void setIsComment(Integer isComment) { + this.isComment = isComment; + } + + public Integer getPromType() { + return promType; + } + + public void setPromType(Integer promType) { + this.promType = promType; + } + + public Integer getPromId() { + return promId; + } + + public void setPromId(Integer promId) { + this.promId = promId; + } + + public Integer getIsSend() { + return isSend; + } + + public void setIsSend(Integer isSend) { + this.isSend = isSend; + } + + public Integer getDeliveryId() { + return deliveryId; + } + + public void setDeliveryId(Integer deliveryId) { + this.deliveryId = deliveryId; + } + + public String getSku() { + return sku; + } + + public void setSku(String sku) { + this.sku = sku; + } + + @Override + protected Serializable pkVal() { + return this.recId; + } + + @Override + public String toString() { + return "StoreOrderGoods{" + + ", recId=" + recId + + ", orderId=" + orderId + + ", goodsId=" + goodsId + + ", goodsName=" + goodsName + + ", goodsSn=" + goodsSn + + ", goodsNum=" + goodsNum + + ", marketPrice=" + marketPrice + + ", goodsPrice=" + goodsPrice + + ", costPrice=" + costPrice + + ", memberGoodsPrice=" + memberGoodsPrice + + ", giveIntegral=" + giveIntegral + + ", specKey=" + specKey + + ", specKeyName=" + specKeyName + + ", barCode=" + barCode + + ", isComment=" + isComment + + ", promType=" + promType + + ", promId=" + promId + + ", isSend=" + isSend + + ", deliveryId=" + deliveryId + + ", sku=" + sku + + "}"; + } +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/common/utils/OrderUtil.java b/ruoyi-api/src/main/java/com/ruoyi/app/common/utils/OrderUtil.java new file mode 100644 index 0000000..48ae036 --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/common/utils/OrderUtil.java @@ -0,0 +1,34 @@ +package com.ruoyi.app.common.utils; + +import cn.hutool.core.date.DateUtil; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * @ClassName OrderUtil + * @Author hupeng <610796224@qq.com> + * @Date 2019/9/13 + **/ +public class OrderUtil { + + /** + * 时间戳订单号 + * @return + */ + public static String orderSn(){ + Date date = DateUtil.date(); + return DateUtil.format(date,"yyyyMMddHHmmssSSS"); + } + + + /** + * 获取精确到秒的时间戳 + * @param date + * @return + **/ + public static int getSecondTimestampTwo(){ + String timestamp = String.valueOf(new Date().getTime()/1000); + return Integer.valueOf(timestamp); + } +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/controller/MallController.java b/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/controller/MallController.java index b729724..fcdba36 100644 --- a/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/controller/MallController.java +++ b/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/controller/MallController.java @@ -3,16 +3,17 @@ package com.ruoyi.app.modular.shop.controller; import cn.hutool.core.util.StrUtil; import com.itmuch.lightsecurity.jwt.UserOperator; import com.ruoyi.app.common.R; -import com.ruoyi.app.common.exception.BadRequestException; import com.ruoyi.app.common.persistence.model.StoreSpecGoodsPrice; import com.ruoyi.app.modular.shop.service.dto.CateDTO; import com.ruoyi.app.modular.shop.service.dto.GoodsDTO; import com.ruoyi.app.modular.shop.service.dto.SpecItemDTO; import com.ruoyi.app.modular.shop.service.impl.CateServiceImpl; import com.ruoyi.app.modular.shop.service.impl.GoodsServiceImpl; +import com.ruoyi.app.modular.shop.service.impl.OrderServiceImpl; import com.ruoyi.app.modular.shop.service.mapper.GoodsMapper; import com.ruoyi.app.modular.shop.service.vo.CartVO; import com.ruoyi.app.modular.shop.service.vo.CollectVO; +import com.ruoyi.app.modular.shop.service.vo.OrderVo; import com.ruoyi.app.modular.shop.service.vo.PageVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -39,6 +40,7 @@ public class MallController { private final GoodsServiceImpl goodsService; private final UserOperator userOperator; private final GoodsMapper goodsMapper; + private final OrderServiceImpl orderervice; @GetMapping("/shop/mall-lists") @ApiOperation(value = "商品分类模块列表",notes = "商品分类模块列表") @@ -153,4 +155,21 @@ public class MallController { return R.success(goodsService.cartList(pageVO,userId)); } + @PostMapping("/shop/mall-order-submit") + @ApiOperation(value = "提交订单",notes = "提交订单") + public R submitOrder(@Validated @RequestBody OrderVo orderVo){ + int userId = userOperator.getUser().getId(); + String orderSn = ""; + if(Integer.valueOf(orderVo.getOrderFrom()) == 1){ + orderSn = orderervice.addOrderOfOne(orderVo,userId); + }else{ + orderSn = orderervice.addOrderOfTwo(orderVo,userId); + } + + HashMap map = new HashMap<>(); + map.put("orderSn",orderSn); + return R.success(map); + } + + } diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/IOrderGoodsService.java b/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/IOrderGoodsService.java new file mode 100644 index 0000000..dd47ff7 --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/IOrderGoodsService.java @@ -0,0 +1,12 @@ +package com.ruoyi.app.modular.shop.service; + + + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.app.common.persistence.model.StoreOrderGoods; + + +public interface IOrderGoodsService extends IService { + +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/IOrderService.java b/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/IOrderService.java new file mode 100644 index 0000000..227e00b --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/IOrderService.java @@ -0,0 +1,23 @@ +package com.ruoyi.app.modular.shop.service; + + + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.app.common.persistence.model.StoreOrder; +import com.ruoyi.app.modular.shop.service.vo.OrderVo; + + +import java.util.List; + + +public interface IOrderService extends IService { + + public String addOrderOfOne(OrderVo orderVo,int userId); + + public String addOrderOfTwo(OrderVo orderVo,int userId); + + public int checkStore(int goodsId,String spec_key); + + public void updateCouponStatus(int id); +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/dto/CouponDTO.java b/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/dto/CouponDTO.java new file mode 100644 index 0000000..8f30826 --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/dto/CouponDTO.java @@ -0,0 +1,21 @@ +package com.ruoyi.app.modular.shop.service.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @ClassName CouponDTO + * @Author hupeng <610796224@qq.com> + * @Date 2019/9/14 + **/ + +@Data +public class CouponDTO implements Serializable { + private int id; + private String name; + private Double money; + private Double condition; + private Date useEndTime; +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/impl/OrderGoodsServiceImpl.java b/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/impl/OrderGoodsServiceImpl.java new file mode 100644 index 0000000..364d4ea --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/impl/OrderGoodsServiceImpl.java @@ -0,0 +1,19 @@ +package com.ruoyi.app.modular.shop.service.impl; + + +//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; + + + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.app.common.persistence.dao.*; +import com.ruoyi.app.common.persistence.model.*; +import com.ruoyi.app.modular.shop.service.IOrderGoodsService; +import org.springframework.stereotype.Service; + + + +@Service +public class OrderGoodsServiceImpl extends ServiceImpl implements IOrderGoodsService { + +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/impl/OrderServiceImpl.java b/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/impl/OrderServiceImpl.java new file mode 100644 index 0000000..569601b --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/impl/OrderServiceImpl.java @@ -0,0 +1,260 @@ +package com.ruoyi.app.modular.shop.service.impl; + + +//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; + + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.RandomUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.itmuch.lightsecurity.exception.LightSecurityException; +import com.ruoyi.app.common.persistence.dao.*; +import com.ruoyi.app.common.persistence.model.*; +import com.ruoyi.app.common.utils.OrderUtil; +import com.ruoyi.app.modular.shop.service.IOrderService; +import com.ruoyi.app.modular.shop.service.dto.CouponDTO; +import com.ruoyi.app.modular.shop.service.vo.CartAttrVO; +import com.ruoyi.app.modular.shop.service.vo.CartVO; +import com.ruoyi.app.modular.shop.service.vo.OrderVo; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + + +@Service +@RequiredArgsConstructor(onConstructor = @__(@Autowired)) +public class OrderServiceImpl extends ServiceImpl implements IOrderService { + + private final StoreCartMapper storeCartMapper; + private final StoreSpecGoodsPriceMapper storeSpecGoodsPriceMapper; + private final StoreMemberAddressMapper storeMemberAddressMapper; + private final StoreCouponMapper storeCouponMapper; + private final StoreCouponListMapper storeCouponListMapper; + private final OrderGoodsServiceImpl orderGoodsService; + private final GoodsServiceImpl goodsService; + + /** + * 购物车提交 + * @param orderVo + * @param userId + * @return + */ + @Override + @Transactional + public String addOrderOfOne(OrderVo orderVo,int userId) { + if(StrUtil.isEmpty(orderVo.getGoodsIds())){ + throw new LightSecurityException("参数缺失"); + } + String[] goddsArr = orderVo.getGoodsIds().split(","); + QueryWrapper cartQueryWrapper = new QueryWrapper<>(); + cartQueryWrapper.eq("user_id",userId).in("goods_id", Arrays.asList(goddsArr)); + List storeCarts = storeCartMapper.selectList(cartQueryWrapper); + System.out.println("storeCarts:"+storeCarts); + if(storeCarts.isEmpty()){ + throw new LightSecurityException("购物车空空如也"); + } + + //计算商品总价 + Double totalGoodsPrice = 0d; + + for (StoreCart cart : storeCarts) { + int storeCount = checkStore(cart.getGoodsId(),cart.getSpecKey()); + if(storeCount < cart.getGoodsNum()){ + throw new LightSecurityException("库存不足"); + } + + // BigDecimal decimal = new BigDecimal(); + totalGoodsPrice += cart.getGoodsPrice().doubleValue()*cart.getGoodsNum(); + } + + //插入主表 + StoreOrder storeOrder = new StoreOrder(); + storeOrder.setOrderSn(OrderUtil.orderSn()); + storeOrder.setUserId(userId); + storeOrder.setReceiveType(2); + storeOrder.setGoodsPrice(BigDecimal.valueOf(totalGoodsPrice)); + storeOrder.setTotalAmount(BigDecimal.valueOf(totalGoodsPrice)); + //storeOrder.setAddTime(OrderUtil.getSecondTimestampTwo()); + + + //处理收货 + StoreMemberAddress address = storeMemberAddressMapper.selectById(orderVo.getAddressId()); + if(address == null){ + throw new LightSecurityException("地址不存在"); + } + storeOrder.setConsignee(address.getUsername()); + storeOrder.setCityInfo(address.getCityInfo()); + storeOrder.setAddress(address.getAddress()); + storeOrder.setMobile(address.getPhone()); + //处理优惠券 + if(StrUtil.isNotEmpty(orderVo.getCouponId())){ + CouponDTO couponInfo = storeCouponMapper + .findLog(Integer.valueOf(orderVo.getCouponId())); + storeOrder.setCouponPrice(BigDecimal.valueOf(couponInfo.getMoney())); + storeOrder.setOrderAmount(BigDecimal + .valueOf((totalGoodsPrice - couponInfo.getMoney()))); + updateCouponStatus(Integer.valueOf(orderVo.getCouponId())); + }else{ + storeOrder.setOrderAmount(BigDecimal.valueOf(totalGoodsPrice)); + } + + //插入主表 + if(baseMapper.insert(storeOrder) == 0) throw new LightSecurityException("操作失败");; + int orderId = storeOrder.getOrderId(); + + //副表 + List orderGoodsList = new ArrayList<>(); + for (StoreCart cart : storeCarts) { + StoreOrderGoods orderGoods = new StoreOrderGoods(); + orderGoods.setOrderId(orderId); + orderGoods.setGoodsId(cart.getGoodsId()); + orderGoods.setGoodsSn(cart.getGoodsSn()); + orderGoods.setGoodsName(cart.getGoodsName()); + orderGoods.setMarketPrice(cart.getMarketPrice()); + orderGoods.setGoodsPrice(cart.getGoodsPrice()); + orderGoods.setGoodsNum(cart.getGoodsNum()); + orderGoods.setSpecKey(cart.getSpecKey()); + orderGoods.setSpecKeyName(cart.getSpecKeyName()); + + orderGoodsList.add(orderGoods); + } + + if(!orderGoodsService.saveBatch(orderGoodsList)){ + throw new LightSecurityException("操作失败"); + } + + //清空购物车 + QueryWrapper cartWrapper = new QueryWrapper<>(); + cartWrapper.eq("user_id",userId).in("goods_id", Arrays.asList(goddsArr)); + storeCartMapper.delete(cartWrapper); + + + + return storeOrder.getOrderSn(); + } + + /** + * 直接提交订单 + * @param orderVo + * @param userId + * @return + */ + @Override + public String addOrderOfTwo(OrderVo orderVo, int userId) { + if(orderVo.getCartVO() == null){ + throw new LightSecurityException("参数缺失"); + } + + CartVO cartVO = orderVo.getCartVO(); + + StoreGoods storeGoods = goodsService.getById(cartVO.getGoodsId()); + if(storeGoods == null) throw new LightSecurityException("商品不存在"); + + //计算商品总价 + Double totalGoodsPrice = 0d; + + for (CartAttrVO attrVO : cartVO.getCartAttr()) { + int storeCount = checkStore(Integer.valueOf(cartVO.getGoodsId()),attrVO.getSpecKey()); + if(storeCount < attrVO.getGoodsNum()){ + throw new LightSecurityException("库存不足"); + } + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("goods_id",cartVO.getGoodsId()).eq("`key`",attrVO.getSpecKey()); + StoreSpecGoodsPrice storeSpecGoodsPrice = storeSpecGoodsPriceMapper + .selectOne(wrapper); + totalGoodsPrice += storeSpecGoodsPrice.getPrice().doubleValue()*attrVO.getGoodsNum(); + + } + + //插入主表 + StoreOrder storeOrder = new StoreOrder(); + storeOrder.setOrderSn(OrderUtil.orderSn()); + storeOrder.setUserId(userId); + storeOrder.setReceiveType(2); + storeOrder.setGoodsPrice(BigDecimal.valueOf(totalGoodsPrice)); + storeOrder.setTotalAmount(BigDecimal.valueOf(totalGoodsPrice)); + + + //处理收货 + StoreMemberAddress address = storeMemberAddressMapper.selectById(orderVo.getAddressId()); + if(address == null){ + throw new LightSecurityException("地址不存在"); + } + storeOrder.setConsignee(address.getUsername()); + storeOrder.setCityInfo(address.getCityInfo()); + storeOrder.setAddress(address.getAddress()); + storeOrder.setMobile(address.getPhone()); + + //处理优惠券 + if(StrUtil.isNotEmpty(orderVo.getCouponId())){ + CouponDTO couponInfo = storeCouponMapper + .findLog(Integer.valueOf(orderVo.getCouponId())); + storeOrder.setCouponPrice(BigDecimal.valueOf(couponInfo.getMoney())); + storeOrder.setOrderAmount(BigDecimal + .valueOf((totalGoodsPrice - couponInfo.getMoney()))); + updateCouponStatus(Integer.valueOf(orderVo.getCouponId())); + }else{ + storeOrder.setOrderAmount(BigDecimal.valueOf(totalGoodsPrice)); + } + + //插入主表 + if(baseMapper.insert(storeOrder) == 0) throw new LightSecurityException("操作失败");; + int orderId = storeOrder.getOrderId(); + + //处理副表 + List orderGoodsList = new ArrayList<>(); + for (CartAttrVO attrVO : cartVO.getCartAttr()) { + QueryWrapper wrap = new QueryWrapper<>(); + wrap.eq("goods_id",cartVO.getGoodsId()).eq("`key`",attrVO.getSpecKey()); + StoreSpecGoodsPrice specGoodsPrice = storeSpecGoodsPriceMapper + .selectOne(wrap); + StoreOrderGoods orderGoods = new StoreOrderGoods(); + orderGoods.setOrderId(orderId); + orderGoods.setGoodsId(storeGoods.getGoodsId()); + orderGoods.setGoodsSn(storeGoods.getGoodsSn()); + orderGoods.setGoodsName(storeGoods.getGoodsName()); + orderGoods.setMarketPrice(BigDecimal.valueOf(specGoodsPrice.getMarketPrice())); + orderGoods.setGoodsPrice(specGoodsPrice.getPrice()); + orderGoods.setGoodsNum(attrVO.getGoodsNum()); + orderGoods.setSpecKey(attrVO.getSpecKey()); + orderGoods.setSpecKeyName(specGoodsPrice.getKeyName()); + + orderGoodsList.add(orderGoods); + + } + + if(!orderGoodsService.saveBatch(orderGoodsList)){ + throw new LightSecurityException("操作失败"); + } + + return storeOrder.getOrderSn(); + } + + @Override + public int checkStore(int goodsId, String spec_key) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("`key`",spec_key) + .eq("goods_id", goodsId); + return storeSpecGoodsPriceMapper.selectOne(queryWrapper).getStoreCount(); + } + + @Override + public void updateCouponStatus(int id) { + StoreCouponList storeCouponList = new StoreCouponList(); + storeCouponList.setId(id); + storeCouponList.setUseTime(OrderUtil.getSecondTimestampTwo()); + storeCouponList.setStatus(1); + storeCouponListMapper.updateById(storeCouponList); + storeCouponMapper.incUserNum(id); + } +} diff --git a/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/vo/OrderVo.java b/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/vo/OrderVo.java new file mode 100644 index 0000000..76b715e --- /dev/null +++ b/ruoyi-api/src/main/java/com/ruoyi/app/modular/shop/service/vo/OrderVo.java @@ -0,0 +1,27 @@ +package com.ruoyi.app.modular.shop.service.vo; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * @ClassName OrderVo + * @Author hupeng <610796224@qq.com> + * @Date 2019/9/13 + **/ + +@Data +public class OrderVo { + + @NotNull + private String orderFrom; //订单来源1-购物车提交 2-直接提交 + + private String goodsIds; //order_from=1时候需要传购物车商品id字符串逗号隔开例如"5,6,7" + + private CartVO cartVO; //order_from=2直接提交 + + @NotNull + private String addressId; + + private String couponId; +} diff --git a/ruoyi-api/src/test/java/com/ruoyi/generator/EntityGenerator.java b/ruoyi-api/src/test/java/com/ruoyi/generator/EntityGenerator.java index cd0716b..1170ce1 100644 --- a/ruoyi-api/src/test/java/com/ruoyi/generator/EntityGenerator.java +++ b/ruoyi-api/src/test/java/com/ruoyi/generator/EntityGenerator.java @@ -58,7 +58,7 @@ public class EntityGenerator { StrategyConfig strategy = new StrategyConfig(); //strategy.setTablePrefix(new String[]{"_"});// 此处可以修改为您的表前缀 strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略 - strategy.setInclude(new String[]{"store_cart"}); + strategy.setInclude(new String[]{"store_coupon","store_coupon_list"}); mpg.setStrategy(strategy); // 包配置