MCPcopy Index your code
hub / github.com/FloatTech/ZeroBot-Plugin / refreshStroeInfo

Method refreshStroeInfo

plugin/mcfish/main.go:548–644  ·  view source on GitHub ↗

*********************************************************/ ************************商店相关函数***********************/ *********************************************************/ 刷新商店信息

()

Source from the content-addressed store, hash-verified

546
547// 刷新商店信息
548func (sql *fishdb) refreshStroeInfo() (ok bool, err error) {
549 sql.Lock()
550 defer sql.Unlock()
551 err = sql.db.Create("stroeDiscount", &storeDiscount{})
552 if err != nil {
553 return false, err
554 }
555 err = sql.db.Create("store", &store{})
556 if err != nil {
557 return false, err
558 }
559 lastTime := storeDiscount{}
560 _ = sql.db.Find("stroeDiscount", &lastTime, "WHERE Name = 'lastTime'")
561 refresh := false
562 timeNow := time.Now().Day()
563 if timeNow != lastTime.Discount {
564 lastTime = storeDiscount{
565 Name: "lastTime",
566 Discount: timeNow,
567 }
568 err = sql.db.Insert("stroeDiscount", &lastTime)
569 if err != nil {
570 return false, err
571 }
572 refresh = true
573 }
574 for _, name := range thingList {
575 thing := storeDiscount{}
576 switch refresh {
577 case true:
578 thingDiscount := 50 + rand.Intn(150)
579 thing = storeDiscount{
580 Name: name,
581 Discount: thingDiscount,
582 }
583 thingInfo := store{}
584 _ = sql.db.Find("store", &thingInfo, "WHERE Name = ?", name)
585 if thingInfo.Number > 150 {
586 // 控制价格浮动区间: -10%到10%
587 thing.Discount = 90 + rand.Intn(20)
588 }
589 err = sql.db.Insert("stroeDiscount", &thing)
590 if err != nil {
591 return
592 }
593 default:
594 _ = sql.db.Find("stroeDiscount", &thing, "WHERE Name = ?", name)
595 }
596 if thing.Discount != 0 {
597 discountList[name] = thing.Discount
598 } else {
599 discountList[name] = 100
600 }
601 }
602 thing := store{}
603 var oldThing []store
604 _ = sql.db.FindFor("stroeDiscount", &thing, "WHERE type = 'pole'", func() error {
605 if time.Since(time.Unix(thing.Duration, 0)) > 24 {

Callers 1

store.goFile · 0.80

Calls 1

DayMethod · 0.80

Tested by

no test coverage detected