Explorar el Código

添加一些小功能

yuliang1112 hace 2 años
padre
commit
e148ffd30b

+ 28 - 0
db/project.go

@@ -313,3 +313,31 @@ func CreateProject(ctx context.Context, projectInfo gorm_model.ProjectInfo) (*in
 	}
 	return &projectInfo.ProjectID, nil
 }
+
+func ProjectHandle(ctx context.Context, data http_model.ProjectHandleRequest) error {
+	err := ChangeProjectStatus(ctx, data.ProjectID, data.ProjectStatus)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[project] call ChangeProjectStatus error,err:%+v", err)
+		return err
+	}
+	return nil
+}
+
+func ChangeProjectStatus(ctx context.Context, projectID int64, projectStatus string) error {
+	db := GetReadDB(ctx)
+	projectInfo := gorm_model.ProjectInfo{}
+	var project_status int64
+	if projectStatus == "待支付" {
+		project_status = 7
+	} else if projectStatus == "创建中" {
+		project_status = 2
+	}
+	if err := db.Debug().Model(&projectInfo).
+		Where("project_id = ?", projectID).
+		Updates(gorm_model.ProjectInfo{ProjectStatus: project_status}).
+		Error; err != nil {
+		logrus.WithContext(ctx).Errorf("[ChangeProjectStatus] error query mysql total, err:%+v", err)
+		return err
+	}
+	return nil
+}

+ 90 - 0
db/user.go

@@ -8,6 +8,7 @@ import (
 	"gorm.io/gorm"
 	"reflect"
 	"time"
+	"youngee_m_api/consts"
 	"youngee_m_api/model/common_model"
 	"youngee_m_api/model/gorm_model"
 	"youngee_m_api/model/http_model"
@@ -265,6 +266,95 @@ func GetCreatorList(ctx context.Context, pageSize, pageNum int32, conditions *co
 	}
 
 	var CreatorList []*http_model.CreatorListPreview
+
 	CreatorList = pack.TalentListToCreatorListData(talentList)
 	return CreatorList, total, nil
 }
+
+func AccountInfo(ctx context.Context, pageSize, pageNum int32, conditions *common_model.AccountInfoConditions) ([]*http_model.AccountInfoData, int64, error) {
+	db := GetReadDB(ctx)
+	db = db.Debug().Model(gorm_model.YoungeePlatformAccountInfo{})
+	// 根据 条件过滤
+	conditionType := reflect.TypeOf(conditions).Elem()
+	conditionValue := reflect.ValueOf(conditions).Elem()
+	for i := 0; i < conditionType.NumField(); i++ {
+		field := conditionType.Field(i)
+		tag := field.Tag.Get("condition")
+		value := conditionValue.FieldByName(field.Name)
+		if !util.IsBlank(value) && tag != "bind_date" && tag != "fans_low" && tag != "fans_high" {
+			db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
+		} else if tag == "bind_date" && value.Interface() != nil {
+			db = db.Where(fmt.Sprintf("bind_date like '%s%%'", value.Interface()))
+		}
+		if !util.IsBlank(value) && tag == "fans_low" {
+			db = db.Where(fmt.Sprintf("%s >= ?", "fans_count"), value.Interface())
+		}
+		if !util.IsBlank(value) && tag == "fans_high" {
+			db = db.Where(fmt.Sprintf("%s <= ?", "fans_count"), value.Interface())
+		}
+	}
+	db = db.Debug().Where("deleted = ?", 0)
+	var total int64
+	if err := db.Count(&total).Error; err != nil {
+		logrus.WithContext(ctx).Errorf("[GetAccountInfo] error query mysql total, err:%+v", err)
+		return nil, 0, err
+	}
+	var PlatformAccountInfos []*gorm_model.YoungeePlatformAccountInfo
+	// 查询该页数据
+	limit := pageSize
+	offset := pageSize * pageNum // assert pageNum start with 0
+	err := db.Order("bind_date desc").Limit(int(limit)).Offset(int(offset)).Find(&PlatformAccountInfos).Error
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[GetAccountInfo] error query mysql total, err:%+v", err)
+		return nil, 0, err
+	}
+	phoneMap := map[string]string{}
+	for _, PlatformAccountInfo := range PlatformAccountInfos {
+		if _, ok := phoneMap[PlatformAccountInfo.TalentID]; !ok {
+			phoneMap[PlatformAccountInfo.TalentID] = getPhoneByTalentID(ctx, PlatformAccountInfo.TalentID)
+		}
+	}
+	var accountInfoDatas []*http_model.AccountInfoData
+	for _, PlatformAccountInfo := range PlatformAccountInfos {
+		accountInfo := new(http_model.AccountInfoData)
+		accountInfo.BindDate = conv.MustString(PlatformAccountInfo.BindDate, "")[0:19]
+		accountInfo.Platform = consts.GetProjectPlatform(PlatformAccountInfo.PlatformID)
+		accountInfo.PlatformNickname = PlatformAccountInfo.PlatformNickname
+		accountInfo.TalentId = PlatformAccountInfo.TalentID
+		accountInfo.Phone = phoneMap[PlatformAccountInfo.TalentID]
+		accountInfo.Fans = PlatformAccountInfo.FansCount
+		accountInfo.HomePageUrl = PlatformAccountInfo.HomePageUrl
+		accountInfo.HomePageCaptureUrl = PlatformAccountInfo.HomePageCaptureUrl
+		accountInfoDatas = append(accountInfoDatas, accountInfo)
+	}
+	return accountInfoDatas, total, nil
+}
+
+func getPhoneByTalentID(ctx context.Context, talentID string) string {
+	db := GetReadDB(ctx)
+	talentInfo := gorm_model.YoungeeTalentInfo{}
+	err := db.Debug().Where("id = ?", talentID).First(&talentInfo).Error
+	if err != nil {
+		if err == gorm.ErrRecordNotFound {
+			return ""
+		} else {
+			return ""
+		}
+	}
+	return talentInfo.TalentPhoneNumber
+}
+
+func DeleteAccount(ctx context.Context, PlatformID, PlatformNickname, TalentId string) error {
+	db := GetReadDB(ctx)
+	accountInfo := gorm_model.YoungeePlatformAccountInfo{}
+	db = db.Debug().Where("talent_id = ? "+
+		"AND platform_nickname = ? "+
+		"AND platform_id = ?",
+		TalentId, PlatformNickname, PlatformID).First(&accountInfo)
+	err := db.Update("deleted", 1).Error
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[user db] call DeleteAccount error,err:%+v", err)
+		return err
+	}
+	return nil
+}

+ 1 - 1
dockerfile

@@ -10,7 +10,7 @@ RUN go env -w GO111MODULE=on
 
 RUN go env -w GOPROXY=https://goproxy.cn,direct
 
-RUN go mod tidy
+RUN go mod tidy -compat=1.17
 
 RUN go build .
 

+ 62 - 0
handler/account_info.go

@@ -0,0 +1,62 @@
+package handler
+
+import (
+	"errors"
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_m_api/consts"
+	"youngee_m_api/model/http_model"
+	"youngee_m_api/pack"
+	"youngee_m_api/service"
+	"youngee_m_api/util"
+)
+
+func WrapAccountInfoHandler(ctx *gin.Context) {
+	handler := newAccountInfoHandler(ctx)
+	baseRun(handler)
+}
+
+type accountHandler struct {
+	ctx  *gin.Context
+	req  *http_model.AccountInfoRequest
+	resp *http_model.CommonResponse
+}
+
+func newAccountInfoHandler(ctx *gin.Context) *accountHandler {
+	return &accountHandler{
+		ctx:  ctx,
+		req:  http_model.NewAccountInfoRequset(),
+		resp: http_model.NewAccountInfoResponse(),
+	}
+}
+func (a accountHandler) getContext() *gin.Context {
+	return a.ctx
+}
+
+func (a accountHandler) getResponse() interface{} {
+	return a.resp
+}
+
+func (a accountHandler) getRequest() interface{} {
+	return a.req
+}
+
+func (a accountHandler) run() {
+	conditions := pack.HttpAccountInfoRequestToCondition(a.req)
+	data, err := service.User.AccountInfo(a.ctx, a.req.PageSize, a.req.PageNum, conditions)
+	if err != nil {
+		logrus.WithContext(a.ctx).Errorf("[WrapAccountInfoHandler] error AccountInfo, err:%+v", err)
+		util.HandlerPackErrorResp(a.resp, consts.ErrorInternal, consts.DefaultToast)
+		return
+	}
+	a.resp.Data = data
+}
+
+func (a accountHandler) checkParam() error {
+	var errs []error
+	if a.req.PageNum < 0 || a.req.PageSize <= 0 {
+		errs = append(errs, errors.New("page param error"))
+	}
+	a.req.PageNum--
+	return nil
+}

+ 56 - 0
handler/delete_account.go

@@ -0,0 +1,56 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_m_api/consts"
+	"youngee_m_api/db"
+	"youngee_m_api/model/http_model"
+	"youngee_m_api/util"
+)
+
+func WrapDeleteAccountHandler(ctx *gin.Context) {
+	handler := newDeleteAccountHandler(ctx)
+	baseRun(handler)
+}
+
+type DeleteAccount struct {
+	ctx  *gin.Context
+	req  *http_model.DeleteAccountRequest
+	resp *http_model.CommonResponse
+}
+
+func (d DeleteAccount) getContext() *gin.Context {
+	return d.ctx
+}
+
+func (d DeleteAccount) getResponse() interface{} {
+	return d.resp
+}
+
+func (d DeleteAccount) getRequest() interface{} {
+	return d.req
+}
+
+func (d DeleteAccount) run() {
+	err := db.DeleteAccount(d.ctx, d.req.PlatformID, d.req.PlatformNickname, d.req.TalentId)
+	if err != nil {
+		logrus.Errorf("[DeleteAccountHandler] call Delete err:%+v\n", err)
+		util.HandlerPackErrorResp(d.resp, consts.ErrorInternal, "")
+		logrus.Info("DeleteAccount fail,req:%+v", d.req)
+		return
+	}
+	d.resp.Message = "解绑成功"
+}
+
+func (d DeleteAccount) checkParam() error {
+	return nil
+}
+
+func newDeleteAccountHandler(ctx *gin.Context) *DeleteAccount {
+	return &DeleteAccount{
+		ctx:  ctx,
+		req:  http_model.NewDeleteAccountRequest(),
+		resp: http_model.NewDeleteAccountResponse(),
+	}
+}

+ 58 - 0
handler/project_handle.go

@@ -0,0 +1,58 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_m_api/consts"
+	"youngee_m_api/db"
+	"youngee_m_api/model/http_model"
+	"youngee_m_api/util"
+)
+
+func WrapProjectHandleHandler(ctx *gin.Context) {
+	handler := NewProjectHandleHandler(ctx)
+	baseRun(handler)
+}
+
+func NewProjectHandleHandler(ctx *gin.Context) *ProjectHandleHandler {
+	return &ProjectHandleHandler{
+		ctx:  ctx,
+		req:  http_model.NewProjectHandleRequest(),
+		resp: http_model.NewProjectHandleResponse(),
+	}
+}
+
+type ProjectHandleHandler struct {
+	ctx  *gin.Context
+	req  *http_model.ProjectHandleRequest
+	resp *http_model.CommonResponse
+}
+
+func (p ProjectHandleHandler) getContext() *gin.Context {
+	return p.ctx
+}
+
+func (p ProjectHandleHandler) getResponse() interface{} {
+	return p.resp
+}
+
+func (p ProjectHandleHandler) getRequest() interface{} {
+	return p.req
+}
+
+func (p ProjectHandleHandler) run() {
+	data := http_model.ProjectHandleRequest{}
+	data = *p.req
+	err := db.ProjectHandle(p.ctx, data)
+	if err != nil {
+		logrus.Errorf("[ProjectHandleHandler] call Create err:%+v\n", err)
+		util.HandlerPackErrorResp(p.resp, consts.ErrorInternal, "")
+		logrus.Info("ProjectHandle fail,req:%+v", p.req)
+		return
+	}
+	p.resp.Message = "处理成功"
+}
+
+func (p ProjectHandleHandler) checkParam() error {
+	return nil
+}

+ 10 - 0
model/common_model/account_info.go

@@ -0,0 +1,10 @@
+package common_model
+
+type AccountInfoConditions struct {
+	PlatformID       int64  `condition:"platform_id"`       // 平台
+	BindDate         string `condition:"bind_date"`         // 绑定时间
+	FansLow          int64  `condition:"fans_low"`          // 最低粉丝数
+	FansHigh         int64  `condition:"fans_high"`         // 最高粉丝数
+	TalentId         string `condition:"talent_id"`         // 创作者ID
+	PlatformNickname string `condition:"platform_nickname"` // 平台昵称
+}

+ 38 - 0
model/http_model/account_info.go

@@ -0,0 +1,38 @@
+package http_model
+
+type AccountInfoRequest struct {
+	PageSize         int32  `json:"page_size"`
+	PageNum          int32  `json:"page_num"`
+	PlatformID       string `json:"platform_id"`
+	BindDate         string `json:"bind_date"`
+	FansLow          string `json:"fans_low"`
+	FansHigh         string `json:"fans_high"`
+	TalentId         string `json:"talent_id"`
+	PlatformNickname string `json:"platform_nickname"`
+}
+
+type AccountInfoData struct {
+	TalentId           string `json:"talent_id"`             //创作者ID
+	PlatformNickname   string `json:"platform_nickname"`     //账号昵称
+	Platform           string `json:"platform"`              //社媒平台
+	Fans               int64  `json:"fans"`                  //粉丝量
+	Phone              string `json:"phone"`                 //联系方式
+	BindDate           string `json:"bind_date"`             // 绑定时间
+	HomePageCaptureUrl string `json:"home_page_capture_url"` //主页截图链接
+	HomePageUrl        string `json:"home_page_url"`         //主页链接
+}
+
+type AccountInfoPreView struct {
+	AccountInfoData []*AccountInfoData `json:"account_info_data"`
+	Total           string             `json:"total"`
+}
+
+func NewAccountInfoRequset() *AccountInfoRequest {
+	return new(AccountInfoRequest)
+}
+
+func NewAccountInfoResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(AccountInfoPreView)
+	return resp
+}

+ 16 - 0
model/http_model/delete_account.go

@@ -0,0 +1,16 @@
+package http_model
+
+type DeleteAccountRequest struct {
+	TalentId         string `json:"talent_id"`
+	PlatformID       string `json:"platform_id"`
+	PlatformNickname string `json:"platform_nickname"`
+}
+
+func NewDeleteAccountRequest() *DeleteAccountRequest {
+	return new(DeleteAccountRequest)
+}
+
+func NewDeleteAccountResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	return resp
+}

+ 15 - 0
model/http_model/project_handle.go

@@ -0,0 +1,15 @@
+package http_model
+
+type ProjectHandleRequest struct {
+	ProjectID     int64  `json:"Project_id"`     // 项目id
+	ProjectStatus string `json:"project_status"` // 项目状态
+}
+
+func NewProjectHandleRequest() *ProjectHandleRequest {
+	return new(ProjectHandleRequest)
+}
+
+func NewProjectHandleResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	return resp
+}

+ 2 - 2
model/http_model/project_show.go

@@ -38,8 +38,8 @@ type ShowProjectData struct {
 }
 
 type ShowProjectRequest struct {
-	EnterpriseID     string                `json:"enterprise_id"`     // 企业id
-	ProjectID int64 `json:"Project_id"` // 项目id
+	EnterpriseID string `json:"enterprise_id"` // 企业id
+	ProjectID    int64  `json:"Project_id"`    // 项目id
 }
 
 func NewShowProjectRequest() *ShowProjectRequest {

+ 12 - 0
pack/creator_list_conditions.go

@@ -1,6 +1,7 @@
 package pack
 
 import (
+	"github.com/caixw/lib.go/conv"
 	"youngee_m_api/model/common_model"
 	"youngee_m_api/model/http_model"
 )
@@ -12,3 +13,14 @@ func HttpCreatorListRequestToCondition(req *http_model.CreatorListRequest) *comm
 		CreateDate:       req.CreateDate,
 	}
 }
+
+func HttpAccountInfoRequestToCondition(req *http_model.AccountInfoRequest) *common_model.AccountInfoConditions {
+	return &common_model.AccountInfoConditions{
+		PlatformID:       conv.MustInt64(req.PlatformID, 0),
+		BindDate:         req.BindDate,
+		FansLow:          conv.MustInt64(req.FansLow, 0),
+		FansHigh:         conv.MustInt64(req.FansHigh, 0),
+		TalentId:         req.TalentId,
+		PlatformNickname: req.PlatformNickname,
+	}
+}

+ 3 - 0
route/init.go

@@ -30,6 +30,7 @@ func InitRoute(r *gin.Engine) {
 		})
 		m.POST("/product/list", handler.WrapFullProjectListHandler)
 		m.POST("/project/show", handler.WrapShowProjectHandler)
+		m.POST("/project/handle", handler.WrapProjectHandleHandler)
 		m.POST("/product/findall", handler.WrapFindAllProductHandler)
 		m.POST("/project/create", handler.WrapCreateProjectHandler)
 		m.POST("/product/create", handler.WrapCreateProductHandler)
@@ -50,5 +51,7 @@ func InitRoute(r *gin.Engine) {
 		u.POST("/creatorList", handler.WrapCreatorListHandler)
 		u.POST("/platformAccInfo", handler.WrapPlatformAccInfoHandler)
 		u.POST("/talentInfo", handler.WrapTalentInfoHandler)
+		u.POST("/accountInfo", handler.WrapAccountInfoHandler)
+		u.POST("/deleteAccount", handler.WrapDeleteAccountHandler)
 	}
 }

+ 12 - 0
service/user.go

@@ -37,3 +37,15 @@ func (*user) CreatorList(ctx context.Context, pageSize, pageNum int32, condition
 	CreatorListData.Total = conv.MustString(total, "")
 	return CreatorListData, nil
 }
+
+func (u *user) AccountInfo(ctx context.Context, pageSize int32, pageNum int32, conditions *common_model.AccountInfoConditions) (*http_model.AccountInfoPreView, error) {
+	accountInfo, total, err := db.AccountInfo(ctx, pageSize, pageNum, conditions)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[user service] call AccountInfo error,err:%+v", err)
+		return nil, err
+	}
+	accountInfoPreView := new(http_model.AccountInfoPreView)
+	accountInfoPreView.AccountInfoData = accountInfo
+	accountInfoPreView.Total = conv.MustString(total, "")
+	return accountInfoPreView, nil
+}