Forráskód Böngészése

Merge remote-tracking branch 'origin/feature/v1.0.7' into feature/v1.0.7

jianghan 5 hónapja
szülő
commit
cf033e6b7d

+ 13 - 10
service/balanceService.go

@@ -1,19 +1,20 @@
 package service
 
 import (
-	"app.yhyue.com/moapp/jyResourcesCenter/entity"
-	"app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenter"
-	"app.yhyue.com/moapp/jybase/mongodb"
 	"bytes"
 	"encoding/json"
 	"fmt"
-	"github.com/gogf/gf/v2/util/gconv"
-	"github.com/google/uuid"
 	"io/ioutil"
 	"log"
 	"net/http"
 	"strconv"
 	"time"
+
+	"app.yhyue.com/moapp/jyResourcesCenter/entity"
+	"app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenter"
+	"app.yhyue.com/moapp/jybase/mongodb"
+	"github.com/gogf/gf/v2/util/gconv"
+	"github.com/google/uuid"
 )
 
 type BalanceService struct{}
@@ -160,9 +161,6 @@ func (service *BalanceService) PurchaseUserBalance(balanceData *resourcesCenter.
 
 // 根据账户标识使用资源
 func (service *BalanceService) UseUserDetailed(duplicateRemoval int64, balanceData *resourcesCenter.Balance, detailedData *resourcesCenter.Detailed, infoId, url string, producMap map[string]interface{}, vipState int64, entId, entUserId int64) (int64, string, int64) {
-	orm := entity.Engine.NewSession()
-	jyOrm := entity.JyEngine.NewSession()
-	err := orm.Begin()
 	sourceTypeStr := "3"
 	if vipState > 0 {
 		sourceTypeStr = "4"
@@ -195,7 +193,12 @@ func (service *BalanceService) UseUserDetailed(duplicateRemoval int64, balanceDa
 			return entity.ErrorCode, "去重失败", 0
 		}
 	}
-
+	if deductionNumbs == 0 {
+		return entity.SuccessCode, "使用结存成功", deductionNumbs
+	}
+	orm := entity.Engine.NewSession()
+	jyOrm := entity.JyEngine.NewSession()
+	err := orm.Begin()
 	//查询结存是否够用
 	type SumStruct struct {
 		Age int `xorm:"age"`
@@ -658,7 +661,7 @@ func (service *BalanceService) DataExpireHandle() {
 				entUserId = gconv.Int64(gconv.String(entUserData["id"]))
 				entName := gconv.String(entUserData["name"])
 				entPhone := gconv.String(entUserData["phone"])
-				operator = fmt.Sprintf("%s(%s)", entName, entPhone)
+				operator = fmt.Sprintf("%s(%s)", entName, entPhone)
 			}
 		}
 		detailed := entity.Detailed{

+ 2 - 4
service/exportChargeService.go

@@ -38,8 +38,7 @@ func ChargeAccount(data *resourcesCenter.ChargeAccountReq) (resp *resourcesCente
 	if exportPower == 1 && (entNums > 0 || personNums == 0) {
 		// 企业流量包扣除
 		var personLimit []*entity.PersonLimit
-		err = jyOrm.Table("entniche_export_limit").Select("*").
-			Where("ent_id = ? and user_id = ?", data.EntId, data.EntUserId).Find(&personLimit)
+		err := jyOrm.SQL(`select a.* from jianyu.entniche_export_limit a inner join jianyu.entniche_user b on (a.user_id=? and a.user_id=b.id and b.export_power=1)`, data.EntUserId).Find(&personLimit)
 		if err != nil || personLimit == nil || len(personLimit) == 0 {
 			return &resourcesCenter.ChargeResp{Code: entity.ErrorCode, Message: "企业个人账号限额查询失败"}
 		}
@@ -86,8 +85,7 @@ func entCharge(data *resourcesCenter.ChargeReq) (resp *resourcesCenter.ChargeRes
 	souceOrm := entity.Engine.NewSession()
 	jyOrm := entity.JyEngine.NewSession()
 	var personLimit []*entity.PersonLimit
-	err := jyOrm.Table("entniche_export_limit").Select("*").
-		Where("ent_id = ? and user_id = ?", data.EntId, data.EntUserId).Find(&personLimit)
+	err := jyOrm.SQL(`select a.* from jianyu.entniche_export_limit a inner join jianyu.entniche_user b on (a.user_id=? and a.user_id=b.id and b.export_power=1)`, data.EntUserId).Find(&personLimit)
 	if err != nil || personLimit == nil || len(personLimit) == 0 {
 		return &resourcesCenter.ChargeResp{Code: entity.ErrorCode, Message: "企业个人账号限额查询失败"}
 	}

+ 1 - 6
service/resourceManageService.go

@@ -57,11 +57,7 @@ func (service *ResourceManageService) FindAccountBalance(in *resourcesCenter.Res
 	}
 	for _, v := range accountBalanceArr {
 		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")
+		endTime := now1.AddDate(0, 0, 30).Format("2006-01-02")
 		//统计30内到期数量
 
 		//统计总数量
@@ -108,7 +104,6 @@ func (service *ResourceManageService) FindAccountBalance(in *resourcesCenter.Res
 				}
 			}
 		} else {
-			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, endTime).Get(&c)