package svc import ( "applet/app/e" "applet/app/lib/validate" "applet/app/md" "applet/app/utils" "code.fnuoos.com/zhimeng/model.git/src/implement" "code.fnuoos.com/zhimeng/model.git/src/model" "github.com/gin-gonic/gin" "github.com/jinzhu/copier" "time" ) func AppletApplicationList(c *gin.Context) { var req md.AppletApplicationListReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } engine := MasterDb(c) NewAppletApplicationDb := implement.NewAppletApplicationDb(engine) state := make([]string, 0) if req.CooperateState != "" { if req.CooperateState == "0" { state = []string{"0", "1"} } else { state = []string{req.CooperateState} } } user := GetUser(c) appletApplicationList, total, _ := NewAppletApplicationDb.FindAppletApplicationList(req.Name, req.Platform, state, user.MediumId, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) data := make([]md.AppletApplicationListData, 0) if len(appletApplicationList) > 0 { for _, v := range appletApplicationList { var tmp md.AppletApplicationListData copier.Copy(&tmp, &v) tmp.Id = utils.IntToStr(v.Id) tmp.State = utils.IntToStr(v.State) if v.State == 1 { v.State = 0 } tmp.CooperateState = utils.IntToStr(v.State) data = append(data, tmp) } } res := md.AppletApplicationListRes{ List: data, Total: total, Platform: []md.SelectData{ { Name: "微信小程序", Value: "wx_applet", }, }, State: []md.SelectData{ { Name: "待审核", Value: "0", }, { Name: "审核中", Value: "1", }, { Name: "审核通过", Value: "2", }, { Name: "审核拒绝", Value: "3", }, { Name: "封禁中", Value: "4", }, }, CooperateState: []md.SelectData{ { Name: "未运行", Value: "0", }, { Name: "运行中", Value: "2", }, { Name: "审核拒绝", Value: "3", }, { Name: "封禁中", Value: "4", }, }, } e.OutSuc(c, res, nil) return } func AppletApplicationSave(c *gin.Context) { var req md.AppletApplicationSaveReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } if req.AppId == "" { e.OutErr(c, 400, e.NewErr(400, "请填写小程序appid")) return } user := GetUser(c) engine := MasterDb(c) NewAppletApplicationDb := implement.NewAppletApplicationDb(engine) var data *model.AppletApplication if utils.StrToInt(req.Id) > 0 { data, _ = NewAppletApplicationDb.GetAppletApplicationList(utils.StrToInt(req.Id)) if data == nil { e.OutErr(c, 400, e.NewErr(400, "记录不存在")) return } if data.State != 3 { e.OutErr(c, 400, e.NewErr(400, "您已提交审核,不能再次修改!")) return } tmp, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(req.AppId) if tmp != nil && tmp.Id != data.Id { e.OutErr(c, 400, e.NewErr(400, "该小程序已提交过")) return } } else { tmp, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(req.AppId) if tmp != nil { e.OutErr(c, 400, e.NewErr(400, "该小程序已提交过")) return } data = &model.AppletApplication{ Platform: req.Platform, State: 0, MediumId: user.MediumId, AppId: req.AppId, CreateAt: time.Now(), } engine.Insert(data) } data.UpdateAt = time.Now() data.State = 0 data.Name = req.Name data.Logo = req.Logo data.AppId = req.AppId data.OriginalId = req.OriginalId engine.Where("id=?", data.Id).Update(data) e.OutSuc(c, "success", nil) return }