Browse Source

定义积分、优惠券、成长值、红包等函数

master
lijianbin 3 years ago
parent
commit
f314462c21
5 changed files with 134 additions and 121 deletions
  1. +73
    -71
      account.client.go
  2. +45
    -45
      common.go
  3. +1
    -1
      go.mod
  4. +4
    -4
      go.sum
  5. +11
    -0
      user.proto

+ 73
- 71
account.client.go View File

@ -1,106 +1,108 @@
package userrpc package userrpc
import ( import (
"encoding/json"
"errors"
"encoding/json"
"errors"
) )
/** /**
* 获取用户积分 * 获取用户积分
*/ */
func GetUserScore(dbname,userId string, url ...string) (string, error) {
func GetUserScore(dbname, userId string, url ...string) (string, error) {
if dbname == "" || userId == "" {
return "", errors.New("参数错误")
}
if dbname == "" || userId == "" {
return "", errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return "", err
}
defer conn.Close()
conn, err := rpc_server_conn(url...)
if err != nil {
return "", err
}
defer conn.Close()
data := GetUserReq{}
data.Dbname = dbname
data.UserId = userId
data := GetUserReq{}
data.Dbname = dbname
data.UserId = userId
req, err := SetReqData(data)
if err != nil {
return "", err
}
req, err := SetReqData(data)
if err != nil {
return "", err
}
res := &Response{}
res := &Response{}
err = conn.GetUserScore(req, res)
err = conn.GetUserScore(req, res)
if err != nil {
return "", err
}
if err != nil {
return "", err
}
res_data_de, err := GetResData(res)
if err != nil {
return "", err
}
if res_data_de == "" {
return "", nil
}
res_data_de, err := GetResData(res)
if err != nil {
return "", err
}
if res_data_de == "" {
return "", nil
}
var score string
err = json.Unmarshal([]byte(res_data_de),&score)
var score string
err = json.Unmarshal([]byte(res_data_de), &score)
if err != nil {
return "", err
}
if err != nil {
return "", err
}
return score, nil
return score, nil
} }
/** /**
* 获取用户红包 * 获取用户红包
*/ */
func GetUserRedEnvelope(dbname,userId string, url ...string) (string, error) {
func GetUserRedEnvelope(dbname, userId string, url ...string) (string, error) {
if dbname == "" || userId == "" {
return "", errors.New("参数错误")
}
if dbname == "" || userId == "" {
return "", errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return "", err
}
defer conn.Close()
conn, err := rpc_server_conn(url...)
if err != nil {
return "", err
}
defer conn.Close()
data := GetUserReq{}
data.Dbname = dbname
data.UserId = userId
data := GetUserReq{}
data.Dbname = dbname
data.UserId = userId
req, err := SetReqData(data)
if err != nil {
return "", err
}
req, err := SetReqData(data)
if err != nil {
return "", err
}
res := &Response{}
res := &Response{}
err = conn.GetUserRedEnvelope(req, res)
err = conn.GetUserRedEnvelope(req, res)
if err != nil {
return "", err
}
if err != nil {
return "", err
}
res_data_de, err := GetResData(res)
if err != nil {
return "", err
}
if res_data_de == "" {
return "", nil
}
res_data_de, err := GetResData(res)
if err != nil {
return "", err
}
if res_data_de == "" {
return "", nil
}
var redEnvelope string
err = json.Unmarshal([]byte(res_data_de),&redEnvelope)
var redEnvelope string
err = json.Unmarshal([]byte(res_data_de), &redEnvelope)
if err != nil {
return "", err
}
return redEnvelope, nil
}
if err != nil {
return "", err
}
return redEnvelope, nil
}

+ 45
- 45
common.go View File

@ -1,83 +1,83 @@
package userrpc package userrpc
import ( import (
"git.tetele.net/tgo/conf"
"git.tetele.net/tgo/conf"
) )
const DES_KEY = "usersrpc" const DES_KEY = "usersrpc"
type Req struct { type Req struct {
SiteId string
Dbname string
SiteId string
Dbname string
} }
type Third struct { type Third struct {
Userid string
Platform string
Openid string
Openname string
Unionid string
Avatar string
Mobile string
Userid string
Platform string
Openid string
Openname string
Unionid string
Avatar string
Mobile string
} }
type BindThirdReq struct { type BindThirdReq struct {
Req
Third
Req
Third
} }
type GetThirdReq struct { type GetThirdReq struct {
Req
Userid string
Platform string
Req
Userid string
Platform string
} }
type GetBusinessReq struct { type GetBusinessReq struct {
Req
BusinessId string
Req
BusinessId string
} }
type GetUserReq struct { type GetUserReq struct {
Req
UserId string
Req
UserId string
} }
type GetAddressReq struct { type GetAddressReq struct {
Req
AddressId string
Req
AddressId string
} }
type Res struct { type Res struct {
Errcode int
Errmsg string
Errcode int
Errmsg string
} }
type Business struct { type Business struct {
Type string
BusinessId string
CustomerId string
Name string
CompanyId string
Contact string
Mobile string
HandingFee string
IsOpen string
Type string
BusinessId string
CustomerId string
Name string
CompanyId string
Contact string
Mobile string
HandingFee string
IsOpen string
} }
func rpc_server_conn(url ...string) (*UserServiceClient, error) { func rpc_server_conn(url ...string) (*UserServiceClient, error) {
var rpc_url string
if len(url) > 0 && url[0] != "" {
rpc_url = url[0]
} else if conf.USER_RPC_URL != "" {
rpc_url = conf.USER_RPC_URL
} else {
rpc_url = "127.0.0.1:" + conf.USER_RPC_PORT
}
var rpc_url string
if len(url) > 0 && url[0] != "" {
rpc_url = url[0]
} else if conf.USER_RPC_URL != "" {
rpc_url = conf.USER_RPC_URL
} else {
rpc_url = "127.0.0.1:" + conf.USER_RPC_PORT
}
conn, _, err := DialUserService("tcp", rpc_url)
if err != nil {
return nil, err
}
conn, _, err := DialUserService("tcp", rpc_url)
if err != nil {
return nil, err
}
return conn, nil
return conn, nil
} }

+ 1
- 1
go.mod View File

@ -5,7 +5,7 @@ go 1.14
require ( require (
git.tetele.net/tgo/conf v0.33.1 git.tetele.net/tgo/conf v0.33.1
git.tetele.net/tgo/crypter v0.2.2 git.tetele.net/tgo/crypter v0.2.2
github.com/chai2010/protorpc v1.0.0
github.com/chai2010/protorpc v1.1.3
github.com/golang/protobuf v1.0.0 github.com/golang/protobuf v1.0.0
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect


+ 4
- 4
go.sum View File

@ -2,12 +2,12 @@ git.tetele.net/tgo/conf v0.33.1 h1:ZEIv3Vq35RCv5f3T3Uz97s2mkZLl7W5OlmXvzI3/sS8=
git.tetele.net/tgo/conf v0.33.1/go.mod h1:AWVIBEDE5dtotthUgR0SWaR2Qa6/f+O5WQ3s7Tj8q7A= git.tetele.net/tgo/conf v0.33.1/go.mod h1:AWVIBEDE5dtotthUgR0SWaR2Qa6/f+O5WQ3s7Tj8q7A=
git.tetele.net/tgo/crypter v0.2.2 h1:YMQJh2Gj5Po4ZfelJUmXBKi01UbmtiSy3bmqRfnYQMo= git.tetele.net/tgo/crypter v0.2.2 h1:YMQJh2Gj5Po4ZfelJUmXBKi01UbmtiSy3bmqRfnYQMo=
git.tetele.net/tgo/crypter v0.2.2/go.mod h1:vfvRLZA8+lHNgNXneOcgvVhDyuv25ZRb+C6xHOmXNx0= git.tetele.net/tgo/crypter v0.2.2/go.mod h1:vfvRLZA8+lHNgNXneOcgvVhDyuv25ZRb+C6xHOmXNx0=
github.com/chai2010/protorpc v1.0.0 h1:aJ45G9sl1utSKo35EqnBSTs5jqTpdJDJAuZMMYPAtFo=
github.com/chai2010/protorpc v1.0.0/go.mod h1:woR3WwjaQDqFjlzdVsFEKiK5Ur12QL8mYxVPjfr5z54=
github.com/chai2010/protorpc v1.1.3 h1:VJK5hIoZn0XCGol0GmbxZkUG6FbTI5LP2Lam6RVd15w=
github.com/chai2010/protorpc v1.1.3/go.mod h1:/wO0kiyVdu7ug8dCMrA2yDr2vLfyhsLEuzLa9J2HJ+I=
github.com/golang/protobuf v1.0.0 h1:lsek0oXi8iFE9L+EXARyHIjU5rlWIhhTkjDz3vHhWWQ= github.com/golang/protobuf v1.0.0 h1:lsek0oXi8iFE9L+EXARyHIjU5rlWIhhTkjDz3vHhWWQ=
github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.0-20170215233205-553a64147049 h1:K9KHZbXKpGydfDN0aZrsoHpLJlZsBrGMFWbgLDGnPZk=
github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=


+ 11
- 0
user.proto View File

@ -100,4 +100,15 @@ service UserService {
rpc getAddressInfo(Request) returns (Response); // rpc getAddressInfo(Request) returns (Response); //
rpc getUserScore(Request) returns (Response); // rpc getUserScore(Request) returns (Response); //
rpc getUserRedEnvelope(Request) returns (Response); // rpc getUserRedEnvelope(Request) returns (Response); //
rpc addUserScore(Request) returns (Response); //
rpc updateUserScore(Request) returns (Response); //
rpc addUserScoreLog(Request) returns (Response); //
rpc addUserUpgrade(Request) returns (Response); //
rpc updateUserUpgrade(Request) returns (Response); //
rpc addUserUpgradeLog(Request) returns (Response); //
rpc addUserRedEnvelope(Request) returns (Response); //
rpc updateUserRedEnvelope(Request) returns (Response); //
rpc addUserRedEnvelopeLog(Request) returns (Response); //
rpc addUserCoupon(Request) returns (Response); //
rpc updateUserCoupon(Request) returns (Response); //
} }

Loading…
Cancel
Save