From 9597bcd7b5798e3ce99fac18d2b940274b639bd0 Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Tue, 25 Aug 2020 10:00:16 +0800 Subject: [PATCH] add area admin login --- controllers/client/area.go | 37 +++++++++++++++++++++++++++++++++++++ models/area_store.go | 35 ++++++++++++++++++++++------------- models/customer.go | 11 ++--------- utils/define/define.go | 1 + 4 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 controllers/client/area.go diff --git a/controllers/client/area.go b/controllers/client/area.go new file mode 100644 index 0000000..2bbe5ad --- /dev/null +++ b/controllers/client/area.go @@ -0,0 +1,37 @@ +package client + +import ( + "hudongzhuanjia/controllers" + "hudongzhuanjia/libs/jwt" + "hudongzhuanjia/models" + "hudongzhuanjia/utils/code" + "hudongzhuanjia/utils/define" +) + +type AreaCtl struct { + controllers.BaseCtl +} + +// 登陆 +func (t *AreaCtl) Login() { + activityId := t.MustGetInt("activity_id") + username := t.MustGet("username") + password := t.MustGet("password") + + activity := &models.Activity{} + exist, err := models.Get(activity, activityId) + t.CheckErr(err) + t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") + + area := &models.AreaStore{} + exist, err = area.Login(activityId, username, password) + t.CheckErr(err) + t.Assert(exist, code.MSG_ERR_Authority, "用户信息异常") + token, err := jwt.GenJwtToken(define.TYPE_AREAADMIN, area.Id, area.CustomerId, area.CustomerId, area.Id, area.ActivityId) + t.CheckErr(err) + t.SetSession(define.TOKEN, token) + t.JSON(map[string]interface{}{ + "token": token, + "area": area, + }) +} diff --git a/models/area_store.go b/models/area_store.go index fa0d049..7458bfb 100644 --- a/models/area_store.go +++ b/models/area_store.go @@ -1,6 +1,7 @@ package models import ( + "github.com/ouxuanserver/osmanthuswine/src/helper" "time" "github.com/ouxuanserver/osmanthuswine/src/core" @@ -10,33 +11,41 @@ const AreaStoreTableName = TableNamePrefix + "area_store" //店铺地区 type AreaStore struct { - Id int `json:"id" xorm:"not null pk autoincr INT(11)"` - Name string `json:"name" xorm:"not null default('') comment('名字') VARCHAR(255)"` - Type string `json:"type" xorm:"not null default('') comment('地区类型') VARCHAR(255)"` - Address string `json:"address" xorm:"not null default('') comment('地址') VARCHAR(255)"` - ActivityId int `json:"activity_id" xorm:"not null comment('主活动id') BIGINT(20)"` - CustomerId int `json:"customer_id" xorm:"not null default 0 comment('客户id') INT(11)"` - IsMainArea bool `json:"is_main_area" xorm:"not null default(0) comment('是否主地区1是') TINYINT(1)"` - IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('软删除') TINYINT(1)"` - CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"` - UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"` + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + Name string `json:"name" xorm:"not null default('') comment('名字') VARCHAR(255)"` + Type string `json:"type" xorm:"not null default('') comment('地区类型') VARCHAR(255)"` + Address string `json:"address" xorm:"not null default('') comment('地址') VARCHAR(255)"` + ActivityId int `json:"activity_id" xorm:"not null comment('主活动id') BIGINT(20)"` + CustomerId int `json:"customer_id" xorm:"not null default 0 comment('客户id') INT(11)"` + IsMainArea bool `json:"is_main_area" xorm:"not null default(0) comment('是否主地区1是') TINYINT(1)"` + AreaServicePhone string `json:"area_service_phone" xorm:"not null default '' comment('地区客服电话') VARCHAR(128)"` + AdminName string `json:"admin_name" xorm:"not null default '' comment('地区管理员名称') VARCHAR(128)"` + Phone string `json:"phone" xorm:"not null default '' comment('地区管理员账号即手机号') VARCHAR(128)"` + Password string `json:"password" xorm:"not null default '' comment('密码') VARCHAR(255)"` + RawPassword string `json:"raw_password" xorm:"not null default '' comment('密码') VARCHAR(255)"` + IsImport int `json:"is_import" xorm:"not null default 0 comment('是否导入的数据') TINYINT(1)"` + AreaGoodsRuleSwitch int `json:"area_goods_rule_switch" xorm:"not null default 0 comment('地区专属商品规则1开启(用自己地区的商品)0关闭(共用主会场的商品)') TINYINT(1)"` + IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('软删除') TINYINT(1)"` + CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"` + UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"` } func (t *AreaStore) TableName() string { return AreaStoreTableName } - +func (t *AreaStore) Login(activityId int, username, password string) (bool, error) { + password = helper.Md5("hdzj==" + password) + return core.GetXormAuto().Where("activity_id=? and phone=? and password=?", activityId, username, password).Get(t) +} func (t *AreaStore) GetByCustomerId(customerId, activityId interface{}) (bool, error) { return core.GetXormAuto().Where("is_delete=0 and customer_id=? and activity_id=?", customerId, activityId).Get(t) } func (t *AreaStore) GetAreaStoreById(id int) (bool, error) { return core.GetXormAuto().Where("id=? and is_delete=0", id).Get(t) } - func (t *AreaStore) GetMainAreaById(aid int) (bool, error) { return core.GetXormAuto().Where("activity_id=? and is_main_area=1 and is_delete=0", aid).Get(t) } - func GetAreaStoresByActivityId(aid int) ([]*AreaStore, error) { list := make([]*AreaStore, 0) err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).Find(&list) diff --git a/models/customer.go b/models/customer.go index b6b097b..4c10978 100644 --- a/models/customer.go +++ b/models/customer.go @@ -2,14 +2,11 @@ package models import ( "fmt" - "hudongzhuanjia/logger" "time" - "github.com/pkg/errors" - "go.uber.org/zap" - "github.com/ouxuanserver/osmanthuswine/src/core" "github.com/ouxuanserver/osmanthuswine/src/helper" + "github.com/pkg/errors" ) const CustomerTN = TableNamePrefix + "customer" @@ -50,11 +47,7 @@ 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.Error("验证用户失败", - zap.Error(err), - zap.String("name", name), - zap.String("pwd", pwd)) - return errors.WithStack(err) + return err } if !exist { return errors.New("用户名错误,请重新输入") diff --git a/utils/define/define.go b/utils/define/define.go index 31f121d..1704cf4 100644 --- a/utils/define/define.go +++ b/utils/define/define.go @@ -81,6 +81,7 @@ const ( const ( TYPE_H5USER = "h5user" TYPE_CUSTOMER = "customer" + TYPE_AREAADMIN = "area_admin" TYPE_ENTRYPEOPLE = "entry_people" )