diff --git a/account.client.go b/account.client.go index 44ee443..d12bfc9 100644 --- a/account.client.go +++ b/account.client.go @@ -3,12 +3,65 @@ package userrpc import ( "encoding/json" "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 == "" { return "", errors.New("参数错误") @@ -46,7 +99,7 @@ func GetUserScore(dbname,userId string, url ...string) (string, error) { } var score string - err = json.Unmarshal([]byte(res_data_de),&score) + err = json.Unmarshal([]byte(res_data_de), &score) if err != nil { 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 == "" { return "", errors.New("参数错误") @@ -96,11 +149,671 @@ func GetUserRedEnvelope(dbname,userId string, url ...string) (string, error) { } var redEnvelope string - err = json.Unmarshal([]byte(res_data_de),&redEnvelope) + err = json.Unmarshal([]byte(res_data_de), &redEnvelope) if err != nil { return "", err } return redEnvelope, nil -} \ No newline at end of file +} + +/** + * 添加积分 + * @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 +} diff --git a/account.client_test.go b/account.client_test.go index 9b86901..6c4bead 100644 --- a/account.client_test.go +++ b/account.client_test.go @@ -1,25 +1,168 @@ package userrpc import ( - "testing" + "strconv" + "testing" + "time" ) 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) { - 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) } diff --git a/common.go b/common.go index 6bf19bd..18019e6 100644 --- a/common.go +++ b/common.go @@ -63,6 +63,13 @@ type Business struct { IsOpen string } +type FansReq struct { + Req + UserId string + BusinessId string + Lock bool +} + func rpc_server_conn(url ...string) (*UserServiceClient, error) { var rpc_url string diff --git a/fans.client.go b/fans.client.go new file mode 100644 index 0000000..ce50c4c --- /dev/null +++ b/fans.client.go @@ -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 +} diff --git a/fans.client_test.go b/fans.client_test.go new file mode 100644 index 0000000..439d774 --- /dev/null +++ b/fans.client_test.go @@ -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) +} diff --git a/go.mod b/go.mod index 21ae39d..dfaf047 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.14 require ( git.tetele.net/tgo/conf v0.33.1 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 golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect diff --git a/go.sum b/go.sum index 61a4576..97c2e8d 100644 --- a/go.sum +++ b/go.sum @@ -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/crypter v0.2.2 h1:YMQJh2Gj5Po4ZfelJUmXBKi01UbmtiSy3bmqRfnYQMo= 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/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/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= diff --git a/user.client.go b/user.client.go index 04e1b07..11e54da 100644 --- a/user.client.go +++ b/user.client.go @@ -12,14 +12,11 @@ import ( 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 { return map[string]string{}, err } + defer conn.Close() 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(), "GroupId": res.GetGroupId(), "Type": res.GetType(), - "ThirdId": res.GetThirdId(), - "Platform": res.GetPlatform(), + "ThirdId": res.GetThirdId(), + "Platform": res.GetPlatform(), + "LockFans": res.GetLockFans(), }, 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) { - 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 { 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) { - 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 { 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) { - 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 { return map[string]string{}, err } diff --git a/user.pb.go b/user.pb.go index 4b6258b..6afca4c 100644 --- a/user.pb.go +++ b/user.pb.go @@ -152,6 +152,7 @@ type UserResponse struct { Type *string `protobuf:"bytes,13,opt,name=type" json:"type,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"` + LockFans *string `protobuf:"bytes,16,opt,name=lock_fans" json:"lock_fans,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -264,6 +265,13 @@ func (m *UserResponse) GetPlatform() string { return "" } +func (m *UserResponse) GetLockFans() string { + if m != nil && m.LockFans != nil { + return *m.LockFans + } + return "" +} + // 用户登录请求结构 type LoginRequest struct { Dbname *string `protobuf:"bytes,1,opt,name=dbname" json:"dbname,omitempty"` @@ -517,6 +525,18 @@ type UserService interface { GetAddressInfo(in *Request, out *Response) error GetUserScore(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 @@ -627,6 +647,42 @@ func (c *UserServiceClient) GetUserScore(in *Request, out *Response) error { func (c *UserServiceClient) GetUserRedEnvelope(in *Request, out *Response) error { 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. func DialUserService(network, addr string) (*UserServiceClient, *rpc.Client, error) { diff --git a/user.proto b/user.proto index 2ebe418..816c09a 100644 --- a/user.proto +++ b/user.proto @@ -39,6 +39,7 @@ message UserResponse { string type = 13;//类型 string third_id = 14; //token对应的third_id string platform = 15; //平台 + string lock_fans = 16; //锁定 } // 用户登录请求结构 @@ -100,4 +101,17 @@ service UserService { rpc getAddressInfo(Request) returns (Response); // 查询地址 rpc getUserScore(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); // 绑定 } \ No newline at end of file