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

83 lines
2.0 KiB

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. "time"
  9. )
  10. type WsCtl struct {
  11. controllers.AuthorCtl
  12. }
  13. // ws doc
  14. // @Summary ws
  15. // @Description get current operation
  16. // @Tags ws
  17. // @Accept json
  18. // @Produce json
  19. // @Param activity_id query int true "Activity ID"
  20. // @Success 0 {array} models.CustomerOperation
  21. // @Failure 503 {string} string "参数不存在"
  22. // @Failure 504 {object} string "用户不存在"
  23. // @Router /Pc/WsCtl/ops [get]
  24. func (t *WsCtl) Ops() {
  25. customerId := t.MustGetUID()
  26. activityId, _ := t.GetInt64("activity_id")
  27. customer := new(models.Customer)
  28. exist, err := models.GetById(customer, customerId)
  29. t.CheckErr(err)
  30. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  31. op := new(models.CustomerOperation)
  32. if customer.Pid == 0 {
  33. exist, err = op.GetOpByActivityId(activityId)
  34. } else {
  35. exist, err = op.GetOpByCustomerId(customer.Pid)
  36. }
  37. t.CheckErr(err)
  38. if !exist {
  39. t.JSON(map[string]interface{}{
  40. "operations": []*models.CustomerOperation{},
  41. })
  42. }
  43. var m = make(map[string]interface{})
  44. err = json.Unmarshal([]byte(op.ExtraData), &m)
  45. t.CheckErr(err)
  46. op.OtherData = m
  47. t.JSON(map[string]interface{}{
  48. "operations": []*models.CustomerOperation{op},
  49. })
  50. }
  51. // ws doc
  52. // @Summary ws
  53. // @Description save operation
  54. // @Tags ws
  55. // @Accept json
  56. // @Produce json
  57. // @Param operation query string true "操作内容"
  58. // @Success 0 {string} string "success"
  59. // @Failure 503 {string} string "参数不存在"
  60. // @Failure 504 {object} string "用户不存在"
  61. // @Router /Pc/WsCtl/saveOp [post]
  62. func (t *WsCtl) SaveOp() {
  63. customerId := t.MustGetInt64("customer_id")
  64. extraData := t.Default("extra_data", "")
  65. op := &models.CustomerOperation{
  66. CustomerId: customerId,
  67. ExtraData: extraData,
  68. UpdatedAt: time.Now(),
  69. CreatedAt: time.Now(),
  70. }
  71. if row := op.SaveCustomerOperation(); row != 1 {
  72. logger.Sugar.Debugf("save customer_operation出现错误")
  73. t.ERROR("customer operation格式错误", code.MSG_ERR)
  74. }
  75. t.STRING("success")
  76. }