WH01243 há 3 anos atrás
pai
commit
144fce0630
2 ficheiros alterados com 31 adições e 10 exclusões
  1. 19 7
      service/balanceService.go
  2. 12 3
      service/resourceManageService.go

+ 19 - 7
service/balanceService.go

@@ -138,8 +138,12 @@ func (service *BalanceService) UseUserDetailed(duplicateRemoval int64, balanceDa
 	}
 	sumStruct := "0"
 	if balanceData.ResourceType == "附件下载包" {
-		now := time.Now()
-		endTime := now.AddDate(0, int(-now.Month()+2), -now.Day()).Format("2006-01-02")
+		now1 := time.Now()
+		currentYear, currentMonth, _ := now1.Date()
+		currentLocation := now1.Location()
+		firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation)
+		lastOfMonth := firstOfMonth.AddDate(0, 1, -1)
+		endTime := lastOfMonth.Format("2006-01-02")
 		_, err = orm.Table(AccountResources).
 			Select("sum(number) as  number").
 			Where("accountId=? and  companyId=? and  departmentId=? and  ResourceType=? and  endTime=? and vipTime>?", balanceData.AccountId, balanceData.CompanyId, balanceData.DepartmentId, balanceData.ResourceType, endTime, time.Now().Unix()).
@@ -187,8 +191,12 @@ func (service *BalanceService) UseUserDetailed(duplicateRemoval int64, balanceDa
 	//修改结存
 	balanceList := []entity.Balance{}
 	if balanceData.ResourceType == "附件下载包" {
-		now := time.Now()
-		endTime := now.AddDate(0, int(-now.Month()+2), -now.Day()).Format("2006-01-02")
+		now1 := time.Now()
+		currentYear, currentMonth, _ := now1.Date()
+		currentLocation := now1.Location()
+		firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation)
+		lastOfMonth := firstOfMonth.AddDate(0, 1, -1)
+		endTime := lastOfMonth.Format("2006-01-02")
 		err = orm.Table(AccountResources).
 			Select("*").
 			Where("accountId=? and  companyId=? and  departmentId=? and  number>0 and  ResourceType=? and  endTime=?  and vipTime>?  ", balanceData.AccountId, balanceData.CompanyId, balanceData.DepartmentId, balanceData.ResourceType, endTime, time.Now().Unix()).
@@ -432,15 +440,19 @@ func (service *BalanceService) UpdateVipTime(data *resourcesCenter.VipReq) (int6
 	err := orm.Begin()
 	defer orm.Close()
 	updateNumb := int64(0)
-	now := time.Now()
-	endTime := now.AddDate(0, int(-now.Month()+2), -now.Day()).Format("2006-01-02")
+	now1 := time.Now()
+	currentYear, currentMonth, _ := now1.Date()
+	currentLocation := now1.Location()
+	firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation)
+	lastOfMonth := firstOfMonth.AddDate(0, 1, -1)
+	endTime := lastOfMonth.Format("2006-01-02")
 	dataMap := map[string]interface{}{
 		"vipTime":     data.VipTime,
 	}
 	updateNumb, err = orm.Table(AccountResources).
 		Cols("vipTime").Where("endTime = ? and  accountId=? and resourceType=?",endTime,data.AccountId,"附件下载包").
 		Update(&dataMap)
-	if err != nil || updateNumb <= 0 {
+	if err != nil || updateNumb < 0 {
 		fmt.Println("结存修改失败:", err)
 		orm.Rollback()
 		return entity.ErrorCode, "超级订阅时间修改失败"

+ 12 - 3
service/resourceManageService.go

@@ -35,7 +35,11 @@ func (service *ResourceManageService) FindResourcesAuth(data *resourcesCenter.Re
 func (service *ResourceManageService) FindAccountBalance(in *resourcesCenter.ResourcesReq) ([]*resourcesCenter.ResourceBalance, error) {
 	now := time.Now().Format("2006-01-02")
 	now1 := time.Now()
-	endTime := now1.AddDate(0, int(-now1.Month()+2), -now1.Day()).Format("2006-01-02")
+	currentYear, currentMonth, _ := now1.Date()
+	currentLocation := now1.Location()
+	firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation)
+	lastOfMonth := firstOfMonth.AddDate(0, 1, -1)
+	endTime := lastOfMonth.Format("2006-01-02")
 	orm := entity.Engine.NewSession()
 	var accountBalanceArr []*entity.AccountBalance
 	dataList := make([]*resourcesCenter.ResourceBalance, 0)
@@ -52,7 +56,12 @@ func (service *ResourceManageService) FindAccountBalance(in *resourcesCenter.Res
 		return dataList, err
 	}
 	for _, v := range accountBalanceArr {
-		oldTime := time.Now().AddDate(0, 0, 30).Format("2006-01-02")
+		now1 := time.Now()
+		currentYear, currentMonth, _ := now1.Date()
+		currentLocation := now1.Location()
+		firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation)
+		lastOfMonth := firstOfMonth.AddDate(0, 1, -1)
+		endTime := lastOfMonth.Format("2006-01-02")
 		//统计30内到期数量
 		b := false
 		var err error
@@ -67,7 +76,7 @@ func (service *ResourceManageService) FindAccountBalance(in *resourcesCenter.Res
 			var c int64
 			b, err = orm.Table("account_resources").Select("sum(number) as number").
 				Where("accountId = ? and resourceType = ? and endTime >= ? and endTime <= ?",
-					in.AccountId, v.ResourceType, now, oldTime).Get(&c)
+					in.AccountId, v.ResourceType, now, endTime).Get(&c)
 			isOk, err = orm.Table("account_resources").Select("sum(number) as number").
 				Where("accountId = ? and resourceType = ? and endTime >= ?", in.AccountId, v.ResourceType, now).Get(&number)
 		}