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

53 lines
1.4 KiB

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