package chat import ( "fmt" "github.com/gin-gonic/gin" "github.com/liangdas/mqant/log" "gorm.io/gorm" "server/call" "server/common" "server/db" "server/modules/customer/app" "server/modules/customer/values" "server/pb" "time" ) // 获取聊天历史 func GetCustomerHistory(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := new(values.GetCustomerHistoryReq) if !a.S(req) { return } var resp values.GetCustomerHistoryResp Count, err := db.Mysql().QueryList(req.Page-1, req.Num, fmt.Sprintf("title = %v", req.Title), "time DESC", &common.CustomerChatData{}, &resp.List) if err != nil { if err != gorm.ErrRecordNotFound { log.Error(err.Error()) a.Code = values.CodeRetry return } } resp.Count = Count a.Data = resp } // 消息已读 func ReadMessage(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.ReadMessageReq{} if !a.S(req) { return } for i := 0; i < len(req.List); i++ { err := db.Mysql().Update(&common.CustomerChatData{ID: req.List[i], Title: req.Title}, map[string]interface{}{"is_read": true}) if err != nil { log.Error(err.Error()) } } if req.OrderId != 0 { db.Mysql().Update(&common.CustomerOrder{ID: req.OrderId}, map[string]interface{}{ "un_read": 0, }) } // 需要通知在线玩家刷新客服消息 // session := call.GetUserSession(req.Title) // if session == nil { // return // } // call.SendSS(session, int(pb.ServerCommonCmd_CMD_BS_CustomerMsgResp), nil, "common") } // 玩家发送消息 func SendMessage(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.SendMessageReq{} if !a.S(req) { return } req.Time = time.Now().Unix() err := db.Mysql().Create(&req) if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry return } // 需要通知在线玩家刷新客服消息 session := call.GetUserSession(req.Title) if session == nil { return } call.SendSS(session, int(pb.ServerCommonCmd_CMD_BS_CustomerMsgResp), nil, "common") } // 根据订单状态获取订单列表 func GetCustomerOrder(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.GetCustomerOrderReq{} if !a.S(req) { return } var resp values.GetCustomerOrderResp var flag bool var query string if req.Label != 0 { query += fmt.Sprintf(" (label1 = %v OR label2 = %v OR label3 = %v OR label4 = %v OR label5 = %v) ", req.Label, req.Label, req.Label, req.Label, req.Label) flag = true } if req.Uid != 0 { if flag { query += " AND " } query += fmt.Sprintf(" uid = %v ", req.Uid) flag = true } if req.CustomerUid != 0 { if flag { query += " AND " } query += fmt.Sprintf(" customer_uid = %v ", req.CustomerUid) flag = true } if req.Status != 0 { if flag { query += " AND " } query = fmt.Sprintf(" status = %v", req.Status) flag = true } else { if req.Status2 != 0 { if flag { query += " AND " } query = fmt.Sprintf(" status <= %v", req.Status2) flag = true } } if req.Vip != 0 { if flag { query += " AND " } query += fmt.Sprintf(" vip >= %v ", req.Vip) flag = true } var order = "start DESC" if req.Order == 2 { order = "start ASC" } if req.Order == 3 { order = "un_read DESC" } count, err := db.Mysql().QueryList(req.Page-1, req.Num, query, order, &common.CustomerOrder{}, &resp.List) if err != nil && err != gorm.ErrRecordNotFound { log.Error(err.Error()) a.Code = values.CodeRetry return } resp.Count = count a.Data = resp } // 工单处理状态改变 func ChangeCustomerOrderStatus(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.ChangeCustomerOrderReq{} if !a.S(req) { return } for i := 0; i < len(req.List); i++ { update := make(map[string]interface{}) /*if req.List[i].Status != 0 { update["status"] = req.List[i].Status } if req.List[i].Label1 != 0 { update["label1"] = req.List[i].Label1 } if req.List[i].Label2 != 0 { update["label2"] = req.List[i].Label2 } if req.List[i].Label3 != 0 { update["label3"] = req.List[i].Label3 } if req.List[i].Label4 != 0 { update["label4"] = req.List[i].Label4 } if req.List[i].Label5 != 0 { update["label5"] = req.List[i].Label5 } if len(update) < 1 { continue }*/ update["status"] = req.List[i].Status update["label1"] = req.List[i].Label1 update["label2"] = req.List[i].Label2 update["label3"] = req.List[i].Label3 update["label4"] = req.List[i].Label4 update["label5"] = req.List[i].Label5 // 完成工单 update["end"] = time.Now().Unix() update["un_read"] = 0 err := db.Mysql().Update(&common.CustomerOrder{ID: req.List[i].Id}, update) if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry return } } } // 分配工单到客服人员 func CustomerOrderAllocate(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.CustomerOrderAllocateReq{} if !a.S(req) { return } tx := db.Mysql().Begin() defer a.MCommit(tx) for i := 0; i < len(req.List); i++ { err := tx.Exec("UPDATE customer_order SET customer_uid = ?, status = ? WHERE id = ? AND status != ?", req.List[i].Uid, common.CustomerOrderAllocate, req.List[i].OrderId, common.CustomerOrderComplete).Error if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry } } } // 编辑标签 func EditCustomerOrderLabel(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.EditCustomerOrderLabelReq{} if !a.S(req) { return } update := make(map[string]interface{}) update["label1"] = req.LabelId1 update["label2"] = req.LabelId2 update["label3"] = req.LabelId3 update["label4"] = req.LabelId4 update["label5"] = req.LabelId5 err := db.Mysql().Update(&common.CustomerOrder{ID: req.OrderId}, update) if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry return } } // 获取玩家信息 func GetPlayerInfo(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.GetPlayerInfoReq{} if !a.S(req) { return } var resp values.GetPlayerInfoResp // 玩家信息 player, err := call.GetUserXInfo(req.Uid, "channel_id", "nick", "avatar", "birth", "mobile") if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry return } resp.Uid = req.Uid resp.Nick = player.Nick resp.Avatar = player.Avatar resp.Birth = player.Birth resp.Phone = player.Mobile resp.Channel = player.ChannelID // 渠道信息 channel := &common.Channel{ChannelID: player.ChannelID} err = db.Mysql().Get(channel) if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry return } resp.Package = channel.PackName // vip resp.Vip = call.GetVIP(req.Uid).Level order := &common.RechargeInfo{UID: req.Uid} err = db.Mysql().Get(order) if err != nil { log.Error(err.Error()) } resp.Withdraw = order.TotalWithdraw resp.Recharge = order.TotalRecharge if db.Mysql().Exist(&common.CustomerBlackUser{Uid: req.Uid}) { resp.CustomerBlack = true } a.Data = resp } // 玩家历史客诉记录 func ComplaintHistory(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.ComplaintHistoryReq{} if !a.S(req) { return } var resp values.ComplaintHistoryResp count, err := db.Mysql().QueryList(req.Page-1, req.Num, fmt.Sprintf("uid = %v", req.Uid), "", &common.CustomerOrder{}, &resp.List) if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry return } resp.Count = count a.Data = resp }