cvc/src/loreal.com/dit/cmd/coupon-service/coupon/logic.coupon.go

41 lines
987 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package coupon
import (
// "database/sql"
"encoding/json"
// "fmt"
"log"
)
// GetPropertiesString 获取属性map[string]string的字符串格式。
func (c *Coupon) GetPropertiesString() (*string, error) {
jsonBytes, err := json.Marshal(c.Properties)
if nil != err {
log.Println(err)
return nil, err
}
var str = string(jsonBytes)
return &str, nil
}
// SetPropertiesFromString 根据string来设置Coupon属性map[string]string
func (c *Coupon) SetPropertiesFromString(properties string) error{
err := json.Unmarshal([]byte(properties), &c.Properties)
if nil != err {
log.Println(err)
return err
}
return nil
}
// GetRules 获取卡券的规则
func (c *Coupon) GetRules() map[string]interface{} {
var rules map[string]interface{}
var ok bool
if rules, ok = c.Properties[KeyBindingRuleProperties].(map[string]interface{}); ok {
return rules
}
// log.Println("============if rules, ok============" )
// log.Println(ok )
return nil
}