@ -4,8 +4,12 @@ import (
"encoding/json"
"fmt"
"key_performance_indicators/api/workwechat"
"key_performance_indicators/models/modelshr"
"key_performance_indicators/models/modelskpi"
"key_performance_indicators/overall"
"key_performance_indicators/overall/publicmethod"
"strings"
"time"
"github.com/gin-gonic/gin"
)
@ -300,3 +304,101 @@ func (a *ApiMethod) SendMessageMini(c *gin.Context) {
outPut [ "workwechatErr" ] = workwechatErr
publicmethod . Result ( 0 , outPut , c )
}
// 更新卡片mini
func ( a * ApiMethod ) UpdateMiniCard ( c * gin . Context ) {
var receivedValue UpdateMiniTemp
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if receivedValue . Type == 0 {
receivedValue . Type = 1
}
if receivedValue . Orderkey == "" {
publicmethod . Result ( 1 , err , c , "未知参数" )
return
}
if receivedValue . Enforcer == "" {
publicmethod . Result ( 1 , err , c , "未知参数" )
return
}
var updateWechatCont modelskpi . UpdateWechatTempmsg
err = overall . CONSTANT_DB_KPI . Where ( "`type` = ? AND `orderkey` = ? AND FIND_IN_SET(?,`enforcer`)" , receivedValue . Type , receivedValue . Orderkey , receivedValue . Enforcer ) . Find ( & updateWechatCont ) . Error
if err != nil || updateWechatCont . Sendmsgcont == "" || updateWechatCont . ResponseCode == "" || updateWechatCont . State == 1 {
publicmethod . Result ( 105 , err , c )
return
}
sendUpdateMsg := publicmethod . MapOut [ string ] ( )
var weChatMsgCont workwechat . SentMiniMessage
json . Unmarshal ( [ ] byte ( updateWechatCont . Sendmsgcont ) , & weChatMsgCont )
templateCardCont := publicmethod . MapOut [ string ] ( )
templateCardCont [ "card_type" ] = weChatMsgCont . TemplateCard . CardType
templateCardCont [ "source" ] = weChatMsgCont . TemplateCard . Source
templateCardCont [ "main_title" ] = weChatMsgCont . TemplateCard . MainTitle
templateCardCont [ "task_id" ] = weChatMsgCont . TemplateCard . TaskId
templateCardCont [ "action_menu" ] = weChatMsgCont . TemplateCard . ActionMenu
templateCardCont [ "quote_area" ] = weChatMsgCont . TemplateCard . QuoteArea
templateCardCont [ "horizontal_content_list" ] = weChatMsgCont . TemplateCard . HorizontalContentList
templateCardCont [ "card_action" ] = weChatMsgCont . TemplateCard . CardAction
var userCont modelshr . PersonArchives
userCont . GetCont ( map [ string ] interface { } { "`key`" : receivedValue . Enforcer } , "`name`" )
titleStr := fmt . Sprintf ( "%v已处理,查看详情" , userCont . Name )
for i , v := range weChatMsgCont . TemplateCard . JumpList {
if v . Type == 1 {
weChatMsgCont . TemplateCard . JumpList [ i ] . Title = titleStr
}
}
templateCardCont [ "jump_list" ] = weChatMsgCont . TemplateCard . JumpList
receiveMsgMan := strings . Split ( updateWechatCont . Enforcer , "," )
if len ( receiveMsgMan ) < 1 {
publicmethod . Result ( 105 , err , c )
return
}
var weCahtOpenId [ ] string
for _ , v := range receiveMsgMan {
var userContWechat modelshr . PersonArchives
userContWechat . GetCont ( map [ string ] interface { } { "`key`" : v } , "`wechat`" , "`work_wechat`" )
if userContWechat . Wechat != "" {
if ! publicmethod . IsInTrue [ string ] ( userContWechat . Wechat , weCahtOpenId ) {
weCahtOpenId = append ( weCahtOpenId , userContWechat . Wechat )
}
}
if userContWechat . WorkWechat != "" {
if ! publicmethod . IsInTrue [ string ] ( userContWechat . WorkWechat , weCahtOpenId ) {
weCahtOpenId = append ( weCahtOpenId , userContWechat . WorkWechat )
}
}
}
if len ( weCahtOpenId ) < 1 {
publicmethod . Result ( 105 , err , c )
return
}
sendUpdateMsg [ "userids" ] = weCahtOpenId
sendUpdateMsg [ "agentid" ] = weChatMsgCont . AgentId
sendUpdateMsg [ "response_code" ] = updateWechatCont . ResponseCode
sendUpdateMsg [ "enable_id_trans" ] = 1
sendUpdateMsg [ "template_card" ] = templateCardCont
UpDateCont , err := workwechat . UpdateMessageMap ( sendUpdateMsg )
var editUpdateWechatCont modelskpi . UpdateWechatTempmsg
editCont := publicmethod . MapOut [ string ] ( )
editCont [ "`sate`" ] = 1
editCont [ "`time`" ] = time . Now ( ) . Unix ( )
editErr := editUpdateWechatCont . EiteCont ( map [ string ] interface { } { "`id`" : updateWechatCont . Id } , editCont )
outPut := publicmethod . MapOut [ string ] ( )
outPut [ "UpDateCont" ] = UpDateCont
outPut [ "err" ] = err
outPut [ "editErr" ] = editErr
outPut [ "sendUpdateMsg" ] = sendUpdateMsg
publicmethod . Result ( 0 , outPut , c )
}