提交订单完成,mall模块基本完成

This commit is contained in:
hupeng committed 2019-09-14 14:55:35 +08:00
1 parent 33a7758e72
commit f3d1c57f42
23 files changed
+1218 -88

No files matched your search

@@ -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;
/**
* <p>
* 优惠券记录表 Mapper 接口
* </p>
*
* @author hupeng
* @since 2019-09-13
*/
public interface StoreCouponListMapper extends BaseMapper<StoreCouponList> {
}
@@ -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;
/**
* <p>
* 优惠券主表 Mapper 接口
* </p>
*
* @author hupeng
* @since 2019-09-13
*/
public interface StoreCouponMapper extends BaseMapper<StoreCoupon> {
@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);
}
@@ -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;
/**
* <p>
* 商城会员收货地址 Mapper 接口
* </p>
*
* @author hupeng
* @since 2019-09-13
*/
public interface StoreMemberAddressMapper extends BaseMapper<StoreMemberAddress> {
}
@@ -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;
/**
* <p>
* 订单商品表与订单主表关联 Mapper 接口
* </p>
*
* @author hupeng
* @since 2019-09-13
*/
public interface StoreOrderGoodsMapper extends BaseMapper<StoreOrderGoods> {
}
@@ -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;
/**
* <p>
@@ -0,0 +1,19 @@
<?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.ruoyi.app.common.persistence.dao.StoreCouponListMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.ruoyi.app.common.persistence.model.StoreCouponList">
<id column="id" property="id" />
<result column="cid" property="cid" />
<result column="type" property="type" />
<result column="uid" property="uid" />
<result column="order_id" property="orderId" />
<result column="get_order_id" property="getOrderId" />
<result column="use_time" property="useTime" />
<result column="code" property="code" />
<result column="send_time" property="sendTime" />
<result column="status" property="status" />
</resultMap>
</mapper>
@@ -0,0 +1,24 @@
<?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.ruoyi.app.common.persistence.dao.StoreCouponMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.ruoyi.app.common.persistence.model.StoreCoupon">
<id column="id" property="id" />
<result column="name" property="name" />
<result column="type" property="type" />
<result column="money" property="money" />
<result column="condition" property="condition" />
<result column="createnum" property="createnum" />
<result column="send_num" property="sendNum" />
<result column="use_num" property="useNum" />
<result column="send_start_time" property="sendStartTime" />
<result column="send_end_time" property="sendEndTime" />
<result column="use_start_time" property="useStartTime" />
<result column="use_end_time" property="useEndTime" />
<result column="add_time" property="addTime" />
<result column="status" property="status" />
<result column="use_type" property="useType" />
</resultMap>
</mapper>
@@ -0,0 +1,22 @@
<?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.ruoyi.app.common.persistence.dao.StoreMemberAddressMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.ruoyi.app.common.persistence.model.StoreMemberAddress">
<id column="id" property="id" />
<result column="mid" property="mid" />
<result column="username" property="username" />
<result column="phone" property="phone" />
<result column="province" property="province" />
<result column="city" property="city" />
<result column="area" property="area" />
<result column="city_info" property="cityInfo" />
<result column="address" property="address" />
<result column="status" property="status" />
<result column="is_default" property="isDefault" />
<result column="is_deleted" property="isDeleted" />
<result column="create_at" property="createAt" />
</resultMap>
</mapper>
@@ -21,12 +21,9 @@
<result column="is_comment" property="isComment" />
<result column="prom_type" property="promType" />
<result column="prom_id" property="promId" />
<result column="pay_status" property="payStatus" />
<result column="is_send" property="isSend" />
<result column="delivery_id" property="deliveryId" />
<result column="sku" property="sku" />
<result column="start_time" property="startTime" />
<result column="end_time" property="endTime" />
</resultMap>
</mapper>
@@ -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;
/**
* <p>
* 优惠券主表
* </p>
*
* @author hupeng
* @since 2019-09-13
*/
@TableName("store_coupon")
public class StoreCoupon extends Model<StoreCoupon> {
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 +
"}";
}
}
@@ -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;
/**
* <p>
* 优惠券记录表
* </p>
*
* @author hupeng
* @since 2019-09-13
*/
@TableName("store_coupon_list")
public class StoreCouponList extends Model<StoreCouponList> {
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 +
"}";
}
}
@@ -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;
/**
* <p>
* 商城会员收货地址
* </p>
*
* @author hupeng
* @since 2019-09-13
*/
@TableName("store_member_address")
public class StoreMemberAddress extends Model<StoreMemberAddress> {
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 +
"}";
}
}
@@ -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;
/**
* <p>
@@ -194,8 +193,8 @@ public class StoreOrder extends Model<StoreOrder> {
/**
* 下单时间
*/
@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<StoreOrder> {
this.totalAmount = totalAmount;
}
public Integer getAddTime() {
public Date getAddTime() {
return addTime;
}
public void setAddTime(Integer addTime) {
public void setAddTime(Date addTime) {
this.addTime = addTime;
}
@@ -2,8 +2,10 @@ 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.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.io.Serializable;
/**
@@ -12,8 +14,9 @@ import java.io.Serializable;
* </p>
*
* @author hupeng
* @since 2019-06-26
* @since 2019-09-13
*/
@TableName("store_order_goods")
public class StoreOrderGoods extends Model<StoreOrderGoods> {
private static final long serialVersionUID = 1L;
@@ -23,117 +26,101 @@ public class StoreOrderGoods extends Model<StoreOrderGoods> {
*/
@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;
/**
* 是否评价
*/
private Boolean isComment;
@TableField("is_comment")
private Integer isComment;
/**
* 0 普通订单,1 限时抢购, 2 团购 , 3 促销优惠,4预售
*/
private Boolean promType;
@TableField("prom_type")
private Integer promType;
/**
* 活动id
*/
@TableField("prom_id")
private Integer promId;
/**
* 0未支付1已支付
*/
private Boolean payStatus;
/**
* 0未发货,1已发货,2已换货,3已退货
*/
private Boolean isSend;
@TableField("is_send")
private Integer isSend;
/**
* 发货单ID
*/
@TableField("delivery_id")
private Integer deliveryId;
/**
* sku
*/
private String sku;
/**
* 订单开始时间
*/
private Integer startTime;
/**
* 订单结束时间
*/
private Integer endTime;
public Integer getRecId() {
return recId;
@@ -247,19 +234,19 @@ public class StoreOrderGoods extends Model<StoreOrderGoods> {
this.barCode = barCode;
}
public Boolean getComment() {
public Integer getIsComment() {
return isComment;
}
public void setComment(Boolean isComment) {
public void setIsComment(Integer isComment) {
this.isComment = isComment;
}
public Boolean getPromType() {
public Integer getPromType() {
return promType;
}
public void setPromType(Boolean promType) {
public void setPromType(Integer promType) {
this.promType = promType;
}
@@ -271,19 +258,11 @@ public class StoreOrderGoods extends Model<StoreOrderGoods> {
this.promId = promId;
}
public Boolean getPayStatus() {
return payStatus;
}
public void setPayStatus(Boolean payStatus) {
this.payStatus = payStatus;
}
public Boolean getSend() {
public Integer getIsSend() {
return isSend;
}
public void setSend(Boolean isSend) {
public void setIsSend(Integer isSend) {
this.isSend = isSend;
}
@@ -303,22 +282,6 @@ public class StoreOrderGoods extends Model<StoreOrderGoods> {
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;
@@ -327,7 +290,7 @@ public class StoreOrderGoods extends Model<StoreOrderGoods> {
@Override
public String toString() {
return "StoreOrderGoods{" +
"recId=" + recId +
", recId=" + recId +
", orderId=" + orderId +
", goodsId=" + goodsId +
", goodsName=" + goodsName +
@@ -344,12 +307,9 @@ public class StoreOrderGoods extends Model<StoreOrderGoods> {
", isComment=" + isComment +
", promType=" + promType +
", promId=" + promId +
", payStatus=" + payStatus +
", isSend=" + isSend +
", deliveryId=" + deliveryId +
", sku=" + sku +
", startTime=" + startTime +
", endTime=" + endTime +
"}";
}
}
@@ -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);
}
}
@@ -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<String,String> map = new HashMap<>();
map.put("orderSn",orderSn);
return R.success(map);
}
}
@@ -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<StoreOrderGoods> {
}
@@ -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<StoreOrder> {
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);
}
@@ -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;
}
@@ -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<StoreOrderGoodsMapper, StoreOrderGoods> implements IOrderGoodsService {
}
@@ -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<StoreOrderMapper, StoreOrder> 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<StoreCart> cartQueryWrapper = new QueryWrapper<>();
cartQueryWrapper.eq("user_id",userId).in("goods_id", Arrays.asList(goddsArr));
List<StoreCart> 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<StoreOrderGoods> 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<StoreCart> 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<StoreSpecGoodsPrice> 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<StoreOrderGoods> orderGoodsList = new ArrayList<>();
for (CartAttrVO attrVO : cartVO.getCartAttr()) {
QueryWrapper<StoreSpecGoodsPrice> 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<StoreSpecGoodsPrice> 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);
}
}
@@ -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;
}
@@ -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);
// 包配置