Browse Source

add role

master
黄梓健 5 years ago
parent
commit
dbd80f00f8
  1. 5
      controllers/base.go
  2. 596
      docs/docs.go
  3. 544
      docs/swagger.json
  4. 360
      docs/swagger.yaml
  5. 1
      go.mod
  6. 2
      go.sum
  7. 55
      logger/logger.go
  8. 28
      main.go
  9. 19
      models/customer.go

5
controllers/base.go

@ -2,10 +2,10 @@ package controllers
import (
"fmt"
"go.uber.org/zap"
"hudongzhuanjia/logger"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"runtime"
"strconv"
"github.com/ouxuanserver/osmanthuswine/src/core"
@ -198,8 +198,7 @@ func (t *BaseCtl) RAW(data interface{}) {
func (t *BaseCtl) CheckErr(err error) {
if err != nil {
pc, file, line, ok := runtime.Caller(1)
logger.Sugar.Debugf("error:%v, pc: %v, file: %v, line:%v, ok: %v", err, pc, file, line, ok)
logger.Error("check err", zap.Error(err))
t.CheckErrDisplayByError(err)
}
}

596
docs/docs.go

@ -1,596 +0,0 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2019-11-07 14:33:12.2505817 +0800 CST m=+0.073000101
package docs
import (
"bytes"
"encoding/json"
"github.com/alecthomas/template"
"github.com/swaggo/swag"
)
var doc = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "This is a sample server Petstore server.",
"title": "hudongzhuangjia api",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "API Support",
"url": "http://www.swagger.io/support",
"email": "support@swagger.io"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0"
},
"host": "172.0.0.1:20181",
"basePath": "/PcClient",
"paths": {
"/Client/InviteEnvelopeCtl/invite": {
"post": {
"description": "填写要求信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"invite envelope"
],
"summary": "InviteEnvelope",
"parameters": [
{
"type": "integer",
"description": "邀请函内容",
"name": "activity_id",
"in": "query",
"required": true
}
],
"responses": {
"0": {
"description": "success",
"schema": {
"type": "string"
}
},
"404": {
"description": "参数不存在",
"schema": {
"type": "string"
}
},
"405": {
"description": "用户不存在",
"schema": {
"type": "string"
}
}
}
}
},
"/Client/InviteEnvelopeCtl/setting": {
"get": {
"description": "get invite envelope setting",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"invite envelope"
],
"summary": "InviteEnvelope",
"parameters": [
{
"type": "integer",
"description": "Activity ID",
"name": "activity_id",
"in": "query",
"required": true
}
],
"responses": {
"0": {
"schema": {
"type": "object",
"$ref": "#/definitions/models.Invitation"
}
},
"404": {
"description": "参数不存在",
"schema": {
"type": "string"
}
},
"405": {
"description": "用户不存在",
"schema": {
"type": "string"
}
}
}
}
},
"/Client/TugOfWarCtl/shake": {
"get": {
"description": "shake bahe activity",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"tug war"
],
"summary": "tug war",
"parameters": [
{
"type": "integer",
"description": "Bahe Activity ID",
"name": "bahe_activity_id",
"in": "query",
"required": true
}
],
"responses": {
"0": {
"schema": {
"type": "object",
"$ref": "#/definitions/models.BaheTeam"
}
},
"404": {
"description": "参数不存在",
"schema": {
"type": "string"
}
},
"405": {
"description": "用户不存在",
"schema": {
"type": "object",
"$ref": "#/definitions/string"
}
}
}
}
},
"/Client/TugOfWarCtl/status": {
"get": {
"description": "get current status",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"client tug war"
],
"summary": "client tug war",
"parameters": [
{
"type": "integer",
"description": "Bahe Activity ID",
"name": "bahe_activity_id",
"in": "query",
"required": true
}
],
"responses": {
"0": {
"schema": {
"type": "object",
"$ref": "#/definitions/models.TugOfWar"
}
},
"503": {
"description": "参数不存在",
"schema": {
"type": "string"
}
},
"504": {
"description": "用户不存在",
"schema": {
"type": "object",
"$ref": "#/definitions/string"
}
}
}
}
},
"/Pc/ActivityCtl/list": {
"get": {
"description": "get all area store",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"pc"
],
"summary": "activity",
"responses": {
"200": {
"description": "success",
"schema": {
"type": "string"
}
}
}
}
},
"/Pc/AuctionCtl/startAuction": {
"get": {
"description": "开始竞拍",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"pc"
],
"summary": "auction",
"parameters": [
{
"type": "integer",
"description": "竞拍id",
"name": "auction_activity_id",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "success",
"schema": {
"type": "string"
}
}
}
}
},
"/Pc/AuctionCtl/stopAuction": {
"get": {
"description": "结束竞拍",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"pc"
],
"summary": "auction",
"parameters": [
{
"type": "integer",
"description": "竞拍id",
"name": "auction_activity_id",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "success",
"schema": {
"type": "string"
}
}
}
}
},
"/Pc/WsCtl/ops": {
"get": {
"description": "get current operation",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ws"
],
"summary": "ws",
"parameters": [
{
"type": "integer",
"description": "Activity ID",
"name": "activity_id",
"in": "query",
"required": true
}
],
"responses": {
"0": {
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.CustomerOperation"
}
}
},
"503": {
"description": "参数不存在",
"schema": {
"type": "string"
}
},
"504": {
"description": "用户不存在",
"schema": {
"type": "object",
"$ref": "#/definitions/string"
}
}
}
}
},
"/Pc/WsCtl/saveOp": {
"post": {
"description": "save operation",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ws"
],
"summary": "ws",
"parameters": [
{
"type": "string",
"description": "操作内容",
"name": "operation",
"in": "query",
"required": true
}
],
"responses": {
"0": {
"description": "success",
"schema": {
"type": "string"
}
},
"503": {
"description": "参数不存在",
"schema": {
"type": "string"
}
},
"504": {
"description": "用户不存在",
"schema": {
"type": "object",
"$ref": "#/definitions/string"
}
}
}
}
}
},
"definitions": {
"models.BaheTeam": {
"type": "object",
"properties": {
"activity_id": {
"type": "integer"
},
"bahe_activity_id": {
"type": "integer"
},
"bahe_team_name": {
"type": "string"
},
"id": {
"type": "integer"
},
"is_delete": {
"type": "boolean"
},
"members": {
"type": "array",
"items": {
"$ref": "#/definitions/models.BaheTeamMember"
}
},
"qrcode": {
"type": "string"
},
"rank": {
"type": "integer"
},
"total_score": {
"type": "integer"
}
}
},
"models.BaheTeamMember": {
"type": "object",
"properties": {
"avatar": {
"type": "string"
},
"bahe_activity_id": {
"type": "integer"
},
"id": {
"type": "integer"
},
"member_id": {
"type": "integer"
},
"nick_name": {
"type": "string"
},
"rehearsal_id": {
"type": "integer"
},
"score": {
"type": "integer"
},
"team_id": {
"type": "integer"
},
"team_name": {
"type": "string"
}
}
},
"models.CustomerOperation": {
"type": "object",
"properties": {
"activity_id": {
"type": "integer"
},
"area_id": {
"type": "integer"
},
"created_at": {
"type": "string"
},
"customer_id": {
"type": "integer"
},
"id": {
"type": "integer"
},
"is_delete": {
"type": "boolean"
},
"module_activity_id": {
"type": "integer"
},
"module_activity_type": {
"type": "string"
},
"operation": {
"type": "string"
},
"other_data": {
"type": "object"
},
"updated_at": {
"type": "string"
}
}
},
"models.Invitation": {
"type": "object",
"properties": {
"activity_id": {
"type": "integer"
},
"id": {
"type": "integer"
},
"qr_dest_url": {
"type": "string"
},
"qr_image_url": {
"type": "string"
},
"self_box": {
"type": "string"
},
"setting_box": {
"type": "string"
},
"submit_time_limit": {
"type": "string"
},
"time_limit_end": {
"type": "string"
}
}
},
"models.TugOfWar": {
"type": "object",
"properties": {
"activity_id": {
"type": "integer"
},
"created_at": {
"type": "string"
},
"id": {
"type": "integer"
},
"is_delete": {
"type": "boolean"
},
"model": {
"type": "string"
},
"number": {
"type": "integer"
},
"status": {
"type": "string"
},
"updated_at": {
"type": "string"
}
}
}
}
}`
type swaggerInfo struct {
Version string
Host string
BasePath string
Schemes []string
Title string
Description string
}
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = swaggerInfo{ Schemes: []string{}}
type s struct{}
func (s *s) ReadDoc() string {
t, err := template.New("swagger_info").Funcs(template.FuncMap{
"marshal": func(v interface {}) string {
a, _ := json.Marshal(v)
return string(a)
},
}).Parse(doc)
if err != nil {
return doc
}
var tpl bytes.Buffer
if err := t.Execute(&tpl, SwaggerInfo); err != nil {
return doc
}
return tpl.String()
}
func init() {
swag.Register(swag.Name, &s{})
}

544
docs/swagger.json

@ -1,544 +0,0 @@
{
"swagger": "2.0",
"info": {
"description": "This is a sample server Petstore server.",
"title": "hudongzhuangjia api",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "API Support",
"url": "http://www.swagger.io/support",
"email": "support@swagger.io"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0"
},
"host": "172.0.0.1:20181",
"basePath": "/PcClient",
"paths": {
"/Client/InviteEnvelopeCtl/invite": {
"post": {
"description": "填写要求信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"invite envelope"
],
"summary": "InviteEnvelope",
"parameters": [
{
"type": "integer",
"description": "邀请函内容",
"name": "activity_id",
"in": "query",
"required": true
}
],
"responses": {
"0": {
"description": "success",
"schema": {
"type": "string"
}
},
"404": {
"description": "参数不存在",
"schema": {
"type": "string"
}
},
"405": {
"description": "用户不存在",
"schema": {
"type": "string"
}
}
}
}
},
"/Client/InviteEnvelopeCtl/setting": {
"get": {
"description": "get invite envelope setting",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"invite envelope"
],
"summary": "InviteEnvelope",
"parameters": [
{
"type": "integer",
"description": "Activity ID",
"name": "activity_id",
"in": "query",
"required": true
}
],
"responses": {
"0": {
"schema": {
"type": "object",
"$ref": "#/definitions/models.Invitation"
}
},
"404": {
"description": "参数不存在",
"schema": {
"type": "string"
}
},
"405": {
"description": "用户不存在",
"schema": {
"type": "string"
}
}
}
}
},
"/Client/TugOfWarCtl/shake": {
"get": {
"description": "shake bahe activity",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"tug war"
],
"summary": "tug war",
"parameters": [
{
"type": "integer",
"description": "Bahe Activity ID",
"name": "bahe_activity_id",
"in": "query",
"required": true
}
],
"responses": {
"0": {
"schema": {
"type": "object",
"$ref": "#/definitions/models.BaheTeam"
}
},
"404": {
"description": "参数不存在",
"schema": {
"type": "string"
}
},
"405": {
"description": "用户不存在",
"schema": {
"type": "object",
"$ref": "#/definitions/string"
}
}
}
}
},
"/Client/TugOfWarCtl/status": {
"get": {
"description": "get current status",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"client tug war"
],
"summary": "client tug war",
"parameters": [
{
"type": "integer",
"description": "Bahe Activity ID",
"name": "bahe_activity_id",
"in": "query",
"required": true
}
],
"responses": {
"0": {
"schema": {
"type": "object",
"$ref": "#/definitions/models.TugOfWar"
}
},
"503": {
"description": "参数不存在",
"schema": {
"type": "string"
}
},
"504": {
"description": "用户不存在",
"schema": {
"type": "object",
"$ref": "#/definitions/string"
}
}
}
}
},
"/Pc/ActivityCtl/list": {
"get": {
"description": "get all area store",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"pc"
],
"summary": "activity",
"responses": {
"200": {
"description": "success",
"schema": {
"type": "string"
}
}
}
}
},
"/Pc/AuctionCtl/startAuction": {
"get": {
"description": "开始竞拍",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"pc"
],
"summary": "auction",
"parameters": [
{
"type": "integer",
"description": "竞拍id",
"name": "auction_activity_id",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "success",
"schema": {
"type": "string"
}
}
}
}
},
"/Pc/AuctionCtl/stopAuction": {
"get": {
"description": "结束竞拍",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"pc"
],
"summary": "auction",
"parameters": [
{
"type": "integer",
"description": "竞拍id",
"name": "auction_activity_id",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "success",
"schema": {
"type": "string"
}
}
}
}
},
"/Pc/WsCtl/ops": {
"get": {
"description": "get current operation",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ws"
],
"summary": "ws",
"parameters": [
{
"type": "integer",
"description": "Activity ID",
"name": "activity_id",
"in": "query",
"required": true
}
],
"responses": {
"0": {
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.CustomerOperation"
}
}
},
"503": {
"description": "参数不存在",
"schema": {
"type": "string"
}
},
"504": {
"description": "用户不存在",
"schema": {
"type": "object",
"$ref": "#/definitions/string"
}
}
}
}
},
"/Pc/WsCtl/saveOp": {
"post": {
"description": "save operation",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ws"
],
"summary": "ws",
"parameters": [
{
"type": "string",
"description": "操作内容",
"name": "operation",
"in": "query",
"required": true
}
],
"responses": {
"0": {
"description": "success",
"schema": {
"type": "string"
}
},
"503": {
"description": "参数不存在",
"schema": {
"type": "string"
}
},
"504": {
"description": "用户不存在",
"schema": {
"type": "object",
"$ref": "#/definitions/string"
}
}
}
}
}
},
"definitions": {
"models.BaheTeam": {
"type": "object",
"properties": {
"activity_id": {
"type": "integer"
},
"bahe_activity_id": {
"type": "integer"
},
"bahe_team_name": {
"type": "string"
},
"id": {
"type": "integer"
},
"is_delete": {
"type": "boolean"
},
"members": {
"type": "array",
"items": {
"$ref": "#/definitions/models.BaheTeamMember"
}
},
"qrcode": {
"type": "string"
},
"rank": {
"type": "integer"
},
"total_score": {
"type": "integer"
}
}
},
"models.BaheTeamMember": {
"type": "object",
"properties": {
"avatar": {
"type": "string"
},
"bahe_activity_id": {
"type": "integer"
},
"id": {
"type": "integer"
},
"member_id": {
"type": "integer"
},
"nick_name": {
"type": "string"
},
"rehearsal_id": {
"type": "integer"
},
"score": {
"type": "integer"
},
"team_id": {
"type": "integer"
},
"team_name": {
"type": "string"
}
}
},
"models.CustomerOperation": {
"type": "object",
"properties": {
"activity_id": {
"type": "integer"
},
"area_id": {
"type": "integer"
},
"created_at": {
"type": "string"
},
"customer_id": {
"type": "integer"
},
"id": {
"type": "integer"
},
"is_delete": {
"type": "boolean"
},
"module_activity_id": {
"type": "integer"
},
"module_activity_type": {
"type": "string"
},
"operation": {
"type": "string"
},
"other_data": {
"type": "object"
},
"updated_at": {
"type": "string"
}
}
},
"models.Invitation": {
"type": "object",
"properties": {
"activity_id": {
"type": "integer"
},
"id": {
"type": "integer"
},
"qr_dest_url": {
"type": "string"
},
"qr_image_url": {
"type": "string"
},
"self_box": {
"type": "string"
},
"setting_box": {
"type": "string"
},
"submit_time_limit": {
"type": "string"
},
"time_limit_end": {
"type": "string"
}
}
},
"models.TugOfWar": {
"type": "object",
"properties": {
"activity_id": {
"type": "integer"
},
"created_at": {
"type": "string"
},
"id": {
"type": "integer"
},
"is_delete": {
"type": "boolean"
},
"model": {
"type": "string"
},
"number": {
"type": "integer"
},
"status": {
"type": "string"
},
"updated_at": {
"type": "string"
}
}
}
}
}

360
docs/swagger.yaml

@ -1,360 +0,0 @@
basePath: /PcClient
definitions:
models.BaheTeam:
properties:
activity_id:
type: integer
bahe_activity_id:
type: integer
bahe_team_name:
type: string
id:
type: integer
is_delete:
type: boolean
members:
items:
$ref: '#/definitions/models.BaheTeamMember'
type: array
qrcode:
type: string
rank:
type: integer
total_score:
type: integer
type: object
models.BaheTeamMember:
properties:
avatar:
type: string
bahe_activity_id:
type: integer
id:
type: integer
member_id:
type: integer
nick_name:
type: string
rehearsal_id:
type: integer
score:
type: integer
team_id:
type: integer
team_name:
type: string
type: object
models.CustomerOperation:
properties:
activity_id:
type: integer
area_id:
type: integer
created_at:
type: string
customer_id:
type: integer
id:
type: integer
is_delete:
type: boolean
module_activity_id:
type: integer
module_activity_type:
type: string
operation:
type: string
other_data:
type: object
updated_at:
type: string
type: object
models.Invitation:
properties:
activity_id:
type: integer
id:
type: integer
qr_dest_url:
type: string
qr_image_url:
type: string
self_box:
type: string
setting_box:
type: string
submit_time_limit:
type: string
time_limit_end:
type: string
type: object
models.TugOfWar:
properties:
activity_id:
type: integer
created_at:
type: string
id:
type: integer
is_delete:
type: boolean
model:
type: string
number:
type: integer
status:
type: string
updated_at:
type: string
type: object
host: 172.0.0.1:20181
info:
contact:
email: support@swagger.io
name: API Support
url: http://www.swagger.io/support
description: This is a sample server Petstore server.
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
termsOfService: http://swagger.io/terms/
title: hudongzhuangjia api
version: "1.0"
paths:
/Client/InviteEnvelopeCtl/invite:
post:
consumes:
- application/json
description: 填写要求信息
parameters:
- description: 邀请函内容
in: query
name: activity_id
required: true
type: integer
produces:
- application/json
responses:
"0":
description: success
schema:
type: string
"404":
description: 参数不存在
schema:
type: string
"405":
description: 用户不存在
schema:
type: string
summary: InviteEnvelope
tags:
- invite envelope
/Client/InviteEnvelopeCtl/setting:
get:
consumes:
- application/json
description: get invite envelope setting
parameters:
- description: Activity ID
in: query
name: activity_id
required: true
type: integer
produces:
- application/json
responses:
"0":
schema:
$ref: '#/definitions/models.Invitation'
type: object
"404":
description: 参数不存在
schema:
type: string
"405":
description: 用户不存在
schema:
type: string
summary: InviteEnvelope
tags:
- invite envelope
/Client/TugOfWarCtl/shake:
get:
consumes:
- application/json
description: shake bahe activity
parameters:
- description: Bahe Activity ID
in: query
name: bahe_activity_id
required: true
type: integer
produces:
- application/json
responses:
"0":
schema:
$ref: '#/definitions/models.BaheTeam'
type: object
"404":
description: 参数不存在
schema:
type: string
"405":
description: 用户不存在
schema:
$ref: '#/definitions/string'
type: object
summary: tug war
tags:
- tug war
/Client/TugOfWarCtl/status:
get:
consumes:
- application/json
description: get current status
parameters:
- description: Bahe Activity ID
in: query
name: bahe_activity_id
required: true
type: integer
produces:
- application/json
responses:
"0":
schema:
$ref: '#/definitions/models.TugOfWar'
type: object
"503":
description: 参数不存在
schema:
type: string
"504":
description: 用户不存在
schema:
$ref: '#/definitions/string'
type: object
summary: client tug war
tags:
- client tug war
/Pc/ActivityCtl/list:
get:
consumes:
- application/json
description: get all area store
produces:
- application/json
responses:
"200":
description: success
schema:
type: string
summary: activity
tags:
- pc
/Pc/AuctionCtl/startAuction:
get:
consumes:
- application/json
description: 开始竞拍
parameters:
- description: 竞拍id
in: query
name: auction_activity_id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: success
schema:
type: string
summary: auction
tags:
- pc
/Pc/AuctionCtl/stopAuction:
get:
consumes:
- application/json
description: 结束竞拍
parameters:
- description: 竞拍id
in: query
name: auction_activity_id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: success
schema:
type: string
summary: auction
tags:
- pc
/Pc/WsCtl/ops:
get:
consumes:
- application/json
description: get current operation
parameters:
- description: Activity ID
in: query
name: activity_id
required: true
type: integer
produces:
- application/json
responses:
"0":
schema:
items:
$ref: '#/definitions/models.CustomerOperation'
type: array
"503":
description: 参数不存在
schema:
type: string
"504":
description: 用户不存在
schema:
$ref: '#/definitions/string'
type: object
summary: ws
tags:
- ws
/Pc/WsCtl/saveOp:
post:
consumes:
- application/json
description: save operation
parameters:
- description: 操作内容
in: query
name: operation
required: true
type: string
produces:
- application/json
responses:
"0":
description: success
schema:
type: string
"503":
description: 参数不存在
schema:
type: string
"504":
description: 用户不存在
schema:
$ref: '#/definitions/string'
type: object
summary: ws
tags:
- ws
swagger: "2.0"

1
go.mod

@ -15,6 +15,7 @@ require (
github.com/kirinlabs/HttpRequest v0.1.5
github.com/ouxuanserver/osmanthuswine v0.0.0-20190916032555-480efadf4941
github.com/panjf2000/ants v4.0.2+incompatible
github.com/pkg/errors v0.9.1 // indirect
github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9
github.com/smartystreets/goconvey v1.6.4
github.com/swaggo/http-swagger v0.0.0-20190614090009-c2865af9083e

2
go.sum

@ -204,6 +204,8 @@ github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=

55
logger/logger.go

@ -9,6 +9,7 @@ import (
)
var Sugar *zap.SugaredLogger
var logger *zap.Logger
func init() {
InitZap()
@ -24,7 +25,8 @@ func InitZap() {
zapcore.NewConsoleEncoder(NewEncoderConfig()),
zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), w),
zap.DebugLevel)
Sugar = zap.New(core, zap.AddCaller()).Sugar()
logger = zap.New(core, zap.AddCaller())
Sugar = logger.Sugar()
}
func NewEncoderConfig() zapcore.EncoderConfig {
return zapcore.EncoderConfig{
@ -46,3 +48,54 @@ func NewEncoderConfig() zapcore.EncoderConfig {
func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(t.Format("2006-01-02 15:04:05.000"))
}
func level(level string) zapcore.Level {
switch level {
case "info":
return zap.InfoLevel
case "fatal":
return zap.FatalLevel
case "panic":
return zap.PanicLevel
case "error":
return zap.ErrorLevel
case "dpanic":
return zap.DPanicLevel
case "warn":
return zap.WarnLevel
default:
return zap.DebugLevel
}
}
func Info(msg string, fields ...zap.Field) {
logger.Info(msg, fields...)
}
func Debug(msg string, fields ...zap.Field) {
logger.Debug(msg, fields...)
}
func Panic(msg string, fields ...zap.Field) {
logger.Debug(msg, fields...)
}
func Warn(msg string, fields ...zap.Field) {
logger.Warn(msg, fields...)
}
func DPanic(msg string, fields ...zap.Field) {
logger.DPanic(msg, fields...)
}
func Error(msg string, fields ...zap.Field) {
logger.Error(msg, fields...)
}
func With(fields ...zap.Field) {
logger.With(fields...)
}
func WithOptions(opts ...zap.Option) {
logger.WithOptions(opts...)
}

28
main.go

@ -1,32 +1,13 @@
package main
import (
"github.com/ouxuanserver/osmanthuswine"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers/client"
"hudongzhuanjia/controllers/common"
"hudongzhuanjia/controllers/pc"
_ "hudongzhuanjia/docs"
"runtime"
"github.com/ouxuanserver/osmanthuswine"
"github.com/ouxuanserver/osmanthuswine/src/core"
"github.com/swaggo/http-swagger"
)
// @title hudongzhuangjia api
// @version 1.0
// @description This is a sample server Petstore server.
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host 172.0.0.1:20181
// @BasePath /PcClient
func main() {
// pc
core.GetInstanceRouterManage().Registered(new(pc.WsCtl)) // 用户
@ -69,10 +50,5 @@ func main() {
core.GetInstanceRouterManage().Registered(new(common.AnnexCtl))
core.GetInstanceRouterManage().Registered(new(common.WeChatOauthCtl))
if runtime.GOOS == "windows" {
// swagger
osmanthuswine.GetChiRouter().Get("/swagger/*", httpSwagger.WrapHandler)
}
osmanthuswine.Run()
}

19
models/customer.go

@ -1,8 +1,9 @@
package models
import (
"errors"
"fmt"
"github.com/pkg/errors"
"go.uber.org/zap"
"hudongzhuanjia/logger"
"time"
@ -10,7 +11,7 @@ import (
"github.com/ouxuanserver/osmanthuswine/src/helper"
)
const CustomerTableName = TableNamePrefix + "customer"
const CustomerTN = TableNamePrefix + "customer"
//客户表
type Customer struct {
@ -39,15 +40,19 @@ type Customer struct {
}
func (t *Customer) TableName() string {
return CustomerTableName
return CustomerTN
}
//根据账号和密码验证用户
func (t *Customer) Author(userName, pwd string) error {
exist, err := core.GetXormAuto().Where("(phone=? or email=?) and is_delete=0", userName, userName).Get(t)
func (t *Customer) Author(name, pwd string) error {
exist, err := core.GetXormAuto().Where("(phone=? or email=?) and role_id=? and is_delete=0",
name, name, 6).Get(t)
if err != nil {
logger.Sugar.Debugf("验证用户失败,失败原因:%+v,账号:%s,密码:%s,MD5后得密码:%s", err, userName, pwd, helper.Md5(fmt.Sprintf("hdzj==%s", pwd)))
return err
logger.Error("验证用户失败",
zap.Error(err),
zap.String("name", name),
zap.String("pwd", pwd))
return errors.WithStack(err)
}
if !exist {
return errors.New("用户名错误,请重新输入")

Loading…
Cancel
Save