diff --git a/document/pdm/mall.pdb b/document/pdm/mall.pdb index f490608..a47672a 100644 --- a/document/pdm/mall.pdb +++ b/document/pdm/mall.pdb @@ -1,5 +1,5 @@ - + @@ -11087,10 +11087,10 @@ LABL 0 新宋体,8,N platform 1522215086 zhenghong -1522215279 +1535445907 zhenghong 使用平台:0->全部;1->移动;2->PC -varchar(1) +int(1) 1 @@ -11413,9 +11413,10 @@ LABL 0 新宋体,8,N id 1522217090 zhenghong -1522217131 +1535522371 zhenghong bigint +1 1 diff --git a/document/pdm/mall.pdm b/document/pdm/mall.pdm index 6976e88..52e8e9d 100644 --- a/document/pdm/mall.pdm +++ b/document/pdm/mall.pdm @@ -1,5 +1,5 @@ - + @@ -11413,9 +11413,10 @@ LABL 0 新宋体,8,N id 1522217090 zhenghong -1522217131 +1535522371 zhenghong bigint +1 1 @@ -15439,7 +15440,7 @@ LABL 0 新宋体,8,N oms_cart_item 1533108597 zhenghong -1533172443 +1535530955 zhenghong 购物车表 @@ -15641,9 +15642,20 @@ LABL 0 新宋体,8,N int(1) 1 + +9C9C2AC9-F58B-4D31-BEF4-1D1892931E51 +product_category_id +product_category_id +1535530934 +zhenghong +1535530961 +zhenghong +商品的分类 +bigint + - + 29D735B7-E618-4C13-AF03-3858C68E6BA4 Key_1 Key_1 @@ -15657,7 +15669,7 @@ LABL 0 新宋体,8,N - + @@ -15683,7 +15695,7 @@ LABL 0 新宋体,8,N - + 5236F74C-2761-4AC4-834A-BECC5D040393 1521706257 zhenghong @@ -15719,7 +15731,7 @@ LABL 0 新宋体,8,N - + 6EE78803-E5F6-4090-B810-7BBF7814F60C 1521710488 zhenghong @@ -15755,7 +15767,7 @@ LABL 0 新宋体,8,N - + 84F722B4-DF57-4BC3-88FD-B249B70D21A7 1521770349 zhenghong @@ -15791,7 +15803,7 @@ LABL 0 新宋体,8,N - + 0309D83E-51C3-4973-A636-9FEB27F4A6B6 1521771362 zhenghong @@ -15827,7 +15839,7 @@ LABL 0 新宋体,8,N - + 7B820697-9FFD-4446-B6DF-F03F4F02FFE3 1521773101 zhenghong @@ -15863,7 +15875,7 @@ LABL 0 新宋体,8,N - + 13DDC5F6-372D-47FF-AAFA-8AEF349E7FA8 1521783613 zhenghong @@ -15899,7 +15911,7 @@ LABL 0 新宋体,8,N - + 31ADEBC6-F176-41A7-8EAA-9AC3B8A253AB 1521791466 zhenghong @@ -15935,7 +15947,7 @@ LABL 0 新宋体,8,N - + F2B169B3-7AC8-4FB1-822D-E1C91DFF6FFD 1521792428 zhenghong @@ -15971,7 +15983,7 @@ LABL 0 新宋体,8,N - + 00AD7B43-F4CA-45D7-86BB-5756B4ED55BD 1521792909 zhenghong @@ -16007,7 +16019,7 @@ LABL 0 新宋体,8,N - + 286E06C6-6FAD-4323-82D9-6FB781153C46 1522045168 zhenghong @@ -16043,7 +16055,7 @@ LABL 0 新宋体,8,N - + A2161167-D453-4661-9BF0-71D8908A6C42 1522046100 zhenghong @@ -16079,7 +16091,7 @@ LABL 0 新宋体,8,N - + E25FF0B6-41E2-4801-8FE9-337EF9B991F7 1522046451 zhenghong @@ -16115,7 +16127,7 @@ LABL 0 新宋体,8,N - + 1E64FE44-48BA-49B0-BDE1-66DA22B89EFF 1522046456 zhenghong @@ -16151,7 +16163,7 @@ LABL 0 新宋体,8,N - + DEE74089-6A6D-4D7E-BADD-76E4D08EFA2D 1522112691 zhenghong @@ -16187,7 +16199,7 @@ LABL 0 新宋体,8,N - + 5D44A212-AD69-4958-BAAF-9E16ED63FC67 1522112694 zhenghong @@ -16223,7 +16235,7 @@ LABL 0 新宋体,8,N - + ECA8F78C-7015-44EB-9CD2-F72634D7F4BD 1522114406 zhenghong @@ -16259,7 +16271,7 @@ LABL 0 新宋体,8,N - + 32BD37D4-4436-4069-9BD1-90CF0B1867E0 1522115961 zhenghong @@ -16295,7 +16307,7 @@ LABL 0 新宋体,8,N - + 1A23B754-71EE-4496-B70F-0A3268C6F651 1522115983 zhenghong @@ -16331,7 +16343,7 @@ LABL 0 新宋体,8,N - + 1C883E67-84F9-4CD0-A4F5-D7CA2BE15DC5 1522118676 zhenghong @@ -16367,7 +16379,7 @@ LABL 0 新宋体,8,N - + 1CE2FCCB-DF37-4C88-99DD-FA8C3EE7A09C 1522119056 zhenghong @@ -16403,7 +16415,7 @@ LABL 0 新宋体,8,N - + 7D8DC4F2-D0A4-4CE9-B03E-44AE166786C0 1522120295 zhenghong @@ -16439,7 +16451,7 @@ LABL 0 新宋体,8,N - + 7CB99F50-753B-4347-B896-1F18D8FE6691 1522138613 zhenghong @@ -16475,7 +16487,7 @@ LABL 0 新宋体,8,N - + EC89DA87-A575-4940-973B-665854268261 1522138618 zhenghong @@ -16511,7 +16523,7 @@ LABL 0 新宋体,8,N - + 8E1A22EC-2246-48C4-A499-3D8A4D264C09 1522138705 zhenghong @@ -16547,7 +16559,7 @@ LABL 0 新宋体,8,N - + 2EA7348D-C8E8-4FCC-8215-01FE3AD58DFB 1522141157 zhenghong @@ -16583,7 +16595,7 @@ LABL 0 新宋体,8,N - + 8B858AAC-D00A-42FE-BEDC-73536876C045 1522141232 zhenghong @@ -16619,7 +16631,7 @@ LABL 0 新宋体,8,N - + FC3A22FE-FD24-4DF0-BAC8-22659D3C8987 1522141317 zhenghong @@ -16655,7 +16667,7 @@ LABL 0 新宋体,8,N - + 14DB9C0C-F9F0-4D4A-B44E-592028F6E75A 1522142006 zhenghong @@ -16691,7 +16703,7 @@ LABL 0 新宋体,8,N - + 15304E84-71AA-40B1-84CB-904384B34B25 1522215975 zhenghong @@ -16727,7 +16739,7 @@ LABL 0 新宋体,8,N - + 457237AD-87EB-4A09-BA9F-36198B10D2FF 1522216015 zhenghong @@ -16763,7 +16775,7 @@ LABL 0 新宋体,8,N - + 3C2E5F27-A07C-4D88-9357-089D36122A25 1522216251 zhenghong @@ -16799,7 +16811,7 @@ LABL 0 新宋体,8,N - + A8FA4798-0F1E-4D96-A254-77F5D71F6BBD 1522216380 zhenghong @@ -16835,7 +16847,7 @@ LABL 0 新宋体,8,N - + 5026171A-4B51-4B83-A113-4051F1E4F415 1522220508 zhenghong @@ -16871,7 +16883,7 @@ LABL 0 新宋体,8,N - + 462222B9-A203-4D60-A353-A168356E3140 1522220546 zhenghong @@ -16907,7 +16919,7 @@ LABL 0 新宋体,8,N - + BD28F911-4F98-4C9D-9171-E99F60476E2A 1522224364 zhenghong @@ -16943,7 +16955,7 @@ LABL 0 新宋体,8,N - + 8D1675C9-7749-4831-A5E6-ACD971AACF57 1522225874 zhenghong @@ -16979,7 +16991,7 @@ LABL 0 新宋体,8,N - + B30347B3-4138-4EA8-A0F5-EF0D9A34E01F 1522226077 zhenghong @@ -17015,7 +17027,7 @@ LABL 0 新宋体,8,N - + 7D29D8DF-7EF1-4F43-928F-DDAC96A23858 1522226272 zhenghong @@ -17051,7 +17063,7 @@ LABL 0 新宋体,8,N - + EB0A7FB4-285A-4D5D-BC1D-E9B299069C1F 1522301998 zhenghong @@ -17087,7 +17099,7 @@ LABL 0 新宋体,8,N - + 942BBD31-85B8-46EA-893C-CB327C86F5BA 1522303390 zhenghong @@ -17123,7 +17135,7 @@ LABL 0 新宋体,8,N - + 1E5174EE-C0B0-4144-98D5-679634DCCAEE 1522303410 zhenghong @@ -17159,7 +17171,7 @@ LABL 0 新宋体,8,N - + BD55704C-3F36-44CC-90E1-143F097FA894 1522304178 zhenghong @@ -17195,7 +17207,7 @@ LABL 0 新宋体,8,N - + 17EC5CAA-580C-493D-9C2D-2EA3E9732A78 1522386868 zhenghong @@ -17231,7 +17243,7 @@ LABL 0 新宋体,8,N - + F469B162-D88C-42A3-B64C-7B2751A4FCE1 1522387461 zhenghong @@ -17267,7 +17279,7 @@ LABL 0 新宋体,8,N - + 1D18BF30-4375-4618-A1C9-6DC998F248E4 1522387526 zhenghong @@ -17303,7 +17315,7 @@ LABL 0 新宋体,8,N - + 183F9969-663E-4842-ABC2-C938F02C05E4 1522389232 zhenghong @@ -17339,7 +17351,7 @@ LABL 0 新宋体,8,N - + AC355266-228D-4333-8E95-D13F2D176DB4 1522390434 zhenghong @@ -17375,7 +17387,7 @@ LABL 0 新宋体,8,N - + 3A358827-AE90-4AC6-80E6-CA340D69F7F2 1522390644 zhenghong @@ -17411,7 +17423,7 @@ LABL 0 新宋体,8,N - + B0F12E0B-F2E6-40A6-AD2B-9FE858AAA8BE 1522391366 zhenghong @@ -17447,7 +17459,7 @@ LABL 0 新宋体,8,N - + F46C48A9-78A1-4C9A-BD75-DE0ED230A76D 1522391379 zhenghong @@ -17483,7 +17495,7 @@ LABL 0 新宋体,8,N - + 711AD4D5-212E-4E3B-BB26-DB79C4BE4E52 1522396648 zhenghong @@ -17519,7 +17531,7 @@ LABL 0 新宋体,8,N - + 094B7BE5-D0AB-4987-8D74-508A27D3117F 1522396864 zhenghong @@ -17555,7 +17567,7 @@ LABL 0 新宋体,8,N - + 8C15D427-62A0-40E7-9B02-84063CC6EB94 1522659209 zhenghong @@ -17591,7 +17603,7 @@ LABL 0 新宋体,8,N - + 043B7E7F-6688-42FD-BECE-3A4CE5A560F2 1522660753 zhenghong @@ -17627,7 +17639,7 @@ LABL 0 新宋体,8,N - + 3592DAA0-2C95-48CF-9359-C157A0E27DC3 1522660820 zhenghong @@ -17663,7 +17675,7 @@ LABL 0 新宋体,8,N - + BEE8D279-8DBF-40B3-899D-5B07570D0AD9 1522721755 zhenghong @@ -17699,7 +17711,7 @@ LABL 0 新宋体,8,N - + F5D0566A-35C3-4451-9C7D-782BC776C53E 1522724329 zhenghong @@ -17735,7 +17747,7 @@ LABL 0 新宋体,8,N - + 3AA8813B-9363-406A-91DF-4AD16E9C3CCA 1522725331 zhenghong @@ -17771,7 +17783,7 @@ LABL 0 新宋体,8,N - + DD05624A-7E08-4273-9758-C5EDA1A03134 1522733188 zhenghong @@ -17807,7 +17819,7 @@ LABL 0 新宋体,8,N - + EBF8A4B9-24B3-4D18-82FD-D12F847328C6 1522745521 zhenghong @@ -17843,7 +17855,7 @@ LABL 0 新宋体,8,N - + BA7665F0-D173-45C6-AFE8-3C93CF330D79 1533109970 zhenghong @@ -17879,7 +17891,7 @@ LABL 0 新宋体,8,N - + 521484A5-B9C4-477D-8D45-97F7B15D7854 1533115829 zhenghong @@ -17915,7 +17927,7 @@ LABL 0 新宋体,8,N - + FCADB7B3-0636-44C7-8AB4-067148971867 1533115896 zhenghong @@ -17932,7 +17944,7 @@ LABL 0 新宋体,8,N - + 48492A0F-63AD-4453-B46B-89915CC87545 PUBLIC PUBLIC @@ -17943,7 +17955,7 @@ LABL 0 新宋体,8,N - + 232AA7B8-E743-48F3-9530-102684B229BE MySQL 5.0 MYSQL50 diff --git a/mall-admin/src/main/java/com/macro/mall/controller/SmsCouponController.java b/mall-admin/src/main/java/com/macro/mall/controller/SmsCouponController.java index 3e2d27f..1cdb801 100644 --- a/mall-admin/src/main/java/com/macro/mall/controller/SmsCouponController.java +++ b/mall-admin/src/main/java/com/macro/mall/controller/SmsCouponController.java @@ -66,4 +66,12 @@ public class SmsCouponController { List couponList = couponService.list(name,type,pageSize,pageNum); return new CommonResult().pageSuccess(couponList); } + + @ApiOperation("获取单个优惠券的详细信息") + @RequestMapping(value = "/{id}", method = RequestMethod.GET) + @ResponseBody + public Object getItem(@PathVariable Long id) { + SmsCouponParam couponParam = couponService.getItem(id); + return new CommonResult().success(couponParam); + } } diff --git a/mall-admin/src/main/java/com/macro/mall/dao/SmsCouponDao.java b/mall-admin/src/main/java/com/macro/mall/dao/SmsCouponDao.java new file mode 100644 index 0000000..3c57ad0 --- /dev/null +++ b/mall-admin/src/main/java/com/macro/mall/dao/SmsCouponDao.java @@ -0,0 +1,12 @@ +package com.macro.mall.dao; + +import com.macro.mall.dto.SmsCouponParam; +import org.apache.ibatis.annotations.Param; + +/** + * 优惠券管理自定义查询Dao + * Created by macro on 2018/8/29. + */ +public interface SmsCouponDao { + SmsCouponParam getItem(@Param("id") Long id); +} diff --git a/mall-admin/src/main/java/com/macro/mall/service/SmsCouponService.java b/mall-admin/src/main/java/com/macro/mall/service/SmsCouponService.java index 05ed595..7155733 100644 --- a/mall-admin/src/main/java/com/macro/mall/service/SmsCouponService.java +++ b/mall-admin/src/main/java/com/macro/mall/service/SmsCouponService.java @@ -33,4 +33,10 @@ public interface SmsCouponService { * 分页获取优惠券列表 */ List list(String name, Integer type, Integer pageSize, Integer pageNum); + + /** + * 获取优惠券详情 + * @param id 优惠券表id + */ + SmsCouponParam getItem(Long id); } diff --git a/mall-admin/src/main/java/com/macro/mall/service/impl/SmsCouponServiceImpl.java b/mall-admin/src/main/java/com/macro/mall/service/impl/SmsCouponServiceImpl.java index 81a69c7..0424f4b 100644 --- a/mall-admin/src/main/java/com/macro/mall/service/impl/SmsCouponServiceImpl.java +++ b/mall-admin/src/main/java/com/macro/mall/service/impl/SmsCouponServiceImpl.java @@ -1,6 +1,7 @@ package com.macro.mall.service.impl; import com.github.pagehelper.PageHelper; +import com.macro.mall.dao.SmsCouponDao; import com.macro.mall.dao.SmsCouponProductCategoryRelationDao; import com.macro.mall.dao.SmsCouponProductRelationDao; import com.macro.mall.dto.SmsCouponParam; @@ -31,6 +32,8 @@ public class SmsCouponServiceImpl implements SmsCouponService { private SmsCouponProductRelationDao productRelationDao; @Autowired private SmsCouponProductCategoryRelationDao productCategoryRelationDao; + @Autowired + private SmsCouponDao couponDao; @Override public int add(SmsCouponParam couponParam) { //插入优惠券表 @@ -112,4 +115,9 @@ public class SmsCouponServiceImpl implements SmsCouponService { PageHelper.startPage(pageNum,pageSize); return couponMapper.selectByExample(example); } + + @Override + public SmsCouponParam getItem(Long id) { + return couponDao.getItem(id); + } } diff --git a/mall-admin/src/main/resources/dao/SmsCouponDao.xml b/mall-admin/src/main/resources/dao/SmsCouponDao.xml new file mode 100644 index 0000000..a23dfd7 --- /dev/null +++ b/mall-admin/src/main/resources/dao/SmsCouponDao.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/mall-mbg/src/main/java/com/macro/mall/model/OmsCartItem.java b/mall-mbg/src/main/java/com/macro/mall/model/OmsCartItem.java index b423116..0852d65 100644 --- a/mall-mbg/src/main/java/com/macro/mall/model/OmsCartItem.java +++ b/mall-mbg/src/main/java/com/macro/mall/model/OmsCartItem.java @@ -104,6 +104,13 @@ public class OmsCartItem implements Serializable { */ private Integer deleteStatus; + /** + * 商品分类 + * + * @mbggenerated + */ + private Long productCategoryId; + private static final long serialVersionUID = 1L; public Long getId() { @@ -242,6 +249,14 @@ public class OmsCartItem implements Serializable { this.deleteStatus = deleteStatus; } + public Long getProductCategoryId() { + return productCategoryId; + } + + public void setProductCategoryId(Long productCategoryId) { + this.productCategoryId = productCategoryId; + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); @@ -265,6 +280,7 @@ public class OmsCartItem implements Serializable { sb.append(", createDate=").append(createDate); sb.append(", modifyDate=").append(modifyDate); sb.append(", deleteStatus=").append(deleteStatus); + sb.append(", productCategoryId=").append(productCategoryId); sb.append(", serialVersionUID=").append(serialVersionUID); sb.append("]"); return sb.toString(); diff --git a/mall-mbg/src/main/java/com/macro/mall/model/OmsCartItemExample.java b/mall-mbg/src/main/java/com/macro/mall/model/OmsCartItemExample.java index 7910b2d..54f2b06 100644 --- a/mall-mbg/src/main/java/com/macro/mall/model/OmsCartItemExample.java +++ b/mall-mbg/src/main/java/com/macro/mall/model/OmsCartItemExample.java @@ -1205,6 +1205,66 @@ public class OmsCartItemExample { addCriterion("delete_status not between", value1, value2, "deleteStatus"); return (Criteria) this; } + + public Criteria andProductCategoryIdIsNull() { + addCriterion("product_category_id is null"); + return (Criteria) this; + } + + public Criteria andProductCategoryIdIsNotNull() { + addCriterion("product_category_id is not null"); + return (Criteria) this; + } + + public Criteria andProductCategoryIdEqualTo(Long value) { + addCriterion("product_category_id =", value, "productCategoryId"); + return (Criteria) this; + } + + public Criteria andProductCategoryIdNotEqualTo(Long value) { + addCriterion("product_category_id <>", value, "productCategoryId"); + return (Criteria) this; + } + + public Criteria andProductCategoryIdGreaterThan(Long value) { + addCriterion("product_category_id >", value, "productCategoryId"); + return (Criteria) this; + } + + public Criteria andProductCategoryIdGreaterThanOrEqualTo(Long value) { + addCriterion("product_category_id >=", value, "productCategoryId"); + return (Criteria) this; + } + + public Criteria andProductCategoryIdLessThan(Long value) { + addCriterion("product_category_id <", value, "productCategoryId"); + return (Criteria) this; + } + + public Criteria andProductCategoryIdLessThanOrEqualTo(Long value) { + addCriterion("product_category_id <=", value, "productCategoryId"); + return (Criteria) this; + } + + public Criteria andProductCategoryIdIn(List values) { + addCriterion("product_category_id in", values, "productCategoryId"); + return (Criteria) this; + } + + public Criteria andProductCategoryIdNotIn(List values) { + addCriterion("product_category_id not in", values, "productCategoryId"); + return (Criteria) this; + } + + public Criteria andProductCategoryIdBetween(Long value1, Long value2) { + addCriterion("product_category_id between", value1, value2, "productCategoryId"); + return (Criteria) this; + } + + public Criteria andProductCategoryIdNotBetween(Long value1, Long value2) { + addCriterion("product_category_id not between", value1, value2, "productCategoryId"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/mall-mbg/src/main/resources/com/macro/mall/mapper/OmsCartItemMapper.xml b/mall-mbg/src/main/resources/com/macro/mall/mapper/OmsCartItemMapper.xml index 366e743..f2145f6 100644 --- a/mall-mbg/src/main/resources/com/macro/mall/mapper/OmsCartItemMapper.xml +++ b/mall-mbg/src/main/resources/com/macro/mall/mapper/OmsCartItemMapper.xml @@ -19,6 +19,7 @@ + @@ -81,7 +82,7 @@ id, product_id, product_sku_id, member_id, quantity, price, sp1, sp2, sp3, product_pic, product_name, product_sub_title, product_sku_code, member_nickname, create_date, - modify_date, delete_status + modify_date, delete_status, product_category_id @@ -296,6 +303,9 @@ delete_status = #{record.deleteStatus,jdbcType=INTEGER}, + + product_category_id = #{record.productCategoryId,jdbcType=BIGINT}, + @@ -319,7 +329,8 @@ member_nickname = #{record.memberNickname,jdbcType=VARCHAR}, create_date = #{record.createDate,jdbcType=TIMESTAMP}, modify_date = #{record.modifyDate,jdbcType=TIMESTAMP}, - delete_status = #{record.deleteStatus,jdbcType=INTEGER} + delete_status = #{record.deleteStatus,jdbcType=INTEGER}, + product_category_id = #{record.productCategoryId,jdbcType=BIGINT} @@ -375,6 +386,9 @@ delete_status = #{deleteStatus,jdbcType=INTEGER}, + + product_category_id = #{productCategoryId,jdbcType=BIGINT}, + where id = #{id,jdbcType=BIGINT} @@ -395,7 +409,8 @@ member_nickname = #{memberNickname,jdbcType=VARCHAR}, create_date = #{createDate,jdbcType=TIMESTAMP}, modify_date = #{modifyDate,jdbcType=TIMESTAMP}, - delete_status = #{deleteStatus,jdbcType=INTEGER} + delete_status = #{deleteStatus,jdbcType=INTEGER}, + product_category_id = #{productCategoryId,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT} \ No newline at end of file diff --git a/mall-portal/src/main/java/com/macro/mall/portal/controller/UmsMemberCouponController.java b/mall-portal/src/main/java/com/macro/mall/portal/controller/UmsMemberCouponController.java new file mode 100644 index 0000000..9ebfbf8 --- /dev/null +++ b/mall-portal/src/main/java/com/macro/mall/portal/controller/UmsMemberCouponController.java @@ -0,0 +1,61 @@ +package com.macro.mall.portal.controller; + +import com.macro.mall.model.SmsCouponHistory; +import com.macro.mall.portal.domain.CartPromotionItem; +import com.macro.mall.portal.domain.CommonResult; +import com.macro.mall.portal.domain.SmsCouponHistoryDetail; +import com.macro.mall.portal.service.OmsCartItemService; +import com.macro.mall.portal.service.UmsMemberCouponService; +import com.macro.mall.portal.service.UmsMemberService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 用户优惠券管理Controller + * Created by macro on 2018/8/29. + */ +@Controller +@Api(tags = "UmsMemberCouponController", description = "用户优惠券管理") +@RequestMapping("/member/coupon") +public class UmsMemberCouponController { + @Autowired + private UmsMemberCouponService memberCouponService; + @Autowired + private OmsCartItemService cartItemService; + @Autowired + private UmsMemberService memberService; + + @ApiOperation("领取指定优惠券") + @RequestMapping(value = "/add/{couponId}", method = RequestMethod.POST) + @ResponseBody + public Object add(@PathVariable Long couponId) { + return memberCouponService.add(couponId); + } + + @ApiOperation("获取用户优惠券列表") + @ApiImplicitParam(name = "useStatus", value = "优惠券筛选类型:0->未使用;1->已使用;2->已过期", + allowableValues = "0,1,2", paramType = "query", dataType = "integer") + @RequestMapping(value = "/list", method = RequestMethod.GET) + @ResponseBody + public Object list(@RequestParam(value = "useStatus", required = false) Integer useStatus) { + List couponHistoryList = memberCouponService.list(useStatus); + return new CommonResult().success(couponHistoryList); + } + + @ApiOperation("获取登录会员购物车的相关优惠券") + @ApiImplicitParam(name = "type", value = "使用可用:0->不可用;1->可用", + defaultValue = "1", allowableValues = "0,1", paramType = "query", dataType = "integer") + @RequestMapping(value = "/list/cart/{type}", method = RequestMethod.GET) + @ResponseBody + public Object listCart(@PathVariable Integer type) { + List cartPromotionItemList = cartItemService.listPromotion(memberService.getCurrentMember().getId()); + List couponHistoryList = memberCouponService.listCart(cartPromotionItemList, type); + return new CommonResult().success(couponHistoryList); + } +} diff --git a/mall-portal/src/main/java/com/macro/mall/portal/dao/SmsCouponHistoryDao.java b/mall-portal/src/main/java/com/macro/mall/portal/dao/SmsCouponHistoryDao.java new file mode 100644 index 0000000..06b687c --- /dev/null +++ b/mall-portal/src/main/java/com/macro/mall/portal/dao/SmsCouponHistoryDao.java @@ -0,0 +1,14 @@ +package com.macro.mall.portal.dao; + +import com.macro.mall.portal.domain.SmsCouponHistoryDetail; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 会员优惠券领取历史自定义Dao + * Created by macro on 2018/8/29. + */ +public interface SmsCouponHistoryDao { + List getDetailList(@Param("memberId") Long memberId); +} diff --git a/mall-portal/src/main/java/com/macro/mall/portal/domain/SmsCouponHistoryDetail.java b/mall-portal/src/main/java/com/macro/mall/portal/domain/SmsCouponHistoryDetail.java new file mode 100644 index 0000000..e39099f --- /dev/null +++ b/mall-portal/src/main/java/com/macro/mall/portal/domain/SmsCouponHistoryDetail.java @@ -0,0 +1,45 @@ +package com.macro.mall.portal.domain; + +import com.macro.mall.model.SmsCoupon; +import com.macro.mall.model.SmsCouponHistory; +import com.macro.mall.model.SmsCouponProductCategoryRelation; +import com.macro.mall.model.SmsCouponProductRelation; + +import java.util.List; + +/** + * 优惠券领取历史详情封装 + * Created by macro on 2018/8/29. + */ +public class SmsCouponHistoryDetail extends SmsCouponHistory { + //相关优惠券信息 + private SmsCoupon coupon; + //优惠券关联商品 + private List productRelationList; + //优惠券关联商品分类 + private List categoryRelationList; + + public SmsCoupon getCoupon() { + return coupon; + } + + public void setCoupon(SmsCoupon coupon) { + this.coupon = coupon; + } + + public List getProductRelationList() { + return productRelationList; + } + + public void setProductRelationList(List productRelationList) { + this.productRelationList = productRelationList; + } + + public List getCategoryRelationList() { + return categoryRelationList; + } + + public void setCategoryRelationList(List categoryRelationList) { + this.categoryRelationList = categoryRelationList; + } +} diff --git a/mall-portal/src/main/java/com/macro/mall/portal/service/UmsMemberCouponService.java b/mall-portal/src/main/java/com/macro/mall/portal/service/UmsMemberCouponService.java new file mode 100644 index 0000000..62f62cf --- /dev/null +++ b/mall-portal/src/main/java/com/macro/mall/portal/service/UmsMemberCouponService.java @@ -0,0 +1,32 @@ +package com.macro.mall.portal.service; + +import com.macro.mall.model.SmsCouponHistory; +import com.macro.mall.portal.domain.CartPromotionItem; +import com.macro.mall.portal.domain.CommonResult; +import com.macro.mall.portal.domain.SmsCouponHistoryDetail; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * 用户优惠券管理Service + * Created by macro on 2018/8/29. + */ +public interface UmsMemberCouponService { + /** + * 会员添加优惠券 + */ + @Transactional + CommonResult add(Long couponId); + + /** + * 获取优惠券列表 + * @param useStatus 优惠券的使用状态 + */ + List list(Integer useStatus); + + /** + * 根据购物车信息获取可用优惠券 + */ + List listCart(List cartItemList, Integer type); +} diff --git a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/UmsMemberCouponServiceImpl.java b/mall-portal/src/main/java/com/macro/mall/portal/service/impl/UmsMemberCouponServiceImpl.java new file mode 100644 index 0000000..513b9e6 --- /dev/null +++ b/mall-portal/src/main/java/com/macro/mall/portal/service/impl/UmsMemberCouponServiceImpl.java @@ -0,0 +1,176 @@ +package com.macro.mall.portal.service.impl; + +import com.macro.mall.mapper.SmsCouponHistoryMapper; +import com.macro.mall.mapper.SmsCouponMapper; +import com.macro.mall.model.*; +import com.macro.mall.portal.dao.SmsCouponHistoryDao; +import com.macro.mall.portal.domain.CartPromotionItem; +import com.macro.mall.portal.domain.CommonResult; +import com.macro.mall.portal.domain.SmsCouponHistoryDetail; +import com.macro.mall.portal.service.UmsMemberCouponService; +import com.macro.mall.portal.service.UmsMemberService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * 会员优惠券管理Service实现类 + * Created by macro on 2018/8/29. + */ +@Service +public class UmsMemberCouponServiceImpl implements UmsMemberCouponService { + @Autowired + private UmsMemberService memberService; + @Autowired + private SmsCouponMapper couponMapper; + @Autowired + private SmsCouponHistoryMapper couponHistoryMapper; + @Autowired + private SmsCouponHistoryDao couponHistoryDao; + @Override + public CommonResult add(Long couponId) { + UmsMember currentMember = memberService.getCurrentMember(); + //获取优惠券信息,判断数量 + SmsCoupon coupon = couponMapper.selectByPrimaryKey(couponId); + if(coupon==null){ + return new CommonResult().failed("优惠券不存在"); + } + if(coupon.getCount()<=0){ + return new CommonResult().failed("优惠券已经领完了"); + } + Date now = new Date(); + if(now.before(coupon.getEnableTime())){ + return new CommonResult().failed("优惠券还没到领取时间"); + } + //判断用户领取的优惠券数量是否超过限制 + SmsCouponHistoryExample couponHistoryExample = new SmsCouponHistoryExample(); + couponHistoryExample.createCriteria().andCouponIdEqualTo(couponId).andMemberIdEqualTo(currentMember.getId()); + int count = couponHistoryMapper.countByExample(couponHistoryExample); + if(count>=coupon.getPerLimit()){ + return new CommonResult().failed("您已经领取过该优惠券"); + } + //生成领取优惠券历史 + SmsCouponHistory couponHistory = new SmsCouponHistory(); + couponHistory.setCouponId(couponId); + couponHistory.setCouponCode(coupon.getCode()); + couponHistory.setCreateTime(now); + couponHistory.setMemberId(currentMember.getId()); + couponHistory.setMemberNickname(currentMember.getNickname()); + //主动领取 + couponHistory.setGetType(1); + //未使用 + couponHistory.setUseStatus(0); + couponHistoryMapper.insert(couponHistory); + //修改优惠券表的数量、领取数量 + coupon.setCount(coupon.getCount()-1); + coupon.setReceiveCount(coupon.getReceiveCount()==null?1:coupon.getReceiveCount()+1); + couponMapper.updateByPrimaryKey(coupon); + return new CommonResult().success("领取成功",null); + } + + @Override + public List list(Integer useStatus) { + UmsMember currentMember = memberService.getCurrentMember(); + SmsCouponHistoryExample couponHistoryExample=new SmsCouponHistoryExample(); + SmsCouponHistoryExample.Criteria criteria = couponHistoryExample.createCriteria(); + criteria.andMemberIdEqualTo(currentMember.getId()); + if(useStatus!=null){ + criteria.andUseStatusEqualTo(useStatus); + } + return couponHistoryMapper.selectByExample(couponHistoryExample); + } + + @Override + public List listCart(List cartItemList, Integer type) { + UmsMember currentMember = memberService.getCurrentMember(); + Date now = new Date(); + //获取该用户所有优惠券 + List allList = couponHistoryDao.getDetailList(currentMember.getId()); + //根据优惠券使用类型来判断优惠券是否可用 + List enableList = new ArrayList<>(); + List disableList = new ArrayList<>(); + for (SmsCouponHistoryDetail couponHistoryDetail : allList) { + Integer useType = couponHistoryDetail.getCoupon().getUseType(); + BigDecimal minPoint = couponHistoryDetail.getCoupon().getMinPoint(); + Date endTime = couponHistoryDetail.getCoupon().getEndTime(); + if(useType.equals(0)){ + //0->全场通用 + //判断是否满足优惠起点 + //计算购物车商品的总价 + BigDecimal totalAmount = calcTotalAmount(cartItemList); + if(now.before(endTime)&&totalAmount.subtract(minPoint).intValue()>=0){ + enableList.add(couponHistoryDetail); + }else{ + disableList.add(couponHistoryDetail); + } + }else if(useType.equals(1)){ + //1->指定分类 + //计算指定分类商品的总价 + List productCategoryIds = new ArrayList<>(); + for (SmsCouponProductCategoryRelation categoryRelation : couponHistoryDetail.getCategoryRelationList()) { + productCategoryIds.add(categoryRelation.getProductCategoryId()); + } + BigDecimal totalAmount = calcTotalAmountByproductCategoryId(cartItemList,productCategoryIds); + if(now.before(endTime)&&totalAmount.intValue()>0&&totalAmount.subtract(minPoint).intValue()>=0){ + enableList.add(couponHistoryDetail); + }else{ + disableList.add(couponHistoryDetail); + } + }else if(useType.equals(2)){ + //2->指定商品 + //计算指定商品的总价 + List productIds = new ArrayList<>(); + for (SmsCouponProductRelation productRelation : couponHistoryDetail.getProductRelationList()) { + productIds.add(productRelation.getProductId()); + } + BigDecimal totalAmount = calcTotalAmountByProductId(cartItemList,productIds); + if(now.before(endTime)&&totalAmount.intValue()>0&&totalAmount.subtract(minPoint).intValue()>=0){ + enableList.add(couponHistoryDetail); + }else{ + disableList.add(couponHistoryDetail); + } + } + } + if(type.equals(1)){ + return enableList; + }else{ + return disableList; + } + } + + private BigDecimal calcTotalAmount(List cartItemList) { + BigDecimal total = new BigDecimal("0"); + for (CartPromotionItem item : cartItemList) { + BigDecimal realPrice = item.getPrice().subtract(item.getReduceAmount()); + total=total.add(realPrice.multiply(new BigDecimal(item.getQuantity()))); + } + return total; + } + + private BigDecimal calcTotalAmountByproductCategoryId(List cartItemList,List productCategoryIds) { + BigDecimal total = new BigDecimal("0"); + for (CartPromotionItem item : cartItemList) { + if(productCategoryIds.contains(item.getProductCategoryId())){ + BigDecimal realPrice = item.getPrice().subtract(item.getReduceAmount()); + total=total.add(realPrice.multiply(new BigDecimal(item.getQuantity()))); + } + } + return total; + } + + private BigDecimal calcTotalAmountByProductId(List cartItemList,List productIds) { + BigDecimal total = new BigDecimal("0"); + for (CartPromotionItem item : cartItemList) { + if(productIds.contains(item.getProductId())){ + BigDecimal realPrice = item.getPrice().subtract(item.getReduceAmount()); + total=total.add(realPrice.multiply(new BigDecimal(item.getQuantity()))); + } + } + return total; + } + +} diff --git a/mall-portal/src/main/resources/dao/SmsCouponHistoryDao.xml b/mall-portal/src/main/resources/dao/SmsCouponHistoryDao.xml new file mode 100644 index 0000000..040eb76 --- /dev/null +++ b/mall-portal/src/main/resources/dao/SmsCouponHistoryDao.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + \ No newline at end of file