广告平台(站长使用)
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
3 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
1 month ago
3 months ago
1 month ago
3 months ago
1 month ago
3 months ago
1 month ago
3 months ago
2 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
1 month ago
3 months ago
2 months ago
3 months ago
1 month ago
3 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. MasterDb(c).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 ?", "%"+name+"%")
  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. }