作者 yangfu

1.短信 权限认证修改

@@ -52,6 +52,16 @@ spec: @@ -52,6 +52,16 @@ spec:
52 - mountPath: /opt/logs 52 - mountPath: /opt/logs
53 name: accesslogs 53 name: accesslogs
54 env: 54 env:
  55 + - name: REDIS_HOST
  56 + valueFrom:
  57 + configMapKeyRef:
  58 + name: suplus-config
  59 + key: redis.ip
  60 + - name: REDIS_PORT
  61 + valueFrom:
  62 + configMapKeyRef:
  63 + name: suplus-config
  64 + key: redis.port
55 - name: POSTGRESQL_DB_NAME 65 - name: POSTGRESQL_DB_NAME
56 value: "partner_test" 66 value: "partner_test"
57 - name: POSTGRESQL_USER 67 - name: POSTGRESQL_USER
@@ -5,6 +5,7 @@ go 1.14 @@ -5,6 +5,7 @@ go 1.14
5 require ( 5 require (
6 github.com/ajg/form v1.5.1 // indirect 6 github.com/ajg/form v1.5.1 // indirect
7 github.com/astaxie/beego v1.12.1 7 github.com/astaxie/beego v1.12.1
  8 + github.com/dgrijalva/jwt-go v3.2.0+incompatible
8 github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect 9 github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
9 github.com/fatih/structs v1.1.0 // indirect 10 github.com/fatih/structs v1.1.0 // indirect
10 github.com/gavv/httpexpect v2.0.0+incompatible 11 github.com/gavv/httpexpect v2.0.0+incompatible
@@ -20,14 +21,15 @@ require ( @@ -20,14 +21,15 @@ require (
20 github.com/onsi/gomega v1.7.1 21 github.com/onsi/gomega v1.7.1
21 github.com/sergi/go-diff v1.1.0 // indirect 22 github.com/sergi/go-diff v1.1.0 // indirect
22 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect 23 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
  24 + github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726
23 github.com/smartystreets/goconvey v1.6.4 // indirect 25 github.com/smartystreets/goconvey v1.6.4 // indirect
  26 + github.com/tiptok/gocomm v0.0.0-20190919092013-c230743f8095
24 github.com/valyala/fasthttp v1.14.0 // indirect 27 github.com/valyala/fasthttp v1.14.0 // indirect
25 github.com/xeipuuv/gojsonschema v1.2.0 // indirect 28 github.com/xeipuuv/gojsonschema v1.2.0 // indirect
26 github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect 29 github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
27 github.com/yudai/gojsondiff v1.0.0 // indirect 30 github.com/yudai/gojsondiff v1.0.0 // indirect
28 github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect 31 github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
29 github.com/yudai/pp v2.0.1+incompatible // indirect 32 github.com/yudai/pp v2.0.1+incompatible // indirect
30 - github.com/dgrijalva/jwt-go v3.2.0+incompatible  
31 ) 33 )
32 34
33 replace gitlab.fjmaimaimai.com/mmm-go/partner => ../partner 35 replace gitlab.fjmaimaimai.com/mmm-go/partner => ../partner
@@ -23,3 +23,21 @@ func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUser @@ -23,3 +23,21 @@ func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUser
23 } 23 }
24 return repository.NewAdminUserRepository(transactionContext) 24 return repository.NewAdminUserRepository(transactionContext)
25 } 25 }
  26 +
  27 +//CreateOrderRepository 订单
  28 +func CreateOrderRepository(options map[string]interface{}) (domain.OrderRepository, error) {
  29 + var transactionContext *transaction.TransactionContext
  30 + if value, ok := options["transactionContext"]; ok {
  31 + transactionContext = value.(*transaction.TransactionContext)
  32 + }
  33 + return repository.NewOrderRepository(transactionContext)
  34 +}
  35 +
  36 +//CreateOrderRepository 订单
  37 +func CreateOrderPaymentRepository(options map[string]interface{}) (domain.OrderPaymentRepository, error) {
  38 + var transactionContext *transaction.TransactionContext
  39 + if value, ok := options["transactionContext"]; ok {
  40 + transactionContext = value.(*transaction.TransactionContext)
  41 + }
  42 + return repository.NewOrderPaymentRepository(transactionContext)
  43 +}
@@ -7,6 +7,8 @@ const SERVICE_NAME = "partner" @@ -7,6 +7,8 @@ const SERVICE_NAME = "partner"
7 var LOG_LEVEL = "debug" 7 var LOG_LEVEL = "debug"
8 var LOG_File = "app.log" 8 var LOG_File = "app.log"
9 9
  10 +var MMM_SMS_SERVICE_HOST = "https://sms.fjmaimaimai.com:9897"
  11 +
10 func init() { 12 func init() {
11 if os.Getenv("LOG_LEVEL") != "" { 13 if os.Getenv("LOG_LEVEL") != "" {
12 LOG_LEVEL = os.Getenv("LOG_LEVEL") 14 LOG_LEVEL = os.Getenv("LOG_LEVEL")
@@ -2,11 +2,11 @@ package constant @@ -2,11 +2,11 @@ package constant
2 2
3 import "os" 3 import "os"
4 4
5 -var POSTGRESQL_DB_NAME = "partner"  
6 -var POSTGRESQL_USER = "postgres"  
7 -var POSTGRESQL_PASSWORD = "pgsql@123"  
8 -var POSTGRESQL_HOST = "127.0.0.1"  
9 -var POSTGRESQL_PORT = "5432" 5 +var POSTGRESQL_DB_NAME = "partner_dev" //partner
  6 +var POSTGRESQL_USER = "postgres" //
  7 +var POSTGRESQL_PASSWORD = "postgres_15432" //pgsql@123
  8 +var POSTGRESQL_HOST = "101.37.68.23" //127.0.0.1
  9 +var POSTGRESQL_PORT = "15432" //5432
10 var DISABLE_CREATE_TABLE = false 10 var DISABLE_CREATE_TABLE = false
11 var DISABLE_SQL_GENERATE_PRINT = false 11 var DISABLE_SQL_GENERATE_PRINT = false
12 12
  1 +package constant
  2 +
  3 +import "os"
  4 +
  5 +var REDIS_HOST = "127.0.0.1"
  6 +var REDIS_PORT = "6379"
  7 +var REDIS_AUTH = "123456"
  8 +
  9 +func init() {
  10 + if os.Getenv("REDIS_HOST") != "" {
  11 + REDIS_HOST = os.Getenv("REDIS_HOST")
  12 + }
  13 + if os.Getenv("REDIS_PORT") != "" {
  14 + REDIS_PORT = os.Getenv("REDIS_PORT")
  15 + }
  16 + if _, ok := os.LookupEnv("REDIS_AUTH"); ok {
  17 + REDIS_AUTH = os.Getenv("REDIS_AUTH")
  18 + }
  19 +}
  1 +package domain
  2 +
  3 +//买家
  4 +type Buyer struct {
  5 + //买家姓名
  6 + BuyerName string `json:"buyerName"`
  7 + //联系方式
  8 + ContactInfo string `json:"contactInfo"`
  9 + //收获地址
  10 + ShippingAddress string `json:"shippingAddress"`
  11 +}
1 package domain 1 package domain
2 2
  3 +import "time"
  4 +
  5 +const (
  6 + OrderStatusReserve = iota + 1 //预定中
  7 + OrderStatusDeliverSome //部分发货
  8 + OrderStatusDeliverAll //全部发货
  9 +)
  10 +
  11 +type OrderRepository interface {
  12 + Save(dm *Order) (*Order, error)
  13 + Remove(dm *Order) (*Order, error)
  14 + FindOne(queryOptions map[string]interface{}) (*Order, error)
  15 + Find(queryOptions map[string]interface{}) (int64, []*Order, error)
  16 +}
  17 +
3 //Order 订单信息 18 //Order 订单信息
4 type Order struct { 19 type Order struct {
5 //id 20 //id
6 - OrderId int64 `json:"orderId"`  
7 - //账号  
8 - OrderName string `json:"orderName"`  
9 - //密码  
10 - OrderCount int `json:"orderCount"`  
11 - //管理员名称  
12 - OrderAmount string `json:"admin_name"`  
13 - //是否是默认系统账号  
14 - IsDefault bool `json:"is_default"`  
15 - //账号是否可用  
16 - IsUsable bool `json:"is_userable"` 21 + Id int64 `json:"Id,omitempty"`
  22 + //订单类型
  23 + OrderType int `json:"orderType,omitempty"`
  24 + //订单编号
  25 + OrderCode string `json:"orderCode,omitempty"`
  26 + //订单名称
  27 + OrderName string `json:"orderName,omitempty"`
  28 + //订单状态
  29 + OrderStatus int `json:"orderStatus,omitempty"`
  30 + //订单数量
  31 + OrderCount int `json:"orderCount,omitempty"`
  32 + //实际订单数量
  33 + OrderActualCount int `json:"orderActualCount,omitempty"`
  34 + //订单金额
  35 + OrderAmount float64 `json:"admin_name,omitempty"`
  36 + //订单实际金额
  37 + OrderActualAmount float64 `json:"orderActualAmount,omitempty"`
  38 + //订单已支付金额(货款)
  39 + OrderPaymentAmount float64 `json:"orderPaymentAmount,omitempty"`
  40 + //订单区域信息
  41 + OrderRegionInfo *RegionInfo `json:"orderRegionInfo,omitempty"`
  42 +
  43 + Buyer *Buyer `json:"buyer,omitempty"`
  44 + //合伙人编号
  45 + PartnerId int64 `json:"partnerId,omitempty"`
  46 + //合伙人分红百分比
  47 + PartnerBonusPercent float64 `json:"partnerBonusPercent,omitempty"`
  48 + //业务员分红百分比
  49 + SalesmanBonusPercent float64 `json:"salesmanBonusPercent,omitempty"`
  50 +
17 //创建时间 51 //创建时间
18 - CreateAt string `json:"create_at"`  
19 - //用户权限  
20 - Permission []string `json:"permission"` 52 + CreateAt time.Time `json:"createAt,omitempty"`
  53 + //更新时间
  54 + UpdateAt time.Time `json:"updateAt,omitempty"`
  55 +
  56 + //上一次查看时间 已读情况
  57 + LastViewTime time.Time `json:"lastViewTime,omitempty"`
  58 +}
  59 +
  60 +func (m *Order) Identify() interface{} {
  61 + if m.Id == 0 {
  62 + return nil
  63 + }
  64 + return m.Id
  65 +}
  66 +
  67 +func (m *Order) Update(data map[string]interface{}) error {
  68 + if orderType, ok := data["orderType"]; ok && orderType != 0 {
  69 + m.OrderType = orderType.(int)
  70 + }
  71 + if orderCode, ok := data["orderCode"]; ok && orderCode != "" {
  72 + m.OrderCode = orderCode.(string)
  73 + }
  74 + if orderName, ok := data["orderName"]; ok && orderName != "" {
  75 + m.OrderName = orderName.(string)
  76 + }
  77 + if orderStatus, ok := data["orderStatus"]; ok && orderStatus != 0 {
  78 + m.OrderStatus = orderStatus.(int)
  79 + }
  80 + if lastViewTime, ok := data["lastViewTime"]; ok && lastViewTime != 0 {
  81 + m.LastViewTime = lastViewTime.(time.Time)
  82 + }
  83 + m.UpdateAt = time.Now()
  84 + return nil
21 } 85 }
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +const (
  6 + BonusWaitPay = iota + 1 //等待支付分红
  7 + BonusPaid //已经支付分红
  8 +)
  9 +
  10 +type OrderPaymentRepository interface {
  11 + Save(dm *OrderPayment) (*OrderPayment, error)
  12 + Remove(dm *OrderPayment) (*OrderPayment, error)
  13 + FindOne(queryOptions map[string]interface{}) (*OrderPayment, error)
  14 + Find(queryOptions map[string]interface{}) (int64, []*OrderPayment, error)
  15 +}
  16 +
  17 +type OrderPayment struct {
  18 + //编号
  19 + Id int64 `json:"id"`
  20 + //订单编号
  21 + OrderId int64 `json:"orderId"`
  22 + //合伙人编号
  23 + PartnerId int64 `json:"partnerId"`
  24 + //支付货款
  25 + PaymentAmount float64 `json:"paymentAmount"`
  26 + //分红金额
  27 + BonusAmount float64 `json:"bonusAmount"`
  28 + //分红状态 1.等待支付分红 2.已支付分红
  29 + BonusStatus int `json:"bonusStatus"`
  30 + //创建时间
  31 + CreateAt time.Time `json:"createAt"`
  32 + //更新时间
  33 + UpdateAt time.Time `json:"updateAt"`
  34 +}
  35 +
  36 +func (m *OrderPayment) Identify() interface{} {
  37 + if m.Id == 0 {
  38 + return nil
  39 + }
  40 + return m.Id
  41 +}
  42 +
  43 +func (m *OrderPayment) Update(data map[string]interface{}) error {
  44 + if m.BonusStatus != BonusWaitPay {
  45 + return nil
  46 + }
  47 + if paymentAmount, ok := data["paymentAmount"]; ok && paymentAmount != 0 {
  48 + m.PaymentAmount = paymentAmount.(float64)
  49 + }
  50 + if bonusAmount, ok := data["bonusAmount"]; ok && bonusAmount != 0 {
  51 + m.BonusAmount = bonusAmount.(float64)
  52 + }
  53 + if bonusStatus, ok := data["bonusStatus"]; ok && bonusStatus != 0 {
  54 + m.BonusStatus = bonusStatus.(int)
  55 + }
  56 + m.UpdateAt = time.Now()
  57 + return nil
  58 +}
1 package domain 1 package domain
2 2
  3 +//业务员
3 type Salesman struct { 4 type Salesman struct {
4 //Id int64 `json:"id"` 5 //Id int64 `json:"id"`
5 Name string `json:"name"` 6 Name string `json:"name"`
@@ -25,6 +25,8 @@ func init() { @@ -25,6 +25,8 @@ func init() {
25 for _, model := range []interface{}{ 25 for _, model := range []interface{}{
26 //(*models.Employee)(nil), 26 //(*models.Employee)(nil),
27 (*models.PartnerInfo)(nil), 27 (*models.PartnerInfo)(nil),
  28 + (*models.Order)(nil),
  29 + (*models.OrderPayment)(nil),
28 } { 30 } {
29 err := DB.CreateTable(model, &orm.CreateTableOptions{ 31 err := DB.CreateTable(model, &orm.CreateTableOptions{
30 Temp: false, 32 Temp: false,
  1 +package models
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
  5 + "time"
  6 +)
  7 +
  8 +type Order struct {
  9 + tableName struct{} `pg:"order"`
  10 + //id
  11 + Id int64 `pg:",pk"`
  12 + //订单类型 1:实际订单 2:意向订单
  13 + OrderType int `pg:",notnull,default:1"`
  14 + //订单编号
  15 + OrderCode string `pg:",notnull`
  16 + //订单名称
  17 + OrderName string
  18 + //订单状态
  19 + OrderStatus int `pg:",notnull,default:1"`
  20 + //订单数量
  21 + OrderCount int
  22 + //实际订单数量
  23 + OrderActualCount int
  24 + //订单金额
  25 + OrderAmount float64
  26 + //订单实际金额
  27 + OrderActualAmount float64
  28 + //订单已支付金额(货款)
  29 + OrderPaymentAmount float64
  30 + //订单区域信息
  31 + OrderRegionInfo *domain.RegionInfo
  32 +
  33 + Buyer *domain.Buyer
  34 + //合伙人编号
  35 + PartnerId int64
  36 + //合伙人分红百分比
  37 + PartnerBonusPercent float64
  38 + //业务员分红百分比
  39 + SalesmanBonusPercent float64
  40 +
  41 + //创建时间
  42 + CreateAt time.Time
  43 + //更新时间
  44 + UpdateAt time.Time
  45 +
  46 + //上一次查看时间 已读情况
  47 + LastViewTime time.Time
  48 +}
  1 +package models
  2 +
  3 +import "time"
  4 +
  5 +type OrderPayment struct {
  6 + tableName struct{} `pg:"order_payment"`
  7 + //编号
  8 + Id int64 `pg:",pk"`
  9 + //订单编号
  10 + OrderId int64
  11 + //合伙人编号
  12 + PartnerId int64
  13 + //支付货款
  14 + PaymentAmount float64 `pg:",notnull,default:0"`
  15 + //分红金额
  16 + BonusAmount float64
  17 + //分红状态 1.等待支付分红 2.已支付分红
  18 + BonusStatus int `pg:",notnull,default:1"`
  19 + //创建时间
  20 + CreateAt time.Time
  21 + //更新时间
  22 + UpdateAt time.Time
  23 +}
  1 +package redis
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/tiptok/gocomm/pkg/redis"
  6 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
  7 +)
  8 +
  9 +func init() {
  10 + redisSource := fmt.Sprintf("%v:%v", constant.REDIS_HOST, constant.REDIS_PORT)
  11 + err := redis.InitWithDb(100, redisSource, constant.REDIS_AUTH, "0")
  12 + if err != nil {
  13 + panic(err)
  14 + }
  15 +}
  1 +package repository
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models"
  6 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
  7 +)
  8 +
  9 +type OrderPaymentRepository struct {
  10 + transactionContext *transaction.TransactionContext
  11 +}
  12 +
  13 +func (repository *OrderPaymentRepository) Save(dm *domain.OrderPayment) (*domain.OrderPayment, error) {
  14 + var (
  15 + err error
  16 + m = &models.OrderPayment{}
  17 + tx = repository.transactionContext.PgTx
  18 + )
  19 + if err = GobModelTransform(m, dm); err != nil {
  20 + return nil, err
  21 + }
  22 + if dm.Identify() == nil {
  23 + if dm.Id, err = NewSnowflakeId(); err != nil {
  24 + return dm, err
  25 + }
  26 + m.Id = dm.Id
  27 + if err = tx.Insert(m); err != nil {
  28 + return nil, err
  29 + }
  30 + return dm, nil
  31 + }
  32 + if err = tx.Update(m); err != nil {
  33 + return nil, err
  34 + }
  35 + return dm, nil
  36 +}
  37 +
  38 +func (repository *OrderPaymentRepository) Remove(OrderPayment *domain.OrderPayment) (*domain.OrderPayment, error) {
  39 + var (
  40 + tx = repository.transactionContext.PgTx
  41 + OrderPaymentModel = &models.OrderPayment{Id: OrderPayment.Identify().(int64)}
  42 + )
  43 + if _, err := tx.Model(OrderPaymentModel).Where("id = ?", OrderPayment.Id).Delete(); err != nil {
  44 + return OrderPayment, err
  45 + }
  46 + return OrderPayment, nil
  47 +}
  48 +
  49 +func (repository *OrderPaymentRepository) FindOne(queryOptions map[string]interface{}) (*domain.OrderPayment, error) {
  50 + tx := repository.transactionContext.PgTx
  51 + OrderPaymentModel := new(models.OrderPayment)
  52 + query := NewQuery(tx.Model(OrderPaymentModel), queryOptions)
  53 + query.SetWhere("order_payment.id = ?", "id")
  54 + query.SetWhere("order_payment.order_id = ?", "orderId")
  55 + if err := query.First(); err != nil {
  56 + return nil, query.HandleError(err, "没有此订单")
  57 + }
  58 + if OrderPaymentModel.Id == 0 {
  59 + return nil, nil
  60 + }
  61 + return repository.transformPgModelToDomainModel(OrderPaymentModel)
  62 +}
  63 +
  64 +func (repository *OrderPaymentRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.OrderPayment, error) {
  65 + tx := repository.transactionContext.PgTx
  66 + var OrderPaymentModels []*models.OrderPayment
  67 + OrderPayments := make([]*domain.OrderPayment, 0)
  68 + query := NewQuery(tx.Model(&OrderPaymentModels), queryOptions)
  69 + query.
  70 + SetWhere("order_payment.partner_id = ?", "partnerId").
  71 + SetWhere("order_payment.order_id = ?", "orderId").
  72 + SetWhere(`order_payment.create_at >= ?`, "beginTime").
  73 + SetWhere(`order_payment.create_at < ?`, "endTime").
  74 + SetLimit().
  75 + SetOrder("order_payment.create_at", "sortByCreateTime").
  76 + SetOrder("order_payment.update_at", "sortByUpdateTime")
  77 + var err error
  78 + if query.AffectRow, err = query.SelectAndCount(); err != nil {
  79 + return 0, OrderPayments, err
  80 + }
  81 + for _, OrderPaymentModel := range OrderPaymentModels {
  82 + if OrderPayment, err := repository.transformPgModelToDomainModel(OrderPaymentModel); err != nil {
  83 + return 0, OrderPayments, err
  84 + } else {
  85 + OrderPayments = append(OrderPayments, OrderPayment)
  86 + }
  87 + }
  88 + return int64(query.AffectRow), OrderPayments, nil
  89 +}
  90 +
  91 +func (repository *OrderPaymentRepository) transformPgModelToDomainModel(OrderPaymentModel *models.OrderPayment) (*domain.OrderPayment, error) {
  92 + m := &domain.OrderPayment{}
  93 + err := GobModelTransform(m, OrderPaymentModel)
  94 + return m, err
  95 +}
  96 +
  97 +func NewOrderPaymentRepository(transactionContext *transaction.TransactionContext) (*OrderPaymentRepository, error) {
  98 + if transactionContext == nil {
  99 + return nil, ERR_EMPTY_TC
  100 + }
  101 + return &OrderPaymentRepository{transactionContext: transactionContext}, nil
  102 +}
  1 +package repository
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models"
  6 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
  7 +)
  8 +
  9 +type OrderRepository struct {
  10 + transactionContext *transaction.TransactionContext
  11 +}
  12 +
  13 +func (repository *OrderRepository) Save(dm *domain.Order) (*domain.Order, error) {
  14 + var (
  15 + err error
  16 + m = &models.Order{}
  17 + tx = repository.transactionContext.PgTx
  18 + )
  19 + if err = GobModelTransform(m, dm); err != nil {
  20 + return nil, err
  21 + }
  22 + if dm.Identify() == nil {
  23 + //if dm.Id, err = NewSnowflakeId(); err != nil {
  24 + // return dm, err
  25 + //}
  26 + //m.Id = dm.Id
  27 + if err = tx.Insert(m); err != nil {
  28 + return nil, err
  29 + }
  30 + return dm, nil
  31 + }
  32 + if err = tx.Update(m); err != nil {
  33 + return nil, err
  34 + }
  35 + return dm, nil
  36 +}
  37 +
  38 +func (repository *OrderRepository) Remove(Order *domain.Order) (*domain.Order, error) {
  39 + var (
  40 + tx = repository.transactionContext.PgTx
  41 + OrderModel = &models.Order{Id: Order.Identify().(int64)}
  42 + )
  43 + if _, err := tx.Model(OrderModel).Where("id = ?", Order.Id).Delete(); err != nil {
  44 + return Order, err
  45 + }
  46 + return Order, nil
  47 +}
  48 +
  49 +func (repository *OrderRepository) FindOne(queryOptions map[string]interface{}) (*domain.Order, error) {
  50 + tx := repository.transactionContext.PgTx
  51 + OrderModel := new(models.Order)
  52 + query := NewQuery(tx.Model(OrderModel), queryOptions)
  53 + query.SetWhere("order.id = ?", "id")
  54 + query.SetWhere("order.order_code = ?", "orderCode")
  55 + if err := query.First(); err != nil {
  56 + return nil, query.HandleError(err, "没有此订单")
  57 + }
  58 + if OrderModel.Id == 0 {
  59 + return nil, nil
  60 + }
  61 + return repository.transformPgModelToDomainModel(OrderModel)
  62 +}
  63 +
  64 +func (repository *OrderRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Order, error) {
  65 + tx := repository.transactionContext.PgTx
  66 + var OrderModels []*models.Order
  67 + Orders := make([]*domain.Order, 0)
  68 + query := NewQuery(tx.Model(&OrderModels), queryOptions)
  69 + query.
  70 + SetWhere("order.partner_id= ?", "partnerId").
  71 + SetWhere(`order.create_at >= ?`, "beginTime").
  72 + SetWhere(`order.create_at < ?`, "endTime").
  73 + SetLimit().
  74 + SetOrder("order.create_at", "sortByCreateTime").
  75 + SetOrder("order.update_at", "sortByUpdateTime")
  76 + var err error
  77 + if query.AffectRow, err = query.SelectAndCount(); err != nil {
  78 + return 0, Orders, err
  79 + }
  80 + for _, OrderModel := range OrderModels {
  81 + if Order, err := repository.transformPgModelToDomainModel(OrderModel); err != nil {
  82 + return 0, Orders, err
  83 + } else {
  84 + Orders = append(Orders, Order)
  85 + }
  86 + }
  87 + return int64(query.AffectRow), Orders, nil
  88 +}
  89 +
  90 +func (repository *OrderRepository) transformPgModelToDomainModel(OrderModel *models.Order) (*domain.Order, error) {
  91 + m := &domain.Order{}
  92 + err := GobModelTransform(m, OrderModel)
  93 + return m, err
  94 +}
  95 +
  96 +func NewOrderRepository(transactionContext *transaction.TransactionContext) (*OrderRepository, error) {
  97 + if transactionContext == nil {
  98 + return nil, ERR_EMPTY_TC
  99 + }
  100 + return &OrderRepository{transactionContext: transactionContext}, nil
  101 +}
  1 +package utils
  2 +
  3 +import (
  4 + "bytes"
  5 + "encoding/gob"
  6 + "encoding/json"
  7 + "errors"
  8 + "fmt"
  9 + "reflect"
  10 + "strconv"
  11 + "strings"
  12 +)
  13 +
  14 +// 此函数将指定的结构体成员值更新到结构体中
  15 +func SetStructValueByType(s interface{}, columnType string, columnValue interface{}) error {
  16 + columnValueV := reflect.ValueOf(columnValue)
  17 + var setValue reflect.Value
  18 + var flag = false
  19 + v := reflect.ValueOf(s)
  20 + for i, n := 0, v.Elem().NumField(); i < n; i++ {
  21 + if v.Elem().Type().Field(i).Name == columnType {
  22 + setValue = v.Elem().Field(i)
  23 + flag = true
  24 + break
  25 + }
  26 + }
  27 + if !flag {
  28 + return errors.New("struct is not type:")
  29 + } else if !setValue.CanSet() {
  30 + return errors.New("setValue.CanSet is false")
  31 + } else if setValue.Kind() != columnValueV.Kind() {
  32 + return errors.New("struct field and value of type is error")
  33 + }
  34 + switch columnValueV.Kind() {
  35 + case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int, reflect.Int64:
  36 + setValue.SetInt(int64(columnValueV.Int()))
  37 + case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
  38 + setValue.SetUint(uint64(columnValueV.Uint()))
  39 + case reflect.Float32, reflect.Float64:
  40 + setValue.SetFloat(float64(columnValueV.Float()))
  41 + case reflect.String:
  42 + setValue.SetString(columnValueV.String())
  43 + case reflect.Struct:
  44 + setValue.Set(columnValueV)
  45 + default:
  46 + return errors.New("columnValue err for:" + columnType)
  47 + }
  48 + return nil
  49 +}
  50 +
  51 +func JoinInts(ids []int, spilt string) string {
  52 + var idStrings []string = make([]string, len(ids))
  53 + for i := 0; i < len(ids); i++ {
  54 + idStrings[i] = fmt.Sprintf("%v", ids[i])
  55 + }
  56 + return strings.Join(idStrings, spilt)
  57 +}
  58 +func JoinInt8s(ids []int8, spilt string) string {
  59 + var idStrings []string = make([]string, len(ids))
  60 + for i := 0; i < len(ids); i++ {
  61 + idStrings[i] = fmt.Sprintf("%v", ids[i])
  62 + }
  63 + return strings.Join(idStrings, spilt)
  64 +}
  65 +func JoinInt64s(ids []int64, spilt string) string {
  66 + var idStrings []string = make([]string, len(ids))
  67 + for i := 0; i < len(ids); i++ {
  68 + idStrings[i] = fmt.Sprintf("%v", ids[i])
  69 + }
  70 + return strings.Join(idStrings, spilt)
  71 +}
  72 +
  73 +//判断是否为空
  74 +func IsNil(i interface{}) bool {
  75 + vi := reflect.ValueOf(i)
  76 + if vi.Kind() == reflect.Ptr {
  77 + return vi.IsNil()
  78 + }
  79 + return false
  80 +}
  81 +
  82 +func JsonUnmarshal(jsonData string, v interface{}) {
  83 + if len(jsonData) == 0 {
  84 + return
  85 + }
  86 + if e := json.Unmarshal([]byte(jsonData), v); e != nil {
  87 +
  88 + }
  89 +}
  90 +
  91 +func JsonAssertString(v interface{}) string {
  92 + if data, e := json.Marshal(v); e == nil {
  93 + return string(data)
  94 + }
  95 + return ""
  96 +}
  97 +
  98 +//深度拷贝
  99 +func DeepCopy(dst, src interface{}) error {
  100 + var buf bytes.Buffer
  101 + if err := gob.NewEncoder(&buf).Encode(src); err != nil {
  102 + return err
  103 + }
  104 + return gob.NewDecoder(&buf).Decode(dst)
  105 +}
  106 +
  107 +//深度拷贝
  108 +func JsonDeepCopy(dst, src interface{}) error {
  109 + var buf bytes.Buffer
  110 + if err := json.NewEncoder(&buf).Encode(src); err != nil {
  111 + return err
  112 + }
  113 + return json.NewDecoder(&buf).Decode(dst)
  114 +}
  115 +
  116 +//检查版本信息
  117 +func ValidVersion(current, compare string) bool {
  118 + curVersions := strings.Split(current, ".")
  119 + comVersions := strings.Split(compare, ".")
  120 + for i := range curVersions {
  121 + //v1,v2:=strings.TrimSpace(curVersions[i]),""
  122 + v1, _ := strconv.ParseInt(strings.TrimSpace(curVersions[i]), 10, 64)
  123 + var v2 int64
  124 + if i < len(comVersions) {
  125 + v2, _ = strconv.ParseInt(strings.TrimSpace(comVersions[i]), 10, 64)
  126 + }
  127 + if v1 == 0 && v2 == 0 {
  128 + continue
  129 + }
  130 + if v1 >= v2 {
  131 + return true
  132 + }
  133 + if v1 < v2 {
  134 + return false
  135 + }
  136 + }
  137 + return false
  138 +}
  139 +
  140 +// 统计某函数执行时间
  141 +// 使用方式
  142 +// defer utils.Profiling("test")()
  143 +//func Profiling(msg string) func() {
  144 +// start := time.Now()
  145 +// return func() {
  146 +// log.Info(fmt.Sprintf("%s[%s]:%s", msg, "use", time.Since(start)))
  147 +// }
  148 +//}
  149 +
  150 +//合并字典
  151 +func MergeMap(to map[string]interface{}, from map[string]interface{}) {
  152 + for k, v := range from {
  153 + to[k] = v
  154 + }
  155 +}
  156 +
  157 +func GetPageInfo(pageIndex, pageSize int) (offset, size int) {
  158 + if pageSize == 0 {
  159 + pageSize = 20
  160 + }
  161 + if pageIndex == 0 {
  162 + pageIndex = 1
  163 + }
  164 + offset = (pageIndex - 1) * pageSize
  165 + size = pageSize
  166 + return
  167 +}
1 -package constant 1 +package log
2 2
3 import ( 3 import (
  4 + "github.com/astaxie/beego"
4 "github.com/astaxie/beego/logs" 5 "github.com/astaxie/beego/logs"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" 6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
6 "path/filepath" 7 "path/filepath"
@@ -40,3 +41,16 @@ func NewBeegoLogger(conf LoggerConfig) *logs.BeeLogger { @@ -40,3 +41,16 @@ func NewBeegoLogger(conf LoggerConfig) *logs.BeeLogger {
40 log.SetLogFuncCallDepth(3) 41 log.SetLogFuncCallDepth(3)
41 return log 42 return log
42 } 43 }
  44 +
  45 +func Debug(args ...interface{}) {
  46 + beego.Debug(args...)
  47 +}
  48 +func Info(args ...interface{}) {
  49 + beego.Info(args...)
  50 +}
  51 +func Warn(args ...interface{}) {
  52 + beego.Warn(args...)
  53 +}
  54 +func Error(args ...interface{}) {
  55 + beego.Error(args...)
  56 +}
@@ -4,11 +4,12 @@ import ( @@ -4,11 +4,12 @@ import (
4 "github.com/astaxie/beego" 4 "github.com/astaxie/beego"
5 "github.com/linmadan/egglib-go/web/beego/filters" 5 "github.com/linmadan/egglib-go/web/beego/filters"
6 . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" 6 . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
  7 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/middleware"
7 _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/routers" 8 _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/routers"
8 ) 9 )
9 10
10 func init() { 11 func init() {
11 beego.InsertFilter("/*", beego.BeforeExec, filters.CreateRequestBodyFilter()) 12 beego.InsertFilter("/*", beego.BeforeExec, filters.CreateRequestBodyFilter())
12 - beego.InsertFilter("/*", beego.BeforeExec, CreateRequstLogFilter(Logger))  
13 - beego.InsertFilter("/*", beego.AfterExec, CreateResponseLogFilter(Logger), false) 13 + beego.InsertFilter("/*", beego.BeforeExec, middleware.CreateRequstLogFilter(Logger))
  14 + beego.InsertFilter("/*", beego.AfterExec, middleware.CreateResponseLogFilter(Logger), false)
14 } 15 }
@@ -28,3 +28,83 @@ func (this *UserController) UserInfo() { @@ -28,3 +28,83 @@ func (this *UserController) UserInfo() {
28 header := this.GetRequestHeader(this.Ctx) 28 header := this.GetRequestHeader(this.Ctx)
29 msg = protocol.NewReturnResponse(user.UserInfo(header, request)) 29 msg = protocol.NewReturnResponse(user.UserInfo(header, request))
30 } 30 }
  31 +
  32 +//CheckSmsCode
  33 +// @router /checkSmsCode [post]
  34 +func (this *UserController) CheckSmsCode() {
  35 + var msg *protocol.ResponseMessage
  36 + defer func() {
  37 + this.Resp(msg)
  38 + }()
  39 + var request *protocol.CheckSmsCodeRequest
  40 + if err := this.JsonUnmarshal(&request); err != nil {
  41 + msg = protocol.BadRequestParam(1)
  42 + return
  43 + }
  44 + if b, m := this.Valid(request); !b {
  45 + msg = m
  46 + return
  47 + }
  48 + header := this.GetRequestHeader(this.Ctx)
  49 + msg = protocol.NewReturnResponse(user.CheckSmsCode(header, request))
  50 +}
  51 +
  52 +//ChangePhone
  53 +// @router /changePhone [post]
  54 +func (this *UserController) ChangePhone() {
  55 + var msg *protocol.ResponseMessage
  56 + defer func() {
  57 + this.Resp(msg)
  58 + }()
  59 + var request *protocol.ChangePhoneRequest
  60 + if err := this.JsonUnmarshal(&request); err != nil {
  61 + msg = protocol.BadRequestParam(1)
  62 + return
  63 + }
  64 + if b, m := this.Valid(request); !b {
  65 + msg = m
  66 + return
  67 + }
  68 + header := this.GetRequestHeader(this.Ctx)
  69 + msg = protocol.NewReturnResponse(user.ChangePhone(header, request))
  70 +}
  71 +
  72 +//ResetPassword
  73 +// @router /resetPassword [post]
  74 +func (this *UserController) ResetPassword() {
  75 + var msg *protocol.ResponseMessage
  76 + defer func() {
  77 + this.Resp(msg)
  78 + }()
  79 + var request *protocol.ResetPasswordRequest
  80 + if err := this.JsonUnmarshal(&request); err != nil {
  81 + msg = protocol.BadRequestParam(1)
  82 + return
  83 + }
  84 + if b, m := this.Valid(request); !b {
  85 + msg = m
  86 + return
  87 + }
  88 + header := this.GetRequestHeader(this.Ctx)
  89 + msg = protocol.NewReturnResponse(user.ResetPassword(header, request))
  90 +}
  91 +
  92 +//ChangePassword
  93 +// @router /changePassword [post]
  94 +func (this *UserController) ChangePassword() {
  95 + var msg *protocol.ResponseMessage
  96 + defer func() {
  97 + this.Resp(msg)
  98 + }()
  99 + var request *protocol.ChangePasswordRequest
  100 + if err := this.JsonUnmarshal(&request); err != nil {
  101 + msg = protocol.BadRequestParam(1)
  102 + return
  103 + }
  104 + if b, m := this.Valid(request); !b {
  105 + msg = m
  106 + return
  107 + }
  108 + header := this.GetRequestHeader(this.Ctx)
  109 + msg = protocol.NewReturnResponse(user.ChangePassword(header, request))
  110 +}
1 -package constant 1 +package middleware
2 2
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
1 package protocol 1 package protocol
2 2
3 var errmessge ErrorMap = map[int]string{ 3 var errmessge ErrorMap = map[int]string{
4 - 0: "成功",  
5 - 1: "系统异常",  
6 - 2: "参数错误",  
7 - 113: "签名验证失败",  
8 - 502: "用户不存在", 4 + 0: "成功",
  5 + 1: "系统异常",
  6 + 2: "参数错误",
  7 + 113: "签名验证失败",
  8 +
  9 + 502: "用户不存在",
  10 +
  11 + 1009: "验证码已失效",
  12 + 1011: "获取验证码次数超出限制,请联系管理员",
  13 + 1012: "请输入正确的验证码",
  14 +
  15 + 2021: "登录失败,手机号或密码错误",
  16 + 2025: "短信验证码验证失败",
  17 + 2026: "新密码与确认密码不一致",
  18 + 2027: "密码必须至少有6个字符",
  19 + 2028: "请输入正确的旧密码",
  20 + 2029: "当前手机号已存在,请重新输入",
  21 + 2030: "新密码与旧密码一致,请重新输入",
  22 +
9 4139: "authCode无效或过期", 23 4139: "authCode无效或过期",
10 4140: "refreshToken过期,需要重新登录授权", 24 4140: "refreshToken过期,需要重新登录授权",
11 4141: "accessToken过期或无效,需要进行重新获取令牌", 25 4141: "accessToken过期或无效,需要进行重新获取令牌",
@@ -27,3 +27,35 @@ type Company struct { @@ -27,3 +27,35 @@ type Company struct {
27 Id int `json:"id"` 27 Id int `json:"id"`
28 Name string `json:"name"` 28 Name string `json:"name"`
29 } 29 }
  30 +
  31 +/*修改手机号-验证旧手机验证码 */
  32 +type CheckSmsCodeRequest struct {
  33 + Captcha string `json:"captcha" valid:"Required"`
  34 +}
  35 +type CheckSmsCodeResponse struct {
  36 +}
  37 +
  38 +/*修改手机号*/
  39 +type ChangePhoneRequest struct {
  40 + Phone string `json:"phone" valid:"Mobile"`
  41 + Captcha string `json:"captcha" valid:"Required"`
  42 +}
  43 +type ChangePhoneResponse struct {
  44 +}
  45 +
  46 +/*ResetPassword */
  47 +type ResetPasswordRequest struct {
  48 + NewPwd string `json:"newPwd" valid:"Required"`
  49 + ConfirmPwd string `json:"confirmPwd" valid:"Required"`
  50 +}
  51 +type ResetPasswordResponse struct {
  52 +}
  53 +
  54 +/*ChangePassword */
  55 +type ChangePasswordRequest struct {
  56 + NewPwd string `json:"newPwd" valid:"Required"`
  57 + ConfirmPwd string `json:"confirmPwd" valid:"Required"`
  58 + OldPwd string `json:"oldPwd" valid:"Required"`
  59 +}
  60 +type ChangePasswordResponse struct {
  61 +}
@@ -7,7 +7,7 @@ import ( @@ -7,7 +7,7 @@ import (
7 ) 7 )
8 8
9 func init() { 9 func init() {
10 - nsV1 := beego.NewNamespace("v1", beego.NSBefore(middleware.CheckJWTToken))//beego.NSNamespace("auth", beego.NSInclude(&controllers.AuthController{})), 10 + nsV1 := beego.NewNamespace("v1", beego.NSBefore(middleware.CheckJWTToken)) //beego.NSNamespace("auth", beego.NSInclude(&controllers.AuthController{})),
11 11
12 nsV1.Router("auth/login", &controllers.AuthController{}, "Post:Login") 12 nsV1.Router("auth/login", &controllers.AuthController{}, "Post:Login")
13 nsV1.Router("auth/smsCode", &controllers.AuthController{}, "Post:SmsCode") 13 nsV1.Router("auth/smsCode", &controllers.AuthController{}, "Post:SmsCode")
@@ -17,5 +17,9 @@ func init() { @@ -17,5 +17,9 @@ func init() {
17 nsV1.Router("auth/updateDevice", &controllers.AuthController{}, "Post:UpdateDevice") 17 nsV1.Router("auth/updateDevice", &controllers.AuthController{}, "Post:UpdateDevice")
18 18
19 nsV1.Router("user/userInfo", &controllers.UserController{}, "Post:UserInfo") 19 nsV1.Router("user/userInfo", &controllers.UserController{}, "Post:UserInfo")
  20 + nsV1.Router("user/checkSmsCode", &controllers.UserController{}, "Post:CheckSmsCode")
  21 + nsV1.Router("user/ChangePhone", &controllers.UserController{}, "Post:ChangePhone")
  22 + nsV1.Router("user/resetPassword", &controllers.UserController{}, "Post:ResetPassword")
  23 + nsV1.Router("user/changePassword", &controllers.UserController{}, "Post:ChangePassword")
20 beego.AddNamespace(nsV1) 24 beego.AddNamespace(nsV1)
21 } 25 }
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query" 5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query"
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service" 6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service"
7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/service_gateway"
8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" 9 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
9 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/protocol" 10 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/protocol"
10 "strings" 11 "strings"
@@ -41,6 +42,15 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp @@ -41,6 +42,15 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp
41 } 42 }
42 43
43 func SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.LoginResponse, err error) { 44 func SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.LoginResponse, err error) {
  45 + var data map[string]interface{}
  46 + sms := service_gateway.NewHttplibMmmSmsApiServiceGateway()
  47 + data, err = sms.SendSms(request.Phone)
  48 + if err != nil {
  49 + if msg, ok := data["msg"]; ok {
  50 + err = protocol.NewCustomMessage(1, msg.(string))
  51 + }
  52 + return
  53 + }
44 return 54 return
45 } 55 }
46 56
@@ -82,3 +92,17 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT @@ -82,3 +92,17 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT
82 return 92 return
83 return 93 return
84 } 94 }
  95 +
  96 +//验证短信验证码 T
  97 +func CheckSmsCode(phone, code string) (result bool, err error) {
  98 + sms := service_gateway.NewHttplibMmmSmsApiServiceGateway()
  99 + _, err = sms.CheckSmsCode(phone, code)
  100 + var data map[string]interface{}
  101 + if err != nil {
  102 + if msg, ok := data["msg"]; ok {
  103 + err = protocol.NewCustomMessage(1, msg.(string))
  104 + }
  105 + return
  106 + }
  107 + return
  108 +}
1 package user 1 package user
2 2
3 import ( 3 import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/command"
4 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query" 5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service" 6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service"
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/protocol" 9 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/protocol"
  10 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/services/auth"
  11 + "strings"
8 ) 12 )
9 13
10 //用户信息 14 //用户信息
@@ -34,3 +38,102 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) @@ -34,3 +38,102 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
34 } 38 }
35 return 39 return
36 } 40 }
  41 +
  42 +//验证smscode
  43 +func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCodeRequest) (rsp *protocol.CheckSmsCodeResponse, err error) {
  44 + var (
  45 + PartnerInfoService = service.NewPartnerInfoService(nil)
  46 + partnerInfo *domain.PartnerInfo
  47 + result bool
  48 + )
  49 + if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil {
  50 + err = protocol.NewErrWithMessage(502, err) //账号不存在
  51 + return
  52 + }
  53 + if result, err = auth.CheckSmsCode(strings.TrimSpace(partnerInfo.Account), request.Captcha); err != nil {
  54 + log.Error(err)
  55 + return
  56 + }
  57 + if !result {
  58 + err = protocol.NewErrWithMessage(1012)
  59 + }
  60 + return
  61 +}
  62 +
  63 +//修改手机号
  64 +func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRequest) (rsp *protocol.ChangePhoneResponse, err error) {
  65 + var (
  66 + PartnerInfoService = service.NewPartnerInfoService(nil)
  67 + )
  68 + if _, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil {
  69 + err = protocol.NewErrWithMessage(502, err) //账号不存在
  70 + return
  71 + }
  72 + if _, err = auth.CheckSmsCode(request.Phone, request.Captcha); err != nil {
  73 + log.Error(err)
  74 + return
  75 + }
  76 + if _, err = PartnerInfoService.UpdatePartnerInfo(&command.UpdatePartnerInfoCommand{Account: request.Phone}); err == nil {
  77 + err = protocol.NewErrWithMessage(502, err) //账号不存在
  78 + return
  79 + }
  80 + return
  81 +}
  82 +
  83 +//重置密码
  84 +func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) {
  85 + var (
  86 + PartnerInfoService = service.NewPartnerInfoService(nil)
  87 + //partnerInfo *domain.PartnerInfo
  88 + )
  89 + if len(request.NewPwd) < 6 {
  90 + err = protocol.NewErrWithMessage(2027)
  91 + return
  92 + }
  93 + if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
  94 + err = protocol.NewErrWithMessage(2026)
  95 + return
  96 + }
  97 + if _, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil {
  98 + err = protocol.NewErrWithMessage(502, err) //账号不存在
  99 + return
  100 + }
  101 + if _, err = PartnerInfoService.UpdatePartnerInfo(&command.UpdatePartnerInfoCommand{Password: request.ConfirmPwd}); err == nil {
  102 + return
  103 + }
  104 + return
  105 +}
  106 +
  107 +//修改密码
  108 +func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePasswordRequest) (rsp *protocol.ChangePasswordResponse, err error) {
  109 + var (
  110 + PartnerInfoService = service.NewPartnerInfoService(nil)
  111 + partnerInfo *domain.PartnerInfo
  112 + )
  113 + rsp = &protocol.ChangePasswordResponse{}
  114 + if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
  115 + err = protocol.NewErrWithMessage(2026)
  116 + return
  117 + }
  118 + if strings.EqualFold(request.NewPwd, request.OldPwd) {
  119 + err = protocol.NewErrWithMessage(2030)
  120 + return
  121 + }
  122 + if len(request.NewPwd) < 6 {
  123 + err = protocol.NewErrWithMessage(2027)
  124 + return
  125 + }
  126 + if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil {
  127 + err = protocol.NewErrWithMessage(502, err) //账号不存在
  128 + return
  129 + }
  130 + if !strings.EqualFold(partnerInfo.Password, request.OldPwd) {
  131 + //密码不一致
  132 + err = protocol.NewErrWithMessage(2028, err) //账号不存在
  133 + return
  134 + }
  135 + if _, err = PartnerInfoService.UpdatePartnerInfo(&command.UpdatePartnerInfoCommand{Password: request.ConfirmPwd}); err == nil {
  136 + return
  137 + }
  138 + return
  139 +}