|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- package svc
-
- import (
- "applet/app/db"
- "applet/app/e"
- md2 "applet/app/md"
- "applet/app/md/member_center"
- "applet/app/svc"
- "applet/app/utils"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "github.com/gin-gonic/gin"
- )
-
- func CertificateList(c *gin.Context) {
- var req *md.CertificateListReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- if req.Phone != "" {
- NewUserDb := implement.NewUserDb(db.Db)
- user, _ := NewUserDb.UserGetOneByParams(map[string]interface{}{
- "key": "phone",
- "value": req.Phone,
- })
- req.Uid = "0"
- if user != nil {
- req.Uid = utils.Int64ToStr(user.Id)
- }
- }
- var resp md.CertificateListResp
- noticeList := make([]md.CertificateList, 0)
- NewUserCertificateDb := implement.NewUserCertificateDb(db.Db)
- notice, total, _ := NewUserCertificateDb.FindUserCertificate(req.Page, req.Limit, req.Uid)
- resp.Total = total
- if notice != nil {
- for _, v := range *notice {
- NewUserDb := implement.NewUserDb(db.Db)
- user, _ := NewUserDb.UserGetOneByParams(map[string]interface{}{
- "key": "phone",
- "value": req.Phone,
- })
- phone := ""
- if user != nil {
- phone = user.Phone
- }
- tmp := md.CertificateList{
- Id: utils.IntToStr(v.Id),
- Name: v.Name,
- Phone: phone,
- Uid: utils.IntToStr(v.Uid),
- No: v.No,
- StartTime: v.StartTime,
- EndTime: v.EndTime,
- Logo: svc.GetOssUrl(md2.Certificate.Logo),
- BgImg: svc.GetOssUrl(md2.Certificate.BgImg),
- NameIcon: svc.GetOssUrl(md2.Certificate.NameIcon),
- Medal: svc.GetOssUrl(md2.Certificate.Medal),
- Seal: svc.GetOssUrl(md2.Certificate.Seal),
- }
- noticeList = append(noticeList, tmp)
- }
- }
- resp.List = noticeList
- e.OutSuc(c, resp, nil)
- return
- }
- func CertificateDel(c *gin.Context) {
- var req *md.CertificateDelReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- db.Db.In("id", req.Id).Delete(&model.UserCertificate{})
- e.OutSuc(c, "success", nil)
- return
- }
- func CertificateSave(c *gin.Context) {
- var req *md.CertificateSave
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var data = new(model.UserCertificate)
- if utils.StrToInt(req.Id) > 0 {
- NewUserCertificateDb := implement.NewUserCertificateDb(db.Db)
- space, _ := NewUserCertificateDb.GetUserCertificateById(req.Id)
- if space == nil {
- e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
- return
- }
- data = space
- } else {
- data.Uid = utils.StrToInt(req.Uid)
- data.No = "DD" + utils.GenerateUniqueInvitationCode(12)
- data.No = check(1, data.No)
- db.Db.Insert(data)
- }
- data.Name = req.Name
- data.StartTime = req.StartTime
- data.EndTime = req.EndTime
- db.Db.Where("id=?", data.Id).Update(data)
- e.OutSuc(c, "success", nil)
- return
- }
- func check(num int, no string) string {
- NewUserCertificateDb := implement.NewUserCertificateDb(db.Db)
- space, _ := NewUserCertificateDb.GetUserCertificateByNo(no)
- if num >= 10 {
- return ""
- }
- if space != nil {
- no = "DD" + utils.GenerateUniqueInvitationCode(12)
- num++
- return check(num, no)
- }
- return no
- }
|