app.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "github.com/json-iterator/go"
  6. "go-common/app/interface/bbq/app-bbq/api/http/v1"
  7. "go-common/app/interface/bbq/app-bbq/conf"
  8. )
  9. // AppSetting .
  10. func (s *Service) AppSetting(c context.Context, arg *v1.AppSettingRequest) (resp *v1.AppSettingResponse, err error) {
  11. plat := 1
  12. if arg.Base.Client == "ios" {
  13. plat = 2
  14. }
  15. appVerison, err := s.dao.FetchNewAppVersion(c, plat, arg.VersionCode)
  16. newVersion := uint8(0)
  17. if err == nil && appVerison.ID > 0 {
  18. newVersion = uint8(1)
  19. }
  20. // TODO:暂时先这样,快速上线,以后改(也许。。)
  21. ver := 1
  22. if arg.Base.Client == "ios" && arg.VersionCode > 100000 {
  23. ver = 2
  24. } else if arg.Base.Client == "android" && arg.VersionCode > 101000 {
  25. ver = 2
  26. }
  27. appResource, err := s.dao.FetchAppResource(c, plat, ver)
  28. current := time.Now().Unix()
  29. pubSetting := make(map[string]interface{})
  30. b, _ := jsoniter.Marshal(conf.App)
  31. jsoniter.Unmarshal(b, &pubSetting)
  32. for _, v := range appResource {
  33. if v.StartTime.Time().Unix() < current && current < v.EndTime.Time().Unix() {
  34. pubSetting["dynamic_effect"] = v.ID
  35. }
  36. }
  37. resp = &v1.AppSettingResponse{
  38. Public: pubSetting,
  39. Update: &v1.AppUpdate{
  40. NewVersion: newVersion,
  41. Info: appVerison,
  42. },
  43. Resources: appResource,
  44. }
  45. return
  46. }
  47. // AppPackage .
  48. func (s *Service) AppPackage(c context.Context, lastest int) (resp []*v1.AppPackage, err error) {
  49. resp = make([]*v1.AppPackage, 0)
  50. if lastest > 0 {
  51. result, e := s.dao.FetchNewAppVersion(c, 1, 0)
  52. resp = append(resp, &v1.AppPackage{
  53. ID: int64(result.ID),
  54. Platform: uint8(result.Platform),
  55. VersionName: result.Name,
  56. VersionCode: uint32(result.Code),
  57. Title: result.Title,
  58. Content: result.Content,
  59. Download: result.Download,
  60. MD5: result.MD5,
  61. Size: int32(result.Size),
  62. Force: uint8(result.Force),
  63. Status: uint8(result.Status),
  64. })
  65. err = e
  66. } else {
  67. resp, err = s.dao.FetchAppPackage(c)
  68. }
  69. return
  70. }