jiaojiao7 4 år sedan
förälder
incheckning
722d32d4c3
3 ändrade filer med 108 tillägg och 29 borttagningar
  1. 10 1
      manage/user/user.go
  2. 5 8
      service/user.go
  3. 93 20
      static/templates/login.html

+ 10 - 1
manage/user/user.go

@@ -119,5 +119,14 @@ func userProductChoose(c *gin.Context) {
 func userProductList(c *gin.Context) {
 	appId := c.PostForm("appId")
 	global.Logger.Info("manage userProductList接口参数:", zap.Any("appId", appId))
-	service.UserProductList(appId, c)
+	if appId != "" {
+		userProduct, err := service.UserProductList(appId, c)
+		if len(userProduct) == 0 && err != nil {
+			response.FailWithMessage("查询出错", c)
+		} else {
+			response.OkWithData(userProduct, c)
+		}
+	} else {
+		response.FailWithMessage("缺少参数", c)
+	}
 }

+ 5 - 8
service/user.go

@@ -12,7 +12,6 @@ import (
 	"sfis/db"
 	"sfis/lock"
 	"sfis/model"
-	"sfis/model/response"
 	"strconv"
 	"strings"
 	"sync"
@@ -133,15 +132,13 @@ func CreateUserProduct(appId string, productArr []map[string]interface{}, buyTyp
 	return 1, haveProductId, nil
 }
 
-func UserProductList(appId string, c *gin.Context) {
-	userProduct := []model.UserProduct{}
-	err := db.GetSFISDB().Where("app_id = ? and ", appId).Find(&userProduct).Error
+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
 	if err != nil {
 		log.Printf("appID:[%s] find into user_product error:[%v]", appId, err)
-		response.FailWithMessage("查询出错", c)
-	} else {
-		response.OkWithData(userProduct, c)
 	}
+	return userProduct, err
 }
 
 //创建用户
@@ -217,7 +214,7 @@ func ListUser(condMap map[string]interface{}, page int, limit int) ([]map[string
 	if totalCount == 0 {
 		return userInfo, 0, nil
 	}
-	if whereSql != ""{
+	if whereSql != "" {
 		whereSql = " and " + whereSql
 	}
 	sql := "select user.app_id,user.name,user.phone,user.secret_key,user.ip_white_list,user.create_at,money from user LEFT JOIN  user_account on user.app_id=user_account.app_id where user.delete_at is Null " + whereSql

+ 93 - 20
static/templates/login.html

@@ -29,6 +29,13 @@
             margin-right: 5px;
         }
 
+        .userProductList {
+            margin-top: 20px;
+        }
+
+        .userProTbody tr td {
+            text-align: center;
+        }
     </style>
     <div>
         <h1 class="title">接口服务平台测试系统</h1>
@@ -55,6 +62,31 @@
             </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: 10%">产品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: 20%">操作</th>
+                </tr>
+                </thead>
+                <tbody class="userProTbody">
+
+                </tbody>
+            </table>
+        </div>
+
+    </div>
 
     <script>
         userList()
@@ -72,45 +104,86 @@
                             $("#tableId").show();
                             for (var i = 0; i < r.data.length; i++) {
                                 var item = r.data[i];
-                                str += '<tr style="">';
+                                str += '<tr onclick="userProductList(this)">';
                                 str += '<td style="width: 50px">' + (i + 1) + '</td>';
                                 str += '<td style="width: 100px">' + item.name + '</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 + '</td>';
-                                str += '<td class="handle" style="width: 100px"><a href="/page/userRecharge">充值</a><a href="/page/chooseProductPage">购买产品</a><a href="/page/interfaceListPage">测试接口</a></td>';
+                                str += '<td class="handle" style="width: 100px"><a href="/page/userRecharge">充值</a><a href="/page/chooseProductPage">购买产品</a></td>';
                                 str += '</tr>';
                             }
                             $('.box').html(str);
                         } else {
-                            $("#tableDiv").html("还没有客户,请添加客户信息");
+                            $(".tableDiv").html("还没有客户,请添加客户信息");
                         }
-
                     } else {
-                        $("#tableDiv").html(r.msg);
+                        $(".tableDiv").html(r.msg);
                     }
                 }
             })
         }
 
-
-        /*$("#projectListDetailBtn").on("click", function(){
+        function userProductList(obj, k) {
+            var appId = $(obj).find("td:eq(2)").text();
+            var key = $(obj).find("td:eq(3)").text();
+            console.log(key)
             var param = {
-                "app_id": appid,
-                "winner": $("#winners").val()
-            };
-            var url = "/sfis/api/v1/projectListDetail";
-            var rType = "post";
-            var now = new Date().getTime();
-            var token = md5(appid+Math.round(now/1000)+key);
-            var hearders = {
-                "timestamp": ""+Math.round(now/1000),
-                "token": token
+                "appId": appId
             }
-            submit(param,rType,url,hearders,"listDetail");
-        })*/
+            $.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.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></td>';
+                                } else {
+                                    str += '<td class="handle" style="width: 100px"><a href="/page/projectListDetail?appId=' + appId + '&key=' + key + ' " >测试接口</a></td>';
+                                }
+                                str += '</tr>';
+                            }
+                            $(".userProTbody").html(str);
+                        } else {
+                            $(".userProductDiv").hide();
+                        }
+
+                    } else {
+                        $(".userProductList").html(r.msg);
+                    }
+                }
+            })
+        }
+
     </script>
     </body>
     </html>