蛋蛋星球 后台端
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.

svc_list.go 5.8 KiB

1 month ago
1 month ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
4 weeks ago
2 weeks ago
1 week ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
3 weeks ago
3 weeks ago
3 weeks ago
1 month ago
1 month ago
3 weeks ago
4 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
1 month ago
1 month ago
3 weeks ago
1 month ago
3 weeks ago
1 month ago
3 days ago
1 month ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. package cloud_bundle
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/db"
  5. "applet/app/e"
  6. "applet/app/md"
  7. "applet/app/svc"
  8. "applet/app/utils"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  10. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  11. "fmt"
  12. "github.com/gin-gonic/gin"
  13. "github.com/syyongx/php2go"
  14. "io"
  15. "net/http"
  16. "strings"
  17. "time"
  18. )
  19. func List(c *gin.Context) {
  20. var req *md.CloudBundleReq
  21. if err := c.ShouldBindJSON(&req); err != nil {
  22. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  23. return
  24. }
  25. var resp md.CloudBundleResp
  26. noticeList := make([]md.CloudBundleList, 0)
  27. NewCloudBundleDb := implement.NewCloudBundleDb(db.Db)
  28. notice, total, _ := NewCloudBundleDb.FindCloudBundleAndTotal(req.Page, req.Limit)
  29. resp.Total = total
  30. if notice != nil {
  31. for _, v := range *notice {
  32. tmp := md.CloudBundleList{
  33. Id: utils.IntToStr(v.Id),
  34. BuildId: v.BuildId,
  35. Version: v.Version,
  36. Os: utils.IntToStr(v.Os),
  37. State: utils.IntToStr(v.State),
  38. Memo: v.Memo,
  39. Src: svc.GetOssUrl(v.Src),
  40. Bit: v.Bit,
  41. IsCombine: v.IsCombine,
  42. FinishAt: "--",
  43. Platform: v.Platform,
  44. IsAuditing: utils.IntToStr(v.IsAuditing),
  45. }
  46. if v.ApplyAt > 0 {
  47. tmp.ApplyAt = time.Unix(int64(v.ApplyAt), 0).Format("2006-01-02 15:04:05")
  48. }
  49. if v.FinishAt > 0 && v.State == 999 {
  50. tmp.FinishAt = time.Unix(int64(v.FinishAt), 0).Format("2006-01-02 15:04:05")
  51. }
  52. noticeList = append(noticeList, tmp)
  53. }
  54. }
  55. lastAndroid, _ := NewCloudBundleDb.GetCloudBundleLast("1")
  56. resp.LastBit = "64"
  57. resp.LastIsCombine = "0"
  58. resp.LastPlatform = make([]string, 0)
  59. if lastAndroid != nil {
  60. resp.LastAndroid = lastAndroid.Version
  61. resp.LastBit = lastAndroid.Bit
  62. resp.LastIsCombine = lastAndroid.IsCombine
  63. platform := strings.Split(lastAndroid.NewPlatform, ",")
  64. resp.LastPlatform = platform
  65. }
  66. lastIos, _ := NewCloudBundleDb.GetCloudBundleLast("2")
  67. if lastIos != nil {
  68. resp.ListIos = lastIos.Version
  69. }
  70. resp.List = noticeList
  71. resp.SelectData = []md.CloudBundleVersionMap{
  72. {Type: "station", Name: "官方渠道"},
  73. {Type: "yingyongbao", Name: "应用宝商店"},
  74. {Type: "huawei", Name: "华为应用商店"},
  75. {Type: "xiaomi", Name: "小米应用商店"},
  76. {Type: "meizu", Name: "魅族应用商店"},
  77. {Type: "vivo", Name: "VIVO应用商店"},
  78. {Type: "oppo", Name: "OPPO应用商店"},
  79. {Type: "360", Name: "360应用商店"},
  80. {Type: "aliApp", Name: "阿里应用"},
  81. }
  82. e.OutSuc(c, resp, nil)
  83. return
  84. }
  85. func Build(c *gin.Context) {
  86. var req *md.CloudBundleBuildReq
  87. if err := c.ShouldBindJSON(&req); err != nil {
  88. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  89. return
  90. }
  91. count, _ := db.Db.Where("os=? and version=?", req.Os, req.Version).Count(&model.CloudBundle{})
  92. if count > 0 {
  93. e.OutErr(c, 400, e.NewErr(400, "版本已存在"))
  94. return
  95. }
  96. if req.Os == "2" {
  97. req.Platform = []string{"ios"}
  98. }
  99. tmp := model.CloudBundle{
  100. Os: utils.StrToInt(req.Os),
  101. Version: req.Version,
  102. ApplyAt: int(time.Now().Unix()),
  103. Memo: req.Memo,
  104. AppletId: 0,
  105. NewPlatform: strings.Join(req.Platform, ","),
  106. IsCombine: req.IsCombine,
  107. NewBit: strings.Join(req.Bit, ","),
  108. }
  109. keys := "ddxq-android"
  110. if req.Os == "2" {
  111. keys = "%E8%9B%8B%E8%9B%8B%E6%98%9F%E7%90%83-iOS"
  112. }
  113. token := "aaaaaa"
  114. masterKey := "master"
  115. domain := "http://" + c.Request.Host
  116. if cfg.Prd == false {
  117. domain = svc.GetSysCfgStr("admin_host")
  118. masterKey = "dev"
  119. }
  120. url := "http://120.76.175.204:8080/job/" + keys + "/buildWithParameters?version=" + req.Version + "&timestamp=" + utils.Int64ToStr(time.Now().Unix()) + "&token=" + token + "&branch=" + masterKey + "&domain=" + php2go.URLEncode(domain)
  121. tmp.Bit = strings.Join(req.Bit, ",")
  122. if req.Os == "2" {
  123. db.Db.Insert(&tmp)
  124. url += "&ios_id=" + utils.IntToStr(tmp.Id)
  125. getcurl(url)
  126. } else {
  127. if req.IsCombine != "1" {
  128. for _, v := range req.Bit {
  129. for _, v1 := range req.Platform {
  130. tmp1 := tmp
  131. tmp1.Bit = v
  132. tmp1.Platform = v1
  133. db.Db.Insert(&tmp1)
  134. newUrl := url
  135. newUrl += "&channel=" + v1 + "&&bit=" + v + "&android_id=" + utils.IntToStr(tmp1.Id)
  136. getcurl(newUrl)
  137. }
  138. }
  139. } else {
  140. for _, v1 := range req.Platform {
  141. tmp1 := tmp
  142. tmp1.Platform = v1
  143. db.Db.Insert(&tmp1)
  144. newUrl := url
  145. newUrl += "&channel=" + v1 + "&bit=" + strings.Join(req.Bit, ",") + "&android_id=" + utils.IntToStr(tmp1.Id)
  146. getcurl(newUrl)
  147. }
  148. }
  149. }
  150. e.OutSuc(c, "success", nil)
  151. return
  152. }
  153. func getcurl(url string) (string, error) {
  154. client := &http.Client{}
  155. // 创建请求
  156. request, err := http.NewRequest("GET", url, nil)
  157. if err != nil {
  158. return "", err
  159. }
  160. // 设置用户名和密码,这里的"user:password"是用户名和密码的组合,中间不能有空格
  161. request.SetBasicAuth("fnuoos", "11ad0050eef8521bc85f1c06ebf018654b")
  162. // 发送请求
  163. response, err := client.Do(request)
  164. if err != nil {
  165. return "", err
  166. }
  167. // 读取响应内容
  168. defer response.Body.Close()
  169. body, err := io.ReadAll(response.Body)
  170. if err != nil {
  171. return "", err
  172. }
  173. fmt.Println(string(body))
  174. return string(body), nil
  175. }
  176. func Del(c *gin.Context) {
  177. var req *md.CloudBundleDelReq
  178. if err := c.ShouldBindJSON(&req); err != nil {
  179. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  180. return
  181. }
  182. db.Db.In("id", req.Ids).Delete(&model.CloudBundle{})
  183. e.OutSuc(c, "success", nil)
  184. return
  185. }
  186. func AuditSet(c *gin.Context) {
  187. var req *md.CommReq
  188. if err := c.ShouldBindJSON(&req); err != nil {
  189. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  190. return
  191. }
  192. db.Db.Where("id=?", req.Id).Cols("is_auditing").Update(&model.CloudBundle{IsAuditing: utils.StrToInt(req.IsAuditing)})
  193. e.OutSuc(c, "success", nil)
  194. return
  195. }
  196. func AuditClear(c *gin.Context) {
  197. var req *md.AuditClearReq
  198. if err := c.ShouldBindJSON(&req); err != nil {
  199. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  200. return
  201. }
  202. db.Db.Where("os=?", req.Os).Cols("is_auditing").Update(&model.CloudBundle{IsAuditing: 0})
  203. e.OutSuc(c, "success", nil)
  204. return
  205. }