dcs 4 bulan lalu
induk
melakukan
5caeaaabcf

+ 13 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/controller/ProductCouponController.java

@@ -21,6 +21,19 @@ public class ProductCouponController {
     @Autowired
     ProductCouponService productCouponService;
 
+    @ApiOperation("新用户优惠券")
+    @RequestMapping(value = "/nowReceive/{organizationId}/{userId}", method = RequestMethod.GET)
+    public Response nowReceive(@PathVariable long organizationId, @PathVariable long userId) {
+        return Response.ok(productCouponService.nowReceive(organizationId, userId));
+    }
+
+    @ApiOperation("领取优惠券")
+    @RequestMapping(value = "/receive/{organizationId}/{userId}/{productCouponModelId}", method = RequestMethod.GET)
+    public Response receive(@PathVariable long organizationId, @PathVariable long userId, @PathVariable long productCouponModelId) {
+        productCouponService.receive(organizationId, userId, productCouponModelId);
+        return Response.ok();
+    }
+
     @ApiOperation("保存")
     @RequestMapping(value = "", method = RequestMethod.POST)
     public Response insert(@RequestBody ProductCoupon productCoupon) {

+ 2 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/dao/ProductCouponDao.java

@@ -22,4 +22,6 @@ public interface ProductCouponDao {
     int getTotalCount(ProductCoupon productCoupon);
 
     List<ProductCoupon> getLimit(@Param("p") ProductCoupon p, @Param("currIndex") int currIndex, @Param("pageSize") int pageSize);
+
+    List<ProductCoupon> getProductCouponModelId(long organizationId, long userId);
 }

+ 3 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/dao/ProductCouponModelDao.java

@@ -19,8 +19,11 @@ public interface ProductCouponModelDao {
 
     ProductCouponModel get(long id);
 
+    List<ProductCouponModel> getAll();
+
     int getTotalCount(ProductCouponModel productCouponModel);
 
     List<ProductCouponModel> getLimit(@Param("p") ProductCouponModel p, @Param("currIndex") int currIndex, @Param("pageSize") int pageSize);
 
+    List<ProductCouponModel> nowReceive(List<Long> ids);
 }

+ 29 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/service/ProductCouponService.java

@@ -1,10 +1,14 @@
 package com.bosshand.virgo.api.workark.service;
 
 import com.bosshand.virgo.api.workark.dao.ProductCouponDao;
+import com.bosshand.virgo.api.workark.dao.ProductCouponModelDao;
 import com.bosshand.virgo.api.workark.model.ProductCoupon;
+import com.bosshand.virgo.api.workark.model.ProductCouponModel;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 @Service
@@ -13,6 +17,9 @@ public class ProductCouponService {
     @Autowired
     ProductCouponDao productCouponDao;
 
+    @Autowired
+    ProductCouponModelDao productCouponModelDao;
+
     public void delete(long id) {
         productCouponDao.delete(id);
     }
@@ -42,4 +49,26 @@ public class ProductCouponService {
         return productCouponDao.get(id);
     }
 
+    public List<ProductCouponModel> nowReceive(long organizationId, long userId) {
+        List<ProductCoupon> list = productCouponDao.getProductCouponModelId(organizationId, userId);
+        if (list.size() == 0) {
+            return productCouponModelDao.getAll();
+        }
+        List<Long> ids = new ArrayList();
+        list.forEach(ls -> ids.add(ls.getId()));
+        return productCouponModelDao.nowReceive(ids);
+    }
+
+    public void receive(long organizationId, long userId, long productCouponModelId) {
+        ProductCouponModel productCouponModel = productCouponModelDao.get(productCouponModelId);
+        ProductCoupon productCoupon = new ProductCoupon();
+        BeanUtils.copyProperties(productCouponModel, productCoupon);
+        productCoupon.setOrganizationId(organizationId);
+        productCoupon.setUserId(userId);
+        productCoupon.setProductCouponModelId(productCouponModel.getId());
+        productCouponDao.save(productCoupon);
+        productCoupon.setState(1);
+        productCouponDao.update(productCoupon);
+    }
+
 }

+ 4 - 0
virgo.api/src/main/resources/mapper/ProductCouponMapper.xml

@@ -30,6 +30,10 @@
         select * from workark_product_coupon where id = #{id}
     </select>
 
+    <select id="getProductCouponModelId" resultMap="result">
+        select id from workark_product_coupon where organizationId = #{organizationId} and userId = #{userId} and productCouponModelId != 0
+    </select>
+
     <select id="getList" resultMap="result">
         select * from workark_product_coupon
         <where>

+ 12 - 0
virgo.api/src/main/resources/mapper/ProductCouponModelMapper.xml

@@ -23,6 +23,18 @@
         select * from workark_product_coupon_model where id = #{id}
     </select>
 
+    <select id="getAll" resultMap="result">
+        select * from workark_product_coupon_model
+    </select>
+
+    <select id="nowReceive" resultMap="result">
+        select * from workark_product_coupon_model where id not in (
+        <foreach collection="list" item="item" index="index" separator=",">
+            #{item}
+        </foreach>
+        )
+    </select>
+
     <select id="getList" resultMap="result">
         select * from workark_product_coupon_model
         <where>