Kaynağa Gözat

超级会员套餐配置

zhijiezhao 3 yıl önce
ebeveyn
işleme
663f7f33ad

+ 8 - 1
src/main/java/com/caimei/modules/supers/dao/CmSvipPackageDao.java

@@ -3,13 +3,20 @@ package com.caimei.modules.supers.dao;
 import com.thinkgem.jeesite.common.persistence.CrudDao;
 import com.thinkgem.jeesite.common.persistence.annotation.MyBatisDao;
 import com.caimei.modules.supers.entity.CmSvipPackage;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * 超级会员套餐配置DAO接口
+ *
  * @author zzj
  * @version 2021-10-09
  */
 @MyBatisDao
 public interface CmSvipPackageDao extends CrudDao<CmSvipPackage> {
-	
+
+    List<CmSvipPackage> findPackage();
+
+    void updatePrice(@Param("price") Double price, @Param("duration") Integer duration, @Param("proportion") Integer proportion);
 }

+ 31 - 3
src/main/java/com/caimei/modules/supers/entity/CmSvipPackage.java

@@ -15,10 +15,14 @@ public class CmSvipPackage extends DataEntity<CmSvipPackage> {
 	
 	private static final long serialVersionUID = 1L;
 	private String name;		// 套餐名称
-	private String price;		// 套餐价格
+	private String price;
+	private String price1;		// 套餐价格
+	private String price2;		// 套餐价格
+	private String price3;		// 套餐价格
 	private String duration;		// 套餐时长(月)
 	private String proportion;		// 采美豆现金兑换比例
 
+
 	public CmSvipPackage() {
 		super();
 	}
@@ -35,7 +39,7 @@ public class CmSvipPackage extends DataEntity<CmSvipPackage> {
 	public void setName(String name) {
 		this.name = name;
 	}
-	
+
 	public String getPrice() {
 		return price;
 	}
@@ -43,7 +47,31 @@ public class CmSvipPackage extends DataEntity<CmSvipPackage> {
 	public void setPrice(String price) {
 		this.price = price;
 	}
-	
+
+	public String getPrice1() {
+		return price1;
+	}
+
+	public void setPrice1(String price1) {
+		this.price1 = price1;
+	}
+
+	public String getPrice2() {
+		return price2;
+	}
+
+	public void setPrice2(String price2) {
+		this.price2 = price2;
+	}
+
+	public String getPrice3() {
+		return price3;
+	}
+
+	public void setPrice3(String price3) {
+		this.price3 = price3;
+	}
+
 	public String getDuration() {
 		return duration;
 	}

+ 58 - 22
src/main/java/com/caimei/modules/supers/service/CmSvipPackageService.java

@@ -4,6 +4,7 @@ import java.util.List;
 
 import com.caimei.modules.supers.dao.CmSvipPackageDao;
 import com.caimei.modules.supers.entity.CmSvipPackage;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -14,33 +15,68 @@ import com.caimei.modules.supers.dao.CmSvipPackageDao;
 
 /**
  * 超级会员套餐配置Service
+ *
  * @author zzj
  * @version 2021-10-09
  */
 @Service
 @Transactional(readOnly = true)
 public class CmSvipPackageService extends CrudService<CmSvipPackageDao, CmSvipPackage> {
+    @Autowired
+    private CmSvipPackageDao dao;
+
+    public CmSvipPackage get(String id) {
+        return super.get(id);
+    }
+
+    public List<CmSvipPackage> findList(CmSvipPackage cmSvipPackage) {
+        return super.findList(cmSvipPackage);
+    }
+
+    public Page<CmSvipPackage> findPage(Page<CmSvipPackage> page, CmSvipPackage cmSvipPackage) {
+        return super.findPage(page, cmSvipPackage);
+    }
+
+    public CmSvipPackage findPackage() {
+        //1套餐12,2套餐3月,3套餐1月
+        List<CmSvipPackage> aPackage = dao.findPackage();
+        CmSvipPackage vip = new CmSvipPackage();
+        for (CmSvipPackage cmSvipPackage : aPackage) {
+            if (cmSvipPackage.getDuration().equals("12")) {
+                vip.setPrice1(cmSvipPackage.getPrice());
+            }
+            if (cmSvipPackage.getDuration().equals("3")) {
+                vip.setPrice2(cmSvipPackage.getPrice());
+            }
+            if (cmSvipPackage.getDuration().equals("1")) {
+                vip.setPrice3(cmSvipPackage.getPrice());
+            }
+            vip.setProportion(cmSvipPackage.getProportion());
+        }
+        return vip;
+    }
+
+    @Transactional(readOnly = false)
+    public void save(CmSvipPackage cmSvipPackage) {
+        super.save(cmSvipPackage);
+    }
+
+    @Transactional(readOnly = false)
+    public void update(CmSvipPackage cmSvipPackage) {
+        //1套餐12,2套餐3月,3套餐1月
+        Double price1 = Double.valueOf(cmSvipPackage.getPrice1());
+        Double price2 = Double.valueOf(cmSvipPackage.getPrice2());
+        Double price3 = Double.valueOf(cmSvipPackage.getPrice3());
+        String p = cmSvipPackage.getProportion();
+        Integer proportion = Integer.valueOf(p);
+        dao.updatePrice(price1, 12, proportion);
+        dao.updatePrice(price2, 3, proportion);
+        dao.updatePrice(price3, 1, proportion);
+    }
+
+    @Transactional(readOnly = false)
+    public void delete(CmSvipPackage cmSvipPackage) {
+        super.delete(cmSvipPackage);
+    }
 
-	public CmSvipPackage get(String id) {
-		return super.get(id);
-	}
-	
-	public List<CmSvipPackage> findList(CmSvipPackage cmSvipPackage) {
-		return super.findList(cmSvipPackage);
-	}
-	
-	public Page<CmSvipPackage> findPage(Page<CmSvipPackage> page, CmSvipPackage cmSvipPackage) {
-		return super.findPage(page, cmSvipPackage);
-	}
-	
-	@Transactional(readOnly = false)
-	public void save(CmSvipPackage cmSvipPackage) {
-		super.save(cmSvipPackage);
-	}
-	
-	@Transactional(readOnly = false)
-	public void delete(CmSvipPackage cmSvipPackage) {
-		super.delete(cmSvipPackage);
-	}
-	
 }

+ 10 - 7
src/main/java/com/caimei/modules/supers/web/CmSvipPackageController.java

@@ -46,9 +46,11 @@ public class CmSvipPackageController extends BaseController {
 
 	@RequestMapping(value = {"list", ""})
 	public String list(CmSvipPackage cmSvipPackage, HttpServletRequest request, HttpServletResponse response, Model model) {
-		Page<CmSvipPackage> page = cmSvipPackageService.findPage(new Page<CmSvipPackage>(request, response), cmSvipPackage); 
-		model.addAttribute("page", page);
-		return "modules/super/cmSvipPackageList";
+//		Page<CmSvipPackage> page = cmSvipPackageService.findPage(new Page<CmSvipPackage>(request, response), cmSvipPackage);
+//		model.addAttribute("page", page);
+		cmSvipPackage = cmSvipPackageService.findPackage();
+		model.addAttribute("cmSvipPackage",cmSvipPackage);
+		return "modules/super/cmSvipPackageForm";
 	}
 
 
@@ -59,16 +61,17 @@ public class CmSvipPackageController extends BaseController {
 	}
 
 
-	@RequestMapping(value = "save")
-	public String save(CmSvipPackage cmSvipPackage, Model model, RedirectAttributes redirectAttributes) {
+	@RequestMapping(value = "update")
+	public String update(CmSvipPackage cmSvipPackage, Model model, RedirectAttributes redirectAttributes) {
 		if (!beanValidator(model, cmSvipPackage)){
 			return form(cmSvipPackage, model);
 		}
-		cmSvipPackageService.save(cmSvipPackage);
+		cmSvipPackageService.update(cmSvipPackage);
 		addMessage(redirectAttributes, "保存超级会员套餐配置成功");
 		return "redirect:"+Global.getAdminPath()+"/super/cmSvipPackage/?repage";
 	}
-	
+
+
 
 	@RequestMapping(value = "delete")
 	public String delete(CmSvipPackage cmSvipPackage, RedirectAttributes redirectAttributes) {

+ 103 - 88
src/main/resources/mappings/modules/super/CmSvipPackageMapper.xml

@@ -1,96 +1,111 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei.modules.supers.dao.CmSvipPackageDao">
-    
-	<sql id="cmSvipPackageColumns">
-		a.id AS "id",
+
+    <sql id="cmSvipPackageColumns">
+        a.id AS "id",
 		a.name AS "name",
 		a.price AS "price",
 		a.duration AS "duration",
 		a.proportion AS "proportion"
-	</sql>
-	
-	<sql id="cmSvipPackageJoins">
-	</sql>
-    
-	<select id="get" resultType="CmSvipPackage">
-		SELECT 
-			<include refid="cmSvipPackageColumns"/>
-		FROM cm_svip_package a
-		<include refid="cmSvipPackageJoins"/>
-		WHERE a.id = #{id}
-	</select>
-	
-	<select id="findList" resultType="CmSvipPackage">
-		SELECT 
-			<include refid="cmSvipPackageColumns"/>
-		FROM cm_svip_package a
-		<include refid="cmSvipPackageJoins"/>
-		<where>
-			
-			<if test="name != null and name != ''">
-				AND a.name LIKE 
-					<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
-					<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
-					<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
-			</if>
-		</where>
-		<choose>
-			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
-				ORDER BY ${page.orderBy}
-			</when>
-			<otherwise>
-			</otherwise>
-		</choose>
-	</select>
-	
-	<select id="findAllList" resultType="CmSvipPackage">
-		SELECT 
-			<include refid="cmSvipPackageColumns"/>
-		FROM cm_svip_package a
-		<include refid="cmSvipPackageJoins"/>
-		<where>
-			
-		</where>		
-		<choose>
-			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
-				ORDER BY ${page.orderBy}
-			</when>
-			<otherwise>
-			</otherwise>
-		</choose>
-	</select>
-	
-	<insert id="insert" parameterType="CmSvipPackage"  keyProperty="id" useGeneratedKeys="true">
-		INSERT INTO cm_svip_package(
-			id,
-			name,
-			price,
-			duration,
-			delFlag,
-			proportion
-		) VALUES (
-			#{id},
-			#{name},
-			#{price},
-			#{duration},
-			0,
-			#{proportion}
-		)
-	</insert>
-	
-	<update id="update">
-		UPDATE cm_svip_package SET 	
-			name = #{name},
-			price = #{price},
-			duration = #{duration},
-			proportion = #{proportion}
-		WHERE id = #{id}
-	</update>
-	
-	<delete id="delete">
-		DELETE FROM cm_svip_package
-		WHERE id = #{id}
-	</delete>
-	
+    </sql>
+
+    <sql id="cmSvipPackageJoins">
+    </sql>
+
+    <select id="get" resultType="CmSvipPackage">
+        SELECT
+        <include refid="cmSvipPackageColumns"/>
+        FROM cm_svip_package a
+        <include refid="cmSvipPackageJoins"/>
+        WHERE a.id = #{id}
+    </select>
+
+    <select id="findList" resultType="CmSvipPackage">
+        SELECT
+        <include refid="cmSvipPackageColumns"/>
+        FROM cm_svip_package a
+        <include refid="cmSvipPackageJoins"/>
+        <where>
+
+            <if test="name != null and name != ''">
+                AND a.name LIKE
+                <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
+                <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
+                <if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
+            </if>
+        </where>
+        <choose>
+            <when test="page !=null and page.orderBy != null and page.orderBy != ''">
+                ORDER BY ${page.orderBy}
+            </when>
+            <otherwise>
+            </otherwise>
+        </choose>
+    </select>
+
+    <select id="findAllList" resultType="CmSvipPackage">
+        SELECT
+        <include refid="cmSvipPackageColumns"/>
+        FROM cm_svip_package a
+        <include refid="cmSvipPackageJoins"/>
+        <where>
+
+        </where>
+        <choose>
+            <when test="page !=null and page.orderBy != null and page.orderBy != ''">
+                ORDER BY ${page.orderBy}
+            </when>
+            <otherwise>
+            </otherwise>
+        </choose>
+    </select>
+
+    <select id="findPackage" resultType="com.caimei.modules.supers.entity.CmSvipPackage">
+        select price, duration, proportion
+        from cm_svip_package
+    </select>
+
+    <insert id="insert" parameterType="CmSvipPackage" keyProperty="id" useGeneratedKeys="true">
+        INSERT INTO cm_svip_package(id,
+                                    name,
+                                    price,
+                                    duration,
+                                    delFlag,
+                                    proportion)
+        VALUES (#{id},
+                #{name},
+                #{price},
+                #{duration},
+                0,
+                #{proportion})
+    </insert>
+
+    <update id="update">
+        UPDATE cm_svip_package
+        SET name       = #{name},
+            price      = #{price},
+            duration   = #{duration},
+            proportion = #{proportion}
+        WHERE id = #{id}
+    </update>
+
+    <update id="updatePrice">
+        update cm_svip_package
+        set
+        <if test="price != null">
+            price = #{price},
+        </if>
+        <if test="proportion != null">
+            proportion = #{proportion}
+        </if>
+        where duration = #{duration}
+    </update>
+
+    <delete id="delete">
+        DELETE
+        FROM cm_svip_package
+        WHERE id = #{id}
+    </delete>
+
 </mapper>

+ 19 - 16
src/main/webapp/WEB-INF/views/modules/super/cmSvipPackageForm.jsp

@@ -6,13 +6,12 @@
     <meta name="decorator" content="default"/>
     <script type="text/javascript">
         $(document).ready(function () {
-
             //$("#name").focus();
             $("#inputForm").validate({
                 submitHandler: function (form) {
                     var places = $(".input-xlarge").val();
                     if (!(/(^[1-9]\d*$)/.test(places))) {
-                        alert("金额应为正整数");
+                        alert("金额应为正整数,如 100");
                         return false;
                     }
                     loading('正在提交,请稍等...');
@@ -30,43 +29,47 @@
             });
         });
 
+
     </script>
 </head>
 <body>
 <ul class="nav nav-tabs">
-    <li><a href="${ctx}/super/cmSvipPackage/">超级会员套餐配置列表</a></li>
-    <li class="active"><a
-            href="${ctx}/super/cmSvipPackage/form?id=${cmSvipPackage.id}">超级会员套餐配置${not empty cmSvipPackage.id?'编辑':'添加'}查看</a>
-    </li>
+    <li><a href="${ctx}/super/cmSvipPackage/">超级会员套餐配置</a></li>
 </ul>
 <br/>
-<form:form id="inputForm" modelAttribute="cmSvipPackage" action="${ctx}/super/cmSvipPackage/save" method="post"
+<form:form id="inputForm" modelAttribute="cmSvipPackage" action="${ctx}/super/cmSvipPackage/update" method="post"
            class="form-horizontal">
     <form:hidden path="id"/>
     <sys:message content="${message}"/>
+<%--    <div class="control-group">--%>
+<%--        <label class="control-label">套餐名称:</label>--%>
+<%--        <div class="controls">--%>
+<%--            <form:input path="name" htmlEscape="false" maxlength="50" class="input-lab"/>--%>
+<%--        </div>--%>
+<%--    </div>--%>
     <div class="control-group">
-        <label class="control-label">套餐名称:</label>
+        <label class="control-label"><span class="help-inline"><font color="red">*</font> </span>套餐1:</label>
         <div class="controls">
-            <form:input path="name" htmlEscape="false" maxlength="50" class="input-lab"/>
+            12个月超级会员,售价:<form:input path="price1" htmlEscape="false" class="input-xlarge" style="width: 60px"/>
         </div>
     </div>
     <div class="control-group">
-        <label class="control-label"><span class="help-inline"><font color="red">*</font> </span>套餐价格:</label>
+        <label class="control-label"><span class="help-inline"><font color="red">*</font> </span>套餐2:</label>
         <div class="controls">
-            <form:input path="price" htmlEscape="false" class="input-xlarge"/>
+            3个月超级会员,售价:<form:input path="price2" htmlEscape="false" class="input-xlarge" style="width: 60px"/>
         </div>
     </div>
+
     <div class="control-group">
-        <label class="control-label"><span class="help-inline"><font color="red">*</font> </span>套餐时长(月):</label>
+        <label class="control-label"><span class="help-inline"><font color="red">*</font> </span>套餐3:</label>
         <div class="controls">
-            <form:input path="duration" htmlEscape="false" class="input-xlarge"/>
+            1个月超级会员,售价:<form:input path="price3" htmlEscape="false" class="input-xlarge" style="width: 60px"/>
         </div>
     </div>
-
     <div class="control-group">
-        <label class="control-label"><span class="help-inline"><font color="red">*</font> </span>采美豆现金兑换比例:</label>
+        <label class="control-label"><span class="help-inline"><font color="red">*</font> </span>采美豆兑换套餐:</label>
         <div class="controls">
-            <form:input path="proportion" htmlEscape="false" class="input-xlarge"/>
+            采美豆兑换超会员套餐比例为<form:input path="proportion" htmlEscape="false" class="input-xlarge" style="width: 30px"/>:1
         </div>
     </div>
     <div class="form-actions">