|
- package hdl
-
- import (
- "applet/app/e"
- "applet/app/lib/validate"
- "applet/app/md"
- "applet/app/svc"
- "applet/app/utils"
- db "code.fnuoos.com/zhimeng/model.git/src"
- "code.fnuoos.com/zhimeng/model.git/src/implement"
- model2 "code.fnuoos.com/zhimeng/model.git/src/model"
- implement2 "code.fnuoos.com/zhimeng/model.git/src/super/implement"
- "code.fnuoos.com/zhimeng/model.git/src/super/model"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- // RegisterForMedium
- // @Summary 媒体注册
- // @Tags 注册模块
- // @Description 注册模块-媒体注册
- // @Accept json
- // @Produce json
- // @Param req body md.RegisterForMediumReq true "用户名密码"
- // @Success 200 string "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/registerForMedium [post]
- func RegisterForMedium(c *gin.Context) {
- var req md.RegisterForMediumReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- masterId := svc.GetMasterId(c)
- engine := db.DBs[masterId]
- now := time.Now()
-
- //1、判断当前账号是否已存在
- mediumDb := implement.NewMediumDb(engine)
- medium, err := mediumDb.GetMediumByUsername(req.Phone)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err)
- return
- }
- if medium != nil {
- e.OutErr(c, e.ERR_NO_DATA, "账号已存在!")
- return
- }
-
- //2、生成 medium_list 记录
- mediumListDb := implement2.NewMediumListDb(db.Db)
- mediumId := utils.GenerateUniqueRandomNumbers(8)
- mediumList := model.MediumList{
- Uuid: utils.StrToInt(masterId),
- MediumId: utils.StrToInt(mediumId),
- Kind: 1,
- SettlementType: 1,
- CompanyName: "",
- CompanyAbbreviation: "",
- UnifiedSocialCreditCode: "",
- CertificateType: 1,
- BusinessLicenseImgUrl: "",
- LegalRepresentative: "",
- CountryRegionId: 1,
- CountryRegion: "",
- RegisteredAddressProvinceId: 0,
- RegisteredAddressCityId: 0,
- RegisteredAddressCountyId: 0,
- RegisteredAddress: "",
- BusinessLicenseAddress: "",
- CertificateValidity: "",
- State: 0,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
- insertAffected, err := mediumListDb.MediumListInsert(&mediumList)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if insertAffected <= 0 {
- e.OutErr(c, e.ERR_DB_ORM, "生成 medium_list 记录失败")
- return
- }
-
- //3、新增 medium 记录
- mediumModel := model2.Medium{
- MediumId: utils.StrToInt(mediumId),
- Username: req.Phone,
- Password: utils.Md5(req.PassWord),
- State: 1,
- IsSuperAdministrator: 1,
- Memo: "",
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
- insertAffected, err = mediumDb.MediumInsert(&mediumModel)
- if err != nil {
- return
- }
- if insertAffected <= 0 {
- e.OutErr(c, e.ERR_DB_ORM, "新增 medium 记录失败")
- return
- }
- //4、新增 MediumDivisionStrategy 记录
- MediumDivisionStrategyModel := model.MediumDivisionStrategy{
- MediumId: utils.StrToInt(mediumId),
- Uuid: utils.StrToInt(masterId),
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
- insertAffected, err = db.Db.Insert(&MediumDivisionStrategyModel)
- if err != nil {
- return
- }
- if insertAffected <= 0 {
- e.OutErr(c, e.ERR_DB_ORM, "新增 记录失败")
- return
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
-
- // RegisterForAgent
- // @Summary 渠道代理注册
- // @Tags 注册模块
- // @Description 注册模块-渠道代理注册
- // @Accept json
- // @Produce json
- // @Param req body md.RegisterForAgentReq true "用户名密码"
- // @Success 200 string "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/registerForAgent [post]
- func RegisterForAgent(c *gin.Context) {
- var req md.RegisterForAgentReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- masterId := svc.GetMasterId(c)
- engine := db.DBs[masterId]
- now := time.Now()
-
- //1、判断当前账号是否已存在
- agentDb := implement.NewAgentDb(engine)
- agent, err := agentDb.GetAgentByUsername(req.Phone)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err)
- return
- }
- if agent != nil {
- e.OutErr(c, e.ERR_NO_DATA, "账号已存在!")
- return
- }
-
- //2、生成 agent_list 记录
- agentListDb := implement2.NewAgentListDb(db.Db)
- agentId := utils.GenerateUniqueRandomNumbers(8)
- agentList := model.AgentList{
- Uuid: utils.StrToInt(masterId),
- AgentId: utils.StrToInt(agentId),
- Kind: 1,
- SettlementType: 1,
- CompanyName: "",
- CompanyAbbreviation: "",
- UnifiedSocialCreditCode: "",
- CertificateType: 1,
- BusinessLicenseImgUrl: "",
- LegalRepresentative: "",
- CountryRegionId: 1,
- CountryRegion: "",
- RegisteredAddressProvinceId: 0,
- RegisteredAddressCityId: 0,
- RegisteredAddressCountyId: 0,
- RegisteredAddress: "",
- BusinessLicenseAddress: "",
- CertificateValidity: "",
- State: 0,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
- insertAffected, err := agentListDb.AgentListInsert(&agentList)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if insertAffected <= 0 {
- e.OutErr(c, e.ERR_DB_ORM, "生成 medium_list 记录失败")
- return
- }
-
- //3、新增 agent 记录
- agentModel := model2.Agent{
- AgentId: utils.StrToInt(agentId),
- Username: req.Phone,
- Password: utils.Md5(req.PassWord),
- State: 1,
- IsSuperAdministrator: 1,
- Memo: "",
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
- insertAffected, err = agentDb.AgentInsert(&agentModel)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if insertAffected <= 0 {
- e.OutErr(c, e.ERR_DB_ORM, "新增 medium 记录失败")
- return
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
|