diff --git a/app/hdl/hdl_login.go b/app/hdl/hdl_login.go index fb12ba0..70b4db4 100644 --- a/app/hdl/hdl_login.go +++ b/app/hdl/hdl_login.go @@ -117,7 +117,7 @@ func LoginPhone(c *gin.Context) { // @Description 手机号注册 // @Accept json // @Produce json -// @Param req body md.LoginReq true "用户名、验证码" +// @Param req body md.RegisterReq true "用户名、验证码" // @Success 200 {object} md.LoginResponse "token" // @Failure 400 {object} md.Response "具体错误" // @Router /api/register [post] @@ -210,26 +210,40 @@ func Register(c *gin.Context) { } insertAffected, err = db.Db.Insert(&MediumDivisionStrategyModel) if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if insertAffected <= 0 { e.OutErr(c, e.ERR_DB_ORM, "新增 记录失败") return } - if utils.StrToInt(req.AgentId) > 0 { - NewAgentWithMediumDb := implement2.NewAgentWithMediumDb(db.Db) - data := NewAgentWithMediumDb.GetAgentWithMediumByMediumIdAndAgentId(utils.StrToInt(mediumId), utils.StrToInt(req.AgentId)) - if data != nil { - e.OutErr(c, 400, e.NewErr(400, "已绑定过该渠道代理")) + + //5、判断是否为渠道代理邀请 + if req.AgentId != "" { + agentDb := implement.NewAgentDb(engine) + agent, err1 := agentDb.GetAgent(utils.StrToInt(req.AgentId)) + if err1 != nil { + e.OutErr(c, e.ERR_DB_ORM, err1.Error()) return } - var tmp = model.AgentWithMedium{ - AgentId: utils.StrToInt(req.AgentId), - MediumId: utils.StrToInt(mediumId), - CreateAt: time.Now().Format("2006-01-02 15:04:05"), - UpdateAt: time.Now().Format("2006-01-02 15:04:05"), + if agent != nil { + //5.1 新增agent_with_medium记录 + agentWithMediumDb := implement2.NewAgentWithMediumDb(engine) + insertAffected, err = agentWithMediumDb.AgentWithMediumInsert(&model.AgentWithMedium{ + AgentId: utils.StrToInt(req.AgentId), + MediumId: utils.StrToInt(mediumId), + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + if insertAffected <= 0 { + e.OutErr(c, e.ERR_DB_ORM, "新增 agent_with_medium 记录失败") + return + } } - db.Db.InsertOne(&tmp) } ip := utils.GetIP(c.Request) key := fmt.Sprintf(md.JwtTokenKey, ip, utils.AnyToString(mediumModel.Id)) diff --git a/app/md/md_login.go b/app/md/md_login.go index cb0806d..4530bbe 100644 --- a/app/md/md_login.go +++ b/app/md/md_login.go @@ -16,6 +16,7 @@ type LoginPhoneReq struct { } type RegisterReq struct { UserName string `json:"username" binding:"required" example:"登录账号"` + AgentId string `json:"agent_id" example:"代理id"` Captcha string `json:"captcha" binding:"required" example:"验证码"` PassWord string `json:"password" binding:"required" example:"登录密码"` AgentId string `json:"agent_id" example:"代理id"` diff --git a/docs/docs.go b/docs/docs.go index 6a07ef1..e4e689c 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1198,7 +1198,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/md.LoginReq" + "$ref": "#/definitions/md.RegisterReq" } } ], @@ -3193,6 +3193,32 @@ const docTemplate = `{ } } }, + "md.RegisterReq": { + "type": "object", + "required": [ + "captcha", + "password", + "username" + ], + "properties": { + "agent_id": { + "type": "string", + "example": "代理id" + }, + "captcha": { + "type": "string", + "example": "验证码" + }, + "password": { + "type": "string", + "example": "登录密码" + }, + "username": { + "type": "string", + "example": "登录账号" + } + } + }, "md.Response": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 6aba707..419e607 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1190,7 +1190,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/md.LoginReq" + "$ref": "#/definitions/md.RegisterReq" } } ], @@ -3185,6 +3185,32 @@ } } }, + "md.RegisterReq": { + "type": "object", + "required": [ + "captcha", + "password", + "username" + ], + "properties": { + "agent_id": { + "type": "string", + "example": "代理id" + }, + "captcha": { + "type": "string", + "example": "验证码" + }, + "password": { + "type": "string", + "example": "登录密码" + }, + "username": { + "type": "string", + "example": "登录账号" + } + } + }, "md.Response": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 38a3da3..c67e198 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -755,6 +755,25 @@ definitions: uuid: type: string type: object + md.RegisterReq: + properties: + agent_id: + example: 代理id + type: string + captcha: + example: 验证码 + type: string + password: + example: 登录密码 + type: string + username: + example: 登录账号 + type: string + required: + - captcha + - password + - username + type: object md.Response: properties: code: @@ -1764,7 +1783,7 @@ paths: name: req required: true schema: - $ref: '#/definitions/md.LoginReq' + $ref: '#/definitions/md.RegisterReq' produces: - application/json responses: diff --git a/go.mod b/go.mod index af06264..0d8a1f8 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ go 1.18 // require ( - code.fnuoos.com/zhimeng/model.git v0.0.3-0.20240913063657-cd3094cf9822 + code.fnuoos.com/zhimeng/model.git v0.0.3-0.20240918130541-2345c97fc95a github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 github.com/boombuler/barcode v1.0.1 github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 diff --git a/k8s/container_prd.yaml b/k8s/container_prd.yaml index e2dc9da..c13f138 100644 --- a/k8s/container_prd.yaml +++ b/k8s/container_prd.yaml @@ -1,49 +1,90 @@ -apiVersion: apps/v1 kind: Deployment +apiVersion: apps/v1 +# 元数据 metadata: - namespace: zhios - name: zhios-mall + name: advertisement-medium + namespace: advertisement labels: - app: zhios-mall + app: advertisement-medium + annotations: + kubesphere.io/creator: dengbiao + kubesphere.io/description: advertisement-medium +# deployment主要部分 spec: replicas: 1 + selector: + matchLabels: + # 名称与上面的labels对应 + app: advertisement-medium template: metadata: - name: zhios-mall labels: - app: zhios-mall + # 名称与上面的matchLabels对应 + app: advertisement-medium spec: - containers: - - name: zhios-mall-container - image: registry-vpc.cn-shenzhen.aliyuncs.com/fnuoos-prd/zyos-mall:0.1 - ports: - - containerPort: 5002 - name: 5002tcp - protocol: TCP - resources: - limits: - cpu: "1" - memory: 256Mi - requests: - cpu: 200m - memory: 128Mi - imagePullPolicy: IfNotPresent - restartPolicy: Always + # 声明挂载卷(将外部已存在的pvc、config等挂载进来) volumes: + # 用于时区校正 - name: host-time hostPath: path: /etc/localtime type: '' - - name: mall-cfg + # 将前面创建的configMap也挂载进来 + - name: advertisement-medium-cfg configMap: - name: zhios-mall-cfg + # 这里的名字就是前面创建的configMap的名字 + name: advertisement-medium-cfg defaultMode: 420 - selector: - matchLabels: - app: zhios-mall - - strategy: - type: RollingUpdate - rollingUpdate: - maxUnavailable: 25% - maxSurge: 25% + # pvc + - name: advertisement-medium-pvc # 在该部署中的名称,后面使用改名称挂载 + persistentVolumeClaim: + claimName: advertisement-medium-pvc # pvc的名称 + # Nginx配置 + - name: advertisement-medium-nginx + configMap: + name: advertisement-medium-nginx # 外部configMap的名称 + items: + - key: go.conf + path: default.conf + containers: + # 主容器 + - name: advertisement-medium-container + # 镜像地址(提前打包好并推送的镜像仓库) + image: 'registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/advertisement-medium:0.0.1' + ports: + - name: ad-medium-1004 + # 容器端口号(注意与golang web server启动的端口一致) + containerPort: 1004 + protocol: TCP + # 将前面volume声明的需要用到的pvc、config挂载上来 + volumeMounts: + - name: host-time + readOnly: true + mountPath: /etc/localtime + - name: advertisement-medium-cfg # 该名字对应前面volumes声明的名字 + readOnly: true + # 挂载到容器的哪个路径 + mountPath: /var/zyos + imagePullPolicy: Always + # Nginx 容器 + - name: nginx + image: 'registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/nginx:latest' + ports: + - name: http-80 + containerPort: 80 + protocol: TCP + volumeMounts: + # 时区校正 + - name: host-time + readOnly: true + mountPath: /etc/localtime + # 存储卷 用于存放前端代码 + - name: advertisement-medium-pvc # 前面volumes声明的名称 + mountPath: /usr/share/nginx/html + - name: advertisement-medium-nginx # Nginx 配置 + readOnly: true + mountPath: /etc/nginx/conf.d/default.conf + subPath: default.conf + restartPolicy: Always + terminationGracePeriodSeconds: 30 + dnsPolicy: ClusterFirst \ No newline at end of file diff --git a/k8s/ingress_prd.yaml b/k8s/ingress_prd.yaml new file mode 100644 index 0000000..4de37c4 --- /dev/null +++ b/k8s/ingress_prd.yaml @@ -0,0 +1,20 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + cert-manager.io/cluster-issuer: letsencrypt-prod + kubesphere.io/creator: dengbiao + name: advertisement-medium + namespace: advertisement +spec: + rules: + - host: '*.admt.zhiyingos.cn' + http: + paths: + - backend: + service: + name: advertisement-medium + port: + number: 80 + path: / + pathType: ImplementationSpecific