广告平台(站长使用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

333 lines
9.8 KiB

  1. package svc
  2. import (
  3. "applet/app/e"
  4. "applet/app/lib/validate"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. db "code.fnuoos.com/zhimeng/model.git/src"
  8. implement2 "code.fnuoos.com/zhimeng/model.git/src/implement"
  9. model2 "code.fnuoos.com/zhimeng/model.git/src/model"
  10. "code.fnuoos.com/zhimeng/model.git/src/super/implement"
  11. "code.fnuoos.com/zhimeng/model.git/src/super/model"
  12. "github.com/gin-gonic/gin"
  13. "strings"
  14. "time"
  15. )
  16. func AgentBindMediumList(c *gin.Context) { //代理 查旗下 媒体
  17. var req md.MediumListReq
  18. err := c.ShouldBindJSON(&req)
  19. if err != nil {
  20. err = validate.HandleValidateErr(err)
  21. err1 := err.(e.E)
  22. e.OutErr(c, err1.Code, err1.Error())
  23. return
  24. }
  25. var tmp model.AgentList
  26. MasterDb(c).Where("id=?", req.Id).Get(&tmp)
  27. engine := db.Db
  28. agentWithMediumDb := implement.NewAgentWithMediumDb(engine)
  29. data, total, _ := agentWithMediumDb.FindAgentWithMediumList(req.Name, req.State, tmp.AgentId, 0, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  30. list := make([]md.MediumListData, 0)
  31. NewMediumDb := implement2.NewMediumDb(MasterDb(c))
  32. if data != nil {
  33. for _, v := range data {
  34. tmp := md.MediumListData{
  35. Id: utils.IntToStr(v.AgentWithMedium.Id),
  36. MediumId: utils.IntToStr(v.AgentWithMedium.MediumId),
  37. CompanyName: v.MediumList.CompanyName,
  38. UnifiedSocialCreditCode: v.MediumList.UnifiedSocialCreditCode,
  39. State: utils.IntToStr(v.MediumList.State),
  40. Memo: v.MediumList.Memo,
  41. LegalRepresentative: v.MediumList.LegalRepresentative,
  42. BusinessLicenseAddress: v.MediumList.BusinessLicenseAddress,
  43. }
  44. medium := NewMediumDb.GetSuperAdmin(v.AgentWithMedium.MediumId)
  45. if medium != nil {
  46. tmp.Account = medium.Username
  47. }
  48. list = append(list, tmp)
  49. }
  50. }
  51. res := md.MediumListRes{
  52. List: list,
  53. Total: total,
  54. State: []md.SelectData{
  55. {Name: "待提交", Value: "0"},
  56. {Name: "待审核", Value: "1"},
  57. {Name: "审核通过", Value: "2"},
  58. {Name: "审核拒绝", Value: "3"},
  59. },
  60. }
  61. e.OutSuc(c, res, nil)
  62. return
  63. }
  64. func MediumBindAgentList(c *gin.Context) {
  65. var req md.MediumListReq
  66. err := c.ShouldBindJSON(&req)
  67. if err != nil {
  68. err = validate.HandleValidateErr(err)
  69. err1 := err.(e.E)
  70. e.OutErr(c, err1.Code, err1.Error())
  71. return
  72. }
  73. var tmp model.MediumList
  74. MasterDb(c).Where("id=?", req.Id).Get(&tmp)
  75. engine := db.Db
  76. agentWithMediumDb := implement.NewAgentWithMediumDb(engine)
  77. data, total, _ := agentWithMediumDb.FindAgentWithMediumList(req.Name, req.State, 0, tmp.MediumId, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  78. list := make([]md.MediumListData, 0)
  79. NewAgentDb := implement2.NewAgentDb(MasterDb(c))
  80. if data != nil {
  81. for _, v := range data {
  82. tmp1 := md.MediumListData{
  83. Id: utils.IntToStr(v.AgentWithMedium.Id),
  84. MediumId: utils.IntToStr(v.AgentWithMedium.AgentId),
  85. CompanyName: v.AgentList.CompanyName,
  86. UnifiedSocialCreditCode: v.AgentList.UnifiedSocialCreditCode,
  87. State: utils.IntToStr(v.AgentList.State),
  88. Memo: v.AgentList.Memo,
  89. LegalRepresentative: v.AgentList.LegalRepresentative,
  90. BusinessLicenseAddress: v.AgentList.BusinessLicenseAddress,
  91. BusinessLicenseImg: v.AgentList.BusinessLicenseImgUrl,
  92. }
  93. agent := NewAgentDb.GetSuperAdmin(v.AgentWithMedium.AgentId)
  94. if agent != nil {
  95. tmp1.Account = agent.Username
  96. }
  97. list = append(list, tmp1)
  98. }
  99. }
  100. res := md.MediumListRes{
  101. List: list,
  102. Total: total,
  103. State: []md.SelectData{
  104. {Name: "待提交", Value: "0"},
  105. {Name: "待审核", Value: "1"},
  106. {Name: "审核通过", Value: "2"},
  107. {Name: "审核拒绝", Value: "3"},
  108. },
  109. }
  110. e.OutSuc(c, res, nil)
  111. return
  112. }
  113. func MediumBindAgentSave(c *gin.Context) {
  114. var req md.MediumListSaveReq
  115. err := c.ShouldBindJSON(&req)
  116. if err != nil {
  117. err = validate.HandleValidateErr(err)
  118. err1 := err.(e.E)
  119. e.OutErr(c, err1.Code, err1.Error())
  120. return
  121. }
  122. agentDb := implement2.NewAgentDb(MasterDb(c))
  123. req.Username = strings.ReplaceAll(req.Username, " ", "")
  124. username, _ := agentDb.GetAgent(utils.StrToInt(req.Username))
  125. if username == nil {
  126. e.OutErr(c, 400, e.NewErr(400, "渠道代理不存在"))
  127. return
  128. }
  129. mediumDb := implement.NewAgentWithMediumDb(db.Db)
  130. data := mediumDb.GetAgentWithMediumByMediumIdAndAgentId(utils.StrToInt(req.MediumId), username.AgentId)
  131. if data != nil {
  132. e.OutErr(c, 400, e.NewErr(400, "已绑定过该渠道代理"))
  133. return
  134. }
  135. var tmp = model.AgentWithMedium{
  136. AgentId: username.AgentId,
  137. MediumId: utils.StrToInt(req.MediumId),
  138. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  139. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  140. }
  141. db.Db.InsertOne(&tmp)
  142. e.OutSuc(c, "success", nil)
  143. return
  144. }
  145. func MediumBindAgentDel(c *gin.Context) {
  146. var req md.MediumListDelReq
  147. err := c.ShouldBindJSON(&req)
  148. if err != nil {
  149. err = validate.HandleValidateErr(err)
  150. err1 := err.(e.E)
  151. e.OutErr(c, err1.Code, err1.Error())
  152. return
  153. }
  154. db.Db.In("id", strings.Split(req.Id, ",")).Delete(&model.AgentWithMedium{})
  155. e.OutSuc(c, "success", nil)
  156. return
  157. }
  158. func GetMediumId(c *gin.Context, name string) string {
  159. mediumId := ""
  160. if name != "" {
  161. ids := []string{"-1"}
  162. var tmp []model2.Medium
  163. MasterDb(c).Where("memo like ? or username like ?", "%"+name+"%", "%"+name+"%").Find(&tmp)
  164. for _, v := range tmp {
  165. ids = append(ids, utils.IntToStr(v.MediumId))
  166. }
  167. var tmp1 []model.MediumList
  168. MasterDb(c).Where("company_name like ? or company_abbreviation like ?", "%"+name+"%", "%"+name+"%").Find(&tmp1)
  169. for _, v := range tmp1 {
  170. ids = append(ids, utils.IntToStr(v.MediumId))
  171. }
  172. mediumId = strings.Join(ids, ",")
  173. }
  174. return mediumId
  175. }
  176. func GetMediumByAccountId(c *gin.Context, name, account string) string {
  177. mediumId := ""
  178. if name != "" || account != "" {
  179. ids := []string{"-1"}
  180. var tmp []model2.Medium
  181. sess := MasterDb(c).Where("1=1")
  182. if name != "" {
  183. sess.And("memo like ?", "%"+name+"%")
  184. var tmp1 []model.MediumList
  185. db.Db.Where("company_name like ? or company_abbreviation like ?", "%"+name+"%", "%"+name+"%").Find(&tmp1)
  186. for _, v := range tmp1 {
  187. ids = append(ids, utils.IntToStr(v.MediumId))
  188. }
  189. }
  190. if account != "" {
  191. sess.And(" username like ?", "%"+account+"%")
  192. }
  193. sess.Find(&tmp)
  194. for _, v := range tmp {
  195. ids = append(ids, utils.IntToStr(v.MediumId))
  196. }
  197. mediumId = strings.Join(ids, ",")
  198. }
  199. return mediumId
  200. }
  201. func GetMediumInfo(c *gin.Context, mediumId int) map[string]string {
  202. var res = map[string]string{
  203. "account": "",
  204. "name": "",
  205. }
  206. NewMediumDb := implement2.NewMediumDb(MasterDb(c))
  207. NewMediumListDb := implement.NewMediumListDb(db.Db)
  208. medium := NewMediumDb.GetSuperAdmin(mediumId)
  209. if medium != nil {
  210. res["account"] = medium.Username
  211. res["name"] = medium.Memo
  212. }
  213. NewMediumList, _ := NewMediumListDb.GetMediumList(mediumId)
  214. if NewMediumList != nil {
  215. if NewMediumList.CompanyName != "" {
  216. res["name"] = NewMediumList.CompanyName
  217. }
  218. if NewMediumList.CompanyAbbreviation != "" {
  219. res["name"] = NewMediumList.CompanyAbbreviation
  220. }
  221. }
  222. return res
  223. }
  224. func GetAgentId(c *gin.Context, name string) string {
  225. mediumId := ""
  226. if name != "" {
  227. ids := []string{"-1"}
  228. var tmp []model2.Agent
  229. MasterDb(c).Where("memo like ? or username like ?", "%"+name+"%", "%"+name+"%").Find(&tmp)
  230. for _, v := range tmp {
  231. ids = append(ids, utils.IntToStr(v.AgentId))
  232. }
  233. var tmp1 []model.AgentList
  234. MasterDb(c).Where("company_name like ? or company_abbreviation like ?", "%"+name+"%", "%"+name+"%").Find(&tmp1)
  235. for _, v := range tmp1 {
  236. ids = append(ids, utils.IntToStr(v.AgentId))
  237. }
  238. mediumId = strings.Join(ids, ",")
  239. }
  240. return mediumId
  241. }
  242. func GetAgentByAccountId(c *gin.Context, name, account string) string {
  243. mediumId := ""
  244. if name != "" || account != "" {
  245. ids := []string{"-1"}
  246. var tmp []model2.Agent
  247. sess := MasterDb(c).Where("1=1")
  248. if name != "" {
  249. sess.And("memo like ?", "%"+name+"%")
  250. var tmp1 []model.AgentList
  251. MasterDb(c).Where("company_name like ? or company_abbreviation like ?", "%"+name+"%", "%"+name+"%").Find(&tmp1)
  252. for _, v := range tmp1 {
  253. ids = append(ids, utils.IntToStr(v.AgentId))
  254. }
  255. }
  256. if account != "" {
  257. sess.And(" username like ?", "%"+name+"%", "%"+name+"%")
  258. }
  259. sess.Find(&tmp)
  260. for _, v := range tmp {
  261. ids = append(ids, utils.IntToStr(v.AgentId))
  262. }
  263. mediumId = strings.Join(ids, ",")
  264. }
  265. return mediumId
  266. }
  267. func GetAgentInfo(c *gin.Context, mediumId int) map[string]string {
  268. var res = map[string]string{
  269. "account": "",
  270. "name": "",
  271. }
  272. NewAgentDb := implement2.NewAgentDb(MasterDb(c))
  273. NewAgentListDb := implement.NewAgentListDb(db.Db)
  274. medium := NewAgentDb.GetSuperAdmin(mediumId)
  275. if medium != nil {
  276. res["account"] = medium.Username
  277. res["name"] = medium.Memo
  278. }
  279. NewAgentList, _ := NewAgentListDb.GetAgentList(mediumId)
  280. if NewAgentList != nil {
  281. if NewAgentList.CompanyName != "" {
  282. res["name"] = NewAgentList.CompanyName
  283. }
  284. if NewAgentList.CompanyAbbreviation != "" {
  285. res["name"] = NewAgentList.CompanyAbbreviation
  286. }
  287. }
  288. return res
  289. }
  290. func GetMediumIdStr(c *gin.Context, admId int, name, account string) string {
  291. appId := GetMediumByAccountId(c, name, account)
  292. appIds := []string{"-1"}
  293. NewAdminBindMediumDb := implement2.NewAdminBindMediumDb(MasterDb(c))
  294. list := NewAdminBindMediumDb.FindAll(admId)
  295. ids := make([]string, 0)
  296. for _, v := range list {
  297. appIds = append(appIds, utils.IntToStr(v.MediumId))
  298. ids = append(ids, utils.IntToStr(v.MediumId))
  299. }
  300. NewAdminDb := implement2.NewAdminDb(MasterDb(c))
  301. super, _ := NewAdminDb.GetSuperAdmin()
  302. if admId == 0 || admId == super.AdmId { //为空就查全部
  303. appIds = []string{}
  304. }
  305. if appId != "" { //不为空就判断 有没有在列表里面
  306. appIds = []string{"-1"}
  307. ex := strings.Split(appId, ",")
  308. for _, v := range ex {
  309. if utils.InArr(v, ids) || admId == super.AdmId {
  310. appIds = append(appIds, v)
  311. }
  312. }
  313. }
  314. str := ""
  315. if len(appIds) > 0 {
  316. str = strings.Join(appIds, ",")
  317. }
  318. return str
  319. }