feat[litemall-db, litemall-wx-api]: 小商城后端支持优惠券

This commit is contained in:
Junling Bu
2018-12-10 19:07:37 +08:00
parent d5abf50cde
commit 80ffb92f7a
23 changed files with 8090 additions and 15 deletions

View File

@@ -158,5 +158,11 @@
<table tableName="litemall_groupon">
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table>
<table tableName="litemall_coupon">
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table>
<table tableName="litemall_coupon_user">
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table>
</context>
</generatorConfiguration>

View File

@@ -0,0 +1,159 @@
package org.linlinjava.litemall.db.dao;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.linlinjava.litemall.db.domain.LitemallCoupon;
import org.linlinjava.litemall.db.domain.LitemallCouponExample;
public interface LitemallCouponMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
*/
long countByExample(LitemallCouponExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
*/
int deleteByExample(LitemallCouponExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
*/
int insert(LitemallCoupon record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
*/
int insertSelective(LitemallCoupon record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
LitemallCoupon selectOneByExample(LitemallCouponExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
LitemallCoupon selectOneByExampleSelective(@Param("example") LitemallCouponExample example, @Param("selective") LitemallCoupon.Column ... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
List<LitemallCoupon> selectByExampleSelective(@Param("example") LitemallCouponExample example, @Param("selective") LitemallCoupon.Column ... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
*/
List<LitemallCoupon> selectByExample(LitemallCouponExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
LitemallCoupon selectByPrimaryKeySelective(@Param("id") Integer id, @Param("selective") LitemallCoupon.Column ... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
*/
LitemallCoupon selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
LitemallCoupon selectByPrimaryKeyWithLogicalDelete(@Param("id") Integer id, @Param("andLogicalDeleted") boolean andLogicalDeleted);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") LitemallCoupon record, @Param("example") LitemallCouponExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
*/
int updateByExample(@Param("record") LitemallCoupon record, @Param("example") LitemallCouponExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(LitemallCoupon record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
*/
int updateByPrimaryKey(LitemallCoupon record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int logicalDeleteByExample(@Param("example") LitemallCouponExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int logicalDeleteByPrimaryKey(Integer id);
}

View File

@@ -0,0 +1,159 @@
package org.linlinjava.litemall.db.dao;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.linlinjava.litemall.db.domain.LitemallCouponUser;
import org.linlinjava.litemall.db.domain.LitemallCouponUserExample;
public interface LitemallCouponUserMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
*/
long countByExample(LitemallCouponUserExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
*/
int deleteByExample(LitemallCouponUserExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
*/
int insert(LitemallCouponUser record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
*/
int insertSelective(LitemallCouponUser record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
LitemallCouponUser selectOneByExample(LitemallCouponUserExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
LitemallCouponUser selectOneByExampleSelective(@Param("example") LitemallCouponUserExample example, @Param("selective") LitemallCouponUser.Column ... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
List<LitemallCouponUser> selectByExampleSelective(@Param("example") LitemallCouponUserExample example, @Param("selective") LitemallCouponUser.Column ... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
*/
List<LitemallCouponUser> selectByExample(LitemallCouponUserExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
LitemallCouponUser selectByPrimaryKeySelective(@Param("id") Integer id, @Param("selective") LitemallCouponUser.Column ... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
*/
LitemallCouponUser selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
LitemallCouponUser selectByPrimaryKeyWithLogicalDelete(@Param("id") Integer id, @Param("andLogicalDeleted") boolean andLogicalDeleted);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") LitemallCouponUser record, @Param("example") LitemallCouponUserExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
*/
int updateByExample(@Param("record") LitemallCouponUser record, @Param("example") LitemallCouponUserExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(LitemallCouponUser record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
*/
int updateByPrimaryKey(LitemallCouponUser record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int logicalDeleteByExample(@Param("example") LitemallCouponUserExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int logicalDeleteByPrimaryKey(Integer id);
}

View File

@@ -0,0 +1,926 @@
package org.linlinjava.litemall.db.domain;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
public class LitemallCoupon {
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public static final Boolean NOT_DELETED = false;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public static final Boolean IS_DELETED = true;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.id
*
* @mbg.generated
*/
private Integer id;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.name
*
* @mbg.generated
*/
private String name;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.desc
*
* @mbg.generated
*/
private String desc;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.tag
*
* @mbg.generated
*/
private String tag;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.total
*
* @mbg.generated
*/
private Integer total;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.discount
*
* @mbg.generated
*/
private BigDecimal discount;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.min
*
* @mbg.generated
*/
private BigDecimal min;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.limit
*
* @mbg.generated
*/
private Short limit;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.type
*
* @mbg.generated
*/
private Short type;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.status
*
* @mbg.generated
*/
private Short status;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.goods_type
*
* @mbg.generated
*/
private Short goodsType;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.goods_value
*
* @mbg.generated
*/
private String goodsValue;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.days
*
* @mbg.generated
*/
private Short days;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.start_time
*
* @mbg.generated
*/
private LocalDateTime startTime;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.end_time
*
* @mbg.generated
*/
private LocalDateTime endTime;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.add_time
*
* @mbg.generated
*/
private LocalDateTime addTime;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.update_time
*
* @mbg.generated
*/
private LocalDateTime updateTime;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon.deleted
*
* @mbg.generated
*/
private Boolean deleted;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.id
*
* @return the value of litemall_coupon.id
*
* @mbg.generated
*/
public Integer getId() {
return id;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.id
*
* @param id the value for litemall_coupon.id
*
* @mbg.generated
*/
public void setId(Integer id) {
this.id = id;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.name
*
* @return the value of litemall_coupon.name
*
* @mbg.generated
*/
public String getName() {
return name;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.name
*
* @param name the value for litemall_coupon.name
*
* @mbg.generated
*/
public void setName(String name) {
this.name = name;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.desc
*
* @return the value of litemall_coupon.desc
*
* @mbg.generated
*/
public String getDesc() {
return desc;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.desc
*
* @param desc the value for litemall_coupon.desc
*
* @mbg.generated
*/
public void setDesc(String desc) {
this.desc = desc;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.tag
*
* @return the value of litemall_coupon.tag
*
* @mbg.generated
*/
public String getTag() {
return tag;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.tag
*
* @param tag the value for litemall_coupon.tag
*
* @mbg.generated
*/
public void setTag(String tag) {
this.tag = tag;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.total
*
* @return the value of litemall_coupon.total
*
* @mbg.generated
*/
public Integer getTotal() {
return total;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.total
*
* @param total the value for litemall_coupon.total
*
* @mbg.generated
*/
public void setTotal(Integer total) {
this.total = total;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.discount
*
* @return the value of litemall_coupon.discount
*
* @mbg.generated
*/
public BigDecimal getDiscount() {
return discount;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.discount
*
* @param discount the value for litemall_coupon.discount
*
* @mbg.generated
*/
public void setDiscount(BigDecimal discount) {
this.discount = discount;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.min
*
* @return the value of litemall_coupon.min
*
* @mbg.generated
*/
public BigDecimal getMin() {
return min;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.min
*
* @param min the value for litemall_coupon.min
*
* @mbg.generated
*/
public void setMin(BigDecimal min) {
this.min = min;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.limit
*
* @return the value of litemall_coupon.limit
*
* @mbg.generated
*/
public Short getLimit() {
return limit;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.limit
*
* @param limit the value for litemall_coupon.limit
*
* @mbg.generated
*/
public void setLimit(Short limit) {
this.limit = limit;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.type
*
* @return the value of litemall_coupon.type
*
* @mbg.generated
*/
public Short getType() {
return type;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.type
*
* @param type the value for litemall_coupon.type
*
* @mbg.generated
*/
public void setType(Short type) {
this.type = type;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.status
*
* @return the value of litemall_coupon.status
*
* @mbg.generated
*/
public Short getStatus() {
return status;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.status
*
* @param status the value for litemall_coupon.status
*
* @mbg.generated
*/
public void setStatus(Short status) {
this.status = status;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.goods_type
*
* @return the value of litemall_coupon.goods_type
*
* @mbg.generated
*/
public Short getGoodsType() {
return goodsType;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.goods_type
*
* @param goodsType the value for litemall_coupon.goods_type
*
* @mbg.generated
*/
public void setGoodsType(Short goodsType) {
this.goodsType = goodsType;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.goods_value
*
* @return the value of litemall_coupon.goods_value
*
* @mbg.generated
*/
public String getGoodsValue() {
return goodsValue;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.goods_value
*
* @param goodsValue the value for litemall_coupon.goods_value
*
* @mbg.generated
*/
public void setGoodsValue(String goodsValue) {
this.goodsValue = goodsValue;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.days
*
* @return the value of litemall_coupon.days
*
* @mbg.generated
*/
public Short getDays() {
return days;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.days
*
* @param days the value for litemall_coupon.days
*
* @mbg.generated
*/
public void setDays(Short days) {
this.days = days;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.start_time
*
* @return the value of litemall_coupon.start_time
*
* @mbg.generated
*/
public LocalDateTime getStartTime() {
return startTime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.start_time
*
* @param startTime the value for litemall_coupon.start_time
*
* @mbg.generated
*/
public void setStartTime(LocalDateTime startTime) {
this.startTime = startTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.end_time
*
* @return the value of litemall_coupon.end_time
*
* @mbg.generated
*/
public LocalDateTime getEndTime() {
return endTime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.end_time
*
* @param endTime the value for litemall_coupon.end_time
*
* @mbg.generated
*/
public void setEndTime(LocalDateTime endTime) {
this.endTime = endTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.add_time
*
* @return the value of litemall_coupon.add_time
*
* @mbg.generated
*/
public LocalDateTime getAddTime() {
return addTime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.add_time
*
* @param addTime the value for litemall_coupon.add_time
*
* @mbg.generated
*/
public void setAddTime(LocalDateTime addTime) {
this.addTime = addTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.update_time
*
* @return the value of litemall_coupon.update_time
*
* @mbg.generated
*/
public LocalDateTime getUpdateTime() {
return updateTime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.update_time
*
* @param updateTime the value for litemall_coupon.update_time
*
* @mbg.generated
*/
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon.deleted
*
* @return the value of litemall_coupon.deleted
*
* @mbg.generated
*/
public Boolean getDeleted() {
return deleted;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon.deleted
*
* @param deleted the value for litemall_coupon.deleted
*
* @mbg.generated
*/
public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", name=").append(name);
sb.append(", desc=").append(desc);
sb.append(", tag=").append(tag);
sb.append(", total=").append(total);
sb.append(", discount=").append(discount);
sb.append(", min=").append(min);
sb.append(", limit=").append(limit);
sb.append(", type=").append(type);
sb.append(", status=").append(status);
sb.append(", goodsType=").append(goodsType);
sb.append(", goodsValue=").append(goodsValue);
sb.append(", days=").append(days);
sb.append(", startTime=").append(startTime);
sb.append(", endTime=").append(endTime);
sb.append(", addTime=").append(addTime);
sb.append(", updateTime=").append(updateTime);
sb.append(", deleted=").append(deleted);
sb.append("]");
return sb.toString();
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
*/
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
LitemallCoupon other = (LitemallCoupon) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
&& (this.getDesc() == null ? other.getDesc() == null : this.getDesc().equals(other.getDesc()))
&& (this.getTag() == null ? other.getTag() == null : this.getTag().equals(other.getTag()))
&& (this.getTotal() == null ? other.getTotal() == null : this.getTotal().equals(other.getTotal()))
&& (this.getDiscount() == null ? other.getDiscount() == null : this.getDiscount().equals(other.getDiscount()))
&& (this.getMin() == null ? other.getMin() == null : this.getMin().equals(other.getMin()))
&& (this.getLimit() == null ? other.getLimit() == null : this.getLimit().equals(other.getLimit()))
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getGoodsType() == null ? other.getGoodsType() == null : this.getGoodsType().equals(other.getGoodsType()))
&& (this.getGoodsValue() == null ? other.getGoodsValue() == null : this.getGoodsValue().equals(other.getGoodsValue()))
&& (this.getDays() == null ? other.getDays() == null : this.getDays().equals(other.getDays()))
&& (this.getStartTime() == null ? other.getStartTime() == null : this.getStartTime().equals(other.getStartTime()))
&& (this.getEndTime() == null ? other.getEndTime() == null : this.getEndTime().equals(other.getEndTime()))
&& (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
&& (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()));
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getDesc() == null) ? 0 : getDesc().hashCode());
result = prime * result + ((getTag() == null) ? 0 : getTag().hashCode());
result = prime * result + ((getTotal() == null) ? 0 : getTotal().hashCode());
result = prime * result + ((getDiscount() == null) ? 0 : getDiscount().hashCode());
result = prime * result + ((getMin() == null) ? 0 : getMin().hashCode());
result = prime * result + ((getLimit() == null) ? 0 : getLimit().hashCode());
result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getGoodsType() == null) ? 0 : getGoodsType().hashCode());
result = prime * result + ((getGoodsValue() == null) ? 0 : getGoodsValue().hashCode());
result = prime * result + ((getDays() == null) ? 0 : getDays().hashCode());
result = prime * result + ((getStartTime() == null) ? 0 : getStartTime().hashCode());
result = prime * result + ((getEndTime() == null) ? 0 : getEndTime().hashCode());
result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
return result;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public void andLogicalDeleted(boolean deleted) {
setDeleted(deleted ? IS_DELETED : NOT_DELETED);
}
/**
* This enum was generated by MyBatis Generator.
* This enum corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public enum Column {
id("id", "id", "INTEGER", false),
name("name", "name", "VARCHAR", true),
desc("desc", "desc", "VARCHAR", true),
tag("tag", "tag", "VARCHAR", false),
total("total", "total", "INTEGER", false),
discount("discount", "discount", "DECIMAL", false),
min("min", "min", "DECIMAL", true),
limit("limit", "limit", "SMALLINT", true),
type("type", "type", "SMALLINT", true),
status("status", "status", "SMALLINT", true),
goodsType("goods_type", "goodsType", "SMALLINT", false),
goodsValue("goods_value", "goodsValue", "VARCHAR", false),
days("days", "days", "SMALLINT", true),
startTime("start_time", "startTime", "TIMESTAMP", false),
endTime("end_time", "endTime", "TIMESTAMP", false),
addTime("add_time", "addTime", "TIMESTAMP", false),
updateTime("update_time", "updateTime", "TIMESTAMP", false),
deleted("deleted", "deleted", "BIT", false);
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private static final String BEGINNING_DELIMITER = "`";
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private static final String ENDING_DELIMITER = "`";
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String column;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final boolean isColumnNameDelimited;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String javaProperty;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String jdbcType;
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String value() {
return this.column;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getValue() {
return this.column;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getJavaProperty() {
return this.javaProperty;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getJdbcType() {
return this.jdbcType;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
this.column = column;
this.javaProperty = javaProperty;
this.jdbcType = jdbcType;
this.isColumnNameDelimited = isColumnNameDelimited;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String desc() {
return this.getEscapedColumnName() + " DESC";
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String asc() {
return this.getEscapedColumnName() + " ASC";
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public static Column[] excludes(Column ... excludes) {
ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
if (excludes != null && excludes.length > 0) {
columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
}
return columns.toArray(new Column[]{});
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getEscapedColumnName() {
if (this.isColumnNameDelimited) {
return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
} else {
return this.column;
}
}
}
}

View File

@@ -0,0 +1,592 @@
package org.linlinjava.litemall.db.domain;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
public class LitemallCouponUser {
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public static final Boolean NOT_DELETED = false;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public static final Boolean IS_DELETED = true;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon_user.id
*
* @mbg.generated
*/
private Integer id;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon_user.user_id
*
* @mbg.generated
*/
private Integer userId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon_user.coupon_id
*
* @mbg.generated
*/
private Integer couponId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon_user.status
*
* @mbg.generated
*/
private Short status;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon_user.used_time
*
* @mbg.generated
*/
private LocalDateTime usedTime;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon_user.order_id
*
* @mbg.generated
*/
private Integer orderId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon_user.add_time
*
* @mbg.generated
*/
private LocalDateTime addTime;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon_user.update_time
*
* @mbg.generated
*/
private LocalDateTime updateTime;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_coupon_user.deleted
*
* @mbg.generated
*/
private Boolean deleted;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon_user.id
*
* @return the value of litemall_coupon_user.id
*
* @mbg.generated
*/
public Integer getId() {
return id;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon_user.id
*
* @param id the value for litemall_coupon_user.id
*
* @mbg.generated
*/
public void setId(Integer id) {
this.id = id;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon_user.user_id
*
* @return the value of litemall_coupon_user.user_id
*
* @mbg.generated
*/
public Integer getUserId() {
return userId;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon_user.user_id
*
* @param userId the value for litemall_coupon_user.user_id
*
* @mbg.generated
*/
public void setUserId(Integer userId) {
this.userId = userId;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon_user.coupon_id
*
* @return the value of litemall_coupon_user.coupon_id
*
* @mbg.generated
*/
public Integer getCouponId() {
return couponId;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon_user.coupon_id
*
* @param couponId the value for litemall_coupon_user.coupon_id
*
* @mbg.generated
*/
public void setCouponId(Integer couponId) {
this.couponId = couponId;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon_user.status
*
* @return the value of litemall_coupon_user.status
*
* @mbg.generated
*/
public Short getStatus() {
return status;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon_user.status
*
* @param status the value for litemall_coupon_user.status
*
* @mbg.generated
*/
public void setStatus(Short status) {
this.status = status;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon_user.used_time
*
* @return the value of litemall_coupon_user.used_time
*
* @mbg.generated
*/
public LocalDateTime getUsedTime() {
return usedTime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon_user.used_time
*
* @param usedTime the value for litemall_coupon_user.used_time
*
* @mbg.generated
*/
public void setUsedTime(LocalDateTime usedTime) {
this.usedTime = usedTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon_user.order_id
*
* @return the value of litemall_coupon_user.order_id
*
* @mbg.generated
*/
public Integer getOrderId() {
return orderId;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon_user.order_id
*
* @param orderId the value for litemall_coupon_user.order_id
*
* @mbg.generated
*/
public void setOrderId(Integer orderId) {
this.orderId = orderId;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon_user.add_time
*
* @return the value of litemall_coupon_user.add_time
*
* @mbg.generated
*/
public LocalDateTime getAddTime() {
return addTime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon_user.add_time
*
* @param addTime the value for litemall_coupon_user.add_time
*
* @mbg.generated
*/
public void setAddTime(LocalDateTime addTime) {
this.addTime = addTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon_user.update_time
*
* @return the value of litemall_coupon_user.update_time
*
* @mbg.generated
*/
public LocalDateTime getUpdateTime() {
return updateTime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon_user.update_time
*
* @param updateTime the value for litemall_coupon_user.update_time
*
* @mbg.generated
*/
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_coupon_user.deleted
*
* @return the value of litemall_coupon_user.deleted
*
* @mbg.generated
*/
public Boolean getDeleted() {
return deleted;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_coupon_user.deleted
*
* @param deleted the value for litemall_coupon_user.deleted
*
* @mbg.generated
*/
public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", userId=").append(userId);
sb.append(", couponId=").append(couponId);
sb.append(", status=").append(status);
sb.append(", usedTime=").append(usedTime);
sb.append(", orderId=").append(orderId);
sb.append(", addTime=").append(addTime);
sb.append(", updateTime=").append(updateTime);
sb.append(", deleted=").append(deleted);
sb.append("]");
return sb.toString();
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
*/
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
LitemallCouponUser other = (LitemallCouponUser) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
&& (this.getCouponId() == null ? other.getCouponId() == null : this.getCouponId().equals(other.getCouponId()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getUsedTime() == null ? other.getUsedTime() == null : this.getUsedTime().equals(other.getUsedTime()))
&& (this.getOrderId() == null ? other.getOrderId() == null : this.getOrderId().equals(other.getOrderId()))
&& (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
&& (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()));
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
result = prime * result + ((getCouponId() == null) ? 0 : getCouponId().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getUsedTime() == null) ? 0 : getUsedTime().hashCode());
result = prime * result + ((getOrderId() == null) ? 0 : getOrderId().hashCode());
result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
return result;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public void andLogicalDeleted(boolean deleted) {
setDeleted(deleted ? IS_DELETED : NOT_DELETED);
}
/**
* This enum was generated by MyBatis Generator.
* This enum corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public enum Column {
id("id", "id", "INTEGER", false),
userId("user_id", "userId", "INTEGER", false),
couponId("coupon_id", "couponId", "INTEGER", false),
status("status", "status", "SMALLINT", true),
usedTime("used_time", "usedTime", "TIMESTAMP", false),
orderId("order_id", "orderId", "INTEGER", false),
addTime("add_time", "addTime", "TIMESTAMP", false),
updateTime("update_time", "updateTime", "TIMESTAMP", false),
deleted("deleted", "deleted", "BIT", false);
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private static final String BEGINNING_DELIMITER = "`";
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private static final String ENDING_DELIMITER = "`";
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String column;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final boolean isColumnNameDelimited;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String javaProperty;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String jdbcType;
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String value() {
return this.column;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getValue() {
return this.column;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getJavaProperty() {
return this.javaProperty;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getJdbcType() {
return this.jdbcType;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
this.column = column;
this.javaProperty = javaProperty;
this.jdbcType = jdbcType;
this.isColumnNameDelimited = isColumnNameDelimited;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String desc() {
return this.getEscapedColumnName() + " DESC";
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String asc() {
return this.getEscapedColumnName() + " ASC";
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public static Column[] excludes(Column ... excludes) {
ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
if (excludes != null && excludes.length > 0) {
columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
}
return columns.toArray(new Column[]{});
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_coupon_user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getEscapedColumnName() {
if (this.isColumnNameDelimited) {
return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
} else {
return this.column;
}
}
}
}

View File

@@ -0,0 +1,50 @@
package org.linlinjava.litemall.db.service;
import org.linlinjava.litemall.db.domain.LitemallCoupon;
import org.linlinjava.litemall.db.domain.LitemallCouponUser;
import org.linlinjava.litemall.db.util.CouponConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
@Service
public class CouponAssignService {
@Autowired
private LitemallCouponUserService couponUserService;
@Autowired
private LitemallCouponService couponService;
/**
* 分发注册优惠券
*
* @param userId
* @return
*/
public void assignForRegister(Integer userId) {
List<LitemallCoupon> couponList = couponService.queryRegister();
for(LitemallCoupon coupon : couponList){
Integer couponId = coupon.getId();
Integer count = couponUserService.countUserAndCoupon(userId, couponId);
if (count > 0) {
continue;
}
Short limit = coupon.getLimit();
while(limit > 0){
LitemallCouponUser couponUser = new LitemallCouponUser();
couponUser.setCouponId(couponId);
couponUser.setUserId(userId);
couponUserService.add(couponUser);
limit--;
}
}
}
}

View File

@@ -0,0 +1,68 @@
package org.linlinjava.litemall.db.service;
import org.linlinjava.litemall.db.domain.LitemallCoupon;
import org.linlinjava.litemall.db.domain.LitemallCouponUser;
import org.linlinjava.litemall.db.util.CouponConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Service
public class CouponVerifyService {
@Autowired
private LitemallCouponUserService couponUserService;
@Autowired
private LitemallCouponService couponService;
/**
* 检测优惠券是否适合
*
* @param userId
* @param couponId
* @param checkedGoodsPrice
* @return
*/
public LitemallCoupon checkCoupon(Integer userId, Integer couponId, BigDecimal checkedGoodsPrice) {
LitemallCoupon coupon = couponService.findById(couponId);
LitemallCouponUser couponUser = couponUserService.queryOne(userId, couponId);
if (coupon == null || couponUser == null) {
return null;
}
// 检查是否超期
Short days = coupon.getDays();
LocalDateTime now = LocalDateTime.now();
if (days == 0) {
if (now.isBefore(coupon.getStartTime()) || now.isAfter(coupon.getEndTime())) {
return null;
}
} else {
LocalDateTime expired = couponUser.getAddTime().plusDays(days);
if (now.isAfter(expired)) {
return null;
}
}
// 检测商品是否符合
// TODO 目前仅支持全平台商品,所以不需要检测
Short goodType = coupon.getGoodsType();
if (!goodType.equals(CouponConstant.GOODS_TYPE_ALL)) {
return null;
}
// 检测订单状态
Short status = coupon.getStatus();
if (!status.equals(CouponConstant.STATUS_NORMAL)) {
return null;
}
// 检测是否满足最低消费
if (checkedGoodsPrice.compareTo(coupon.getMin()) == -1) {
return null;
}
return coupon;
}
}

View File

@@ -75,5 +75,4 @@ public class LitemallAdminService {
public LitemallAdmin findById(Integer id) {
return adminMapper.selectByPrimaryKeySelective(id, result);
}
}

View File

@@ -0,0 +1,65 @@
package org.linlinjava.litemall.db.service;
import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallCouponMapper;
import org.linlinjava.litemall.db.domain.LitemallCoupon;
import org.linlinjava.litemall.db.domain.LitemallCoupon.Column;
import org.linlinjava.litemall.db.domain.LitemallCouponExample;
import org.linlinjava.litemall.db.domain.LitemallCouponUser;
import org.linlinjava.litemall.db.util.CouponConstant;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class LitemallCouponService {
@Resource
private LitemallCouponMapper couponMapper;
private Column[] result = new Column[]{Column.id, Column.name, Column.desc, Column.tag,
Column.days, Column.startTime, Column.endTime,
Column.discount, Column.min};
/**
* 查询
*
* @param offset
* @param limit
* @param sort
* @param order
* @return
*/
public List<LitemallCoupon> queryList(int offset, int limit, String sort, String order) {
LitemallCouponExample example = new LitemallCouponExample();
example.or().andTypeEqualTo(CouponConstant.TYPE_COMMON).andStatusEqualTo(CouponConstant.STATUS_NORMAL).andDeletedEqualTo(false);
example.setOrderByClause(sort + " " + order);
PageHelper.startPage(offset, limit);
return couponMapper.selectByExampleSelective(example, result);
}
public int queryTotal() {
LitemallCouponExample example = new LitemallCouponExample();
example.or().andTypeEqualTo(CouponConstant.TYPE_COMMON).andStatusEqualTo(CouponConstant.STATUS_NORMAL).andDeletedEqualTo(false);
return (int) couponMapper.countByExample(example);
}
public List<LitemallCoupon> queryList(int offset, int limit) {
return queryList(offset, limit, "add_time", "desc");
}
public LitemallCoupon findById(Integer id) {
return couponMapper.selectByPrimaryKey(id);
}
/**
* 查询新用户注册优惠券
*
* @return
*/
public List<LitemallCoupon> queryRegister() {
LitemallCouponExample example = new LitemallCouponExample();
example.or().andTypeEqualTo(CouponConstant.TYPE_REGISTER).andStatusEqualTo(CouponConstant.STATUS_NORMAL).andDeletedEqualTo(false);
return couponMapper.selectByExample(example);
}
}

View File

@@ -0,0 +1,88 @@
package org.linlinjava.litemall.db.service;
import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallCouponUserMapper;
import org.linlinjava.litemall.db.domain.LitemallCouponUser;
import org.linlinjava.litemall.db.domain.LitemallCouponUserExample;
import org.linlinjava.litemall.db.util.CouponUserConstant;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
@Service
public class LitemallCouponUserService {
@Resource
private LitemallCouponUserMapper couponUserMapper;
public Integer countCoupon(Integer couponId) {
LitemallCouponUserExample example = new LitemallCouponUserExample();
example.or().andCouponIdEqualTo(couponId).andDeletedEqualTo(false);
return (int)couponUserMapper.countByExample(example);
}
public Integer countUserAndCoupon(Integer userId, Integer couponId) {
LitemallCouponUserExample example = new LitemallCouponUserExample();
example.or().andUserIdEqualTo(userId).andCouponIdEqualTo(couponId).andDeletedEqualTo(false);
return (int)couponUserMapper.countByExample(example);
}
public void add(LitemallCouponUser couponUser) {
couponUser.setAddTime(LocalDateTime.now());
couponUser.setUpdateTime(LocalDateTime.now());
couponUserMapper.insertSelective(couponUser);
}
public List<LitemallCouponUser> queryList(Integer userId, Integer couponId, Short status, Integer page, Integer size, String sort, String order) {
LitemallCouponUserExample example = new LitemallCouponUserExample();
LitemallCouponUserExample.Criteria criteria = example.createCriteria();
if (userId != null) {
criteria.andUserIdEqualTo(userId);
}
if(couponId != null){
criteria.andCouponIdEqualTo(couponId);
}
if (status != null) {
criteria.andStatusEqualTo(status);
}
criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
if (!StringUtils.isEmpty(page) && !StringUtils.isEmpty(size)) {
PageHelper.startPage(page, size);
}
return couponUserMapper.selectByExample(example);
}
public List<LitemallCouponUser> queryAll(Integer userId, Integer couponId) {
return queryList(userId, couponId, CouponUserConstant.STATUS_USABLE, null, null, "add_time", "desc");
}
public List<LitemallCouponUser> queryAll(Integer userId) {
return queryList(userId, null, CouponUserConstant.STATUS_USABLE, null, null, "add_time", "desc");
}
public LitemallCouponUser queryOne(Integer userId, Integer couponId) {
List<LitemallCouponUser> couponUserList = queryList(userId, couponId, CouponUserConstant.STATUS_USABLE, 1, 1, "add_time", "desc");
if(couponUserList.size() == 0){
return null;
}
return couponUserList.get(0);
}
public LitemallCouponUser findById(Integer id) {
return couponUserMapper.selectByPrimaryKey(id);
}
public int update(LitemallCouponUser couponUser) {
couponUser.setUpdateTime(LocalDateTime.now());
return couponUserMapper.updateByPrimaryKeySelective(couponUser);
}
}

View File

@@ -0,0 +1,14 @@
package org.linlinjava.litemall.db.util;
public class CouponConstant {
public static final Short TYPE_COMMON = 0;
public static final Short TYPE_REGISTER = 1;
public static final Short GOODS_TYPE_ALL = 0;
public static final Short GOODS_TYPE_CATEGORY = 1;
public static final Short GOODS_TYPE_ARRAY = 2;
public static final Short STATUS_NORMAL = 0;
public static final Short STATUS_EXPIRED = 1;
public static final Short STATUS_OUT = 2;
}

View File

@@ -0,0 +1,8 @@
package org.linlinjava.litemall.db.util;
public class CouponUserConstant {
public static final Short STATUS_USABLE = 0;
public static final Short STATUS_USED = 1;
public static final Short STATUS_EXPIRED = 2;
public static final Short STATUS_OUT = 3;
}

View File

@@ -0,0 +1,613 @@
<?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="org.linlinjava.litemall.db.dao.LitemallCouponMapper">
<resultMap id="BaseResultMap" type="org.linlinjava.litemall.db.domain.LitemallCoupon">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="desc" jdbcType="VARCHAR" property="desc" />
<result column="tag" jdbcType="VARCHAR" property="tag" />
<result column="total" jdbcType="INTEGER" property="total" />
<result column="discount" jdbcType="DECIMAL" property="discount" />
<result column="min" jdbcType="DECIMAL" property="min" />
<result column="limit" jdbcType="SMALLINT" property="limit" />
<result column="type" jdbcType="SMALLINT" property="type" />
<result column="status" jdbcType="SMALLINT" property="status" />
<result column="goods_type" jdbcType="SMALLINT" property="goodsType" />
<result column="goods_value" jdbcType="VARCHAR" property="goodsValue" />
<result column="days" jdbcType="SMALLINT" property="days" />
<result column="start_time" jdbcType="TIMESTAMP" property="startTime" />
<result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
<result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="deleted" jdbcType="BIT" property="deleted" />
</resultMap>
<sql id="Example_Where_Clause">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, `name`, `desc`, tag, total, discount, `min`, `limit`, `type`, `status`, goods_type,
goods_value, `days`, start_time, end_time, add_time, update_time, deleted
</sql>
<select id="selectByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallCouponExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from litemall_coupon
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExampleSelective" parameterType="map" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
<if test="example.distinct">
distinct
</if>
<choose>
<when test="selective != null and selective.length &gt; 0">
<foreach collection="selective" item="column" separator=",">
${column.escapedColumnName}
</foreach>
</when>
<otherwise>
id, `name`, `desc`, tag, total, discount, `min`, `limit`, `type`, `status`, goods_type,
goods_value, `days`, start_time, end_time, add_time, update_time, deleted
</otherwise>
</choose>
from litemall_coupon
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
<if test="example.orderByClause != null">
order by ${example.orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<include refid="Base_Column_List" />
from litemall_coupon
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByPrimaryKeyWithLogicalDelete" parameterType="map" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<include refid="Base_Column_List" />
from litemall_coupon
where id = #{id,jdbcType=INTEGER}
and deleted =
<choose>
<when test="andLogicalDeleted">
1
</when>
<otherwise>
0
</otherwise>
</choose>
</select>
<select id="selectByPrimaryKeySelective" parameterType="map" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
<choose>
<when test="selective != null and selective.length &gt; 0">
<foreach collection="selective" item="column" separator=",">
${column.escapedColumnName}
</foreach>
</when>
<otherwise>
id, `name`, `desc`, tag, total, discount, `min`, `limit`, `type`, `status`, goods_type,
goods_value, `days`, start_time, end_time, add_time, update_time, deleted
</otherwise>
</choose>
from litemall_coupon
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
delete from litemall_coupon
where id = #{id,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallCouponExample">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
delete from litemall_coupon
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="org.linlinjava.litemall.db.domain.LitemallCoupon">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into litemall_coupon (`name`, `desc`, tag,
total, discount, `min`,
`limit`, `type`, `status`,
goods_type, goods_value, `days`,
start_time, end_time, add_time,
update_time, deleted)
values (#{name,jdbcType=VARCHAR}, #{desc,jdbcType=VARCHAR}, #{tag,jdbcType=VARCHAR},
#{total,jdbcType=INTEGER}, #{discount,jdbcType=DECIMAL}, #{min,jdbcType=DECIMAL},
#{limit,jdbcType=SMALLINT}, #{type,jdbcType=SMALLINT}, #{status,jdbcType=SMALLINT},
#{goodsType,jdbcType=SMALLINT}, #{goodsValue,jdbcType=VARCHAR}, #{days,jdbcType=SMALLINT},
#{startTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}, #{addTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT})
</insert>
<insert id="insertSelective" parameterType="org.linlinjava.litemall.db.domain.LitemallCoupon">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into litemall_coupon
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">
`name`,
</if>
<if test="desc != null">
`desc`,
</if>
<if test="tag != null">
tag,
</if>
<if test="total != null">
total,
</if>
<if test="discount != null">
discount,
</if>
<if test="min != null">
`min`,
</if>
<if test="limit != null">
`limit`,
</if>
<if test="type != null">
`type`,
</if>
<if test="status != null">
`status`,
</if>
<if test="goodsType != null">
goods_type,
</if>
<if test="goodsValue != null">
goods_value,
</if>
<if test="days != null">
`days`,
</if>
<if test="startTime != null">
start_time,
</if>
<if test="endTime != null">
end_time,
</if>
<if test="addTime != null">
add_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="deleted != null">
deleted,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="desc != null">
#{desc,jdbcType=VARCHAR},
</if>
<if test="tag != null">
#{tag,jdbcType=VARCHAR},
</if>
<if test="total != null">
#{total,jdbcType=INTEGER},
</if>
<if test="discount != null">
#{discount,jdbcType=DECIMAL},
</if>
<if test="min != null">
#{min,jdbcType=DECIMAL},
</if>
<if test="limit != null">
#{limit,jdbcType=SMALLINT},
</if>
<if test="type != null">
#{type,jdbcType=SMALLINT},
</if>
<if test="status != null">
#{status,jdbcType=SMALLINT},
</if>
<if test="goodsType != null">
#{goodsType,jdbcType=SMALLINT},
</if>
<if test="goodsValue != null">
#{goodsValue,jdbcType=VARCHAR},
</if>
<if test="days != null">
#{days,jdbcType=SMALLINT},
</if>
<if test="startTime != null">
#{startTime,jdbcType=TIMESTAMP},
</if>
<if test="endTime != null">
#{endTime,jdbcType=TIMESTAMP},
</if>
<if test="addTime != null">
#{addTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="deleted != null">
#{deleted,jdbcType=BIT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallCouponExample" resultType="java.lang.Long">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select count(*) from litemall_coupon
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update litemall_coupon
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=INTEGER},
</if>
<if test="record.name != null">
`name` = #{record.name,jdbcType=VARCHAR},
</if>
<if test="record.desc != null">
`desc` = #{record.desc,jdbcType=VARCHAR},
</if>
<if test="record.tag != null">
tag = #{record.tag,jdbcType=VARCHAR},
</if>
<if test="record.total != null">
total = #{record.total,jdbcType=INTEGER},
</if>
<if test="record.discount != null">
discount = #{record.discount,jdbcType=DECIMAL},
</if>
<if test="record.min != null">
`min` = #{record.min,jdbcType=DECIMAL},
</if>
<if test="record.limit != null">
`limit` = #{record.limit,jdbcType=SMALLINT},
</if>
<if test="record.type != null">
`type` = #{record.type,jdbcType=SMALLINT},
</if>
<if test="record.status != null">
`status` = #{record.status,jdbcType=SMALLINT},
</if>
<if test="record.goodsType != null">
goods_type = #{record.goodsType,jdbcType=SMALLINT},
</if>
<if test="record.goodsValue != null">
goods_value = #{record.goodsValue,jdbcType=VARCHAR},
</if>
<if test="record.days != null">
`days` = #{record.days,jdbcType=SMALLINT},
</if>
<if test="record.startTime != null">
start_time = #{record.startTime,jdbcType=TIMESTAMP},
</if>
<if test="record.endTime != null">
end_time = #{record.endTime,jdbcType=TIMESTAMP},
</if>
<if test="record.addTime != null">
add_time = #{record.addTime,jdbcType=TIMESTAMP},
</if>
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
</if>
<if test="record.deleted != null">
deleted = #{record.deleted,jdbcType=BIT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update litemall_coupon
set id = #{record.id,jdbcType=INTEGER},
`name` = #{record.name,jdbcType=VARCHAR},
`desc` = #{record.desc,jdbcType=VARCHAR},
tag = #{record.tag,jdbcType=VARCHAR},
total = #{record.total,jdbcType=INTEGER},
discount = #{record.discount,jdbcType=DECIMAL},
`min` = #{record.min,jdbcType=DECIMAL},
`limit` = #{record.limit,jdbcType=SMALLINT},
`type` = #{record.type,jdbcType=SMALLINT},
`status` = #{record.status,jdbcType=SMALLINT},
goods_type = #{record.goodsType,jdbcType=SMALLINT},
goods_value = #{record.goodsValue,jdbcType=VARCHAR},
`days` = #{record.days,jdbcType=SMALLINT},
start_time = #{record.startTime,jdbcType=TIMESTAMP},
end_time = #{record.endTime,jdbcType=TIMESTAMP},
add_time = #{record.addTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
deleted = #{record.deleted,jdbcType=BIT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="org.linlinjava.litemall.db.domain.LitemallCoupon">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update litemall_coupon
<set>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
<if test="desc != null">
`desc` = #{desc,jdbcType=VARCHAR},
</if>
<if test="tag != null">
tag = #{tag,jdbcType=VARCHAR},
</if>
<if test="total != null">
total = #{total,jdbcType=INTEGER},
</if>
<if test="discount != null">
discount = #{discount,jdbcType=DECIMAL},
</if>
<if test="min != null">
`min` = #{min,jdbcType=DECIMAL},
</if>
<if test="limit != null">
`limit` = #{limit,jdbcType=SMALLINT},
</if>
<if test="type != null">
`type` = #{type,jdbcType=SMALLINT},
</if>
<if test="status != null">
`status` = #{status,jdbcType=SMALLINT},
</if>
<if test="goodsType != null">
goods_type = #{goodsType,jdbcType=SMALLINT},
</if>
<if test="goodsValue != null">
goods_value = #{goodsValue,jdbcType=VARCHAR},
</if>
<if test="days != null">
`days` = #{days,jdbcType=SMALLINT},
</if>
<if test="startTime != null">
start_time = #{startTime,jdbcType=TIMESTAMP},
</if>
<if test="endTime != null">
end_time = #{endTime,jdbcType=TIMESTAMP},
</if>
<if test="addTime != null">
add_time = #{addTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="deleted != null">
deleted = #{deleted,jdbcType=BIT},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="org.linlinjava.litemall.db.domain.LitemallCoupon">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update litemall_coupon
set `name` = #{name,jdbcType=VARCHAR},
`desc` = #{desc,jdbcType=VARCHAR},
tag = #{tag,jdbcType=VARCHAR},
total = #{total,jdbcType=INTEGER},
discount = #{discount,jdbcType=DECIMAL},
`min` = #{min,jdbcType=DECIMAL},
`limit` = #{limit,jdbcType=SMALLINT},
`type` = #{type,jdbcType=SMALLINT},
`status` = #{status,jdbcType=SMALLINT},
goods_type = #{goodsType,jdbcType=SMALLINT},
goods_value = #{goodsValue,jdbcType=VARCHAR},
`days` = #{days,jdbcType=SMALLINT},
start_time = #{startTime,jdbcType=TIMESTAMP},
end_time = #{endTime,jdbcType=TIMESTAMP},
add_time = #{addTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
deleted = #{deleted,jdbcType=BIT}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectOneByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallCouponExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
<include refid="Base_Column_List" />
from litemall_coupon
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
limit 1
</select>
<select id="selectOneByExampleSelective" parameterType="map" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
<choose>
<when test="selective != null and selective.length &gt; 0">
<foreach collection="selective" item="column" separator=",">
${column.escapedColumnName}
</foreach>
</when>
<otherwise>
id, `name`, `desc`, tag, total, discount, `min`, `limit`, `type`, `status`, goods_type,
goods_value, `days`, start_time, end_time, add_time, update_time, deleted
</otherwise>
</choose>
from litemall_coupon
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
<if test="example.orderByClause != null">
order by ${example.orderByClause}
</if>
limit 1
</select>
<update id="logicalDeleteByExample" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
update litemall_coupon set deleted = 1
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="logicalDeleteByPrimaryKey" parameterType="java.lang.Integer">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
update litemall_coupon set deleted = 1
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>

View File

@@ -0,0 +1,471 @@
<?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="org.linlinjava.litemall.db.dao.LitemallCouponUserMapper">
<resultMap id="BaseResultMap" type="org.linlinjava.litemall.db.domain.LitemallCouponUser">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<id column="id" jdbcType="INTEGER" property="id" />
<result column="user_id" jdbcType="INTEGER" property="userId" />
<result column="coupon_id" jdbcType="INTEGER" property="couponId" />
<result column="status" jdbcType="SMALLINT" property="status" />
<result column="used_time" jdbcType="TIMESTAMP" property="usedTime" />
<result column="order_id" jdbcType="INTEGER" property="orderId" />
<result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="deleted" jdbcType="BIT" property="deleted" />
</resultMap>
<sql id="Example_Where_Clause">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, user_id, coupon_id, `status`, used_time, order_id, add_time, update_time, deleted
</sql>
<select id="selectByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallCouponUserExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from litemall_coupon_user
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExampleSelective" parameterType="map" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
<if test="example.distinct">
distinct
</if>
<choose>
<when test="selective != null and selective.length &gt; 0">
<foreach collection="selective" item="column" separator=",">
${column.escapedColumnName}
</foreach>
</when>
<otherwise>
id, user_id, coupon_id, `status`, used_time, order_id, add_time, update_time, deleted
</otherwise>
</choose>
from litemall_coupon_user
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
<if test="example.orderByClause != null">
order by ${example.orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<include refid="Base_Column_List" />
from litemall_coupon_user
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByPrimaryKeyWithLogicalDelete" parameterType="map" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<include refid="Base_Column_List" />
from litemall_coupon_user
where id = #{id,jdbcType=INTEGER}
and deleted =
<choose>
<when test="andLogicalDeleted">
1
</when>
<otherwise>
0
</otherwise>
</choose>
</select>
<select id="selectByPrimaryKeySelective" parameterType="map" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
<choose>
<when test="selective != null and selective.length &gt; 0">
<foreach collection="selective" item="column" separator=",">
${column.escapedColumnName}
</foreach>
</when>
<otherwise>
id, user_id, coupon_id, `status`, used_time, order_id, add_time, update_time, deleted
</otherwise>
</choose>
from litemall_coupon_user
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
delete from litemall_coupon_user
where id = #{id,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallCouponUserExample">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
delete from litemall_coupon_user
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="org.linlinjava.litemall.db.domain.LitemallCouponUser">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into litemall_coupon_user (user_id, coupon_id, `status`,
used_time, order_id, add_time,
update_time, deleted)
values (#{userId,jdbcType=INTEGER}, #{couponId,jdbcType=INTEGER}, #{status,jdbcType=SMALLINT},
#{usedTime,jdbcType=TIMESTAMP}, #{orderId,jdbcType=INTEGER}, #{addTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT})
</insert>
<insert id="insertSelective" parameterType="org.linlinjava.litemall.db.domain.LitemallCouponUser">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into litemall_coupon_user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId != null">
user_id,
</if>
<if test="couponId != null">
coupon_id,
</if>
<if test="status != null">
`status`,
</if>
<if test="usedTime != null">
used_time,
</if>
<if test="orderId != null">
order_id,
</if>
<if test="addTime != null">
add_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="deleted != null">
deleted,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId != null">
#{userId,jdbcType=INTEGER},
</if>
<if test="couponId != null">
#{couponId,jdbcType=INTEGER},
</if>
<if test="status != null">
#{status,jdbcType=SMALLINT},
</if>
<if test="usedTime != null">
#{usedTime,jdbcType=TIMESTAMP},
</if>
<if test="orderId != null">
#{orderId,jdbcType=INTEGER},
</if>
<if test="addTime != null">
#{addTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="deleted != null">
#{deleted,jdbcType=BIT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallCouponUserExample" resultType="java.lang.Long">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select count(*) from litemall_coupon_user
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update litemall_coupon_user
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=INTEGER},
</if>
<if test="record.userId != null">
user_id = #{record.userId,jdbcType=INTEGER},
</if>
<if test="record.couponId != null">
coupon_id = #{record.couponId,jdbcType=INTEGER},
</if>
<if test="record.status != null">
`status` = #{record.status,jdbcType=SMALLINT},
</if>
<if test="record.usedTime != null">
used_time = #{record.usedTime,jdbcType=TIMESTAMP},
</if>
<if test="record.orderId != null">
order_id = #{record.orderId,jdbcType=INTEGER},
</if>
<if test="record.addTime != null">
add_time = #{record.addTime,jdbcType=TIMESTAMP},
</if>
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
</if>
<if test="record.deleted != null">
deleted = #{record.deleted,jdbcType=BIT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update litemall_coupon_user
set id = #{record.id,jdbcType=INTEGER},
user_id = #{record.userId,jdbcType=INTEGER},
coupon_id = #{record.couponId,jdbcType=INTEGER},
`status` = #{record.status,jdbcType=SMALLINT},
used_time = #{record.usedTime,jdbcType=TIMESTAMP},
order_id = #{record.orderId,jdbcType=INTEGER},
add_time = #{record.addTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
deleted = #{record.deleted,jdbcType=BIT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="org.linlinjava.litemall.db.domain.LitemallCouponUser">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update litemall_coupon_user
<set>
<if test="userId != null">
user_id = #{userId,jdbcType=INTEGER},
</if>
<if test="couponId != null">
coupon_id = #{couponId,jdbcType=INTEGER},
</if>
<if test="status != null">
`status` = #{status,jdbcType=SMALLINT},
</if>
<if test="usedTime != null">
used_time = #{usedTime,jdbcType=TIMESTAMP},
</if>
<if test="orderId != null">
order_id = #{orderId,jdbcType=INTEGER},
</if>
<if test="addTime != null">
add_time = #{addTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="deleted != null">
deleted = #{deleted,jdbcType=BIT},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="org.linlinjava.litemall.db.domain.LitemallCouponUser">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update litemall_coupon_user
set user_id = #{userId,jdbcType=INTEGER},
coupon_id = #{couponId,jdbcType=INTEGER},
`status` = #{status,jdbcType=SMALLINT},
used_time = #{usedTime,jdbcType=TIMESTAMP},
order_id = #{orderId,jdbcType=INTEGER},
add_time = #{addTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
deleted = #{deleted,jdbcType=BIT}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectOneByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallCouponUserExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
<include refid="Base_Column_List" />
from litemall_coupon_user
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
limit 1
</select>
<select id="selectOneByExampleSelective" parameterType="map" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
<choose>
<when test="selective != null and selective.length &gt; 0">
<foreach collection="selective" item="column" separator=",">
${column.escapedColumnName}
</foreach>
</when>
<otherwise>
id, user_id, coupon_id, `status`, used_time, order_id, add_time, update_time, deleted
</otherwise>
</choose>
from litemall_coupon_user
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
<if test="example.orderByClause != null">
order by ${example.orderByClause}
</if>
limit 1
</select>
<update id="logicalDeleteByExample" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
update litemall_coupon_user set deleted = 1
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="logicalDeleteByPrimaryKey" parameterType="java.lang.Integer">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
update litemall_coupon_user set deleted = 1
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>

View File

@@ -0,0 +1,79 @@
package org.linlinjava.litemall.wx.dao;
import java.time.LocalDateTime;
public class CouponVo {
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
private String name;
private String desc;
private String tag;
private String min;
private String discount;
private LocalDateTime startTime;
private LocalDateTime endTime;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getMin() {
return min;
}
public void setMin(String min) {
this.min = min;
}
public String getDiscount() {
return discount;
}
public void setDiscount(String discount) {
this.discount = discount;
}
public LocalDateTime getStartTime() {
return startTime;
}
public void setStartTime(LocalDateTime startTime) {
this.startTime = startTime;
}
public LocalDateTime getEndTime() {
return endTime;
}
public void setEndTime(LocalDateTime endTime) {
this.endTime = endTime;
}
}

View File

@@ -28,4 +28,8 @@ public class WxResponseCode {
public static final Integer ORDER_COMMENT_EXPIRED = 727;
public static final Integer GROUPON_EXPIRED = 730;
public static final int COUPON_EXCEED_LIMIT = 740;
public static final int COUPON_RECEIVE_FAIL= 741;
}

View File

@@ -13,6 +13,7 @@ import org.linlinjava.litemall.core.util.RegexUtil;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.util.bcrypt.BCryptPasswordEncoder;
import org.linlinjava.litemall.db.domain.LitemallUser;
import org.linlinjava.litemall.db.service.CouponAssignService;
import org.linlinjava.litemall.db.service.LitemallUserService;
import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.dao.UserInfo;
@@ -55,6 +56,9 @@ public class WxAuthController {
@Autowired
private NotifyService notifyService;
@Autowired
private CouponAssignService couponAssignService;
/**
* 账号登录
*
@@ -144,6 +148,9 @@ public class WxAuthController {
user.setLastLoginIp(IpUtil.client(request));
userService.add(user);
// 新用户发送注册优惠券
couponAssignService.assignForRegister(user.getId());
} else {
user.setLastLoginTime(LocalDateTime.now());
user.setLastLoginIp(IpUtil.client(request));
@@ -289,6 +296,9 @@ public class WxAuthController {
user.setLastLoginIp(IpUtil.client(request));
userService.add(user);
// 给新用户发送注册优惠券
couponAssignService.assignForRegister(user.getId());
// userInfo
UserInfo userInfo = new UserInfo();
userInfo.setNickName(username);

View File

@@ -41,6 +41,12 @@ public class WxCartController {
private LitemallAddressService addressService;
@Autowired
private LitemallGrouponRulesService grouponRulesService;
@Autowired
private LitemallCouponService couponService;
@Autowired
private LitemallCouponUserService couponUserService;
@Autowired
private CouponVerifyService couponVerifyService;
/**
* 用户购物车信息
@@ -367,7 +373,7 @@ public class WxCartController {
* @param addressId 收货地址ID
* 如果收货地址ID是空则查询当前用户的默认地址。
* @param couponId 优惠券ID
* 目前不支持
* 如果优惠券ID是空则自动选择合适的优惠券。
* @return 购物车操作结果
*/
@GetMapping("checkout")
@@ -398,10 +404,6 @@ public class WxCartController {
}
}
// 获取可用的优惠券信息
// 使用优惠券减免的金额
BigDecimal couponPrice = new BigDecimal(0.00);
// 团购优惠
BigDecimal grouponPrice = new BigDecimal(0.00);
LitemallGrouponRules grouponRules = grouponRulesService.queryById(grouponRulesId);
@@ -431,6 +433,46 @@ public class WxCartController {
}
}
// 计算优惠券可用情况
BigDecimal tmpCouponPrice = new BigDecimal(0.00);
Integer tmpCouponId = 0;
int tmpCouponLength = 0;
List<LitemallCouponUser> couponUserList = couponUserService.queryAll(userId);
for(LitemallCouponUser couponUser : couponUserList){
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponUser.getCouponId(), checkedGoodsPrice);
if(coupon == null){
continue;
}
tmpCouponLength++;
if(tmpCouponPrice.compareTo(coupon.getDiscount()) == -1){
tmpCouponPrice = coupon.getDiscount();
tmpCouponId = coupon.getId();
}
}
// 获取优惠券减免金额,优惠券可用数量
int availableCouponLength = tmpCouponLength;
BigDecimal couponPrice = new BigDecimal(0);
// 这里存在三种情况
// 1. 用户不想使用优惠券,则不处理
// 2. 用户想自动使用优惠券,则选择合适优惠券
// 3. 用户已选择优惠券,则测试优惠券是否合适
if (couponId == null || couponId.equals(-1)){
couponId = -1;
}
else if (couponId.equals(0)) {
couponPrice = tmpCouponPrice;
couponId = tmpCouponId;
}
else {
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, checkedGoodsPrice);
// 用户选择的优惠券有问题
if(coupon == null){
return ResponseUtil.badArgumentValue();
}
couponPrice = coupon.getDiscount();
}
// 根据订单商品总价计算运费满88则免运费否则8元
BigDecimal freightPrice = new BigDecimal(0.00);
if (checkedGoodsPrice.compareTo(SystemConfig.getFreightLimit()) < 0) {
@@ -450,8 +492,7 @@ public class WxCartController {
data.put("grouponPrice", grouponPrice);
data.put("checkedAddress", checkedAddress);
data.put("couponId", couponId);
data.put("checkedCoupon", 0);
data.put("couponList", "");
data.put("availableCouponLength", availableCouponLength);
data.put("goodsTotalPrice", checkedGoodsPrice);
data.put("freightPrice", freightPrice);
data.put("couponPrice", couponPrice);

View File

@@ -0,0 +1,256 @@
package org.linlinjava.litemall.wx.web;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.util.JacksonUtil;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.LitemallCart;
import org.linlinjava.litemall.db.domain.LitemallCoupon;
import org.linlinjava.litemall.db.domain.LitemallCouponUser;
import org.linlinjava.litemall.db.domain.LitemallGrouponRules;
import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.db.util.CouponConstant;
import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.dao.CouponVo;
import org.linlinjava.litemall.wx.util.WxResponseCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 优惠券服务
*/
@RestController
@RequestMapping("/wx/coupon")
@Validated
public class WxCouponController {
private final Log logger = LogFactory.getLog(WxCouponController.class);
@Autowired
private LitemallCouponService couponService;
@Autowired
private LitemallCouponUserService couponUserService;
@Autowired
private LitemallGrouponRulesService grouponRulesService;
@Autowired
private LitemallCartService cartService;
@Autowired
private CouponVerifyService couponVerifyService;
/**
* 优惠券列表
*
* @param page
* @param size
* @param sort
* @param order
* @return
*/
@GetMapping("list")
public Object list(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size,
@Sort @RequestParam(defaultValue = "add_time") String sort,
@Order @RequestParam(defaultValue = "desc") String order) {
List<LitemallCoupon> couponList = couponService.queryList(page, size, sort, order);
int total = couponService.queryTotal();
Map<String, Object> data = new HashMap<String, Object>();
data.put("data", couponList);
data.put("count", total);
return ResponseUtil.ok(data);
}
/**
* 个人优惠券列表
*
* @param userId
* @param status
* @param page
* @param size
* @param sort
* @param order
* @return
*/
@GetMapping("mylist")
public Object mylist(@LoginUser Integer userId,
@NotNull Short status,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size,
@Sort @RequestParam(defaultValue = "add_time") String sort,
@Order @RequestParam(defaultValue = "desc") String order) {
if (userId == null) {
return ResponseUtil.unlogin();
}
List<LitemallCouponUser> couponUserList = couponUserService.queryList(userId, null, status, page, size, sort, order);
List<CouponVo> couponVoList = change(couponUserList);
int total = couponService.queryTotal();
Map<String, Object> data = new HashMap<String, Object>();
data.put("data", couponVoList);
data.put("count", total);
return ResponseUtil.ok(data);
}
private List<CouponVo> change(List<LitemallCouponUser> couponList) {
List<CouponVo> couponVoList = new ArrayList<>(couponList.size());
for(LitemallCouponUser couponUser : couponList){
Integer couponId = couponUser.getCouponId();
LitemallCoupon coupon = couponService.findById(couponId);
CouponVo couponVo = new CouponVo();
couponVo.setId(coupon.getId());
couponVo.setName(coupon.getName());
couponVo.setDesc(coupon.getDesc());
couponVo.setTag(coupon.getTag());
couponVo.setMin(coupon.getMin().toPlainString());
couponVo.setDiscount(coupon.getDiscount().toPlainString());
Short days = coupon.getDays();
if (days == 0) {
couponVo.setStartTime(coupon.getStartTime());
couponVo.setEndTime(coupon.getEndTime());
}
else{
couponVo.setStartTime(coupon.getAddTime());
couponVo.setEndTime(coupon.getAddTime().plusDays(days));
}
couponVoList.add(couponVo);
}
return couponVoList;
}
/**
* 当前购物车下单商品订单可用优惠券
*
* @param userId
* @param cartId
* @param grouponRulesId
* @return
*/
@GetMapping("selectlist")
public Object selectlist(@LoginUser Integer userId, Integer cartId, Integer grouponRulesId) {
if (userId == null) {
return ResponseUtil.unlogin();
}
// 团购优惠
BigDecimal grouponPrice = new BigDecimal(0.00);
LitemallGrouponRules grouponRules = grouponRulesService.queryById(grouponRulesId);
if (grouponRules != null) {
grouponPrice = grouponRules.getDiscount();
}
// 商品价格
List<LitemallCart> checkedGoodsList = null;
if (cartId == null || cartId.equals(0)) {
checkedGoodsList = cartService.queryByUidAndChecked(userId);
} else {
LitemallCart cart = cartService.findById(cartId);
if (cart == null) {
return ResponseUtil.badArgumentValue();
}
checkedGoodsList = new ArrayList<>(1);
checkedGoodsList.add(cart);
}
BigDecimal checkedGoodsPrice = new BigDecimal(0.00);
for (LitemallCart cart : checkedGoodsList) {
// 只有当团购规格商品ID符合才进行团购优惠
if (grouponRules != null && grouponRules.getGoodsId().equals(cart.getGoodsId())) {
checkedGoodsPrice = checkedGoodsPrice.add(cart.getPrice().subtract(grouponPrice).multiply(new BigDecimal(cart.getNumber())));
} else {
checkedGoodsPrice = checkedGoodsPrice.add(cart.getPrice().multiply(new BigDecimal(cart.getNumber())));
}
}
// 计算优惠券可用情况
List<LitemallCouponUser> couponUserList = couponUserService.queryAll(userId);
List<LitemallCouponUser> availableCouponUserList = new ArrayList<>(couponUserList.size());
for (LitemallCouponUser couponUser : couponUserList) {
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponUser.getCouponId(), checkedGoodsPrice);
if (coupon == null) {
continue;
}
availableCouponUserList.add(couponUser);
}
List<CouponVo> couponVoList = change(availableCouponUserList);
return ResponseUtil.ok(couponVoList);
}
/**
* 优惠券领取
*
* @param userId 用户ID
* @param body 请求内容, { couponId: xxx }
* @return 操作结果
*/
@PostMapping("receive")
public Object receive(@LoginUser Integer userId, @RequestBody String body) {
if (userId == null) {
return ResponseUtil.unlogin();
}
Integer couponId = JacksonUtil.parseInteger(body, "couponId");
if(couponId == null){
return ResponseUtil.badArgument();
}
LitemallCoupon coupon = couponService.findById(couponId);
if(coupon == null){
return ResponseUtil.badArgumentValue();
}
// 当前已领取数量和总数量比较
Integer total = coupon.getTotal();
Integer totalCoupons = couponUserService.countCoupon(couponId);
if((total != 0) && (totalCoupons >= total)){
return ResponseUtil.fail(WxResponseCode.COUPON_EXCEED_LIMIT, "优惠券已领完");
}
// 当前用户已领取数量和用户限领数量比较
Integer limit = coupon.getLimit().intValue();
Integer userCounpons = couponUserService.countUserAndCoupon(userId, couponId);
if((limit != 0) && (userCounpons >= limit)){
return ResponseUtil.fail(WxResponseCode.COUPON_EXCEED_LIMIT, "优惠券已经领取过");
}
// 优惠券分发类型
// 例如注册赠券类型的优惠券不能领取
Short type = coupon.getType();
if(type.equals(CouponConstant.TYPE_REGISTER)){
return ResponseUtil.fail(WxResponseCode.COUPON_RECEIVE_FAIL, "新用户优惠券自动发送");
}
else if(!type.equals(CouponConstant.TYPE_COMMON)){
return ResponseUtil.fail(WxResponseCode.COUPON_RECEIVE_FAIL, "优惠券类型不支持");
}
// 优惠券状态,已下架或者过期不能领取
Short status = coupon.getStatus();
if(status.equals(CouponConstant.STATUS_OUT)){
return ResponseUtil.fail(WxResponseCode.COUPON_EXCEED_LIMIT, "优惠券已领完");
}
if(status.equals(CouponConstant.STATUS_EXPIRED)){
return ResponseUtil.fail(WxResponseCode.COUPON_RECEIVE_FAIL, "优惠券已经过期");
}
// 用户领券记录
LitemallCouponUser couponUser = new LitemallCouponUser();
couponUser.setCouponId(couponId);
couponUser.setUserId(userId);
couponUserService.add(couponUser);
return ResponseUtil.ok();
}
}

View File

@@ -40,7 +40,8 @@ public class WxHomeController {
private LitemallCategoryService categoryService;
@Autowired
private LitemallGrouponRulesService grouponRulesService;
@Autowired
private LitemallCouponService couponService;
@GetMapping("/cache")
public Object cache(@NotNull String key) {
@@ -74,6 +75,9 @@ public class WxHomeController {
List<LitemallCategory> channel = categoryService.queryChannel();
data.put("channel", channel);
List<LitemallCoupon> couponList = couponService.queryList(0, 3);
data.put("couponList", couponList);
List<LitemallGoods> newGoods = goodsService.queryByNew(0, SystemConfig.getNewLimit());
data.put("newGoodsList", newGoods);

View File

@@ -21,6 +21,7 @@ import org.linlinjava.litemall.core.util.JacksonUtil;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.db.util.CouponUserConstant;
import org.linlinjava.litemall.db.util.OrderHandleOption;
import org.linlinjava.litemall.db.util.OrderUtil;
import org.linlinjava.litemall.wx.annotation.LoginUser;
@@ -106,6 +107,12 @@ public class WxOrderController {
private ExpressService expressService;
@Autowired
private LitemallCommentService commentService;
@Autowired
private LitemallCouponService couponService;
@Autowired
private LitemallCouponUserService couponUserService;
@Autowired
private CouponVerifyService couponVerifyService;
private String detailedAddress(LitemallAddress litemallAddress) {
Integer provinceId = litemallAddress.getProvinceId();
@@ -241,7 +248,7 @@ public class WxOrderController {
* <p>
* 1. 创建订单表项和订单商品表项;
* 2. 购物车清空;
* 3. TODO 优惠券设置已用;
* 3. 优惠券设置已用;
* 4. 商品货品库存减少;
* 5. 如果是团购商品,则创建团购活动表项。
*
@@ -287,10 +294,6 @@ public class WxOrderController {
return ResponseUtil.badArgument();
}
// 获取可用的优惠券信息
// 使用优惠券减免的金额
BigDecimal couponPrice = new BigDecimal(0.00);
// 团购优惠
BigDecimal grouponPrice = new BigDecimal(0.00);
LitemallGrouponRules grouponRules = grouponRulesService.queryById(grouponRulesId);
@@ -320,6 +323,19 @@ public class WxOrderController {
}
}
// 获取可用的优惠券信息
// 使用优惠券减免的金额
BigDecimal couponPrice = new BigDecimal(0.00);
// 如果couponId=0则没有优惠券couponId=-1则不使用优惠券
if(couponId != 0 && couponId != -1){
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, checkedGoodsPrice);
if(coupon == null){
return ResponseUtil.badArgumentValue();
}
couponPrice = coupon.getDiscount();
}
// 根据订单商品总价计算运费满足条件例如88元则免运费否则需要支付运费例如8元
BigDecimal freightPrice = new BigDecimal(0.00);
if (checkedGoodsPrice.compareTo(SystemConfig.getFreightLimit()) < 0) {
@@ -331,6 +347,7 @@ public class WxOrderController {
// 订单费用
BigDecimal orderTotalPrice = checkedGoodsPrice.add(freightPrice).subtract(couponPrice);
// 最终支付费用
BigDecimal actualPrice = orderTotalPrice.subtract(integralPrice);
// 开启事务管理
@@ -368,6 +385,7 @@ public class WxOrderController {
orderService.add(order);
orderId = order.getId();
// 添加订单商品表项
for (LitemallCart cartGoods : checkedGoodsList) {
// 订单商品
LitemallOrderGoods orderGoods = new LitemallOrderGoods();
@@ -382,7 +400,6 @@ public class WxOrderController {
orderGoods.setSpecifications(cartGoods.getSpecifications());
orderGoods.setAddTime(LocalDateTime.now());
// 添加订单商品表项
orderGoodsService.add(orderGoods);
}
@@ -403,6 +420,15 @@ public class WxOrderController {
}
}
// 如果使用了优惠券,设置优惠券使用状态
if(couponId != 0 && couponId != -1){
LitemallCouponUser couponUser = couponUserService.queryOne(userId, couponId);
couponUser.setStatus(CouponUserConstant.STATUS_USED);
couponUser.setUsedTime(LocalDateTime.now());
couponUser.setOrderId(orderId);
couponUserService.update(couponUser);
}
//如果是团购项目,添加团购信息
if (grouponRulesId != null && grouponRulesId > 0) {
LitemallGroupon groupon = new LitemallGroupon();