|
- package svc
-
- import (
- "applet/app/e"
- "applet/app/lib/validate"
- "applet/app/md"
- "applet/app/utils"
- db "code.fnuoos.com/zhimeng/model.git/src"
- implement2 "code.fnuoos.com/zhimeng/model.git/src/implement"
- "code.fnuoos.com/zhimeng/model.git/src/super/implement"
- "code.fnuoos.com/zhimeng/model.git/src/super/model"
- "github.com/gin-gonic/gin"
- "strings"
- "time"
- )
-
- func AgentBindMediumList(c *gin.Context) { //代理 查旗下 媒体
- var req md.MediumListReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- engine := db.Db
- agentWithMediumDb := implement.NewAgentWithMediumDb(engine)
- data, total, _ := agentWithMediumDb.FindAgentWithMediumList(req.Name, req.State, utils.StrToInt(req.Id), 0, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
-
- list := make([]md.MediumListData, 0)
- NewMediumDb := implement2.NewMediumDb(MasterDb(c))
-
- if data != nil {
- for _, v := range data {
- tmp := md.MediumListData{
- Id: utils.IntToStr(v.AgentWithMedium.Id),
- MediumId: utils.IntToStr(v.AgentWithMedium.MediumId),
- CompanyName: v.MediumList.CompanyName,
- UnifiedSocialCreditCode: v.MediumList.UnifiedSocialCreditCode,
- State: utils.IntToStr(v.MediumList.State),
- Memo: v.MediumList.Memo,
- LegalRepresentative: v.MediumList.LegalRepresentative,
- BusinessLicenseAddress: v.MediumList.BusinessLicenseAddress,
- }
- medium := NewMediumDb.GetSuperAdmin(v.AgentWithMedium.MediumId)
- if medium != nil {
- tmp.Account = medium.Username
- }
- list = append(list, tmp)
- }
- }
- res := md.MediumListRes{
- List: list,
- Total: total,
- State: []md.SelectData{
- {Name: "待提交", Value: "0"},
- {Name: "待审核", Value: "1"},
- {Name: "审核通过", Value: "2"},
- {Name: "审核拒绝", Value: "3"},
- },
- }
- e.OutSuc(c, res, nil)
- return
- }
- func MediumBindAgentList(c *gin.Context) {
- var req md.MediumListReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- engine := db.Db
- agentWithMediumDb := implement.NewAgentWithMediumDb(engine)
- data, total, _ := agentWithMediumDb.FindAgentWithMediumList(req.Name, req.State, 0, utils.StrToInt(req.Id), utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
-
- list := make([]md.MediumListData, 0)
- NewAgentDb := implement2.NewAgentDb(MasterDb(c))
-
- if data != nil {
- for _, v := range data {
- tmp := md.MediumListData{
- Id: utils.IntToStr(v.AgentWithMedium.Id),
- MediumId: utils.IntToStr(v.AgentWithMedium.AgentId),
- CompanyName: v.AgentList.CompanyName,
- UnifiedSocialCreditCode: v.AgentList.UnifiedSocialCreditCode,
- State: utils.IntToStr(v.AgentList.State),
- Memo: v.AgentList.Memo,
- LegalRepresentative: v.AgentList.LegalRepresentative,
- BusinessLicenseAddress: v.AgentList.BusinessLicenseAddress,
- }
- agent := NewAgentDb.GetSuperAdmin(v.AgentWithMedium.AgentId)
- if agent != nil {
- tmp.Account = agent.Username
- }
- list = append(list, tmp)
- }
- }
- res := md.MediumListRes{
- List: list,
- Total: total,
- State: []md.SelectData{
- {Name: "待提交", Value: "0"},
- {Name: "待审核", Value: "1"},
- {Name: "审核通过", Value: "2"},
- {Name: "审核拒绝", Value: "3"},
- },
- }
- e.OutSuc(c, res, nil)
- return
- }
- func MediumBindAgentSave(c *gin.Context) {
- var req md.MediumListSaveReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- agentDb := implement2.NewAgentDb(MasterDb(c))
- username, _ := agentDb.GetSuperAgentByUsername(req.Username)
- if username == nil {
- e.OutErr(c, 400, e.NewErr(400, "渠道代理不存在"))
- return
- }
- mediumDb := implement.NewAgentWithMediumDb(db.Db)
- data := mediumDb.GetAgentWithMediumByMediumIdAndAgentId(utils.StrToInt(req.MediumId), username.AgentId)
- if data != nil {
- e.OutErr(c, 400, e.NewErr(400, "已绑定过该渠道代理"))
- return
- }
- var tmp = model.AgentWithMedium{
- AgentId: username.AgentId,
- MediumId: utils.StrToInt(req.MediumId),
- CreateAt: time.Now(),
- UpdateAt: time.Now(),
- }
- db.Db.InsertOne(&tmp)
- e.OutSuc(c, "success", nil)
- return
- }
- func MediumBindAgentDel(c *gin.Context) {
- var req md.MediumListDelReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- db.Db.In("id", strings.Split(req.Id, ",")).Delete(&model.AgentWithMedium{})
- e.OutSuc(c, "success", nil)
- return
- }
|