Skip to content

Commit

Permalink
iphone 13 预约到店逻辑修改
Browse files Browse the repository at this point in the history
  • Loading branch information
hteen committed Sep 26, 2021
1 parent 33430e0 commit 85fcc1e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 37 deletions.
2 changes: 1 addition & 1 deletion common/const.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package common

const VERSION = "1.3.0"
const VERSION = "1.3.1"
10 changes: 0 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ func main() {
areaWidget.SetSelected(defaultArea)
areaWidget.Horizontal = true

services.Listen.Quantity.SetSelected("1")

w.SetContent(container.NewVBox(
widget.NewLabel("1.首次运行请先获取Apple注册码,确保能正确打开网页\n"+
"2.选择门店和型号,点击添加按钮\n"+
Expand All @@ -68,8 +66,6 @@ func main() {
}),
),
container.NewHBox(
container.NewCenter(widget.NewLabel("预购数量:")),
services.Listen.Quantity,
widget.NewButton("开始", func() {
services.Listen.Status.Set(services.Running)
}),
Expand All @@ -83,12 +79,6 @@ func main() {
services.Listen.Logs,
layout.NewSpacer(),
container.NewHBox(
widget.NewButton("13mini/13 注册码", func() {
go services.Listen.RegisterCode("iphone13")
}),
widget.NewButton("13p/13pm 注册码", func() {
go services.Listen.RegisterCode("iphone13pro")
}),
layout.NewSpacer(),
widget.NewLabel("version: "+common.VERSION),
),
Expand Down
38 changes: 12 additions & 26 deletions services/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var Listen = listenService{
Status: binding.NewString(),
Area: model.Areas[0],
Logs: widget.NewLabel(""),
Quantity: widget.NewSelect([]string{"1", "2"}, nil),
}

type listenService struct {
Expand All @@ -40,7 +39,6 @@ type listenService struct {
Area model.Area
Window fyne.Window
Logs *widget.Label
Quantity *widget.Select
}

type ListenItem struct {
Expand Down Expand Up @@ -111,7 +109,7 @@ func (s *listenService) Run() {

if status {
s.UpdateStatus(key, StatusInStock)
s.openBrowser(s.model2Url(item.Product.Type, item.Store.StoreNumber, item.Product.Code))
s.openBrowser(s.model2Url(item.Product.Type, item.Product.Code))
dialog.ShowInformation("匹配成功", fmt.Sprintf("%s %s 有货", item.Store.CityStoreName, item.Product.Title), s.Window)
} else {
s.UpdateStatus(key, StatusOutStock)
Expand Down Expand Up @@ -153,32 +151,20 @@ func (s *listenService) getSkus() map[string]bool {
return skus
}

// RegisterCode 帮助提前获取注册码
func (s *listenService) RegisterCode(productType string) {
stores := s.getSkuByCode(model.TypeCode[productType])

// 寻找任意一个有货门店
for store, items := range stores.Map() {
for k, v := range items.Map() {
if v.Get("availability.contract").Bool() && v.Get("availability.unlocked").Bool() {
s.openBrowser(s.model2Url(productType, store, k))
return
}
}
// 型号对应预约地址
func (s *listenService) model2Url(productType string, partNumber string) string {
// https://www.apple.com.cn/shop/buy-iphone/iphone-13/MLE73CH/A
var t string
switch productType {
case "iphone13promax", "iphone13pro":
t = "iphone-13-pro"
case "iphone13mini", "iphone13":
t = "iphone-13"
}

dialog.ShowError(errors.New("所有门店无货,无法前往注册码页面"), s.Window)
}

// 型号对应预约地址
func (s *listenService) model2Url(productType string, store string, partNumber string) string {
return fmt.Sprintf(
"https://reserve-prime.apple.com/%s/reserve/%s?quantity=%s&anchor-store=%s&store=%s&partNumber=%s&plan=unlocked",
s.Area.Code,
model.TypeCode[productType],
s.Quantity.Selected,
store,
store,
"https://www.apple.com.cn/shop/buy-iphone/%s/%s",
t,
partNumber,
)
}
Expand Down

0 comments on commit 85fcc1e

Please sign in to comment.