|
@@ -28,8 +28,19 @@ public class BuyService {
|
|
|
public int buyGroup(Buy buy) {
|
|
|
Buy buy1 = buyMapper.selectBuyOne(buy.getUserId(), buy.getJmId());
|
|
|
if (buy1 != null) {
|
|
|
- buy.setBuyId(buy1.getBuyId());
|
|
|
- return buyMapper.updateById(buy);
|
|
|
+ JmTuangou jmTuangou = jmTuangouDao.selectJmTuangouByJmId(buy1.getJmId());
|
|
|
+ Buy buy2 = buyMapper.selectById(buy1.getBuyId());
|
|
|
+ if (jmTuangou.getTgMaxNum().intValue() >= jmTuangou.getCurrentNum().intValue() - buy2.getBuyCount().intValue() + buy.getBuyCount().intValue()) {
|
|
|
+ buy.setBuyId(buy1.getBuyId());
|
|
|
+ return buyMapper.updateById(buy);
|
|
|
+ } else {
|
|
|
+ return 3;//不允许更改团购数量
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //第一次购买团购数量大于最大上限数量不允许
|
|
|
+ JmTuangou jmTuangou = jmTuangouDao.selectJmTuangouByJmId(buy.getJmId());
|
|
|
+ if (jmTuangou.getTgMaxNum().intValue() < buy.getBuyCount().intValue()) {
|
|
|
+ return 3;
|
|
|
}
|
|
|
buy.setBuyId(IdWorker.getId());
|
|
|
buy.setUserCreate(buy.getUserId());
|
|
@@ -82,12 +93,12 @@ public class BuyService {
|
|
|
public int updateStatus() {
|
|
|
List<JmTuangou> jmTuangous = jmTuangouDao.selectAll();
|
|
|
if (jmTuangous != null && jmTuangous.size() > 0) {
|
|
|
- //已经到截止时间
|
|
|
- for (JmTuangou list : jmTuangous)
|
|
|
+ for (JmTuangou list : jmTuangous) {
|
|
|
+ // 团购数量 最小起订量
|
|
|
+ Buy buy = buyMapper.selectCountNum(list.getJmId());
|
|
|
+ //已经到截止时间
|
|
|
if (list.getTgEndTime().getTime() < new DateTime().getMillis()) {
|
|
|
|
|
|
- // 团购数量 最小起订量
|
|
|
- Buy buy = buyMapper.selectCountNum(list.getJmId());
|
|
|
if (buy != null) { //最小起订量
|
|
|
if (list.getTgMinNum().intValue() > buy.getCount().intValue()) {
|
|
|
jmTuangouDao.updateStatusByJmId(list.getJmId(), 4L);//取消
|
|
@@ -97,19 +108,16 @@ public class BuyService {
|
|
|
} else {
|
|
|
jmTuangouDao.updateStatusByJmId(list.getJmId(), 4L);//取消
|
|
|
}
|
|
|
- /* if (buys != null && buys.size() > 0) {
|
|
|
- for (Buy v : buys) {
|
|
|
- if (v.getCount().intValue() < list.getTgMinNum().intValue()) {
|
|
|
- jmTuangouDao.updateStatusByJmId(list.getJmId(), 4L);//取消
|
|
|
- } else {
|
|
|
- jmTuangouDao.updateStatusByJmId(list.getJmId(), 2L);//发货
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ //团购数量已经过了最大起订量的 就直接发货
|
|
|
+ if (buy != null) {
|
|
|
+ if (list.getTgMaxNum().intValue() == buy.getCount().intValue()) {
|
|
|
+ jmTuangouDao.updateStatusByJmId(list.getJmId(), 2L);//发货
|
|
|
}
|
|
|
- } else {
|
|
|
- jmTuangouDao.updateStatusByJmId(list.getJmId(), 4L);//取消
|
|
|
- }*/
|
|
|
-
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
return 1;
|
|
|
}
|