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

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