mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-11 13:53:35 +08:00
多个API支持查询用户查询
This commit is contained in:
@@ -19,7 +19,7 @@ const (
|
|||||||
// 其他节点版本号,用来检测是否有需要升级的节点
|
// 其他节点版本号,用来检测是否有需要升级的节点
|
||||||
|
|
||||||
NodeVersion = "0.3.7"
|
NodeVersion = "0.3.7"
|
||||||
UserNodeVersion = "0.2.0"
|
UserNodeVersion = "0.2.1"
|
||||||
AuthorityNodeVersion = "0.0.2"
|
AuthorityNodeVersion = "0.0.2"
|
||||||
MonitorNodeVersion = "0.0.3"
|
MonitorNodeVersion = "0.0.3"
|
||||||
DNSNodeVersion = "0.2.0"
|
DNSNodeVersion = "0.2.0"
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ func (this *UserAccountDAO) UpdateUserAccount(tx *dbs.Tx, accountId int64, delta
|
|||||||
if account == nil {
|
if account == nil {
|
||||||
return errors.New("invalid account id '" + types.String(accountId) + "'")
|
return errors.New("invalid account id '" + types.String(accountId) + "'")
|
||||||
}
|
}
|
||||||
var userId = int64(account.Id)
|
var userId = int64(account.UserId)
|
||||||
var deltaFloat64 = float64(delta)
|
var deltaFloat64 = float64(delta)
|
||||||
if deltaFloat64 < 0 && account.Total < -deltaFloat64 {
|
if deltaFloat64 < 0 && account.Total < -deltaFloat64 {
|
||||||
return errors.New("not enough account quota to decrease")
|
return errors.New("not enough account quota to decrease")
|
||||||
@@ -235,3 +235,18 @@ func (this *UserAccountDAO) PayBills(tx *dbs.Tx) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckUserAccount 检查用户账户
|
||||||
|
func (this *UserAccountDAO) CheckUserAccount(tx *dbs.Tx, userId int64, accountId int64) error {
|
||||||
|
exists, err := this.Query(tx).
|
||||||
|
Pk(accountId).
|
||||||
|
Attr("userId", userId).
|
||||||
|
Exist()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return models.ErrNotFound
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -50,6 +50,11 @@ var (
|
|||||||
Code: "finance",
|
Code: "finance",
|
||||||
Description: "开启费用账单相关功能",
|
Description: "开启费用账单相关功能",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "套餐",
|
||||||
|
Code: "plan",
|
||||||
|
Description: "用户可以购买和管理套餐",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -86,11 +86,17 @@ func (this *UserPlanDAO) FindEnabledUserPlan(tx *dbs.Tx, userPlanId int64, cache
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CountAllEnabledUserPlans 计算套餐数量
|
// CountAllEnabledUserPlans 计算套餐数量
|
||||||
func (this *UserPlanDAO) CountAllEnabledUserPlans(tx *dbs.Tx, isAvailable bool, isExpired bool, expiringDays int32) (int64, error) {
|
func (this *UserPlanDAO) CountAllEnabledUserPlans(tx *dbs.Tx, userId int64, isAvailable bool, isExpired bool, expiringDays int32) (int64, error) {
|
||||||
var query = this.Query(tx).
|
var query = this.Query(tx).
|
||||||
State(UserPlanStateEnabled).
|
State(UserPlanStateEnabled).
|
||||||
Where("userId IN (SELECT id FROM " + SharedUserDAO.Table + " WHERE state=1)").
|
|
||||||
Where("planId IN (SELECT id FROM " + SharedPlanDAO.Table + " WHERE state=1)")
|
Where("planId IN (SELECT id FROM " + SharedPlanDAO.Table + " WHERE state=1)")
|
||||||
|
|
||||||
|
if userId > 0 {
|
||||||
|
query.Attr("userId", userId)
|
||||||
|
} else {
|
||||||
|
query.Where("userId IN (SELECT id FROM " + SharedUserDAO.Table + " WHERE state=1)")
|
||||||
|
}
|
||||||
|
|
||||||
var today = timeutil.Format("Y-m-d")
|
var today = timeutil.Format("Y-m-d")
|
||||||
if isAvailable {
|
if isAvailable {
|
||||||
query.Gte("dayTo", today)
|
query.Gte("dayTo", today)
|
||||||
@@ -110,10 +116,11 @@ func (this *UserPlanDAO) CountAllEnabledUserPlans(tx *dbs.Tx, isAvailable bool,
|
|||||||
func (this *UserPlanDAO) ListEnabledUserPlans(tx *dbs.Tx, userId int64, isAvailable bool, isExpired bool, expiringDays int32, offset int64, size int64) (result []*UserPlan, err error) {
|
func (this *UserPlanDAO) ListEnabledUserPlans(tx *dbs.Tx, userId int64, isAvailable bool, isExpired bool, expiringDays int32, offset int64, size int64) (result []*UserPlan, err error) {
|
||||||
var query = this.Query(tx).
|
var query = this.Query(tx).
|
||||||
State(UserPlanStateEnabled).
|
State(UserPlanStateEnabled).
|
||||||
Where("userId IN (SELECT id FROM " + SharedUserDAO.Table + " WHERE state=1)").
|
|
||||||
Where("planId IN (SELECT id FROM " + SharedPlanDAO.Table + " WHERE state=1)")
|
Where("planId IN (SELECT id FROM " + SharedPlanDAO.Table + " WHERE state=1)")
|
||||||
if userId > 0 {
|
if userId > 0 {
|
||||||
query.Attr("userId", userId)
|
query.Attr("userId", userId)
|
||||||
|
} else {
|
||||||
|
query.Where("userId IN (SELECT id FROM " + SharedUserDAO.Table + " WHERE state=1)")
|
||||||
}
|
}
|
||||||
var today = timeutil.Format("Y-m-d")
|
var today = timeutil.Format("Y-m-d")
|
||||||
if isAvailable {
|
if isAvailable {
|
||||||
@@ -198,6 +205,22 @@ func (this *UserPlanDAO) FindAllEnabledPlansForServer(tx *dbs.Tx, userId int64,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckUserPlan 检查用户套餐
|
||||||
|
func (this *UserPlanDAO) CheckUserPlan(tx *dbs.Tx, userId int64, userPlanId int64) error {
|
||||||
|
exists, err := this.Query(tx).
|
||||||
|
Pk(userPlanId).
|
||||||
|
Attr("userId", userId).
|
||||||
|
State(UserPlanStateEnabled).
|
||||||
|
Exist()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return ErrNotFound
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// NotifyUpdate 通知更新
|
// NotifyUpdate 通知更新
|
||||||
func (this *UserPlanDAO) NotifyUpdate(tx *dbs.Tx, userPlanId int64) error {
|
func (this *UserPlanDAO) NotifyUpdate(tx *dbs.Tx, userPlanId int64) error {
|
||||||
serverId, err := SharedServerDAO.FindEnabledServerIdWithUserPlanId(tx, userPlanId)
|
serverId, err := SharedServerDAO.FindEnabledServerIdWithUserPlanId(tx, userPlanId)
|
||||||
|
|||||||
Reference in New Issue
Block a user