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

3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
2 weeks ago
3 weeks ago
2 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
2 weeks ago
2 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
2 weeks ago
2 weeks ago
5 days ago
2 weeks ago
3 weeks ago
2 weeks ago
3 weeks ago
2 weeks ago
3 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
3 weeks ago
3 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
3 weeks ago
3 weeks ago
2 weeks ago
3 weeks ago
2 weeks ago
3 weeks ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. }
  81. e.OutSuc(c, resp, nil)
  82. return
  83. }
  84. func Build(c *gin.Context) {
  85. var req *md.CloudBundleBuildReq
  86. if err := c.ShouldBindJSON(&req); err != nil {
  87. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  88. return
  89. }
  90. count, _ := db.Db.Where("os=? and version=?", req.Os, req.Version).Count(&model.CloudBundle{})
  91. if count > 0 {
  92. e.OutErr(c, 400, e.NewErr(400, "版本已存在"))
  93. return
  94. }
  95. if req.Os == "2" {
  96. req.Platform = []string{"ios"}
  97. }
  98. tmp := model.CloudBundle{
  99. Os: utils.StrToInt(req.Os),
  100. Version: req.Version,
  101. ApplyAt: int(time.Now().Unix()),
  102. Memo: req.Memo,
  103. AppletId: 0,
  104. NewPlatform: strings.Join(req.Platform, ","),
  105. IsCombine: req.IsCombine,
  106. NewBit: strings.Join(req.Bit, ","),
  107. }
  108. keys := "ddxq-android"
  109. if req.Os == "2" {
  110. keys = "%E8%9B%8B%E8%9B%8B%E6%98%9F%E7%90%83-iOS"
  111. }
  112. token := "aaaaaa"
  113. masterKey := "master"
  114. domain := "http://" + c.Request.Host
  115. if cfg.Prd == false {
  116. domain = svc.GetSysCfgStr("admin_host")
  117. masterKey = "dev"
  118. }
  119. 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)
  120. tmp.Bit = strings.Join(req.Bit, ",")
  121. if req.Os == "2" {
  122. db.Db.Insert(&tmp)
  123. url += "&ios_id=" + utils.IntToStr(tmp.Id)
  124. getcurl(url)
  125. } else {
  126. if req.IsCombine != "1" {
  127. for _, v := range req.Bit {
  128. for _, v1 := range req.Platform {
  129. tmp1 := tmp
  130. tmp1.Bit = v
  131. tmp1.Platform = v1
  132. db.Db.Insert(&tmp1)
  133. newUrl := url
  134. newUrl += "&channel=" + v1 + "&&bit=" + v + "&android_id=" + utils.IntToStr(tmp1.Id)
  135. getcurl(newUrl)
  136. }
  137. }
  138. } else {
  139. for _, v1 := range req.Platform {
  140. tmp1 := tmp
  141. tmp1.Platform = v1
  142. db.Db.Insert(&tmp1)
  143. newUrl := url
  144. newUrl += "&channel=" + v1 + "&bit=" + strings.Join(req.Bit, ",") + "&android_id=" + utils.IntToStr(tmp1.Id)
  145. getcurl(newUrl)
  146. }
  147. }
  148. }
  149. e.OutSuc(c, "success", nil)
  150. return
  151. }
  152. func getcurl(url string) (string, error) {
  153. client := &http.Client{}
  154. // 创建请求
  155. request, err := http.NewRequest("GET", url, nil)
  156. if err != nil {
  157. return "", err
  158. }
  159. // 设置用户名和密码,这里的"user:password"是用户名和密码的组合,中间不能有空格
  160. request.SetBasicAuth("fnuoos", "11ad0050eef8521bc85f1c06ebf018654b")
  161. // 发送请求
  162. response, err := client.Do(request)
  163. if err != nil {
  164. return "", err
  165. }
  166. // 读取响应内容
  167. defer response.Body.Close()
  168. body, err := io.ReadAll(response.Body)
  169. if err != nil {
  170. return "", err
  171. }
  172. fmt.Println(string(body))
  173. return string(body), nil
  174. }
  175. func Del(c *gin.Context) {
  176. var req *md.CloudBundleDelReq
  177. if err := c.ShouldBindJSON(&req); err != nil {
  178. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  179. return
  180. }
  181. db.Db.In("id", req.Ids).Delete(&model.CloudBundle{})
  182. e.OutSuc(c, "success", nil)
  183. return
  184. }
  185. func AuditSet(c *gin.Context) {
  186. var req *md.CommReq
  187. if err := c.ShouldBindJSON(&req); err != nil {
  188. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  189. return
  190. }
  191. db.Db.Where("id=?", req.Id).Cols("is_auditing").Update(&model.CloudBundle{IsAuditing: 1})
  192. e.OutSuc(c, "success", nil)
  193. return
  194. }
  195. func AuditClear(c *gin.Context) {
  196. var req *md.AuditClearReq
  197. if err := c.ShouldBindJSON(&req); err != nil {
  198. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  199. return
  200. }
  201. db.Db.Where("os=?", req.Os).Cols("is_auditing").Update(&model.CloudBundle{IsAuditing: 0})
  202. e.OutSuc(c, "success", nil)
  203. return
  204. }