Commit 23b1821a authored by Menethil's avatar Menethil
Browse files

添加团购

parent 39135af3
......@@ -4,15 +4,12 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
import me.chanjar.weixin.common.error.WxErrorException;
import org.linlinjava.litemall.core.storage.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public abstract class QCodeBase {
......@@ -51,9 +48,9 @@ public abstract class QCodeBase {
}
protected void saveImage(String id, byte[] imageData) {
MultipartFile multipartFile = new MockMultipartFile(getKeyName(id), getKeyName(id), "image/jpeg", imageData);
//存储分享图
storageService.store(multipartFile, getKeyName(id));
// MultipartFile multipartFile = new MockMultipartFile(getKeyName(id), getKeyName(id), "image/jpeg", imageData);
// //存储分享图
// storageService.store(multipartFile, getKeyName(id));
}
/**
......
package org.linlinjava.litemall.core.qcode;
import org.linlinjava.litemall.core.system.SystemConfig;
import org.linlinjava.litemall.db.domain.LitemallGroupon;
import org.springframework.core.io.ClassPathResource;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
public class QCodeGroupon extends QCodeBase {
@Override
protected String getKeyName(String id) {
return null;
}
public void createGrouponShareImage(String goodName, String goodPicUrl, LitemallGroupon groupon) {
try {
BufferedImage qrCodeImage = getQCode("groupon," + groupon.getId(), "pages/index/index");
//将商品图片,商品名字,商城名字画到模版图中
byte[] imageData = drawPicture(qrCodeImage, goodPicUrl, goodName, SystemConfig.getMallName());
saveImage(groupon.getId().toString(), imageData);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 将商品图片,商品名字画到模版图中
*
* @param qrCodeImage 二维码图片
* @param goodPicUrl 商品图片地址
* @param goodName 商品名称
* @return
* @throws IOException
*/
private byte[] drawPicture(BufferedImage qrCodeImage, String goodPicUrl, String goodName, String shopName) throws IOException {
//底图
ClassPathResource redResource = new ClassPathResource("back.jpg");
BufferedImage red = ImageIO.read(redResource.getInputStream());
//商品图片
URL goodPic = new URL(goodPicUrl);
BufferedImage goodImage = ImageIO.read(goodPic);
// --- 画图 ---
//底层空白 bufferedImage
BufferedImage baseImage = new BufferedImage(red.getWidth(), red.getHeight(), BufferedImage.TYPE_4BYTE_ABGR_PRE);
//画上图片
drawImgInImg(baseImage, red, 0, 0, red.getWidth(), red.getHeight());
//画上商品图片
drawImgInImg(baseImage, goodImage, 56, 135, 720, 720);
//画上小程序二维码
drawImgInImg(baseImage, qrCodeImage, 442, 1006, 340, 340);
Font font = new Font("Microsoft YaHei", Font.PLAIN, 42);
Color color = new Color(167, 136, 69);
//写上商品名称
drawTextInImg(baseImage, goodName, font, color, 112, 955);
//写上商城名称
drawTextInImgCenter(baseImage, shopName, font, color, 98);
//转jpg
BufferedImage result = new BufferedImage(baseImage.getWidth(), baseImage
.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
result.getGraphics().drawImage(baseImage, 0, 0, null);
ByteArrayOutputStream bs = new ByteArrayOutputStream();
ImageIO.write(result, "jpg", bs);
//最终byte数组
return bs.toByteArray();
}
}
......@@ -176,11 +176,11 @@
<table tableName="litemall_groupon_rules">
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
<columnOverride javaType="java.time.LocalDateTime" column="add_time"/>
<columnOverride javaType="java.time.LocalDateTime" column="expire_time"/>
</table>
<table tableName="litemall_groupon">
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
<columnOverride javaType="java.time.LocalDateTime" column="add_time"/>
<columnOverride javaType="java.time.LocalDateTime" column="expire_time"/>
</table>
</context>
</generatorConfiguration>
\ No newline at end of file
......@@ -86,15 +86,6 @@ public class LitemallGroupon {
*/
private LocalDateTime addTime;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_groupon.expire_time
*
* @mbg.generated
*/
private LocalDateTime expireTime;
/**
*
* This field was generated by MyBatis Generator.
......@@ -299,30 +290,6 @@ public class LitemallGroupon {
this.addTime = addTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_groupon.expire_time
*
* @return the value of litemall_groupon.expire_time
*
* @mbg.generated
*/
public LocalDateTime getExpireTime() {
return expireTime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_groupon.expire_time
*
* @param expireTime the value for litemall_groupon.expire_time
*
* @mbg.generated
*/
public void setExpireTime(LocalDateTime expireTime) {
this.expireTime = expireTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_groupon.share_url
......@@ -438,7 +405,6 @@ public class LitemallGroupon {
sb.append(", userId=").append(userId);
sb.append(", creatorUserId=").append(creatorUserId);
sb.append(", addTime=").append(addTime);
sb.append(", expireTime=").append(expireTime);
sb.append(", shareUrl=").append(shareUrl);
sb.append(", payed=").append(payed);
sb.append(", deleted=").append(deleted);
......@@ -472,7 +438,6 @@ public class LitemallGroupon {
&& (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
&& (this.getCreatorUserId() == null ? other.getCreatorUserId() == null : this.getCreatorUserId().equals(other.getCreatorUserId()))
&& (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
&& (this.getExpireTime() == null ? other.getExpireTime() == null : this.getExpireTime().equals(other.getExpireTime()))
&& (this.getShareUrl() == null ? other.getShareUrl() == null : this.getShareUrl().equals(other.getShareUrl()))
&& (this.getPayed() == null ? other.getPayed() == null : this.getPayed().equals(other.getPayed()))
&& (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()))
......@@ -496,7 +461,6 @@ public class LitemallGroupon {
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
result = prime * result + ((getCreatorUserId() == null) ? 0 : getCreatorUserId().hashCode());
result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode());
result = prime * result + ((getExpireTime() == null) ? 0 : getExpireTime().hashCode());
result = prime * result + ((getShareUrl() == null) ? 0 : getShareUrl().hashCode());
result = prime * result + ((getPayed() == null) ? 0 : getPayed().hashCode());
result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
......@@ -530,7 +494,6 @@ public class LitemallGroupon {
userId("user_id", "userId", "INTEGER"),
creatorUserId("creator_user_id", "creatorUserId", "INTEGER"),
addTime("add_time", "addTime", "TIMESTAMP"),
expireTime("expire_time", "expireTime", "TIMESTAMP"),
shareUrl("share_url", "shareUrl", "VARCHAR"),
payed("payed", "payed", "BIT"),
deleted("deleted", "deleted", "BIT"),
......
......@@ -646,66 +646,6 @@ public class LitemallGrouponExample {
return (Criteria) this;
}
public Criteria andExpireTimeIsNull() {
addCriterion("expire_time is null");
return (Criteria) this;
}
public Criteria andExpireTimeIsNotNull() {
addCriterion("expire_time is not null");
return (Criteria) this;
}
public Criteria andExpireTimeEqualTo(LocalDateTime value) {
addCriterion("expire_time =", value, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeNotEqualTo(LocalDateTime value) {
addCriterion("expire_time <>", value, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeGreaterThan(LocalDateTime value) {
addCriterion("expire_time >", value, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeGreaterThanOrEqualTo(LocalDateTime value) {
addCriterion("expire_time >=", value, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeLessThan(LocalDateTime value) {
addCriterion("expire_time <", value, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeLessThanOrEqualTo(LocalDateTime value) {
addCriterion("expire_time <=", value, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeIn(List<LocalDateTime> values) {
addCriterion("expire_time in", values, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeNotIn(List<LocalDateTime> values) {
addCriterion("expire_time not in", values, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeBetween(LocalDateTime value1, LocalDateTime value2) {
addCriterion("expire_time between", value1, value2, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeNotBetween(LocalDateTime value1, LocalDateTime value2) {
addCriterion("expire_time not between", value1, value2, "expireTime");
return (Criteria) this;
}
public Criteria andShareUrlIsNull() {
addCriterion("share_url is null");
return (Criteria) this;
......
......@@ -87,6 +87,15 @@ public class LitemallGrouponRules {
*/
private LocalDateTime addTime;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_groupon_rules.expire_time
*
* @mbg.generated
*/
private LocalDateTime expireTime;
/**
*
* This field was generated by MyBatis Generator.
......@@ -273,6 +282,30 @@ public class LitemallGrouponRules {
this.addTime = addTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_groupon_rules.expire_time
*
* @return the value of litemall_groupon_rules.expire_time
*
* @mbg.generated
*/
public LocalDateTime getExpireTime() {
return expireTime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_groupon_rules.expire_time
*
* @param expireTime the value for litemall_groupon_rules.expire_time
*
* @mbg.generated
*/
public void setExpireTime(LocalDateTime expireTime) {
this.expireTime = expireTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_groupon_rules.deleted
......@@ -340,6 +373,7 @@ public class LitemallGrouponRules {
sb.append(", discount=").append(discount);
sb.append(", discountMember=").append(discountMember);
sb.append(", addTime=").append(addTime);
sb.append(", expireTime=").append(expireTime);
sb.append(", deleted=").append(deleted);
sb.append(", version=").append(version);
sb.append("]");
......@@ -371,6 +405,7 @@ public class LitemallGrouponRules {
&& (this.getDiscount() == null ? other.getDiscount() == null : this.getDiscount().equals(other.getDiscount()))
&& (this.getDiscountMember() == null ? other.getDiscountMember() == null : this.getDiscountMember().equals(other.getDiscountMember()))
&& (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
&& (this.getExpireTime() == null ? other.getExpireTime() == null : this.getExpireTime().equals(other.getExpireTime()))
&& (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()))
&& (this.getVersion() == null ? other.getVersion() == null : this.getVersion().equals(other.getVersion()));
}
......@@ -392,6 +427,7 @@ public class LitemallGrouponRules {
result = prime * result + ((getDiscount() == null) ? 0 : getDiscount().hashCode());
result = prime * result + ((getDiscountMember() == null) ? 0 : getDiscountMember().hashCode());
result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode());
result = prime * result + ((getExpireTime() == null) ? 0 : getExpireTime().hashCode());
result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
result = prime * result + ((getVersion() == null) ? 0 : getVersion().hashCode());
return result;
......@@ -423,6 +459,7 @@ public class LitemallGrouponRules {
discount("discount", "discount", "DECIMAL"),
discountMember("discount_member", "discountMember", "INTEGER"),
addTime("add_time", "addTime", "TIMESTAMP"),
expireTime("expire_time", "expireTime", "TIMESTAMP"),
deleted("deleted", "deleted", "BIT"),
version("version", "version", "INTEGER");
......
......@@ -667,6 +667,66 @@ public class LitemallGrouponRulesExample {
return (Criteria) this;
}
public Criteria andExpireTimeIsNull() {
addCriterion("expire_time is null");
return (Criteria) this;
}
public Criteria andExpireTimeIsNotNull() {
addCriterion("expire_time is not null");
return (Criteria) this;
}
public Criteria andExpireTimeEqualTo(LocalDateTime value) {
addCriterion("expire_time =", value, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeNotEqualTo(LocalDateTime value) {
addCriterion("expire_time <>", value, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeGreaterThan(LocalDateTime value) {
addCriterion("expire_time >", value, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeGreaterThanOrEqualTo(LocalDateTime value) {
addCriterion("expire_time >=", value, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeLessThan(LocalDateTime value) {
addCriterion("expire_time <", value, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeLessThanOrEqualTo(LocalDateTime value) {
addCriterion("expire_time <=", value, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeIn(List<LocalDateTime> values) {
addCriterion("expire_time in", values, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeNotIn(List<LocalDateTime> values) {
addCriterion("expire_time not in", values, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeBetween(LocalDateTime value1, LocalDateTime value2) {
addCriterion("expire_time between", value1, value2, "expireTime");
return (Criteria) this;
}
public Criteria andExpireTimeNotBetween(LocalDateTime value1, LocalDateTime value2) {
addCriterion("expire_time not between", value1, value2, "expireTime");
return (Criteria) this;
}
public Criteria andDeletedIsNull() {
addCriterion("deleted is null");
return (Criteria) this;
......
......@@ -28,12 +28,14 @@ public class LitemallGrouponService {
public List<LitemallGroupon> queryMyGroupon(Integer userId) {
LitemallGrouponExample example = new LitemallGrouponExample();
example.or().andUserIdEqualTo(userId).andCreatorUserIdEqualTo(userId).andGrouponIdEqualTo(0).andDeletedEqualTo(false);
example.orderBy("add_time desc");
return mapper.selectByExample(example);
}
public List<LitemallGroupon> queryMyJoinGroupon(Integer userId) {
LitemallGrouponExample example = new LitemallGrouponExample();
example.or().andUserIdEqualTo(userId).andGrouponIdNotEqualTo(0).andDeletedEqualTo(false);
example.orderBy("add_time desc");
return mapper.selectByExample(example);
}
......@@ -43,6 +45,13 @@ public class LitemallGrouponService {
return mapper.selectOneByExample(example);
}
public List<LitemallGroupon> queryJoiners(Integer id) {
LitemallGrouponExample example = new LitemallGrouponExample();
example.or().andGrouponIdEqualTo(id).andDeletedEqualTo(false);
example.orderBy("add_time desc");
return mapper.selectByExample(example);
}
/**
* 根据ID查询记录
*
......
......@@ -13,7 +13,6 @@
<result column="user_id" jdbcType="INTEGER" property="userId" />
<result column="creator_user_id" jdbcType="INTEGER" property="creatorUserId" />
<result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
<result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" />
<result column="share_url" jdbcType="VARCHAR" property="shareUrl" />
<result column="payed" jdbcType="BIT" property="payed" />
<result column="deleted" jdbcType="BIT" property="deleted" />
......@@ -90,8 +89,8 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, order_id, groupon_id, rules_id, user_id, creator_user_id, add_time, expire_time,
share_url, payed, deleted, version
id, order_id, groupon_id, rules_id, user_id, creator_user_id, add_time, share_url,
payed, deleted, version
</sql>
<select id="selectByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallGrouponExample" resultMap="BaseResultMap">
<!--
......@@ -128,8 +127,8 @@
</foreach>
</when>
<otherwise>
id, order_id, groupon_id, rules_id, user_id, creator_user_id, add_time, expire_time,
share_url, payed, deleted, version
id, order_id, groupon_id, rules_id, user_id, creator_user_id, add_time, share_url,
payed, deleted, version
</otherwise>
</choose>
from litemall_groupon
......@@ -188,8 +187,8 @@
</foreach>
</when>
<otherwise>
id, order_id, groupon_id, rules_id, user_id, creator_user_id, add_time, expire_time,
share_url, payed, deleted, version
id, order_id, groupon_id, rules_id, user_id, creator_user_id, add_time, share_url,
payed, deleted, version
</otherwise>
</choose>
from litemall_groupon
......@@ -223,12 +222,12 @@
</selectKey>
insert into litemall_groupon (order_id, groupon_id, rules_id,
user_id, creator_user_id, add_time,
expire_time, share_url, payed,
deleted, version)
share_url, payed, deleted, version
)
values (#{orderId,jdbcType=INTEGER}, #{grouponId,jdbcType=INTEGER}, #{rulesId,jdbcType=INTEGER},
#{userId,jdbcType=INTEGER}, #{creatorUserId,jdbcType=INTEGER}, #{addTime,jdbcType=TIMESTAMP},
#{expireTime,jdbcType=TIMESTAMP}, #{shareUrl,jdbcType=VARCHAR}, #{payed,jdbcType=BIT},
#{deleted,jdbcType=BIT}, #{version,jdbcType=INTEGER})
#{shareUrl,jdbcType=VARCHAR}, #{payed,jdbcType=BIT}, #{deleted,jdbcType=BIT}, #{version,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="org.linlinjava.litemall.db.domain.LitemallGroupon">
<!--
......@@ -258,9 +257,6 @@
<if test="addTime != null">
add_time,
</if>
<if test="expireTime != null">
expire_time,
</if>
<if test="shareUrl != null">
share_url,
</if>
......@@ -293,9 +289,6 @@
<if test="addTime != null">
#{addTime,jdbcType=TIMESTAMP},
</if>
<if test="expireTime != null">
#{expireTime,jdbcType=TIMESTAMP},
</if>
<if test="shareUrl != null">
#{shareUrl,jdbcType=VARCHAR},
</if>
......@@ -348,9 +341,6 @@
<if test="record.addTime != null">
add_time = #{record.addTime,jdbcType=TIMESTAMP},
</if>
<if test="record.expireTime != null">
expire_time = #{record.expireTime,jdbcType=TIMESTAMP},
</if>
<if test="record.shareUrl != null">
share_url = #{record.shareUrl,jdbcType=VARCHAR},
</if>
......@@ -381,7 +371,6 @@
user_id = #{record.userId,jdbcType=INTEGER},
creator_user_id = #{record.creatorUserId,jdbcType=INTEGER},
add_time = #{record.addTime,jdbcType=TIMESTAMP},
expire_time = #{record.expireTime,jdbcType=TIMESTAMP},
share_url = #{record.shareUrl,jdbcType=VARCHAR},
payed = #{record.payed,jdbcType=BIT},
deleted = #{record.deleted,jdbcType=BIT},
......@@ -415,9 +404,6 @@
<if test="addTime != null">
add_time = #{addTime,jdbcType=TIMESTAMP},
</if>
<if test="expireTime != null">
expire_time = #{expireTime,jdbcType=TIMESTAMP},
</if>
<if test="shareUrl != null">
share_url = #{shareUrl,jdbcType=VARCHAR},
</if>
......@@ -445,7 +431,6 @@
user_id = #{userId,jdbcType=INTEGER},
creator_user_id = #{creatorUserId,jdbcType=INTEGER},
add_time = #{addTime,jdbcType=TIMESTAMP},
expire_time = #{expireTime,jdbcType=TIMESTAMP},
share_url = #{shareUrl,jdbcType=VARCHAR},
payed = #{payed,jdbcType=BIT},
deleted = #{deleted,jdbcType=BIT},
......@@ -483,8 +468,8 @@
</foreach>
</when>
<otherwise>
id, order_id, groupon_id, rules_id, user_id, creator_user_id, add_time, expire_time,
share_url, payed, deleted, version
id, order_id, groupon_id, rules_id, user_id, creator_user_id, add_time, share_url,
payed, deleted, version
</otherwise>
</choose>
from litemall_groupon
......
......@@ -13,6 +13,7 @@
<result column="discount" jdbcType="DECIMAL" property="discount" />
<result column="discount_member" jdbcType="INTEGER" property="discountMember" />
<result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
<result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" />
<result column="deleted" jdbcType="BIT" property="deleted" />
<result column="version" jdbcType="INTEGER" property="version" />
</resultMap>
......@@ -87,8 +88,8 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, goods_id, goods_name, pic_url, discount, discount_member, add_time, deleted,
version
id, goods_id, goods_name, pic_url, discount, discount_member, add_time, expire_time,
deleted, version
</sql>
<select id="selectByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallGrouponRulesExample" resultMap="BaseResultMap">
<!--
......@@ -125,8 +126,8 @@
</foreach>
</when>
<otherwise>
id, goods_id, goods_name, pic_url, discount, discount_member, add_time, deleted,
version
id, goods_id, goods_name, pic_url, discount, discount_member, add_time, expire_time,
deleted, version
</otherwise>
</choose>
from litemall_groupon_rules
......@@ -185,8 +186,8 @@
</foreach>
</when>
<otherwise>
id, goods_id, goods_name, pic_url, discount, discount_member, add_time, deleted,
version
id, goods_id, goods_name, pic_url, discount, discount_member, add_time, expire_time,
deleted, version
</otherwise>
</choose>
from litemall_groupon_rules
......@@ -220,10 +221,12 @@
</selectKey>
insert into litemall_groupon_rules (goods_id, goods_name, pic_url,
discount, discount_member, add_time,
deleted, version)
expire_time, deleted, version
)
values (#{goodsId,jdbcType=INTEGER}, #{goodsName,jdbcType=VARCHAR}, #{picUrl,jdbcType=VARCHAR},
#{discount,jdbcType=DECIMAL}, #{discountMember,jdbcType=INTEGER}, #{addTime,jdbcType=TIMESTAMP},
#{deleted,jdbcType=BIT}, #{version,jdbcType=INTEGER})
#{expireTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT}, #{version,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="org.linlinjava.litemall.db.domain.LitemallGrouponRules">
<!--
......@@ -253,6 +256,9 @@
<if test="addTime != null">
add_time,
</if>
<if test="expireTime != null">
expire_time,
</if>
<if test="deleted != null">
deleted,
</if>
......@@ -279,6 +285,9 @@
<if test="addTime != null">
#{addTime,jdbcType=TIMESTAMP},
</if>
<if test="expireTime != null">
#{expireTime,jdbcType=TIMESTAMP},
</if>
<if test="deleted != null">
#{deleted,jdbcType=BIT},
</if>
......@@ -325,6 +334,9 @@
<if test="record.addTime != null">
add_time = #{record.addTime,jdbcType=TIMESTAMP},
</if>
<if test="record.expireTime != null">
expire_time = #{record.expireTime,jdbcType=TIMESTAMP},
</if>
<if test="record.deleted != null">
deleted = #{record.deleted,jdbcType=BIT},
</if>
......@@ -349,6 +361,7 @@
discount = #{record.discount,jdbcType=DECIMAL},
discount_member = #{record.discountMember,jdbcType=INTEGER},
add_time = #{record.addTime,jdbcType=TIMESTAMP},
expire_time = #{record.expireTime,jdbcType=TIMESTAMP},
deleted = #{record.deleted,jdbcType=BIT},
version = #{record.version,jdbcType=INTEGER}
<if test="_parameter != null">
......@@ -380,6 +393,9 @@
<if test="addTime != null">
add_time = #{addTime,jdbcType=TIMESTAMP},
</if>
<if test="expireTime != null">
expire_time = #{expireTime,jdbcType=TIMESTAMP},
</if>
<if test="deleted != null">
deleted = #{deleted,jdbcType=BIT},
</if>
......@@ -401,6 +417,7 @@
discount = #{discount,jdbcType=DECIMAL},
discount_member = #{discountMember,jdbcType=INTEGER},
add_time = #{addTime,jdbcType=TIMESTAMP},
expire_time = #{expireTime,jdbcType=TIMESTAMP},
deleted = #{deleted,jdbcType=BIT},
version = #{version,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
......@@ -436,8 +453,8 @@
</foreach>
</when>
<otherwise>
id, goods_id, goods_name, pic_url, discount, discount_member, add_time, deleted,
version
id, goods_id, goods_name, pic_url, discount, discount_member, add_time, expire_time,
deleted, version
</otherwise>
</choose>
from litemall_groupon_rules
......
......@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -51,17 +52,97 @@ public class WxGrouponController {
return ResponseUtil.badArgumentValue();
}
LitemallGoods goods = goodsService.findById(rules.getGoodsId());
// 订单信息
LitemallOrder order = orderService.findById(groupon.getOrderId());
if (null == order) {
return ResponseUtil.fail(403, "订单不存在");
}
if (!order.getUserId().equals(userId)) {
return ResponseUtil.fail(403, "不是当前用户的订单");
}
Map<String, Object> orderVo = new HashMap<String, Object>();
orderVo.put("id", order.getId());
orderVo.put("orderSn", order.getOrderSn());
orderVo.put("addTime", LocalDate.now());
orderVo.put("consignee", order.getConsignee());
orderVo.put("mobile", order.getMobile());
orderVo.put("address", order.getAddress());
orderVo.put("goodsPrice", order.getGoodsPrice());
orderVo.put("freightPrice", order.getFreightPrice());
orderVo.put("actualPrice", order.getActualPrice());
orderVo.put("orderStatusText", OrderUtil.orderStatusText(order));
orderVo.put("handleOption", OrderUtil.build(order));
orderVo.put("expCode", order.getShipChannel());
orderVo.put("expNo", order.getShipSn());
List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(order.getId());
List<Map<String, Object>> orderGoodsVoList = new ArrayList<>(orderGoodsList.size());
for (LitemallOrderGoods orderGoods : orderGoodsList) {
Map<String, Object> orderGoodsVo = new HashMap<>();
orderGoodsVo.put("id", orderGoods.getId());
orderGoodsVo.put("orderId", orderGoods.getOrderId());
orderGoodsVo.put("goodsId", orderGoods.getGoodsId());
orderGoodsVo.put("goodsName", orderGoods.getGoodsName());
orderGoodsVo.put("number", orderGoods.getNumber());
orderGoodsVo.put("retailPrice", orderGoods.getPrice());
orderGoodsVo.put("picUrl", orderGoods.getPicUrl());
orderGoodsVo.put("goodsSpecificationValues", orderGoods.getSpecifications());
orderGoodsVoList.add(orderGoodsVo);
}
Map<String, Object> result = new HashMap<>();
result.put("orderInfo", orderVo);
result.put("orderGoods", orderGoodsVoList);
UserVo creator = userService.findUserVoById(groupon.getCreatorUserId());
List<UserVo> joiners = new ArrayList<>();
joiners.add(creator);
int linkGrouponId;
// 这是一个团购发起记录
if (groupon.getGrouponId() == 0) {
linkGrouponId = groupon.getId();
} else {
linkGrouponId = groupon.getGrouponId();
int count = grouponService.countGroupon(grouponId);
}
List<LitemallGroupon> groupons = grouponService.queryJoiners(linkGrouponId);
Map<String, Object> groupInfo = new HashMap<>();
groupInfo.put("groupon", groupon);
groupInfo.put("rules", rules);
groupInfo.put("goods", goods);
groupInfo.put("count", count);
UserVo joiner;
for (LitemallGroupon grouponItem : groupons) {
joiner = userService.findUserVoById(grouponItem.getUserId());
joiners.add(joiner);
}
return ResponseUtil.ok(groupInfo);
result.put("linkGrouponId", linkGrouponId);
result.put("creator", creator);
result.put("joiners", joiners);
result.put("groupon", groupon);
result.put("rules", rules);
return ResponseUtil.ok(result);
}
@GetMapping("join")
public Object join(@NotNull Integer grouponId) {
LitemallGroupon groupon = grouponService.queryById(grouponId);
if (groupon == null) {
return ResponseUtil.badArgumentValue();
}
LitemallGrouponRules rules = rulesService.queryById(groupon.getRulesId());
if (rules == null) {
return ResponseUtil.badArgumentValue();
}
LitemallGoods goods = goodsService.findById(rules.getGoodsId());
if (goods == null) {
return ResponseUtil.badArgumentValue();
}
Map<String, Object> result = new HashMap<>();
result.put("groupon", groupon);
result.put("goods", goods);
return ResponseUtil.ok(result);
}
@GetMapping("my")
......@@ -93,7 +174,18 @@ public class WxGrouponController {
grouponVo.put("groupon", groupon);
grouponVo.put("rules", rules);
grouponVo.put("creator", creator.getNickname());
grouponVo.put("isCreator", creator.getId() == userId && groupon.getGrouponId() == 0);
int linkGrouponId;
// 这是一个团购发起记录
if (groupon.getGrouponId() == 0) {
linkGrouponId = groupon.getId();
grouponVo.put("isCreator", creator.getId() == userId);
} else {
linkGrouponId = groupon.getGrouponId();
grouponVo.put("isCreator", false);
}
int joinerCount = grouponService.countGroupon(linkGrouponId);
grouponVo.put("joinerCount", joinerCount + 1);
//填充订单信息
grouponVo.put("orderId", order.getId());
......@@ -134,15 +226,4 @@ public class WxGrouponController {
return ResponseUtil.ok(rules);
}
@RequestMapping("list")
public Object list(@LoginUser Integer userId) {
if (userId == null) {
return ResponseUtil.unlogin();
}
List<LitemallGroupon> myGroupOn = grouponService.queryByUserId(userId);
return ResponseUtil.ok(myGroupOn);
}
}
......@@ -157,6 +157,13 @@ public class WxOrderController {
orderVo.put("orderStatusText", OrderUtil.orderStatusText(order));
orderVo.put("handleOption", OrderUtil.build(order));
LitemallGroupon groupon = grouponService.queryByOrderId(order.getId());
if (groupon != null) {
orderVo.put("isGroupin", true);
} else {
orderVo.put("isGroupin", false);
}
List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(order.getId());
List<Map<String, Object>> orderGoodsVoList = new ArrayList<>(orderGoodsList.size());
for (LitemallOrderGoods orderGoods : orderGoodsList) {
......@@ -171,6 +178,7 @@ public class WxOrderController {
orderVoList.add(orderVo);
}
Map<String, Object> result = new HashMap<>();
result.put("count", count);
result.put("data", orderVoList);
......@@ -410,7 +418,6 @@ public class WxOrderController {
}
groupon.setAddTime(LocalDateTime.now());
groupon.setExpireTime(LocalDateTime.now().plusDays(2));
grouponService.createGroupon(groupon);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment