79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
package imports
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
account "fonchain-fiee/api/accountFiee"
|
|
"fonchain-fiee/api/bundle"
|
|
apiCast "fonchain-fiee/api/cast"
|
|
"fonchain-fiee/pkg/service"
|
|
"fonchain-fiee/pkg/service/cast"
|
|
"log"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func WorkConfirm(c *gin.Context) { // 确认作品并扣除余量
|
|
newCtx := cast.NewCtxWithUserInfo(c)
|
|
list, err := service.CastProvider.WorkList(newCtx, &apiCast.WorkListReq{
|
|
WorkStatus: 4,
|
|
Page: 1,
|
|
PageSize: 999,
|
|
})
|
|
if err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
if len(list.Data) == 0 {
|
|
service.Error(c, errors.New("没有待确认的作品"))
|
|
return
|
|
}
|
|
//遍历更新状态
|
|
var failedRecords []FailedRecord
|
|
for _, v := range list.Data {
|
|
res, err := service.AccountFieeProvider.UserList(context.Background(), &account.UserListRequest{
|
|
Name: v.ArtistName,
|
|
})
|
|
if err != nil {
|
|
failedRecords = append(failedRecords, FailedRecord{
|
|
Name: v.ArtistName,
|
|
Msg: fmt.Sprintf("获取用户信息失败: %s", err.Error()),
|
|
})
|
|
log.Printf(fmt.Sprintf("获取用户信息失败: %s", err.Error()))
|
|
continue
|
|
}
|
|
var artistId uint64
|
|
if res != nil && len(res.UserList) > 0 {
|
|
artistId = res.UserList[0].Id
|
|
}
|
|
_, err = service.BundleProvider.AddBundleBalance(c, &bundle.AddBundleBalanceReq{
|
|
UserId: int32(artistId),
|
|
VideoConsumptionNumber: 1,
|
|
})
|
|
if err != nil {
|
|
failedRecords = append(failedRecords, FailedRecord{
|
|
Name: v.ArtistName,
|
|
Msg: fmt.Sprintf("扣除余额失败: %s", err.Error()),
|
|
})
|
|
log.Printf(fmt.Sprintf("扣除余额失败: %s", err.Error()))
|
|
continue
|
|
}
|
|
_, err = service.CastProvider.UpdateStatus(c, &apiCast.UpdateStatusReq{
|
|
WorkAction: apiCast.WorkActionENUM_CONFIRM,
|
|
WorkUuid: v.WorkUuid,
|
|
ConfirmRemark: "",
|
|
ConfirmStatus: 1,
|
|
})
|
|
if err != nil {
|
|
failedRecords = append(failedRecords, FailedRecord{
|
|
Name: v.ArtistName,
|
|
Msg: fmt.Sprintf("更新状态失败: %s", err.Error()),
|
|
})
|
|
log.Printf(fmt.Sprintf("更新状态失败: %s", err.Error()))
|
|
continue
|
|
}
|
|
}
|
|
service.Success(c, failedRecords)
|
|
}
|