Ejemplo n.º 1
0
func main() {
	i := 5
	if 3 < i && i < 7 {
		log.Println("foo")
	}
	log.Println(u.FirstOf("", "", 1234))

}
func _get_feedback(fields []s.InField) (fdb string, rate int) {
	//todo return not only string represent also int rating
	for _, v := range fields {
		if v.Name == "text" {
			fdb = u.FirstOf(v.Data.Value, v.Data.Text).(string)
		}
	}
	rate = 5
	return fdb, rate
}
Ejemplo n.º 3
0
func (s *SediAPI) prepareOrderParams(order t.NewOrderInfo) map[string]string {
	params := map[string]string{
		"street0": order.Delivery.Street,
		"house0":  order.Delivery.House,
		"city0":   utils.FirstOf(order.Delivery.City, s.City).(string),
	}
	if order.Delivery.IdAddress != "" {
		params["addrid0"] = order.Delivery.IdAddress
	}

	for i, destination := range order.Destinations {
		if destination == nil {
			continue
		}
		address_number := i + 1
		params[fmt.Sprintf("street%v", address_number)] = destination.Street
		params[fmt.Sprintf("house%v", address_number)] = destination.House
		params[fmt.Sprintf("city%v", address_number)] = utils.FirstOf(destination.City, s.City).(string)

		if destination.IdAddress != "" {
			params[fmt.Sprintf("addrid%v", address_number)] = destination.IdAddress
		}
		if destination.Lat != 0.0 && destination.Lon != 0.0 {
			params[fmt.Sprintf("lat%v", address_number)], params[fmt.Sprintf("lon%v", address_number)] = GeoToString(destination.Lat, destination.Lon)
		}
	}

	if order.DeliveryTime != "" {
		t, _ := time.Parse("2006-01-02 15:04:05", order.DeliveryTime)
		params["date"] = "new Date(" + fmt.Sprintf("%v", t) + ")"
		params["ordertype"] = "preliminary"
	} else {
		params["date"] = "new Date(" + fmt.Sprintf("%v", time.Now().Unix()+60*(1+int64(order.DeliveryMinutes))) + ")"
		params["ordertype"] = "rush"
	}

	if s.SaleKeyword != "" {
		params["keyword"] = s.SaleKeyword
	}
	return params
}
func get_text(in s.InCommand) (s string, err error) {
	if len(in.Form.Fields) == 1 {
		//		log.Printf("TAXI Getting text from: %+v\n at: %+v", in.Form.Fields[0])
		if s, ok := u.FirstOf(in.Form.Fields[0].Data.Text, in.Form.Fields[0].Data.Value).(string); ok {
			return s, nil
		}
		return "", errors.New("Can not find text at this form :(")
	} else {
		err = errors.New("No fields in input command :(")
		return s, err
	}
}
func _form_order(fields []s.InField, ah AddressHandler) (*NewOrderInfo, error) {
	var from_key, from_name, to_key, to_name, hf, ht, entrance string
	var dHours, dMin int
	for _, field := range fields {
		switch fn := field.Name; fn {
		case "street_from":
			from_key = field.Data.Value
			from_name = field.Data.Text
		case "street_to":
			to_key = field.Data.Value
			to_name = field.Data.Text
		case "house_to":
			ht = u.FirstOf(field.Data.Value, field.Data.Text).(string)
		case "house_from":
			hf = u.FirstOf(field.Data.Value, field.Data.Text).(string)
		case "entrance":
			entrance = u.FirstOf(field.Data.Value, field.Data.Text).(string)
		case "thour":
			dHours, _ = strconv.Atoi(field.Data.Text)
		case "tmin":
			dMin, _ = strconv.Atoi(field.Data.Text)
		}
	}
	var dest, deliv AddressF
	if ah != nil {
		if from_key == "" || to_key == "" {
			return nil, &AddressNotHere{From: from_key, To: to_key}
		}
		if !ah.IsHere(from_key) && !ah.IsHere(to_key) {
			return nil, &AddressNotHere{From: from_key, To: to_key}
		}
		del_id_street_, err_from := ah.GetExternalInfo(from_key, from_name)
		dest_id_street_, err_to := ah.GetExternalInfo(to_key, to_name)
		if err_from != nil {
			return nil, err_from
		}
		if err_to != nil {
			return nil, err_to
		}
		deliv = *del_id_street_
		dest = *dest_id_street_
	} else {
		//		log.Printf("Address handler is nil. Using street id and name values... [%v] %v --> [%v] %v", from_key, from_name, to_key, to_name)
		err := json.Unmarshal([]byte(from_key), &deliv)
		if err != nil {
			log.Printf("FORM ORDER Error at unmarshal address from; %v\n%v", err, from_key)
		}
		err = json.Unmarshal([]byte(to_key), &dest)
		if err != nil {
			log.Printf("FORM ORDER Error at unmarshal address to; %v\n%v", err, to_key)
		}
		//		log.Printf("\nDelivery: %v\nDestination: %v", deliv, dest)
	}

	deliv_id := strconv.FormatInt(deliv.ID, 10)
	dest_id := strconv.FormatInt(dest.ID, 10)

	delivery := Delivery{
		Street:    u.FirstOf(from_name, deliv.Name).(string),
		IdStreet:  deliv.ID,
		House:     hf,
		City:      deliv.City,
		Entrance:  entrance,
		IdRegion:  deliv.IDRegion,
		IdAddress: deliv_id,
	}

	destination := Destination{
		Street:    u.FirstOf(to_name, dest.Name).(string),
		IdStreet:  dest.ID,
		House:     ht,
		IdRegion:  dest.IDRegion,
		IdAddress: dest_id,
		City:      dest.City,
	}

	new_order := NewOrderInfo{Notes: "Заказ создан через мессенджер Klichat"}
	if dHours > 0 && dMin > 0 {
		dTime := time.Now().Add(time.Duration(dHours) * time.Hour)
		dTime = time.Now().Add(time.Duration(dMin) * time.Minute)
		log.Printf("Order after: %+v", dTime)
		dTime.Format("2006.01.02 15:04:05")
		new_order.DeliveryTime = dTime.Format("2006.01.02 15:04:05")
	}

	new_order.Delivery = &delivery
	new_order.Destinations = []*Destination{&destination}
	return &new_order, nil
}