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.

66 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package biz
import (
"context"
"customer/api/valuation"
"database/sql"
"github.com/go-kratos/kratos/v2/transport/grpc"
"gorm.io/gorm"
)
type CustomerWork struct {
Telephone string `gorm:"type:varchar(15);uniqueIndex;" json:"telephone,omitempty"`
Name sql.NullString `gorm:"type:varchar(255);uniqueIndex;" json:"name,omitempty"`
Email sql.NullString `gorm:"type:varchar(255);uniqueIndex;" json:"email,omitempty"`
Wechat sql.NullString `gorm:"type:varchar(255);uniqueIndex;" json:"wechat,omitempty"`
CityID uint `gorm:"index;" json:"city_id"`
}
const CustomerSecret = "yourSecretKey"
const CustomerDuration = 2 * 30 * 24 * 3600
type CustomerToken struct {
Token string `gorm:"type:varchar(4095);" json:"token,omitempty"`
TokenCreatedAt sql.NullTime `gorm:"" json:"tokenCreatedAt"`
}
type Customer struct {
gorm.Model
CustomerToken
CustomerWork
}
type CustomerBiz struct {
}
func NewCustomerBiz() *CustomerBiz {
return &CustomerBiz{}
}
func (cb *CustomerBiz) GetEstimatePrice(origin, destination string) (int64, error) {
// 一grpc 获取
conn, err := grpc.DialInsecure(
context.Background(),
grpc.WithEndpoint("localhost:9300"),
)
if err != nil {
return 0, nil
}
//关闭
defer func() {
_ = conn.Close()
}()
// 2.2,发送获取验证码请求
client := valuation.NewValuationClient(conn)
reply, err := client.GetEstimatePrice(context.Background(), &valuation.GetEstimatePriceReq{
Origin: origin,
Destination: destination,
})
if err != nil {
return 0, err
}
return reply.Price, nil
}