From 972d3bc71115ec977dccf835fbcd148da3bcc86c Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期二, 03 九月 2019 16:41:49 +0800
Subject: [PATCH] 统计可用的免单券数量-countUsableFreeCouponForBuy
---
fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java | 92 +++++++++++++++++++++++++---------------------
1 files changed, 50 insertions(+), 42 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java
index e8a7e10..cf64f6c 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java
@@ -1,6 +1,5 @@
package com.yeshi.fanli.service.impl.push;
-import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@@ -12,13 +11,17 @@
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.mybatis.push.PushCouponMapper;
+import com.yeshi.fanli.entity.bus.user.UserSystemCoupon;
import com.yeshi.fanli.entity.push.PushCoupon;
-import com.yeshi.fanli.exception.PushException;
+import com.yeshi.fanli.entity.push.PushCouponRecord;
import com.yeshi.fanli.exception.push.PushCouponException;
+import com.yeshi.fanli.exception.push.PushException;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.push.PushCouponRecordService;
import com.yeshi.fanli.service.inter.push.PushCouponService;
import com.yeshi.fanli.service.inter.push.PushService;
+import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
+import com.yeshi.fanli.util.StringUtil;
import net.sf.json.JSONObject;
@@ -36,6 +39,9 @@
@Resource
private PushCouponRecordService pushCouponRecordService;
+
+ @Resource
+ private UserSystemCouponService userSystemCouponService;
@Override
public int deleteByPrimaryKey(Long id) {
@@ -80,23 +86,16 @@
@Override
@Transactional
- public void save(PushCoupon record) throws PushCouponException {
+ public void save(PushCoupon record) throws PushCouponException,Exception {
if (record == null) {
throw new PushCouponException(1, "鍙傛暟涓嶆纭�");
}
- String title = record.getTitle();
- String content = record.getContent();
- if (title == null || title.trim().length() == 0 || content == null || content.trim().length() == 0) {
- throw new PushCouponException(1, "鏍囬鎴栧唴瀹逛笉鑳戒负绌�");
+ String uids = record.getUids();
+ if (StringUtil.isNullOrEmpty(uids)) {
+ throw new PushCouponException(1, "鍙戞斁鐢ㄦ埛涓嶈兘涓虹┖");
}
-
- Date startTime = record.getStartTime();
- Date endTime = record.getEndTime();
- if (startTime == null || endTime == null) {
- throw new PushCouponException(1, "鏈夋晥鏈熸椂闂翠笉鑳戒负绌�");
- }
-
+
Integer amount = record.getAmount();
if (amount == null) {
throw new PushCouponException(1, "鍒告暟閲忎笉鑳戒负绌�");
@@ -104,43 +103,52 @@
throw new PushCouponException(1, "鍒告暟閲忚寖鍥存槸 1~5");
}
- BigDecimal percent = record.getPercent();
- if (percent != null && (percent.compareTo(new BigDecimal(60)) > 0
- || percent.compareTo(new BigDecimal(1)) < 0)) {
- throw new PushCouponException(1, "鍒告瘮渚嬭寖鍥存槸1~60 鐨勬鏁存暟");
- }
-
Long id = record.getId();
if (id == null) {
// 鏂板
- record.setPushed(false);
record.setCreateTime(new Date());
record.setUpdateTime(new Date());
-
// 鎻掑叆鏁版嵁
- insert(record);
- } else {
- // 淇敼
- PushCoupon current = selectByPrimaryKey(id);
- if (current == null) {
- throw new PushCouponException(1, "璇ヨ褰曞凡涓嶅瓨鍦�");
+ pushCouponMapper.insert(record);
+
+ String[] uidArray = uids.split(",");
+
+ if (uidArray != null) {
+ for (int i = 0; i < uidArray.length; i++) {
+
+ Long uid = Long.parseLong(uidArray[i]);
+ // 鎻掑叆璁板綍
+ PushCouponRecord pushCouponRecord = new PushCouponRecord();
+ pushCouponRecord.setPushCoupon(record);
+ pushCouponRecord.setUid(uid);
+ pushCouponRecord.setCreateTime(new Date());
+
+ // 鎻掑叆棰嗗彇璁板綍
+ pushCouponRecordService.insertSelective(pushCouponRecord);
+ // 鐩存帴鍙戦�佸埜
+ userSystemCouponService.randomRewardCoupon(amount, uid, UserSystemCoupon.SOURCE_SYSTEM_PUSH);
+ }
}
- if(current.isPushed()) {
- throw new PushCouponException(1, "宸叉帹閫佺殑淇℃伅涓嶈兘淇敼");
- }
-
- current.setTitle(title);
- current.setContent(content);
- current.setAmount(amount);
- current.setStartTime(startTime);
- current.setEndTime(endTime);
- current.setUids(record.getUids());
- current.setRemark(record.getRemark());
-
- // 鏇存柊鏁版嵁
- updateByPrimaryKey(current);
+
+ } else {
+//
+// // 淇敼
+// PushCoupon current = selectByPrimaryKey(id);
+// if (current == null) {
+// throw new PushCouponException(1, "璇ヨ褰曞凡涓嶅瓨鍦�");
+// }
+//
+// if(current.isPushed()) {
+// throw new PushCouponException(1, "宸叉帹閫佺殑淇℃伅涓嶈兘淇敼");
+// }
+// current.setAmount(amount);
+// current.setUids(record.getUids());
+// current.setRemark(record.getRemark());
+// current.setUpdateTime(new Date());
+// // 鏇存柊鏁版嵁
+// updateByPrimaryKey(current);
}
}
--
Gitblit v1.8.0