广告平台(站长使用)
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 

223 Zeilen
6.5 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. SettlementType: 1,
  57. CompanyName: "",
  58. CompanyAbbreviation: "",
  59. UnifiedSocialCreditCode: "",
  60. CertificateType: 1,
  61. BusinessLicenseImgUrl: "",
  62. LegalRepresentative: "",
  63. CountryRegionId: 1,
  64. CountryRegion: "",
  65. RegisteredAddressProvinceId: 0,
  66. RegisteredAddressCityId: 0,
  67. RegisteredAddressCountyId: 0,
  68. RegisteredAddress: "",
  69. BusinessLicenseAddress: "",
  70. CertificateValidity: "",
  71. State: 0,
  72. CreateAt: now.Format("2006-01-02 15:04:05"),
  73. UpdateAt: now.Format("2006-01-02 15:04:05"),
  74. }
  75. insertAffected, err := mediumListDb.MediumListInsert(&mediumList)
  76. if err != nil {
  77. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  78. return
  79. }
  80. if insertAffected <= 0 {
  81. e.OutErr(c, e.ERR_DB_ORM, "生成 medium_list 记录失败")
  82. return
  83. }
  84. //3、新增 medium 记录
  85. mediumModel := model2.Medium{
  86. MediumId: utils.StrToInt(mediumId),
  87. Username: req.Phone,
  88. Password: utils.Md5(req.PassWord),
  89. State: 1,
  90. IsSuperAdministrator: 1,
  91. Memo: "",
  92. CreateAt: now.Format("2006-01-02 15:04:05"),
  93. UpdateAt: now.Format("2006-01-02 15:04:05"),
  94. }
  95. insertAffected, err = mediumDb.MediumInsert(&mediumModel)
  96. if err != nil {
  97. return
  98. }
  99. if insertAffected <= 0 {
  100. e.OutErr(c, e.ERR_DB_ORM, "新增 medium 记录失败")
  101. return
  102. }
  103. //4、新增 MediumDivisionStrategy 记录
  104. MediumDivisionStrategyModel := model.MediumDivisionStrategy{
  105. MediumId: utils.StrToInt(mediumId),
  106. Uuid: utils.StrToInt(masterId),
  107. CreateAt: now.Format("2006-01-02 15:04:05"),
  108. UpdateAt: now.Format("2006-01-02 15:04:05"),
  109. }
  110. insertAffected, err = db.Db.Insert(&MediumDivisionStrategyModel)
  111. if err != nil {
  112. return
  113. }
  114. if insertAffected <= 0 {
  115. e.OutErr(c, e.ERR_DB_ORM, "新增 记录失败")
  116. return
  117. }
  118. e.OutSuc(c, "success", nil)
  119. return
  120. }
  121. // RegisterForAgent
  122. // @Summary 渠道代理注册
  123. // @Tags 注册模块
  124. // @Description 注册模块-渠道代理注册
  125. // @Accept json
  126. // @Produce json
  127. // @Param req body md.RegisterForAgentReq true "用户名密码"
  128. // @Success 200 string "success"
  129. // @Failure 400 {object} md.Response "具体错误"
  130. // @Router /api/registerForAgent [post]
  131. func RegisterForAgent(c *gin.Context) {
  132. var req md.RegisterForAgentReq
  133. err := c.ShouldBindJSON(&req)
  134. if err != nil {
  135. err = validate.HandleValidateErr(err)
  136. err1 := err.(e.E)
  137. e.OutErr(c, err1.Code, err1.Error())
  138. return
  139. }
  140. masterId := svc.GetMasterId(c)
  141. engine := db.DBs[masterId]
  142. now := time.Now()
  143. //1、判断当前账号是否已存在
  144. agentDb := implement.NewAgentDb(engine)
  145. agent, err := agentDb.GetAgentByUsername(req.Phone)
  146. if err != nil {
  147. e.OutErr(c, e.ERR_DB_ORM, err)
  148. return
  149. }
  150. if agent != nil {
  151. e.OutErr(c, e.ERR_NO_DATA, "账号已存在!")
  152. return
  153. }
  154. //2、生成 agent_list 记录
  155. agentListDb := implement2.NewAgentListDb(db.Db)
  156. agentId := utils.GenerateUniqueRandomNumbers(8)
  157. agentList := model.AgentList{
  158. Uuid: utils.StrToInt(masterId),
  159. AgentId: utils.StrToInt(agentId),
  160. Kind: 1,
  161. SettlementType: 1,
  162. CompanyName: "",
  163. CompanyAbbreviation: "",
  164. UnifiedSocialCreditCode: "",
  165. CertificateType: 1,
  166. BusinessLicenseImgUrl: "",
  167. LegalRepresentative: "",
  168. CountryRegionId: 1,
  169. CountryRegion: "",
  170. RegisteredAddressProvinceId: 0,
  171. RegisteredAddressCityId: 0,
  172. RegisteredAddressCountyId: 0,
  173. RegisteredAddress: "",
  174. BusinessLicenseAddress: "",
  175. CertificateValidity: "",
  176. State: 0,
  177. CreateAt: now.Format("2006-01-02 15:04:05"),
  178. UpdateAt: now.Format("2006-01-02 15:04:05"),
  179. }
  180. insertAffected, err := agentListDb.AgentListInsert(&agentList)
  181. if err != nil {
  182. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  183. return
  184. }
  185. if insertAffected <= 0 {
  186. e.OutErr(c, e.ERR_DB_ORM, "生成 medium_list 记录失败")
  187. return
  188. }
  189. //3、新增 agent 记录
  190. agentModel := model2.Agent{
  191. AgentId: utils.StrToInt(agentId),
  192. Username: req.Phone,
  193. Password: utils.Md5(req.PassWord),
  194. State: 1,
  195. IsSuperAdministrator: 1,
  196. Memo: "",
  197. CreateAt: now.Format("2006-01-02 15:04:05"),
  198. UpdateAt: now.Format("2006-01-02 15:04:05"),
  199. }
  200. insertAffected, err = agentDb.AgentInsert(&agentModel)
  201. if err != nil {
  202. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  203. return
  204. }
  205. if insertAffected <= 0 {
  206. e.OutErr(c, e.ERR_DB_ORM, "新增 medium 记录失败")
  207. return
  208. }
  209. e.OutSuc(c, "success", nil)
  210. return
  211. }