蛋蛋星球 后台端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

svc_list.go 5.7 KiB

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