广告平台(站长使用)
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

206 lignes
6.0 KiB

  1. package hdl
  2. import (
  3. "applet/app/e"
  4. "applet/app/lib/validate"
  5. "applet/app/md"
  6. "applet/app/svc"
  7. "applet/app/utils"
  8. db "code.fnuoos.com/zhimeng/model.git/src"
  9. "code.fnuoos.com/zhimeng/model.git/src/implement"
  10. model2 "code.fnuoos.com/zhimeng/model.git/src/model"
  11. implement2 "code.fnuoos.com/zhimeng/model.git/src/super/implement"
  12. "code.fnuoos.com/zhimeng/model.git/src/super/model"
  13. "github.com/gin-gonic/gin"
  14. "time"
  15. )
  16. // RegisterForMedium
  17. // @Summary 媒体注册
  18. // @Tags 注册模块
  19. // @Description 注册模块-媒体注册
  20. // @Accept json
  21. // @Produce json
  22. // @Param req body md.RegisterForMediumReq true "用户名密码"
  23. // @Success 200 string "success"
  24. // @Failure 400 {object} md.Response "具体错误"
  25. // @Router /api/registerForMedium [post]
  26. func RegisterForMedium(c *gin.Context) {
  27. var req md.RegisterForMediumReq
  28. err := c.ShouldBindJSON(&req)
  29. if err != nil {
  30. err = validate.HandleValidateErr(err)
  31. err1 := err.(e.E)
  32. e.OutErr(c, err1.Code, err1.Error())
  33. return
  34. }
  35. masterId := svc.GetMasterId(c)
  36. engine := db.DBs[masterId]
  37. now := time.Now()
  38. //1、判断当前账号是否已存在
  39. mediumDb := implement.NewMediumDb(engine)
  40. medium, err := mediumDb.GetMediumByUsername(req.Phone)
  41. if err != nil {
  42. e.OutErr(c, e.ERR_DB_ORM, err)
  43. return
  44. }
  45. if medium != nil {
  46. e.OutErr(c, e.ERR_NO_DATA, "账号已存在!")
  47. return
  48. }
  49. //2、生成 medium_list 记录
  50. mediumListDb := implement2.NewMediumListDb(db.Db)
  51. mediumId := utils.GenerateUniqueRandomNumbers(8)
  52. mediumList := model.MediumList{
  53. Uuid: utils.StrToInt(masterId),
  54. MediumId: utils.StrToInt(mediumId),
  55. Kind: 1,
  56. CompanyName: "",
  57. CompanyAbbreviation: "",
  58. UnifiedSocialCreditCode: "",
  59. CertificateType: 1,
  60. BusinessLicenseImgUrl: "",
  61. LegalRepresentative: "",
  62. CountryRegionId: 1,
  63. CountryRegion: "",
  64. RegisteredAddressProvinceId: 0,
  65. RegisteredAddressCityId: 0,
  66. RegisteredAddressCountyId: 0,
  67. RegisteredAddress: "",
  68. BusinessLicenseAddress: "",
  69. CertificateValidity: "",
  70. State: 0,
  71. CreateAt: now.Format("2006-01-02 15:04:05"),
  72. UpdateAt: now.Format("2006-01-02 15:04:05"),
  73. }
  74. insertAffected, err := mediumListDb.MediumListInsert(&mediumList)
  75. if err != nil {
  76. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  77. return
  78. }
  79. if insertAffected <= 0 {
  80. e.OutErr(c, e.ERR_DB_ORM, "生成 medium_list 记录失败")
  81. return
  82. }
  83. //3、新增 medium 记录
  84. mediumModel := model2.Medium{
  85. MediumId: utils.StrToInt(mediumId),
  86. Username: req.Phone,
  87. Password: utils.Md5(req.PassWord),
  88. State: 1,
  89. IsSuperAdministrator: 1,
  90. Memo: "",
  91. CreateAt: now.Format("2006-01-02 15:04:05"),
  92. UpdateAt: now.Format("2006-01-02 15:04:05"),
  93. }
  94. insertAffected, err = mediumDb.MediumInsert(&mediumModel)
  95. if err != nil {
  96. return
  97. }
  98. if insertAffected <= 0 {
  99. e.OutErr(c, e.ERR_DB_ORM, "新增 medium 记录失败")
  100. return
  101. }
  102. e.OutSuc(c, "success", nil)
  103. return
  104. }
  105. // RegisterForAgent
  106. // @Summary 渠道代理注册
  107. // @Tags 注册模块
  108. // @Description 注册模块-渠道代理注册
  109. // @Accept json
  110. // @Produce json
  111. // @Param req body md.RegisterForAgentReq true "用户名密码"
  112. // @Success 200 string "success"
  113. // @Failure 400 {object} md.Response "具体错误"
  114. // @Router /api/registerForAgent [post]
  115. func RegisterForAgent(c *gin.Context) {
  116. var req md.RegisterForAgentReq
  117. err := c.ShouldBindJSON(&req)
  118. if err != nil {
  119. err = validate.HandleValidateErr(err)
  120. err1 := err.(e.E)
  121. e.OutErr(c, err1.Code, err1.Error())
  122. return
  123. }
  124. masterId := svc.GetMasterId(c)
  125. engine := db.DBs[masterId]
  126. now := time.Now()
  127. //1、判断当前账号是否已存在
  128. agentDb := implement.NewAgentDb(engine)
  129. agent, err := agentDb.GetAgentByUsername(req.Phone)
  130. if err != nil {
  131. e.OutErr(c, e.ERR_DB_ORM, err)
  132. return
  133. }
  134. if agent != nil {
  135. e.OutErr(c, e.ERR_NO_DATA, "账号已存在!")
  136. return
  137. }
  138. //2、生成 agent_list 记录
  139. agentListDb := implement2.NewAgentListDb(db.Db)
  140. agentId := utils.GenerateUniqueRandomNumbers(8)
  141. agentList := model.AgentList{
  142. Uuid: utils.StrToInt(masterId),
  143. AgentId: utils.StrToInt(agentId),
  144. Kind: 1,
  145. CompanyName: "",
  146. CompanyAbbreviation: "",
  147. UnifiedSocialCreditCode: "",
  148. CertificateType: 1,
  149. BusinessLicenseImgUrl: "",
  150. LegalRepresentative: "",
  151. CountryRegionId: 1,
  152. CountryRegion: "",
  153. RegisteredAddressProvinceId: 0,
  154. RegisteredAddressCityId: 0,
  155. RegisteredAddressCountyId: 0,
  156. RegisteredAddress: "",
  157. BusinessLicenseAddress: "",
  158. CertificateValidity: "",
  159. State: 0,
  160. CreateAt: now.Format("2006-01-02 15:04:05"),
  161. UpdateAt: now.Format("2006-01-02 15:04:05"),
  162. }
  163. insertAffected, err := agentListDb.AgentListInsert(&agentList)
  164. if err != nil {
  165. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  166. return
  167. }
  168. if insertAffected <= 0 {
  169. e.OutErr(c, e.ERR_DB_ORM, "生成 medium_list 记录失败")
  170. return
  171. }
  172. //3、新增 agent 记录
  173. agentModel := model2.Agent{
  174. AgentId: utils.StrToInt(agentId),
  175. Username: req.Phone,
  176. Password: utils.Md5(req.PassWord),
  177. State: 1,
  178. IsSuperAdministrator: 1,
  179. Memo: "",
  180. CreateAt: now.Format("2006-01-02 15:04:05"),
  181. UpdateAt: now.Format("2006-01-02 15:04:05"),
  182. }
  183. insertAffected, err = agentDb.AgentInsert(&agentModel)
  184. if err != nil {
  185. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  186. return
  187. }
  188. if insertAffected <= 0 {
  189. e.OutErr(c, e.ERR_DB_ORM, "新增 medium 记录失败")
  190. return
  191. }
  192. e.OutSuc(c, "success", nil)
  193. return
  194. }