diff --git a/app/hdl/hdl_data_center_generate_data.go b/app/hdl/hdl_data_center_generate_data.go index 0638ffa..89024fe 100644 --- a/app/hdl/hdl_data_center_generate_data.go +++ b/app/hdl/hdl_data_center_generate_data.go @@ -58,6 +58,18 @@ func IncomeDataList(c *gin.Context) { e.OutSuc(c, res, nil) return } +func IncomeDataListOutPut(c *gin.Context) { + var req md.DataCenterGenerateDataReq + err := c.ShouldBindJSON(&req) + if err != nil { + err = validate.HandleValidateErr(err) + err1 := err.(e.E) + e.OutErr(c, err1.Code, err1.Error()) + return + } + svc.DataCenterIncomeDataListOutput(c, req) + +} // IncomeDataDetail // @Summary 收益报表-详情 diff --git a/app/hdl/hdl_index.go b/app/hdl/hdl_index.go index fb586b6..95286af 100644 --- a/app/hdl/hdl_index.go +++ b/app/hdl/hdl_index.go @@ -26,12 +26,17 @@ func Base(c *gin.Context) { res := map[string]string{ "account_id": utils.IntToStr(user.AdmId), "name": name, + "is_super": "0", "account": user.Username, "logo": "", + "memo": user.Memo, "label": "", "seo_logo": "", "seo_title": "", } + if user.IsSuperAdministrator == 1 { + res["is_super"] = "1" + } NewAdminRoleDb := implement.NewAdminRoleDb(svc.MasterDb(c)) role, _ := NewAdminRoleDb.GetAdminRoleByAdminId(user.AdmId) if role != nil { diff --git a/app/hdl/hdl_role.go b/app/hdl/hdl_role.go index 4ab445f..a4c1e3b 100644 --- a/app/hdl/hdl_role.go +++ b/app/hdl/hdl_role.go @@ -10,6 +10,7 @@ import ( db "code.fnuoos.com/zhimeng/model.git/src" "code.fnuoos.com/zhimeng/model.git/src/implement" "code.fnuoos.com/zhimeng/model.git/src/model" + implement2 "code.fnuoos.com/zhimeng/model.git/src/super/implement" "github.com/gin-gonic/gin" "time" ) @@ -655,3 +656,85 @@ func AdminInfo(c *gin.Context) { }, nil) return } +func RoleMediumList(c *gin.Context) { + var req md.AdminBindMediumListReq + err := c.ShouldBindJSON(&req) + if err != nil { + err = validate.HandleValidateErr(err) + err1 := err.(e.E) + e.OutErr(c, err1.Code, err1.Error()) + return + } + engine := svc.MasterDb(c) + NewMediumDb := implement.NewMediumDb(engine) + appId := svc.GetMediumIdStr(c, 0, req.Name, req.Account) + list, total, _ := NewMediumDb.FindSuperAdminByMediumId(appId, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) + data := make([]md.AdminBindMediumListData, 0) + if len(list) > 0 { + for _, v := range list { + var tmp = md.AdminBindMediumListData{ + MediumId: utils.IntToStr(v.MediumId), + Name: v.Memo, + IsBind: "0", + Account: v.Username, + } + NewMediumListDb := implement2.NewMediumListDb(db.Db) + GetMediumList, _ := NewMediumListDb.GetMediumList(v.MediumId) + if GetMediumList != nil { + tmp.Name = GetMediumList.CompanyName + if GetMediumList.CompanyAbbreviation != "" { + tmp.Name = GetMediumList.CompanyAbbreviation + } + } + count, _ := engine.Where("medium_id=? and admin_id=?", v.MediumId, req.AdminId).Count(&model.AdminBindMedium{}) + if count > 0 { + tmp.IsBind = "1" + } + data = append(data, tmp) + } + } + res := md.AdminBindMediumListRes{ + List: data, + Total: total, + } + e.OutSuc(c, res, nil) + return +} +func RoleBindMedium(c *gin.Context) { + var req md.AdminBindMediumListSaveReq + err := c.ShouldBindJSON(&req) + if err != nil { + err = validate.HandleValidateErr(err) + err1 := err.(e.E) + e.OutErr(c, err1.Code, err1.Error()) + return + } + NewAdminBindMediumDb := implement.NewAdminBindMediumDb(svc.MasterDb(c)) + data := NewAdminBindMediumDb.GetAdminByMediumId(utils.StrToInt(req.AdminId), utils.StrToInt(req.MediumId)) + if data != nil { + e.OutErr(c, 400, e.NewErr(400, "已绑定该媒体")) + return + } + tmp := model.AdminBindMedium{ + AdminId: utils.StrToInt(req.AdminId), + MediumId: utils.StrToInt(req.MediumId), + CreateAt: time.Now(), + UpdateAt: time.Now(), + } + svc.MasterDb(c).Insert(&tmp) + e.OutSuc(c, "success", nil) + return +} +func RoleDelMedium(c *gin.Context) { + var req md.AdminBindMediumListSaveReq + err := c.ShouldBindJSON(&req) + if err != nil { + err = validate.HandleValidateErr(err) + err1 := err.(e.E) + e.OutErr(c, err1.Code, err1.Error()) + return + } + svc.MasterDb(c).Where("medium_id=? and admin_id=?", req.MediumId, req.AdminId).Delete(&model.AdminBindMedium{}) + e.OutSuc(c, "success", nil) + return +} diff --git a/app/md/admin.go b/app/md/admin.go new file mode 100644 index 0000000..554d0af --- /dev/null +++ b/app/md/admin.go @@ -0,0 +1,24 @@ +package md + +type AdminBindMediumListData struct { + MediumId string `json:"medium_id" example:"媒体id"` + Name string `json:"name" example:""` + Account string `json:"account" example:""` + IsBind string `json:"is_bind"` +} +type AdminBindMediumListRes struct { + List []AdminBindMediumListData `json:"list"` + Total int64 `json:"total"` +} + +type AdminBindMediumListSaveReq struct { + MediumId string `json:"medium_id"` + AdminId string `json:"admin_id"` +} +type AdminBindMediumListReq struct { + Limit string `json:"limit"` + Page string `json:"page" ` + Name string `json:"name" example:"媒体名称"` + Account string `json:"account" example:"媒体账号"` + AdminId string `json:"admin_id"` +} diff --git a/app/md/md_data_center_original_data.go b/app/md/md_data_center_original_data.go index fe85d99..49f33dc 100644 --- a/app/md/md_data_center_original_data.go +++ b/app/md/md_data_center_original_data.go @@ -10,6 +10,7 @@ var AdState = []SelectData{ var AdPlatform = []SelectData{ {Name: "微信小程序", Value: "wx_applet"}, } +var AdPlatformMap = map[string]string{"wx_applet": "微信小程序"} type DataCenterOriginalDataReq struct { Limit string `json:"limit"` diff --git a/app/router/router.go b/app/router/router.go index 08d1216..13fe0ec 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -135,6 +135,9 @@ func rRole(r *gin.RouterGroup) { r.DELETE("/deleteAdmin/:adm_id", hdl.DeleteAdmin) // 删除管理员 r.GET("/adminInfo", hdl.AdminInfo) // 获取管理员信息 r.POST("/bindAdminRole", hdl.BindAdminRole) // 绑定角色 + r.POST("/mediumList", hdl.RoleMediumList) // 管理员列表-媒体列表 + r.POST("/bindMedium", hdl.RoleBindMedium) // 管理员列表-关联媒体 + r.POST("/mediumDel", hdl.RoleDelMedium) // 管理员列表-删除关联媒体 } func rAgentQualification(r *gin.RouterGroup) { @@ -238,12 +241,13 @@ func rDataCenter(r *gin.RouterGroup) { r.POST("/original/data/one/application/doing", hdl.OriginalDataOneApplicationDoing) // 数据中心-原始数据-单个应用数据操作 r.GET("/original/data/one/application/state", hdl.OriginalDataOneApplicationState) // 数据中心-原始数据-单个应用数据操作后的完成状态 - r.POST("/generate/data/list", hdl.GenerateDataList) // 数据中心-分成数据 - r.POST("/generate/data/del", hdl.GenerateDataDel) // 数据中心-分成数据-删除 - r.POST("/generate/data/detail", hdl.GenerateDataDetail) // 数据中心-分成数据-详情 - r.POST("/generate/data/doing", hdl.GenerateDataDoing) // 数据中心-分成数据-报表生成操作 - r.POST("/income/data/list", hdl.IncomeDataList) // 数据中心-收益报表 - r.POST("/income/data/detail", hdl.IncomeDataDetail) // 数据中心-收益报表-详情 + r.POST("/generate/data/list", hdl.GenerateDataList) // 数据中心-分成数据 + r.POST("/generate/data/del", hdl.GenerateDataDel) // 数据中心-分成数据-删除 + r.POST("/generate/data/detail", hdl.GenerateDataDetail) // 数据中心-分成数据-详情 + r.POST("/generate/data/doing", hdl.GenerateDataDoing) // 数据中心-分成数据-报表生成操作 + r.POST("/income/data/list", hdl.IncomeDataList) // 数据中心-收益报表 + r.POST("/income/data/list/output", hdl.IncomeDataListOutPut) // 数据中心-收益报表 + r.POST("/income/data/detail", hdl.IncomeDataDetail) // 数据中心-收益报表-详情 } diff --git a/app/svc/svc_applet_application.go b/app/svc/svc_applet_application.go index 87a6423..af2cb2f 100644 --- a/app/svc/svc_applet_application.go +++ b/app/svc/svc_applet_application.go @@ -27,8 +27,10 @@ func AppletApplicationMediumList(c *gin.Context) { } engine := MasterDb(c) NewMediumDb := implement.NewMediumDb(engine) + user := GetUser(c) + appId := GetMediumIdStr(c, user.AdmId, req.Name, req.Account) - list, total, _ := NewMediumDb.FindSuperAdmin(req.Account, req.Name, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) + list, total, _ := NewMediumDb.FindSuperAdminByMediumId(appId, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) data := make([]md.AppletApplicationMediumListData, 0) if len(list) > 0 { for _, v := range list { @@ -47,6 +49,14 @@ func AppletApplicationMediumList(c *gin.Context) { tmp.ContactName = infoList.Name tmp.Phone = infoList.Phone } + NewMediumListDb := implement2.NewMediumListDb(db.Db) + GetMediumList, _ := NewMediumListDb.GetMediumList(v.MediumId) + if GetMediumList != nil { + tmp.Name = GetMediumList.CompanyName + if GetMediumList.CompanyAbbreviation != "" { + tmp.Name = GetMediumList.CompanyAbbreviation + } + } count, _ := engine.Where("medium_id=?", v.MediumId).Count(&model.AppletApplication{}) tmp.Count = utils.Int64ToStr(count) data = append(data, tmp) diff --git a/app/svc/svc_applet_application_ad_space.go b/app/svc/svc_applet_application_ad_space.go index 0c3a375..180003c 100644 --- a/app/svc/svc_applet_application_ad_space.go +++ b/app/svc/svc_applet_application_ad_space.go @@ -26,8 +26,10 @@ func AppletApplicationAdSpaceMediumList(c *gin.Context) { } engine := MasterDb(c) NewMediumDb := implement.NewMediumDb(engine) + user := GetUser(c) + appId := GetMediumIdStr(c, user.AdmId, req.Name, req.Account) - list, total, _ := NewMediumDb.FindSuperAdmin(req.Account, req.Name, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) + list, total, _ := NewMediumDb.FindSuperAdminByMediumId(appId, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) data := make([]md.AppletApplicationAdSpaceMediumListData, 0) if len(list) > 0 { for _, v := range list { @@ -46,6 +48,14 @@ func AppletApplicationAdSpaceMediumList(c *gin.Context) { tmp.ContactName = infoList.Name tmp.Phone = infoList.Phone } + NewMediumListDb := implement2.NewMediumListDb(db.Db) + GetMediumList, _ := NewMediumListDb.GetMediumList(v.MediumId) + if GetMediumList != nil { + tmp.Name = GetMediumList.CompanyName + if GetMediumList.CompanyAbbreviation != "" { + tmp.Name = GetMediumList.CompanyAbbreviation + } + } count, _ := engine.Where("medium_id=?", v.MediumId).Count(&model.AppletApplicationAdSpaceList{}) tmp.Count = utils.Int64ToStr(count) data = append(data, tmp) diff --git a/app/svc/svc_data_center_generate_data.go b/app/svc/svc_data_center_generate_data.go index c75c451..7076b0e 100644 --- a/app/svc/svc_data_center_generate_data.go +++ b/app/svc/svc_data_center_generate_data.go @@ -17,9 +17,11 @@ import ( func DataCenterIncomeDataList(c *gin.Context, req md.DataCenterGenerateDataReq) md.DataCenterIncomeDataRes { engine := db.Db NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(engine) + user := GetUser(c) appId := GetAppletId(c, req.Name, req.Platform) + mediumId := GetMediumIdStr(c, user.AdmId, "", "") slotId := GetSlotId(c, req.State) - MediumList, total, _ := NewGenerateWxAdDataDb.FindGenerateWxAdDataListMedium(c.GetString("mid"), appId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) + MediumList, total, _ := NewGenerateWxAdDataDb.FindGenerateWxAdDataListMedium(c.GetString("mid"), appId, mediumId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) data := make([]md.DataCenterIncomeDataData, 0) if len(MediumList) > 0 { for _, v := range MediumList { @@ -60,6 +62,82 @@ func DataCenterIncomeDataList(c *gin.Context, req md.DataCenterGenerateDataReq) } return res } +func DataCenterIncomeDataListOutput(c *gin.Context, req md.DataCenterGenerateDataReq) { + engine := db.Db + NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(engine) + user := GetUser(c) + appId := GetAppletId(c, req.Name, req.Platform) + mediumId := GetMediumIdStr(c, user.AdmId, "", "") + slotId := GetSlotId(c, req.State) + req.Limit = "3000" + MediumList, _ := NewGenerateWxAdDataDb.FindGenerateWxAdDataListMediumAll(c.GetString("mid"), appId, mediumId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) + data := map[string]string{ + "A1": "名称", + "B1": "日期", + "C1": "广告位", + "D1": "曝光量", + "E1": "点击率(%)", + "F1": "点击量", + "G1": "结算平台", + "H1": "媒体-ECPM", + "I1": "媒体收益(元)", + "J1": "代理收益(元)", + "K1": "平台收益(元)", + } + name := "运营报表第" + req.Page + "页" + + if len(MediumList) > 0 { + for k, v := range MediumList { + var tmp = md.DataCenterIncomeDataData{ + AgreementSharing: utils.Float64ToStr(float64(v.AgreementSharing) / 100), + AgentRevenue: utils.Float64ToStr(float64(v.AgentRevenue) / 100), + Id: utils.IntToStr(v.Id), + ExposureCount: utils.IntToStr(v.ExposureCount), + ClickCount: utils.IntToStr(v.ClickCount), + ClickRate: v.ClickRate, + Ecpm: utils.Float64ToStr(utils.StrToFloat64(v.Ecpm) / 100), + Date: v.Date, + MediaRevenue: utils.Float64ToStr(float64(v.MediaRevenue) / 100), + SettleAmount: utils.Float64ToStr(float64(v.MediaRevenue+v.AgentRevenue+v.AgreementSharing) / 100), + } + tmpApplet := GetAppletInfo(c, v.AppId) + if tmpApplet["platform"] != "" { + tmp.Platform = md.AdPlatformMap[tmpApplet["platform"]] + } + if tmpApplet["name"] != "" { + tmp.Name = tmpApplet["name"] + } + tmpSlot := GetSlotInfo(c, v.SlotId) + if tmpSlot["state"] != "" { + tmp.State = tmpSlot["state"] + } + if tmpSlot["name"] != "" { + tmp.AdvName = tmpSlot["name"] + } + i := utils.IntToStr(k + 2) + data["A"+i] = tmp.Name + data["B"+i] = tmp.Date + data["C"+i] = tmp.AdvName + data["D"+i] = tmp.ExposureCount + data["E"+i] = tmp.ClickRate + data["F"+i] = tmp.ClickCount + data["G"+i] = tmp.Platform + data["H"+i] = tmp.Ecpm + data["I"+i] = tmp.MediaRevenue + data["J"+i] = tmp.AgentRevenue + data["K"+i] = tmp.AgreementSharing + } + } + + file := utils.Output(c, name, data) + filename := name + ".xlsx" + r := map[string]string{ + "file": file, + "filename": filename, + } + e.OutSuc(c, r, nil) + return +} func DataCenterIncomeDataDetail(c *gin.Context, req md.DataCenterGenerateDataCommReq) { NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(db.Db) data, _ := NewGenerateWxAdDataDb.GetGenerateWxAdData(utils.StrToInt(req.Id)) @@ -120,9 +198,11 @@ func DataCenterIncomeDataDetail(c *gin.Context, req md.DataCenterGenerateDataCom func DataCenterGenerateDataList(c *gin.Context, req md.DataCenterGenerateDataReq) md.DataCenterGenerateDataRes { engine := db.Db NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(engine) + user := GetUser(c) appId := GetAppletId(c, req.Name, req.Platform) + mediumId := GetMediumIdStr(c, user.AdmId, "", "") slotId := GetSlotId(c, req.State) - MediumList, total, _ := NewGenerateWxAdDataDb.FindGenerateWxAdDataList(c.GetString("mid"), appId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) + MediumList, total, _ := NewGenerateWxAdDataDb.FindGenerateWxAdDataList(c.GetString("mid"), appId, mediumId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) data := make([]md.DataCenterGenerateDataData, 0) if len(MediumList) > 0 { NewOriginalWxAdDataDb := implement.NewOriginalWxAdDataDb(engine) diff --git a/app/svc/svc_data_center_original_data.go b/app/svc/svc_data_center_original_data.go index 347a587..6d62e59 100644 --- a/app/svc/svc_data_center_original_data.go +++ b/app/svc/svc_data_center_original_data.go @@ -21,7 +21,8 @@ import ( func DataCenterOriginalDataList(c *gin.Context, req md.DataCenterOriginalDataReq) md.DataCenterOriginalDataRes { engine := db.Db NewOriginalWxAdDataDb := implement.NewOriginalWxAdDataDb(engine) - appId := GetAppletId(c, req.Name, req.Platform) + user := GetUser(c) + appId := GetAppletIdByAdminId(c, user.AdmId, req.Name, req.Platform) slotId := GetSlotId(c, req.State) MediumList, total, _ := NewOriginalWxAdDataDb.FindOriginalWxAdDataList(c.GetString("mid"), appId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) data := make([]md.DataCenterOriginalDataData, 0) @@ -376,6 +377,34 @@ func GetAppletId(c *gin.Context, name, platform string) string { } return mediumId } +func GetAppletIdByAdminId(c *gin.Context, admId int, name, platform string) string { + appId := GetAppletId(c, name, platform) + appIds := []string{"-1"} + NewAdminBindMediumDb := implement2.NewAdminBindMediumDb(MasterDb(c)) + list := NewAdminBindMediumDb.FindAll(admId) + ids := make([]string, 0) + for _, v := range list { + appIds = append(appIds, utils.IntToStr(v.MediumId)) + ids = append(ids, utils.IntToStr(v.MediumId)) + } + if len(list) == 0 { //为空就查全部 + appIds = []string{} + } + if appId != "" { //不为空就判断 有没有在列表里面 + appIds = []string{"-1"} + ex := strings.Split(appId, ",") + for _, v := range ex { + if utils.InArr(v, ids) || len(list) == 0 { + appIds = append(appIds, v) + } + } + } + str := "" + if len(appIds) > 0 { + str = strings.Join(appIds, ",") + } + return str +} // 广告位 func GetSlotId(c *gin.Context, state string) string { diff --git a/app/svc/svc_medium_agent.go b/app/svc/svc_medium_agent.go index 75b3b85..0d151b7 100644 --- a/app/svc/svc_medium_agent.go +++ b/app/svc/svc_medium_agent.go @@ -190,7 +190,7 @@ func GetMediumByAccountId(c *gin.Context, name, account string) string { if name != "" { sess.And("memo like ?", "%"+name+"%") var tmp1 []model.MediumList - MasterDb(c).Where("company_name like ? or company_abbreviation like ?", "%"+name+"%", "%"+name+"%").Find(&tmp1) + db.Db.Where("company_name like ? or company_abbreviation like ?", "%"+name+"%", "%"+name+"%").Find(&tmp1) for _, v := range tmp1 { ids = append(ids, utils.IntToStr(v.MediumId)) } @@ -299,3 +299,34 @@ func GetAgentInfo(c *gin.Context, mediumId int) map[string]string { } return res } + +func GetMediumIdStr(c *gin.Context, admId int, name, account string) string { + appId := GetMediumByAccountId(c, name, account) + appIds := []string{"-1"} + NewAdminBindMediumDb := implement2.NewAdminBindMediumDb(MasterDb(c)) + list := NewAdminBindMediumDb.FindAll(admId) + ids := make([]string, 0) + for _, v := range list { + appIds = append(appIds, utils.IntToStr(v.MediumId)) + ids = append(ids, utils.IntToStr(v.MediumId)) + } + NewAdminDb := implement2.NewAdminDb(MasterDb(c)) + super, _ := NewAdminDb.GetSuperAdmin() + if admId == 0 || admId == super.AdmId { //为空就查全部 + appIds = []string{} + } + if appId != "" { //不为空就判断 有没有在列表里面 + appIds = []string{"-1"} + ex := strings.Split(appId, ",") + for _, v := range ex { + if utils.InArr(v, ids) || admId == super.AdmId { + appIds = append(appIds, v) + } + } + } + str := "" + if len(appIds) > 0 { + str = strings.Join(appIds, ",") + } + return str +} diff --git a/app/svc/svc_medium_qualification.go b/app/svc/svc_medium_qualification.go index 86aabc9..a2c958e 100644 --- a/app/svc/svc_medium_qualification.go +++ b/app/svc/svc_medium_qualification.go @@ -16,7 +16,9 @@ func MediumQualificationEnterprise(c *gin.Context, minState int, req md.MediumQu engine := db.Db MediumListDb := implement.NewMediumListDb(engine) - MediumList, total, _ := MediumListDb.FindMediumList(c.GetString("mid"), req.Name, req.State, minState, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) + user := GetUser(c) + appIds := GetMediumIdStr(c, user.AdmId, req.Name, "") + MediumList, total, _ := MediumListDb.FindMediumList(c.GetString("mid"), "", appIds, req.State, minState, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) data := make([]md.MediumQualificationEnterpriseData, 0) if len(MediumList) > 0 { NewMediumDb := implement2.NewMediumDb(MasterDb(c)) @@ -92,7 +94,9 @@ func MediumQualificationEnterpriseAudit(c *gin.Context, req md.MediumQualificati func MediumQualificationBank(c *gin.Context, req md.MediumQualificationEnterpriseReq) md.MediumQualificationBankRes { engine := db.Db MediumListDb := implement.NewMediumBankInfoDb(engine) - MediumList, total, _ := MediumListDb.FindMediumBankInfoList(c.GetString("mid"), req.Name, req.State, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) + user := GetUser(c) + appIds := GetMediumIdStr(c, user.AdmId, req.Name, "") + MediumList, total, _ := MediumListDb.FindMediumBankInfoList(c.GetString("mid"), "", appIds, req.State, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) list := make([]md.MediumQualificationBankData, 0) if MediumList != nil { @@ -175,7 +179,9 @@ func MediumQualificationContactInfo(c *gin.Context, req md.MediumQualificationEn engine := db.Db MediumListDb := implement.NewMediumContactInfoDb(engine) - MediumList, total, _ := MediumListDb.FindMediumContactInfoList(c.GetString("mid"), req.Name, req.State, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) + user := GetUser(c) + appIds := GetMediumIdStr(c, user.AdmId, req.Name, "") + MediumList, total, _ := MediumListDb.FindMediumContactInfoList(c.GetString("mid"), "", appIds, req.State, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) list := make([]md.MediumQualificationContactData, 0) if MediumList != nil { diff --git a/app/svc/svc_operator_index.go b/app/svc/svc_operator_index.go index 5663768..00cb3b6 100644 --- a/app/svc/svc_operator_index.go +++ b/app/svc/svc_operator_index.go @@ -166,6 +166,11 @@ func commOperatorTotal(c *gin.Context, startDate, endDate string) []map[string]s if endDate != "" { where += " and date<='" + endDate + "'" } + user := GetUser(c) + appId := GetMediumIdStr(c, user.AdmId, "", "") + if appId != "" { + where += " and medium_id in(" + appId + ")" + } sql = fmt.Sprintf(sql, where) nativeString, _ := db.QueryNativeString(db.Db, sql) if len(nativeString) == 0 { @@ -197,9 +202,10 @@ func commOperatorTotalByApp(c *gin.Context, req md.IndexAppListReq, appId []stri if req.EndDate != "" { where += " and date<='" + req.EndDate + "'" } - if req.Name != "" { - mediumId := GetMediumId(c, req.Name) - where += " and medium_id in(" + mediumId + ")" + user := GetUser(c) + appIds := GetMediumIdStr(c, user.AdmId, req.Name, "") + if appIds != "" { + where += " and medium_id in(" + appIds + ")" } if len(appId) > 0 { where += " and app_id in('" + strings.Join(appId, ",") + "')" diff --git a/app/svc/svc_role.go b/app/svc/svc_role.go index f1fcb22..c805e64 100644 --- a/app/svc/svc_role.go +++ b/app/svc/svc_role.go @@ -9,6 +9,7 @@ import ( "code.fnuoos.com/zhimeng/model.git/src/model" "encoding/json" "errors" + "fmt" "github.com/gin-gonic/gin" "regexp" "strings" @@ -139,7 +140,14 @@ func RoleBindPermissionGroup(c *gin.Context, req md.RoleBindPermissionGroupReq) return } - return session.Commit() + session.Commit() + var data []model.AdminRole + MasterDb(c).Where("role_id=?", role.Id).Find(&data) + for _, v := range data { + rolePermissionKey := fmt.Sprintf(md.AdminRolePermissionKey, c.GetString("mid"), utils.AnyToString(v.AdmId)) + cache.Del(rolePermissionKey) + } + return nil } func BindAdminRole(c *gin.Context, req md.BindAdminRoleReq) (err error) { diff --git a/app/svc/svc_settle_center_medium.go b/app/svc/svc_settle_center_medium.go index f0fe5c1..45a6e45 100644 --- a/app/svc/svc_settle_center_medium.go +++ b/app/svc/svc_settle_center_medium.go @@ -12,7 +12,8 @@ import ( func SettleCenterMediumList(c *gin.Context, req md.SettleCenterDataReq) md.SettleCenterDataRes { engine := db.Db NewOriginalWxAdDataDb := implement.NewMediumListDb(engine) - appId := GetMediumByAccountId(c, req.Name, req.Account) + user := GetUser(c) + appId := GetMediumIdStr(c, user.AdmId, req.Name, req.Account) MediumList, total, _ := NewOriginalWxAdDataDb.FindMediumListBySettleType(c.GetString("mid"), appId, req.State, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) data := make([]md.SettleCenterDataData, 0) if len(MediumList) > 0 { diff --git a/app/utils/xls.go b/app/utils/xls.go new file mode 100644 index 0000000..4b0318a --- /dev/null +++ b/app/utils/xls.go @@ -0,0 +1,36 @@ +package utils + +import ( + "bytes" + "fmt" + "github.com/360EntSecGroup-Skylar/excelize" + "github.com/gin-gonic/gin" + "io/ioutil" +) + +func Output(c *gin.Context, name string, data map[string]string) string { + //创建excel文件 + xlsx := excelize.NewFile() + //创建新表单 + index := xlsx.NewSheet(name) + for k, v := range data { + //设置单元格的值 + xlsx.SetCellValue(name, k, v) + } + //设置默认打开的表单 + xlsx.SetActiveSheet(index) + ////保存文件到指定路径 + //err := xlsx.SaveAs("./" + name + ".xlsx") + //if err != nil { + // log.Fatal(err) + //} + //_ = file.Save(fileName) + c.Header("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name+".xlsx")) + c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") + var buffer bytes.Buffer + _ = xlsx.Write(&buffer) + r := bytes.NewReader(buffer.Bytes()) + fSrc, _ := ioutil.ReadAll(r) + str := "data:application/vnd.ms-excel;base64," + Base64RawStdEncode(string(fSrc)) + return str +} diff --git a/go.mod b/go.mod index 5024e81..e55f39b 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,8 @@ require ( require ( code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240830072333-a1980ffb256e - code.fnuoos.com/zhimeng/model.git v0.0.3-0.20241009095023-24f5079bb959 + code.fnuoos.com/zhimeng/model.git v0.0.3-0.20241025084129-8b263ebe9032 + github.com/360EntSecGroup-Skylar/excelize v1.4.1 github.com/jinzhu/copier v0.4.0 ) @@ -67,6 +68,7 @@ require ( github.com/mattn/go-isatty v0.0.19 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/pelletier/go-toml/v2 v2.0.6 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/streadway/amqp v1.0.0 // indirect