Shanks 7 年之前
父节点
当前提交
0e65387b48

+ 1 - 0
src/main/java/com/ygj/yuemum/controller/coupon/CouponController.java

@@ -68,4 +68,5 @@ public class CouponController {
         return couponService.getRechargeTaskCoupon(phone,channel);
     }
 
+
 }

+ 19 - 0
src/main/java/com/ygj/yuemum/controller/customer/CustomerCouponController.java

@@ -3,6 +3,8 @@ package com.ygj.yuemum.controller.customer;
 
 import com.alibaba.fastjson.JSONObject;
 import com.ygj.yuemum.domain.customer.CustomerCoupon;
+import com.ygj.yuemum.domain.customer.CustomerCouponQuery;
+import com.ygj.yuemum.domain.customer.CustomerCouponUpdate;
 import com.ygj.yuemum.service.customer.CustomerCouponService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -43,8 +45,25 @@ public class CustomerCouponController {
         return customerCouponService.updateCustomerCoupon(customerCoupon);
     }
 
+    @PostMapping("/getCustomerCoupons")
+    public String getCustomerCoupons(@ModelAttribute CustomerCouponQuery customerCouponQuery) {
+        Map<String, Object> customerCoupons = customerCouponService.getCustomerCoupons(customerCouponQuery);
+        String jso = JSONObject.toJSONString(customerCoupons);
+        return jso;
+    }
+
     @GetMapping("/getCustomerCoupon/{id}")
     public CustomerCoupon getOne(@PathVariable("id") Integer id) {
         return customerCouponService.getCustomerCoupon(id);
     }
+
+    @PostMapping("/getCouponSum")
+    public List<CustomerCoupon> getCouponSum(@ModelAttribute CustomerCouponQuery customerCouponQuery) {
+        return customerCouponService.getCouponSum(customerCouponQuery);
+    }
+
+    @PostMapping("/CustomerUseCoupon")
+    public int CustomerUseCoupon(@ModelAttribute CustomerCouponUpdate customerCouponUpdate) {
+        return customerCouponService.CustomerUseCoupon(customerCouponUpdate);
+    }
 }

+ 1 - 0
src/main/java/com/ygj/yuemum/dao/coupon/CouponDao.java

@@ -21,6 +21,7 @@ public interface CouponDao {
     int enableCoupon(Integer id);
 
     int updateByPrimaryKeySelective(Coupon record);
+    int updateUseCoupon(Coupon record);
 
     int getCount();
 

+ 6 - 1
src/main/java/com/ygj/yuemum/dao/customer/CustomerCouponDao.java

@@ -1,6 +1,7 @@
 package com.ygj.yuemum.dao.customer;
 
 import com.ygj.yuemum.domain.customer.CustomerCoupon;
+import com.ygj.yuemum.domain.customer.CustomerCouponQuery;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
@@ -17,12 +18,16 @@ public interface CustomerCouponDao {
     CustomerCoupon selectByPrimaryKey(Integer id);
 
     int updateByPrimaryKeySelective(CustomerCoupon record);
-
+    int updateCustomerUseCoupon(CustomerCoupon record);
     int getCount();
 
     int checkCustomerCoupon(CustomerCoupon record);
     int checkSumCustomerCoupon(String cm_phone);
 
+    List<CustomerCoupon> getCustomerCoupons(CustomerCouponQuery customerCouponQuery);
+    int getCustomerCouponsCount(CustomerCouponQuery customerCouponQuery);
+
+    List<CustomerCoupon> getCouponSum(CustomerCouponQuery customerCouponQuery);
 
 
 }

+ 73 - 0
src/main/java/com/ygj/yuemum/domain/customer/CustomerCoupon.java

@@ -12,6 +12,79 @@ public class CustomerCoupon {
     private Integer cc_getchannel;
     private String cc_usedate;
     private String cc_usebillno;
+    //--query
+    private String cb_name;
+    private String cb_rule;
+    private String cb_packages;
+    private String cb_citys;
+    private String cp_startdate;
+    private String cp_enddate;
+    private Integer cp_amount;
+    private Integer cc_quantity;
+
+    public Integer getCc_quantity() {
+        return cc_quantity;
+    }
+
+    public void setCc_quantity(Integer cc_quantity) {
+        this.cc_quantity = cc_quantity;
+    }
+
+    public String getCb_name() {
+        return cb_name;
+    }
+
+    public void setCb_name(String cb_name) {
+        this.cb_name = cb_name;
+    }
+
+    public String getCb_rule() {
+        return cb_rule;
+    }
+
+    public void setCb_rule(String cb_rule) {
+        this.cb_rule = cb_rule;
+    }
+
+    public String getCb_packages() {
+        return cb_packages;
+    }
+
+    public void setCb_packages(String cb_packages) {
+        this.cb_packages = cb_packages;
+    }
+
+    public String getCb_citys() {
+        return cb_citys;
+    }
+
+    public void setCb_citys(String cb_citys) {
+        this.cb_citys = cb_citys;
+    }
+
+    public String getCp_startdate() {
+        return cp_startdate;
+    }
+
+    public void setCp_startdate(String cp_startdate) {
+        this.cp_startdate = cp_startdate;
+    }
+
+    public String getCp_enddate() {
+        return cp_enddate;
+    }
+
+    public void setCp_enddate(String cp_enddate) {
+        this.cp_enddate = cp_enddate;
+    }
+
+    public Integer getCp_amount() {
+        return cp_amount;
+    }
+
+    public void setCp_amount(Integer cp_amount) {
+        this.cp_amount = cp_amount;
+    }
 
     public Integer getId() {
         return id;

+ 50 - 0
src/main/java/com/ygj/yuemum/domain/customer/CustomerCouponQuery.java

@@ -0,0 +1,50 @@
+package com.ygj.yuemum.domain.customer;
+
+public class CustomerCouponQuery {
+
+    private String cm_phone;
+    private String cb_packages;
+    private String cb_citys;
+    private Integer page;
+    private Integer limit;
+
+    public Integer getPage() {
+        return page;
+    }
+
+    public void setPage(Integer page) {
+        this.page = page;
+    }
+
+    public Integer getLimit() {
+        return limit;
+    }
+
+    public void setLimit(Integer limit) {
+        this.limit = limit;
+    }
+
+    public String getCm_phone() {
+        return cm_phone;
+    }
+
+    public void setCm_phone(String cm_phone) {
+        this.cm_phone = cm_phone;
+    }
+
+    public String getCb_packages() {
+        return cb_packages;
+    }
+
+    public void setCb_packages(String cb_packages) {
+        this.cb_packages = cb_packages;
+    }
+
+    public String getCb_citys() {
+        return cb_citys;
+    }
+
+    public void setCb_citys(String cb_citys) {
+        this.cb_citys = cb_citys;
+    }
+}

+ 23 - 0
src/main/java/com/ygj/yuemum/domain/customer/CustomerCouponUpdate.java

@@ -0,0 +1,23 @@
+package com.ygj.yuemum.domain.customer;
+
+public class CustomerCouponUpdate {
+
+    private String couponCode;
+    private String cm_phone;
+
+    public String getCm_phone() {
+        return cm_phone;
+    }
+
+    public void setCm_phone(String cm_phone) {
+        this.cm_phone = cm_phone;
+    }
+
+    public String getCouponCode() {
+        return couponCode;
+    }
+
+    public void setCouponCode(String couponCode) {
+        this.couponCode = couponCode;
+    }
+}

+ 20 - 15
src/main/java/com/ygj/yuemum/service/coupon/CouponService.java

@@ -64,6 +64,11 @@ public class CouponService {
         return couponDao.updateByPrimaryKeySelective(coupon);
     }
 
+    public int  updateUseCoupon(Coupon coupon)
+    {
+        return couponDao.updateUseCoupon(coupon);
+    }
+
     public Coupon getCoupon(Integer id) {
         return couponDao.selectByPrimaryKey(id);
     }
@@ -101,14 +106,14 @@ public class CouponService {
             customerCoupon.setCm_phone(phone);
             customerCoupon.setCb_code("PVP2018051297451");
             customerCoupon.setCc_code(cp_code);
-            customerCoupon.setCp_status(1);
+            customerCoupon.setCp_status(2);
             customerCoupon.setCc_getdate(sdf.format(new Date()));
             customerCoupon.setCc_getchannel(channel);
             customerCouponService.addCustomerCoupon(customerCoupon);
             couponDao.updateGetCoupon(cp_code);
             CouponLog couponLog = new CouponLog();
             couponLog.setCp_code(cp_code);
-            couponLog.setCl_type(1);
+            couponLog.setCl_type(2);
             couponLog.setCl_mp(phone);
             couponLog.setCl_user(9527);
             couponLog.setCl_date(sdf.format(new Date()));
@@ -136,13 +141,13 @@ public class CouponService {
             checkCustomer.setCb_code("PVP2018051273883");
             int coupons = customerCouponService.checkCustomerCoupon(checkCustomer);
             Coupon getCouponAmount = new Coupon();
-            if ( coupons >= 3) {
+            if (coupons >= 3) {
                 return 62;
-            } else if (coupons == 2){
+            } else if (coupons == 2) {
                 getCouponAmount.setCp_amount(50);
-            } else if (coupons == 1){
+            } else if (coupons == 1) {
                 getCouponAmount.setCp_amount(30);
-            } else if (coupons == 0){
+            } else if (coupons == 0) {
                 getCouponAmount.setCp_amount(20);
             }
             getCouponAmount.setCb_code("PVP2018051273883");
@@ -154,14 +159,14 @@ public class CouponService {
             customerCoupon.setCm_phone(phone);
             customerCoupon.setCb_code("PVP2018051273883");
             customerCoupon.setCc_code(cp_code);
-            customerCoupon.setCp_status(1);
+            customerCoupon.setCp_status(2);
             customerCoupon.setCc_getdate(sdf.format(new Date()));
             customerCoupon.setCc_getchannel(channel);
             customerCouponService.addCustomerCoupon(customerCoupon);
             couponDao.updateGetCoupon(cp_code);
             CouponLog couponLog = new CouponLog();
             couponLog.setCp_code(cp_code);
-            couponLog.setCl_type(1);
+            couponLog.setCl_type(2);
             couponLog.setCl_mp(phone);
             couponLog.setCl_user(9527);
             couponLog.setCl_date(sdf.format(new Date()));
@@ -189,12 +194,12 @@ public class CouponService {
             checkCustomer.setCb_code("PVP2018051211608");
             int coupons = customerCouponService.checkCustomerCoupon(checkCustomer);
             Coupon getCouponAmount = new Coupon();
-            if ( coupons >= 3) {
+            if (coupons >= 3) {
                 return 62;
             } else if (coupons == 2) getCouponAmount.setCp_amount(50);
-            else if (coupons == 1){
+            else if (coupons == 1) {
                 getCouponAmount.setCp_amount(30);
-            } else if (coupons == 0){
+            } else if (coupons == 0) {
                 getCouponAmount.setCp_amount(20);
             }
             getCouponAmount.setCb_code("PVP2018051211608");
@@ -206,14 +211,14 @@ public class CouponService {
             customerCoupon.setCm_phone(phone);
             customerCoupon.setCb_code("PVP2018051211608");
             customerCoupon.setCc_code(cp_code);
-            customerCoupon.setCp_status(1);
+            customerCoupon.setCp_status(2);
             customerCoupon.setCc_getdate(sdf.format(new Date()));
             customerCoupon.setCc_getchannel(channel);
             customerCouponService.addCustomerCoupon(customerCoupon);
             couponDao.updateGetCoupon(cp_code);
             CouponLog couponLog = new CouponLog();
             couponLog.setCp_code(cp_code);
-            couponLog.setCl_type(1);
+            couponLog.setCl_type(2);
             couponLog.setCl_mp(phone);
             couponLog.setCl_user(9527);
             couponLog.setCl_date(sdf.format(new Date()));
@@ -250,14 +255,14 @@ public class CouponService {
             customerCoupon.setCm_phone(phone);
             customerCoupon.setCb_code("PVP2018051263016");
             customerCoupon.setCc_code(cp_code);
-            customerCoupon.setCp_status(1);
+            customerCoupon.setCp_status(2);
             customerCoupon.setCc_getdate(sdf.format(new Date()));
             customerCoupon.setCc_getchannel(channel);
             customerCouponService.addCustomerCoupon(customerCoupon);
             couponDao.updateGetCoupon(cp_code);
             CouponLog couponLog = new CouponLog();
             couponLog.setCp_code(cp_code);
-            couponLog.setCl_type(1);
+            couponLog.setCl_type(2);
             couponLog.setCl_mp(phone);
             couponLog.setCl_user(9527);
             couponLog.setCl_date(sdf.format(new Date()));

+ 57 - 0
src/main/java/com/ygj/yuemum/service/customer/CustomerCouponService.java

@@ -2,10 +2,18 @@ package com.ygj.yuemum.service.customer;
 
 import com.github.pagehelper.PageHelper;
 import com.ygj.yuemum.dao.customer.CustomerCouponDao;
+import com.ygj.yuemum.domain.coupon.Coupon;
+import com.ygj.yuemum.domain.coupon.CouponLog;
 import com.ygj.yuemum.domain.customer.CustomerCoupon;
+import com.ygj.yuemum.domain.customer.CustomerCouponQuery;
+import com.ygj.yuemum.domain.customer.CustomerCouponUpdate;
+import com.ygj.yuemum.service.coupon.CouponLogService;
+import com.ygj.yuemum.service.coupon.CouponService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -15,6 +23,10 @@ public class CustomerCouponService {
 
     @Autowired
     private CustomerCouponDao customerCouponDao;
+    @Autowired
+    private CouponService couponService;
+    @Autowired
+    private CouponLogService couponLogService;
     //分页
     public Map<String, Object> getCustomerCoupons(int page, int limit) {
         PageHelper.startPage(page, limit);
@@ -29,6 +41,12 @@ public class CustomerCouponService {
         List<CustomerCoupon> customerCoupons = customerCouponDao.getAll();
         return customerCoupons;
     }
+
+    public List<CustomerCoupon> getCouponSum(CustomerCouponQuery customerCouponQuery) {
+        List<CustomerCoupon> customerCoupons = customerCouponDao.getCouponSum(customerCouponQuery);
+        return customerCoupons;
+    }
+
     public int addCustomerCoupon(CustomerCoupon customerCoupon) {
         return customerCouponDao.insertSelective(customerCoupon);
     }
@@ -53,4 +71,43 @@ public class CustomerCouponService {
         return customerCouponDao.checkSumCustomerCoupon(phone);
     }
 
+    public Map<String, Object> getCustomerCoupons(CustomerCouponQuery customerCouponQuery) {
+        PageHelper.startPage(customerCouponQuery.getPage(), customerCouponQuery.getLimit());
+        List<CustomerCoupon> customerCoupons = customerCouponDao.getCustomerCoupons(customerCouponQuery);
+        Map<String, Object> tableData = new HashMap<>();
+        Integer count  = customerCouponDao.getCustomerCouponsCount(customerCouponQuery);
+        tableData.put("items", customerCoupons);
+        tableData.put("total", count);
+        return tableData;
+    }
+    public int CustomerUseCoupon(CustomerCouponUpdate customerCouponUpdate){
+        String[] CouponCodes= customerCouponUpdate.getCouponCode().split(",");
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try{
+            for(int i = 0;i<CouponCodes.length;i++){
+                CustomerCoupon customerCoupon = new CustomerCoupon();
+                Coupon coupon = new Coupon();
+                customerCoupon.setCc_code(CouponCodes[i]);
+                customerCoupon.setCp_status(3);
+                coupon.setCp_code(CouponCodes[i]);
+                coupon.setCp_status(3);
+                CouponLog couponLog = new CouponLog();
+                couponLog.setCp_code(CouponCodes[i]);
+                couponLog.setCl_type(3);
+                couponLog.setCl_mp(customerCouponUpdate.getCm_phone());
+                couponLog.setCl_user(9527);
+                couponLog.setCl_date(sdf.format(new Date()));
+                couponLog.setCb_code("PVP2018051297451");
+                couponLogService.addCouponLog(couponLog);
+                customerCouponDao.updateCustomerUseCoupon(customerCoupon);
+                couponService.updateUseCoupon(coupon);
+            }
+
+        }catch (Exception ex){
+            ex.printStackTrace();
+            return 0;
+        }
+        return 1;
+    }
+
 }

+ 10 - 0
src/main/resources/mybatis/mapper/coupon/CouponMapper.xml

@@ -140,4 +140,14 @@
         where cp_code = #{cp_code,jdbcType=INTEGER}
     </update>
 
+    <update id="updateUseCoupon" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon" >
+        update coupon
+        <set >
+            <if test="cp_status != null" >
+                cp_status = #{cp_status,jdbcType=VARCHAR},
+            </if>
+        </set>
+        where cp_code = #{cp_code,jdbcType=INTEGER}
+    </update>
+
 </mapper>

+ 105 - 0
src/main/resources/mybatis/mapper/customer/CustomerCouponMapper.xml

@@ -13,6 +13,13 @@
         <result column="cc_getchannel" property="cc_getchannel" jdbcType="INTEGER" />
         <result column="cc_usedate" property="cc_usedate" jdbcType="DATE" />
         <result column="cc_usebillno" property="cc_usebillno" jdbcType="VARCHAR" />
+        <result column="cb_name" property="cb_name" jdbcType="VARCHAR" />
+        <result column="cb_rule" property="cb_rule" jdbcType="VARCHAR" />
+        <result column="cb_packages" property="cb_packages" jdbcType="VARCHAR" />
+        <result column="cb_citys" property="cb_citys" jdbcType="VARCHAR" />
+        <result column="cp_enddate" property="cp_enddate" jdbcType="VARCHAR" />
+        <result column="cp_amount" property="cp_amount" jdbcType="INTEGER" />
+        <result column="cc_quantity" property="cc_quantity" jdbcType="INTEGER" />
     </resultMap>
 
     <sql id="Base_Column_List" >
@@ -42,6 +49,94 @@
         where id = #{id,jdbcType=INTEGER}
     </select>
 
+
+    <select id="getCouponSum" resultMap="BaseResultMap" parameterType="com.ygj.yuemum.domain.customer.CustomerCouponQuery"  >
+        SELECT
+        cm_phone,
+        count(1) cc_quantity,
+        sum(cp_amount) cp_amount
+        FROM
+        (
+        SELECT
+        ta.cm_phone,
+        ta.cc_code,
+        tb.cb_packages,
+        tb.cb_citys
+        FROM
+        customer_coupon ta
+        LEFT JOIN coupon_batch tb ON ta.cb_code = tb.cb_code
+        where ta.cp_status = 2
+        <if test="cm_phone != null and cm_phone != ''" >
+            and ta.cm_phone = #{cm_phone,jdbcType=VARCHAR}
+        </if>
+        <if test="cb_packages != null and cb_packages != ''">
+            and tb.cb_packages like "%"#{cb_packages,jdbcType=VARCHAR}"%"
+        </if>
+        <if test="cb_citys != null and cb_citys != ''">
+            and tb.cb_citys like "%"#{cb_citys,jdbcType=VARCHAR}"%"
+        </if>
+        ) tta,
+        coupon ttb
+        WHERE
+        tta.cc_code = ttb.cp_code
+        group by tta.cm_phone
+    </select>
+
+    <select id="getCustomerCoupons" resultMap="BaseResultMap" parameterType="com.ygj.yuemum.domain.customer.CustomerCouponQuery"  >
+        SELECT
+        ta.cc_code,
+        tb.cb_name,
+        tb.cb_rule,
+        fgetpackages(tb.id) cb_packages,
+        fgetmoretcityname(tb.id) cb_citys,
+        tc.cp_startdate,
+        tc.cp_enddate,
+        tc.cp_amount,
+        cc_getdate,
+        ta.cp_status
+        FROM
+            customer_coupon ta
+        LEFT JOIN coupon_batch tb ON ta.cb_code = tb.cb_code
+        left JOIN coupon tc on ta.cc_code = tc.cp_code
+        where
+        1=1
+        <if test="cm_phone != null and cm_phone != ''" >
+            and ta.cm_phone = #{cm_phone,jdbcType=VARCHAR}
+        </if>
+        <if test="cb_packages != null and cb_packages != ''">
+            and tb.cb_packages like "%"#{cb_packages,jdbcType=VARCHAR}"%"
+        </if>
+        <if test="cb_citys != null and cb_citys != ''">
+            and tb.cb_citys like "%"#{cb_citys,jdbcType=VARCHAR}"%"
+        </if>
+        and ta.cp_status = 2
+        order by ta.cb_code ,tc.cp_amount desc
+    </select>
+
+
+    <select id="getCustomerCouponsCount" resultType="java.lang.Integer"  parameterType="com.ygj.yuemum.domain.customer.CustomerCouponQuery" >
+        SELECT
+        count(1)
+        FROM
+        customer_coupon ta
+        LEFT JOIN coupon_batch tb ON ta.cb_code = tb.cb_code
+        left JOIN coupon tc on ta.cc_code = tc.cp_code
+        where
+        1=1
+        <if test="cm_phone != null and cm_phone != ''" >
+            and ta.cm_phone = #{cm_phone,jdbcType=VARCHAR}
+        </if>
+        <if test="cb_packages != null and cb_packages != ''">
+            and tb.cb_packages like "%"#{cb_packages,jdbcType=VARCHAR}"%"
+        </if>
+        <if test="cb_citys != null and cb_citys != ''">
+            and tb.cb_citys like "%"#{cb_citys,jdbcType=VARCHAR}"%"
+        </if>
+        and ta.cp_status = 2
+        order by ta.cb_code ,tc.cp_amount desc
+    </select>
+
+
     <select id="checkCustomerCoupon" resultType="java.lang.Integer" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon" >
         SELECT
         count(1)
@@ -229,5 +324,15 @@
 
     </select>
 
+    <update id="updateCustomerUseCoupon" parameterType="com.ygj.yuemum.domain.customer.CustomerCoupon" >
+        update customer_coupon
+        <set >
+            <if test="cp_status != null" >
+                cp_status = #{cp_status,jdbcType=VARCHAR},
+            </if>
+        </set>
+        where cc_code = #{cc_code,jdbcType=INTEGER}
+    </update>
+
 
 </mapper>