广告平台(站长使用)
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.

svc_medium_agent.go 8.7 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. engine := db.Db
  26. agentWithMediumDb := implement.NewAgentWithMediumDb(engine)
  27. data, total, _ := agentWithMediumDb.FindAgentWithMediumList(req.Name, req.State, utils.StrToInt(req.Id), 0, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  28. list := make([]md.MediumListData, 0)
  29. NewMediumDb := implement2.NewMediumDb(MasterDb(c))
  30. if data != nil {
  31. for _, v := range data {
  32. tmp := md.MediumListData{
  33. Id: utils.IntToStr(v.AgentWithMedium.Id),
  34. MediumId: utils.IntToStr(v.AgentWithMedium.MediumId),
  35. CompanyName: v.MediumList.CompanyName,
  36. UnifiedSocialCreditCode: v.MediumList.UnifiedSocialCreditCode,
  37. State: utils.IntToStr(v.MediumList.State),
  38. Memo: v.MediumList.Memo,
  39. LegalRepresentative: v.MediumList.LegalRepresentative,
  40. BusinessLicenseAddress: v.MediumList.BusinessLicenseAddress,
  41. }
  42. medium := NewMediumDb.GetSuperAdmin(v.AgentWithMedium.MediumId)
  43. if medium != nil {
  44. tmp.Account = medium.Username
  45. }
  46. list = append(list, tmp)
  47. }
  48. }
  49. res := md.MediumListRes{
  50. List: list,
  51. Total: total,
  52. State: []md.SelectData{
  53. {Name: "待提交", Value: "0"},
  54. {Name: "待审核", Value: "1"},
  55. {Name: "审核通过", Value: "2"},
  56. {Name: "审核拒绝", Value: "3"},
  57. },
  58. }
  59. e.OutSuc(c, res, nil)
  60. return
  61. }
  62. func MediumBindAgentList(c *gin.Context) {
  63. var req md.MediumListReq
  64. err := c.ShouldBindJSON(&req)
  65. if err != nil {
  66. err = validate.HandleValidateErr(err)
  67. err1 := err.(e.E)
  68. e.OutErr(c, err1.Code, err1.Error())
  69. return
  70. }
  71. engine := db.Db
  72. agentWithMediumDb := implement.NewAgentWithMediumDb(engine)
  73. data, total, _ := agentWithMediumDb.FindAgentWithMediumList(req.Name, req.State, 0, utils.StrToInt(req.Id), utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  74. list := make([]md.MediumListData, 0)
  75. NewAgentDb := implement2.NewAgentDb(MasterDb(c))
  76. if data != nil {
  77. for _, v := range data {
  78. tmp := md.MediumListData{
  79. Id: utils.IntToStr(v.AgentWithMedium.Id),
  80. MediumId: utils.IntToStr(v.AgentWithMedium.AgentId),
  81. CompanyName: v.AgentList.CompanyName,
  82. UnifiedSocialCreditCode: v.AgentList.UnifiedSocialCreditCode,
  83. State: utils.IntToStr(v.AgentList.State),
  84. Memo: v.AgentList.Memo,
  85. LegalRepresentative: v.AgentList.LegalRepresentative,
  86. BusinessLicenseAddress: v.AgentList.BusinessLicenseAddress,
  87. }
  88. agent := NewAgentDb.GetSuperAdmin(v.AgentWithMedium.AgentId)
  89. if agent != nil {
  90. tmp.Account = agent.Username
  91. }
  92. list = append(list, tmp)
  93. }
  94. }
  95. res := md.MediumListRes{
  96. List: list,
  97. Total: total,
  98. State: []md.SelectData{
  99. {Name: "待提交", Value: "0"},
  100. {Name: "待审核", Value: "1"},
  101. {Name: "审核通过", Value: "2"},
  102. {Name: "审核拒绝", Value: "3"},
  103. },
  104. }
  105. e.OutSuc(c, res, nil)
  106. return
  107. }
  108. func MediumBindAgentSave(c *gin.Context) {
  109. var req md.MediumListSaveReq
  110. err := c.ShouldBindJSON(&req)
  111. if err != nil {
  112. err = validate.HandleValidateErr(err)
  113. err1 := err.(e.E)
  114. e.OutErr(c, err1.Code, err1.Error())
  115. return
  116. }
  117. agentDb := implement2.NewAgentDb(MasterDb(c))
  118. username, _ := agentDb.GetSuperAgentByUsername(req.Username)
  119. if username == nil {
  120. e.OutErr(c, 400, e.NewErr(400, "渠道代理不存在"))
  121. return
  122. }
  123. mediumDb := implement.NewAgentWithMediumDb(db.Db)
  124. data := mediumDb.GetAgentWithMediumByMediumIdAndAgentId(utils.StrToInt(req.MediumId), username.AgentId)
  125. if data != nil {
  126. e.OutErr(c, 400, e.NewErr(400, "已绑定过该渠道代理"))
  127. return
  128. }
  129. var tmp = model.AgentWithMedium{
  130. AgentId: username.AgentId,
  131. MediumId: utils.StrToInt(req.MediumId),
  132. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  133. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  134. }
  135. db.Db.InsertOne(&tmp)
  136. e.OutSuc(c, "success", nil)
  137. return
  138. }
  139. func MediumBindAgentDel(c *gin.Context) {
  140. var req md.MediumListDelReq
  141. err := c.ShouldBindJSON(&req)
  142. if err != nil {
  143. err = validate.HandleValidateErr(err)
  144. err1 := err.(e.E)
  145. e.OutErr(c, err1.Code, err1.Error())
  146. return
  147. }
  148. db.Db.In("id", strings.Split(req.Id, ",")).Delete(&model.AgentWithMedium{})
  149. e.OutSuc(c, "success", nil)
  150. return
  151. }
  152. func GetMediumId(c *gin.Context, name string) string {
  153. mediumId := ""
  154. if name != "" {
  155. ids := []string{"-1"}
  156. var tmp []model2.Medium
  157. MasterDb(c).Where("memo like ? or username like ?", "%"+name+"%", "%"+name+"%").Find(&tmp)
  158. for _, v := range tmp {
  159. ids = append(ids, utils.IntToStr(v.MediumId))
  160. }
  161. var tmp1 []model.MediumList
  162. MasterDb(c).Where("company_name like ? or company_abbreviation like ?", "%"+name+"%", "%"+name+"%").Find(&tmp1)
  163. for _, v := range tmp1 {
  164. ids = append(ids, utils.IntToStr(v.MediumId))
  165. }
  166. mediumId = strings.Join(ids, ",")
  167. }
  168. return mediumId
  169. }
  170. func GetMediumByAccountId(c *gin.Context, name, account string) string {
  171. mediumId := ""
  172. if name != "" || account != "" {
  173. ids := []string{"-1"}
  174. var tmp []model2.Medium
  175. sess := MasterDb(c).Where("1=1")
  176. if name != "" {
  177. sess.And("memo like ?", "%"+name+"%")
  178. var tmp1 []model.MediumList
  179. MasterDb(c).Where("company_name like ? or company_abbreviation like ?", "%"+name+"%", "%"+name+"%").Find(&tmp1)
  180. for _, v := range tmp1 {
  181. ids = append(ids, utils.IntToStr(v.MediumId))
  182. }
  183. }
  184. if account != "" {
  185. sess.And(" username like ?", "%"+name+"%", "%"+name+"%")
  186. }
  187. sess.Find(&tmp)
  188. for _, v := range tmp {
  189. ids = append(ids, utils.IntToStr(v.MediumId))
  190. }
  191. mediumId = strings.Join(ids, ",")
  192. }
  193. return mediumId
  194. }
  195. func GetMediumInfo(c *gin.Context, mediumId int) map[string]string {
  196. var res = map[string]string{
  197. "account": "",
  198. "name": "",
  199. }
  200. NewMediumDb := implement2.NewMediumDb(MasterDb(c))
  201. NewMediumListDb := implement.NewMediumListDb(MasterDb(c))
  202. medium := NewMediumDb.GetSuperAdmin(mediumId)
  203. if medium != nil {
  204. res["account"] = medium.Username
  205. res["name"] = medium.Memo
  206. }
  207. NewMediumList, _ := NewMediumListDb.GetMediumList(mediumId)
  208. if NewMediumList != nil {
  209. if NewMediumList.CompanyName != "" {
  210. res["name"] = NewMediumList.CompanyName
  211. }
  212. if NewMediumList.CompanyAbbreviation != "" {
  213. res["name"] = NewMediumList.CompanyAbbreviation
  214. }
  215. }
  216. return res
  217. }
  218. func GetAgentId(c *gin.Context, name string) string {
  219. mediumId := ""
  220. if name != "" {
  221. ids := []string{"-1"}
  222. var tmp []model2.Agent
  223. MasterDb(c).Where("memo like ? or username like ?", "%"+name+"%", "%"+name+"%").Find(&tmp)
  224. for _, v := range tmp {
  225. ids = append(ids, utils.IntToStr(v.AgentId))
  226. }
  227. var tmp1 []model.AgentList
  228. MasterDb(c).Where("company_name like ? or company_abbreviation like ?", "%"+name+"%", "%"+name+"%").Find(&tmp1)
  229. for _, v := range tmp1 {
  230. ids = append(ids, utils.IntToStr(v.AgentId))
  231. }
  232. mediumId = strings.Join(ids, ",")
  233. }
  234. return mediumId
  235. }
  236. func GetAgentByAccountId(c *gin.Context, name, account string) string {
  237. mediumId := ""
  238. if name != "" || account != "" {
  239. ids := []string{"-1"}
  240. var tmp []model2.Agent
  241. sess := MasterDb(c).Where("1=1")
  242. if name != "" {
  243. sess.And("memo like ?", "%"+name+"%")
  244. var tmp1 []model.AgentList
  245. MasterDb(c).Where("company_name like ? or company_abbreviation like ?", "%"+name+"%", "%"+name+"%").Find(&tmp1)
  246. for _, v := range tmp1 {
  247. ids = append(ids, utils.IntToStr(v.AgentId))
  248. }
  249. }
  250. if account != "" {
  251. sess.And(" username like ?", "%"+name+"%", "%"+name+"%")
  252. }
  253. sess.Find(&tmp)
  254. for _, v := range tmp {
  255. ids = append(ids, utils.IntToStr(v.AgentId))
  256. }
  257. mediumId = strings.Join(ids, ",")
  258. }
  259. return mediumId
  260. }
  261. func GetAgentInfo(c *gin.Context, mediumId int) map[string]string {
  262. var res = map[string]string{
  263. "account": "",
  264. "name": "",
  265. }
  266. NewAgentDb := implement2.NewAgentDb(MasterDb(c))
  267. NewAgentListDb := implement.NewAgentListDb(MasterDb(c))
  268. medium := NewAgentDb.GetSuperAdmin(mediumId)
  269. if medium != nil {
  270. res["account"] = medium.Username
  271. res["name"] = medium.Memo
  272. }
  273. NewAgentList, _ := NewAgentListDb.GetAgentList(mediumId)
  274. if NewAgentList != nil {
  275. if NewAgentList.CompanyName != "" {
  276. res["name"] = NewAgentList.CompanyName
  277. }
  278. if NewAgentList.CompanyAbbreviation != "" {
  279. res["name"] = NewAgentList.CompanyAbbreviation
  280. }
  281. }
  282. return res
  283. }