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

package invitation_service
import (
"encoding/json"
"errors"
"hudongzhuanjia/models"
"strings"
)
func GetOptionItem(aid int64) ([]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
}