Explorar o código

呵呵商城拼团/分享减免part2

Aslee %!s(int64=3) %!d(string=hai) anos
pai
achega
ae130e5117

+ 2 - 0
src/main/java/com/caimei/modules/hehe/dao/CmHeheActivityProductDao.java

@@ -70,4 +70,6 @@ public interface CmHeheActivityProductDao extends CrudDao<CmHeheActivityProduct>
      * @param productId
      */
     void deleteUserActivity(Integer productId);
+
+    List<Integer> findCollageProductId();
 }

+ 3 - 0
src/main/java/com/caimei/modules/hehe/dao/CmHeheCollageProductDao.java

@@ -18,4 +18,7 @@ public interface CmHeheCollageProductDao extends CrudDao<CmHeheCollageProduct> {
     void updateStatus(@Param("id") Integer id,@Param("status") Integer status);
 
     List<Integer> findExistProductIds();
+
+    List<Integer> findActivityProductIds();
+
 }

+ 2 - 0
src/main/java/com/caimei/modules/hehe/dao/CmHeheReductionDao.java

@@ -21,4 +21,6 @@ public interface CmHeheReductionDao extends CrudDao<CmHeheReduction> {
     void updateTime(CmHeheReduction cmHeheReduction);
 
     List<CmHeheReductionUser> findUserList(CmHeheReductionUser cmHeheReductionUser);
+
+    List<CmHeheReduction> getAllTime();
 }

+ 3 - 0
src/main/java/com/caimei/modules/hehe/service/CmHeheActivityProductService.java

@@ -62,6 +62,9 @@ public class CmHeheActivityProductService extends CrudService<CmHeheActivityProd
 
     public Page<CmHeheProduct> findProductPage(Page<CmHeheProduct> productPage, CmHeheProduct product) {
         List<Integer> productIds = activityProductDao.findActivityProductId();
+        // 已参与拼团商品id
+        List<Integer> collageProductIds = activityProductDao.findCollageProductId();
+        productIds.addAll(collageProductIds);
         product.setIds(productIds);
         product.setPage(productPage);
         List<CmHeheProduct> productList = activityProductDao.findAllHeHeProduct(product);

+ 5 - 1
src/main/java/com/caimei/modules/hehe/service/CmHeheCollageProductService.java

@@ -61,8 +61,12 @@ public class CmHeheCollageProductService extends CrudService<CmHeheCollageProduc
     public Page<Product> findProductList(Page<Product> productPage, Product product) {
 		product.setPage(productPage);
 		product.setSearchType(2);
+		// 已参与拼团商品id
 		List<Integer> productIds = cmHeheCollageProductDao.findExistProductIds();
-		product.setIds(productIds);
+		// 已参与商品活动商品id
+		List<Integer> actProductIds = cmHeheCollageProductDao.findActivityProductIds();
+		productIds.addAll(actProductIds);
+		product.setProductIdList(productIds);
 		List<Product> productList = cmHeheFloorProductDao.findAllProduct(product);
 		if (productList != null && productList.size() > 0) {
 			productList.forEach(item -> {

+ 21 - 1
src/main/java/com/caimei/modules/hehe/service/CmHeheReductionService.java

@@ -5,6 +5,7 @@ import java.util.List;
 
 import com.caimei.modules.hehe.entity.CmHeheReduction;
 import com.caimei.modules.hehe.entity.CmHeheReductionUser;
+import com.thinkgem.jeesite.common.utils.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -45,7 +46,26 @@ public class CmHeheReductionService extends CrudService<CmHeheReductionDao, CmHe
 	public void save(CmHeheReduction cmHeheReduction) {
 		super.save(cmHeheReduction);
 	}
-	
+
+	/**
+	 * 保证一个时间只存在唯一的活动
+	 * @return
+	 */
+	public Boolean checkTime(String reductionId, Date startTime1, Date endTime1) {
+		List<CmHeheReduction> allTimeList = cmHeheReductionDao.getAllTime();
+		for (int i = 0; i < allTimeList.size(); i++) {
+			CmHeheReduction time = allTimeList.get(i);
+			Date startTime2 = time.getStartTime();
+			Date endTime2 = time.getEndTime();
+			boolean sameTimeFlag = (startTime1.compareTo(startTime2) <= 0 && endTime1.compareTo(startTime2) >= 0)
+					|| (startTime2.compareTo(startTime1) <= 0 && endTime2.compareTo(startTime1) >= 0);
+			if (sameTimeFlag && !(StringUtils.isNotEmpty(reductionId) && reductionId.equals(time.getId()))) {
+				return false;
+			}
+		}
+		return true;
+	}
+
 	@Transactional(readOnly = false)
 	public void delete(CmHeheReduction cmHeheReduction) {
 		super.delete(cmHeheReduction);

+ 15 - 0
src/main/java/com/caimei/modules/hehe/web/CmHeheReductionController.java

@@ -24,6 +24,7 @@ import com.thinkgem.jeesite.common.utils.StringUtils;
 import com.caimei.modules.hehe.entity.CmHeheReduction;
 import com.caimei.modules.hehe.service.CmHeheReductionService;
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -108,4 +109,18 @@ public class CmHeheReductionController extends BaseController {
 		return "modules/hehe/cmHeheReductionUserList";
 	}
 
+	@RequestMapping(value = "checkTime")
+	@ResponseBody
+	public Map<String, Object> checkTime(String reductionId, Date startTime, Date endTime) {
+		HashMap<String, Object> map = new HashMap<>(2);
+		Boolean result = cmHeheReductionService.checkTime(reductionId, startTime, endTime);
+		if (result) {
+			map.put("success", true);
+		} else {
+			map.put("success", false);
+			map.put("msg", "当前上下架时间活动已存在");
+		}
+		return map;
+	}
+
 }

+ 9 - 0
src/main/java/com/caimei/modules/product/entity/Product.java

@@ -126,6 +126,7 @@ public class Product extends DataEntity<Product> {
     private Integer trainingType; //售价是否包含:1售价未包含,2售价已包含
     private BigDecimal trainingFee; //培训费用(售价未包含)
     private Integer svipFlag;	//超级会员商品标识:1是,2不是
+    private List<Integer> productIdList;//商品id列表
 
     //以下参数是搜索回显参数
     private String searchName;
@@ -1842,4 +1843,12 @@ public class Product extends DataEntity<Product> {
     public void setSearchType(Integer searchType) {
         this.searchType = searchType;
     }
+
+    public List<Integer> getProductIdList() {
+        return productIdList;
+    }
+
+    public void setProductIdList(List<Integer> productIdList) {
+        this.productIdList = productIdList;
+    }
 }

+ 2 - 2
src/main/resources/mappings/modules/baike/CmBaikeProductMapper.xml

@@ -48,7 +48,7 @@
 			<include refid="cmBaikeProductColumns"/>
 		FROM cm_baike_product a
 		<include refid="cmBaikeProductJoins"/>
-		WHERE a.id = #{id}
+		WHERE a.id = #{id} and delFlag = 0
 	</select>
 	
 	<select id="findList" resultType="CmBaikeProduct">
@@ -57,7 +57,7 @@
 		FROM cm_baike_product a
 		<include refid="cmBaikeProductJoins"/>
 		<where>
-			
+			delFlag = 0
 			<if test="id != null and id != ''">
 				AND a.id = #{id}
 			</if>

+ 4 - 1
src/main/resources/mappings/modules/hehe/CmHeheActivityProductMapper.xml

@@ -179,8 +179,11 @@
 	<select id="findActivityByProductId" resultType="integer">
 		SELECT activityId FROM cm_hehe_activity_product WHERE productId = #{productId} AND delFlag = 0
 	</select>
+    <select id="findCollageProductId" resultType="java.lang.Integer">
+		select chp.productId from cm_hehe_collage_product chcp left join cm_hehe_product chp on chcp.productId = chp.id
+	</select>
 
-	<delete id="deleteUserActivity">
+    <delete id="deleteUserActivity">
 		DELETE FROM cm_hehe_user_activity WHERE productId = #{productId}
 	</delete>
 

+ 4 - 3
src/main/resources/mappings/modules/hehe/CmHeheCollageMapper.xml

@@ -16,8 +16,8 @@
 	</sql>
 	
 	<sql id="cmHeheCollageJoins">
-		left join cm_hehe_product hp on a.productId = hp.id
-		left join product p on hp.productId = p.productID
+		left join product p on a.productId = p.productID
+		left join cm_hehe_product hp on p.productID = hp.productId
 		left join shop s on p.shopID = s.shopID
 	</sql>
     
@@ -81,7 +81,8 @@
 	<select id="findMemberList" resultType="com.caimei.modules.hehe.entity.CmHeheCollageMember">
 		select chu.nickName,cm.launchFlag,chu.mobile,chu.userIdentity,co.orderTime,co.orderNo
 		from cm_hehe_collage_member cm
-		left join cm_hehe_user chu on cm.userId = chu.userId
+		left join user u on cm.userId = u.userID
+		left join cm_hehe_user chu on u.userID = chu.userId
 		left join cm_order co on cm.orderId = co.orderID
 		where collageId = #{collageId}
 		<if test="nickName != null and nickName != ''">

+ 9 - 4
src/main/resources/mappings/modules/hehe/CmHeheCollageProductMapper.xml

@@ -17,8 +17,8 @@
 	</sql>
 	
 	<sql id="cmHeheCollageProductJoins">
-		left join cm_hehe_product hp on a.productId = hp.id
-		left join product p on hp.productId = p.productID
+		left join product p on a.productId = p.productID
+		left join cm_hehe_product hp on p.productID = hp.productId
 		left join shop s on p.shopID = s.shopID
 	</sql>
     
@@ -78,6 +78,11 @@
 	<select id="findExistProductIds" resultType="java.lang.String">
 		select productId from cm_hehe_collage_product;
 	</select>
+	<select id="findActivityProductIds" resultType="java.lang.Integer">
+		select chp.id
+		from cm_hehe_activity_product chap
+				 left join cm_hehe_product chp on chap.productId = chp.productId;
+	</select>
 
 	<insert id="insert" parameterType="CmHeheCollageProduct"  keyProperty="id" useGeneratedKeys="true">
 		INSERT INTO cm_hehe_collage_product(
@@ -89,7 +94,7 @@
 			status,
 			addTime
 		) VALUES (
-			#{productId},
+			(select productId from cm_hehe_product where id = #{productId}),
 			#{price},
 			#{limitedNum},
 			#{unlimitedFlag},
@@ -101,7 +106,7 @@
 	
 	<update id="update">
 		UPDATE cm_hehe_collage_product SET 	
-			productId = #{productId},
+			productId = (select productId from cm_hehe_product where id = #{productId}),
 			price = #{price},
 			limitedNum = #{limitedNum},
 			unlimitedFlag = #{unlimitedFlag},

+ 6 - 0
src/main/resources/mappings/modules/hehe/CmHeheFloorProductMapper.xml

@@ -115,6 +115,12 @@
 					#{id}
 				</foreach>
 			</if>
+			<if test="productIdList != null and productIdList.size() > 0 ">
+				AND p.productID NOT IN
+				<foreach collection="productIdList" open="(" close=")" item="id" separator=",">
+					#{id}
+				</foreach>
+			</if>
 		</where>
 		<choose>
 			<when test="page !=null and page.orderBy != null and page.orderBy != ''">

+ 6 - 2
src/main/resources/mappings/modules/hehe/CmHeheReductionMapper.xml

@@ -78,7 +78,8 @@
     <select id="findUserList" resultType="com.caimei.modules.hehe.entity.CmHeheReductionUser">
         select ru.id,chu.nickName,chu.mobile,ru.shareType,ru.shareTime
         from cm_hehe_reduction_user ru
-            left join cm_hehe_user chu on ru.userId = chu.id
+			left join user u on ru.userId = u.userID
+			left join cm_hehe_user chu on u.userID = chu.userId
         where reductionId = #{reductionId}
         <if test="nickName != null and nickName != ''">
             and chu.nickName like concat('%',#{nickName},'%')
@@ -91,8 +92,11 @@
         </if>
         order by shareTime desc
     </select>
+	<select id="getAllTime" resultType="com.caimei.modules.hehe.entity.CmHeheReduction">
+		select id, startTime,endTime from cm_hehe_reduction;
+	</select>
 
-    <insert id="insert" parameterType="CmHeheReduction"  keyProperty="id" useGeneratedKeys="true">
+	<insert id="insert" parameterType="CmHeheReduction"  keyProperty="id" useGeneratedKeys="true">
 		INSERT INTO cm_hehe_reduction(
 			name,
 			reducedAmount,

+ 0 - 1
src/main/webapp/WEB-INF/views/modules/baike/cmBaikeProductForm.jsp

@@ -154,7 +154,6 @@
 			//$("#name").focus();
 			$("#inputForm").validate({
 				submitHandler: function(form){
-					debugger
 					var commodityType = '${commodityType}';
 					var mainImage = $("#image").val();
 					var authImage0 = $("#authImage0").val() == undefined?'':$("#authImage0").val();

+ 11 - 2
src/main/webapp/WEB-INF/views/modules/hehe/cmHeheReductionForm.jsp

@@ -21,8 +21,17 @@
 						alertx("下架时间不能早于上架时间");
 						return false;
 					}
-					loading('正在提交,请稍等...');
-					form.submit();
+					var reductionId = $("#id").val();
+					// 检查时间是否与其他活动时间重叠
+					$.post('${ctx}/hehe/cmHeheReduction/checkTime?startTime=' + startTime + '&endTime=' + endTime + '&reductionId=' + reductionId,function (data) {
+						if (!data.success) {
+							alertx(data.msg);
+							return false;
+						} else {
+							loading('正在提交,请稍等...');
+							form.submit();
+						}
+					});
 				},
 				errorContainer: "#messageBox",
 				errorPlacement: function(error, element) {

+ 13 - 5
src/main/webapp/WEB-INF/views/modules/hehe/cmHeheReductionList.jsp

@@ -151,11 +151,19 @@
 								top.$.jBox.tip("请选择下架时间");
 								return false;
 							}
-							$.post("${ctx}/hehe/cmHeheReduction/updateTime?id="+reductionId+"&startTime=" + startTime + "&endTime=" + endTime, function (data) {
-								top.$.jBox.tip("修改成功");
-								setTimeout(function () {
-									$("#searchForm").submit();
-								}, 1000);
+							// 检查时间是否与其他活动时间重叠
+							$.post('${ctx}/hehe/cmHeheReduction/checkTime?startTime=' + startTime + '&endTime=' + endTime + '&reductionId=' + reductionId,function (data) {
+								if (!data.success) {
+									top.$.jBox.tip(data.msg);
+									return false;
+								} else {
+									$.post("${ctx}/hehe/cmHeheReduction/updateTime?id="+reductionId+"&startTime=" + startTime + "&endTime=" + endTime, function (data) {
+										top.$.jBox.tip("修改成功");
+										setTimeout(function () {
+											$("#searchForm").submit();
+										}, 1000);
+									});
+								}
 							});
 						} else {
 							top.$.jBox.tip("请先勾选商品...");