智慧食堂
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.

main_back.go 3.9 KiB

10 months ago
3 months ago
10 months ago
3 months ago
10 months ago
3 months ago
10 months ago
3 months ago
10 months ago
3 months ago
10 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package main
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. "applet/app/utils"
  6. "context"
  7. "fmt"
  8. "log"
  9. "net/http"
  10. "os"
  11. "os/signal"
  12. "syscall"
  13. "time"
  14. "applet/app/cfg"
  15. "applet/app/router"
  16. )
  17. func main1() {
  18. //svc.CentralKitchenForSchoolAlipayTradeFastpayRefundQuery(db.Db)
  19. var list []model.CentralKitchenForSchoolPackageOrdForReserve
  20. if err := db.Db.Where("create_at >= '2024-09-01 15:00:00'").Desc("id").Find(&list); err != nil {
  21. fmt.Println(err)
  22. }
  23. //
  24. var ordIds = map[string]string{}
  25. for _, v := range list {
  26. if ordIds[v.OutTradeNo+"_"+utils.AnyToString(v.Kind)+"_"+v.ReserveMonth] != "" {
  27. continue
  28. }
  29. var tmpList []model.CentralKitchenForSchoolPackageOrdForReserve
  30. if err := db.Db.Where("out_trade_no = ?", v.OutTradeNo).And("kind =?", v.Kind).And("reserve_month =?", v.ReserveMonth).
  31. And("total_price =?", v.TotalPrice).Find(&tmpList); err != nil {
  32. fmt.Println(err)
  33. }
  34. fmt.Println(v.OutTradeNo)
  35. if len(tmpList) > 1 {
  36. ordIds[v.OutTradeNo+"_"+utils.AnyToString(v.Kind)+"_"+v.ReserveMonth] = v.OutTradeNo
  37. utils.FilePutContents("test_test_test", v.OutTradeNo)
  38. }
  39. // v.RecordsId = -v.RecordsId
  40. // v.OutTradeNo = "-" + v.OutTradeNo
  41. // affected1, err := db.Db.Where("id=?", v.Id).Cols("records_id", "out_trade_no").Update(&v)
  42. // if err != nil {
  43. // fmt.Println(err)
  44. // }
  45. // fmt.Println(">>>>>>>>>>>>>>>>>affected1<<<<<<<<<<<<<<<<<<<", affected1)
  46. // continue
  47. // var mm []model.CentralKitchenForSchoolUserRefundDay
  48. // if err := db.Db.Where("uid = ?", v.Uid).And("state = 1").Desc("records_id").Find(&mm); err != nil {
  49. // fmt.Println(err)
  50. // }
  51. //
  52. // if len(mm) > 0 {
  53. // mmm := new(model.CentralKitchenForSchoolUserWithDay)
  54. // _, err := db.Db.Where("id =?", mm[0].RecordsId).Get(mmm)
  55. // if err != nil {
  56. // fmt.Println(err)
  57. // }
  58. // //if mmm.Date == "2024-01-31" {
  59. // //1、更改当前记录
  60. // v.Uid = -v.Uid
  61. // affected1, err := db.Db.Where("id=?", v.Id).Cols("uid").Update(&v)
  62. // if err != nil {
  63. // fmt.Println(err)
  64. // }
  65. // fmt.Println(">>>>>>>>>>>>>>>>>affected1<<<<<<<<<<<<<<<<<<<", affected1)
  66. // vv := new(model.CentralKitchenForSchoolUserWithDay)
  67. // _, err = db.Db.Where("id =?", v.RecordsId).Get(vv)
  68. // if err != nil {
  69. // fmt.Println(err)
  70. // }
  71. // vv.State = 2
  72. // affected11, err := db.Db.Where("id=?", vv.Id).Cols("state").Update(vv)
  73. // if err != nil {
  74. // fmt.Println(err)
  75. // }
  76. // fmt.Println(">>>>>>>>>>>>>>>>>affected11<<<<<<<<<<<<<<<<<<<", affected11)
  77. //
  78. // //2、更改兑换记录
  79. // mm[0].OutRequestNo = v.OutRequestNo
  80. // mm[0].State = v.State
  81. // mm[0].RefundDate = v.RefundDate
  82. // mm[0].Memo = "exchange"
  83. // affected2, err := db.Db.Where("id=?", mm[0].Id).Cols("out_request_no", "state", "refund_date", "memo").Update(mm[0])
  84. // if err != nil {
  85. // fmt.Println(err)
  86. // }
  87. // fmt.Println(">>>>>>>>>>>>>>>>>affected2<<<<<<<<<<<<<<<<<<<", affected2)
  88. // mmm.State = 4
  89. // affected22, err := db.Db.Where("id=?", mmm.Id).Cols("state").Update(mmm)
  90. // if err != nil {
  91. // fmt.Println(err)
  92. // }
  93. // fmt.Println(">>>>>>>>>>>>>>>>>affected22<<<<<<<<<<<<<<<<<<<", affected22)
  94. //
  95. // //}
  96. // } else {
  97. // notCanUserIds = append(notCanUserIds, v.Uid)
  98. // }
  99. }
  100. return
  101. r := router.Init() //创建路由
  102. srv := &http.Server{ //设置http服务参数
  103. Addr: cfg.SrvAddr, //指定ip和端口
  104. Handler: r, //指定路由
  105. }
  106. go func() { //协程启动监听http服务
  107. fmt.Println("Listening and serving HTTP on " + cfg.SrvAddr)
  108. if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
  109. log.Fatalf("listen: %s\n", err)
  110. }
  111. }()
  112. //退出go守护进程
  113. quit := make(chan os.Signal)
  114. signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
  115. <-quit
  116. log.Println("Shutting down server...")
  117. ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
  118. defer cancel()
  119. if err := srv.Shutdown(ctx); err != nil {
  120. log.Fatal("Server forced to shutdown:", err)
  121. }
  122. log.Println("Server exiting")
  123. }