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

63 lines
1.4 KiB

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. "time"
  9. )
  10. type WsCtl struct {
  11. controllers.AuthorCtl
  12. }
  13. // ws doc
  14. func (t *WsCtl) Ops() {
  15. customerId := t.MustGetUID()
  16. activityId, _ := t.GetInt64("activity_id")
  17. customer := new(models.Customer)
  18. exist, err := models.Get(customer, customerId)
  19. t.CheckErr(err)
  20. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  21. op := new(models.CustomerOperation)
  22. if customer.Pid == 0 {
  23. exist, err = op.GetOpByActivityId(activityId)
  24. } else {
  25. exist, err = op.GetOpByCustomerId(customer.Pid)
  26. }
  27. t.CheckErr(err)
  28. if !exist {
  29. t.JSON(map[string]interface{}{
  30. "operations": []*models.CustomerOperation{},
  31. })
  32. }
  33. var m = make(map[string]interface{})
  34. err = json.Unmarshal([]byte(op.ExtraData), &m)
  35. t.CheckErr(err)
  36. op.OtherData = m
  37. t.JSON(map[string]interface{}{
  38. "operations": []*models.CustomerOperation{op},
  39. })
  40. }
  41. // ws doc
  42. func (t *WsCtl) SaveOp() {
  43. customerId := t.MustGetInt64("customer_id")
  44. extraData := t.Default("extra_data", "")
  45. op := &models.CustomerOperation{
  46. CustomerId: customerId,
  47. ExtraData: extraData,
  48. UpdatedAt: time.Now(),
  49. CreatedAt: time.Now(),
  50. }
  51. if row := op.SaveCustomerOperation(); row != 1 {
  52. logger.Error("save customer_operation出现错误")
  53. t.ERROR("customer operation格式错误", code.MSG_ERR)
  54. }
  55. t.SUCCESS("success")
  56. }