You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.5 KiB
71 lines
1.5 KiB
package ws
|
|
|
|
import (
|
|
"encoding/json"
|
|
"hudongzhuanjia/models"
|
|
"time"
|
|
)
|
|
|
|
func init() {
|
|
N.RegisterLogic(LogicSync, syncFunc)
|
|
}
|
|
|
|
func syncFunc(c *Client, msg *Message) {
|
|
if c.AccountType != IDCustomer && c.Pid != 0 {
|
|
c.Write([]byte("此账号无此权限"))
|
|
return
|
|
}
|
|
|
|
operation, ok := msg.Data["operation"]
|
|
if !ok {
|
|
operation = ""
|
|
}
|
|
areaId, ok := msg.Data["area_id"]
|
|
if !ok {
|
|
areaId = 0.0
|
|
}
|
|
moduleActivityId, ok := msg.Data["module_activity_id"]
|
|
if !ok {
|
|
moduleActivityId = 0.0
|
|
}
|
|
moduleActivityType, ok := msg.Data["module_activity_type"]
|
|
if !ok {
|
|
moduleActivityType = ""
|
|
}
|
|
activityId, ok := msg.Data["activity_id"]
|
|
if !ok {
|
|
activityId = 0.0
|
|
}
|
|
extraData := []byte("")
|
|
if otherData, ok := msg.Data["other_data"]; ok {
|
|
extraData, _ = json.Marshal(otherData)
|
|
}
|
|
|
|
// 发送给所有的账户
|
|
msg.Tag = ""
|
|
msg.Dest = 0
|
|
msg.RoomId = c.RoomId
|
|
go c.Send(msg)
|
|
|
|
op := &models.CustomerOperation{
|
|
CustomerId: c.AccountId,
|
|
Operation: operation.(string),
|
|
AreaId: int64(areaId.(float64)),
|
|
ModuleActivityId: int64(moduleActivityId.(float64)),
|
|
ModuleActivityType: moduleActivityType.(string),
|
|
ActivityId: int64(activityId.(float64)),
|
|
ExtraData: string(extraData),
|
|
UpdatedAt: time.Now(),
|
|
CreatedAt: time.Now(),
|
|
}
|
|
err := models.Save(map[string]interface{}{
|
|
"activity_id=": activityId,
|
|
"is_delete=": 0,
|
|
}, op)
|
|
if err != nil {
|
|
c.Write([]byte("同步失败"))
|
|
return
|
|
}
|
|
|
|
c.Write([]byte("同步成功"))
|
|
}
|