|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- 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
- }
|