SmartMurphytt/chainmaker_go/controller/rightConfirmationNoticeCont...

72 lines
1.8 KiB
Go
Raw Normal View History

2023-11-29 21:48:12 +08:00
package controller
import (
"chainmaker_go/database"
"chainmaker_go/model"
"fmt"
"github.com/gin-gonic/gin"
"strconv"
)
func RightConfirmationNotice(ctx *gin.Context) {
DB := database.GetDB()
cookie, err := ctx.Cookie("username")
if err != nil {
cookie = "NotSet"
}
fmt.Printf("Cookie value: %s \n", cookie)
//获取参数
user_id = cookie
var requestNotice = model.Id{}
ctx.Bind(&requestNotice)
//获取参数
owner_userid := requestNotice.Owner_userid
right_type = requestNotice.Right_type
id := requestNotice.Id
int_id, err := strconv.Atoi(id)
if err != nil {
fmt.Println("error")
}
//查询该用户所有资源
var resources []model.Resource
DB.Where("User_id = ? ", user_id).Find(&resources)
var resource = model.Resource{}
resource = resources[int_id]
var rightConfirmation = model.RightConfirmation{}
DB.Where("Right_type = ? and Resource_name = ? and Resource_describe = ? and Resource_uniqueid = ? "+
"and Owner_userid = ? and Is_right_confirmation = ?", right_type, resource.Resource_name, resource.Resource_describe,
resource.Resource_uniqueid, owner_userid, "否").First(&rightConfirmation)
if rightConfirmation.ID != 0 {
//如果通知过,则
ctx.JSON(200, gin.H{
"code": 203,
"msg": "已确权通知,请等待权属人确权",
})
return
}
//如果没有通知过,则
rightConfirmation.Right_type = right_type
rightConfirmation.Resource_name = resource.Resource_name
rightConfirmation.Resource_describe = resource.Resource_describe
rightConfirmation.Resource_uniqueid = resource.Resource_uniqueid
rightConfirmation.Owner_userid = owner_userid
rightConfirmation.Is_right_confirmation = "否"
DB.Create(&rightConfirmation)
//返回结果
ctx.JSON(200, gin.H{
"code": 200,
"msg": "确权通知成功",
})
}