Compare commits
	
		
			2 Commits
		
	
	
		
			b4c90f4d18
			...
			953eb4b419
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 953eb4b419 | |||
| 62c48b2ea9 | 
							
								
								
									
										10
									
								
								pkg/model/cast/media.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								pkg/model/cast/media.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | |||||||
|  | package cast | ||||||
|  | 
 | ||||||
|  | type BalanceTypeEnum int32 | ||||||
|  | 
 | ||||||
|  | // 定义枚举值
 | ||||||
|  | const ( | ||||||
|  | 	BalanceTypeAccountValue BalanceTypeEnum = 1 | ||||||
|  | 	BalanceTypeImageValue   BalanceTypeEnum = 2 | ||||||
|  | 	BalanceTypeVideoValue   BalanceTypeEnum = 3 | ||||||
|  | ) | ||||||
| @ -8,6 +8,7 @@ import ( | |||||||
| 	"fonchain-fiee/api/cast" | 	"fonchain-fiee/api/cast" | ||||||
| 	"fonchain-fiee/cmd/config" | 	"fonchain-fiee/cmd/config" | ||||||
| 	"fonchain-fiee/pkg/e" | 	"fonchain-fiee/pkg/e" | ||||||
|  | 	modelCast "fonchain-fiee/pkg/model/cast" | ||||||
| 	"fonchain-fiee/pkg/service" | 	"fonchain-fiee/pkg/service" | ||||||
| 	"github.com/gin-gonic/gin" | 	"github.com/gin-gonic/gin" | ||||||
| 	"strconv" | 	"strconv" | ||||||
| @ -122,23 +123,36 @@ func UpdateMediaAccount(ctx *gin.Context) { | |||||||
| 		service.Error(ctx, errors.New(e.GetMsg(e.InvalidParams))) | 		service.Error(ctx, errors.New(e.GetMsg(e.InvalidParams))) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	resp, err := service.CastProvider.UpdateMediaAccount(ctx, req) | 	userID, _ := strconv.ParseInt(req.ArtistUuid, 10, 64) | ||||||
| 	if err != nil { | 	if req.MediaAccountUuid == "" { | ||||||
|  | 		if err = CheckUserBundleBalance(int32(userID), modelCast.BalanceTypeAccountValue); err != nil { | ||||||
| 			service.Error(ctx, err) | 			service.Error(ctx, err) | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| 	if req.MediaAccountUuid == "" { |  | ||||||
| 		userID, _ := strconv.ParseInt(req.ArtistUuid, 10, 64) |  | ||||||
| 		_, err = service.BundleProvider.AddBundleBalance(context.Background(), &bundle.AddBundleBalanceReq{ | 		_, err = service.BundleProvider.AddBundleBalance(context.Background(), &bundle.AddBundleBalanceReq{ | ||||||
| 			UserId:                   int32(userID), | 			UserId:                   int32(userID), | ||||||
| 			AccountConsumptionNumber: 1, | 			AccountConsumptionNumber: 1, | ||||||
| 		}) | 		}) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			service.Error(ctx, err) | 			service.Error(ctx, err) | ||||||
| 			//FIXME 进行回滚
 |  | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	resp, err := service.CastProvider.UpdateMediaAccount(ctx, req) | ||||||
|  | 	if err != nil { | ||||||
|  | 		service.Error(ctx, err) | ||||||
|  | 		if req.MediaAccountUuid == "" { | ||||||
|  | 			_, err = service.BundleProvider.AddBundleBalance(context.Background(), &bundle.AddBundleBalanceReq{ | ||||||
|  | 				UserId:                   int32(userID), | ||||||
|  | 				AccountConsumptionNumber: -1, | ||||||
|  | 			}) | ||||||
|  | 			if err != nil { | ||||||
|  | 				service.Error(ctx, err) | ||||||
|  | 				return | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
| 	service.Success(ctx, resp) | 	service.Success(ctx, resp) | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
|  | |||||||
| @ -9,6 +9,7 @@ import ( | |||||||
| 	"fonchain-fiee/api/cast" | 	"fonchain-fiee/api/cast" | ||||||
| 	"fonchain-fiee/cmd/config" | 	"fonchain-fiee/cmd/config" | ||||||
| 	"fonchain-fiee/pkg/e" | 	"fonchain-fiee/pkg/e" | ||||||
|  | 	modelCast "fonchain-fiee/pkg/model/cast" | ||||||
| 	"fonchain-fiee/pkg/service" | 	"fonchain-fiee/pkg/service" | ||||||
| 	"github.com/gin-gonic/gin" | 	"github.com/gin-gonic/gin" | ||||||
| 	"go.uber.org/zap" | 	"go.uber.org/zap" | ||||||
| @ -42,7 +43,7 @@ func UpdateWorkImage(ctx *gin.Context) { | |||||||
| 	req.ArtistName = infoResp.Name | 	req.ArtistName = infoResp.Name | ||||||
| 	req.ArtistPhone = infoResp.TelNum | 	req.ArtistPhone = infoResp.TelNum | ||||||
| 	artistID, _ := strconv.ParseUint(req.ArtistUuid, 10, 64) | 	artistID, _ := strconv.ParseUint(req.ArtistUuid, 10, 64) | ||||||
| 	if err = CheckUserBundleBalance(int32(artistID)); err != nil { | 	if err = CheckUserBundleBalance(int32(artistID), modelCast.BalanceTypeImageValue); err != nil { | ||||||
| 		service.Error(ctx, err) | 		service.Error(ctx, err) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| @ -81,7 +82,7 @@ func UpdateWorkVideo(ctx *gin.Context) { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	artistID, _ := strconv.ParseUint(req.ArtistUuid, 10, 64) | 	artistID, _ := strconv.ParseUint(req.ArtistUuid, 10, 64) | ||||||
| 	if err = CheckUserBundleBalance(int32(artistID)); err != nil { | 	if err = CheckUserBundleBalance(int32(artistID), modelCast.BalanceTypeVideoValue); err != nil { | ||||||
| 		service.Error(ctx, err) | 		service.Error(ctx, err) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| @ -131,38 +132,18 @@ func WorkList(ctx *gin.Context) { | |||||||
| 		service.Error(ctx, err) | 		service.Error(ctx, err) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	var castS = new(CastService) |  | ||||||
| 	if len(resp.Data) > 0 { | 	if len(resp.Data) > 0 { | ||||||
| 		var approvalIDs []int |  | ||||||
| 		var data map[int]int |  | ||||||
| 		var workUuidApprovalIDMap = make(map[int]string) | 		var workUuidApprovalIDMap = make(map[int]string) | ||||||
| 		for _, v := range resp.Data { | 		for _, v := range resp.Data { | ||||||
| 			if v.WorkStatus == 2 && v.ApprovalID != "" { | 			if v.WorkStatus == 2 && v.ApprovalID != "" { | ||||||
| 				approvalID, _ := strconv.ParseUint(v.ApprovalID, 10, 64) | 				approvalID, _ := strconv.ParseUint(v.ApprovalID, 10, 64) | ||||||
| 				approvalIDs = append(approvalIDs, int(approvalID)) |  | ||||||
| 				workUuidApprovalIDMap[int(approvalID)] = v.WorkUuid | 				workUuidApprovalIDMap[int(approvalID)] = v.WorkUuid | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		if len(approvalIDs) > 0 { | 		if len(workUuidApprovalIDMap) > 0 { | ||||||
| 			data, err = castS.ApprovalDetail(approvalIDs) | 			_ = RefreshWorkApprovalStatus(workUuidApprovalIDMap) | ||||||
| 			if len(data) > 0 { |  | ||||||
| 				for approvalId, approvalStatus := range data { |  | ||||||
| 					var workAction cast.WorkActionENUM |  | ||||||
| 					if approvalStatus == 2 { |  | ||||||
| 						workAction = cast.WorkActionENUM_APPROVAL_PASS |  | ||||||
| 					} else { |  | ||||||
| 						workAction = cast.WorkActionENUM_APPROVAL_REJECT |  | ||||||
| 					} |  | ||||||
| 					_, _ = service.CastProvider.UpdateStatus(context.Background(), &cast.UpdateStatusReq{ |  | ||||||
| 						WorkAction: workAction, |  | ||||||
| 						WorkUuid:   workUuidApprovalIDMap[approvalId], |  | ||||||
| 						ApprovalID: fmt.Sprint(approvalId), |  | ||||||
| 					}) |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	service.Success(ctx, resp) | 	service.Success(ctx, resp) | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| @ -187,17 +168,30 @@ func WorkDetail(ctx *gin.Context) { | |||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func CheckUserBundleBalance(userID int32) (err error) { | func CheckUserBundleBalance(userID int32, balanceType modelCast.BalanceTypeEnum) (err error) { | ||||||
| 	resp, err := service.BundleProvider.GetBundleBalanceByUserId(context.Background(), &bundle.GetBundleBalanceByUserIdReq{UserId: userID}) | 	resp, err := service.BundleProvider.GetBundleBalanceByUserId(context.Background(), &bundle.GetBundleBalanceByUserIdReq{UserId: userID}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	zap.L().Info("CheckUserBundleBalance", zap.Any("resp", resp)) | 	zap.L().Info("CheckUserBundleBalance", zap.Any("resp", resp)) | ||||||
| 	fmt.Println("CheckUserBundleBalance resp", resp) | 	fmt.Println("CheckUserBundleBalance resp", resp) | ||||||
|  | 	switch balanceType { | ||||||
|  | 	case modelCast.BalanceTypeAccountValue: | ||||||
| 		if resp.AccountNumber-resp.AccountConsumptionNumber <= 0 { | 		if resp.AccountNumber-resp.AccountConsumptionNumber <= 0 { | ||||||
| 			err = errors.New(e.ErrorBalanceInsufficient) | 			err = errors.New(e.ErrorBalanceInsufficient) | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
|  | 	case modelCast.BalanceTypeImageValue: | ||||||
|  | 		if resp.ImageNumber-resp.ImageConsumptionNumber <= 0 { | ||||||
|  | 			err = errors.New(e.ErrorBalanceInsufficient) | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 	case modelCast.BalanceTypeVideoValue: | ||||||
|  | 		if resp.VideoNumber-resp.VideoConsumptionNumber <= 0 { | ||||||
|  | 			err = errors.New(e.ErrorBalanceInsufficient) | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -241,3 +235,35 @@ func RePublish(ctx *gin.Context) { | |||||||
| func UserBundleBalanceCost() { | func UserBundleBalanceCost() { | ||||||
| 	service.BundleProvider.AddBundleBalance(context.Background(), &bundle.AddBundleBalanceReq{}) | 	service.BundleProvider.AddBundleBalance(context.Background(), &bundle.AddBundleBalanceReq{}) | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func RefreshWorkApprovalStatus(approvalIDWorkUuidMap map[int]string) (err error) { | ||||||
|  | 	var castS = new(CastService) | ||||||
|  | 	var data = make(map[int]int) | ||||||
|  | 	var approvalIDs []int | ||||||
|  | 	for approvalId, _ := range approvalIDWorkUuidMap { | ||||||
|  | 		approvalIDs = append(approvalIDs, approvalId) | ||||||
|  | 	} | ||||||
|  | 	if len(approvalIDs) == 0 { | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 	data, err = castS.ApprovalDetail(approvalIDs) | ||||||
|  | 	// status: 1待审批 2审批通过 3审批不通过 6撤销发其中 7撤销完成
 | ||||||
|  | 	if len(data) > 0 { | ||||||
|  | 		for approvalId, approvalStatus := range data { | ||||||
|  | 			var workAction cast.WorkActionENUM | ||||||
|  | 			if approvalStatus == 2 { | ||||||
|  | 				workAction = cast.WorkActionENUM_APPROVAL_PASS | ||||||
|  | 			} else if approvalStatus == 3 { | ||||||
|  | 				workAction = cast.WorkActionENUM_APPROVAL_REJECT | ||||||
|  | 			} else { | ||||||
|  | 				continue | ||||||
|  | 			} | ||||||
|  | 			_, _ = service.CastProvider.UpdateStatus(context.Background(), &cast.UpdateStatusReq{ | ||||||
|  | 				WorkAction: workAction, | ||||||
|  | 				WorkUuid:   approvalIDWorkUuidMap[approvalId], | ||||||
|  | 				ApprovalID: fmt.Sprint(approvalId), | ||||||
|  | 			}) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user