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

65 regels
1.1 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/utils"
  5. "applet/app/utils/logx"
  6. "errors"
  7. "fmt"
  8. "time"
  9. "xorm.io/xorm"
  10. )
  11. func CancelOrder(eg *xorm.Engine, dbName string) {
  12. fmt.Println("cancel order...")
  13. defer func() {
  14. if err := recover(); err != nil {
  15. _ = logx.Error(err)
  16. }
  17. }()
  18. timeStr, err := getCancelCfg(eg, dbName)
  19. if err != nil {
  20. fmt.Println(err.Error())
  21. return
  22. }
  23. now := time.Now()
  24. // x 分钟后取消订单
  25. expTime := now.Add(-time.Hour * time.Duration(utils.StrToInt64(timeStr)))
  26. expTimeStr := utils.Time2String(expTime, "")
  27. page := 1
  28. for {
  29. isEmpty, err := handleOnePage(eg, dbName, expTimeStr)
  30. if err != nil {
  31. _ = logx.Error(err)
  32. break
  33. }
  34. if isEmpty {
  35. break
  36. }
  37. if page > 100 {
  38. break
  39. }
  40. page += 1
  41. }
  42. }
  43. func handleOnePage(eg *xorm.Engine, dbName, expTimeStr string) (isEmpty bool, err error) {
  44. return false, nil
  45. }
  46. func getCancelCfg(eg *xorm.Engine, masterId string) (string, error) {
  47. cfg := db.SysCfgGetWithDb(eg, masterId, "order_expiration_time")
  48. if cfg == "" {
  49. return "", errors.New("order_expiration_time no found")
  50. }
  51. return cfg, nil
  52. }