|
@@ -5,17 +5,20 @@ import com.caimei.utils.StringUtil;
|
|
|
import com.caimei365.manager.dao.svip.CmSvipHistoryDao;
|
|
|
import com.caimei365.manager.entity.PaginationVo;
|
|
|
import com.caimei365.manager.entity.ResponseJson;
|
|
|
-import com.caimei365.manager.entity.caimei.svip.CmSku;
|
|
|
-import com.caimei365.manager.entity.caimei.svip.CmSvipHistory;
|
|
|
-import com.caimei365.manager.entity.caimei.svip.CmSvipPackage;
|
|
|
-import com.caimei365.manager.entity.caimei.svip.CmSvipProduct;
|
|
|
+import com.caimei365.manager.entity.caimei.CmUser;
|
|
|
+import com.caimei365.manager.entity.caimei.MessageCenter;
|
|
|
+import com.caimei365.manager.entity.caimei.svip.*;
|
|
|
+import com.caimei365.manager.service.SendSmsService;
|
|
|
import com.caimei365.manager.service.caimei.svip.CmSvipHistoryService;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.List;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Description
|
|
@@ -23,10 +26,12 @@ import java.util.List;
|
|
|
* @author : Charles
|
|
|
* @date : 2023/4/7
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class CmSvipHistoryServiceImpl implements CmSvipHistoryService {
|
|
|
|
|
|
@Autowired private CmSvipHistoryDao historyDao;
|
|
|
+ @Resource private SendSmsService sendSmsService;
|
|
|
|
|
|
@Override
|
|
|
public ResponseJson<PaginationVo<CmSvipHistory>> memberList(CmSvipHistory vip, Integer pageNum, Integer pageSize) {
|
|
@@ -44,6 +49,127 @@ public class CmSvipHistoryServiceImpl implements CmSvipHistoryService {
|
|
|
return ResponseJson.success(page);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ResponseJson<PaginationVo<CmUser>> findClubList(Integer clubId, String name, String shortName, Integer pageNum, Integer pageSize) {
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ List<CmUser> clubList = historyDao.findUserList(clubId, name, shortName);
|
|
|
+ PaginationVo<CmUser> page = new PaginationVo<>(clubList);
|
|
|
+ return ResponseJson.success(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseJson saveGive(CmSvipGive cmSvipGive) throws Exception {
|
|
|
+ //cm_svip_user加用户,cm_svip_history插入一条记录
|
|
|
+ CmSvipHistory cmSvipHistory = new CmSvipHistory();
|
|
|
+ Date now = new Date();
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
+ c.setTime(now);
|
|
|
+ c.add(Calendar.MONTH, cmSvipGive.getMonth());
|
|
|
+ Date endTime = c.getTime();
|
|
|
+ cmSvipHistory.setBeginTime(now);
|
|
|
+ cmSvipHistory.setEndTime(endTime);
|
|
|
+ cmSvipHistory.setUserId(Long.valueOf(cmSvipGive.getUserId()));
|
|
|
+ // 5 系统赠送
|
|
|
+ cmSvipHistory.setPayWay("5");
|
|
|
+ cmSvipHistory.setPayTime(now);
|
|
|
+ CmSvipHistory user = historyDao.findVipUser(cmSvipGive.getUserId());
|
|
|
+// Integer clubID = messageCenterDao.clubIdCule(Integer.parseInt(cmSvipGive.getUserId()));
|
|
|
+ Date date=new Date();
|
|
|
+ String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
|
|
|
+ MessageCenter messageCenter = new MessageCenter();
|
|
|
+ messageCenter.setShopId(null);
|
|
|
+ messageCenter.setClubId(cmSvipGive.getClubId());
|
|
|
+ messageCenter.setUserType(1);
|
|
|
+ messageCenter.setMessageType(2);
|
|
|
+ messageCenter.setAccountType(4);
|
|
|
+ messageCenter.setContent(cmSvipGive.getMonth().toString()+"个月");
|
|
|
+ messageCenter.setTime(curDateStr);
|
|
|
+ historyDao.addMessageCenter(messageCenter);
|
|
|
+
|
|
|
+// String bindMobile= messageCenterDao.contractMobile(cmSvipGive.getUserId());
|
|
|
+
|
|
|
+ String content = "【采美365】您已获得采美平台赠送的"+cmSvipGive.getMonth()+"个月超级会员服务,快戳采美网站链接www.caimei365.com/M2Tr98CG 或微信搜索“采美采购商城”小程序登录采美平台畅享会员特权吧。关注公众号“采美网”可获取更多优惠和精彩资讯。";
|
|
|
+ if (null == cmSvipGive.getContractMobile()) {
|
|
|
+ return ResponseJson.error(-1,"手机号为空,无法发送短信",null);
|
|
|
+ }
|
|
|
+ boolean sendSms = sendSmsService.getSendSms(9, cmSvipGive.getContractMobile(), content);
|
|
|
+ if(sendSms){
|
|
|
+ log.info(">>>>>>>获得采美平台赠送的超级会员短信推送成功");
|
|
|
+ }
|
|
|
+ if (null != user) {
|
|
|
+ //不为空update
|
|
|
+ CmSvipHistory endTimeFlag = historyDao.findEndTime(Long.valueOf(cmSvipGive.getUserId()));
|
|
|
+ if (null != endTimeFlag) {
|
|
|
+ //不为空begintime不改,续期,否则正常update
|
|
|
+ Date beginTime = endTimeFlag.getEndTime();
|
|
|
+ cmSvipHistory.setBeginTime(beginTime);
|
|
|
+ c.setTime(beginTime);
|
|
|
+ c.add(Calendar.MONTH,cmSvipGive.getMonth());
|
|
|
+ cmSvipHistory.setEndTime(c.getTime());
|
|
|
+ historyDao.insertHistory(cmSvipHistory);
|
|
|
+ //cm_svip_user的begintime不变
|
|
|
+ cmSvipHistory.setBeginTime(null);
|
|
|
+ historyDao.updateVip(cmSvipHistory);
|
|
|
+ }else{
|
|
|
+ historyDao.insertHistory(cmSvipHistory);
|
|
|
+ //正常update
|
|
|
+ historyDao.updateVip(cmSvipHistory);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //cm_svip_history插入一条记录
|
|
|
+ historyDao.giveVip(cmSvipHistory);
|
|
|
+ //cm_svip_user无则新增
|
|
|
+ historyDao.insertHistory(cmSvipHistory);
|
|
|
+ }
|
|
|
+ return ResponseJson.success(1,"超级会员赠送成功",null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取购买记录
|
|
|
+ *
|
|
|
+ * @param cmSvipHistory
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<PaginationVo<CmSvipHistory>> findHistory(CmSvipHistory cmSvipHistory, int pageNum, int pageSize) {
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ List<CmSvipHistory> history = historyDao.findHistory(cmSvipHistory);
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ //1生效2过期3未生效
|
|
|
+ for (CmSvipHistory svipHistory : history) {
|
|
|
+ Integer packageID = svipHistory.getPackageId();
|
|
|
+ Integer duration = historyDao.findDuration(packageID);
|
|
|
+ if (null != duration && duration.equals(3)) {
|
|
|
+ svipHistory.setPackageId(3);
|
|
|
+ }
|
|
|
+ if (null != duration && duration.equals(1)) {
|
|
|
+ svipHistory.setPackageId(1);
|
|
|
+ }
|
|
|
+ if (null != duration && duration.equals(12)) {
|
|
|
+ svipHistory.setPackageId(12);
|
|
|
+ }
|
|
|
+ if(0==packageID){
|
|
|
+ svipHistory.setGiveMonth(historyDao.findMonth(svipHistory.getId()));
|
|
|
+ }
|
|
|
+ Date beginTime = svipHistory.getBeginTime();
|
|
|
+ Date endTime = svipHistory.getEndTime();
|
|
|
+ //开始时间<现在
|
|
|
+ Date now = new Date();
|
|
|
+ if (beginTime.after(now)) {
|
|
|
+ svipHistory.setStatus("3");
|
|
|
+ }
|
|
|
+ if (beginTime.before(now) && endTime.after(now)) {
|
|
|
+ svipHistory.setStatus("1");
|
|
|
+ }
|
|
|
+ //终止时间>现在
|
|
|
+ if (endTime.before(now)) {
|
|
|
+ svipHistory.setStatus("2");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PaginationVo<CmSvipHistory> page = new PaginationVo<>(history);
|
|
|
+ return ResponseJson.success(page);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 超级会员优惠商品
|
|
|
*
|