Bläddra i källkod

选择产品测试页面

jiaojiao7 4 år sedan
förälder
incheckning
62dfc7f445
4 ändrade filer med 220 tillägg och 60 borttagningar
  1. 3 1
      manage/user/user.go
  2. 5 0
      router/pageRouter.go
  3. 149 0
      static/templates/chooseProduct.html
  4. 63 59
      static/templates/login.html

+ 3 - 1
manage/user/user.go

@@ -67,9 +67,11 @@ func userProductChoose(c *gin.Context) {
 		productArr = sutils.ObjArrToMapArr(_products)
 		log.Println(productArr)
 	}
-	//log.Println(len(productArr), appId)
+	log.Println("appid", appId)
+	log.Println(len(productArr), appId)
 	if appId != "" && len(productArr) > 0 {
 		status, haveProductId, err := service.CreateUserProduct(appId, productArr, buyType)
+		log.Println(status, haveProductId, err)
 		if status == 1 && err == nil {
 			if haveProductId != "" {
 				response.OkWithMessage("用户已购买过"+haveProductId+"产品,请去充值", c)

+ 5 - 0
router/pageRouter.go

@@ -9,9 +9,14 @@ func pageRouterRegister(router *gin.Engine) {
 	//pageRouterGroup.Use(middleware.JwtAuth())
 	{
 		pageRouterGroup.GET("/main", mainPage)
+		pageRouterGroup.GET("/chooseProductPage", chooseProductPage)
 	}
 }
 
 func mainPage(context *gin.Context) {
 	context.HTML(200, "login.html", nil)
 }
+
+func chooseProductPage(context *gin.Context) {
+	context.HTML(200, "chooseProduct.html", nil)
+}

+ 149 - 0
static/templates/chooseProduct.html

@@ -0,0 +1,149 @@
+{{define "chooseProduct.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>
+    <body>
+    <table border="0" id="tableId">
+        <thead>
+        <tr class="tableTitle">
+            <th style="width: 20px"><input type="checkbox" name="item">
+            </td></th>
+            <th style="width: 50px">序号</th>
+            <th style="width: 100px">产品名称</th>
+            <th style="width: 200px">url</th>
+            <th style="width: 100px">产品单价</th>
+            <th style="width: 100px">产品类型</th>
+            <th style="width: 100px">最小单位</th>
+            <th style="width: 100px">试用次数</th>
+            {{/*            <th style="width: 100px">开始时间</th>*/}}
+            {{/*            <th style="width: 100px">结束时间</th>*/}}
+            {{/*            <th style="width: 100px">结束时间</th>*/}}
+        </tr>
+        </thead>
+        <tbody class="box">
+
+        </tbody>
+    </table>
+    <div style="margin-top: 20px">
+        开始时间:<input id="startTime" type="text">
+        结束时间:<input id="endTime" type="text" name="" id=""><br>
+        扣费模式:<select id="costModel" style="width: 165px;height: 25px;margin-top: 10px">
+            <option value="0">剩余量</option>
+            <option value="1">余额</option>
+        </select>
+        充值量:<input id="leftNum" type="text"><br>
+        充值金额:<input id="money" type="text">
+        产品状态:<select id="interfaceStatus" style="width: 165px;height: 25px;margin-top: 10px">
+            <option value="0">开启</option>
+            <option value="1">关闭</option>
+        </select><br>
+        每日调用次数:<input id="dayLimit" type="text">
+        每次获取数据量:<input id="oneLimit" type="text">
+        用户appid:<input id="appId" type="text">
+    </div>
+    <div style="margin-top: 10px">
+        <button type="submit" onclick="submit()" style="width: 80px;height: 30px;">提交</button>
+    </div>
+
+    <div>
+        <p class="result"></p>
+    </div>
+
+    </body>
+    </html>
+    <script>
+        productList()
+
+        function productList() {
+            $.ajax({
+                url: "/manage/product/list",
+                type: "POST",
+                dataType: "json",
+                async: false,
+                success: function (r) {
+                    if (r.code === 0) {
+                        console.log(r.data)
+                        var str = ""
+                        for (var i = 0; i < r.data.length; i++) {
+                            var item = r.data[i];
+                            str += '<tr>';
+                            str += '<td style="width: 20px"><input id=' + item["id"] + ' value=' + item["id"] + ' type="radio" name="item"></td>';
+                            str += '<td style="width: 50px">' + (i + 1) + '</td>';
+                            str += '<td style="width: 100px">' + item.name + '</td>';
+                            str += '<td style="width: 200px">' + item.url + '</td>';
+                            str += '<td style="width: 100px">' + item.unit_price + '</td>';
+                            if (item.product_type === 0) {
+                                str += '<td style="width: 100px">按次</td>';
+                            } else {
+                                str += '<td style="width: 100px">按条</td>';
+                            }
+
+                            str += '<td style="width: 100px">' + item.min_unit + '</td>';
+                            str += '<td style="width: 100px">' + item.test_num + '</td>';
+                            str += '</tr>';
+                        }
+                        $('.box').html(str);
+                    } else {
+
+                    }
+                }
+            })
+        }
+
+        function submit() {
+            var productId = $("input[name='item']:checked").val();
+            var startTime = $("#startTime").val();
+            var endTime = $("#endTime").val();
+            var leftNum = $("#leftNum").val();
+            var money = $("#money").val();
+            var costModel = $("#costModel").find("option:selected").val();
+            var interfaceStatus = $("#interfaceStatus").find("option:selected").val();
+            var dayLimit = $("#dayLimit").val();
+            var oneLimit = $("#oneLimit").val();
+            var appId = $("#appId").val();
+            var product = {}
+            product["productId"] = productId
+            product["startTime"] = startTime
+            product["endTime"] = endTime
+            product["leftNum"] = leftNum
+            product["tradeMoney"] = money
+            product["costModel"] = costModel
+            product["interfaceStatus"] = interfaceStatus
+            product["callTimesLimitDay"] = dayLimit
+            product["dataNumOneTimes"] = oneLimit
+            var products = []
+            products.push(product)
+            param = {
+                "products": products,
+                "appId": appId,
+                "buyType": 1,
+            }
+            console.log("参数:", param)
+            /*if (productId === undefined || productId === "") {
+                return
+            }*/
+            $.ajax({
+                url: "/manage/user/userProductChoose",
+                data: JSON.stringify(param),
+                type: "POST",
+                dataType: "json",
+                async: false,
+                success: function (r) {
+                    var a = JSON.stringify(r)
+                    $(".result").html(a);
+                    /*if (r.code == 0) {
+                        $(".result").html("请求成功!" + r.msg);
+                    } else {
+                        $(".result").html("购买产品失败!" + r.msg);
+                    }
+*/
+                }
+            })
+        }
+    </script>
+{{end}}

+ 63 - 59
static/templates/login.html

@@ -8,72 +8,76 @@
         <title>接口服务平台后台管理系统</title>
     </head>
     <style>
-      
+
     </style>
     <body>
-        <dev id="main">
-            <h1>对外接口</h1>
-            <dev>
-                <a onclick="$('#projectList').show();$('#main').hide();">1.项目列表</a>
-                <a>2.项目详情</a>
-                <a>3.项目列表及详情</a>
-            </dev>
-            <h1>充值接口</h1>
-            <dev>
-                <a>1.余额充值</a>
-                <a>2.产品充值</a>
-            </dev>
-            <h1>内部接口</h1>
-            <dev>
-            </dev>
+    <dev id="main">
+        <h1>对外接口</h1>
+        <dev>
+            <a onclick="$('#projectList').show();$('#main').hide();">1.项目列表</a>
+            <a>2.项目详情</a>
+            <a>3.项目列表及详情</a>
         </dev>
-        <dev id="projectList" style="display: none;">
-            <input type="text" id="projectName" placeholder="请输入项目名">
-            <input type="text" id="winner" placeholder="请输入中标企业名">
-            <input type="text" id="bidTime" placeholder="请输入中标日期">
-            <button type="button" id="projectListBtn">提交</button>
+        <h1>充值接口</h1>
+        <dev>
+            <a href="/page/chooseProductPage">1.选择产品</a>
+            <a>2.余额充值</a>
+            <a>3.产品充值</a>
         </dev>
-        <dev id="resultContent"></dev>
-        <script>
-            var appid = "sfGSVYRQMAAgkGBAUBJg4f";
-            var key = "364xw909";
-            function submit(param,rType,url,hearders){
-                $.ajax({
-                    url: url,
-                    type: rType,
-                    headers: hearders,
-                    data: param,
-                    success:function(r){
-                    	if(r.code === 1000){
-                            $("#resultContent").text(r.msg);
-                    	}else{
-                    		$("#resultContent").text(r.msg);
-                    	}
+        <h1>内部接口</h1>
+        <dev>
+        </dev>
+    </dev>
+    <dev id="projectList" style="display: none;">
+        <input type="text" id="projectName" placeholder="请输入项目名">
+        <input type="text" id="winner" placeholder="请输入中标企业名">
+        <input type="text" id="bidTime" placeholder="请输入中标日期">
+        <button type="button" id="projectListBtn">提交</button>
+    </dev>
+    <dev id="resultContent"></dev>
+    <script>
+        var appid = "sfGSVYRQMAAgkGBAUBJg4f";
+        var key = "364xw909";
+
+        function submit(param, rType, url, hearders) {
+            $.ajax({
+                url: url,
+                type: rType,
+                headers: hearders,
+                data: param,
+                success: function (r) {
+                    if (r.code === 1000) {
+                        $("#resultContent").text(r.msg);
+                    } else {
+                        $("#resultContent").text(r.msg);
                     }
-                })
-            }
-            console.log(md5(appid+"1610611965"+key))
-            $("#projectListBtn").on("click", function(){
-                var param = {
-                    "app_id": appid,
-                    "project_name": $("#projectName").val(),
-                    "winner": $("#winner").val(),
-                    "bid_time": $("#bidTime").val()
-                };
-                var url = "/sfis/api/v1/projectList";
-                var rType = "post";
-                var now = new Date().getTime();
-                var token = md5(appid+Math.round(now/1000)+key);
-                // var token = "6f6d4434cc424a44360ce1b27939500e";
-                console.log(token)
-                var hearders = {
-                    "timestamp": ""+Math.round(now/1000),
-                    // "timestamp": "1610610260",
-                    "token": token
                 }
-                submit(param,rType,url,hearders);
             })
-        </script>
+        }
+
+        console.log(md5(appid + "1610611965" + key))
+        $("#projectListBtn").on("click", function () {
+            var param = {
+                "app_id": appid,
+                "project_name": $("#projectName").val(),
+                "winner": $("#winner").val(),
+                "bid_time": $("#bidTime").val()
+            };
+            var url = "/sfis/api/v1/projectList";
+            var rType = "post";
+            var now = new Date().getTime();
+            var token = md5(appid + Math.round(now / 1000) + key);
+            // var token = "6f6d4434cc424a44360ce1b27939500e";
+            console.log(token)
+            var hearders = {
+                "timestamp": "" + Math.round(now / 1000),
+                // "timestamp": "1610610260",
+                "token": token
+            }
+            submit(param, rType, url, hearders);
+        })
+
+    </script>
     </body>
     </html>
 {{end}}