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

52 lines
1.1 KiB

5 years ago
  1. package invitation_service
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "hudongzhuanjia/models"
  6. "strings"
  7. )
  8. func GetOptionItem(aid int64) ([]string, error) {
  9. // 添加邀请函的内容
  10. option := new(models.CustomerOrderOption)
  11. exist, err := option.GetByActivityId(aid)
  12. if err != nil {
  13. return nil, err
  14. }
  15. if !exist {
  16. return nil, errors.New("订单表单设置不存在")
  17. }
  18. if option.SettingBox == "" {
  19. return []string{}, nil
  20. }
  21. optionItems := make([]string, 0)
  22. err = json.Unmarshal([]byte(option.SettingBox), &optionItems)
  23. if err != nil {
  24. return nil, err
  25. }
  26. return optionItems, nil
  27. }
  28. func GetOptionValue(items []string, extra string) ([]map[string]interface{}, error) {
  29. if len(items) == 0 || len(extra) == 0 {
  30. return []map[string]interface{}{}, nil
  31. }
  32. answers := make([]map[string]interface{}, 0)
  33. err := json.Unmarshal([]byte(strings.Trim(extra, `"`)), &answers)
  34. if err != nil {
  35. return nil, err
  36. }
  37. data := make([]map[string]interface{}, 0)
  38. for _, answer := range answers {
  39. for _, item := range items {
  40. if item == answer["name"] {
  41. data = append(data, answer)
  42. }
  43. }
  44. }
  45. return data, nil
  46. }