Browse Source

修改用户剩余量充值

fuwencai 4 years ago
parent
commit
04966776f2
5 changed files with 368 additions and 341 deletions
  1. 8 5
      manage/user/userRecharge.go
  2. 3 4
      service/user.go
  3. 16 21
      service/userRecharge.go
  4. 224 220
      static/templates/login.html
  5. 117 91
      static/templates/userRecharge.html

+ 8 - 5
manage/user/userRecharge.go

@@ -1,13 +1,12 @@
 package user
 
 import (
+	"github.com/gin-gonic/gin"
+	"go.uber.org/zap"
 	"sfbase/global"
 	"sfis/model/response"
 	"sfis/service"
 	"strconv"
-
-	"github.com/gin-gonic/gin"
-	"go.uber.org/zap"
 )
 
 //余额充值接口
@@ -37,8 +36,10 @@ func productRecharge(c *gin.Context) {
 	appid := c.PostForm("appid")
 	productId, err := strconv.Atoi(c.PostForm("productId"))
 	rechargeNum, errs := strconv.Atoi(c.PostForm("rechargeNum"))
+	startTime := c.PostForm("startTime")
 	endTime := c.PostForm("endTime")
-	if err != nil || errs != nil {
+	tradeMoney, errs_ := strconv.Atoi(c.PostForm("tradeMoney"))
+	if err != nil || errs != nil || errs_ != nil {
 		response.FailWithDetailed(response.ParamError, nil, "参数错误", c)
 		return
 	}
@@ -46,10 +47,12 @@ func productRecharge(c *gin.Context) {
 		"appid":       appid,
 		"productId":   productId,
 		"rechargeNum": rechargeNum,
+		"startTime":   startTime,
 		"endTime":     endTime,
+		"tradeMoney":  tradeMoney,
 	}
 	global.Logger.Info("api productRecharge:", zap.Any("param:", p))
-	errss := service.ProductRecharge(appid, productId, rechargeNum, endTime, c)
+	errss := service.ProductRecharge(appid, productId, rechargeNum, startTime, endTime, tradeMoney, c)
 	if errs == nil {
 		response.Ok(c)
 	} else {

+ 3 - 4
service/user.go

@@ -137,13 +137,12 @@ func CreateUserProduct(appId string, productArr []map[string]interface{}, buyTyp
 	return 1, haveProductId, errArr
 }
 
-func UserProductList(appId string, c *gin.Context) (userProduct []model.UserProduct, err error) {
-	//userProduct := []model.UserProduct{}
-	err = db.GetSFISDB().Where("app_id = ? ", appId).Find(&userProduct).Error
+func UserProductList(appId string, c *gin.Context) (results []map[string]interface{}, err error) {
+	err = db.GetSFISDB().Table("user_product").Select("user_product.app_id, user_product.product_id,user_product.create_at,user_product.start_at,user_product.end_at,user_product.left_num,user_product.cost_model,user_product.interface_status,user_product.call_times_limit_day,user_product.data_num_limit_one_times,product.name").Joins("left join product on product.id = user_product.product_id").Where("app_id = ? ", appId).Scan(&results).Error
 	if err != nil {
 		log.Printf("appID:[%s] find into user_product error:[%v]", appId, err)
 	}
-	return userProduct, err
+	return results, err
 }
 
 //创建用户

+ 16 - 21
service/userRecharge.go

@@ -1,17 +1,15 @@
 package service
 
 import (
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"gorm.io/gorm"
+	"log"
 	"sfis/db"
 	"sfis/lock"
 	"sfis/model"
-
-	"github.com/gin-gonic/gin"
-
-	"log"
 	"sfis/utils"
 	"time"
-
-	"gorm.io/gorm"
 )
 
 func MoneyRecharge(appid string, money int, context *gin.Context) error {
@@ -46,42 +44,39 @@ func MoneyRecharge(appid string, money int, context *gin.Context) error {
 	return errs
 }
 
-func ProductRecharge(appid string, productId, rechargeNum int, endTime string, context *gin.Context) error {
+func ProductRecharge(appid string, productId, rechargeNum int, startTime string, endTime string, tradeMoney int, context *gin.Context) error {
 	//取出用户锁
 	lock.MainLock.Lock()
 	userLock := lock.UserLockMap[appid]
 	lock.MainLock.Unlock()
 	userLock.Lock()
 	defer userLock.Unlock()
-	endTimes := ""
-	if endTime != "" {
-		end := endTime + " 23:59:59"
-		loc, _ := time.LoadLocation("Local")
-		if ends, err := time.ParseInLocation("2006-01-02 15:04:05", end, loc); err == nil {
-			endTimes = ends.Local().Format("2006-01-02 15:04:05")
-		}
-	}
+
 	//查用户当前剩余量
+	fmt.Println(startTime, endTime)
 	userProduct := &model.UserProduct{}
 	db.GetSFISDB().First(userProduct, &model.UserProduct{AppID: appid, ProductID: productId})
 	product := &model.Product{}
 	if products, ok := utils.ProductCaches.Map.Load(productId); ok {
 		product = products.(*model.Product)
 	}
+	// 更新时间
+	nowStr := time.Now().Local().Format("2006-01-02 15:04:05")
+
 	errs := db.GetSFISDB().Transaction(func(tx *gorm.DB) error {
 		before := userProduct.LeftNum
 		after := userProduct.LeftNum + rechargeNum
 		//充值
 		var err error
-		if endTimes != "" {
-			err = tx.Exec("update user_product set left_num = ?,end_at = ? WHERE `app_id` = ? and product_id = ?", after, endTimes, appid, productId).Error
+		if endTime != "" && startTime != "" {
+			err = tx.Exec("update user_product set left_num = ?,start_at=?,end_at = ? ,update_at = ? WHERE `app_id` = ? and product_id = ?", after, startTime, endTime,nowStr, appid, productId).Error
 			if err != nil {
-				log.Printf("appID:[%s],left_num:[%d],endtime:[%s] execute cost user_product error:[%v]", appid, after, endTimes, err)
+				log.Printf("appID:[%s],left_num:[%d],endtime:[%s],starttime:[%s]  execute cost user_product error:[%v]", appid, after, endTime, startTime, err)
 				tx.Rollback()
 				return err
 			}
 		} else {
-			err = tx.Exec("update user_product set left_num = ? WHERE `app_id` = ? and product_id = ?", after, appid, productId).Error
+			err = tx.Exec("update user_product set left_num = ?,update_at = ? WHERE `app_id` = ? and product_id = ?", after,nowStr, appid, productId).Error
 			if err != nil {
 				log.Printf("appID:[%s],left_num:[%d] execute cost user_product error:[%v]", appid, after, err)
 				tx.Rollback()
@@ -89,9 +84,9 @@ func ProductRecharge(appid string, productId, rechargeNum int, endTime string, c
 			}
 		}
 		//生购买记录
-		err = tx.Exec("insert into user_buy_record (app_id,product_id,user_product_id,`before`,`after`,trade_money,buy_type,history_unit_price) values (?,?,?,?,?,?,?,?)", appid, productId, userProduct.ID, before, after, product.UnitPrice*rechargeNum, 1, product.UnitPrice).Error
+		err = tx.Exec("insert into user_buy_record (app_id,product_id,user_product_id,`before`,`after`,trade_money,buy_type,history_unit_price,create_at) values (?,?,?,?,?,?,?,?,?)", appid, productId, userProduct.ID, before, after, tradeMoney, 1, product.UnitPrice,nowStr).Error
 		if err != nil {
-			log.Printf("appID:[%s],product_id:[%d],user_product_id:[%d],after:[%d],trade_money:[%d] execute insert into user_buy_record error:[%v]", appid, productId, userProduct.ID, after, product.UnitPrice*rechargeNum, err)
+			log.Printf("appID:[%s],product_id:[%d],user_product_id:[%d],after:[%d],trade_money:[%d] execute insert into user_buy_record error:[%v]", appid, productId, userProduct.ID, after, tradeMoney, err)
 			tx.Rollback()
 			return err
 		}

+ 224 - 220
static/templates/login.html

@@ -1,249 +1,253 @@
 {{define "login.html"}}
-    <!DOCTYPE html>
-    <html lang="en">
-    <head>
-        <meta charset="UTF-8">
-        <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
-        <script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.js"></script>
-        <title>接口服务平台后台管理系统</title>
-    </head>
-    <style>
-
-    </style>
-    <body>
-    <style>
-        .title {
-            text-align: center;
-        }
-
-        .tableDiv {
-            margin-top: 20px;
-        }
-
-        .box tr td {
-            text-align: center;
-        }
-
-        .handle a {
-            text-decoration: none;
-            margin-right: 5px;
-        }
-
-        .userProductList {
-            margin-top: 20px;
-        }
-
-        .userProTbody tr td {
-            text-align: center;
-        }
-
-        .test {
-
-            width: 400px;
-            height: 400px;
-        }
-
-
-    </style>
-    <div>
-        <h1 class="title">接口服务平台测试系统</h1>
-    </div>
-    <div>
-        <button style="width: 80px;height: 35px"><a style="text-decoration:none;" href="/page/createUser">创建用户</a>
-        </button>
-    </div>
-    <div class="tableDiv">
-        <table border="0" id="tableId" hidden>
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
+    <script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.js"></script>
+    <title>接口服务平台后台管理系统</title>
+</head>
+<style>
+
+</style>
+<body>
+<style>
+    .title {
+        text-align: center;
+    }
+
+    .tableDiv {
+        margin-top: 20px;
+    }
+
+    .box tr td {
+        text-align: center;
+    }
+
+    .handle a {
+        text-decoration: none;
+        margin-right: 5px;
+    }
+
+    .userProductList {
+        margin-top: 20px;
+    }
+
+    .userProTbody tr td {
+        text-align: center;
+    }
+
+    .test {
+
+        width: 400px;
+        height: 400px;
+    }
+
+
+</style>
+<div>
+    <h1 class="title">接口服务平台测试系统</h1>
+</div>
+<div>
+    <button style="width: 80px;height: 35px"><a style="text-decoration:none;" href="/page/createUser">创建用户</a>
+    </button>
+</div>
+<div class="tableDiv">
+    <table border="0" id="tableId" hidden>
+        <thead>
+        <tr class="tableTitle">
+            <th style="width: 5%">序号</th>
+            <th style="width: 25%">客户名称</th>
+            <th style="width: 20%">APPID</th>
+            <th style="width: 10%">密钥</th>
+            <th style="width: 10%">客户电话</th>
+            <th style="width: 10%">余额</th>
+            <th style="width: 20%">操作</th>
+        </tr>
+        </thead>
+        <tbody class="box">
+
+        </tbody>
+    </table>
+</div>
+<div class="userProductList">
+    <div class="userProductDiv" hidden>
+        <p class="nodata"></p>
+        <h3>用户购买产品列表</h3>
+        <table border="0" id="userProduct">
             <thead>
             <tr class="tableTitle">
                 <th style="width: 5%">序号</th>
-                <th style="width: 25%">客户名称</th>
-                <th style="width: 20%">APPID</th>
-                <th style="width: 10%">密钥</th>
-                <th style="width: 10%">客户电话</th>
-                <th style="width: 10%">余额</th>
-                <th style="width: 20%">操作</th>
+                <th style="width: 5%">产品ID</th>
+                <th style="width: 8%">产品名称</th>
+                <th style="width: 25%">用户APPID</th>
+                <th style="width: 5%">剩余量</th>
+                <th style="width: 10%">扣费模式</th>
+                <th style="width: 5%">状态</th>
+                <th style="width: 10%">每日调用次数</th>
+                <th style="width: 10%">单次返回数量</th>
+                <th style="width: 25%">操作</th>
             </tr>
             </thead>
-            <tbody class="box">
+            <tbody class="userProTbody">
 
             </tbody>
         </table>
     </div>
-    <div class="userProductList">
-        <div class="userProductDiv" hidden>
-            <p class="nodata"></p>
-            <h3>用户购买产品列表</h3>
-            <table border="0" id="userProduct">
-                <thead>
-                <tr class="tableTitle">
-                    <th style="width: 5%">序号</th>
-                    <th style="width: 5%">产品ID</th>
-                    <th style="width: 25%">用户APPID</th>
-                    <th style="width: 5%">剩余量</th>
-                    <th style="width: 10%">扣费模式</th>
-                    <th style="width: 5%">状态</th>
-                    <th style="width: 10%">每日调用次数</th>
-                    <th style="width: 10%">单次返回数量</th>
-                    <th style="width: 25%">操作</th>
-                </tr>
-                </thead>
-                <tbody class="userProTbody">
-
-                </tbody>
-            </table>
-        </div>
-
-    </div>
 
-    {{/*<div class="test">
-        <h3 id="demo">并发测试</h3>
-        <input type="text" placeholder="请输入并发量">
-        <button>确定</button>
-    </div>*/}}
-    <div class="result"></div>
-
-
-    <script>
-        userList()
-
-        function userList() {
-            $.ajax({
-                url: "/manage/user/list",
-                type: "POST",
-                dataType: "json",
-                async: false,
-                success: function (r) {
-                    if (r.code === 0) {
-                        var str = ""
-                        if (r.data.length != 0) {
-                            $("#tableId").show();
-                            for (var i = 0; i < r.data.length; i++) {
-                                var item = r.data[i];
-                                str += "<tr >";
-                                str += "<td style='width: 50px'>" + (i + 1) + "</td>";
-                                str += "<td style='width: 100px'><a href='javascript:void(0);' style='pointer:hand;' onclick=\"userProductList('" + item.app_id + "','" + item.secret_key + "')\">" + item.name + "</a></td>";
-                                str += "<td style='width: 200px'>" + item.app_id + "</td>";
-                                str += "<td style='width: 100px'>" + item.secret_key + "</td>";
-                                str += "<td style='width: 100px'>" + item.phone + "</td>";
-                                str += "<td style='width: 100px'>" + (item.money / 100) + "</td>";
-                                str += "<td class='handle' style='width: 100px'><a href=\"/page/moneyRechargePage?appId=" + item.app_id + "\">余额充值</a><a href=\"/page/chooseProductPage?appId=" + item.app_id + "\">购买产品</a></td>";
-
-                                str += "</tr>";
-                            }
-                            $(".box").html(str);
-                        } else {
-                            $(".tableDiv").html("还没有客户,请添加客户信息");
+</div>
+
+{{/*
+<div class="test">
+    <h3 id="demo">并发测试</h3>
+    <input type="text" placeholder="请输入并发量">
+    <button>确定</button>
+</div>
+*/}}
+<div class="result"></div>
+
+
+<script>
+    userList()
+
+    function userList() {
+        $.ajax({
+            url: "/manage/user/list",
+            type: "POST",
+            dataType: "json",
+            async: false,
+            success: function (r) {
+                if (r.code === 0) {
+                    var str = ""
+                    if (r.data.length != 0) {
+                        $("#tableId").show();
+                        for (var i = 0; i < r.data.length; i++) {
+                            var item = r.data[i];
+                            str += "<tr >";
+                            str += "<td style='width: 50px'>" + (i + 1) + "</td>";
+                            str += "<td style='width: 100px'><a href='javascript:void(0);' style='pointer:hand;' onclick=\"userProductList('" + item.app_id + "','" + item.secret_key + "')\">" + item.name + "</a></td>";
+                            str += "<td style='width: 200px'>" + item.app_id + "</td>";
+                            str += "<td style='width: 100px'>" + item.secret_key + "</td>";
+                            str += "<td style='width: 100px'>" + item.phone + "</td>";
+                            str += "<td style='width: 100px'>" + (item.money / 100) + "</td>";
+                            str += "<td class='handle' style='width: 100px'><a href=\"/page/moneyRechargePage?appId=" + item.app_id + "\">余额充值</a><a href=\"/page/chooseProductPage?appId=" + item.app_id + "\">购买产品</a></td>";
+
+                            str += "</tr>";
                         }
+                        $(".box").html(str);
                     } else {
-                        $(".tableDiv").html(r.msg);
+                        $(".tableDiv").html("还没有客户,请添加客户信息");
                     }
+                } else {
+                    $(".tableDiv").html(r.msg);
                 }
-            })
-        }
+            }
+        })
+    }
+
+    function userProductList(appId, key) {
+        //var appId = $(obj).find("td:eq(2)").text();
+        //var key = $(obj).find("td:eq(3)").text();
+        console.log(appId, "|", key)
+        let param = {
+            "appId": appId
+        };
+        $.ajax({
+            url: "/manage/user/userProductList",
+            type: "POST",
+            dataType: "json",
+            async: false,
+            data: param,
+            success: function (r) {
+                if (r.code === 0) {
+                    var str = "";
+                    console.log(r.data)
+                    if (r.data.length != 0) {
+                        $(".nodata").html("");
+                        $(".userProductDiv").show();
+                        $(".userProTbody").html("");
+                        for (var i = 0; i < r.data.length; i++) {
+                            var item = r.data[i];
+                            str += "<tr>";
+                            str += "<td>" + (i + 1) + "</td>";
+                            str += "<td>" + item.product_id + "</td>";
+                            str += "<td>" + item.name + "</td>";
+                            str += "<td>" + item.app_id + "</td>";
+                            str += "<td>" + item.left_num + "</td>";
+                            if (item.cost_model == 0) {
+                                str += "<td>扣量</td>";
+                            } else {
+                                str += "<td>扣余额</td>";
+                            }
+                            if (item.interface_status == 0) {
+                                str += "<td>开启</td>";
+                            } else {
+                                str += "<td>关闭</td>";
+                            }
+                            str += "<td>" + item.call_times_limit_day + "</td>";
+                            str += "<td>" + item.data_num_limit_one_times + "</td>";
+                            if (item.product_id === 1000 || item.product_id === 1001) {
+                                str += "<td class='handle' style='width: 100px ;'><a href=\"/page/projectListPage?appId=" + appId + "&key=" + key + "\" >测试接口</a>";
+                            } else {
+                                str += "<td class='handle' style='width: 100px;'><a href=\"/page/projectListDetail?appId=" + appId + "&key=" + key + "\"  >测试接口</a>";
+                            }
+                            if (item.cost_model == 0) {
+                                str += "<a href=\"/page/userRecharge?appId=" + appId + "\"  >剩余量充值</a>"
+                            }
+                            str += "<a onclick=\"myFunction('" + appId + "','" + key + "','" + item.product_id + "')\"  href='javascript:void(0);' style='pointer:hand;'>并发测试</a>"
+                            // else {
+                            //
+                            // }
+                            str += "</td>";
+                            str += "</tr>";
+                        }
+                        // console.log(str);
+                        let trBody = $(str);
+                        $(".userProTbody").append(trBody);
+                    } else {
+                        $(".userProductDiv").hide();
+                    }
 
-        function userProductList(appId, key) {
-            //var appId = $(obj).find("td:eq(2)").text();
-            //var key = $(obj).find("td:eq(3)").text();
-            console.log(appId, "|", key)
-            let param = {
-                "appId": appId
-            };
+                } else {
+                    $(".userProductList").html(r.msg);
+                }
+            }
+        })
+    }
+
+    //并发测试点击事件,参数 appid 产品id,并发量
+
+    function myFunction(appId, key, productId) {
+        console.log(appId, key, productId)
+        var num = prompt("请输入并发量", "");
+        if (num != null && num != "") {
+            console.log(num)
+            var param = {
+                "appid": appId,
+                "productId": productId,
+                "count": num,
+            }
             $.ajax({
-                url: "/manage/user/userProductList",
+                url: "/manage/user/concurrentTest",
                 type: "POST",
                 dataType: "json",
                 async: false,
                 data: param,
                 success: function (r) {
-                    if (r.code === 0) {
-                        var str = "";
-                        console.log(r.data)
-                        if (r.data.length != 0) {
-                            $(".nodata").html("");
-                            $(".userProductDiv").show();
-                            $(".userProTbody").html("");
-                            for (var i = 0; i < r.data.length; i++) {
-                                var item = r.data[i];
-                                str += "<tr>";
-                                str += "<td>" + (i + 1) + "</td>";
-                                str += "<td>" + item.product_id + "</td>";
-                                str += "<td>" + item.app_id + "</td>";
-                                str += "<td>" + item.left_num + "</td>";
-                                if (item.cost_model == 0) {
-                                    str += "<td>扣量</td>";
-                                } else {
-                                    str += "<td>扣余额</td>";
-                                }
-                                if (item.interface_status == 0) {
-                                    str += "<td>开启</td>";
-                                } else {
-                                    str += "<td>关闭</td>";
-                                }
-                                str += "<td>" + item.call_times_limit_day + "</td>";
-                                str += "<td>" + item.data_num_limit_one_times + "</td>";
-                                if (item.product_id === 1000 || item.product_id === 1001) {
-                                    str += "<td class='handle' style='width: 100px ;'><a href=\"/page/projectListPage?appId=" + appId + "&key=" + key + "\" >测试接口</a>";
-                                } else {
-                                    str += "<td class='handle' style='width: 100px;'><a href=\"/page/projectListDetail?appId=" + appId + "&key=" + key + "\"  >测试接口</a>";
-                                }
-                                if (item.cost_model == 0) {
-                                    str += "<a href=\"/page/userRecharge?appId=" + appId + "\"  >剩余量充值</a>"
-                                }
-                                str += "<a onclick=\"myFunction('" + appId + "','" + key + "','" + item.product_id + "')\"  href='javascript:void(0);' style='pointer:hand;'>并发测试</a>"
-                                // else {
-                                //
-                                // }
-                                str += "</td>";
-                                str += "</tr>";
-                            }
-                            // console.log(str);
-                            let trBody = $(str);
-                            $(".userProTbody").append(trBody);
-                        } else {
-                            $(".userProductDiv").hide();
-                        }
-
-                    } else {
-                        $(".userProductList").html(r.msg);
-                    }
+                    // if (r.code === 0) {
+                    alert(JSON.stringify(r))
+                    // $(".result").html(r)
+                    // } else {
+                    //
+                    // }
                 }
             })
-        }
-
-        //并发测试点击事件,参数 appid 产品id,并发量
-
-        function myFunction(appId, key, productId) {
-            console.log(appId, key, productId)
-            var num = prompt("请输入并发量", "");
-            if (num != null && num != "") {
-                console.log(num)
-                var param = {
-                    "appid": appId,
-                    "productId": productId,
-                    "count": num,
-                }
-                $.ajax({
-                    url: "/manage/user/concurrentTest",
-                    type: "POST",
-                    dataType: "json",
-                    async: false,
-                    data: param,
-                    success: function (r) {
-                        // if (r.code === 0) {
-                        alert(JSON.stringify(r))
-                        // $(".result").html(r)
-                        // } else {
-                        //
-                        // }
-                    }
-                })
 
-            }
         }
+    }
 
 
-    </script>
-    </body>
-    </html>
+</script>
+</body>
+</html>
 {{end}}

+ 117 - 91
static/templates/userRecharge.html

@@ -1,96 +1,122 @@
 {{define "userRecharge.html"}}
-    <!DOCTYPE html>
-    <html lang="en">
-    <head>
-        <meta charset="UTF-8">
-        <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
-        <title>接口服务平台后台管理系统</title>
-    </head>
-    <style>
-      .list a {
-          text-decoration: none;
-      }
-    </style>
-    <body>
-        {{/*<div id="main">
-            <div class="list">
-                <h1>充值接口</h1>
-                <a href="#" onclick="$('#money').show();$('#main').hide();">1.余额充值</a><br>
-                <a href="#" onclick="$('#product').show();$('#main').hide();">2.剩余量充值</a>
-            </div>
-        </div>*/}}
-        {{/*<div id="money" style="display: none;">
-            <input type="number" id="moneys" placeholder="请输入充值金额">
-            <button type="button" id="moneyBtn">提交</button>
-        </div>*/}}
-        <h3>剩余量充值</h3>
-        <div id="product">
-            <!-- <input type="number" id="productId" placeholder="请输入产品id"> -->
-            产品 <select id="productId"></select>
-            <input type="number" id="rechargeNum" placeholder="请输入充值次数">
-            <input type="text" id="endTime" placeholder="请输入结束时间">
-            <button type="button" id="productBtn">提交</button>
-        </div>
-        <div id="resultContent"></div>
-        <script>
-            var appid = getParam("appId");
-            if (appid !== "") {
-                $.ajax({
-                    url: "/manage/user/userProductList",
-                    type: "post",
-                    data: {"appId":appid},
-                    success:function(r){
-                    	if(r.data){
-                            var html = ""
-                            for (var i in r.data){
-                                html += `<option value ="${r.data[i]["product_id"]}">${r.data[i]["product_id"]}</option>`
-                            }
-                            $("#productId").append(html);
-                    	}
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
+    <title>接口服务平台后台管理系统</title>
+</head>
+<style>
+    .list a {
+        text-decoration: none;
+    }
+</style>
+<body>
+{{/*
+<div id="main">
+    <div class="list">
+        <h1>充值接口</h1>
+        <a href="#" onclick="$('#money').show();$('#main').hide();">1.余额充值</a><br>
+        <a href="#" onclick="$('#product').show();$('#main').hide();">2.剩余量充值</a>
+    </div>
+</div>
+*/}}
+{{/*
+<div id="money" style="display: none;">
+    <input type="number" id="moneys" placeholder="请输入充值金额">
+    <button type="button" id="moneyBtn">提交</button>
+</div>
+*/}}
+<h3>剩余量充值</h3>
+<div id="product">
+    <!-- <input type="number" id="productId" placeholder="请输入产品id"> -->
+    产品 <select id="productId"></select><br><br>
+    充值次数 <input type="number" id="rechargeNum" placeholder="请输入充值次数"><br><br>
+    开始时间 <input type="text" id="startTime" placeholder="请输入开始时间"><br><br>
+    结束时间 <input type="text" id="endTime" placeholder="请输入结束时间"><br><br>
+    交易金额 <input type="text" id="tradeMoney" placeholder="请输入交易金额"> <br><br>
+    <button type="button" id="productBtn">提交</button>
+</div>
+<div id="resultContent"></div>
+<script>
+    $(document).ready(function () {
+        // 初始化内容
+        var myDate = new Date;
+        var year = myDate.getFullYear(); //获取当前年
+        var mon = myDate.getMonth() + 1; //获取当前月
+        var date = myDate.getDate(); //获取当前日
+        var h = myDate.getHours();//获取当前小时数(0-23)
+        var m = myDate.getMinutes();//获取当前分钟数(0-59)
+        var s = myDate.getSeconds();//获取当前秒
+        startTime = year + "-" + mon + "-" + date + " " + h + ":" + m + ":" + s
+        endYear = year + 1
+        endTime = endYear + "-" + mon + "-" + date + " " + h + ":" + m + ":" + s
+        console.log(startTime)
+        $("#startTime").val(startTime)
+        $("#endTime").val(endTime)
+    });
+
+    var appid = getParam("appId");
+    if (appid !== "") {
+        $.ajax({
+            url: "/manage/user/userProductList",
+            type: "post",
+            data: {"appId": appid},
+            success: function (r) {
+                if (r.data) {
+                    var html = ""
+                    for (var i in r.data) {
+                        html += `<option value ="${r.data[i]["product_id"]}">${r.data[i]["name"]}(${r.data[i]["product_id"]})</option>`
                     }
-                })
+                    $("#productId").append(html);
+                }
             }
-            
-            $("#productBtn").on("click", function(){
-                var param = {
-                    "appid": appid,
-                    "rechargeNum": $("#rechargeNum").val(),
-                    "productId": $("#productId option:selected").val(),
-                    "endTime": $("#endTime").val()
-                };
-                var url = "/manage/user/productRecharge";
-                var rType = "post";
-                submit(param,rType,url);
-            })
-            
-            // 获取上个页面传来的参数
-            function getParam(name) {
-                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
-                var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
-                var context = "";
-                if (r != null)
-                    context = r[2];
-                reg = null;
-                r = null;
-                return context == null || context == "" || context == "undefined" ? "" : context;
+        })
+    }
+
+    $("#productBtn").on("click", function () {
+        var param = {
+            "appid": appid,
+            "rechargeNum": $("#rechargeNum").val(),
+            "productId": $("#productId option:selected").val(),
+            "startTime": $("#startTime").val(),
+            "endTime": $("#endTime").val(),
+            "tradeMoney": $("#tradeMoney").val() * 100
+        };
+        var url = "/manage/user/productRecharge";
+        var rType = "post";
+        submit(param, rType, url);
+    })
+
+    // 获取上个页面传来的参数
+    function getParam(name) {
+        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
+        var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
+        var context = "";
+        if (r != null)
+            context = r[2];
+        reg = null;
+        r = null;
+        return context == null || context == "" || context == "undefined" ? "" : context;
+    }
+
+    function submit(param, rType, url, hearders) {
+        $.ajax({
+            url: url,
+            type: rType,
+            headers: hearders,
+            data: param,
+            success: function (r) {
+                $("#resultContent").text("");
+                if (r.code === 1000) {
+                    $("#resultContent").text(r.msg);
+                } else {
+                    $("#resultContent").text(r.msg);
+                }
             }
-            function submit(param, rType, url, hearders) {
-                $.ajax({
-                    url: url,
-                    type: rType,
-                    headers: hearders,
-                    data: param,
-                    success: function (r) {
-                        $("#resultContent").text("");
-                        if (r.code === 1000) {
-                            $("#resultContent").text(r.msg);
-                        } else {
-                            $("#resultContent").text(r.msg);
-                        }
-                    }
-                })
-            }
-        </script>
-    </body>
-    </html>
+        })
+    }
+</script>
+</body>
+</html>
 {{end}}