Browse Source

Merge branch 'master' of https://git.tetele.net/tgo/userrpc

master
listen 3 years ago
parent
commit
dee100d277
10 changed files with 1055 additions and 43 deletions
  1. +718
    -5
      account.client.go
  2. +154
    -11
      account.client_test.go
  3. +7
    -0
      common.go
  4. +75
    -0
      fans.client.go
  5. +16
    -0
      fans.client_test.go
  6. +1
    -1
      go.mod
  7. +4
    -4
      go.sum
  8. +10
    -22
      user.client.go
  9. +56
    -0
      user.pb.go
  10. +14
    -0
      user.proto

+ 718
- 5
account.client.go View File

@ -3,12 +3,65 @@ package userrpc
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"log"
) )
type GetAddReq struct {
Req
UserId string
Value string
Memo string
Source string
SourceId string
}
type GetUpdateReq struct {
Req
UserId string
Value string
UsedValue string
}
type GetLogReq struct {
Req
UserId string
Value string
Before string
After string
Source string
SourceId string
OrderSn string
Target string
TargetId string
ProductThumb string
Memo string
}
type GetUpgradeLogReq struct {
Req
UserId string
Upgrade string
Before string
After string
Source string
Memo string
}
type GetCouponReq struct {
Req
UserId string
CouponId string
ExpireTime string
OrderSn string
Remark string
IsUse string
Usertime string
}
/** /**
* 获取用户积分 * 获取用户积分
*/ */
func GetUserScore(dbname,userId string, url ...string) (string, error) {
func GetUserScore(dbname, userId string, url ...string) (string, error) {
if dbname == "" || userId == "" { if dbname == "" || userId == "" {
return "", errors.New("参数错误") return "", errors.New("参数错误")
@ -46,7 +99,7 @@ func GetUserScore(dbname,userId string, url ...string) (string, error) {
} }
var score string var score string
err = json.Unmarshal([]byte(res_data_de),&score)
err = json.Unmarshal([]byte(res_data_de), &score)
if err != nil { if err != nil {
return "", err return "", err
@ -58,7 +111,7 @@ func GetUserScore(dbname,userId string, url ...string) (string, error) {
/** /**
* 获取用户红包 * 获取用户红包
*/ */
func GetUserRedEnvelope(dbname,userId string, url ...string) (string, error) {
func GetUserRedEnvelope(dbname, userId string, url ...string) (string, error) {
if dbname == "" || userId == "" { if dbname == "" || userId == "" {
return "", errors.New("参数错误") return "", errors.New("参数错误")
@ -96,11 +149,671 @@ func GetUserRedEnvelope(dbname,userId string, url ...string) (string, error) {
} }
var redEnvelope string var redEnvelope string
err = json.Unmarshal([]byte(res_data_de),&redEnvelope)
err = json.Unmarshal([]byte(res_data_de), &redEnvelope)
if err != nil { if err != nil {
return "", err return "", err
} }
return redEnvelope, nil return redEnvelope, nil
}
}
/**
* 添加积分
* @2021/09/30
* @bin
*/
func AddUserScore(dbname, userId, score, memo string, url ...string) (int64, error) {
if dbname == "" || userId == "" || score == "" {
return 0, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return 0, err
}
defer conn.Close()
data := GetAddReq{}
data.Dbname = dbname
data.UserId = userId
data.Value = score
data.Memo = memo
req, err := SetReqData(data)
if err != nil {
log.Println("AddUserScore crypter error:", err)
return 0, err
}
res := &Response{}
err = conn.AddUserScore(req, res)
if err != nil {
log.Println("userrpc AddUserScore error:", err)
return 0, err
}
res_data_de, err := GetResData(res)
if err != nil {
return 0, err
}
if res_data_de == "" {
return 0, nil
}
var insertId int64
err = json.Unmarshal([]byte(res_data_de), &insertId)
if err != nil {
return 0, err
}
return insertId, nil
}
/**
* 更新积分记录
* @2021/09/30
* @bin
*/
func UpdateUserScore(dbname, userId, score, used_score string, url ...string) (bool, error) {
if dbname == "" || userId == "" || score == "" {
return false, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return false, err
}
defer conn.Close()
data := GetUpdateReq{}
data.Dbname = dbname
data.UserId = userId
data.Value = score
data.UsedValue = used_score
req, err := SetReqData(data)
if err != nil {
log.Println("UpdateUserScore crypter error:", err)
return false, err
}
res := &Response{}
err = conn.UpdateUserScore(req, res)
if err != nil {
log.Println("userrpc UpdateUserScore error:", err)
return false, err
}
res_data_de, err := GetResData(res)
if err != nil {
return false, err
}
if res_data_de == "" {
return false, nil
}
var updateres bool
err = json.Unmarshal([]byte(res_data_de), &updateres)
if err != nil {
return false, err
}
return updateres, nil
}
/**
* 增加积分日志
* @2021/09/30
* @bin
*/
func AddUserScoreLog(dbname, UserId, Score, Before, After, Source, SourceId, OrderSn, Target, TargetId, ProductThumb, Memo string, url ...string) (int64, error) {
if dbname == "" || UserId == "" || Score == "" || After == "" {
return 0, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return 0, err
}
defer conn.Close()
data := GetLogReq{}
data.Dbname = dbname
data.UserId = UserId
data.Value = Score
data.Before = Before
data.After = After
data.Source = Source
data.SourceId = SourceId
data.OrderSn = OrderSn
data.Target = Target
data.TargetId = TargetId
data.ProductThumb = ProductThumb
data.Memo = Memo
req, err := SetReqData(data)
if err != nil {
log.Println("AddUserScoreLog crypter error:", err)
return 0, err
}
res := &Response{}
err = conn.AddUserScoreLog(req, res)
if err != nil {
log.Println("userrpc AddUserScoreLog error:", err)
return 0, err
}
res_data_de, err := GetResData(res)
if err != nil {
return 0, err
}
if res_data_de == "" {
return 0, nil
}
var insertId int64
err = json.Unmarshal([]byte(res_data_de), &insertId)
if err != nil {
return 0, err
}
return insertId, nil
}
/**
* 添加成长值
* @2021/09/30
* @bin
*/
func AddUserUpgrade(dbname, userId, upgrade, memo string, url ...string) (int64, error) {
if dbname == "" || userId == "" || upgrade == "" {
return 0, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return 0, err
}
defer conn.Close()
data := GetAddReq{}
data.Dbname = dbname
data.UserId = userId
data.Value = upgrade
data.Memo = memo
req, err := SetReqData(data)
if err != nil {
log.Println("AddUserUpgrade crypter error:", err)
return 0, err
}
res := &Response{}
err = conn.AddUserUpgrade(req, res)
if err != nil {
log.Println("userrpc AddUserUpgrade error:", err)
return 0, err
}
res_data_de, err := GetResData(res)
if err != nil {
return 0, err
}
if res_data_de == "" {
return 0, nil
}
var insertId int64
err = json.Unmarshal([]byte(res_data_de), &insertId)
if err != nil {
return 0, err
}
return insertId, nil
}
/**
* 更新成长值记录
* @2021/09/30
* @bin
*/
func UpdateUserUpgrade(dbname, userId, upgrade string, url ...string) (bool, error) {
if dbname == "" || userId == "" || upgrade == "" {
return false, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return false, err
}
defer conn.Close()
data := GetAddReq{}
data.Dbname = dbname
data.UserId = userId
data.Value = upgrade
req, err := SetReqData(data)
if err != nil {
log.Println("UpdateUserUpgrade crypter error:", err)
return false, err
}
res := &Response{}
err = conn.UpdateUserUpgrade(req, res)
if err != nil {
log.Println("userrpc UpdateUserUpgrade error:", err)
return false, err
}
res_data_de, err := GetResData(res)
if err != nil {
return false, err
}
if res_data_de == "" {
return false, nil
}
var updateres bool
err = json.Unmarshal([]byte(res_data_de), &updateres)
if err != nil {
return false, err
}
return updateres, nil
}
/**
* 增加成长值日志
* @2021/09/30
* @bin
*/
func AddUserUpgradeLog(dbname, UserId, Upgrade, Before, After, Source, Memo string, url ...string) (int64, error) {
if dbname == "" || UserId == "" || Upgrade == "" || After == "" {
return 0, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return 0, err
}
defer conn.Close()
data := GetUpgradeLogReq{}
data.Dbname = dbname
data.UserId = UserId
data.Upgrade = Upgrade
data.Before = Before
data.After = After
data.Source = Source
data.Memo = Memo
req, err := SetReqData(data)
if err != nil {
log.Println("AddUserUpgradeLog crypter error:", err)
return 0, err
}
res := &Response{}
err = conn.AddUserUpgradeLog(req, res)
if err != nil {
log.Println("userrpc AddUserUpgradeLog error:", err)
return 0, err
}
res_data_de, err := GetResData(res)
if err != nil {
return 0, err
}
if res_data_de == "" {
return 0, nil
}
var insertId int64
err = json.Unmarshal([]byte(res_data_de), &insertId)
if err != nil {
return 0, err
}
return insertId, nil
}
/**
* 添加红包
* @2021/09/30
* @bin
*/
func AddUserRedEnvelope(dbname, userId, money, memo string, url ...string) (int64, error) {
if dbname == "" || userId == "" || money == "" {
return 0, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return 0, err
}
defer conn.Close()
data := GetAddReq{}
data.Dbname = dbname
data.UserId = userId
data.Value = money
data.Memo = memo
req, err := SetReqData(data)
if err != nil {
log.Println("AddUserRedEnvelope crypter error:", err)
return 0, err
}
res := &Response{}
err = conn.AddUserRedEnvelope(req, res)
if err != nil {
log.Println("userrpc AddUserRedEnvelope error:", err)
return 0, err
}
res_data_de, err := GetResData(res)
if err != nil {
return 0, err
}
if res_data_de == "" {
return 0, nil
}
var insertId int64
err = json.Unmarshal([]byte(res_data_de), &insertId)
if err != nil {
return 0, err
}
return insertId, nil
}
/**
* 更新红包记录
* @2021/09/30
* @bin
*/
func UpdateUserRedEnvelope(dbname, userId, money, used_money string, url ...string) (bool, error) {
if dbname == "" || userId == "" || money == "" {
return false, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return false, err
}
defer conn.Close()
data := GetUpdateReq{}
data.Dbname = dbname
data.UserId = userId
data.Value = money
data.UsedValue = used_money
req, err := SetReqData(data)
if err != nil {
log.Println("UpdateUserRedEnvelope crypter error:", err)
return false, err
}
res := &Response{}
err = conn.UpdateUserRedEnvelope(req, res)
if err != nil {
log.Println("userrpc UpdateUserRedEnvelope error:", err)
return false, err
}
res_data_de, err := GetResData(res)
if err != nil {
return false, err
}
if res_data_de == "" {
return false, nil
}
var updateres bool
err = json.Unmarshal([]byte(res_data_de), &updateres)
if err != nil {
return false, err
}
return updateres, nil
}
/**
* 增加红包日志
* @2021/09/30
* @bin
*/
func AddUserRedEnvelopeLog(dbname, UserId, Money, Before, After, Source, SourceId, OrderSn, Target, TargetId, Memo string, url ...string) (int64, error) {
if dbname == "" || UserId == "" || Money == "" || After == "" {
return 0, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return 0, err
}
defer conn.Close()
data := GetLogReq{}
data.Dbname = dbname
data.UserId = UserId
data.Value = Money
data.Before = Before
data.After = After
data.Source = Source
data.SourceId = SourceId
data.OrderSn = OrderSn
data.Target = Target
data.TargetId = TargetId
data.Memo = Memo
req, err := SetReqData(data)
if err != nil {
log.Println("AddUserRedEnvelopeLog crypter error:", err)
return 0, err
}
res := &Response{}
err = conn.AddUserRedEnvelopeLog(req, res)
if err != nil {
log.Println("userrpc AddUserRedEnvelopeLog error:", err)
return 0, err
}
res_data_de, err := GetResData(res)
if err != nil {
return 0, err
}
if res_data_de == "" {
return 0, nil
}
var insertId int64
err = json.Unmarshal([]byte(res_data_de), &insertId)
if err != nil {
return 0, err
}
return insertId, nil
}
/**
* 添加优惠券
* @2021/09/30
* @bin
*/
func AddUserCoupon(dbname, userId, couponId, expireTime, orderSn, remark string, url ...string) (int64, error) {
if dbname == "" || userId == "" || couponId == "" {
return 0, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return 0, err
}
defer conn.Close()
data := GetCouponReq{}
data.Dbname = dbname
data.UserId = userId
data.CouponId = couponId
data.ExpireTime = expireTime
data.OrderSn = orderSn
data.Remark = remark
req, err := SetReqData(data)
if err != nil {
log.Println("AddUserCoupon crypter error:", err)
return 0, err
}
res := &Response{}
err = conn.AddUserCoupon(req, res)
if err != nil {
log.Println("userrpc AddUserCoupon error:", err)
return 0, err
}
res_data_de, err := GetResData(res)
if err != nil {
return 0, err
}
if res_data_de == "" {
return 0, nil
}
var insertId int64
err = json.Unmarshal([]byte(res_data_de), &insertId)
if err != nil {
return 0, err
}
return insertId, nil
}
/**
* 更新优惠券记录
* @2021/09/30
* @bin
*/
func UpdateUserCoupon(dbname, userId, couponId, remark, orderSn, isUse, usetime string, url ...string) (bool, error) {
if dbname == "" || userId == "" || couponId == "" {
return false, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return false, err
}
defer conn.Close()
data := GetCouponReq{}
data.Dbname = dbname
data.UserId = userId
data.CouponId = couponId
data.Remark = remark
data.OrderSn = orderSn
data.IsUse = isUse
data.Usertime = usetime
req, err := SetReqData(data)
if err != nil {
log.Println("UpdateUserCoupon crypter error:", err)
return false, err
}
res := &Response{}
err = conn.UpdateUserCoupon(req, res)
if err != nil {
log.Println("userrpc UpdateUserCoupon error:", err)
return false, err
}
res_data_de, err := GetResData(res)
if err != nil {
return false, err
}
if res_data_de == "" {
return false, nil
}
var updateres bool
err = json.Unmarshal([]byte(res_data_de), &updateres)
if err != nil {
return false, err
}
return updateres, nil
}

+ 154
- 11
account.client_test.go View File

@ -1,25 +1,168 @@
package userrpc package userrpc
import ( import (
"testing"
"strconv"
"testing"
"time"
) )
func Test_GetUserScore(t *testing.T) { func Test_GetUserScore(t *testing.T) {
dbname := "shop_v2"
id := "2"
dbname := "shop_v2_org"
id := "2"
ret, err := GetUserScore(dbname, id)
t.Log(ret)
t.Log(err)
ret, err := GetUserScore(dbname, id)
t.Log(ret)
t.Log(err)
} }
func Test_GetUserRedEnvelope(t *testing.T) { func Test_GetUserRedEnvelope(t *testing.T) {
dbname := "shop_v2"
id := "2"
dbname := "shop_v2_org"
id := "2"
ret, err := GetUserRedEnvelope(dbname, id)
t.Log(ret)
t.Log(err)
ret, err := GetUserRedEnvelope(dbname, id)
t.Log(ret)
t.Log(err)
}
func Test_AddUserScore(t *testing.T) {
dbname := "shop_v2_org"
userid := "2"
score := "20"
ret, err := AddUserScore(dbname, userid, score)
t.Log(ret)
t.Log(err)
}
func Test_UpdateUserScore(t *testing.T) {
dbname := "shop_v2_org"
userid := "2"
score := "400"
used_score := "300"
ret, err := UpdateUserScore(dbname, userid, score, used_score)
t.Log(ret)
t.Log(err)
}
func Test_AddUserScoreLog(t *testing.T) {
dbname := "shop_v2_org"
userid := "2"
score := "100"
before := "500"
after := "400"
Source := "task"
SourceId := ""
OrderSn := ""
Target := ""
TargetId := ""
ProductThumb := ""
Memo := ""
ret, err := AddUserScoreLog(dbname, userid, score, before, after, Source, SourceId, OrderSn, Target, TargetId, ProductThumb, Memo)
t.Log(ret)
t.Log(err)
}
func Test_AddUserUpgrade(t *testing.T) {
dbname := "shop_v2_org"
userid := "5"
upgrade := "100"
ret, err := AddUserUpgrade(dbname, userid, upgrade)
t.Log(ret)
t.Log(err)
}
func Test_UpdateUserUpgrade(t *testing.T) {
dbname := "shop_v2_org"
userid := "5"
upgrade := "100"
ret, err := UpdateUserUpgrade(dbname, userid, upgrade)
t.Log(ret)
t.Log(err)
}
func Test_AddUserUpgradeLog(t *testing.T) {
dbname := "shop_v2_org"
userid := "2"
upgrade := "20"
before := "11"
after := "31"
Source := "task"
Memo := ""
ret, err := AddUserUpgradeLog(dbname, userid, upgrade, before, after, Source, Memo)
t.Log(ret)
t.Log(err)
}
func Test_AddUserRedEnvelope(t *testing.T) {
dbname := "shop_v2_org"
userid := "5"
money := "20"
ret, err := AddUserRedEnvelope(dbname, userid, money)
t.Log(ret)
t.Log(err)
}
func Test_UpdateUserRedEnvelope(t *testing.T) {
dbname := "shop_v2_org"
userid := "2"
money := "40"
used_money := "1"
ret, err := UpdateUserRedEnvelope(dbname, userid, money, used_money)
t.Log(ret)
t.Log(err)
}
func Test_AddUserRedEnvelopeLog(t *testing.T) {
dbname := "shop_v2_org"
userid := "2"
money := "-1"
before := "41"
after := "40"
Source := "task"
SourceId := ""
OrderSn := "216304042479173922"
Target := ""
TargetId := ""
ProductThumb := ""
Memo := ""
ret, err := AddUserRedEnvelopeLog(dbname, userid, money, before, after, Source, SourceId, OrderSn, Target, TargetId, ProductThumb, Memo)
t.Log(ret)
t.Log(err)
}
func Test_AddUserCoupon(t *testing.T) {
dbname := "shop_v2_org"
userid := "2"
couponId := "6"
expired_time := "1634684122"
order_sn := ""
remark := "商品券"
ret, err := AddUserCoupon(dbname, userid, couponId, expired_time,order_sn,remark)
t.Log(ret)
t.Log(err)
}
func Test_UpdateUserCoupon(t *testing.T) {
dbname := "shop_v2_org"
userid := "2"
couponId := "6"
remark := "下单使用优惠券"
orderSn := "12345678910"
isUse := "1"
usetime := strconv.Itoa(int(time.Now().Unix()))
ret, err := UpdateUserCoupon(dbname, userid, couponId, remark, orderSn, isUse,usetime)
t.Log(ret)
t.Log(err)
} }

+ 7
- 0
common.go View File

@ -63,6 +63,13 @@ type Business struct {
IsOpen string IsOpen string
} }
type FansReq struct {
Req
UserId string
BusinessId string
Lock bool
}
func rpc_server_conn(url ...string) (*UserServiceClient, error) { func rpc_server_conn(url ...string) (*UserServiceClient, error) {
var rpc_url string var rpc_url string


+ 75
- 0
fans.client.go View File

@ -0,0 +1,75 @@
package userrpc
/**
* 绑定粉丝
* 2021/10/23
* gz
*/
func Fans(site_id, dbname, user_id, business_id string, url ...string) error {
conn, err := rpc_server_conn(url...)
if err != nil {
return err
}
defer conn.Close()
data := FansReq{}
data.SiteId = site_id
data.Dbname = dbname
data.UserId = user_id
data.BusinessId = business_id
data.Lock = false
req, err := SetReqData(data)
if err != nil {
return err
}
res := &Response{}
err = conn.Fans(req, res)
if err != nil {
return err
}
_, err = GetResData(res)
return nil
}
/**
* 绑定粉丝
* 2021/10/23
* gz
*/
func LockFans(site_id, dbname, user_id, business_id string, url ...string) error {
conn, err := rpc_server_conn(url...)
if err != nil {
return err
}
defer conn.Close()
data := FansReq{}
data.SiteId = site_id
data.Dbname = dbname
data.UserId = user_id
data.BusinessId = business_id
data.Lock = true
req, err := SetReqData(data)
if err != nil {
return err
}
res := &Response{}
err = conn.Fans(req, res)
if err != nil {
return err
}
_, err = GetResData(res)
return nil
}

+ 16
- 0
fans.client_test.go View File

@ -0,0 +1,16 @@
package userrpc
import (
"testing"
)
func Test_Fans(t *testing.T) {
dbname := "shop_v2"
user_id := "6"
business_id := "5"
err := LockFans("", dbname, user_id, business_id)
t.Log(err)
}

+ 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=


+ 10
- 22
user.client.go View File

@ -12,14 +12,11 @@ import (
func GetUserByToken(dbname, token string, url ...string) (map[string]string, error) { func GetUserByToken(dbname, token string, url ...string) (map[string]string, error) {
var user_rpc_url string = "127.0.0.1:7976"
if len(url) > 0 && url[0] != "" {
user_rpc_url = url[0]
}
conn, _, err := DialUserService("tcp", user_rpc_url)
conn, err := rpc_server_conn(url...)
if err != nil { if err != nil {
return map[string]string{}, err return map[string]string{}, err
} }
defer conn.Close() defer conn.Close()
req := &UserRequest{proto.String(dbname), proto.String(token), nil} req := &UserRequest{proto.String(dbname), proto.String(token), nil}
@ -47,8 +44,9 @@ func GetUserByToken(dbname, token string, url ...string) (map[string]string, err
"Usercode": res.GetUsercode(), "Usercode": res.GetUsercode(),
"GroupId": res.GetGroupId(), "GroupId": res.GetGroupId(),
"Type": res.GetType(), "Type": res.GetType(),
"ThirdId": res.GetThirdId(),
"Platform": res.GetPlatform(),
"ThirdId": res.GetThirdId(),
"Platform": res.GetPlatform(),
"LockFans": res.GetLockFans(),
}, nil }, nil
} }
@ -60,12 +58,8 @@ func GetUserByToken(dbname, token string, url ...string) (map[string]string, err
*/ */
func GetUserByUsername(dbname, username string, url ...string) (*UserResponse, error) { func GetUserByUsername(dbname, username string, url ...string) (*UserResponse, error) {
var user_rpc_url string = "127.0.0.1:7976"
if len(url) > 0 && url[0] != "" {
user_rpc_url = url[0]
}
conn, err := rpc_server_conn(url...)
conn, _, err := DialUserService("tcp", user_rpc_url)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -89,12 +83,8 @@ func GetUserByUsername(dbname, username string, url ...string) (*UserResponse, e
*/ */
func GetUserByUsercode(dbname, usercode string, url ...string) (*UserResponse, error) { func GetUserByUsercode(dbname, usercode string, url ...string) (*UserResponse, error) {
var user_rpc_url string = "127.0.0.1:7976"
if len(url) > 0 && url[0] != "" {
user_rpc_url = url[0]
}
conn, err := rpc_server_conn(url...)
conn, _, err := DialUserService("tcp", user_rpc_url)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -115,12 +105,10 @@ func GetUserByUsercode(dbname, usercode string, url ...string) (*UserResponse, e
func Login(dbname, account, password string, url ...string) (map[string]string, error) { func Login(dbname, account, password string, url ...string) (map[string]string, error) {
var user_rpc_url string = "127.0.0.1:7976"
if len(url) > 0 && url[0] != "" {
user_rpc_url = url[0]
conn, err := rpc_server_conn(url...)
if err != nil {
return map[string]string{}, err
} }
conn, _, err := DialUserService("tcp", user_rpc_url)
if err != nil { if err != nil {
return map[string]string{}, err return map[string]string{}, err
} }


+ 56
- 0
user.pb.go View File

@ -152,6 +152,7 @@ type UserResponse struct {
Type *string `protobuf:"bytes,13,opt,name=type" json:"type,omitempty"` Type *string `protobuf:"bytes,13,opt,name=type" json:"type,omitempty"`
ThirdId *string `protobuf:"bytes,14,opt,name=third_id" json:"third_id,omitempty"` ThirdId *string `protobuf:"bytes,14,opt,name=third_id" json:"third_id,omitempty"`
Platform *string `protobuf:"bytes,15,opt,name=platform" json:"platform,omitempty"` Platform *string `protobuf:"bytes,15,opt,name=platform" json:"platform,omitempty"`
LockFans *string `protobuf:"bytes,16,opt,name=lock_fans" json:"lock_fans,omitempty"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
} }
@ -264,6 +265,13 @@ func (m *UserResponse) GetPlatform() string {
return "" return ""
} }
func (m *UserResponse) GetLockFans() string {
if m != nil && m.LockFans != nil {
return *m.LockFans
}
return ""
}
// 用户登录请求结构 // 用户登录请求结构
type LoginRequest struct { type LoginRequest struct {
Dbname *string `protobuf:"bytes,1,opt,name=dbname" json:"dbname,omitempty"` Dbname *string `protobuf:"bytes,1,opt,name=dbname" json:"dbname,omitempty"`
@ -517,6 +525,18 @@ type UserService interface {
GetAddressInfo(in *Request, out *Response) error GetAddressInfo(in *Request, out *Response) error
GetUserScore(in *Request, out *Response) error GetUserScore(in *Request, out *Response) error
GetUserRedEnvelope(in *Request, out *Response) error GetUserRedEnvelope(in *Request, out *Response) error
AddUserScore(in *Request, out *Response) error
UpdateUserScore(in *Request, out *Response) error
AddUserScoreLog(in *Request, out *Response) error
AddUserUpgrade(in *Request, out *Response) error
UpdateUserUpgrade(in *Request, out *Response) error
AddUserUpgradeLog(in *Request, out *Response) error
AddUserRedEnvelope(in *Request, out *Response) error
UpdateUserRedEnvelope(in *Request, out *Response) error
AddUserRedEnvelopeLog(in *Request, out *Response) error
AddUserCoupon(in *Request, out *Response) error
UpdateUserCoupon(in *Request, out *Response) error
Fans(in *Request, out *Response) error
} }
// AcceptUserServiceClient accepts connections on the listener and serves requests // AcceptUserServiceClient accepts connections on the listener and serves requests
@ -627,6 +647,42 @@ func (c *UserServiceClient) GetUserScore(in *Request, out *Response) error {
func (c *UserServiceClient) GetUserRedEnvelope(in *Request, out *Response) error { func (c *UserServiceClient) GetUserRedEnvelope(in *Request, out *Response) error {
return c.Call("UserService.GetUserRedEnvelope", in, out) return c.Call("UserService.GetUserRedEnvelope", in, out)
} }
func (c *UserServiceClient) AddUserScore(in *Request, out *Response) error {
return c.Call("UserService.AddUserScore", in, out)
}
func (c *UserServiceClient) UpdateUserScore(in *Request, out *Response) error {
return c.Call("UserService.UpdateUserScore", in, out)
}
func (c *UserServiceClient) AddUserScoreLog(in *Request, out *Response) error {
return c.Call("UserService.AddUserScoreLog", in, out)
}
func (c *UserServiceClient) AddUserUpgrade(in *Request, out *Response) error {
return c.Call("UserService.AddUserUpgrade", in, out)
}
func (c *UserServiceClient) UpdateUserUpgrade(in *Request, out *Response) error {
return c.Call("UserService.UpdateUserUpgrade", in, out)
}
func (c *UserServiceClient) AddUserUpgradeLog(in *Request, out *Response) error {
return c.Call("UserService.AddUserUpgradeLog", in, out)
}
func (c *UserServiceClient) AddUserRedEnvelope(in *Request, out *Response) error {
return c.Call("UserService.AddUserRedEnvelope", in, out)
}
func (c *UserServiceClient) UpdateUserRedEnvelope(in *Request, out *Response) error {
return c.Call("UserService.UpdateUserRedEnvelope", in, out)
}
func (c *UserServiceClient) AddUserRedEnvelopeLog(in *Request, out *Response) error {
return c.Call("UserService.AddUserRedEnvelopeLog", in, out)
}
func (c *UserServiceClient) AddUserCoupon(in *Request, out *Response) error {
return c.Call("UserService.AddUserCoupon", in, out)
}
func (c *UserServiceClient) UpdateUserCoupon(in *Request, out *Response) error {
return c.Call("UserService.UpdateUserCoupon", in, out)
}
func (c *UserServiceClient) Fans(in *Request, out *Response) error {
return c.Call("UserService.Fans", in, out)
}
// DialUserService connects to an UserService at the specified network address. // DialUserService connects to an UserService at the specified network address.
func DialUserService(network, addr string) (*UserServiceClient, *rpc.Client, error) { func DialUserService(network, addr string) (*UserServiceClient, *rpc.Client, error) {


+ 14
- 0
user.proto View File

@ -39,6 +39,7 @@ message UserResponse {
string type = 13;// string type = 13;//
string third_id = 14; //token对应的third_id string third_id = 14; //token对应的third_id
string platform = 15; // string platform = 15; //
string lock_fans = 16; //
} }
// //
@ -100,4 +101,17 @@ 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); //
//rpc favoriteProduct(Request) returns (Response); //
rpc Fans(Request) returns (Response); //
} }

Loading…
Cancel
Save