51 lines
1.9 KiB
Go
51 lines
1.9 KiB
Go
package main
|
|
|
|
import "github.com/line/line-bot-sdk-go/v7/linebot"
|
|
|
|
func ApiMe(event *linebot.Event) {
|
|
leftBtn := linebot.NewURIAction("修改資料", flagBase+"/profile")
|
|
rightBtn := linebot.NewMessageAction("我的保單", "我的保單")
|
|
template := linebot.NewConfirmTemplate("請問想辦理甚麼服務?", leftBtn, rightBtn)
|
|
msg := linebot.NewTemplateMessage("請問想辦理甚麼服務?", template)
|
|
if _, err := SendMessage(event.ReplyToken, event.Source.UserID, msg); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func ApiMyOrders(event *linebot.Event) {
|
|
var orders []Order
|
|
DB.Order("product_id").Find(&orders, "user_id = ?", event.Source.UserID)
|
|
|
|
if len(orders) == 0 {
|
|
text := "您目前沒有保單喲, 歡迎前往投保專區選取保單。"
|
|
tmp := linebot.NewButtonsTemplate("", "", text, linebot.NewMessageAction("帶我前往", "我想投保"))
|
|
msg := linebot.NewTemplateMessage(text, tmp)
|
|
if _, err := SendMessage(event.ReplyToken, event.Source.UserID, msg); err != nil {
|
|
panic(err)
|
|
}
|
|
} else {
|
|
pids := make([]uint, len(orders))
|
|
for i := range orders {
|
|
pids[i] = orders[i].ProductID
|
|
}
|
|
var products []Product
|
|
if err := DB.Preload("Categories").Order("id").Find(&products, "id in ?", pids).Error; err != nil {
|
|
panic(err)
|
|
}
|
|
columns := make([]*linebot.CarouselColumn, len(products))
|
|
for i, prod := range products {
|
|
columns[i] = linebot.NewCarouselColumn(
|
|
prod.Img, prod.Name, prod.Brief,
|
|
linebot.NewURIAction("保單詳細", flagBase+"/product"),
|
|
linebot.NewPostbackAction("我要理賠", "claim="+prod.Name, "我要理賠", ""),
|
|
// linebot.NewPostbackAction("我是"+prof.Name, "select="+prof.Name, "我是"+prof.Name, ""),
|
|
)
|
|
}
|
|
template := linebot.NewCarouselTemplate(columns...)
|
|
msg := linebot.NewTemplateMessage("您的保單資訊", template)
|
|
if _, err := SendMessage(event.ReplyToken, event.Source.UserID, msg); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
}
|