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

215 lines
5.8 KiB

  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. //TODO 调用打包机
  108. keys := "CloudBuild"
  109. if req.Os == "2" {
  110. keys = "CloudBuild-iOS"
  111. }
  112. token := "aaaaaa"
  113. masterKey := "master"
  114. domain := ""
  115. if cfg.Prd == false {
  116. masterKey = "dev"
  117. domain = "http://ddstar.izhim.cn"
  118. }
  119. url := "http://120.76.175.204:8080/job/" + keys + "/buildWithParameters?platform=" + tmp.NewPlatform + "&os=" + req.Os + "&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 += "&id=" + utils.IntToStr(tmp.Id)
  124. getcurl(url)
  125. } else {
  126. if req.IsCombine != "1" {
  127. for _, v := range req.Bit {
  128. newUrl := url
  129. ids := make([]string, 0)
  130. for _, v1 := range req.Platform {
  131. tmp1 := tmp
  132. tmp1.Bit = v
  133. tmp1.Platform = v1
  134. db.Db.Insert(&tmp1)
  135. ids = append(ids, utils.IntToStr(tmp1.Id))
  136. }
  137. newUrl += "&bit=" + v + "&id=" + strings.Join(ids, ",")
  138. getcurl(newUrl)
  139. }
  140. } else {
  141. ids := make([]string, 0)
  142. for _, v1 := range req.Platform {
  143. tmp1 := tmp
  144. tmp1.Platform = v1
  145. db.Db.Insert(&tmp1)
  146. url += "&id=" + utils.IntToStr(tmp1.Id)
  147. getcurl(url)
  148. }
  149. url += "&bit=" + strings.Join(req.Bit, ",") + "&id=" + strings.Join(ids, ",")
  150. getcurl(url)
  151. }
  152. }
  153. e.OutSuc(c, "success", nil)
  154. return
  155. }
  156. func getcurl(url string) (string, error) {
  157. return "", nil
  158. client := &http.Client{}
  159. // 创建请求
  160. request, err := http.NewRequest("GET", url, nil)
  161. if err != nil {
  162. return "", err
  163. }
  164. // 设置用户名和密码,这里的"user:password"是用户名和密码的组合,中间不能有空格
  165. request.SetBasicAuth("fnuoos", "11ad0050eef8521bc85f1c06ebf018654b")
  166. // 发送请求
  167. response, err := client.Do(request)
  168. if err != nil {
  169. return "", err
  170. }
  171. // 读取响应内容
  172. defer response.Body.Close()
  173. body, err := io.ReadAll(response.Body)
  174. if err != nil {
  175. return "", err
  176. }
  177. fmt.Println(string(body))
  178. return string(body), nil
  179. }
  180. func Del(c *gin.Context) {
  181. var req *md.ArticleDelReq
  182. if err := c.ShouldBindJSON(&req); err != nil {
  183. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  184. return
  185. }
  186. db.Db.In("id", req.Id).Delete(&model.CloudBundle{})
  187. e.OutSuc(c, "success", nil)
  188. return
  189. }
  190. func AuditSet(c *gin.Context) {
  191. var req *md.CommReq
  192. if err := c.ShouldBindJSON(&req); err != nil {
  193. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  194. return
  195. }
  196. db.Db.Where("id=?", req.Id).Cols("is_auditing").Update(&model.CloudBundle{IsAuditing: 1})
  197. e.OutSuc(c, "success", nil)
  198. return
  199. }
  200. func AuditClear(c *gin.Context) {
  201. var req *md.AuditClearReq
  202. if err := c.ShouldBindJSON(&req); err != nil {
  203. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  204. return
  205. }
  206. db.Db.Where("os=?", req.Os).Cols("is_auditing").Update(&model.CloudBundle{IsAuditing: 0})
  207. e.OutSuc(c, "success", nil)
  208. return
  209. }