xuzhiheng 4 anos atrás
pai
commit
922b416b2d
1 arquivos alterados com 23 adições e 8 exclusões
  1. 23 8
      src/users/userManage.go

+ 23 - 8
src/users/userManage.go

@@ -324,7 +324,7 @@ func UserSubDetail(context *admin.Context) (interface{}, error) {
 	param := new(struct {
 		utils.Page
 		UserId    string `form:"userId"`    //用户id
-		ServiceId int    `form:"serviceId"` //功能
+		ServiceId string `form:"serviceId"` //功能
 		Phone     string `form:"keyword"`
 	})
 	err := context.Form(param)
@@ -333,15 +333,23 @@ func UserSubDetail(context *admin.Context) (interface{}, error) {
 	}
 	data := map[string]interface{}{}
 	if param.UserId != "" {
-		query := map[string]interface{}{"s_master_userid": param.UserId}
+		sql := "select * from bigmember_consume where s_master_userid = '" + param.UserId + "'"
+		sqls := "select count(1) from bigmember_consume where s_master_userid = '" + param.UserId + "'"
 		if param.Phone != "" {
-			query["s_phone"] = param.Phone
+			sql += " and s_phone = '" + param.Phone + "'"
+			sqls += " and s_phone = '" + param.Phone + "'"
 		}
-		if param.ServiceId != 0 {
-			query["s_serviceid"] = param.ServiceId
+		if param.ServiceId != "" {
+			sql += " and s_serviceid = '" + param.ServiceId + "'"
+			sqls += " and s_serviceid = '" + param.ServiceId + "'"
+		} else {
+			sql += " and (s_serviceid = '11' or s_serviceid = '15')"
+			sqls += " and (s_serviceid = '11' or s_serviceid = '15')"
 		}
-		subData := JysqlDB.Find("bigmember_consume", query, "s_phone,s_serviceid,l_createtime", "l_createtime desc", param.Offset, param.PageSize)
-		count := JysqlDB.Count("bigmember_consume", query)
+		count := JysqlDB.CountBySql(sqls)
+		sql += " order by l_createtime desc"
+		sql += " limit " + fmt.Sprint(param.Offset) + "," + fmt.Sprint(param.PageSize)
+		subData := JysqlDB.SelectBySql(sql)
 		data = map[string]interface{}{
 			"lists": subData,
 			"total": count,
@@ -398,7 +406,7 @@ func SubAdd(context *admin.Context) (interface{}, error) {
 		return nil, nil
 	}
 	if param.Phone != "" {
-		userId, memberStatus, bigEnd := "", 0, int64(0)
+		userId, memberStatus, bigStart, bigEnd := "", 0, int64(0), int64(0)
 		now := time.Now()
 		userData, ok := MQFW.FindOne("user", map[string]interface{}{"s_phone": param.Phone})
 		if ok && len(*userData) > 0 {
@@ -454,9 +462,13 @@ func SubAdd(context *admin.Context) (interface{}, error) {
 			pay := qutil.IntAll((*data)["i_pay_sub_num"])
 			free := qutil.IntAll((*data)["i_free_sub_num"])
 			subCount := pay + free
+			bigStart = qutil.Int64All((*data)["i_member_starttime"])
 			if openCount >= subCount && param.SubStatus == 1 {
 				return nil, errors.New("启用子账号数量已达上限")
 			}
+			if param.SubStatus == 1 && time.Now().Unix() < bigStart {
+				return nil, errors.New("主账号未生效,无法启用子账号")
+			}
 			set := map[string]interface{}{}
 			if param.SubStatus == 0 {
 				set = map[string]interface{}{
@@ -543,6 +555,9 @@ func SubOpenClose(context *admin.Context) (interface{}, error) {
 		} else {
 			return nil, errors.New("主账号信息未找到,请重试")
 		}
+		if time.Now().Unix() < buyStart && param.SubStatus == 1 {
+			return nil, errors.New("主账号未生效,无法启用子账号")
+		}
 		if memberStatus > 0 && subStatus == 0 {
 			return nil, errors.New("已有大会员权限,不能启用")
 		}