package svc import ( "applet/app/db" "applet/app/db/im/model" md "applet/app/md/im" "errors" "time" ) func PageEmoticon(req md.PageEmoticonReq) (err error, resp md.PageEmoticonResp) { sess := db.DbIm.Where("1=1") if req.Memo != "" { sess.And("memo LIKE ?", "%"+req.Memo+"%") } if req.State != 0 { sess.And("state = ?", req.State) } if req.Name != "" { sess.And("name LIKE ?", "%"+req.Name+"%") } var mm []*model.Emoticon resp.Total, err = sess.Limit(req.PageSize, (req.Page-1)*req.PageSize).Desc("id").FindAndCount(&mm) if err != nil { return } resp.Page = req.Page resp.PageSize = req.PageSize for _, v := range mm { resp.List = append(resp.List, struct { Id int64 `json:"id"` //记录id Name string `json:"name" example:"名称"` ImgUrl string `json:"img_url" example:"图片地址"` Sort int `json:"Sort"` // 权重 State int `json:"state"` // 状态0关闭,1开启 Memo string `json:"memo" example:"备注"` // 备注 CreateAt string `json:"create_at" example:"创建时间"` // 创建时间 UpdateAt string `json:"update_at" example:"更新时间"` // 更新时间 }{Id: v.Id, Name: v.Name, ImgUrl: v.ImgUrl, Sort: v.Sort, State: v.State, Memo: v.Memo, CreateAt: v.CreateAt, UpdateAt: v.UpdateAt}) } return } func AddEmoticon(req md.AddEmoticonReq) (err error) { cfg := model.Emoticon{ Name: req.Name, ImgUrl: req.ImgUrl, Memo: req.Memo, Sort: req.Sort, State: 1, CreateAt: time.Now().Format("2006-01-02 15:04:05"), UpdateAt: time.Now().Format("2006-01-02 15:04:05"), } _, err = db.DbIm.InsertOne(&cfg) if err != nil { return } return } func SetEmoticonState(req md.SetEmoticonStateReq) (err error) { var customerService model.Emoticon has, err := db.DbIm.ID(req.Id).Get(&customerService) if err != nil { return } if !has { return errors.New("未查询到对应记录!") } customerService.State = req.State _, err = db.DbIm.ID(req.Id).Cols("state").Update(&customerService) if err != nil { return } return } func UpdateEmoticon(req md.UpdateEmoticonReq) (err error) { var customerService model.Emoticon has, err := db.DbIm.ID(req.Id).Get(&customerService) if err != nil { return } if !has { return errors.New("未查询到对应记录!") } customerService.Name = req.Name customerService.ImgUrl = req.ImgUrl customerService.Sort = req.Sort customerService.Memo = req.Memo _, err = db.DbIm.ID(req.Id).Update(&customerService) if err != nil { return } return } func DeleteEmoticon(req md.DeleteEmoticonReq) (err error) { _, err = db.DbIm.Where("id = ?", req.Id).Delete(&model.Emoticon{}) return }