fonchain-fiee/pkg/service/invitationLetter.go

193 lines
6.7 KiB
Go
Raw Normal View History

2025-02-19 06:24:15 +00:00
// Package service -----------------------------
// @file : invitationLetter.go
// @author : JJXu
// @contact : wavingbear@163.com
// @time : 2024/3/27 11:30
// -------------------------------------------
package service
import (
"context"
"dubbo.apache.org/dubbo-go/v3/common/logger"
"fmt"
artShow "github.com/fonchain_enterprise/fonchain-main/api/artShow"
"github.com/fonchain_enterprise/fonchain-main/api/artist"
"github.com/fonchain_enterprise/fonchain-main/api/artistInfoUser"
"github.com/fonchain_enterprise/fonchain-main/pkg/e"
"github.com/fonchain_enterprise/fonchain-main/pkg/utils/stime"
"github.com/gin-gonic/gin"
"time"
)
func InvitationUpdate2(c *gin.Context) {
var req artist.UpdateInvitationLetterReq
if err := c.ShouldBind(&req); err != nil {
logger.Errorf("InvitationUpdate ShouldBind err", err)
ResponseQuickMsg(c, e.Failed, err.Error(), nil)
return
}
if req.LetterUid == "" {
ResponseQuickMsg(c, e.Failed, "letterUid不能为空", nil)
return
}
//如果取消邀请webPath为"/pages/invite/notcome"
if req.IsCome == 2 && req.WebPath == "" {
req.WebPath = "/pages/invite/notcome"
}
_, err := GrpcArtistImpl.UpdateInvitationLetter(context.Background(), &req)
if err != nil {
ResponseQuickMsg(c, e.Failed, err.Error(), nil)
return
}
ResponseQuickMsg(c, e.Ok, "ok", nil)
return
}
func InvitationReAdd(c *gin.Context) {
var req artist.InvitationAddRequest
if err := c.ShouldBind(&req); err != nil {
logger.Errorf("InvitationAdd ShouldBind err", err)
ResponseQuickMsg(c, e.Failed, err.Error(), nil)
return
}
// 徐嘉鸿撤销修改 update by xjj 2024-05-28
////修改逻辑 其它画展包的邀请状态= [待回复 或 已同意](使用邀请函状态判断) 且 其它画展包的画展时间为未来时间,则邀请函状态变为不可邀约 updated by xjj 2024-05-27
////徐嘉鸿新增逻辑,如果存在待回复的邀请函则不发送邀请 updated by xjj 2024-05-22
//artistLetters, errs := GrpcArtistImpl.GetInvitationLetterList(context.Background(), &artist.GetInvitationLetterListRequest{Page: 1, PageSize: -1, Query: &artist.InvitationLetterData{ArtistUuid: req.ArtistUuids[0]}})
//if errs != nil {
// ErrorWithMark(c, e.Failed, errs, "GetInvitationLetterList Err")
// return
//}
//if artistLetters.Total > 0 {
// currentTime := stime.Currentime(stime.Format_Normal_YMDhm)
// for _, artistLetter := range artistLetters.List {
// if artistLetter.ShowUid != req.ShowUid {
// if artistLetter.IsCome == 0 { //待回复
// ShowDetailRes, err := GrpcArtShowImpl.ShowDetail(context.Background(), &artShow.ShowDetailReq{ShowUID: []string{artistLetter.ShowUid}})
// if err != nil {
// fmt.Println("Err 查询画展包失败 err", err)
// continue
// }
// var otherShow *artShow.ShowDetail
// if len(ShowDetailRes.Data) > 0 {
// otherShow = ShowDetailRes.Data[0]
// }
// if otherShow != nil {
// var otherPackageTime string
// if otherShow.ShowTime != "" {
// otherPackageTime = otherShow.ShowTime
// } else if otherShow.PreTime != "" {
// otherPackageTime = otherShow.PreTime
// }
// if otherPackageTime > currentTime { //其它画展的画展时间为未来时间
// fmt.Println("对比showUid:" + otherShow.ShowUID + " 画展时间:" + otherShow.ShowName + " otherPackageTime:" + otherPackageTime)
// ErrorWithMark(c, e.Failed, nil, fmt.Sprintf("比较showuid:%s isCome:%d", artistLetter.ShowUid, artistLetter.IsCome), "该画家存在其它待回复邀请函,当前操作无法执行!")
// return
// } else {
// fmt.Println("showUid:" + req.ShowUid + " 画展时间超过当前时间,可以邀约")
// }
// }
// }
// }
// }
//}
//徐嘉鸿新增逻辑,查询画展包的画展时间如果小于今天则不发送邀请 updated by xjj 2024-05-22
showListRes, err := GrpcArtShowImpl.ShowDetail(c, &artShow.ShowDetailReq{
ShowUID: []string{req.ShowUid},
})
if err != nil {
ErrorWithMark(c, e.Failed, err, "", "查询画展包信息失败!")
return
}
if len(showListRes.Data) > 0 {
var packageShowTime string
if showListRes.Data[0].ShowTime != "" {
packageShowTime = showListRes.Data[0].ShowTime
} else if showListRes.Data[0].PreTime != "" {
packageShowTime = showListRes.Data[0].PreTime
}
var now = time.Now().Format(stime.Format_Normal_YMD)
if packageShowTime < now {
ResponseQuickMsg(c, e.Failed, "画展时间已过,无法发送邀请函!", nil)
return
}
} else {
ResponseQuickMsg(c, e.Failed, "画展包信息不存在!,无法发送邀请函", nil)
return
}
//默认未预发起邀请函
if req.IsPreload == 0 {
req.IsPreload = 1
}
//查询邀请函
invitationListResp, err := GrpcArtistImpl.InvitationList(c, &artist.InvitationListRequest{ArtistUuid: req.ArtistUuids[0]})
if err != nil {
ResponseQuickMsg(c, e.Failed, err.Error(), nil)
return
}
var thisInvitation *artist.InvitationUpdateRequest
if invitationListResp.Data != nil && len(invitationListResp.Data) > 0 {
for _, v := range invitationListResp.Data {
if v.ShowUid == req.ShowUid {
v := v
thisInvitation = v
break
}
}
}
if thisInvitation == nil {
ResponseQuickMsg(c, e.Failed, "邀请函不存在", nil)
return
}
//删除邀请函
_, err = GrpcArtistImpl.InvitationDel(c, &artist.InvitationDelRequest{Uuid: thisInvitation.Uuid})
if err != nil {
ResponseQuickMsg(c, e.Failed, err.Error(), nil)
return
}
//发送邀请函
resp, err := SendInvitationLetter(&req)
if err != nil {
ResponseQuickMsg(c, e.Failed, err.Error(), nil)
return
}
ResponseQuickMsg(c, e.Ok, resp.Msg, nil)
return
}
// 通过外部调用来解决 邀请函app通知 循环引包问题
var invitationLetterAppNoticeFunc func(userId int64) error
func SetInvitationLetterAppNoticeFunc(function func(userId int64) error) {
invitationLetterAppNoticeFunc = function
}
// SendInvitationLetter 发送邀请函
func SendInvitationLetter(req *artist.InvitationAddRequest) (resp *artist.InvitationAddResponse, err error) {
var c = context.Background()
req.Address = "苏州" //默认为苏州
fmt.Println("req.ShowUid", req.ShowUid)
resp, err = GrpcArtistImpl.InvitationAdd(c, req)
if err != nil {
return
}
//发送app推送通知
go func() {
var theseArtists, err = GrpcArtistInfoUserImpl.FindUsers(c, &artistInfoUser.FindUsersRequest{MgmtArtistUids: req.ArtistUuids})
if err != nil {
fmt.Printf("app通知发送失败。获取画家信息失败:%s\n", err.Error())
return
}
for _, thisUser := range theseArtists.Data {
//errs := asPush.NewPusher().InvitationLetterWaitToBeConfirmedNotice(thisUser.Id)
errs := invitationLetterAppNoticeFunc(thisUser.Id)
if errs != nil {
fmt.Printf("邀请函app推送失败artistUid:%v ,err:%v", thisUser.MgmtArtistUid, errs)
}
}
}()
return
}