Commit d6f243d8 authored by Junling Bu's avatar Junling Bu
Browse files

perf: 团购代码优化

parent eff4862d
...@@ -2787,7 +2787,7 @@ API应该存在版本控制,以保证兼容性。 ...@@ -2787,7 +2787,7 @@ API应该存在版本控制,以保证兼容性。
请求参数 请求参数
cartId: 购物车ID,如果0则是购物车商品,如果非0则是立即单一商品 cartId: 购物车ID,如果0则是购物车商品,如果非0则是立即单一商品
grouponRulesId: 团购活动ID,如果是团购商品则需要设置具体团购活动ID grouponRulesId: 团购规则ID,如果是团购商品则需要设置具体团购规则ID
响应内容 响应内容
......
...@@ -84,55 +84,4 @@ public class OrderJob { ...@@ -84,55 +84,4 @@ public class OrderJob {
} }
} }
} }
/**
* 团购订单拼团超期自动取消
*/
@Scheduled(initialDelay = 5000, fixedDelay = 10 * 60 * 1000)
@Transactional(rollbackFor = Exception.class)
public void checkGrouponOrderTimeout() {
logger.info("系统开启定时任务检查团购订单是否已经拼团超期自动取消订单");
List<LitemallGroupon> grouponList = grouponService.queryJoinRecord(0);
for (LitemallGroupon groupon : grouponList) {
LitemallGrouponRules rules = rulesService.queryById(groupon.getRulesId());
if (rulesService.isExpired(rules)) {
List<LitemallGroupon> subGrouponList = grouponService.queryJoinRecord(groupon.getId());
for (LitemallGroupon subGroupon : subGrouponList) {
cancelGrouponScope(subGroupon);
}
cancelGrouponScope(groupon);
}
}
}
private void cancelGrouponScope(LitemallGroupon groupon) {
LitemallOrder order = orderService.findById(groupon.getOrderId());
if (order.getOrderStatus().equals(OrderUtil.STATUS_PAY_GROUPON)) {
order.setOrderStatus(OrderUtil.STATUS_TIMEOUT_GROUPON);
order.setEndTime(LocalDateTime.now());
cancelOrderScope(order);
logger.info("团购订单 ID" + order.getId() + " 已经拼团超期自动取消订单");
}
}
private void cancelOrderScope(LitemallOrder order) {
if (orderService.updateWithOptimisticLocker(order) == 0) {
throw new RuntimeException("更新数据已失效");
}
// 商品货品数量增加
Integer orderId = order.getId();
List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(orderId);
for (LitemallOrderGoods orderGoods : orderGoodsList) {
Integer productId = orderGoods.getProductId();
Short number = orderGoods.getNumber();
if (productService.addStock(productId, number) == 0) {
throw new RuntimeException("商品货品库存增加失败");
}
}
}
} }
...@@ -138,6 +138,7 @@ public class AdminOrderService { ...@@ -138,6 +138,7 @@ public class AdminOrderService {
// 设置订单取消状态 // 设置订单取消状态
order.setOrderStatus(OrderUtil.STATUS_REFUND_CONFIRM); order.setOrderStatus(OrderUtil.STATUS_REFUND_CONFIRM);
order.setEndTime(LocalDateTime.now());
if (orderService.updateWithOptimisticLocker(order) == 0) { if (orderService.updateWithOptimisticLocker(order) == 0) {
throw new RuntimeException("更新数据已失效"); throw new RuntimeException("更新数据已失效");
} }
......
package org.linlinjava.litemall.admin.task;
import org.linlinjava.litemall.core.task.TaskService;
import org.linlinjava.litemall.db.domain.LitemallGrouponRules;
import org.linlinjava.litemall.db.service.LitemallGrouponRulesService;
import org.linlinjava.litemall.db.util.GrouponConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
@Component
public class AdminTaskStartupRunner implements ApplicationRunner {
@Autowired
private LitemallGrouponRulesService rulesService;
@Autowired
private TaskService taskService;
@Override
public void run(ApplicationArguments args) throws Exception {
List<LitemallGrouponRules> grouponRulesList = rulesService.queryByStatus(GrouponConstant.RULE_STATUS_ON);
for(LitemallGrouponRules grouponRules : grouponRulesList){
LocalDateTime now = LocalDateTime.now();
LocalDateTime expire = grouponRules.getExpireTime();
if(expire.isBefore(now)) {
// 已经过期,则加入延迟队列
taskService.addTask(new GrouponRuleExpiredTask(grouponRules.getId(), 0));
}
else{
// 还没过期,则加入延迟队列
long delay = ChronoUnit.MILLIS.between(now, expire);
taskService.addTask(new GrouponRuleExpiredTask(grouponRules.getId(), delay));
}
}
}
}
\ No newline at end of file
package org.linlinjava.litemall.admin.task;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.task.Task;
import org.linlinjava.litemall.core.util.BeanUtil;
import org.linlinjava.litemall.db.domain.LitemallGroupon;
import org.linlinjava.litemall.db.domain.LitemallGrouponRules;
import org.linlinjava.litemall.db.domain.LitemallOrder;
import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.db.util.GrouponConstant;
import org.linlinjava.litemall.db.util.OrderUtil;
import java.util.List;
public class GrouponRuleExpiredTask extends Task {
private final Log logger = LogFactory.getLog(GrouponRuleExpiredTask.class);
private int grouponRuleId = -1;
public GrouponRuleExpiredTask(Integer grouponRuleId, long delayInMilliseconds){
super("GrouponRuleExpiredTask-" + grouponRuleId, delayInMilliseconds);
this.grouponRuleId = grouponRuleId;
}
@Override
public void run() {
logger.info("系统开始处理延时任务---团购规则过期---" + this.grouponRuleId);
LitemallOrderService orderService = BeanUtil.getBean(LitemallOrderService.class);
LitemallGrouponService grouponService = BeanUtil.getBean(LitemallGrouponService.class);
LitemallGrouponRulesService grouponRulesService = BeanUtil.getBean(LitemallGrouponRulesService.class);
LitemallGrouponRules grouponRules = grouponRulesService.findById(grouponRuleId);
if(grouponRules == null){
return;
}
if(!grouponRules.getStatus().equals(GrouponConstant.RULE_STATUS_ON)){
return;
}
// 团购活动取消
grouponRules.setStatus(GrouponConstant.RULE_STATUS_DOWN_EXPIRE);
grouponRulesService.updateById(grouponRules);
List<LitemallGroupon> grouponList = grouponService.queryByRuleId(grouponRuleId);
// 用户团购处理
for(LitemallGroupon groupon : grouponList){
Short status = groupon.getStatus();
LitemallOrder order = orderService.findById(groupon.getOrderId());
if(status.equals(GrouponConstant.STATUS_NONE)){
groupon.setStatus(GrouponConstant.STATUS_FAIL);
grouponService.updateById(groupon);
}
else if(status.equals(GrouponConstant.STATUS_ON)){
// 如果团购进行中
// (1) 团购设置团购失败等待退款状态
groupon.setStatus(GrouponConstant.STATUS_FAIL);
grouponService.updateById(groupon);
// (2) 团购订单申请退款
if(OrderUtil.isPayStatus(order)) {
order.setOrderStatus(OrderUtil.STATUS_REFUND);
orderService.updateWithOptimisticLocker(order);
}
}
}
logger.info("系统结束处理延时任务---团购规则过期---" + this.grouponRuleId);
}
}
...@@ -20,5 +20,8 @@ public class AdminResponseCode { ...@@ -20,5 +20,8 @@ public class AdminResponseCode {
public static final Integer ROLE_NAME_EXIST = 640; public static final Integer ROLE_NAME_EXIST = 640;
public static final Integer ROLE_SUPER_SUPERMISSION = 641; public static final Integer ROLE_SUPER_SUPERMISSION = 641;
public static final Integer ROLE_USER_EXIST = 642; public static final Integer ROLE_USER_EXIST = 642;
public static final Integer GROUPON_GOODS_UNKNOWN = 650;
public static final Integer GROUPON_GOODS_EXISTED = 651;
public static final Integer GROUPON_GOODS_OFFLINE = 652;
} }
...@@ -4,6 +4,9 @@ import org.apache.commons.logging.Log; ...@@ -4,6 +4,9 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.linlinjava.litemall.admin.annotation.RequiresPermissionsDesc; import org.linlinjava.litemall.admin.annotation.RequiresPermissionsDesc;
import org.linlinjava.litemall.admin.task.GrouponRuleExpiredTask;
import org.linlinjava.litemall.admin.util.AdminResponseCode;
import org.linlinjava.litemall.core.task.TaskService;
import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Order; import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort; import org.linlinjava.litemall.core.validator.Sort;
...@@ -13,12 +16,15 @@ import org.linlinjava.litemall.db.domain.LitemallGrouponRules; ...@@ -13,12 +16,15 @@ import org.linlinjava.litemall.db.domain.LitemallGrouponRules;
import org.linlinjava.litemall.db.service.LitemallGoodsService; import org.linlinjava.litemall.db.service.LitemallGoodsService;
import org.linlinjava.litemall.db.service.LitemallGrouponRulesService; import org.linlinjava.litemall.db.service.LitemallGrouponRulesService;
import org.linlinjava.litemall.db.service.LitemallGrouponService; import org.linlinjava.litemall.db.service.LitemallGrouponService;
import org.linlinjava.litemall.db.util.GrouponConstant;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -36,6 +42,8 @@ public class AdminGrouponController { ...@@ -36,6 +42,8 @@ public class AdminGrouponController {
private LitemallGoodsService goodsService; private LitemallGoodsService goodsService;
@Autowired @Autowired
private LitemallGrouponService grouponService; private LitemallGrouponService grouponService;
@Autowired
private TaskService taskService;
@RequiresPermissions("admin:groupon:read") @RequiresPermissions("admin:groupon:read")
@RequiresPermissionsDesc(menu = {"推广管理", "团购管理"}, button = "详情") @RequiresPermissionsDesc(menu = {"推广管理", "团购管理"}, button = "详情")
...@@ -52,7 +60,7 @@ public class AdminGrouponController { ...@@ -52,7 +60,7 @@ public class AdminGrouponController {
try { try {
Map<String, Object> recordData = new HashMap<>(); Map<String, Object> recordData = new HashMap<>();
List<LitemallGroupon> subGrouponList = grouponService.queryJoinRecord(groupon.getId()); List<LitemallGroupon> subGrouponList = grouponService.queryJoinRecord(groupon.getId());
LitemallGrouponRules rules = rulesService.queryById(groupon.getRulesId()); LitemallGrouponRules rules = rulesService.findById(groupon.getRulesId());
LitemallGoods goods = goodsService.findById(rules.getGoodsId()); LitemallGoods goods = goodsService.findById(rules.getGoodsId());
recordData.put("groupon", groupon); recordData.put("groupon", groupon);
...@@ -111,6 +119,14 @@ public class AdminGrouponController { ...@@ -111,6 +119,14 @@ public class AdminGrouponController {
return error; return error;
} }
LitemallGrouponRules rules = rulesService.findById(grouponRules.getId());
if(rules == null){
return ResponseUtil.badArgumentValue();
}
if(!rules.getStatus().equals(GrouponConstant.RULE_STATUS_ON)){
return ResponseUtil.fail(AdminResponseCode.GROUPON_GOODS_OFFLINE, "团购已经下线");
}
Integer goodsId = grouponRules.getGoodsId(); Integer goodsId = grouponRules.getGoodsId();
LitemallGoods goods = goodsService.findById(goodsId); LitemallGoods goods = goodsService.findById(goodsId);
if (goods == null) { if (goods == null) {
...@@ -139,14 +155,23 @@ public class AdminGrouponController { ...@@ -139,14 +155,23 @@ public class AdminGrouponController {
Integer goodsId = grouponRules.getGoodsId(); Integer goodsId = grouponRules.getGoodsId();
LitemallGoods goods = goodsService.findById(goodsId); LitemallGoods goods = goodsService.findById(goodsId);
if (goods == null) { if (goods == null) {
return ResponseUtil.badArgumentValue(); return ResponseUtil.fail(AdminResponseCode.GROUPON_GOODS_UNKNOWN, "团购商品不存在");
}
if(rulesService.countByGoodsId(goodsId) > 0){
return ResponseUtil.fail(AdminResponseCode.GROUPON_GOODS_EXISTED, "团购商品已经存在");
} }
grouponRules.setGoodsName(goods.getName()); grouponRules.setGoodsName(goods.getName());
grouponRules.setPicUrl(goods.getPicUrl()); grouponRules.setPicUrl(goods.getPicUrl());
grouponRules.setStatus(GrouponConstant.RULE_STATUS_ON);
rulesService.createRules(grouponRules); rulesService.createRules(grouponRules);
LocalDateTime now = LocalDateTime.now();
LocalDateTime expire = grouponRules.getExpireTime();
long delay = ChronoUnit.MILLIS.between(now, expire);
// 团购过期任务
taskService.addTask(new GrouponRuleExpiredTask(grouponRules.getId(), delay));
return ResponseUtil.ok(grouponRules); return ResponseUtil.ok(grouponRules);
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<!-- 查询和其他操作 --> <!-- 查询和其他操作 -->
<div class="filter-container"> <div class="filter-container">
<el-input v-model="listQuery.goodsId" clearable class="filter-item" style="width: 200px;" placeholder="请输入商品编号"/> <el-input v-model="listQuery.goodsId" clearable class="filter-item" style="width: 200px;" placeholder="请输入商品编号" />
<el-button v-permission="['GET /admin/groupon/list']" class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">查找</el-button> <el-button v-permission="['GET /admin/groupon/list']" class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">查找</el-button>
<el-button v-permission="['POST /admin/groupon/create']" class="filter-item" type="primary" icon="el-icon-edit" @click="handleCreate">添加</el-button> <el-button v-permission="['POST /admin/groupon/create']" class="filter-item" type="primary" icon="el-icon-edit" @click="handleCreate">添加</el-button>
<el-button <el-button
...@@ -11,15 +11,18 @@ ...@@ -11,15 +11,18 @@
class="filter-item" class="filter-item"
type="primary" type="primary"
icon="el-icon-download" icon="el-icon-download"
@click="handleDownload">导出 @click="handleDownload"
>导出
</el-button> </el-button>
</div> </div>
<!-- 查询结果 --> <!-- 查询结果 -->
<el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row> <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row>
<el-table-column align="center" label="商品ID" prop="goodsId"/> <el-table-column align="center" label="团购规则ID" prop="id" />
<el-table-column align="center" min-width="100" label="名称" prop="goodsName"/> <el-table-column align="center" label="商品ID" prop="goodsId" />
<el-table-column align="center" min-width="100" label="名称" prop="goodsName" />
<el-table-column align="center" property="picUrl" label="图片"> <el-table-column align="center" property="picUrl" label="图片">
<template slot-scope="scope"> <template slot-scope="scope">
...@@ -27,13 +30,17 @@ ...@@ -27,13 +30,17 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="团购优惠" prop="discount"/> <el-table-column align="center" label="团购优惠" prop="discount" />
<el-table-column align="center" label="团购要求" prop="discountMember"/> <el-table-column align="center" label="团购要求" prop="discountMember" />
<el-table-column align="center" label="开始时间" prop="addTime"/> <el-table-column align="center" label="状态" prop="status">
<template slot-scope="scope">
<el-tag :type="scope.row.status === 0 ? 'success' : 'error' ">{{ statusMap[scope.row.status] }}</el-tag>
</template>
</el-table-column>
<el-table-column align="center" label="结束时间" prop="expireTime"/> <el-table-column align="center" label="结束时间" prop="expireTime" />
<el-table-column align="center" label="操作" width="200" class-name="small-padding fixed-width"> <el-table-column align="center" label="操作" width="200" class-name="small-padding fixed-width">
<template slot-scope="scope"> <template slot-scope="scope">
...@@ -51,23 +58,25 @@ ...@@ -51,23 +58,25 @@
:model="dataForm" :model="dataForm"
status-icon status-icon
label-position="left" label-position="left"
label-width="100px" label-width="120px"
style="width: 400px; margin-left:50px;"> style="width: 400px; margin-left:50px;"
>
<el-form-item label="商品ID" prop="goodsId"> <el-form-item label="商品ID" prop="goodsId">
<el-input v-model="dataForm.goodsId"/> <el-input v-model="dataForm.goodsId" />
</el-form-item> </el-form-item>
<el-form-item label="团购折扣" prop="discount"> <el-form-item label="团购折扣" prop="discount">
<el-input v-model="dataForm.discount"/> <el-input v-model="dataForm.discount" />
</el-form-item> </el-form-item>
<el-form-item label="团购人数要求" prop="discountMember"> <el-form-item label="团购人数要求" prop="discountMember">
<el-input v-model="dataForm.discountMember"/> <el-input v-model="dataForm.discountMember" />
</el-form-item> </el-form-item>
<el-form-item label="过期时间" prop="expireTime"> <el-form-item label="过期时间" prop="expireTime">
<el-date-picker <el-date-picker
v-model="dataForm.expireTime" v-model="dataForm.expireTime"
type="datetime" type="datetime"
placeholder="选择日期" placeholder="选择日期"
value-format="yyyy-MM-dd HH:mm:ss"/> value-format="yyyy-MM-dd HH:mm:ss"
/>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
...@@ -80,7 +89,7 @@ ...@@ -80,7 +89,7 @@
<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" /> <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
<el-tooltip placement="top" content="返回顶部"> <el-tooltip placement="top" content="返回顶部">
<back-to-top :visibility-height="100"/> <back-to-top :visibility-height="100" />
</el-tooltip> </el-tooltip>
</div> </div>
...@@ -120,8 +129,16 @@ export default { ...@@ -120,8 +129,16 @@ export default {
update: '编辑', update: '编辑',
create: '创建' create: '创建'
}, },
statusMap: [
'正常',
'到期下线',
'提前下线'
],
rules: { rules: {
goodsId: [{ required: true, message: '商品不能为空', trigger: 'blur' }] goodsId: [{ required: true, message: '商品不能为空', trigger: 'blur' }],
discount: [{ required: true, message: '团购折扣不能为空', trigger: 'blur' }],
discountMember: [{ required: true, message: '团购人数不能为空', trigger: 'blur' }],
expireTime: [{ required: true, message: '过期时间不能为空', trigger: 'blur' }]
} }
} }
}, },
......
...@@ -66,6 +66,15 @@ public class LitemallGroupon { ...@@ -66,6 +66,15 @@ public class LitemallGroupon {
*/ */
private Integer userId; private Integer userId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_groupon.share_url
*
* @mbg.generated
*/
private String shareUrl;
/** /**
* *
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
...@@ -78,38 +87,38 @@ public class LitemallGroupon { ...@@ -78,38 +87,38 @@ public class LitemallGroupon {
/** /**
* *
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_groupon.add_time * This field corresponds to the database column litemall_groupon.creator_user_time
* *
* @mbg.generated * @mbg.generated
*/ */
private LocalDateTime addTime; private LocalDateTime creatorUserTime;
/** /**
* *
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_groupon.update_time * This field corresponds to the database column litemall_groupon.status
* *
* @mbg.generated * @mbg.generated
*/ */
private LocalDateTime updateTime; private Short status;
/** /**
* *
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_groupon.share_url * This field corresponds to the database column litemall_groupon.add_time
* *
* @mbg.generated * @mbg.generated
*/ */
private String shareUrl; private LocalDateTime addTime;
/** /**
* *
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_groupon.payed * This field corresponds to the database column litemall_groupon.update_time
* *
* @mbg.generated * @mbg.generated
*/ */
private Boolean payed; private LocalDateTime updateTime;
/** /**
* *
...@@ -240,6 +249,30 @@ public class LitemallGroupon { ...@@ -240,6 +249,30 @@ public class LitemallGroupon {
this.userId = userId; this.userId = userId;
} }
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_groupon.share_url
*
* @return the value of litemall_groupon.share_url
*
* @mbg.generated
*/
public String getShareUrl() {
return shareUrl;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_groupon.share_url
*
* @param shareUrl the value for litemall_groupon.share_url
*
* @mbg.generated
*/
public void setShareUrl(String shareUrl) {
this.shareUrl = shareUrl;
}
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_groupon.creator_user_id * This method returns the value of the database column litemall_groupon.creator_user_id
...@@ -266,98 +299,98 @@ public class LitemallGroupon { ...@@ -266,98 +299,98 @@ public class LitemallGroupon {
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_groupon.add_time * This method returns the value of the database column litemall_groupon.creator_user_time
* *
* @return the value of litemall_groupon.add_time * @return the value of litemall_groupon.creator_user_time
* *
* @mbg.generated * @mbg.generated
*/ */
public LocalDateTime getAddTime() { public LocalDateTime getCreatorUserTime() {
return addTime; return creatorUserTime;
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_groupon.add_time * This method sets the value of the database column litemall_groupon.creator_user_time
* *
* @param addTime the value for litemall_groupon.add_time * @param creatorUserTime the value for litemall_groupon.creator_user_time
* *
* @mbg.generated * @mbg.generated
*/ */
public void setAddTime(LocalDateTime addTime) { public void setCreatorUserTime(LocalDateTime creatorUserTime) {
this.addTime = addTime; this.creatorUserTime = creatorUserTime;
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_groupon.update_time * This method returns the value of the database column litemall_groupon.status
* *
* @return the value of litemall_groupon.update_time * @return the value of litemall_groupon.status
* *
* @mbg.generated * @mbg.generated
*/ */
public LocalDateTime getUpdateTime() { public Short getStatus() {
return updateTime; return status;
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_groupon.update_time * This method sets the value of the database column litemall_groupon.status
* *
* @param updateTime the value for litemall_groupon.update_time * @param status the value for litemall_groupon.status
* *
* @mbg.generated * @mbg.generated
*/ */
public void setUpdateTime(LocalDateTime updateTime) { public void setStatus(Short status) {
this.updateTime = updateTime; this.status = status;
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_groupon.share_url * This method returns the value of the database column litemall_groupon.add_time
* *
* @return the value of litemall_groupon.share_url * @return the value of litemall_groupon.add_time
* *
* @mbg.generated * @mbg.generated
*/ */
public String getShareUrl() { public LocalDateTime getAddTime() {
return shareUrl; return addTime;
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_groupon.share_url * This method sets the value of the database column litemall_groupon.add_time
* *
* @param shareUrl the value for litemall_groupon.share_url * @param addTime the value for litemall_groupon.add_time
* *
* @mbg.generated * @mbg.generated
*/ */
public void setShareUrl(String shareUrl) { public void setAddTime(LocalDateTime addTime) {
this.shareUrl = shareUrl; this.addTime = addTime;
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_groupon.payed * This method returns the value of the database column litemall_groupon.update_time
* *
* @return the value of litemall_groupon.payed * @return the value of litemall_groupon.update_time
* *
* @mbg.generated * @mbg.generated
*/ */
public Boolean getPayed() { public LocalDateTime getUpdateTime() {
return payed; return updateTime;
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_groupon.payed * This method sets the value of the database column litemall_groupon.update_time
* *
* @param payed the value for litemall_groupon.payed * @param updateTime the value for litemall_groupon.update_time
* *
* @mbg.generated * @mbg.generated
*/ */
public void setPayed(Boolean payed) { public void setUpdateTime(LocalDateTime updateTime) {
this.payed = payed; this.updateTime = updateTime;
} }
/** /**
...@@ -413,11 +446,12 @@ public class LitemallGroupon { ...@@ -413,11 +446,12 @@ public class LitemallGroupon {
sb.append(", grouponId=").append(grouponId); sb.append(", grouponId=").append(grouponId);
sb.append(", rulesId=").append(rulesId); sb.append(", rulesId=").append(rulesId);
sb.append(", userId=").append(userId); sb.append(", userId=").append(userId);
sb.append(", shareUrl=").append(shareUrl);
sb.append(", creatorUserId=").append(creatorUserId); sb.append(", creatorUserId=").append(creatorUserId);
sb.append(", creatorUserTime=").append(creatorUserTime);
sb.append(", status=").append(status);
sb.append(", addTime=").append(addTime); sb.append(", addTime=").append(addTime);
sb.append(", updateTime=").append(updateTime); sb.append(", updateTime=").append(updateTime);
sb.append(", shareUrl=").append(shareUrl);
sb.append(", payed=").append(payed);
sb.append(", deleted=").append(deleted); sb.append(", deleted=").append(deleted);
sb.append("]"); sb.append("]");
return sb.toString(); return sb.toString();
...@@ -446,11 +480,12 @@ public class LitemallGroupon { ...@@ -446,11 +480,12 @@ public class LitemallGroupon {
&& (this.getGrouponId() == null ? other.getGrouponId() == null : this.getGrouponId().equals(other.getGrouponId())) && (this.getGrouponId() == null ? other.getGrouponId() == null : this.getGrouponId().equals(other.getGrouponId()))
&& (this.getRulesId() == null ? other.getRulesId() == null : this.getRulesId().equals(other.getRulesId())) && (this.getRulesId() == null ? other.getRulesId() == null : this.getRulesId().equals(other.getRulesId()))
&& (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
&& (this.getShareUrl() == null ? other.getShareUrl() == null : this.getShareUrl().equals(other.getShareUrl()))
&& (this.getCreatorUserId() == null ? other.getCreatorUserId() == null : this.getCreatorUserId().equals(other.getCreatorUserId())) && (this.getCreatorUserId() == null ? other.getCreatorUserId() == null : this.getCreatorUserId().equals(other.getCreatorUserId()))
&& (this.getCreatorUserTime() == null ? other.getCreatorUserTime() == null : this.getCreatorUserTime().equals(other.getCreatorUserTime()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime())) && (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())) && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
&& (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())); && (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()));
} }
...@@ -469,11 +504,12 @@ public class LitemallGroupon { ...@@ -469,11 +504,12 @@ public class LitemallGroupon {
result = prime * result + ((getGrouponId() == null) ? 0 : getGrouponId().hashCode()); result = prime * result + ((getGrouponId() == null) ? 0 : getGrouponId().hashCode());
result = prime * result + ((getRulesId() == null) ? 0 : getRulesId().hashCode()); result = prime * result + ((getRulesId() == null) ? 0 : getRulesId().hashCode());
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode()); result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
result = prime * result + ((getShareUrl() == null) ? 0 : getShareUrl().hashCode());
result = prime * result + ((getCreatorUserId() == null) ? 0 : getCreatorUserId().hashCode()); result = prime * result + ((getCreatorUserId() == null) ? 0 : getCreatorUserId().hashCode());
result = prime * result + ((getCreatorUserTime() == null) ? 0 : getCreatorUserTime().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode()); result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().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()); result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
return result; return result;
} }
...@@ -558,11 +594,12 @@ public class LitemallGroupon { ...@@ -558,11 +594,12 @@ public class LitemallGroupon {
grouponId("groupon_id", "grouponId", "INTEGER", false), grouponId("groupon_id", "grouponId", "INTEGER", false),
rulesId("rules_id", "rulesId", "INTEGER", false), rulesId("rules_id", "rulesId", "INTEGER", false),
userId("user_id", "userId", "INTEGER", false), userId("user_id", "userId", "INTEGER", false),
shareUrl("share_url", "shareUrl", "VARCHAR", false),
creatorUserId("creator_user_id", "creatorUserId", "INTEGER", false), creatorUserId("creator_user_id", "creatorUserId", "INTEGER", false),
creatorUserTime("creator_user_time", "creatorUserTime", "TIMESTAMP", false),
status("status", "status", "SMALLINT", true),
addTime("add_time", "addTime", "TIMESTAMP", false), addTime("add_time", "addTime", "TIMESTAMP", false),
updateTime("update_time", "updateTime", "TIMESTAMP", false), updateTime("update_time", "updateTime", "TIMESTAMP", false),
shareUrl("share_url", "shareUrl", "VARCHAR", false),
payed("payed", "payed", "BIT", false),
deleted("deleted", "deleted", "BIT", false); deleted("deleted", "deleted", "BIT", false);
/** /**
......
...@@ -79,29 +79,38 @@ public class LitemallGrouponRules { ...@@ -79,29 +79,38 @@ public class LitemallGrouponRules {
/** /**
* *
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_groupon_rules.add_time * This field corresponds to the database column litemall_groupon_rules.expire_time
* *
* @mbg.generated * @mbg.generated
*/ */
private LocalDateTime addTime; private LocalDateTime expireTime;
/** /**
* *
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_groupon_rules.update_time * This field corresponds to the database column litemall_groupon_rules.status
* *
* @mbg.generated * @mbg.generated
*/ */
private LocalDateTime updateTime; private Short status;
/** /**
* *
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_groupon_rules.expire_time * This field corresponds to the database column litemall_groupon_rules.add_time
* *
* @mbg.generated * @mbg.generated
*/ */
private LocalDateTime expireTime; private LocalDateTime addTime;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column litemall_groupon_rules.update_time
*
* @mbg.generated
*/
private LocalDateTime updateTime;
/** /**
* *
...@@ -258,74 +267,98 @@ public class LitemallGrouponRules { ...@@ -258,74 +267,98 @@ public class LitemallGrouponRules {
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_groupon_rules.add_time * This method returns the value of the database column litemall_groupon_rules.expire_time
* *
* @return the value of litemall_groupon_rules.add_time * @return the value of litemall_groupon_rules.expire_time
* *
* @mbg.generated * @mbg.generated
*/ */
public LocalDateTime getAddTime() { public LocalDateTime getExpireTime() {
return addTime; return expireTime;
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_groupon_rules.add_time * This method sets the value of the database column litemall_groupon_rules.expire_time
* *
* @param addTime the value for litemall_groupon_rules.add_time * @param expireTime the value for litemall_groupon_rules.expire_time
* *
* @mbg.generated * @mbg.generated
*/ */
public void setAddTime(LocalDateTime addTime) { public void setExpireTime(LocalDateTime expireTime) {
this.addTime = addTime; this.expireTime = expireTime;
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_groupon_rules.update_time * This method returns the value of the database column litemall_groupon_rules.status
* *
* @return the value of litemall_groupon_rules.update_time * @return the value of litemall_groupon_rules.status
* *
* @mbg.generated * @mbg.generated
*/ */
public LocalDateTime getUpdateTime() { public Short getStatus() {
return updateTime; return status;
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_groupon_rules.update_time * This method sets the value of the database column litemall_groupon_rules.status
* *
* @param updateTime the value for litemall_groupon_rules.update_time * @param status the value for litemall_groupon_rules.status
* *
* @mbg.generated * @mbg.generated
*/ */
public void setUpdateTime(LocalDateTime updateTime) { public void setStatus(Short status) {
this.updateTime = updateTime; this.status = status;
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_groupon_rules.expire_time * This method returns the value of the database column litemall_groupon_rules.add_time
* *
* @return the value of litemall_groupon_rules.expire_time * @return the value of litemall_groupon_rules.add_time
* *
* @mbg.generated * @mbg.generated
*/ */
public LocalDateTime getExpireTime() { public LocalDateTime getAddTime() {
return expireTime; return addTime;
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method sets the value of the database column litemall_groupon_rules.expire_time * This method sets the value of the database column litemall_groupon_rules.add_time
* *
* @param expireTime the value for litemall_groupon_rules.expire_time * @param addTime the value for litemall_groupon_rules.add_time
* *
* @mbg.generated * @mbg.generated
*/ */
public void setExpireTime(LocalDateTime expireTime) { public void setAddTime(LocalDateTime addTime) {
this.expireTime = expireTime; this.addTime = addTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_groupon_rules.update_time
*
* @return the value of litemall_groupon_rules.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_groupon_rules.update_time
*
* @param updateTime the value for litemall_groupon_rules.update_time
*
* @mbg.generated
*/
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
} }
/** /**
...@@ -382,9 +415,10 @@ public class LitemallGrouponRules { ...@@ -382,9 +415,10 @@ public class LitemallGrouponRules {
sb.append(", picUrl=").append(picUrl); sb.append(", picUrl=").append(picUrl);
sb.append(", discount=").append(discount); sb.append(", discount=").append(discount);
sb.append(", discountMember=").append(discountMember); sb.append(", discountMember=").append(discountMember);
sb.append(", expireTime=").append(expireTime);
sb.append(", status=").append(status);
sb.append(", addTime=").append(addTime); sb.append(", addTime=").append(addTime);
sb.append(", updateTime=").append(updateTime); sb.append(", updateTime=").append(updateTime);
sb.append(", expireTime=").append(expireTime);
sb.append(", deleted=").append(deleted); sb.append(", deleted=").append(deleted);
sb.append("]"); sb.append("]");
return sb.toString(); return sb.toString();
...@@ -414,9 +448,10 @@ public class LitemallGrouponRules { ...@@ -414,9 +448,10 @@ public class LitemallGrouponRules {
&& (this.getPicUrl() == null ? other.getPicUrl() == null : this.getPicUrl().equals(other.getPicUrl())) && (this.getPicUrl() == null ? other.getPicUrl() == null : this.getPicUrl().equals(other.getPicUrl()))
&& (this.getDiscount() == null ? other.getDiscount() == null : this.getDiscount().equals(other.getDiscount())) && (this.getDiscount() == null ? other.getDiscount() == null : this.getDiscount().equals(other.getDiscount()))
&& (this.getDiscountMember() == null ? other.getDiscountMember() == null : this.getDiscountMember().equals(other.getDiscountMember())) && (this.getDiscountMember() == null ? other.getDiscountMember() == null : this.getDiscountMember().equals(other.getDiscountMember()))
&& (this.getExpireTime() == null ? other.getExpireTime() == null : this.getExpireTime().equals(other.getExpireTime()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime())) && (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())) && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
&& (this.getExpireTime() == null ? other.getExpireTime() == null : this.getExpireTime().equals(other.getExpireTime()))
&& (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted())); && (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()));
} }
...@@ -436,9 +471,10 @@ public class LitemallGrouponRules { ...@@ -436,9 +471,10 @@ public class LitemallGrouponRules {
result = prime * result + ((getPicUrl() == null) ? 0 : getPicUrl().hashCode()); result = prime * result + ((getPicUrl() == null) ? 0 : getPicUrl().hashCode());
result = prime * result + ((getDiscount() == null) ? 0 : getDiscount().hashCode()); result = prime * result + ((getDiscount() == null) ? 0 : getDiscount().hashCode());
result = prime * result + ((getDiscountMember() == null) ? 0 : getDiscountMember().hashCode()); result = prime * result + ((getDiscountMember() == null) ? 0 : getDiscountMember().hashCode());
result = prime * result + ((getExpireTime() == null) ? 0 : getExpireTime().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode()); result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
result = prime * result + ((getExpireTime() == null) ? 0 : getExpireTime().hashCode());
result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode()); result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
return result; return result;
} }
...@@ -524,9 +560,10 @@ public class LitemallGrouponRules { ...@@ -524,9 +560,10 @@ public class LitemallGrouponRules {
picUrl("pic_url", "picUrl", "VARCHAR", false), picUrl("pic_url", "picUrl", "VARCHAR", false),
discount("discount", "discount", "DECIMAL", false), discount("discount", "discount", "DECIMAL", false),
discountMember("discount_member", "discountMember", "INTEGER", false), discountMember("discount_member", "discountMember", "INTEGER", false),
expireTime("expire_time", "expireTime", "TIMESTAMP", false),
status("status", "status", "SMALLINT", true),
addTime("add_time", "addTime", "TIMESTAMP", false), addTime("add_time", "addTime", "TIMESTAMP", false),
updateTime("update_time", "updateTime", "TIMESTAMP", false), updateTime("update_time", "updateTime", "TIMESTAMP", false),
expireTime("expire_time", "expireTime", "TIMESTAMP", false),
deleted("deleted", "deleted", "BIT", false); deleted("deleted", "deleted", "BIT", false);
/** /**
......
...@@ -7,6 +7,7 @@ import org.linlinjava.litemall.db.dao.LitemallGrouponRulesMapper; ...@@ -7,6 +7,7 @@ import org.linlinjava.litemall.db.dao.LitemallGrouponRulesMapper;
import org.linlinjava.litemall.db.domain.LitemallGoods; import org.linlinjava.litemall.db.domain.LitemallGoods;
import org.linlinjava.litemall.db.domain.LitemallGrouponRules; import org.linlinjava.litemall.db.domain.LitemallGrouponRules;
import org.linlinjava.litemall.db.domain.LitemallGrouponRulesExample; import org.linlinjava.litemall.db.domain.LitemallGrouponRulesExample;
import org.linlinjava.litemall.db.util.GrouponConstant;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -36,10 +37,8 @@ public class LitemallGrouponRulesService { ...@@ -36,10 +37,8 @@ public class LitemallGrouponRulesService {
* @param id * @param id
* @return * @return
*/ */
public LitemallGrouponRules queryById(Integer id) { public LitemallGrouponRules findById(Integer id) {
LitemallGrouponRulesExample example = new LitemallGrouponRulesExample(); return mapper.selectByPrimaryKey(id);
example.or().andIdEqualTo(id).andDeletedEqualTo(false);
return mapper.selectOneByExample(example);
} }
/** /**
...@@ -50,12 +49,24 @@ public class LitemallGrouponRulesService { ...@@ -50,12 +49,24 @@ public class LitemallGrouponRulesService {
*/ */
public List<LitemallGrouponRules> queryByGoodsId(Integer goodsId) { public List<LitemallGrouponRules> queryByGoodsId(Integer goodsId) {
LitemallGrouponRulesExample example = new LitemallGrouponRulesExample(); LitemallGrouponRulesExample example = new LitemallGrouponRulesExample();
example.or().andGoodsIdEqualTo(goodsId).andDeletedEqualTo(false); example.or().andGoodsIdEqualTo(goodsId).andStatusEqualTo(GrouponConstant.RULE_STATUS_ON).andDeletedEqualTo(false);
return mapper.selectByExample(example);
}
public int countByGoodsId(Integer goodsId) {
LitemallGrouponRulesExample example = new LitemallGrouponRulesExample();
example.or().andGoodsIdEqualTo(goodsId).andStatusEqualTo(GrouponConstant.RULE_STATUS_ON).andDeletedEqualTo(false);
return (int)mapper.countByExample(example);
}
public List<LitemallGrouponRules> queryByStatus(Short status) {
LitemallGrouponRulesExample example = new LitemallGrouponRulesExample();
example.or().andStatusEqualTo(status).andDeletedEqualTo(false);
return mapper.selectByExample(example); return mapper.selectByExample(example);
} }
/** /**
* 获取首页团购活动列表 * 获取首页团购规则列表
* *
* @param page * @param page
* @param limit * @param limit
...@@ -67,14 +78,14 @@ public class LitemallGrouponRulesService { ...@@ -67,14 +78,14 @@ public class LitemallGrouponRulesService {
public List<LitemallGrouponRules> queryList(Integer page, Integer limit, String sort, String order) { public List<LitemallGrouponRules> queryList(Integer page, Integer limit, String sort, String order) {
LitemallGrouponRulesExample example = new LitemallGrouponRulesExample(); LitemallGrouponRulesExample example = new LitemallGrouponRulesExample();
example.or().andDeletedEqualTo(false); example.or().andStatusEqualTo(GrouponConstant.RULE_STATUS_ON).andDeletedEqualTo(false);
example.setOrderByClause(sort + " " + order); example.setOrderByClause(sort + " " + order);
PageHelper.startPage(page, limit); PageHelper.startPage(page, limit);
return mapper.selectByExample(example); return mapper.selectByExample(example);
} }
/** /**
* 判断某个团购活动是否已经过期 * 判断某个团购规则是否已经过期
* *
* @return * @return
*/ */
...@@ -83,7 +94,7 @@ public class LitemallGrouponRulesService { ...@@ -83,7 +94,7 @@ public class LitemallGrouponRulesService {
} }
/** /**
* 获取团购活动列表 * 获取团购规则列表
* *
* @param goodsId * @param goodsId
* @param page * @param page
......
...@@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper; ...@@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallGrouponMapper; import org.linlinjava.litemall.db.dao.LitemallGrouponMapper;
import org.linlinjava.litemall.db.domain.LitemallGroupon; import org.linlinjava.litemall.db.domain.LitemallGroupon;
import org.linlinjava.litemall.db.domain.LitemallGrouponExample; import org.linlinjava.litemall.db.domain.LitemallGrouponExample;
import org.linlinjava.litemall.db.util.GrouponConstant;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -24,7 +25,7 @@ public class LitemallGrouponService { ...@@ -24,7 +25,7 @@ public class LitemallGrouponService {
*/ */
public List<LitemallGroupon> queryMyGroupon(Integer userId) { public List<LitemallGroupon> queryMyGroupon(Integer userId) {
LitemallGrouponExample example = new LitemallGrouponExample(); LitemallGrouponExample example = new LitemallGrouponExample();
example.or().andUserIdEqualTo(userId).andCreatorUserIdEqualTo(userId).andGrouponIdEqualTo(0).andDeletedEqualTo(false).andPayedEqualTo(true); example.or().andUserIdEqualTo(userId).andCreatorUserIdEqualTo(userId).andGrouponIdEqualTo(0).andStatusNotEqualTo(GrouponConstant.STATUS_NONE).andDeletedEqualTo(false);
example.orderBy("add_time desc"); example.orderBy("add_time desc");
return mapper.selectByExample(example); return mapper.selectByExample(example);
} }
...@@ -37,7 +38,7 @@ public class LitemallGrouponService { ...@@ -37,7 +38,7 @@ public class LitemallGrouponService {
*/ */
public List<LitemallGroupon> queryMyJoinGroupon(Integer userId) { public List<LitemallGroupon> queryMyJoinGroupon(Integer userId) {
LitemallGrouponExample example = new LitemallGrouponExample(); LitemallGrouponExample example = new LitemallGrouponExample();
example.or().andUserIdEqualTo(userId).andGrouponIdNotEqualTo(0).andDeletedEqualTo(false).andPayedEqualTo(true); example.or().andUserIdEqualTo(userId).andGrouponIdNotEqualTo(0).andStatusNotEqualTo(GrouponConstant.STATUS_NONE).andDeletedEqualTo(false);
example.orderBy("add_time desc"); example.orderBy("add_time desc");
return mapper.selectByExample(example); return mapper.selectByExample(example);
} }
...@@ -62,7 +63,7 @@ public class LitemallGrouponService { ...@@ -62,7 +63,7 @@ public class LitemallGrouponService {
*/ */
public List<LitemallGroupon> queryJoinRecord(Integer id) { public List<LitemallGroupon> queryJoinRecord(Integer id) {
LitemallGrouponExample example = new LitemallGrouponExample(); LitemallGrouponExample example = new LitemallGrouponExample();
example.or().andGrouponIdEqualTo(id).andDeletedEqualTo(false).andPayedEqualTo(true); example.or().andGrouponIdEqualTo(id).andStatusNotEqualTo(GrouponConstant.STATUS_NONE).andDeletedEqualTo(false);
example.orderBy("add_time desc"); example.orderBy("add_time desc");
return mapper.selectByExample(example); return mapper.selectByExample(example);
} }
...@@ -75,7 +76,7 @@ public class LitemallGrouponService { ...@@ -75,7 +76,7 @@ public class LitemallGrouponService {
*/ */
public LitemallGroupon queryById(Integer id) { public LitemallGroupon queryById(Integer id) {
LitemallGrouponExample example = new LitemallGrouponExample(); LitemallGrouponExample example = new LitemallGrouponExample();
example.or().andIdEqualTo(id).andDeletedEqualTo(false).andPayedEqualTo(true); example.or().andIdEqualTo(id).andDeletedEqualTo(false);
return mapper.selectOneByExample(example); return mapper.selectOneByExample(example);
} }
...@@ -87,10 +88,16 @@ public class LitemallGrouponService { ...@@ -87,10 +88,16 @@ public class LitemallGrouponService {
*/ */
public int countGroupon(Integer grouponId) { public int countGroupon(Integer grouponId) {
LitemallGrouponExample example = new LitemallGrouponExample(); LitemallGrouponExample example = new LitemallGrouponExample();
example.or().andGrouponIdEqualTo(grouponId).andDeletedEqualTo(false).andPayedEqualTo(true); example.or().andGrouponIdEqualTo(grouponId).andStatusNotEqualTo(GrouponConstant.STATUS_NONE).andDeletedEqualTo(false);
return (int) mapper.countByExample(example); return (int) mapper.countByExample(example);
} }
public boolean hasJoin(Integer userId, Integer grouponId) {
LitemallGrouponExample example = new LitemallGrouponExample();
example.or().andUserIdEqualTo(userId).andGrouponIdEqualTo(grouponId).andStatusNotEqualTo(GrouponConstant.STATUS_NONE).andDeletedEqualTo(false);
return mapper.countByExample(example) != 0;
}
public int updateById(LitemallGroupon groupon) { public int updateById(LitemallGroupon groupon) {
groupon.setUpdateTime(LocalDateTime.now()); groupon.setUpdateTime(LocalDateTime.now());
return mapper.updateByPrimaryKeySelective(groupon); return mapper.updateByPrimaryKeySelective(groupon);
...@@ -127,10 +134,16 @@ public class LitemallGrouponService { ...@@ -127,10 +134,16 @@ public class LitemallGrouponService {
criteria.andRulesIdEqualTo(Integer.parseInt(rulesId)); criteria.andRulesIdEqualTo(Integer.parseInt(rulesId));
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
criteria.andPayedEqualTo(true); criteria.andStatusNotEqualTo(GrouponConstant.STATUS_NONE);
criteria.andGrouponIdEqualTo(0); criteria.andGrouponIdEqualTo(0);
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
return mapper.selectByExample(example); return mapper.selectByExample(example);
} }
public List<LitemallGroupon> queryByRuleId(int grouponRuleId) {
LitemallGrouponExample example = new LitemallGrouponExample();
example.or().andRulesIdEqualTo(grouponRuleId).andDeletedEqualTo(false);
return mapper.selectByExample(example);
}
} }
package org.linlinjava.litemall.db.util;
import org.linlinjava.litemall.db.domain.LitemallOrder;
public class GrouponConstant {
public static final Short RULE_STATUS_ON = 0;
public static final Short RULE_STATUS_DOWN_EXPIRE = 1;
public static final Short RULE_STATUS_DOWN_ADMIN = 2;
public static final Short STATUS_NONE = 0;
public static final Short STATUS_ON = 1;
public static final Short STATUS_SUCCEED = 2;
public static final Short STATUS_FAIL = 3;
}
...@@ -27,6 +27,7 @@ public class OrderUtil { ...@@ -27,6 +27,7 @@ public class OrderUtil {
public static final Short STATUS_CONFIRM = 401; public static final Short STATUS_CONFIRM = 401;
public static final Short STATUS_CANCEL = 102; public static final Short STATUS_CANCEL = 102;
public static final Short STATUS_AUTO_CANCEL = 103; public static final Short STATUS_AUTO_CANCEL = 103;
public static final Short STATUS_ADMIN_CANCEL = 104;
public static final Short STATUS_REFUND = 202; public static final Short STATUS_REFUND = 202;
public static final Short STATUS_REFUND_CONFIRM = 203; public static final Short STATUS_REFUND_CONFIRM = 203;
public static final Short STATUS_AUTO_CONFIRM = 402; public static final Short STATUS_AUTO_CONFIRM = 402;
......
...@@ -11,11 +11,12 @@ ...@@ -11,11 +11,12 @@
<result column="groupon_id" jdbcType="INTEGER" property="grouponId" /> <result column="groupon_id" jdbcType="INTEGER" property="grouponId" />
<result column="rules_id" jdbcType="INTEGER" property="rulesId" /> <result column="rules_id" jdbcType="INTEGER" property="rulesId" />
<result column="user_id" jdbcType="INTEGER" property="userId" /> <result column="user_id" jdbcType="INTEGER" property="userId" />
<result column="share_url" jdbcType="VARCHAR" property="shareUrl" />
<result column="creator_user_id" jdbcType="INTEGER" property="creatorUserId" /> <result column="creator_user_id" jdbcType="INTEGER" property="creatorUserId" />
<result column="creator_user_time" jdbcType="TIMESTAMP" property="creatorUserTime" />
<result column="status" jdbcType="SMALLINT" property="status" />
<result column="add_time" jdbcType="TIMESTAMP" property="addTime" /> <result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="share_url" jdbcType="VARCHAR" property="shareUrl" />
<result column="payed" jdbcType="BIT" property="payed" />
<result column="deleted" jdbcType="BIT" property="deleted" /> <result column="deleted" jdbcType="BIT" property="deleted" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
...@@ -89,8 +90,8 @@ ...@@ -89,8 +90,8 @@
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. 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, update_time, id, order_id, groupon_id, rules_id, user_id, share_url, creator_user_id, creator_user_time,
share_url, payed, deleted `status`, add_time, update_time, deleted
</sql> </sql>
<select id="selectByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallGrouponExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallGrouponExample" resultMap="BaseResultMap">
<!-- <!--
...@@ -212,13 +213,13 @@ ...@@ -212,13 +213,13 @@
SELECT LAST_INSERT_ID() SELECT LAST_INSERT_ID()
</selectKey> </selectKey>
insert into litemall_groupon (order_id, groupon_id, rules_id, insert into litemall_groupon (order_id, groupon_id, rules_id,
user_id, creator_user_id, add_time, user_id, share_url, creator_user_id,
update_time, share_url, payed, creator_user_time, `status`, add_time,
deleted) update_time, deleted)
values (#{orderId,jdbcType=INTEGER}, #{grouponId,jdbcType=INTEGER}, #{rulesId,jdbcType=INTEGER}, values (#{orderId,jdbcType=INTEGER}, #{grouponId,jdbcType=INTEGER}, #{rulesId,jdbcType=INTEGER},
#{userId,jdbcType=INTEGER}, #{creatorUserId,jdbcType=INTEGER}, #{addTime,jdbcType=TIMESTAMP}, #{userId,jdbcType=INTEGER}, #{shareUrl,jdbcType=VARCHAR}, #{creatorUserId,jdbcType=INTEGER},
#{updateTime,jdbcType=TIMESTAMP}, #{shareUrl,jdbcType=VARCHAR}, #{payed,jdbcType=BIT}, #{creatorUserTime,jdbcType=TIMESTAMP}, #{status,jdbcType=SMALLINT}, #{addTime,jdbcType=TIMESTAMP},
#{deleted,jdbcType=BIT}) #{updateTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT})
</insert> </insert>
<insert id="insertSelective" parameterType="org.linlinjava.litemall.db.domain.LitemallGroupon"> <insert id="insertSelective" parameterType="org.linlinjava.litemall.db.domain.LitemallGroupon">
<!-- <!--
...@@ -242,21 +243,24 @@ ...@@ -242,21 +243,24 @@
<if test="userId != null"> <if test="userId != null">
user_id, user_id,
</if> </if>
<if test="shareUrl != null">
share_url,
</if>
<if test="creatorUserId != null"> <if test="creatorUserId != null">
creator_user_id, creator_user_id,
</if> </if>
<if test="creatorUserTime != null">
creator_user_time,
</if>
<if test="status != null">
`status`,
</if>
<if test="addTime != null"> <if test="addTime != null">
add_time, add_time,
</if> </if>
<if test="updateTime != null"> <if test="updateTime != null">
update_time, update_time,
</if> </if>
<if test="shareUrl != null">
share_url,
</if>
<if test="payed != null">
payed,
</if>
<if test="deleted != null"> <if test="deleted != null">
deleted, deleted,
</if> </if>
...@@ -274,21 +278,24 @@ ...@@ -274,21 +278,24 @@
<if test="userId != null"> <if test="userId != null">
#{userId,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER},
</if> </if>
<if test="shareUrl != null">
#{shareUrl,jdbcType=VARCHAR},
</if>
<if test="creatorUserId != null"> <if test="creatorUserId != null">
#{creatorUserId,jdbcType=INTEGER}, #{creatorUserId,jdbcType=INTEGER},
</if> </if>
<if test="creatorUserTime != null">
#{creatorUserTime,jdbcType=TIMESTAMP},
</if>
<if test="status != null">
#{status,jdbcType=SMALLINT},
</if>
<if test="addTime != null"> <if test="addTime != null">
#{addTime,jdbcType=TIMESTAMP}, #{addTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="updateTime != null"> <if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="shareUrl != null">
#{shareUrl,jdbcType=VARCHAR},
</if>
<if test="payed != null">
#{payed,jdbcType=BIT},
</if>
<if test="deleted != null"> <if test="deleted != null">
#{deleted,jdbcType=BIT}, #{deleted,jdbcType=BIT},
</if> </if>
...@@ -326,21 +333,24 @@ ...@@ -326,21 +333,24 @@
<if test="record.userId != null"> <if test="record.userId != null">
user_id = #{record.userId,jdbcType=INTEGER}, user_id = #{record.userId,jdbcType=INTEGER},
</if> </if>
<if test="record.shareUrl != null">
share_url = #{record.shareUrl,jdbcType=VARCHAR},
</if>
<if test="record.creatorUserId != null"> <if test="record.creatorUserId != null">
creator_user_id = #{record.creatorUserId,jdbcType=INTEGER}, creator_user_id = #{record.creatorUserId,jdbcType=INTEGER},
</if> </if>
<if test="record.creatorUserTime != null">
creator_user_time = #{record.creatorUserTime,jdbcType=TIMESTAMP},
</if>
<if test="record.status != null">
`status` = #{record.status,jdbcType=SMALLINT},
</if>
<if test="record.addTime != null"> <if test="record.addTime != null">
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="record.updateTime != null"> <if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=TIMESTAMP}, update_time = #{record.updateTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="record.shareUrl != null">
share_url = #{record.shareUrl,jdbcType=VARCHAR},
</if>
<if test="record.payed != null">
payed = #{record.payed,jdbcType=BIT},
</if>
<if test="record.deleted != null"> <if test="record.deleted != null">
deleted = #{record.deleted,jdbcType=BIT}, deleted = #{record.deleted,jdbcType=BIT},
</if> </if>
...@@ -360,11 +370,12 @@ ...@@ -360,11 +370,12 @@
groupon_id = #{record.grouponId,jdbcType=INTEGER}, groupon_id = #{record.grouponId,jdbcType=INTEGER},
rules_id = #{record.rulesId,jdbcType=INTEGER}, rules_id = #{record.rulesId,jdbcType=INTEGER},
user_id = #{record.userId,jdbcType=INTEGER}, user_id = #{record.userId,jdbcType=INTEGER},
share_url = #{record.shareUrl,jdbcType=VARCHAR},
creator_user_id = #{record.creatorUserId,jdbcType=INTEGER}, creator_user_id = #{record.creatorUserId,jdbcType=INTEGER},
creator_user_time = #{record.creatorUserTime,jdbcType=TIMESTAMP},
`status` = #{record.status,jdbcType=SMALLINT},
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP}, update_time = #{record.updateTime,jdbcType=TIMESTAMP},
share_url = #{record.shareUrl,jdbcType=VARCHAR},
payed = #{record.payed,jdbcType=BIT},
deleted = #{record.deleted,jdbcType=BIT} deleted = #{record.deleted,jdbcType=BIT}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
...@@ -389,21 +400,24 @@ ...@@ -389,21 +400,24 @@
<if test="userId != null"> <if test="userId != null">
user_id = #{userId,jdbcType=INTEGER}, user_id = #{userId,jdbcType=INTEGER},
</if> </if>
<if test="shareUrl != null">
share_url = #{shareUrl,jdbcType=VARCHAR},
</if>
<if test="creatorUserId != null"> <if test="creatorUserId != null">
creator_user_id = #{creatorUserId,jdbcType=INTEGER}, creator_user_id = #{creatorUserId,jdbcType=INTEGER},
</if> </if>
<if test="creatorUserTime != null">
creator_user_time = #{creatorUserTime,jdbcType=TIMESTAMP},
</if>
<if test="status != null">
`status` = #{status,jdbcType=SMALLINT},
</if>
<if test="addTime != null"> <if test="addTime != null">
add_time = #{addTime,jdbcType=TIMESTAMP}, add_time = #{addTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="updateTime != null"> <if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="shareUrl != null">
share_url = #{shareUrl,jdbcType=VARCHAR},
</if>
<if test="payed != null">
payed = #{payed,jdbcType=BIT},
</if>
<if test="deleted != null"> <if test="deleted != null">
deleted = #{deleted,jdbcType=BIT}, deleted = #{deleted,jdbcType=BIT},
</if> </if>
...@@ -420,11 +434,12 @@ ...@@ -420,11 +434,12 @@
groupon_id = #{grouponId,jdbcType=INTEGER}, groupon_id = #{grouponId,jdbcType=INTEGER},
rules_id = #{rulesId,jdbcType=INTEGER}, rules_id = #{rulesId,jdbcType=INTEGER},
user_id = #{userId,jdbcType=INTEGER}, user_id = #{userId,jdbcType=INTEGER},
share_url = #{shareUrl,jdbcType=VARCHAR},
creator_user_id = #{creatorUserId,jdbcType=INTEGER}, creator_user_id = #{creatorUserId,jdbcType=INTEGER},
creator_user_time = #{creatorUserTime,jdbcType=TIMESTAMP},
`status` = #{status,jdbcType=SMALLINT},
add_time = #{addTime,jdbcType=TIMESTAMP}, add_time = #{addTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
share_url = #{shareUrl,jdbcType=VARCHAR},
payed = #{payed,jdbcType=BIT},
deleted = #{deleted,jdbcType=BIT} deleted = #{deleted,jdbcType=BIT}
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</update> </update>
......
...@@ -12,9 +12,10 @@ ...@@ -12,9 +12,10 @@
<result column="pic_url" jdbcType="VARCHAR" property="picUrl" /> <result column="pic_url" jdbcType="VARCHAR" property="picUrl" />
<result column="discount" jdbcType="DECIMAL" property="discount" /> <result column="discount" jdbcType="DECIMAL" property="discount" />
<result column="discount_member" jdbcType="INTEGER" property="discountMember" /> <result column="discount_member" jdbcType="INTEGER" property="discountMember" />
<result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" />
<result column="status" jdbcType="SMALLINT" property="status" />
<result column="add_time" jdbcType="TIMESTAMP" property="addTime" /> <result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" />
<result column="deleted" jdbcType="BIT" property="deleted" /> <result column="deleted" jdbcType="BIT" property="deleted" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
...@@ -88,8 +89,8 @@ ...@@ -88,8 +89,8 @@
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
--> -->
id, goods_id, goods_name, pic_url, discount, discount_member, add_time, update_time, id, goods_id, goods_name, pic_url, discount, discount_member, expire_time, `status`,
expire_time, deleted add_time, update_time, deleted
</sql> </sql>
<select id="selectByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallGrouponRulesExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallGrouponRulesExample" resultMap="BaseResultMap">
<!-- <!--
...@@ -211,13 +212,13 @@ ...@@ -211,13 +212,13 @@
SELECT LAST_INSERT_ID() SELECT LAST_INSERT_ID()
</selectKey> </selectKey>
insert into litemall_groupon_rules (goods_id, goods_name, pic_url, insert into litemall_groupon_rules (goods_id, goods_name, pic_url,
discount, discount_member, add_time, discount, discount_member, expire_time,
update_time, expire_time, deleted `status`, add_time, update_time,
) deleted)
values (#{goodsId,jdbcType=INTEGER}, #{goodsName,jdbcType=VARCHAR}, #{picUrl,jdbcType=VARCHAR}, values (#{goodsId,jdbcType=INTEGER}, #{goodsName,jdbcType=VARCHAR}, #{picUrl,jdbcType=VARCHAR},
#{discount,jdbcType=DECIMAL}, #{discountMember,jdbcType=INTEGER}, #{addTime,jdbcType=TIMESTAMP}, #{discount,jdbcType=DECIMAL}, #{discountMember,jdbcType=INTEGER}, #{expireTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP}, #{expireTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT} #{status,jdbcType=SMALLINT}, #{addTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
) #{deleted,jdbcType=BIT})
</insert> </insert>
<insert id="insertSelective" parameterType="org.linlinjava.litemall.db.domain.LitemallGrouponRules"> <insert id="insertSelective" parameterType="org.linlinjava.litemall.db.domain.LitemallGrouponRules">
<!-- <!--
...@@ -244,15 +245,18 @@ ...@@ -244,15 +245,18 @@
<if test="discountMember != null"> <if test="discountMember != null">
discount_member, discount_member,
</if> </if>
<if test="expireTime != null">
expire_time,
</if>
<if test="status != null">
`status`,
</if>
<if test="addTime != null"> <if test="addTime != null">
add_time, add_time,
</if> </if>
<if test="updateTime != null"> <if test="updateTime != null">
update_time, update_time,
</if> </if>
<if test="expireTime != null">
expire_time,
</if>
<if test="deleted != null"> <if test="deleted != null">
deleted, deleted,
</if> </if>
...@@ -273,15 +277,18 @@ ...@@ -273,15 +277,18 @@
<if test="discountMember != null"> <if test="discountMember != null">
#{discountMember,jdbcType=INTEGER}, #{discountMember,jdbcType=INTEGER},
</if> </if>
<if test="expireTime != null">
#{expireTime,jdbcType=TIMESTAMP},
</if>
<if test="status != null">
#{status,jdbcType=SMALLINT},
</if>
<if test="addTime != null"> <if test="addTime != null">
#{addTime,jdbcType=TIMESTAMP}, #{addTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="updateTime != null"> <if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="expireTime != null">
#{expireTime,jdbcType=TIMESTAMP},
</if>
<if test="deleted != null"> <if test="deleted != null">
#{deleted,jdbcType=BIT}, #{deleted,jdbcType=BIT},
</if> </if>
...@@ -322,15 +329,18 @@ ...@@ -322,15 +329,18 @@
<if test="record.discountMember != null"> <if test="record.discountMember != null">
discount_member = #{record.discountMember,jdbcType=INTEGER}, discount_member = #{record.discountMember,jdbcType=INTEGER},
</if> </if>
<if test="record.expireTime != null">
expire_time = #{record.expireTime,jdbcType=TIMESTAMP},
</if>
<if test="record.status != null">
`status` = #{record.status,jdbcType=SMALLINT},
</if>
<if test="record.addTime != null"> <if test="record.addTime != null">
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="record.updateTime != null"> <if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=TIMESTAMP}, update_time = #{record.updateTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="record.expireTime != null">
expire_time = #{record.expireTime,jdbcType=TIMESTAMP},
</if>
<if test="record.deleted != null"> <if test="record.deleted != null">
deleted = #{record.deleted,jdbcType=BIT}, deleted = #{record.deleted,jdbcType=BIT},
</if> </if>
...@@ -351,9 +361,10 @@ ...@@ -351,9 +361,10 @@
pic_url = #{record.picUrl,jdbcType=VARCHAR}, pic_url = #{record.picUrl,jdbcType=VARCHAR},
discount = #{record.discount,jdbcType=DECIMAL}, discount = #{record.discount,jdbcType=DECIMAL},
discount_member = #{record.discountMember,jdbcType=INTEGER}, discount_member = #{record.discountMember,jdbcType=INTEGER},
expire_time = #{record.expireTime,jdbcType=TIMESTAMP},
`status` = #{record.status,jdbcType=SMALLINT},
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP}, update_time = #{record.updateTime,jdbcType=TIMESTAMP},
expire_time = #{record.expireTime,jdbcType=TIMESTAMP},
deleted = #{record.deleted,jdbcType=BIT} deleted = #{record.deleted,jdbcType=BIT}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
...@@ -381,15 +392,18 @@ ...@@ -381,15 +392,18 @@
<if test="discountMember != null"> <if test="discountMember != null">
discount_member = #{discountMember,jdbcType=INTEGER}, discount_member = #{discountMember,jdbcType=INTEGER},
</if> </if>
<if test="expireTime != null">
expire_time = #{expireTime,jdbcType=TIMESTAMP},
</if>
<if test="status != null">
`status` = #{status,jdbcType=SMALLINT},
</if>
<if test="addTime != null"> <if test="addTime != null">
add_time = #{addTime,jdbcType=TIMESTAMP}, add_time = #{addTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="updateTime != null"> <if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="expireTime != null">
expire_time = #{expireTime,jdbcType=TIMESTAMP},
</if>
<if test="deleted != null"> <if test="deleted != null">
deleted = #{deleted,jdbcType=BIT}, deleted = #{deleted,jdbcType=BIT},
</if> </if>
...@@ -407,9 +421,10 @@ ...@@ -407,9 +421,10 @@
pic_url = #{picUrl,jdbcType=VARCHAR}, pic_url = #{picUrl,jdbcType=VARCHAR},
discount = #{discount,jdbcType=DECIMAL}, discount = #{discount,jdbcType=DECIMAL},
discount_member = #{discountMember,jdbcType=INTEGER}, discount_member = #{discountMember,jdbcType=INTEGER},
expire_time = #{expireTime,jdbcType=TIMESTAMP},
`status` = #{status,jdbcType=SMALLINT},
add_time = #{addTime,jdbcType=TIMESTAMP}, add_time = #{addTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
expire_time = #{expireTime,jdbcType=TIMESTAMP},
deleted = #{deleted,jdbcType=BIT} deleted = #{deleted,jdbcType=BIT}
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</update> </update>
......
...@@ -56,6 +56,7 @@ public class WxGrouponRuleService { ...@@ -56,6 +56,7 @@ public class WxGrouponRuleService {
grouponRuleVo.setGrouponPrice(goods.getRetailPrice().subtract(rule.getDiscount())); grouponRuleVo.setGrouponPrice(goods.getRetailPrice().subtract(rule.getDiscount()));
grouponRuleVo.setGrouponDiscount(rule.getDiscount()); grouponRuleVo.setGrouponDiscount(rule.getDiscount());
grouponRuleVo.setGrouponMember(rule.getDiscountMember()); grouponRuleVo.setGrouponMember(rule.getDiscountMember());
grouponRuleVo.setExpireTime(rule.getExpireTime());
grouponList.add(grouponRuleVo); grouponList.add(grouponRuleVo);
} }
......
...@@ -25,6 +25,7 @@ import org.linlinjava.litemall.core.util.ResponseUtil; ...@@ -25,6 +25,7 @@ import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.*; import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*; import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.db.util.CouponUserConstant; import org.linlinjava.litemall.db.util.CouponUserConstant;
import org.linlinjava.litemall.db.util.GrouponConstant;
import org.linlinjava.litemall.db.util.OrderHandleOption; import org.linlinjava.litemall.db.util.OrderHandleOption;
import org.linlinjava.litemall.db.util.OrderUtil; import org.linlinjava.litemall.db.util.OrderUtil;
import org.linlinjava.litemall.core.util.IpUtil; import org.linlinjava.litemall.core.util.IpUtil;
...@@ -262,14 +263,31 @@ public class WxOrderService { ...@@ -262,14 +263,31 @@ public class WxOrderService {
//如果是团购项目,验证活动是否有效 //如果是团购项目,验证活动是否有效
if (grouponRulesId != null && grouponRulesId > 0) { if (grouponRulesId != null && grouponRulesId > 0) {
LitemallGrouponRules rules = grouponRulesService.queryById(grouponRulesId); LitemallGrouponRules rules = grouponRulesService.findById(grouponRulesId);
//找不到记录 //找不到记录
if (rules == null) { if (rules == null) {
return ResponseUtil.badArgument(); return ResponseUtil.badArgument();
} }
//团购活动已经过期 //团购规则已经过期
if (grouponRulesService.isExpired(rules)) { if (rules.getStatus().equals(GrouponConstant.RULE_STATUS_DOWN_EXPIRE)) {
return ResponseUtil.fail(GROUPON_EXPIRED, "团购活动已过期!"); return ResponseUtil.fail(GROUPON_EXPIRED, "团购已过期!");
}
//团购规则已经下线
if (rules.getStatus().equals(GrouponConstant.RULE_STATUS_DOWN_ADMIN)) {
return ResponseUtil.fail(GROUPON_OFFLINE, "团购已下线!");
}
if (grouponLinkId != null && grouponLinkId > 0) {
//团购人数已满
if(grouponService.countGroupon(grouponLinkId) >= rules.getDiscountMember()){
return ResponseUtil.fail(GROUPON_FULL, "团购活动人数已满!");
}
// NOTE
// 这里业务方面允许用户多次开团,以及多次参团,
// 但是不允许参加已经参加过的团购
if(grouponService.hasJoin(userId, grouponLinkId)){
return ResponseUtil.fail(GROUPON_JOIN, "团购活动已经参加!");
}
} }
} }
...@@ -284,8 +302,8 @@ public class WxOrderService { ...@@ -284,8 +302,8 @@ public class WxOrderService {
} }
// 团购优惠 // 团购优惠
BigDecimal grouponPrice = new BigDecimal(0.00); BigDecimal grouponPrice = new BigDecimal(0);
LitemallGrouponRules grouponRules = grouponRulesService.queryById(grouponRulesId); LitemallGrouponRules grouponRules = grouponRulesService.findById(grouponRulesId);
if (grouponRules != null) { if (grouponRules != null) {
grouponPrice = grouponRules.getDiscount(); grouponPrice = grouponRules.getDiscount();
} }
...@@ -302,7 +320,7 @@ public class WxOrderService { ...@@ -302,7 +320,7 @@ public class WxOrderService {
if (checkedGoodsList.size() == 0) { if (checkedGoodsList.size() == 0) {
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
} }
BigDecimal checkedGoodsPrice = new BigDecimal(0.00); BigDecimal checkedGoodsPrice = new BigDecimal(0);
for (LitemallCart checkGoods : checkedGoodsList) { for (LitemallCart checkGoods : checkedGoodsList) {
// 只有当团购规格商品ID符合才进行团购优惠 // 只有当团购规格商品ID符合才进行团购优惠
if (grouponRules != null && grouponRules.getGoodsId().equals(checkGoods.getGoodsId())) { if (grouponRules != null && grouponRules.getGoodsId().equals(checkGoods.getGoodsId())) {
...@@ -314,7 +332,7 @@ public class WxOrderService { ...@@ -314,7 +332,7 @@ public class WxOrderService {
// 获取可用的优惠券信息 // 获取可用的优惠券信息
// 使用优惠券减免的金额 // 使用优惠券减免的金额
BigDecimal couponPrice = new BigDecimal(0.00); BigDecimal couponPrice = new BigDecimal(0);
// 如果couponId=0则没有优惠券,couponId=-1则不使用优惠券 // 如果couponId=0则没有优惠券,couponId=-1则不使用优惠券
if (couponId != 0 && couponId != -1) { if (couponId != 0 && couponId != -1) {
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, userCouponId, checkedGoodsPrice); LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, userCouponId, checkedGoodsPrice);
...@@ -326,16 +344,16 @@ public class WxOrderService { ...@@ -326,16 +344,16 @@ public class WxOrderService {
// 根据订单商品总价计算运费,满足条件(例如88元)则免运费,否则需要支付运费(例如8元); // 根据订单商品总价计算运费,满足条件(例如88元)则免运费,否则需要支付运费(例如8元);
BigDecimal freightPrice = new BigDecimal(0.00); BigDecimal freightPrice = new BigDecimal(0);
if (checkedGoodsPrice.compareTo(SystemConfig.getFreightLimit()) < 0) { if (checkedGoodsPrice.compareTo(SystemConfig.getFreightLimit()) < 0) {
freightPrice = SystemConfig.getFreight(); freightPrice = SystemConfig.getFreight();
} }
// 可以使用的其他钱,例如用户积分 // 可以使用的其他钱,例如用户积分
BigDecimal integralPrice = new BigDecimal(0.00); BigDecimal integralPrice = new BigDecimal(0);
// 订单费用 // 订单费用
BigDecimal orderTotalPrice = checkedGoodsPrice.add(freightPrice).subtract(couponPrice).max(new BigDecimal(0.00)); BigDecimal orderTotalPrice = checkedGoodsPrice.add(freightPrice).subtract(couponPrice).max(new BigDecimal(0));
// 最终支付费用 // 最终支付费用
BigDecimal actualPrice = orderTotalPrice.subtract(integralPrice); BigDecimal actualPrice = orderTotalPrice.subtract(integralPrice);
...@@ -358,11 +376,11 @@ public class WxOrderService { ...@@ -358,11 +376,11 @@ public class WxOrderService {
order.setOrderPrice(orderTotalPrice); order.setOrderPrice(orderTotalPrice);
order.setActualPrice(actualPrice); order.setActualPrice(actualPrice);
// 有团购活动 // 有团购
if (grouponRules != null) { if (grouponRules != null) {
order.setGrouponPrice(grouponPrice); // 团购价格 order.setGrouponPrice(grouponPrice); // 团购价格
} else { } else {
order.setGrouponPrice(new BigDecimal(0.00)); // 团购价格 order.setGrouponPrice(new BigDecimal(0)); // 团购价格
} }
// 添加订单表项 // 添加订单表项
...@@ -395,7 +413,7 @@ public class WxOrderService { ...@@ -395,7 +413,7 @@ public class WxOrderService {
Integer productId = checkGoods.getProductId(); Integer productId = checkGoods.getProductId();
LitemallGoodsProduct product = productService.findById(productId); LitemallGoodsProduct product = productService.findById(productId);
Integer remainNumber = product.getNumber() - checkGoods.getNumber(); int remainNumber = product.getNumber() - checkGoods.getNumber();
if (remainNumber < 0) { if (remainNumber < 0) {
throw new RuntimeException("下单的商品货品数量大于库存量"); throw new RuntimeException("下单的商品货品数量大于库存量");
} }
...@@ -417,7 +435,7 @@ public class WxOrderService { ...@@ -417,7 +435,7 @@ public class WxOrderService {
if (grouponRulesId != null && grouponRulesId > 0) { if (grouponRulesId != null && grouponRulesId > 0) {
LitemallGroupon groupon = new LitemallGroupon(); LitemallGroupon groupon = new LitemallGroupon();
groupon.setOrderId(orderId); groupon.setOrderId(orderId);
groupon.setPayed(false); groupon.setStatus(GrouponConstant.STATUS_NONE);
groupon.setUserId(userId); groupon.setUserId(userId);
groupon.setRulesId(grouponRulesId); groupon.setRulesId(grouponRulesId);
...@@ -428,12 +446,14 @@ public class WxOrderService { ...@@ -428,12 +446,14 @@ public class WxOrderService {
groupon.setCreatorUserId(baseGroupon.getCreatorUserId()); groupon.setCreatorUserId(baseGroupon.getCreatorUserId());
groupon.setGrouponId(grouponLinkId); groupon.setGrouponId(grouponLinkId);
groupon.setShareUrl(baseGroupon.getShareUrl()); groupon.setShareUrl(baseGroupon.getShareUrl());
grouponService.createGroupon(groupon);
} else { } else {
groupon.setCreatorUserId(userId); groupon.setCreatorUserId(userId);
groupon.setCreatorUserTime(LocalDateTime.now());
groupon.setGrouponId(0); groupon.setGrouponId(0);
grouponService.createGroupon(groupon);
grouponLinkId = groupon.getId();
} }
grouponService.createGroupon(groupon);
} }
// 订单支付超期任务 // 订单支付超期任务
...@@ -441,6 +461,12 @@ public class WxOrderService { ...@@ -441,6 +461,12 @@ public class WxOrderService {
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
data.put("orderId", orderId); data.put("orderId", orderId);
if (grouponRulesId != null && grouponRulesId > 0) {
data.put("grouponLinkId", grouponLinkId);
}
else {
data.put("grouponLinkId", 0);
}
return ResponseUtil.ok(data); return ResponseUtil.ok(data);
} }
...@@ -451,7 +477,6 @@ public class WxOrderService { ...@@ -451,7 +477,6 @@ public class WxOrderService {
* 2. 设置订单取消状态; * 2. 设置订单取消状态;
* 3. 商品货品库存恢复; * 3. 商品货品库存恢复;
* 4. TODO 优惠券; * 4. TODO 优惠券;
* 5. TODO 团购活动。
* *
* @param userId 用户ID * @param userId 用户ID
* @param body 订单信息,{ orderId:xxx } * @param body 订单信息,{ orderId:xxx }
...@@ -721,47 +746,29 @@ public class WxOrderService { ...@@ -721,47 +746,29 @@ public class WxOrderService {
// 支付成功,有团购信息,更新团购信息 // 支付成功,有团购信息,更新团购信息
LitemallGroupon groupon = grouponService.queryByOrderId(order.getId()); LitemallGroupon groupon = grouponService.queryByOrderId(order.getId());
if (groupon != null) { if (groupon != null) {
LitemallGrouponRules grouponRules = grouponRulesService.queryById(groupon.getRulesId()); LitemallGrouponRules grouponRules = grouponRulesService.findById(groupon.getRulesId());
//仅当发起者才创建分享图片 //仅当发起者才创建分享图片
if (groupon.getGrouponId() == 0) { if (groupon.getGrouponId() == 0) {
String url = qCodeService.createGrouponShareImage(grouponRules.getGoodsName(), grouponRules.getPicUrl(), groupon); String url = qCodeService.createGrouponShareImage(grouponRules.getGoodsName(), grouponRules.getPicUrl(), groupon);
groupon.setShareUrl(url); groupon.setShareUrl(url);
} }
groupon.setPayed(true); groupon.setStatus(GrouponConstant.STATUS_ON);
if (grouponService.updateById(groupon) == 0) { if (grouponService.updateById(groupon) == 0) {
return WxPayNotifyResponse.fail("更新数据已失效"); return WxPayNotifyResponse.fail("更新数据已失效");
} }
// 团购已达成,更新关联订单支付状态
if (groupon.getGrouponId() > 0) { List<LitemallGroupon> grouponList = grouponService.queryJoinRecord(groupon.getGrouponId());
List<LitemallGroupon> grouponList = grouponService.queryJoinRecord(groupon.getGrouponId()); if (groupon.getGrouponId() != 0 && (grouponList.size() >= grouponRules.getDiscountMember() - 1)) {
if (grouponList.size() >= grouponRules.getDiscountMember() - 1) { for (LitemallGroupon grouponActivity : grouponList) {
for (LitemallGroupon grouponActivity : grouponList) { grouponActivity.setStatus(GrouponConstant.STATUS_SUCCEED);
if (grouponActivity.getOrderId().equals(order.getId())) { grouponService.updateById(grouponActivity);
//当前订单
continue;
}
LitemallOrder grouponOrder = orderService.findById(grouponActivity.getOrderId());
if (grouponOrder.getOrderStatus().equals(OrderUtil.STATUS_PAY_GROUPON)) {
grouponOrder.setOrderStatus(OrderUtil.STATUS_PAY);
orderService.updateWithOptimisticLocker(grouponOrder);
}
}
LitemallGroupon grouponSource = grouponService.queryById(groupon.getGrouponId());
LitemallOrder grouponOrder = orderService.findById(grouponSource.getOrderId());
if (grouponOrder.getOrderStatus().equals(OrderUtil.STATUS_PAY_GROUPON)) {
grouponOrder.setOrderStatus(OrderUtil.STATUS_PAY);
orderService.updateWithOptimisticLocker(grouponOrder);
}
} }
} else { LitemallGroupon grouponSource = grouponService.queryById(groupon.getGrouponId());
order = orderService.findBySn(orderSn); grouponSource.setStatus(GrouponConstant.STATUS_SUCCEED);
order.setOrderStatus(OrderUtil.STATUS_PAY_GROUPON); grouponService.updateById(grouponSource);
orderService.updateWithOptimisticLocker(order);
} }
} }
......
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