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
53 lines
1.4 KiB
package invitation_service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"hudongzhuanjia/models"
|
|
"strings"
|
|
)
|
|
|
|
// [{"type":"输入框","name":"姓名","label":"姓名","options":[],"val":"体重"},{"type":"输入框","name":"手机","label":"手机","options":[],"val":"17688184874"},{"type":"输入框","name":"地址","label":"地址","options":[],"val":"5(๑><๑)好吃喵!"}]
|
|
func GetOptionItem(aid int) ([]string, error) {
|
|
// 添加邀请函的内容
|
|
option := new(models.CustomerOrderOption)
|
|
exist, err := option.GetByActivityId(aid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if !exist {
|
|
return nil, errors.New("订单表单设置不存在")
|
|
}
|
|
if option.SettingBox == "" {
|
|
return []string{}, nil
|
|
}
|
|
|
|
optionItems := make([]string, 0)
|
|
err = json.Unmarshal([]byte(option.SettingBox), &optionItems)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return optionItems, nil
|
|
|
|
}
|
|
|
|
func GetOptionValue(items []string, extra string) ([]map[string]interface{}, error) {
|
|
if len(items) == 0 || len(extra) == 0 {
|
|
return []map[string]interface{}{}, nil
|
|
}
|
|
|
|
answers := make([]map[string]interface{}, 0)
|
|
err := json.Unmarshal([]byte(strings.Trim(extra, `"`)), &answers)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
data := make([]map[string]interface{}, 0)
|
|
for _, answer := range answers {
|
|
for _, item := range items {
|
|
if item == answer["name"] {
|
|
data = append(data, answer)
|
|
}
|
|
}
|
|
}
|
|
return data, nil
|
|
}
|