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

perf: 团购代码优化

parent eff4862d
......@@ -2787,7 +2787,7 @@ API应该存在版本控制,以保证兼容性。
请求参数
cartId: 购物车ID,如果0则是购物车商品,如果非0则是立即单一商品
grouponRulesId: 团购活动ID,如果是团购商品则需要设置具体团购活动ID
grouponRulesId: 团购规则ID,如果是团购商品则需要设置具体团购规则ID
响应内容
......
......@@ -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 {
// 设置订单取消状态
order.setOrderStatus(OrderUtil.STATUS_REFUND_CONFIRM);
order.setEndTime(LocalDateTime.now());
if (orderService.updateWithOptimisticLocker(order) == 0) {
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 {
public static final Integer ROLE_NAME_EXIST = 640;
public static final Integer ROLE_SUPER_SUPERMISSION = 641;
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;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
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.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
......@@ -13,12 +16,15 @@ import org.linlinjava.litemall.db.domain.LitemallGrouponRules;
import org.linlinjava.litemall.db.service.LitemallGoodsService;
import org.linlinjava.litemall.db.service.LitemallGrouponRulesService;
import org.linlinjava.litemall.db.service.LitemallGrouponService;
import org.linlinjava.litemall.db.util.GrouponConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -36,6 +42,8 @@ public class AdminGrouponController {
private LitemallGoodsService goodsService;
@Autowired
private LitemallGrouponService grouponService;
@Autowired
private TaskService taskService;
@RequiresPermissions("admin:groupon:read")
@RequiresPermissionsDesc(menu = {"推广管理", "团购管理"}, button = "详情")
......@@ -52,7 +60,7 @@ public class AdminGrouponController {
try {
Map<String, Object> recordData = new HashMap<>();
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());
recordData.put("groupon", groupon);
......@@ -111,6 +119,14 @@ public class AdminGrouponController {
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();
LitemallGoods goods = goodsService.findById(goodsId);
if (goods == null) {
......@@ -139,14 +155,23 @@ public class AdminGrouponController {
Integer goodsId = grouponRules.getGoodsId();
LitemallGoods goods = goodsService.findById(goodsId);
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.setPicUrl(goods.getPicUrl());
grouponRules.setStatus(GrouponConstant.RULE_STATUS_ON);
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);
}
......
......@@ -3,7 +3,7 @@
<!-- 查询和其他操作 -->
<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="['POST /admin/groupon/create']" class="filter-item" type="primary" icon="el-icon-edit" @click="handleCreate">添加</el-button>
<el-button
......@@ -11,15 +11,18 @@
class="filter-item"
type="primary"
icon="el-icon-download"
@click="handleDownload">导出
@click="handleDownload"
>导出
</el-button>
</div>
<!-- 查询结果 -->
<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="图片">
<template slot-scope="scope">
......@@ -27,13 +30,17 @@
</template>
</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">
<template slot-scope="scope">
......@@ -51,23 +58,25 @@
:model="dataForm"
status-icon
label-position="left"
label-width="100px"
style="width: 400px; margin-left:50px;">
label-width="120px"
style="width: 400px; margin-left:50px;"
>
<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 label="团购折扣" prop="discount">
<el-input v-model="dataForm.discount"/>
<el-input v-model="dataForm.discount" />
</el-form-item>
<el-form-item label="团购人数要求" prop="discountMember">
<el-input v-model="dataForm.discountMember"/>
<el-input v-model="dataForm.discountMember" />
</el-form-item>
<el-form-item label="过期时间" prop="expireTime">
<el-date-picker
v-model="dataForm.expireTime"
type="datetime"
placeholder="选择日期"
value-format="yyyy-MM-dd HH:mm:ss"/>
value-format="yyyy-MM-dd HH:mm:ss"
/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
......@@ -80,7 +89,7 @@
<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
<el-tooltip placement="top" content="返回顶部">
<back-to-top :visibility-height="100"/>
<back-to-top :visibility-height="100" />
</el-tooltip>
</div>
......@@ -120,8 +129,16 @@ export default {
update: '编辑',
create: '创建'
},
statusMap: [
'正常',
'到期下线',
'提前下线'
],
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 {
*/
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.
......@@ -78,38 +87,38 @@ public class LitemallGroupon {
/**
*
* 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
*/
private LocalDateTime addTime;
private LocalDateTime creatorUserTime;
/**
*
* 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
*/
private LocalDateTime updateTime;
private Short status;
/**
*
* 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
*/
private String shareUrl;
private LocalDateTime addTime;
/**
*
* 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
*/
private Boolean payed;
private LocalDateTime updateTime;
/**
*
......@@ -240,6 +249,30 @@ public class LitemallGroupon {
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 returns the value of the database column litemall_groupon.creator_user_id
......@@ -266,98 +299,98 @@ public class LitemallGroupon {
/**
* 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
*/
public LocalDateTime getAddTime() {
return addTime;
public LocalDateTime getCreatorUserTime() {
return creatorUserTime;
}
/**
* 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
*/
public void setAddTime(LocalDateTime addTime) {
this.addTime = addTime;
public void setCreatorUserTime(LocalDateTime creatorUserTime) {
this.creatorUserTime = creatorUserTime;
}
/**
* 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
*/
public LocalDateTime getUpdateTime() {
return updateTime;
public Short getStatus() {
return status;
}
/**
* 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
*/
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
public void setStatus(Short status) {
this.status = status;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_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
*/
public String getShareUrl() {
return shareUrl;
public LocalDateTime getAddTime() {
return addTime;
}
/**
* 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
*/
public void setShareUrl(String shareUrl) {
this.shareUrl = shareUrl;
public void setAddTime(LocalDateTime addTime) {
this.addTime = addTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_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
*/
public Boolean getPayed() {
return payed;
public LocalDateTime getUpdateTime() {
return updateTime;
}
/**
* 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
*/
public void setPayed(Boolean payed) {
this.payed = payed;
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
/**
......@@ -413,11 +446,12 @@ public class LitemallGroupon {
sb.append(", grouponId=").append(grouponId);
sb.append(", rulesId=").append(rulesId);
sb.append(", userId=").append(userId);
sb.append(", shareUrl=").append(shareUrl);
sb.append(", creatorUserId=").append(creatorUserId);
sb.append(", creatorUserTime=").append(creatorUserTime);
sb.append(", status=").append(status);
sb.append(", addTime=").append(addTime);
sb.append(", updateTime=").append(updateTime);
sb.append(", shareUrl=").append(shareUrl);
sb.append(", payed=").append(payed);
sb.append(", deleted=").append(deleted);
sb.append("]");
return sb.toString();
......@@ -446,11 +480,12 @@ public class LitemallGroupon {
&& (this.getGrouponId() == null ? other.getGrouponId() == null : this.getGrouponId().equals(other.getGrouponId()))
&& (this.getRulesId() == null ? other.getRulesId() == null : this.getRulesId().equals(other.getRulesId()))
&& (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.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.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()));
}
......@@ -469,11 +504,12 @@ public class LitemallGroupon {
result = prime * result + ((getGrouponId() == null) ? 0 : getGrouponId().hashCode());
result = prime * result + ((getRulesId() == null) ? 0 : getRulesId().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 + ((getCreatorUserTime() == null) ? 0 : getCreatorUserTime().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().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());
return result;
}
......@@ -558,11 +594,12 @@ public class LitemallGroupon {
grouponId("groupon_id", "grouponId", "INTEGER", false),
rulesId("rules_id", "rulesId", "INTEGER", false),
userId("user_id", "userId", "INTEGER", false),
shareUrl("share_url", "shareUrl", "VARCHAR", 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),
updateTime("update_time", "updateTime", "TIMESTAMP", false),
shareUrl("share_url", "shareUrl", "VARCHAR", false),
payed("payed", "payed", "BIT", false),
deleted("deleted", "deleted", "BIT", false);
/**
......
......@@ -79,29 +79,38 @@ public class LitemallGrouponRules {
/**
*
* 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
*/
private LocalDateTime addTime;
private LocalDateTime expireTime;
/**
*
* 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
*/
private LocalDateTime updateTime;
private Short status;
/**
*
* 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
*/
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 {
/**
* 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
*/
public LocalDateTime getAddTime() {
return addTime;
public LocalDateTime getExpireTime() {
return expireTime;
}
/**
* 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
*/
public void setAddTime(LocalDateTime addTime) {
this.addTime = addTime;
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.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
*/
public LocalDateTime getUpdateTime() {
return updateTime;
public Short getStatus() {
return status;
}
/**
* 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
*/
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
public void setStatus(Short status) {
this.status = status;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_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
*/
public LocalDateTime getExpireTime() {
return expireTime;
public LocalDateTime getAddTime() {
return addTime;
}
/**
* 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
*/
public void setExpireTime(LocalDateTime expireTime) {
this.expireTime = expireTime;
public void setAddTime(LocalDateTime addTime) {
this.addTime = addTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column litemall_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 {
sb.append(", picUrl=").append(picUrl);
sb.append(", discount=").append(discount);
sb.append(", discountMember=").append(discountMember);
sb.append(", expireTime=").append(expireTime);
sb.append(", status=").append(status);
sb.append(", addTime=").append(addTime);
sb.append(", updateTime=").append(updateTime);
sb.append(", expireTime=").append(expireTime);
sb.append(", deleted=").append(deleted);
sb.append("]");
return sb.toString();
......@@ -414,9 +448,10 @@ public class LitemallGrouponRules {
&& (this.getPicUrl() == null ? other.getPicUrl() == null : this.getPicUrl().equals(other.getPicUrl()))
&& (this.getDiscount() == null ? other.getDiscount() == null : this.getDiscount().equals(other.getDiscount()))
&& (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.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()));
}
......@@ -436,9 +471,10 @@ public class LitemallGrouponRules {
result = prime * result + ((getPicUrl() == null) ? 0 : getPicUrl().hashCode());
result = prime * result + ((getDiscount() == null) ? 0 : getDiscount().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 + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
result = prime * result + ((getExpireTime() == null) ? 0 : getExpireTime().hashCode());
result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
return result;
}
......@@ -524,9 +560,10 @@ public class LitemallGrouponRules {
picUrl("pic_url", "picUrl", "VARCHAR", false),
discount("discount", "discount", "DECIMAL", false),
discountMember("discount_member", "discountMember", "INTEGER", false),
expireTime("expire_time", "expireTime", "TIMESTAMP", false),
status("status", "status", "SMALLINT", true),
addTime("add_time", "addTime", "TIMESTAMP", false),
updateTime("update_time", "updateTime", "TIMESTAMP", false),
expireTime("expire_time", "expireTime", "TIMESTAMP", false),
deleted("deleted", "deleted", "BIT", false);
/**
......
......@@ -7,6 +7,7 @@ import org.linlinjava.litemall.db.dao.LitemallGrouponRulesMapper;
import org.linlinjava.litemall.db.domain.LitemallGoods;
import org.linlinjava.litemall.db.domain.LitemallGrouponRules;
import org.linlinjava.litemall.db.domain.LitemallGrouponRulesExample;
import org.linlinjava.litemall.db.util.GrouponConstant;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -36,10 +37,8 @@ public class LitemallGrouponRulesService {
* @param id
* @return
*/
public LitemallGrouponRules queryById(Integer id) {
LitemallGrouponRulesExample example = new LitemallGrouponRulesExample();
example.or().andIdEqualTo(id).andDeletedEqualTo(false);
return mapper.selectOneByExample(example);
public LitemallGrouponRules findById(Integer id) {
return mapper.selectByPrimaryKey(id);
}
/**
......@@ -50,12 +49,24 @@ public class LitemallGrouponRulesService {
*/
public List<LitemallGrouponRules> queryByGoodsId(Integer goodsId) {
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);
}
/**
* 获取首页团购活动列表
* 获取首页团购规则列表
*
* @param page
* @param limit
......@@ -67,14 +78,14 @@ public class LitemallGrouponRulesService {
public List<LitemallGrouponRules> queryList(Integer page, Integer limit, String sort, String order) {
LitemallGrouponRulesExample example = new LitemallGrouponRulesExample();
example.or().andDeletedEqualTo(false);
example.or().andStatusEqualTo(GrouponConstant.RULE_STATUS_ON).andDeletedEqualTo(false);
example.setOrderByClause(sort + " " + order);
PageHelper.startPage(page, limit);
return mapper.selectByExample(example);
}
/**
* 判断某个团购活动是否已经过期
* 判断某个团购规则是否已经过期
*
* @return
*/
......@@ -83,7 +94,7 @@ public class LitemallGrouponRulesService {
}
/**
* 获取团购活动列表
* 获取团购规则列表
*
* @param goodsId
* @param page
......
......@@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallGrouponMapper;
import org.linlinjava.litemall.db.domain.LitemallGroupon;
import org.linlinjava.litemall.db.domain.LitemallGrouponExample;
import org.linlinjava.litemall.db.util.GrouponConstant;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -24,7 +25,7 @@ public class LitemallGrouponService {
*/
public List<LitemallGroupon> queryMyGroupon(Integer userId) {
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");
return mapper.selectByExample(example);
}
......@@ -37,7 +38,7 @@ public class LitemallGrouponService {
*/
public List<LitemallGroupon> queryMyJoinGroupon(Integer userId) {
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");
return mapper.selectByExample(example);
}
......@@ -62,7 +63,7 @@ public class LitemallGrouponService {
*/
public List<LitemallGroupon> queryJoinRecord(Integer id) {
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");
return mapper.selectByExample(example);
}
......@@ -75,7 +76,7 @@ public class LitemallGrouponService {
*/
public LitemallGroupon queryById(Integer id) {
LitemallGrouponExample example = new LitemallGrouponExample();
example.or().andIdEqualTo(id).andDeletedEqualTo(false).andPayedEqualTo(true);
example.or().andIdEqualTo(id).andDeletedEqualTo(false);
return mapper.selectOneByExample(example);
}
......@@ -87,10 +88,16 @@ public class LitemallGrouponService {
*/
public int countGroupon(Integer grouponId) {
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);
}
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) {
groupon.setUpdateTime(LocalDateTime.now());
return mapper.updateByPrimaryKeySelective(groupon);
......@@ -127,10 +134,16 @@ public class LitemallGrouponService {
criteria.andRulesIdEqualTo(Integer.parseInt(rulesId));
}
criteria.andDeletedEqualTo(false);
criteria.andPayedEqualTo(true);
criteria.andStatusNotEqualTo(GrouponConstant.STATUS_NONE);
criteria.andGrouponIdEqualTo(0);
PageHelper.startPage(page, size);
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 {
public static final Short STATUS_CONFIRM = 401;
public static final Short STATUS_CANCEL = 102;
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_CONFIRM = 203;
public static final Short STATUS_AUTO_CONFIRM = 402;
......
......@@ -11,11 +11,12 @@
<result column="groupon_id" jdbcType="INTEGER" property="grouponId" />
<result column="rules_id" jdbcType="INTEGER" property="rulesId" />
<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_time" jdbcType="TIMESTAMP" property="creatorUserTime" />
<result column="status" jdbcType="SMALLINT" property="status" />
<result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
<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" />
</resultMap>
<sql id="Example_Where_Clause">
......@@ -89,8 +90,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, update_time,
share_url, payed, deleted
id, order_id, groupon_id, rules_id, user_id, share_url, creator_user_id, creator_user_time,
`status`, add_time, update_time, deleted
</sql>
<select id="selectByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallGrouponExample" resultMap="BaseResultMap">
<!--
......@@ -212,13 +213,13 @@
SELECT LAST_INSERT_ID()
</selectKey>
insert into litemall_groupon (order_id, groupon_id, rules_id,
user_id, creator_user_id, add_time,
update_time, share_url, payed,
deleted)
user_id, share_url, creator_user_id,
creator_user_time, `status`, add_time,
update_time, deleted)
values (#{orderId,jdbcType=INTEGER}, #{grouponId,jdbcType=INTEGER}, #{rulesId,jdbcType=INTEGER},
#{userId,jdbcType=INTEGER}, #{creatorUserId,jdbcType=INTEGER}, #{addTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP}, #{shareUrl,jdbcType=VARCHAR}, #{payed,jdbcType=BIT},
#{deleted,jdbcType=BIT})
#{userId,jdbcType=INTEGER}, #{shareUrl,jdbcType=VARCHAR}, #{creatorUserId,jdbcType=INTEGER},
#{creatorUserTime,jdbcType=TIMESTAMP}, #{status,jdbcType=SMALLINT}, #{addTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT})
</insert>
<insert id="insertSelective" parameterType="org.linlinjava.litemall.db.domain.LitemallGroupon">
<!--
......@@ -242,21 +243,24 @@
<if test="userId != null">
user_id,
</if>
<if test="shareUrl != null">
share_url,
</if>
<if test="creatorUserId != null">
creator_user_id,
</if>
<if test="creatorUserTime != null">
creator_user_time,
</if>
<if test="status != null">
`status`,
</if>
<if test="addTime != null">
add_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="shareUrl != null">
share_url,
</if>
<if test="payed != null">
payed,
</if>
<if test="deleted != null">
deleted,
</if>
......@@ -274,21 +278,24 @@
<if test="userId != null">
#{userId,jdbcType=INTEGER},
</if>
<if test="shareUrl != null">
#{shareUrl,jdbcType=VARCHAR},
</if>
<if test="creatorUserId != null">
#{creatorUserId,jdbcType=INTEGER},
</if>
<if test="creatorUserTime != null">
#{creatorUserTime,jdbcType=TIMESTAMP},
</if>
<if test="status != null">
#{status,jdbcType=SMALLINT},
</if>
<if test="addTime != null">
#{addTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="shareUrl != null">
#{shareUrl,jdbcType=VARCHAR},
</if>
<if test="payed != null">
#{payed,jdbcType=BIT},
</if>
<if test="deleted != null">
#{deleted,jdbcType=BIT},
</if>
......@@ -326,21 +333,24 @@
<if test="record.userId != null">
user_id = #{record.userId,jdbcType=INTEGER},
</if>
<if test="record.shareUrl != null">
share_url = #{record.shareUrl,jdbcType=VARCHAR},
</if>
<if test="record.creatorUserId != null">
creator_user_id = #{record.creatorUserId,jdbcType=INTEGER},
</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">
add_time = #{record.addTime,jdbcType=TIMESTAMP},
</if>
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
</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">
deleted = #{record.deleted,jdbcType=BIT},
</if>
......@@ -360,11 +370,12 @@
groupon_id = #{record.grouponId,jdbcType=INTEGER},
rules_id = #{record.rulesId,jdbcType=INTEGER},
user_id = #{record.userId,jdbcType=INTEGER},
share_url = #{record.shareUrl,jdbcType=VARCHAR},
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},
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
share_url = #{record.shareUrl,jdbcType=VARCHAR},
payed = #{record.payed,jdbcType=BIT},
deleted = #{record.deleted,jdbcType=BIT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
......@@ -389,21 +400,24 @@
<if test="userId != null">
user_id = #{userId,jdbcType=INTEGER},
</if>
<if test="shareUrl != null">
share_url = #{shareUrl,jdbcType=VARCHAR},
</if>
<if test="creatorUserId != null">
creator_user_id = #{creatorUserId,jdbcType=INTEGER},
</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">
add_time = #{addTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="shareUrl != null">
share_url = #{shareUrl,jdbcType=VARCHAR},
</if>
<if test="payed != null">
payed = #{payed,jdbcType=BIT},
</if>
<if test="deleted != null">
deleted = #{deleted,jdbcType=BIT},
</if>
......@@ -420,11 +434,12 @@
groupon_id = #{grouponId,jdbcType=INTEGER},
rules_id = #{rulesId,jdbcType=INTEGER},
user_id = #{userId,jdbcType=INTEGER},
share_url = #{shareUrl,jdbcType=VARCHAR},
creator_user_id = #{creatorUserId,jdbcType=INTEGER},
creator_user_time = #{creatorUserTime,jdbcType=TIMESTAMP},
`status` = #{status,jdbcType=SMALLINT},
add_time = #{addTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
share_url = #{shareUrl,jdbcType=VARCHAR},
payed = #{payed,jdbcType=BIT},
deleted = #{deleted,jdbcType=BIT}
where id = #{id,jdbcType=INTEGER}
</update>
......
......@@ -12,9 +12,10 @@
<result column="pic_url" jdbcType="VARCHAR" property="picUrl" />
<result column="discount" jdbcType="DECIMAL" property="discount" />
<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="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" />
<result column="deleted" jdbcType="BIT" property="deleted" />
</resultMap>
<sql id="Example_Where_Clause">
......@@ -88,8 +89,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, update_time,
expire_time, deleted
id, goods_id, goods_name, pic_url, discount, discount_member, expire_time, `status`,
add_time, update_time, deleted
</sql>
<select id="selectByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallGrouponRulesExample" resultMap="BaseResultMap">
<!--
......@@ -211,13 +212,13 @@
SELECT LAST_INSERT_ID()
</selectKey>
insert into litemall_groupon_rules (goods_id, goods_name, pic_url,
discount, discount_member, add_time,
update_time, expire_time, deleted
)
discount, discount_member, expire_time,
`status`, add_time, update_time,
deleted)
values (#{goodsId,jdbcType=INTEGER}, #{goodsName,jdbcType=VARCHAR}, #{picUrl,jdbcType=VARCHAR},
#{discount,jdbcType=DECIMAL}, #{discountMember,jdbcType=INTEGER}, #{addTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP}, #{expireTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT}
)
#{discount,jdbcType=DECIMAL}, #{discountMember,jdbcType=INTEGER}, #{expireTime,jdbcType=TIMESTAMP},
#{status,jdbcType=SMALLINT}, #{addTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
#{deleted,jdbcType=BIT})
</insert>
<insert id="insertSelective" parameterType="org.linlinjava.litemall.db.domain.LitemallGrouponRules">
<!--
......@@ -244,15 +245,18 @@
<if test="discountMember != null">
discount_member,
</if>
<if test="expireTime != null">
expire_time,
</if>
<if test="status != null">
`status`,
</if>
<if test="addTime != null">
add_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="expireTime != null">
expire_time,
</if>
<if test="deleted != null">
deleted,
</if>
......@@ -273,15 +277,18 @@
<if test="discountMember != null">
#{discountMember,jdbcType=INTEGER},
</if>
<if test="expireTime != null">
#{expireTime,jdbcType=TIMESTAMP},
</if>
<if test="status != null">
#{status,jdbcType=SMALLINT},
</if>
<if test="addTime != null">
#{addTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="expireTime != null">
#{expireTime,jdbcType=TIMESTAMP},
</if>
<if test="deleted != null">
#{deleted,jdbcType=BIT},
</if>
......@@ -322,15 +329,18 @@
<if test="record.discountMember != null">
discount_member = #{record.discountMember,jdbcType=INTEGER},
</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">
add_time = #{record.addTime,jdbcType=TIMESTAMP},
</if>
<if test="record.updateTime != null">
update_time = #{record.updateTime,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>
......@@ -351,9 +361,10 @@
pic_url = #{record.picUrl,jdbcType=VARCHAR},
discount = #{record.discount,jdbcType=DECIMAL},
discount_member = #{record.discountMember,jdbcType=INTEGER},
expire_time = #{record.expireTime,jdbcType=TIMESTAMP},
`status` = #{record.status,jdbcType=SMALLINT},
add_time = #{record.addTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
expire_time = #{record.expireTime,jdbcType=TIMESTAMP},
deleted = #{record.deleted,jdbcType=BIT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
......@@ -381,15 +392,18 @@
<if test="discountMember != null">
discount_member = #{discountMember,jdbcType=INTEGER},
</if>
<if test="expireTime != null">
expire_time = #{expireTime,jdbcType=TIMESTAMP},
</if>
<if test="status != null">
`status` = #{status,jdbcType=SMALLINT},
</if>
<if test="addTime != null">
add_time = #{addTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="expireTime != null">
expire_time = #{expireTime,jdbcType=TIMESTAMP},
</if>
<if test="deleted != null">
deleted = #{deleted,jdbcType=BIT},
</if>
......@@ -407,9 +421,10 @@
pic_url = #{picUrl,jdbcType=VARCHAR},
discount = #{discount,jdbcType=DECIMAL},
discount_member = #{discountMember,jdbcType=INTEGER},
expire_time = #{expireTime,jdbcType=TIMESTAMP},
`status` = #{status,jdbcType=SMALLINT},
add_time = #{addTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
expire_time = #{expireTime,jdbcType=TIMESTAMP},
deleted = #{deleted,jdbcType=BIT}
where id = #{id,jdbcType=INTEGER}
</update>
......
......@@ -56,6 +56,7 @@ public class WxGrouponRuleService {
grouponRuleVo.setGrouponPrice(goods.getRetailPrice().subtract(rule.getDiscount()));
grouponRuleVo.setGrouponDiscount(rule.getDiscount());
grouponRuleVo.setGrouponMember(rule.getDiscountMember());
grouponRuleVo.setExpireTime(rule.getExpireTime());
grouponList.add(grouponRuleVo);
}
......
......@@ -25,6 +25,7 @@ import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.db.util.CouponUserConstant;
import org.linlinjava.litemall.db.util.GrouponConstant;
import org.linlinjava.litemall.db.util.OrderHandleOption;
import org.linlinjava.litemall.db.util.OrderUtil;
import org.linlinjava.litemall.core.util.IpUtil;
......@@ -262,14 +263,31 @@ public class WxOrderService {
//如果是团购项目,验证活动是否有效
if (grouponRulesId != null && grouponRulesId > 0) {
LitemallGrouponRules rules = grouponRulesService.queryById(grouponRulesId);
LitemallGrouponRules rules = grouponRulesService.findById(grouponRulesId);
//找不到记录
if (rules == null) {
return ResponseUtil.badArgument();
}
//团购活动已经过期
if (grouponRulesService.isExpired(rules)) {
return ResponseUtil.fail(GROUPON_EXPIRED, "团购活动已过期!");
//团购规则已经过期
if (rules.getStatus().equals(GrouponConstant.RULE_STATUS_DOWN_EXPIRE)) {
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 {
}
// 团购优惠
BigDecimal grouponPrice = new BigDecimal(0.00);
LitemallGrouponRules grouponRules = grouponRulesService.queryById(grouponRulesId);
BigDecimal grouponPrice = new BigDecimal(0);
LitemallGrouponRules grouponRules = grouponRulesService.findById(grouponRulesId);
if (grouponRules != null) {
grouponPrice = grouponRules.getDiscount();
}
......@@ -302,7 +320,7 @@ public class WxOrderService {
if (checkedGoodsList.size() == 0) {
return ResponseUtil.badArgumentValue();
}
BigDecimal checkedGoodsPrice = new BigDecimal(0.00);
BigDecimal checkedGoodsPrice = new BigDecimal(0);
for (LitemallCart checkGoods : checkedGoodsList) {
// 只有当团购规格商品ID符合才进行团购优惠
if (grouponRules != null && grouponRules.getGoodsId().equals(checkGoods.getGoodsId())) {
......@@ -314,7 +332,7 @@ public class WxOrderService {
// 获取可用的优惠券信息
// 使用优惠券减免的金额
BigDecimal couponPrice = new BigDecimal(0.00);
BigDecimal couponPrice = new BigDecimal(0);
// 如果couponId=0则没有优惠券,couponId=-1则不使用优惠券
if (couponId != 0 && couponId != -1) {
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, userCouponId, checkedGoodsPrice);
......@@ -326,16 +344,16 @@ public class WxOrderService {
// 根据订单商品总价计算运费,满足条件(例如88元)则免运费,否则需要支付运费(例如8元);
BigDecimal freightPrice = new BigDecimal(0.00);
BigDecimal freightPrice = new BigDecimal(0);
if (checkedGoodsPrice.compareTo(SystemConfig.getFreightLimit()) < 0) {
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);
......@@ -358,11 +376,11 @@ public class WxOrderService {
order.setOrderPrice(orderTotalPrice);
order.setActualPrice(actualPrice);
// 有团购活动
// 有团购
if (grouponRules != null) {
order.setGrouponPrice(grouponPrice); // 团购价格
} else {
order.setGrouponPrice(new BigDecimal(0.00)); // 团购价格
order.setGrouponPrice(new BigDecimal(0)); // 团购价格
}
// 添加订单表项
......@@ -395,7 +413,7 @@ public class WxOrderService {
Integer productId = checkGoods.getProductId();
LitemallGoodsProduct product = productService.findById(productId);
Integer remainNumber = product.getNumber() - checkGoods.getNumber();
int remainNumber = product.getNumber() - checkGoods.getNumber();
if (remainNumber < 0) {
throw new RuntimeException("下单的商品货品数量大于库存量");
}
......@@ -417,7 +435,7 @@ public class WxOrderService {
if (grouponRulesId != null && grouponRulesId > 0) {
LitemallGroupon groupon = new LitemallGroupon();
groupon.setOrderId(orderId);
groupon.setPayed(false);
groupon.setStatus(GrouponConstant.STATUS_NONE);
groupon.setUserId(userId);
groupon.setRulesId(grouponRulesId);
......@@ -428,12 +446,14 @@ public class WxOrderService {
groupon.setCreatorUserId(baseGroupon.getCreatorUserId());
groupon.setGrouponId(grouponLinkId);
groupon.setShareUrl(baseGroupon.getShareUrl());
grouponService.createGroupon(groupon);
} else {
groupon.setCreatorUserId(userId);
groupon.setCreatorUserTime(LocalDateTime.now());
groupon.setGrouponId(0);
grouponService.createGroupon(groupon);
grouponLinkId = groupon.getId();
}
grouponService.createGroupon(groupon);
}
// 订单支付超期任务
......@@ -441,6 +461,12 @@ public class WxOrderService {
Map<String, Object> data = new HashMap<>();
data.put("orderId", orderId);
if (grouponRulesId != null && grouponRulesId > 0) {
data.put("grouponLinkId", grouponLinkId);
}
else {
data.put("grouponLinkId", 0);
}
return ResponseUtil.ok(data);
}
......@@ -451,7 +477,6 @@ public class WxOrderService {
* 2. 设置订单取消状态;
* 3. 商品货品库存恢复;
* 4. TODO 优惠券;
* 5. TODO 团购活动。
*
* @param userId 用户ID
* @param body 订单信息,{ orderId:xxx }
......@@ -721,47 +746,29 @@ public class WxOrderService {
// 支付成功,有团购信息,更新团购信息
LitemallGroupon groupon = grouponService.queryByOrderId(order.getId());
if (groupon != null) {
LitemallGrouponRules grouponRules = grouponRulesService.queryById(groupon.getRulesId());
LitemallGrouponRules grouponRules = grouponRulesService.findById(groupon.getRulesId());
//仅当发起者才创建分享图片
if (groupon.getGrouponId() == 0) {
String url = qCodeService.createGrouponShareImage(grouponRules.getGoodsName(), grouponRules.getPicUrl(), groupon);
groupon.setShareUrl(url);
}
groupon.setPayed(true);
groupon.setStatus(GrouponConstant.STATUS_ON);
if (grouponService.updateById(groupon) == 0) {
return WxPayNotifyResponse.fail("更新数据已失效");
}
// 团购已达成,更新关联订单支付状态
if (groupon.getGrouponId() > 0) {
List<LitemallGroupon> grouponList = grouponService.queryJoinRecord(groupon.getGrouponId());
if (grouponList.size() >= grouponRules.getDiscountMember() - 1) {
for (LitemallGroupon grouponActivity : grouponList) {
if (grouponActivity.getOrderId().equals(order.getId())) {
//当前订单
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);
}
List<LitemallGroupon> grouponList = grouponService.queryJoinRecord(groupon.getGrouponId());
if (groupon.getGrouponId() != 0 && (grouponList.size() >= grouponRules.getDiscountMember() - 1)) {
for (LitemallGroupon grouponActivity : grouponList) {
grouponActivity.setStatus(GrouponConstant.STATUS_SUCCEED);
grouponService.updateById(grouponActivity);
}
} else {
order = orderService.findBySn(orderSn);
order.setOrderStatus(OrderUtil.STATUS_PAY_GROUPON);
orderService.updateWithOptimisticLocker(order);
LitemallGroupon grouponSource = grouponService.queryById(groupon.getGrouponId());
grouponSource.setStatus(GrouponConstant.STATUS_SUCCEED);
grouponService.updateById(grouponSource);
}
}
......
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