Bläddra i källkod

优惠码补充

李天标 5 år sedan
förälder
incheckning
36cfbb5a2c

+ 46 - 10
app-api/src/main/java/com/hboxs/control/api/order/OrderController.java

@@ -23,6 +23,7 @@ import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.net.URLDecoder;
+import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -47,6 +48,8 @@ public class OrderController extends BaseController {
     private MchService mchService;
     @Resource(name = "promoCodeServiceImpl")
     private PromoCodeService promoCodeService;
+    @Resource(name = "priceServiceImpl")
+    private PriceService priceService;
     /**
      * 请求在线支付
      *
@@ -614,9 +617,15 @@ public class OrderController extends BaseController {
         // 订单号
 
         //价格
-
+        Double money = null;
+        List<Price> prices = priceService.findAll();
+        for(Price price1:prices){
+            if(price1.getName().equals("优惠码")){
+                money = price1.getPrice();
+            }
+        }
         //生成优惠码的个数
-        double num = price/0.02;
+        double num = price/money;
         int number = (int) num;
         Order order = orderService.findBySn(sn);
         Admin admin = adminService.find(order.getAdminId());
@@ -645,14 +654,20 @@ public class OrderController extends BaseController {
             for(int i=0;i<number;i++){
                 String code = orderService.initSn(order.getEquipmentId());
                 StringBuffer str = new StringBuffer();
-                str.append(code.substring(0,4)).append(code.substring(code.length()-4,code.length()));
+                str.append(code.substring(0,6));
                 codes.add(str.toString());
             }
+            Long data = Calendar.getInstance().getTimeInMillis();
+            Long month = 30L*24L*60L*60L*1000L;
+            Long d = data + month;
+            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            Date lastUseDate = new Date(Long.parseLong(String.valueOf(d)));
             for(String code : codes){
                 PromoCode promoCode = new PromoCode();
                 promoCode.setCode(Long.parseLong(code));
                 promoCode.setAdminId(String.valueOf(order.getAdminId()));
                 promoCode.setIsUse("0");
+                promoCode.setLastUseDate(lastUseDate);
                 promoCode.setCreateDate(new Date());
                 promoCode.setModifyDate(null);
                 promoCode.setUserName(admin.getUsername());
@@ -683,8 +698,15 @@ public class OrderController extends BaseController {
         String sn = request.getParameter("r2_OrderNo");
         //价格
         String price = request.getParameter("r3_Amount");
+        Double money = null;
+        List<Price> prices = priceService.findAll();
+        for(Price price1:prices){
+            if(price1.getName().equals("优惠码")){
+                money = price1.getPrice();
+            }
+        }
         //生成优惠码的个数
-        double num = Long.valueOf(price)/0.02;
+        double num = Double.parseDouble(price)/money;
         int number = (int) num;
         Order order = orderService.findBySn(sn);
         if(order.getStatus()!=Order.Status.unpay){
@@ -723,14 +745,21 @@ public class OrderController extends BaseController {
             for(int i=0;i<number;i++){
                 String code = orderService.initSn(order.getEquipmentId());
                 StringBuffer str = new StringBuffer();
-                str.append(code.substring(0,4)).append(code.substring(code.length()-4,code.length()));
+                str.append(code.substring(0,6));
                 codes.add(str.toString());
             }
+            Long data = Calendar.getInstance().getTimeInMillis();
+            Long month = 30L*24L*60L*60L*1000L;
+            Long d = data + month;
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            String sd = sdf.format(new Date(Long.parseLong(String.valueOf(d))));
+            Date lastUseDate = new Date(Long.parseLong(String.valueOf(d)));
             for(String code : codes){
                 PromoCode promoCode = new PromoCode();
                 promoCode.setCode(Long.parseLong(code));
                 promoCode.setAdminId(String.valueOf(order.getAdminId()));
                 promoCode.setIsUse("0");
+                promoCode.setLastUseDate(lastUseDate);
                 promoCode.setCreateDate(new Date());
                 promoCode.setUserName(admin.getUsername());
                 promoCodeService.save(promoCode);
@@ -825,15 +854,22 @@ public class OrderController extends BaseController {
     public JsonMessage promoCodeDo(String code ,String  clientId) {
         Equipment equipment = equipmentService.findByClientId(clientId);
         PromoCode promoCode = promoCodeService.findByCode(Long.valueOf(code));
-        if(promoCode==null){
+        Date lastUseDate=null;
+        if(promoCode!=null){
+            lastUseDate = promoCode.getLastUseDate();
+        }
+        if(lastUseDate!=null&&lastUseDate.getTime()<((new Date()).getTime())){
+            promoCode.setIsUse("2");
+            promoCodeService.update(promoCode);
+            //过期
+            return JsonMessage.success("4");
+        } else if(promoCode==null){
             //不存在
             return JsonMessage.success("1");
-        }
-        if(promoCode.getIsUse().equals("1")){
+        } else if(promoCode.getIsUse().equals("1")){
             //被使用
             return JsonMessage.success("2");
-        }
-        if(String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())){
+        } else if(String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())){
             promoCode.setIsUse("1");
             promoCode.setUseBy(equipment.getName());
             SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

+ 45 - 6
app-backend-web/src/main/java/com/hboxs/control/admin/PromoCodeController.java

@@ -43,6 +43,7 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
+import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -74,21 +75,30 @@ public class PromoCodeController extends BaseController {
     private OrderService orderService;
     @Resource(name = "proportionServiceImpl")
     private ProportionService proportionService;
-
+    @Resource(name = "priceServiceImpl")
+    private PriceService priceService;
     /**
      * 列表
      */
     @RequestMapping(value = "/list", method = RequestMethod.GET)
     public String agencyList(Long code,String isUse,Pageable pageable, ModelMap model) {
-        String a = "";
+
         if (code != null) {
             pageable.getFilters().add(Filter.eq("code", code));
         }
         if (isUse != null) {
             pageable.getFilters().add(Filter.eq("isUse", isUse));
         }
-        //        pageable.getFilters().add(Filter.eq("type", Admin.Type.agency));
-//        pageable.getFilters().add(Filter.eq("isAdmined" , false));
+        Double money = null;
+        List<Price> prices = priceService.findAll();
+        for(Price price:prices){
+            if(price.getName().equals("优惠码")){
+                money = price.getPrice();
+            }
+        }
+        String type = adminService.getCurrent().getType().toValue();
+        model.addAttribute("price", money);
+        model.addAttribute("type", type);
         model.addAttribute("isUse", isUse);
         model.addAttribute("code", code);
         model.addAttribute("page", promoCodeService.findPage(pageable));
@@ -101,10 +111,31 @@ public class PromoCodeController extends BaseController {
      */
     @RequestMapping(value = "/add", method = RequestMethod.GET)
     public String add(ModelMap model) {
-
+        Double money = null;
+        List<Price> prices = priceService.findAll();
+        for(Price price:prices){
+            if(price.getName().equals("优惠码")){
+                money = price.getPrice();
+            }
+        }
+        model.addAttribute("price", money);
         return "/admin/promoCode/add";
     }
 
+    /**
+     * 更新
+     */
+    @RequestMapping(value = "/upMoney", method = RequestMethod.POST)
+    public String upMoney(Double price, RedirectAttributes redirectAttributes) {
+        List<Price> prices = priceService.findAll();
+        for(Price price1:prices){
+            if(price1.getName().equals("优惠码")){
+                price1.setPrice(price);
+                priceService.update(price1);
+            }
+        }
+        return "redirect:list.htm";
+    }
     @RequestMapping(value = "/edit", method = RequestMethod.GET)
     public String edit(ModelMap model) {
 
@@ -141,10 +172,18 @@ public class PromoCodeController extends BaseController {
                 orderType = Order.Type.personage;
                 break;
         }
+        Double money = null;
+        List<Price> prices = priceService.findAll();
+        for(Price price:prices){
+            if(price.getName().equals("优惠码")){
+                money = price.getPrice();
+            }
+        }
+
         String sn = orderService.initSn(equipmentId);
         String orderNo = sn;
         String productName = "优惠码";
-        BigDecimal price = BigDecimal.valueOf(0.02*number);
+        BigDecimal price = BigDecimal.valueOf(money*number);
         BigDecimal cutPrice = price.multiply(new BigDecimal(100)).divide(new BigDecimal(100));
         BigDecimal amount = cutPrice;
         String productDesc = "";

+ 1 - 1
app-backend-web/src/main/webapp/WEB-INF/template/admin/promoCode/add.ftl

@@ -32,7 +32,7 @@ $().ready(function() {
 	<form id="inputForm" action="img.htm" method="get">
 		<table class="input">
 			<tr>
-				当前优惠码价格为:0.5元/个
+				当前优惠码价格为:${price}元/个
 			</tr>
 			<tr>
 				<th>

+ 1 - 1
app-backend-web/src/main/webapp/WEB-INF/template/admin/promoCode/img.ftl

@@ -39,7 +39,7 @@
                 &nbsp;您需要支付:${price}元
             </th>
             <td>
-                <img src="${image}">
+                <img src="${image}"  style="height: 250px">
             </td>
         </tr>
 [#--        ${rd_Pic}--]

+ 32 - 143
app-backend-web/src/main/webapp/WEB-INF/template/admin/promoCode/list.ftl

@@ -61,8 +61,23 @@
 <div class="path ">
     首页 &raquo; 优惠码列表 <span>(总共${page.total}行)</span>
 </div>
-
-
+[#if type=="管理员"]
+    <form id="listForm" action="upMoney.htm" method="post" class="">
+        <tr>
+            <th>
+                <span class="requiredField"></span>优惠码价格:
+            </th>
+            <td>
+                <input type="text" name="price" class="text" maxlength="20"
+                       value="${price}"/>
+            </td>
+            <td>
+                <input id="upMoney" type="submit" class="button" value="提交更新"/>
+            </td>
+        </tr>
+    </form>
+[/#if]
+<br/>
 <form id="listForm" action="list.htm" method="get" class="">
     <div class="bar buttonWrap">
     <a href="add.htm" class="iconButton" id="addButton">
@@ -106,6 +121,7 @@
                 <option value="" >全部</option>
                 <option value="0" [#if isUse=="0"] selected[/#if]>未使用</option>
                 <option value="1" [#if isUse=="1"] selected[/#if]>已使用</option>
+                <option value="2" [#if isUse=="2"] selected[/#if]>过期</option>
             </select>
             <button class="layui-btn layui-btn-normal layui-btn-xs">筛选</button>
         </div>
@@ -117,6 +133,7 @@
 
         <button id="export" class="layui-btn layui-btn-normal layui-btn-xs">导出Excel</button>
     </div>
+    <br/>
     <table id="listTable" class="list">
         <tr>
             <th class="check">
@@ -132,6 +149,9 @@
                 <a href="javascript:" class="sort" name="createDate">创建时间</a>
             </th>
             <th>
+                <a href="javascript:" class="sort" name="lastUseDate">有效期至</a>
+            </th>
+            <th>
                 <a href="javascript:" class="sort" name="isUse">是否使用</a>
             </th>
             <th>
@@ -156,18 +176,24 @@
                     <td>
                         ${promoCode.createDate?string("yyyy-MM-dd HH:mm:ss")}
                     </td>
-[#--                    <td>--]
-[#--                        ${promoCode.isUse}--]
-[#--                    </td>--]
+                    <td>
+                        ${promoCode.lastUseDate?string("yyyy-MM-dd HH:mm:ss")}
+                    </td>
                     [#if promoCode.isUse==0]
                     <td>
                         <span class="green">未使用</span>
                     </td>
-                    [#else]
+                    [/#if]
+                    [#if promoCode.isUse==1]
                         <td>
                             <span class="red">使用</span>
                         </td>
                     [/#if]
+                    [#if promoCode.isUse==2]
+                        <td>
+                            <span class="red">过期</span>
+                        </td>
+                    [/#if]
                     <td>
                         ${promoCode.useDate}
                     </td>
@@ -202,141 +228,4 @@
 
     });
 </script>
-[#--<script>--]
-[#--    var h = '<div id="container" style="width: 1200px;height: 650px"></div>';--]
-[#--    $('.location').click(function () {--]
-
-[#--        var longitude = $(this).attr('data-longitude');--]
-[#--        var latitude = $(this).attr('data-latitude');--]
-[#--        if (longitude == '' || latitude == '') {--]
-[#--            layer.msg('获取不到经纬度');--]
-[#--            return;--]
-[#--        }--]
-
-[#--        var index = layer.open({--]
-[#--            content: h,--]
-[#--            shade: false,--]
-[#--            area: [longitude, latitude],--]
-[#--        });--]
-
-[#--        var map = new AMap.Map('container', {--]
-[#--            center: [longitude, latitude],--]
-[#--            zoom: 15--]
-[#--        });--]
-
-[#--        // 创建一个 Marker 实例:--]
-[#--        var marker = new AMap.Marker({--]
-[#--            position: new AMap.LngLat(longitude, latitude)   // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]--]
-[#--        });--]
-
-[#--        // 将创建的点标记添加到已有的地图实例:--]
-[#--        map.add(marker);--]
-
-[#--    });--]
-
-[#--    $('.editNo').click(function () {--]
-[#--        var id = $(this).attr('data-id');--]
-[#--        var name = $(this).attr('data-name');--]
-
-[#--        if (name == '') {--]
-[#--            layer.msg('请完善设备信息再进行设备号推送');--]
-[#--            return;--]
-[#--        }--]
-[#--        layui.use('layer', function () {--]
-[#--            var layer = layui.layer;--]
-
-[#--            //例子2--]
-[#--            layer.prompt({--]
-[#--                formType: 2,--]
-[#--                value: '',--]
-[#--                title: '正在修改 "' + name + '" 设备号',--]
-[#--                area: ['300px', '40px'] //自定义文本域宽高--]
-[#--            }, function (value, index, elem) {--]
-[#--                layer.close(index);--]
-
-[#--                $.ajax({--]
-[#--                    url: 'editNo.htm',--]
-[#--                    type: "GET",--]
-[#--                    data: {no: value, id: id},--]
-[#--                    dataType: "json",--]
-[#--                    cache: false,--]
-[#--                    beforeSend: function () {--]
-[#--                        mask = layer.load(1, {shade: [0.4, '#333333']});--]
-[#--                    },--]
-[#--                    success: function (data) {--]
-[#--                        layer.close(mask);--]
-[#--                        if (data.code == 0) {--]
-[#--                            layer.msg(data.data);--]
-[#--                        } else {--]
-[#--                            layer.msg(data.errmsg);--]
-[#--                        }--]
-[#--                    },--]
-[#--                    error: function () {--]
-[#--                        layer.close(mask);--]
-[#--                    }--]
-[#--                });--]
-[#--            });--]
-[#--        });--]
-[#--    });--]
-
-
-[#--    $('.freshNo').click(function () {--]
-[#--        var id = $(this).attr('data-id');--]
-[#--        var t = $(this);--]
-[#--        $.ajax({--]
-[#--            url: 'getNo.htm',--]
-[#--            type: "GET",--]
-[#--            data: {id: id},--]
-[#--            dataType: "json",--]
-[#--            cache: false,--]
-[#--            beforeSend: function () {--]
-[#--                t.html('<img class="l" src="/resources/admin/images/loading.gif" />')--]
-[#--            },--]
-[#--            success: function (data) {--]
-[#--                setTimeout(t.html('刷新'), 1000);--]
-[#--                if (data.code == 0) {--]
-[#--                    t.parent('td').find('b').html(data.data)--]
-[#--                } else {--]
-[#--                    layer.msg(data.errmsg);--]
-[#--                }--]
-[#--            },--]
-[#--            error: function () {--]
-[#--                t.html('刷新')--]
-[#--            }--]
-[#--        });--]
-[#--    });--]
-
-[#--</script>--]
-[#--<script>--]
-[#--    $(".status").click(function () {--]
-[#--        var id = $(this).attr('data-id');--]
-[#--        var code = $(this).attr('data-status');--]
-[#--        var url = $(this).attr('data-url');--]
-[#--        layer.confirm('确定执行此操作?', {icon: 3, title: '提示'}, function (index) {--]
-[#--            $.ajax({--]
-[#--                url: url,--]
-[#--                data: {--]
-[#--                    code: code,--]
-[#--                    id: id--]
-[#--                },--]
-[#--                type: "POST",--]
-[#--                dataType: "json",--]
-[#--                cache: false,--]
-[#--                success: function (data) {--]
-[#--                    if (data.type == "success") {--]
-
-[#--                        location.reload();--]
-[#--                    } else {--]
-[#--                        layer.msg("执行失败");--]
-[#--                    }--]
-[#--                }--]
-[#--            });--]
-
-[#--            layer.close(index);--]
-[#--        });--]
-[#--    });--]
-[#--</script>--]
-
-
-
 </html>

+ 15 - 0
app-dao/src/main/java/com/hboxs/dao/PriceDao.java

@@ -0,0 +1,15 @@
+/*
+ *
+ *  PriceDao
+ *
+ */
+package com.hboxs.dao;
+
+import com.hboxs.entity.Price;
+
+/**
+ * Dao -
+ */
+public interface PriceDao extends BaseDao<Price, Long> {
+
+}

+ 18 - 0
app-dao/src/main/java/com/hboxs/dao/impl/PriceDaoImpl.java

@@ -0,0 +1,18 @@
+/*
+ *
+ *  PriceDaoImpl
+ *
+ */
+package com.hboxs.dao.impl;
+
+import com.hboxs.dao.PriceDao;
+import com.hboxs.entity.Price;
+import org.springframework.stereotype.Repository;
+
+/**
+ * Dao - 广告管理
+ */
+@Repository("priceDaoImpl")
+public class PriceDaoImpl extends BaseDaoImpl<Price, Long> implements PriceDao {
+
+}

+ 33 - 0
app-entity/src/main/java/com/hboxs/entity/Price.java

@@ -0,0 +1,33 @@
+package com.hboxs.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "t_price")
+@SequenceGenerator(name = "sequenceGenerator", sequenceName = "t_price_sequence")
+public class Price extends BaseEntity{
+
+  private String name;
+
+  private double price;
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+
+  public double getPrice() {
+    return price;
+  }
+
+  public void setPrice(double price) {
+    this.price = price;
+  }
+
+}

+ 9 - 1
app-entity/src/main/java/com/hboxs/entity/PromoCode.java

@@ -15,7 +15,7 @@ public class PromoCode extends BaseEntity{
 
   private String adminId;
 
-//  private Date createDate;
+  private Date lastUseDate;
 
   private String useDate;
 
@@ -43,6 +43,14 @@ public class PromoCode extends BaseEntity{
     this.useDate = useDate;
   }
 
+  public Date getLastUseDate() {
+    return lastUseDate;
+  }
+
+  public void setLastUseDate(Date lastUseDate) {
+    this.lastUseDate = lastUseDate;
+  }
+
   public String getUserName() {
     return userName;
   }

+ 15 - 0
app-service/src/main/java/com/hboxs/service/PriceService.java

@@ -0,0 +1,15 @@
+/*
+ *
+ * PriceService
+ *
+ */
+package com.hboxs.service;
+
+import com.hboxs.entity.Price;
+
+/**
+ * Service -
+ */
+public interface PriceService extends BaseService<Price, Long> {
+
+}

+ 30 - 0
app-service/src/main/java/com/hboxs/service/impl/PriceServiceImpl.java

@@ -0,0 +1,30 @@
+/*
+ *
+ *  PriceServiceImpl
+ *
+ */
+package com.hboxs.service.impl;
+
+import com.hboxs.dao.PriceDao;
+import com.hboxs.entity.Price;
+import com.hboxs.service.PriceService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+/**
+ * Service -
+ */
+@Service("priceServiceImpl")
+public class PriceServiceImpl extends BaseServiceImpl<Price, Long> implements PriceService {
+
+    @Resource(name = "priceDaoImpl")
+    private PriceDao priceDao;
+
+    @Resource(name = "priceDaoImpl")
+    public void setBaseDao(PriceDao priceDao) {
+        super.setBaseDao(priceDao);
+    }
+
+
+}

+ 1 - 1
app-service/src/main/java/com/hboxs/service/impl/PromoCodeServiceImpl.java

@@ -16,7 +16,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 /**
- * Service - 广告管理
+ * Service - 优惠码
  */
 @Service("promoCodeServiceImpl")
 public class PromoCodeServiceImpl extends BaseServiceImpl<PromoCode, Long> implements PromoCodeService {