互动
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.

95 lines
2.3 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package pc
  2. import (
  3. "encoding/json"
  4. "hudongzhuanjia/controllers"
  5. "hudongzhuanjia/logger"
  6. "hudongzhuanjia/models"
  7. "hudongzhuanjia/utils/code"
  8. "hudongzhuanjia/utils/define"
  9. "strings"
  10. "time"
  11. )
  12. type WsCtl struct {
  13. controllers.AuthorCtl
  14. }
  15. // ws doc
  16. func (t *WsCtl) Ops() {
  17. customerId := t.GetAccountId()
  18. activityId, _ := t.GetInt("activity_id")
  19. customer := new(models.Customer)
  20. exist, err := models.Get(customer, customerId)
  21. t.CheckErr(err)
  22. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  23. op := new(models.CustomerOperation)
  24. if customer.Pid == 0 {
  25. exist, err = op.GetOpByActivityId(activityId)
  26. } else {
  27. exist, err = op.GetOpByCustomerId(customer.Pid)
  28. }
  29. t.CheckErr(err)
  30. if !exist {
  31. t.JSON(map[string]interface{}{
  32. "operations": []*models.CustomerOperation{},
  33. })
  34. }
  35. var m = make(map[string]interface{})
  36. err = json.Unmarshal([]byte(op.ExtraData), &m)
  37. t.CheckErr(err)
  38. op.OtherData = m
  39. t.JSON(map[string]interface{}{
  40. "operations": []*models.CustomerOperation{op},
  41. })
  42. }
  43. // ws doc
  44. func (t *WsCtl) SaveOp() {
  45. customerId := t.MustGetInt("customer_id")
  46. extraData := t.Default("extra_data", "")
  47. op := &models.CustomerOperation{
  48. CustomerId: customerId,
  49. ExtraData: extraData,
  50. UpdatedAt: time.Now(),
  51. CreatedAt: time.Now(),
  52. }
  53. if row := op.SaveCustomerOperation(); row != 1 {
  54. logger.Error("save customer_operation出现错误")
  55. t.ERROR("customer operation格式错误", code.MSG_ERR)
  56. }
  57. t.SUCCESS("success")
  58. }
  59. func (t *WsCtl) CheckToken() {
  60. token := t.MustGet("token")
  61. tokens := strings.SplitN(token, ":", 2)
  62. if tokens[0] == define.TYPE_USER { // h5用户
  63. user := &models.User{}
  64. err := user.GetByToken(tokens[1])
  65. t.CheckErr(err)
  66. t.AccountId = user.Id
  67. t.AccountType = tokens[0]
  68. } else if tokens[0] == define.TYPE_CUSTOMER { // 客户
  69. customer := &models.Customer{}
  70. err := customer.GetByToken(tokens[1])
  71. t.CheckErr(err)
  72. t.AccountId = customer.Id
  73. t.AccountType = tokens[0]
  74. } else if tokens[0] == define.TYPE_ENTRYPEOPLE { // 录入人员
  75. entry := &models.OrderEntryPerson{}
  76. err := entry.GetByToken(tokens[1])
  77. t.CheckErr(err)
  78. t.AccountId = entry.Id
  79. t.AccountType = tokens[0]
  80. } else {
  81. t.ERROR("token失效", code.MSG_ERR_Authority)
  82. }
  83. t.JSON(map[string]interface{}{
  84. "account_id": t.AccountId,
  85. "account_type": t.AccountType,
  86. })
  87. }