Explorar el Código

赠送超级会员

zhijiezhao hace 3 años
padre
commit
aee5b4ece5

+ 8 - 0
src/main/java/com/caimei/modules/supervip/dao/CmSvipHistoryDao.java

@@ -27,4 +27,12 @@ public interface CmSvipHistoryDao extends CrudDao<CmSvipHistory> {
     Integer findPackage(Integer pac);
 
     Integer findDuration(Integer packageId);
+
+    void giveVip(CmSvipHistory cmSvipHistory);
+
+    CmSvipHistory findVipUser(String userId);
+
+    void updateVip(CmSvipHistory cmSvipHistory);
+
+    void insertHistory(CmSvipHistory cmSvipHistory);
 }

+ 6 - 6
src/main/java/com/caimei/modules/supervip/entity/CmSvipGive.java

@@ -7,11 +7,11 @@ public class CmSvipGive  extends DataEntity<CmSvipGive> {
     /**
      * 赠送套餐月份数
      */
-    private String month;
+    private Integer month;
     /**
      * 机构id
      */
-    private String clubId;
+    private Integer clubId;
 
     /**
      * 用户id
@@ -26,19 +26,19 @@ public class CmSvipGive  extends DataEntity<CmSvipGive> {
         this.userId = userId;
     }
 
-    public String getMonth() {
+    public Integer getMonth() {
         return month;
     }
 
-    public void setMonth(String month) {
+    public void setMonth(Integer month) {
         this.month = month;
     }
 
-    public String getClubId() {
+    public Integer getClubId() {
         return clubId;
     }
 
-    public void setClubId(String clubId) {
+    public void setClubId(Integer clubId) {
         this.clubId = clubId;
     }
 }

+ 63 - 0
src/main/java/com/caimei/modules/supervip/service/CmSvipGiveService.java

@@ -0,0 +1,63 @@
+package com.caimei.modules.supervip.service;
+
+import com.caimei.modules.supervip.dao.CmSvipHistoryDao;
+import com.caimei.modules.supervip.entity.CmSvipGive;
+import com.caimei.modules.supervip.entity.CmSvipHistory;
+import com.thinkgem.jeesite.common.service.CrudService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Calendar;
+import java.util.Date;
+
+@Service
+@Transactional(readOnly = true)
+public class CmSvipGiveService extends CrudService<CmSvipHistoryDao, CmSvipHistory> {
+
+    @Autowired
+    private CmSvipHistoryDao svipDao;
+
+    @Transactional(readOnly = false)
+    public void saveGive(CmSvipGive cmSvipGive) {
+        //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 = svipDao.findVipUser(cmSvipGive.getUserId());
+        if (null != user) {
+            //不为空update
+            CmSvipHistory endTimeFlag = svipDao.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());
+                svipDao.insertHistory(cmSvipHistory);
+                //cm_svip_user的begintime不变
+                cmSvipHistory.setBeginTime(null);
+                svipDao.updateVip(cmSvipHistory);
+            }else{
+                svipDao.insertHistory(cmSvipHistory);
+                //正常update
+                svipDao.updateVip(cmSvipHistory);
+            }
+        } else {
+            //cm_svip_history插入一条记录
+            svipDao.giveVip(cmSvipHistory);
+            //cm_svip_user无则新增
+            svipDao.insertHistory(cmSvipHistory);
+        }
+    }
+}

+ 4 - 4
src/main/java/com/caimei/modules/supervip/service/CmSvipHistoryService.java

@@ -38,14 +38,14 @@ public class CmSvipHistoryService extends CrudService<CmSvipHistoryDao, CmSvipHi
         //1生效2过期3未生效
         for (CmSvipHistory svipHistory : history) {
             Integer packageID = svipHistory.getPackageId();
-            Integer duration=svipDao.findDuration(packageID);
-            if(duration.equals(3)){
+            Integer duration = svipDao.findDuration(packageID);
+            if (null != duration && duration.equals(3)) {
                 svipHistory.setPackageId(3);
             }
-            if(duration.equals(1)){
+            if (null != duration && duration.equals(1)) {
                 svipHistory.setPackageId(1);
             }
-            if(duration.equals(12)){
+            if (null != duration && duration.equals(12)) {
                 svipHistory.setPackageId(12);
             }
             Date beginTime = svipHistory.getBeginTime();

+ 14 - 4
src/main/java/com/caimei/modules/supervip/web/CmSvipGiveController.java

@@ -1,7 +1,11 @@
 package com.caimei.modules.supervip.web;
 
 import com.caimei.modules.supervip.entity.CmSvipGive;
+import com.caimei.modules.supervip.service.CmSvipGiveService;
+import com.thinkgem.jeesite.common.config.Global;
+import com.thinkgem.jeesite.common.utils.StringUtils;
 import com.thinkgem.jeesite.common.web.BaseController;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.ModelAttribute;
@@ -13,8 +17,10 @@ import javax.servlet.http.HttpServletResponse;
 
 @Controller
 @RequestMapping(value = "${adminPath}/svip/cmSvipGive")
-public class CmSvipGiveController  extends BaseController {
+public class CmSvipGiveController extends BaseController {
 
+    @Autowired
+    private CmSvipGiveService svipService;
 
     @ModelAttribute
     public CmSvipGive get(@RequestParam(required = false) String id) {
@@ -30,9 +36,13 @@ public class CmSvipGiveController  extends BaseController {
 
     @RequestMapping(value = "save")
     public String save(CmSvipGive cmSvipGive, HttpServletRequest request, HttpServletResponse response, Model model) {
-        System.out.println(cmSvipGive.toString());
-
-        return "modules/svip/cmSvipHistoryList";
+        if (StringUtils.isBlank(cmSvipGive.getUserId()) || null == cmSvipGive.getMonth()) {
+            model.addAttribute("message", "参数错误或缺少参数");
+            return "modules/super/cmSvipGiveForm";
+        }
+        svipService.saveGive(cmSvipGive);
+        model.addAttribute("message", "赠送成功");
+        return "redirect:" + Global.getAdminPath() + "/svip/cmSvipHistory";
     }
 
 }

+ 32 - 4
src/main/resources/mappings/modules/super/CmSvipHistoryMapper.xml

@@ -17,7 +17,24 @@
 
     <sql id="cmSvipHistoryJoins">
     </sql>
-
+    <insert id="giveVip">
+        insert into cm_svip_user (userId, beginTime, endTime, delFlag, updateTime)
+        values (#{userId}, #{beginTime}, #{endTime}, 0, #{beginTime})
+    </insert>
+    <insert id="insertHistory">
+        insert into cm_svip_history(userId, packageId, beginTime, endTime, payStatus, payWay, price, userBeans, payTime)
+        values (#{userId}, 0, #{beginTime}, #{endTime}, 1, #{payWay}, 0, 0, #{payTime})
+    </insert>
+    <update id="updateVip">
+        UPDATE cm_svip_user
+        SET
+            <if test="beginTime != null">
+            beginTime  = #{beginTime},
+            </if>
+            endTime    = #{endTime},
+            updateTime = now()
+        WHERE userId = #{userId}
+    </update>
     <select id="get" resultType="com.caimei.modules.supervip.entity.CmSvipHistory">
         SELECT
         <include refid="cmSvipHistoryColumns"/>
@@ -102,9 +119,12 @@
         <if test="startEndTime != null and startEndTime != '' and endEndTime != null and endEndTime != ''">
             and (cs.endTime between #{startEndTime} and #{endEndTime})
         </if>
-        <if test="packageId != null">
+        <if test="packageId != null and packageId != 0">
             and cp.duration = #{packageId}
         </if>
+        <if test="packageId == 0">
+            and cs.packageId = 0
+        </if>
         <if test='status == "1"'>
             and (NOW() between cs.beginTime and cs.endTime)
         </if>
@@ -124,7 +144,6 @@
           and endTime > now()
     </select>
 
-
     <select id="superFind" resultType="com.caimei.modules.supervip.entity.CmSvipHistory">
         SELECT u.name as clubName, u.username as linkMan, u.bindMobile as mobile,
         cs.userId,cs.beginTime,cs.endTime,cs.packageId
@@ -150,9 +169,12 @@
             <if test="startEndTime !=null and startEndTime!='' and endEndTime!=null and endEndTime!=''">
                 and (cu.endTime between #{startEndTime} and #{endEndTime})
             </if>
-            <if test="packageId !=null and packageId != ''">
+            <if test="packageId !=null and packageId != '' and packageId != 0">
                 and cp.duration = #{packageId}
             </if>
+            <if test="packageId == 0">
+                and cs.packageId = 0
+            </if>
             <if test='status == "1"'>
                 and cu.endTime > NOW()
             </if>
@@ -182,5 +204,11 @@
         from cm_svip_package
         where id = #{packageId}
     </select>
+    <select id="findVipUser" resultType="com.caimei.modules.supervip.entity.CmSvipHistory">
+        select beginTime, endTime, updateTime, userId
+        from cm_svip_user
+        where userId = #{userId}
+          and delflag = 0
+    </select>
 
 </mapper>

+ 25 - 2
src/main/webapp/WEB-INF/views/modules/super/cmSvipGiveForm.jsp

@@ -62,6 +62,29 @@
             $("#userId").val("");
         }
 
+        $(document).ready(function () {
+            //$("#name").focus();
+            $("#inputForm").validate({
+                submitHandler: function (form) {
+                    var places1 = $("#give").val();
+                    if (!(/(^[1-9]\d*$)/.test(places1))) {
+                        alert("套餐时长应为正整数且不能为0");
+                        return false;
+                    }
+                    loading('正在提交,请稍等...');
+                    form.submit();
+                },
+                errorContainer: "#messageBox",
+                errorPlacement: function (error, element) {
+                    $("#messageBox").text("输入有误,请先更正。");
+                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
+                        error.appendTo(element.parent().parent());
+                    } else {
+                        error.insertAfter(element);
+                    }
+                }
+            });
+        });
     </script>
 </head>
 <body>
@@ -78,7 +101,7 @@
         <label class="control-label"><font color="red">*</font>机构:</label>
         <div class="controls">
             <a href="javascript:void(0);" onclick="showSelectClub()" id="chooseClub">请选择机构</a>
-            <input type="hidden" name="userId" id="userId" value="${cmCoupon.userId}">
+            <input type="hidden" name="userId" id="userId" required="required" value="${cmCoupon.userId}">
             <table id="contentTableClub" class="table table-striped table-bordered table-condensed" hidden="hidden">
                 <thead>
                 <tr>
@@ -96,7 +119,7 @@
     <div class="control-group">
         <label class="control-label"><span class="help-inline"><font color="red">*</font> </span>赠送套餐:</label>
         <div class="controls">
-            <form:input path="month" htmlEscape="false" class="input-xlarge2" style="width: 60px"/> 个月
+            <form:input path="month" id="give" htmlEscape="false" class="input-xlarge required" style="width: 60px"/> 个月
         </div>
     </div>
 

+ 4 - 0
src/main/webapp/WEB-INF/views/modules/svip/cmSvipHistoryForm.jsp

@@ -54,6 +54,7 @@
         <label>购买套餐:</label>
         <form:select path="packageId" class="input-medium ">
             <form:option value="" label="全部"/>
+            <form:option value="0" label="系统赠送"/>
             <form:option value="1" label="1个月"/>
             <form:option value="3" label="3个月"/>
             <form:option value="12" label="12个月"/>
@@ -106,6 +107,7 @@
                     <c:if test="${cmSvipHistory.packageId eq '12'}">12个月</c:if>
                     <c:if test="${cmSvipHistory.packageId eq '3'}">3个月</c:if>
                     <c:if test="${cmSvipHistory.packageId eq '1'}">1个月</c:if>
+                    <c:if test="${cmSvipHistory.packageId eq '0'}">系统赠送</c:if>
             </td>
             <td>
                 <c:if test="${cmSvipHistory.payWay eq '0'}">¥${cmSvipHistory.price}</c:if>
@@ -113,6 +115,7 @@
                 <c:if test="${cmSvipHistory.payWay eq '2'}">¥${cmSvipHistory.price}</c:if>
                 <c:if test="${cmSvipHistory.payWay eq '3'}">¥${cmSvipHistory.price}</c:if>
                 <c:if test="${cmSvipHistory.payWay eq '4'}"><fmt:formatNumber value="${cmSvipHistory.userBeans}" pattern="#" type="number"/>采美豆</c:if>
+                <c:if test="${cmSvipHistory.payWay eq '5'}">系统赠送</c:if>
             </td>
             <td>
                 <c:if test="${cmSvipHistory.payWay eq '0'}">未知</c:if>
@@ -172,6 +175,7 @@
                 <c:if test="${cmSvipHistory.payWay eq '2'}">线下</c:if>
                 <c:if test="${cmSvipHistory.payWay eq '3'}">余额抵扣</c:if>
                 <c:if test="${cmSvipHistory.payWay eq '4'}">采美豆抵扣</c:if>
+                <c:if test="${cmSvipHistory.payWay eq '5'}">系统赠送</c:if>
             </td>
             <td>
                 <c:if test="${cmSvipHistory.status eq '1'}"><font color="green">已生效</font> </c:if>

+ 1 - 0
src/main/webapp/WEB-INF/views/modules/svip/cmSvipHistoryList.jsp

@@ -45,6 +45,7 @@
         <label>购买套餐:</label>
         <form:select path="packageId" class="input-medium required">
             <form:option value="" label="全部"/>
+            <form:option value="0" label="系统赠送"/>
             <form:option value="1" label="1个月"/>
             <form:option value="3" label="3个月"/>
             <form:option value="12" label="12个月"/>