Quellcode durchsuchen

领取优惠券

zoujiajian vor 2 Jahren
Ursprung
Commit
713001120b

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/mapper/manage/coupon/CouponUserMapper.java

@@ -29,4 +29,6 @@ public interface CouponUserMapper extends BaseMapper<CouponUser> {
 	CouponUserView getNewUserWelfareCouponsByUserId(@Param("userId") long userId, @Param("channel") CouponUser.Channel channel, @Param("now") DateTime now);
 
 	CouponUser getCouponByCouponUserId(Long couponUserId);
+
+	CouponUserView getCouponDetailById(@Param("userId") long userId, @Param("couponId") Long couponId);
 }

+ 23 - 0
netflix-dao/src/main/resources/mapper/CouponUserMapper.xml

@@ -210,4 +210,27 @@
         from coupon_user
         where id = #{couponUserId} limit 1
     </select>
+
+    <select id="getCouponDetailById" resultType="com.cyksj.model.views.CouponUserView">
+        select cu.*,
+               c.name,
+               c.goods_type,
+               c.type,
+               c.reduce_condition,
+               c.reduce_money,
+               c.discount,
+               c.use_scope,
+               c.goods_sku_ids,
+               cu.valid_start_time,
+               cu.valid_end_time,
+               unix_timestamp(cu.valid_end_time) * 1000 as validEndTimestamp
+        from (select coupon_id,
+                     valid_start_time,
+                     valid_end_time,
+                     status as couponUserStatus
+              from `coupon_user`
+              where user_id = #{userId}
+                and coupon_id = #{couponId} limit 1) cu
+                 inner join coupon c on c.id = cu.coupon_id
+    </select>
 </mapper>

+ 4 - 0
netflix-service/src/main/java/com/cyksj/service/coupon/CouponFontService.java

@@ -66,4 +66,8 @@ public interface CouponFontService {
 	 * 新用户福利优惠券
 	 */
 	CouponUserView getNewUserWelfareCoupons(long userId, DateTime now);
+
+	CouponUserView getCouponDetailById(long userId, Long couponId);
+
+	CouponUserView receiveCoupon(long userId, Long couponId);
 }

+ 20 - 0
netflix-service/src/main/java/com/cyksj/service/coupon/impl/CouponFontServiceImpl.java

@@ -364,4 +364,24 @@ public class CouponFontServiceImpl implements CouponFontService {
 	public CouponUserView getNewUserWelfareCoupons(long userId, DateTime now) {
 		return couponUserMapper.getNewUserWelfareCouponsByUserId(userId, CouponUser.Channel.new_welfare, now);
 	}
+
+	@Override
+	public CouponUserView getCouponDetailById(long userId, Long couponId) {
+		CouponUserView couponUserView = couponUserMapper.getCouponDetailById(userId, couponId);
+		if (couponUserView != null) {
+			String str = couponSkuMapper.selectGoodsSkuStr(couponUserView.getCouponId());
+			couponUserView.setGoodsSkuStr(str.replaceAll(",", "/").replaceAll(";", ""));
+		}
+		return couponUserView;
+	}
+
+	@Override
+	public CouponUserView receiveCoupon(long userId, Long couponId) {
+		try {
+			receiveCouponUser(couponId, userId, CouponUser.Channel.manual);
+		} catch (Exception e) {
+			return null;
+		}
+		return getCouponDetailById(userId, couponId);
+	}
 }

+ 17 - 0
netflix-web/src/main/java/com/cyksj/web/controller/coupon/CouponFrontController.java

@@ -363,4 +363,21 @@ public class CouponFrontController {
 		CouponUserView couponUserView = couponFontService.getNewUserWelfareCoupons(userId, now);
 		return GatewayResponse.SUCCESS.newBuilder().toResult(couponUserView);
 	}
+
+	@GetMapping("/get/coupon/detail/{couponId}")
+	public Result<CouponUserView> getCouponDetailById(@PathVariable Long couponId) {
+		long userId = StpUserUtil.getLoginIdAsLong();
+		CouponUserView couponUserView = couponFontService.getCouponDetailById(userId, couponId);
+		return GatewayResponse.SUCCESS.newBuilder().toResult(couponUserView);
+	}
+
+	/**
+	 * 领取优惠券
+	 */
+	@PostMapping("/receive/coupon/{couponId}")
+	public Result<CouponUserView> receiveCoupon(@PathVariable Long couponId) {
+		long userId = StpUserUtil.getLoginIdAsLong();
+		CouponUserView couponUserView = couponFontService.receiveCoupon(userId, couponId);
+		return GatewayResponse.SUCCESS.newBuilder().toResult(couponUserView);
+	}
 }