report.go 2.77 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
package mgr_m

import (
	"fmt"
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
	"gorm.io/gorm"
	"hilo-group/_const/enum/mgr_e"
	"hilo-group/myerr"
)

//投诉
type MgrReport struct {
	mysql.Entity
	*domain.Model `gorm:"-"`
	FromUserId    mysql.ID
	ToUserId      mysql.ID
	FromPageType  mgr_e.ReportPageType
	ReasonType    mgr_e.ReportReasonType
	OriginId      mysql.ID
	ImageUrl      mysql.Str
	Reason        mysql.Str
	Status        mgr_e.ReportStatus
	ReportDealId  mysql.ID
}

//投诉-群组
type MgrReportGroup struct {
	mysql.Entity
	*domain.Model `gorm:"-"`
	FromUserId    mysql.ID
	GroupId       mysql.Str
	ReasonType    mgr_e.ReportReasonType
	ImageUrl      mysql.Str
	Reason        mysql.Str
	Status        mgr_e.ReportStatus
	ReportDealId  mysql.ID
}

func ReportAdd(model *domain.Model, fromUserId mysql.ID, toUserId mysql.ID, fromPageType mgr_e.ReportPageType, originId mysql.ID, reasonType mgr_e.ReportReasonType, imageUrl mysql.Str, reason mysql.Str) *MgrReport {
	return &MgrReport{
		Model:        model,
		FromUserId:   fromUserId,
		ToUserId:     toUserId,
		FromPageType: fromPageType,
		ReasonType:   reasonType,
		OriginId:     originId,
		ImageUrl:     imageUrl,
		Reason:       reason,
		Status:       mgr_e.NoDealReportStatus,
	}
}

func ReportGroupAdd(model *domain.Model, fromUserId mysql.ID, groupId mysql.Str, reasonType mgr_e.ReportReasonType, imageUrl mysql.Str, reason mysql.Str) *MgrReportGroup {
	return &MgrReportGroup{
		Model:      model,
		FromUserId: fromUserId,
		GroupId:    groupId,
		ReasonType: reasonType,
		ImageUrl:   imageUrl,
		Reason:     reason,
		Status:     mgr_e.NoDealReportStatus,
	}
}

//检查投诉
func checkReport(model *domain.Model, reportId mysql.ID) (*MgrReport, error) {
	//var report = new(MgrReport)
	var report MgrReport
	if err := model.Db.First(&report, reportId).Error; err != nil {
		if err == gorm.ErrRecordNotFound {
			return nil, myerr.NewSysError("投诉不存在, Id:" + fmt.Sprintf("%d", reportId))
		} else {
			return nil, myerr.WrapErr(err)
		}
	}
	/*	if report.Status == mgr_m.HasDealReportStatus {
		return nil, myerr.NewSysError("投诉已被处理。, Id:" + mysql.IdToStr(reportId))
	}*/
	return &report, nil
}

//投诉处理
func ReportDeal(model *domain.Model, reportId mysql.ID) (*MgrReport, error) {
	report, err := checkReport(model, reportId)
	if err != nil {
		return nil, err
	}
	report.Status = mgr_e.HasDealReportStatus
	return report, nil
}

func GetMyReport(userId mysql.ID) ([]uint64, error) {
	users := make([]uint64, 0)
	report := make([]MgrReport, 0)
	if err := mysql.Db.Where("from_user_id = ?", userId).Find(&report).Error; err != nil && err != gorm.ErrRecordNotFound {
		return nil, myerr.WrapErr(err)
	}
	for _, i := range report {
		users = append(users, i.ToUserId)
	}
	return users, nil
}