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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package ws
  2. import (
  3. "encoding/json"
  4. "hudongzhuanjia/models"
  5. "time"
  6. )
  7. func init() {
  8. N.RegisterLogic(LogicSync, syncFunc)
  9. }
  10. func syncFunc(c *Client, msg *Message) {
  11. if c.AccountType != IDCustomer && c.Pid != 0 {
  12. c.Write([]byte("此账号无此权限"))
  13. return
  14. }
  15. operation, ok := msg.Data["operation"]
  16. if !ok {
  17. operation = ""
  18. }
  19. areaId, ok := msg.Data["area_id"]
  20. if !ok {
  21. areaId = 0.0
  22. }
  23. moduleActivityId, ok := msg.Data["module_activity_id"]
  24. if !ok {
  25. moduleActivityId = 0.0
  26. }
  27. moduleActivityType, ok := msg.Data["module_activity_type"]
  28. if !ok {
  29. moduleActivityType = ""
  30. }
  31. activityId, ok := msg.Data["activity_id"]
  32. if !ok {
  33. activityId = 0.0
  34. }
  35. extraData := []byte("")
  36. if otherData, ok := msg.Data["other_data"]; ok {
  37. extraData, _ = json.Marshal(otherData)
  38. }
  39. // 发送给所有的账户
  40. msg.Tag = ""
  41. msg.Dest = 0
  42. msg.RoomId = c.RoomId
  43. go c.Send(msg)
  44. op := &models.CustomerOperation{
  45. CustomerId: c.AccountId,
  46. Operation: operation.(string),
  47. AreaId: int64(areaId.(float64)),
  48. ModuleActivityId: int64(moduleActivityId.(float64)),
  49. ModuleActivityType: moduleActivityType.(string),
  50. ActivityId: int64(activityId.(float64)),
  51. ExtraData: string(extraData),
  52. UpdatedAt: time.Now(),
  53. CreatedAt: time.Now(),
  54. }
  55. err := models.Save(map[string]interface{}{
  56. "activity_id=": activityId,
  57. "is_delete=": 0,
  58. }, op)
  59. if err != nil {
  60. c.Write([]byte("同步失败"))
  61. return
  62. }
  63. c.Write([]byte("同步成功"))
  64. }