From 813fa8c02fd1937a61baf87c7935f9071334d7c9 Mon Sep 17 00:00:00 2001 From: guzeng Date: Mon, 27 Sep 2021 10:06:10 +0800 Subject: [PATCH 01/21] =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0lock=5Ffans=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user.pb.go | 8 ++++++++ user.proto | 1 + 2 files changed, 9 insertions(+) diff --git a/user.pb.go b/user.pb.go index 4b6258b..ad39e55 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"` diff --git a/user.proto b/user.proto index 6563b4a..5ed5b69 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; //锁定 } // 用户登录请求结构 From ebb211b42e28e72d14e4c4a85c0f90c69e155d47 Mon Sep 17 00:00:00 2001 From: guzeng Date: Mon, 27 Sep 2021 10:21:38 +0800 Subject: [PATCH 02/21] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user.client.go | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/user.client.go b/user.client.go index 04e1b07..6c5ffed 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.LockFans(), }, nil } @@ -60,12 +58,10 @@ 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...) + if err != nil { + return map[string]string{}, err } - - conn, _, err := DialUserService("tcp", user_rpc_url) if err != nil { return nil, err } @@ -89,12 +85,10 @@ 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...) + if err != nil { + return map[string]string{}, err } - - conn, _, err := DialUserService("tcp", user_rpc_url) if err != nil { return nil, err } @@ -115,12 +109,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 } From ef2327d159505a493a017af1cd9f20bb9ad5d2b9 Mon Sep 17 00:00:00 2001 From: guzeng Date: Mon, 27 Sep 2021 10:25:11 +0800 Subject: [PATCH 03/21] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user.client.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/user.client.go b/user.client.go index 6c5ffed..11e54da 100644 --- a/user.client.go +++ b/user.client.go @@ -46,7 +46,7 @@ func GetUserByToken(dbname, token string, url ...string) (map[string]string, err "Type": res.GetType(), "ThirdId": res.GetThirdId(), "Platform": res.GetPlatform(), - "LockFans": res.LockFans(), + "LockFans": res.GetLockFans(), }, nil } @@ -59,9 +59,7 @@ func GetUserByToken(dbname, token string, url ...string) (map[string]string, err func GetUserByUsername(dbname, username string, url ...string) (*UserResponse, error) { conn, err := rpc_server_conn(url...) - if err != nil { - return map[string]string{}, err - } + if err != nil { return nil, err } @@ -86,9 +84,7 @@ func GetUserByUsername(dbname, username string, url ...string) (*UserResponse, e func GetUserByUsercode(dbname, usercode string, url ...string) (*UserResponse, error) { conn, err := rpc_server_conn(url...) - if err != nil { - return map[string]string{}, err - } + if err != nil { return nil, err } From f314462c21e8518cdfef00adacd330b715e6c098 Mon Sep 17 00:00:00 2001 From: lijianbin <513837235@.qq.com> Date: Thu, 30 Sep 2021 14:18:43 +0800 Subject: [PATCH 04/21] =?UTF-8?q?=E5=AE=9A=E4=B9=89=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E3=80=81=E4=BC=98=E6=83=A0=E5=88=B8=E3=80=81=E6=88=90=E9=95=BF?= =?UTF-8?q?=E5=80=BC=E3=80=81=E7=BA=A2=E5=8C=85=E7=AD=89=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account.client.go | 144 +++++++++++++++++++++++----------------------- common.go | 90 ++++++++++++++--------------- go.mod | 2 +- go.sum | 8 +-- user.proto | 11 ++++ 5 files changed, 134 insertions(+), 121 deletions(-) diff --git a/account.client.go b/account.client.go index 44ee443..add0a69 100644 --- a/account.client.go +++ b/account.client.go @@ -1,106 +1,108 @@ package userrpc 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 -} \ No newline at end of file diff --git a/common.go b/common.go index 6bf19bd..662444f 100644 --- a/common.go +++ b/common.go @@ -1,83 +1,83 @@ package userrpc import ( - "git.tetele.net/tgo/conf" + "git.tetele.net/tgo/conf" ) const DES_KEY = "usersrpc" type Req struct { - SiteId string - Dbname string + SiteId string + Dbname string } 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 { - Req - Third + Req + Third } type GetThirdReq struct { - Req - Userid string - Platform string + Req + Userid string + Platform string } type GetBusinessReq struct { - Req - BusinessId string + Req + BusinessId string } type GetUserReq struct { - Req - UserId string + Req + UserId string } type GetAddressReq struct { - Req - AddressId string + Req + AddressId string } type Res struct { - Errcode int - Errmsg string + Errcode int + Errmsg string } 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) { - 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 } 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.proto b/user.proto index 5ed5b69..9506b50 100644 --- a/user.proto +++ b/user.proto @@ -100,4 +100,15 @@ 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); // 更新用户优惠券记录 } \ No newline at end of file From fdd0b662e2f5e59ded8d00e056f722bd6ad1952f Mon Sep 17 00:00:00 2001 From: guzeng Date: Thu, 30 Sep 2021 14:19:27 +0800 Subject: [PATCH 05/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0pb.go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user.pb.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/user.pb.go b/user.pb.go index ad39e55..cff92c8 100644 --- a/user.pb.go +++ b/user.pb.go @@ -525,6 +525,17 @@ 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 } // AcceptUserServiceClient accepts connections on the listener and serves requests @@ -635,6 +646,39 @@ 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) +} // DialUserService connects to an UserService at the specified network address. func DialUserService(network, addr string) (*UserServiceClient, *rpc.Client, error) { From 371829ca29825e687b34ec970f88c9587abcd5cf Mon Sep 17 00:00:00 2001 From: lijianbin <513837235@.qq.com> Date: Thu, 30 Sep 2021 18:05:46 +0800 Subject: [PATCH 06/21] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E3=80=81=E6=88=90=E9=95=BF=E5=80=BC=E3=80=81=E7=BA=A2=E5=8C=85?= =?UTF-8?q?=E3=80=81=E4=BC=98=E6=83=A0=E5=88=B8=E7=AD=89=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account.client.go | 707 +++++++++++++++++++++++++++++++++++++++++ account.client_test.go | 9 + 2 files changed, 716 insertions(+) diff --git a/account.client.go b/account.client.go index add0a69..6db32eb 100644 --- a/account.client.go +++ b/account.client.go @@ -3,8 +3,63 @@ package userrpc import ( "encoding/json" "errors" + "log" ) +type GetAddReq struct { + Req + UserId string + Value 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 +} + +type GetUpdateCouponReq struct { + Req + UserId string + CouponId string + OrderSn string + Remark string + IsUse string +} + /** * 获取用户积分 */ @@ -105,4 +160,656 @@ func GetUserRedEnvelope(dbname, userId string, url ...string) (string, error) { return redEnvelope, nil } +/** + * 添加积分 + * @2021/09/30 + * @bin + */ +func AddUserScore(dbname, userId, score 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 + + 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 == "" || used_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 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 + + 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 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 + + 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 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 := GetAddReq{} + data.Dbname = dbname + data.UserId = userId + data.Value = money + + req, err := SetReqData(data) + if err != nil { + log.Println("UpdateUserRedEnvelope crypter error:", err) + return false, err + } + + res := &Response{} + + err = conn.UpdateUserUpgrade(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, ProductThumb, 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.ProductThumb = ProductThumb + 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 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 + + 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 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 := GetUpdateCouponReq{} + data.Dbname = dbname + data.UserId = userId + data.CouponId = couponId + data.Remark = remark + data.OrderSn = orderSn + data.IsUse = isUse + + req, err := SetReqData(data) + if err != nil { + log.Println("UpdateUserCoupon crypter error:", err) + return false, err + } + + res := &Response{} + + err = conn.UpdateUserUpgrade(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..a1b17a2 100644 --- a/account.client_test.go +++ b/account.client_test.go @@ -23,3 +23,12 @@ func Test_GetUserRedEnvelope(t *testing.T) { t.Log(ret) t.Log(err) } + +func Test_AddUserScore(t *testing.T) { + dbname := "shop_v2" + userid := "2" + + ret, err := AddUserScore(dbname,userid,"20") + t.Log(ret) + t.Log(err) +} From 354d17d271687aa6bda14e8d6783187ea867c4c3 Mon Sep 17 00:00:00 2001 From: lijianbin <513837235@.qq.com> Date: Fri, 8 Oct 2021 14:47:13 +0800 Subject: [PATCH 07/21] debug --- account.client_test.go | 160 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 144 insertions(+), 16 deletions(-) diff --git a/account.client_test.go b/account.client_test.go index a1b17a2..95ebb46 100644 --- a/account.client_test.go +++ b/account.client_test.go @@ -1,34 +1,162 @@ package userrpc import ( - "testing" + "testing" ) func Test_GetUserScore(t *testing.T) { - dbname := "shop_v2" - id := "2" + dbname := "shop_v2" + 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" + 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" - userid := "2" + dbname := "shop_v2" + userid := "2" + score := "20" - ret, err := AddUserScore(dbname,userid,"20") - t.Log(ret) - t.Log(err) + ret, err := AddUserScore(dbname, userid, score) + t.Log(ret) + t.Log(err) +} + +func Test_UpdateUserScore(t *testing.T) { + dbname := "shop_v2" + userid := "2" + score := "20" + used_score := "10" + + ret, err := UpdateUserScore(dbname, userid, score, used_score) + t.Log(ret) + t.Log(err) +} + +func Test_AddUserScoreLog(t *testing.T) { + dbname := "shop_v2" + userid := "2" + score := "20" + before := "10" + after := "30" + 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" + userid := "2" + upgrade := "20" + + ret, err := AddUserUpgrade(dbname, userid, upgrade) + t.Log(ret) + t.Log(err) +} + +func Test_UpdateUserUpgrade(t *testing.T) { + dbname := "shop_v2" + userid := "2" + upgrade := "20" + + ret, err := UpdateUserUpgrade(dbname, userid, upgrade) + t.Log(ret) + t.Log(err) +} + +func Test_AddUserUpgradeLog(t *testing.T) { + dbname := "shop_v2" + userid := "2" + upgrade := "20" + before := "10" + after := "30" + 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" + userid := "2" + money := "20" + + ret, err := AddUserRedEnvelope(dbname, userid, money) + t.Log(ret) + t.Log(err) +} + +func Test_UpdateUserRedEnvelope(t *testing.T) { + dbname := "shop_v2" + userid := "2" + money := "20" + + ret, err := UpdateUserRedEnvelope(dbname, userid, money) + t.Log(ret) + t.Log(err) +} + +func Test_AddUserRedEnvelopeLog(t *testing.T) { + dbname := "shop_v2" + userid := "2" + money := "20" + before := "10" + after := "30" + Source := "task" + SourceId := "" + OrderSn := "" + 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" + userid := "2" + couponId := "20" + expired_time := "" + + ret, err := AddUserCoupon(dbname, userid, couponId, expired_time) + t.Log(ret) + t.Log(err) +} + +func Test_UpdateUserCoupon(t *testing.T) { + dbname := "shop_v2" + userid := "2" + couponId := "20" + remark := "" + orderSn := "" + isUse := "" + + ret, err := UpdateUserCoupon(dbname, userid, couponId, remark, orderSn, isUse) + t.Log(ret) + t.Log(err) } From a196dd9e1bdff791821592978c120d657dab26c4 Mon Sep 17 00:00:00 2001 From: lijianbin <513837235@.qq.com> Date: Fri, 8 Oct 2021 18:11:05 +0800 Subject: [PATCH 08/21] debug --- account.client.go | 34 ++++++++++---------- account.client_test.go | 70 ++++++++++++++++++++++-------------------- 2 files changed, 53 insertions(+), 51 deletions(-) diff --git a/account.client.go b/account.client.go index 6db32eb..acd9ba7 100644 --- a/account.client.go +++ b/account.client.go @@ -49,15 +49,10 @@ type GetCouponReq struct { UserId string CouponId string ExpireTime string -} - -type GetUpdateCouponReq struct { - Req - UserId string - CouponId string - OrderSn string - Remark string - IsUse string + OrderSn string + Remark string + IsUse string + Usertime string } /** @@ -223,7 +218,7 @@ func AddUserScore(dbname, userId, score string, url ...string) (int64, error) { * @bin */ func UpdateUserScore(dbname, userId, score, used_score string, url ...string) (bool, error) { - if dbname == "" || userId == "" || score == "" || used_score == "" { + if dbname == "" || userId == "" || score == "" { return false, errors.New("参数错误") } @@ -578,7 +573,7 @@ func AddUserRedEnvelope(dbname, userId, money string, url ...string) (int64, err * @2021/09/30 * @bin */ -func UpdateUserRedEnvelope(dbname, userId, money string, url ...string) (bool, error) { +func UpdateUserRedEnvelope(dbname, userId, money, used_money string, url ...string) (bool, error) { if dbname == "" || userId == "" || money == "" { return false, errors.New("参数错误") } @@ -589,10 +584,11 @@ func UpdateUserRedEnvelope(dbname, userId, money string, url ...string) (bool, e } defer conn.Close() - data := GetAddReq{} + data := GetUpdateReq{} data.Dbname = dbname data.UserId = userId data.Value = money + data.UsedValue = used_money req, err := SetReqData(data) if err != nil { @@ -602,7 +598,7 @@ func UpdateUserRedEnvelope(dbname, userId, money string, url ...string) (bool, e res := &Response{} - err = conn.UpdateUserUpgrade(req, res) + err = conn.UpdateUserRedEnvelope(req, res) if err != nil { log.Println("userrpc UpdateUserRedEnvelope error:", err) @@ -635,7 +631,7 @@ func UpdateUserRedEnvelope(dbname, userId, money string, url ...string) (bool, e * @2021/09/30 * @bin */ -func AddUserRedEnvelopeLog(dbname, UserId, Money, Before, After, Source, SourceId, OrderSn, Target, TargetId, ProductThumb, Memo string, url ...string) (int64, error) { +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("参数错误") } @@ -657,7 +653,6 @@ func AddUserRedEnvelopeLog(dbname, UserId, Money, Before, After, Source, SourceI data.OrderSn = OrderSn data.Target = Target data.TargetId = TargetId - data.ProductThumb = ProductThumb data.Memo = Memo req, err := SetReqData(data) @@ -701,7 +696,7 @@ func AddUserRedEnvelopeLog(dbname, UserId, Money, Before, After, Source, SourceI * @2021/09/30 * @bin */ -func AddUserCoupon(dbname, userId, couponId, expireTime string, url ...string) (int64, error) { +func AddUserCoupon(dbname, userId, couponId, expireTime, orderSn, remark string, url ...string) (int64, error) { if dbname == "" || userId == "" || couponId == "" { return 0, errors.New("参数错误") } @@ -717,6 +712,8 @@ func AddUserCoupon(dbname, userId, couponId, expireTime string, url ...string) ( data.UserId = userId data.CouponId = couponId data.ExpireTime = expireTime + data.OrderSn = orderSn + data.Remark = remark req, err := SetReqData(data) if err != nil { @@ -759,7 +756,7 @@ func AddUserCoupon(dbname, userId, couponId, expireTime string, url ...string) ( * @2021/09/30 * @bin */ -func UpdateUserCoupon(dbname, userId, couponId, remark, orderSn, isUse string, url ...string) (bool, error) { +func UpdateUserCoupon(dbname, userId, couponId, remark, orderSn, isUse, usetime string, url ...string) (bool, error) { if dbname == "" || userId == "" || couponId == "" { return false, errors.New("参数错误") } @@ -770,13 +767,14 @@ func UpdateUserCoupon(dbname, userId, couponId, remark, orderSn, isUse string, u } defer conn.Close() - data := GetUpdateCouponReq{} + 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 { diff --git a/account.client_test.go b/account.client_test.go index 95ebb46..a903e71 100644 --- a/account.client_test.go +++ b/account.client_test.go @@ -6,7 +6,7 @@ import ( func Test_GetUserScore(t *testing.T) { - dbname := "shop_v2" + dbname := "shop_v2_org" id := "2" ret, err := GetUserScore(dbname, id) @@ -16,7 +16,7 @@ func Test_GetUserScore(t *testing.T) { func Test_GetUserRedEnvelope(t *testing.T) { - dbname := "shop_v2" + dbname := "shop_v2_org" id := "2" ret, err := GetUserRedEnvelope(dbname, id) @@ -25,7 +25,7 @@ func Test_GetUserRedEnvelope(t *testing.T) { } func Test_AddUserScore(t *testing.T) { - dbname := "shop_v2" + dbname := "shop_v2_org" userid := "2" score := "20" @@ -35,10 +35,10 @@ func Test_AddUserScore(t *testing.T) { } func Test_UpdateUserScore(t *testing.T) { - dbname := "shop_v2" + dbname := "shop_v2_org" userid := "2" - score := "20" - used_score := "10" + score := "400" + used_score := "300" ret, err := UpdateUserScore(dbname, userid, score, used_score) t.Log(ret) @@ -46,11 +46,11 @@ func Test_UpdateUserScore(t *testing.T) { } func Test_AddUserScoreLog(t *testing.T) { - dbname := "shop_v2" + dbname := "shop_v2_org" userid := "2" - score := "20" - before := "10" - after := "30" + score := "100" + before := "500" + after := "400" Source := "task" SourceId := "" OrderSn := "" @@ -65,9 +65,9 @@ func Test_AddUserScoreLog(t *testing.T) { } func Test_AddUserUpgrade(t *testing.T) { - dbname := "shop_v2" - userid := "2" - upgrade := "20" + dbname := "shop_v2_org" + userid := "5" + upgrade := "100" ret, err := AddUserUpgrade(dbname, userid, upgrade) t.Log(ret) @@ -75,9 +75,9 @@ func Test_AddUserUpgrade(t *testing.T) { } func Test_UpdateUserUpgrade(t *testing.T) { - dbname := "shop_v2" - userid := "2" - upgrade := "20" + dbname := "shop_v2_org" + userid := "5" + upgrade := "100" ret, err := UpdateUserUpgrade(dbname, userid, upgrade) t.Log(ret) @@ -85,11 +85,11 @@ func Test_UpdateUserUpgrade(t *testing.T) { } func Test_AddUserUpgradeLog(t *testing.T) { - dbname := "shop_v2" + dbname := "shop_v2_org" userid := "2" upgrade := "20" - before := "10" - after := "30" + before := "11" + after := "31" Source := "task" Memo := "" @@ -99,8 +99,8 @@ func Test_AddUserUpgradeLog(t *testing.T) { } func Test_AddUserRedEnvelope(t *testing.T) { - dbname := "shop_v2" - userid := "2" + dbname := "shop_v2_org" + userid := "5" money := "20" ret, err := AddUserRedEnvelope(dbname, userid, money) @@ -109,24 +109,25 @@ func Test_AddUserRedEnvelope(t *testing.T) { } func Test_UpdateUserRedEnvelope(t *testing.T) { - dbname := "shop_v2" + dbname := "shop_v2_org" userid := "2" - money := "20" + money := "40" + used_money := "1" - ret, err := UpdateUserRedEnvelope(dbname, userid, money) + ret, err := UpdateUserRedEnvelope(dbname, userid, money, used_money) t.Log(ret) t.Log(err) } func Test_AddUserRedEnvelopeLog(t *testing.T) { - dbname := "shop_v2" + dbname := "shop_v2_org" userid := "2" - money := "20" - before := "10" - after := "30" + money := "-1" + before := "41" + after := "40" Source := "task" SourceId := "" - OrderSn := "" + OrderSn := "216304042479173922" Target := "" TargetId := "" ProductThumb := "" @@ -138,25 +139,28 @@ func Test_AddUserRedEnvelopeLog(t *testing.T) { } func Test_AddUserCoupon(t *testing.T) { - dbname := "shop_v2" + dbname := "shop_v2_org" userid := "2" couponId := "20" expired_time := "" + order_sn := "" + remark := "" - ret, err := AddUserCoupon(dbname, userid, couponId, expired_time) + 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" + dbname := "shop_v2_org" userid := "2" couponId := "20" remark := "" orderSn := "" isUse := "" + usetime := "" - ret, err := UpdateUserCoupon(dbname, userid, couponId, remark, orderSn, isUse) + ret, err := UpdateUserCoupon(dbname, userid, couponId, remark, orderSn, isUse,usetime) t.Log(ret) t.Log(err) } From ed808316e8cdc9fd8171c8796f90c98b4581e5c7 Mon Sep 17 00:00:00 2001 From: lijianbin <513837235@.qq.com> Date: Fri, 8 Oct 2021 18:24:03 +0800 Subject: [PATCH 09/21] debug --- account.client.go | 2 +- account.client_test.go | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/account.client.go b/account.client.go index acd9ba7..8000d77 100644 --- a/account.client.go +++ b/account.client.go @@ -784,7 +784,7 @@ func UpdateUserCoupon(dbname, userId, couponId, remark, orderSn, isUse, usetime res := &Response{} - err = conn.UpdateUserUpgrade(req, res) + err = conn.UpdateUserCoupon(req, res) if err != nil { log.Println("userrpc UpdateUserCoupon error:", err) diff --git a/account.client_test.go b/account.client_test.go index a903e71..6c4bead 100644 --- a/account.client_test.go +++ b/account.client_test.go @@ -1,7 +1,9 @@ package userrpc import ( + "strconv" "testing" + "time" ) func Test_GetUserScore(t *testing.T) { @@ -141,10 +143,10 @@ func Test_AddUserRedEnvelopeLog(t *testing.T) { func Test_AddUserCoupon(t *testing.T) { dbname := "shop_v2_org" userid := "2" - couponId := "20" - expired_time := "" + couponId := "6" + expired_time := "1634684122" order_sn := "" - remark := "" + remark := "商品券" ret, err := AddUserCoupon(dbname, userid, couponId, expired_time,order_sn,remark) t.Log(ret) @@ -154,11 +156,11 @@ func Test_AddUserCoupon(t *testing.T) { func Test_UpdateUserCoupon(t *testing.T) { dbname := "shop_v2_org" userid := "2" - couponId := "20" - remark := "" - orderSn := "" - isUse := "" - usetime := "" + 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) From 07041e3a0ca8e7581e6c62a7693032094426796f Mon Sep 17 00:00:00 2001 From: guzeng Date: Wed, 13 Oct 2021 21:01:09 +0800 Subject: [PATCH 10/21] =?UTF-8?q?=E5=A2=9E=E5=8A=A0favoriteProduct?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user.pb.go | 4 ++++ user.proto | 1 + 2 files changed, 5 insertions(+) diff --git a/user.pb.go b/user.pb.go index cff92c8..3e6ea20 100644 --- a/user.pb.go +++ b/user.pb.go @@ -536,6 +536,7 @@ type UserService interface { AddUserRedEnvelopeLog(in *Request, out *Response) error AddUserCoupon(in *Request, out *Response) error UpdateUserCoupon(in *Request, out *Response) error + FavoriteProduct(in *Request, out *Response) error } // AcceptUserServiceClient accepts connections on the listener and serves requests @@ -679,6 +680,9 @@ func (c *UserServiceClient) AddUserCoupon(in *Request, out *Response) error { func (c *UserServiceClient) UpdateUserCoupon(in *Request, out *Response) error { return c.Call("UserService.UpdateUserCoupon", in, out) } +func (c *UserServiceClient) FavoriteProduct(in *Request, out *Response) error { + return c.Call("UserService.FavoriteProduct", 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 9506b50..6464258 100644 --- a/user.proto +++ b/user.proto @@ -111,4 +111,5 @@ service UserService { rpc addUserRedEnvelopeLog(Request) returns (Response); // 添加用户红包日志 rpc addUserCoupon(Request) returns (Response); // 添加用户优惠券记录 rpc updateUserCoupon(Request) returns (Response); // 更新用户优惠券记录 + rpc favoriteProduct(Request) returns (Response); // 收藏商品 } \ No newline at end of file From 7bb5070ef4cd6cd67a52cd1c09b01ecde4dcb556 Mon Sep 17 00:00:00 2001 From: guzeng Date: Sat, 23 Oct 2021 17:15:07 +0800 Subject: [PATCH 11/21] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user.pb.go | 8 ++++++++ user.proto | 2 ++ 2 files changed, 10 insertions(+) diff --git a/user.pb.go b/user.pb.go index 3e6ea20..57ed49f 100644 --- a/user.pb.go +++ b/user.pb.go @@ -537,6 +537,8 @@ type UserService interface { AddUserCoupon(in *Request, out *Response) error UpdateUserCoupon(in *Request, out *Response) error FavoriteProduct(in *Request, out *Response) error + Fans(in *Request, out *Response) error + LockFans(in *Request, out *Response) error } // AcceptUserServiceClient accepts connections on the listener and serves requests @@ -683,6 +685,12 @@ func (c *UserServiceClient) UpdateUserCoupon(in *Request, out *Response) error { func (c *UserServiceClient) FavoriteProduct(in *Request, out *Response) error { return c.Call("UserService.FavoriteProduct", in, out) } +func (c *UserServiceClient) Fans(in *Request, out *Response) error { + return c.Call("UserService.Fans", in, out) +} +func (c *UserServiceClient) LockFans(in *Request, out *Response) error { + return c.Call("UserService.LockFans", 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 6464258..67efaaa 100644 --- a/user.proto +++ b/user.proto @@ -112,4 +112,6 @@ service UserService { rpc addUserCoupon(Request) returns (Response); // 添加用户优惠券记录 rpc updateUserCoupon(Request) returns (Response); // 更新用户优惠券记录 rpc favoriteProduct(Request) returns (Response); // 收藏商品 + rpc Fans(Request) returns (Response); // 弱绑定 + rpc LockFans(Request) returns (Response); // 强绑定 } \ No newline at end of file From 2bf5d2b055187ec4482eda4cbeea22ad8e7b3f4a Mon Sep 17 00:00:00 2001 From: guzeng Date: Sat, 23 Oct 2021 17:23:07 +0800 Subject: [PATCH 12/21] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common.go | 96 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/common.go b/common.go index 662444f..f27545e 100644 --- a/common.go +++ b/common.go @@ -1,83 +1,89 @@ package userrpc import ( - "git.tetele.net/tgo/conf" + "git.tetele.net/tgo/conf" ) const DES_KEY = "usersrpc" type Req struct { - SiteId string - Dbname string + SiteId string + Dbname string } 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 { - Req - Third + Req + Third } type GetThirdReq struct { - Req - Userid string - Platform string + Req + Userid string + Platform string } type GetBusinessReq struct { - Req - BusinessId string + Req + BusinessId string } type GetUserReq struct { - Req - UserId string + Req + UserId string } type GetAddressReq struct { - Req - AddressId string + Req + AddressId string } type Res struct { - Errcode int - Errmsg string + Errcode int + Errmsg string } 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 +} + +type FansReq struct { + Req + UserId string + BusinessId string } 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 } From c47ff3d2ec1a11f1817076270221e6189dfa2992 Mon Sep 17 00:00:00 2001 From: guzeng Date: Sat, 23 Oct 2021 18:20:27 +0800 Subject: [PATCH 13/21] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=AC=E5=85=B1?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common.go | 1 + fans.client.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 fans.client.go diff --git a/common.go b/common.go index f27545e..18019e6 100644 --- a/common.go +++ b/common.go @@ -67,6 +67,7 @@ type FansReq struct { Req UserId string BusinessId string + Lock bool } func rpc_server_conn(url ...string) (*UserServiceClient, error) { diff --git a/fans.client.go b/fans.client.go new file mode 100644 index 0000000..110c290 --- /dev/null +++ b/fans.client.go @@ -0,0 +1,50 @@ +package userrpc + +import ( + "encoding/json" + "errors" + "strconv" + "time" + + "git.tetele.net/tgo/crypter" + "github.com/golang/protobuf/proto" +) + +/** + * 绑定粉丝 + * 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 nil, err + } + defer conn.Close() + + data := FansReq{} + data.SiteId = site_id + data.Dbname = dbname + data.UserId = user_id + data.BusinessId = business_id + + data_json, err := json.Marshal(data) + if err != nil { + return nil, err + } + + SetReqData(data) + + res := &Response{} + + err = conn.Fans(req, res) + + if err != nil { + return nil, err + } + + _, err := GetResData(res) + + return err +} From bd92e877c0cb8eecef512cfc4d3bcf7796a108ff Mon Sep 17 00:00:00 2001 From: guzeng Date: Sat, 23 Oct 2021 18:22:48 +0800 Subject: [PATCH 14/21] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fans.client.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/fans.client.go b/fans.client.go index 110c290..2967fe8 100644 --- a/fans.client.go +++ b/fans.client.go @@ -2,12 +2,6 @@ package userrpc import ( "encoding/json" - "errors" - "strconv" - "time" - - "git.tetele.net/tgo/crypter" - "github.com/golang/protobuf/proto" ) /** @@ -19,7 +13,7 @@ func Fans(site_id, dbname, user_id, business_id string, url ...string) error { conn, err := rpc_server_conn(url...) if err != nil { - return nil, err + return err } defer conn.Close() @@ -31,7 +25,7 @@ func Fans(site_id, dbname, user_id, business_id string, url ...string) error { data_json, err := json.Marshal(data) if err != nil { - return nil, err + return err } SetReqData(data) @@ -41,10 +35,10 @@ func Fans(site_id, dbname, user_id, business_id string, url ...string) error { err = conn.Fans(req, res) if err != nil { - return nil, err + return err } - _, err := GetResData(res) + _, err = GetResData(res) return err } From 7b6bd0b8a4e0e398840db2e0d30debc97dd74044 Mon Sep 17 00:00:00 2001 From: guzeng Date: Sat, 23 Oct 2021 18:24:46 +0800 Subject: [PATCH 15/21] debug --- fans.client.go | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/fans.client.go b/fans.client.go index 2967fe8..de03e01 100644 --- a/fans.client.go +++ b/fans.client.go @@ -11,34 +11,5 @@ import ( */ 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_json, err := json.Marshal(data) - if err != nil { - return err - } - - SetReqData(data) - - res := &Response{} - - err = conn.Fans(req, res) - - if err != nil { - return err - } - - _, err = GetResData(res) - return err } From 5bf61dc368118d39e0f197146ced2024bcf8689b Mon Sep 17 00:00:00 2001 From: guzeng Date: Sat, 23 Oct 2021 18:25:51 +0800 Subject: [PATCH 16/21] debug --- fans.client.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fans.client.go b/fans.client.go index de03e01..d0d5a6f 100644 --- a/fans.client.go +++ b/fans.client.go @@ -1,8 +1,6 @@ package userrpc -import ( - "encoding/json" -) +// "encoding/json" /** * 绑定粉丝 @@ -11,5 +9,5 @@ import ( */ func Fans(site_id, dbname, user_id, business_id string, url ...string) error { - return err + return nil } From 27305dd3181ffe295bff09920292bc58bda5e6f2 Mon Sep 17 00:00:00 2001 From: guzeng Date: Sat, 23 Oct 2021 18:42:30 +0800 Subject: [PATCH 17/21] =?UTF-8?q?=E5=8E=BB=E6=8E=89favoriteProduct?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user.pb.go | 4 ---- user.proto | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/user.pb.go b/user.pb.go index 57ed49f..712f602 100644 --- a/user.pb.go +++ b/user.pb.go @@ -536,7 +536,6 @@ type UserService interface { AddUserRedEnvelopeLog(in *Request, out *Response) error AddUserCoupon(in *Request, out *Response) error UpdateUserCoupon(in *Request, out *Response) error - FavoriteProduct(in *Request, out *Response) error Fans(in *Request, out *Response) error LockFans(in *Request, out *Response) error } @@ -682,9 +681,6 @@ func (c *UserServiceClient) AddUserCoupon(in *Request, out *Response) error { func (c *UserServiceClient) UpdateUserCoupon(in *Request, out *Response) error { return c.Call("UserService.UpdateUserCoupon", in, out) } -func (c *UserServiceClient) FavoriteProduct(in *Request, out *Response) error { - return c.Call("UserService.FavoriteProduct", in, out) -} func (c *UserServiceClient) Fans(in *Request, out *Response) error { return c.Call("UserService.Fans", in, out) } diff --git a/user.proto b/user.proto index 67efaaa..ef44d83 100644 --- a/user.proto +++ b/user.proto @@ -111,7 +111,7 @@ service UserService { rpc addUserRedEnvelopeLog(Request) returns (Response); // 添加用户红包日志 rpc addUserCoupon(Request) returns (Response); // 添加用户优惠券记录 rpc updateUserCoupon(Request) returns (Response); // 更新用户优惠券记录 - rpc favoriteProduct(Request) returns (Response); // 收藏商品 + //rpc favoriteProduct(Request) returns (Response); // 收藏商品 rpc Fans(Request) returns (Response); // 弱绑定 rpc LockFans(Request) returns (Response); // 强绑定 } \ No newline at end of file From 95f632eb259542acdbb75efa730763d2ec76c30f Mon Sep 17 00:00:00 2001 From: guzeng Date: Sat, 23 Oct 2021 18:44:28 +0800 Subject: [PATCH 18/21] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user.pb.go | 4 ---- user.proto | 3 +-- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/user.pb.go b/user.pb.go index 712f602..6afca4c 100644 --- a/user.pb.go +++ b/user.pb.go @@ -537,7 +537,6 @@ type UserService interface { AddUserCoupon(in *Request, out *Response) error UpdateUserCoupon(in *Request, out *Response) error Fans(in *Request, out *Response) error - LockFans(in *Request, out *Response) error } // AcceptUserServiceClient accepts connections on the listener and serves requests @@ -684,9 +683,6 @@ func (c *UserServiceClient) UpdateUserCoupon(in *Request, out *Response) error { func (c *UserServiceClient) Fans(in *Request, out *Response) error { return c.Call("UserService.Fans", in, out) } -func (c *UserServiceClient) LockFans(in *Request, out *Response) error { - return c.Call("UserService.LockFans", 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 ef44d83..a8a7dff 100644 --- a/user.proto +++ b/user.proto @@ -112,6 +112,5 @@ service UserService { rpc addUserCoupon(Request) returns (Response); // 添加用户优惠券记录 rpc updateUserCoupon(Request) returns (Response); // 更新用户优惠券记录 //rpc favoriteProduct(Request) returns (Response); // 收藏商品 - rpc Fans(Request) returns (Response); // 弱绑定 - rpc LockFans(Request) returns (Response); // 强绑定 + rpc Fans(Request) returns (Response); // 绑定 } \ No newline at end of file From 8e7bcf90f99738f69d71cbc4206c9ba67d4cfc22 Mon Sep 17 00:00:00 2001 From: guzeng Date: Sat, 23 Oct 2021 19:07:59 +0800 Subject: [PATCH 19/21] =?UTF-8?q?=E4=BF=AE=E6=94=B9fans=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fans.client.go | 66 +++++++++++++++++++++++++++++++++++++++++++-- fans.client_test.go | 16 +++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 fans.client_test.go diff --git a/fans.client.go b/fans.client.go index d0d5a6f..ce50c4c 100644 --- a/fans.client.go +++ b/fans.client.go @@ -1,7 +1,5 @@ package userrpc -// "encoding/json" - /** * 绑定粉丝 * 2021/10/23 @@ -9,5 +7,69 @@ package userrpc */ 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) +} From 35e2c44605969e48666aaa0e5c7342e6b869cb0f Mon Sep 17 00:00:00 2001 From: guzeng Date: Wed, 3 Nov 2021 21:35:55 +0800 Subject: [PATCH 20/21] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account.client.go | 1116 +++++++++++++++++++++++---------------------- 1 file changed, 560 insertions(+), 556 deletions(-) diff --git a/account.client.go b/account.client.go index 8000d77..1d512f0 100644 --- a/account.client.go +++ b/account.client.go @@ -1,58 +1,61 @@ package userrpc import ( - "encoding/json" - "errors" - "log" + "encoding/json" + "errors" + "log" ) type GetAddReq struct { - Req - UserId string - Value string + Req + UserId string + Value string + Memo string + Source string + SourceId string } type GetUpdateReq struct { - Req - UserId string - Value string - UsedValue string + 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 + 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 + 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 + Req + UserId string + CouponId string + ExpireTime string + OrderSn string + Remark string + IsUse string + Usertime string } /** @@ -60,49 +63,49 @@ type GetCouponReq struct { */ 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 } /** @@ -110,49 +113,49 @@ func GetUserScore(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 - } + if err != nil { + return "", err + } - return redEnvelope, nil + return redEnvelope, nil } /** @@ -160,56 +163,57 @@ func GetUserRedEnvelope(dbname, userId string, url ...string) (string, error) { * @2021/09/30 * @bin */ -func AddUserScore(dbname, userId, score string, url ...string) (int64, error) { - if dbname == "" || userId == "" || score == "" { - return 0, errors.New("参数错误") - } +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() + 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 := 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 - } + req, err := SetReqData(data) + if err != nil { + log.Println("AddUserScore crypter error:", err) + return 0, err + } - res := &Response{} + res := &Response{} - err = conn.AddUserScore(req, res) + err = conn.AddUserScore(req, res) - if err != nil { - log.Println("userrpc AddUserScore error:", err) - return 0, err - } + if err != nil { + log.Println("userrpc AddUserScore error:", err) + return 0, err + } - res_data_de, err := GetResData(res) + res_data_de, err := GetResData(res) - if err != nil { - return 0, err - } + if err != nil { + return 0, err + } - if res_data_de == "" { - return 0, nil - } + if res_data_de == "" { + return 0, nil + } - var insertId int64 + var insertId int64 - err = json.Unmarshal([]byte(res_data_de), &insertId) + err = json.Unmarshal([]byte(res_data_de), &insertId) - if err != nil { - return 0, err - } + if err != nil { + return 0, err + } - return insertId, nil + return insertId, nil } /** @@ -218,56 +222,56 @@ func AddUserScore(dbname, userId, score string, url ...string) (int64, error) { * @bin */ func UpdateUserScore(dbname, userId, score, used_score string, url ...string) (bool, error) { - if dbname == "" || userId == "" || score == "" { - return false, errors.New("参数错误") - } + if dbname == "" || userId == "" || score == "" { + return false, errors.New("参数错误") + } - conn, err := rpc_server_conn(url...) - if err != nil { - return false, err - } - defer conn.Close() + 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 + 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 - } + req, err := SetReqData(data) + if err != nil { + log.Println("UpdateUserScore crypter error:", err) + return false, err + } - res := &Response{} + res := &Response{} - err = conn.UpdateUserScore(req, res) + err = conn.UpdateUserScore(req, res) - if err != nil { - log.Println("userrpc UpdateUserScore error:", err) - return false, err - } + if err != nil { + log.Println("userrpc UpdateUserScore error:", err) + return false, err + } - res_data_de, err := GetResData(res) + res_data_de, err := GetResData(res) - if err != nil { - return false, err - } + if err != nil { + return false, err + } - if res_data_de == "" { - return false, nil - } + if res_data_de == "" { + return false, nil + } - var updateres bool + var updateres bool - err = json.Unmarshal([]byte(res_data_de), &updateres) + err = json.Unmarshal([]byte(res_data_de), &updateres) - if err != nil { - return false, err - } + if err != nil { + return false, err + } - return updateres, nil + return updateres, nil } /** @@ -276,64 +280,64 @@ func UpdateUserScore(dbname, userId, score, used_score string, url ...string) (b * @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 + 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 } /** @@ -342,55 +346,55 @@ func AddUserScoreLog(dbname, UserId, Score, Before, After, Source, SourceId, Ord * @bin */ func AddUserUpgrade(dbname, userId, upgrade string, url ...string) (int64, error) { - if dbname == "" || userId == "" || upgrade == "" { - return 0, errors.New("参数错误") - } + if dbname == "" || userId == "" || upgrade == "" { + return 0, errors.New("参数错误") + } - conn, err := rpc_server_conn(url...) - if err != nil { - return 0, err - } - defer conn.Close() + 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 := GetAddReq{} + data.Dbname = dbname + data.UserId = userId + data.Value = upgrade - req, err := SetReqData(data) - if err != nil { - log.Println("AddUserUpgrade crypter error:", err) - return 0, err - } + req, err := SetReqData(data) + if err != nil { + log.Println("AddUserUpgrade crypter error:", err) + return 0, err + } - res := &Response{} + res := &Response{} - err = conn.AddUserUpgrade(req, res) + err = conn.AddUserUpgrade(req, res) - if err != nil { - log.Println("userrpc AddUserUpgrade error:", err) - return 0, err - } + if err != nil { + log.Println("userrpc AddUserUpgrade error:", err) + return 0, err + } - res_data_de, err := GetResData(res) + res_data_de, err := GetResData(res) - if err != nil { - return 0, err - } + if err != nil { + return 0, err + } - if res_data_de == "" { - return 0, nil - } + if res_data_de == "" { + return 0, nil + } - var insertId int64 + var insertId int64 - err = json.Unmarshal([]byte(res_data_de), &insertId) + err = json.Unmarshal([]byte(res_data_de), &insertId) - if err != nil { - return 0, err - } + if err != nil { + return 0, err + } - return insertId, nil + return insertId, nil } /** @@ -399,55 +403,55 @@ func AddUserUpgrade(dbname, userId, upgrade string, url ...string) (int64, error * @bin */ func UpdateUserUpgrade(dbname, userId, upgrade string, url ...string) (bool, error) { - if dbname == "" || userId == "" || upgrade == "" { - return false, errors.New("参数错误") - } + if dbname == "" || userId == "" || upgrade == "" { + return false, errors.New("参数错误") + } - conn, err := rpc_server_conn(url...) - if err != nil { - return false, err - } - defer conn.Close() + 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 + 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 - } + req, err := SetReqData(data) + if err != nil { + log.Println("UpdateUserUpgrade crypter error:", err) + return false, err + } - res := &Response{} + res := &Response{} - err = conn.UpdateUserUpgrade(req, res) + err = conn.UpdateUserUpgrade(req, res) - if err != nil { - log.Println("userrpc UpdateUserUpgrade error:", err) - return false, err - } + if err != nil { + log.Println("userrpc UpdateUserUpgrade error:", err) + return false, err + } - res_data_de, err := GetResData(res) + res_data_de, err := GetResData(res) - if err != nil { - return false, err - } + if err != nil { + return false, err + } - if res_data_de == "" { - return false, nil - } + if res_data_de == "" { + return false, nil + } - var updateres bool + var updateres bool - err = json.Unmarshal([]byte(res_data_de), &updateres) + err = json.Unmarshal([]byte(res_data_de), &updateres) - if err != nil { - return false, err - } + if err != nil { + return false, err + } - return updateres, nil + return updateres, nil } /** @@ -456,59 +460,59 @@ func UpdateUserUpgrade(dbname, userId, upgrade string, url ...string) (bool, err * @bin */ func AddUserUpgradeLog(dbname, UserId, Upgrade, Before, After, Source, Memo string, url ...string) (int64, error) { - if dbname == "" || UserId == "" || Upgrade == "" || After == "" { - return 0, errors.New("参数错误") - } + if dbname == "" || UserId == "" || Upgrade == "" || After == "" { + return 0, errors.New("参数错误") + } - conn, err := rpc_server_conn(url...) - if err != nil { - return 0, err - } - defer conn.Close() + 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 + 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 - } + req, err := SetReqData(data) + if err != nil { + log.Println("AddUserUpgradeLog crypter error:", err) + return 0, err + } - res := &Response{} + res := &Response{} - err = conn.AddUserUpgradeLog(req, res) + err = conn.AddUserUpgradeLog(req, res) - if err != nil { - log.Println("userrpc AddUserUpgradeLog error:", err) - return 0, err - } + if err != nil { + log.Println("userrpc AddUserUpgradeLog error:", err) + return 0, err + } - res_data_de, err := GetResData(res) + res_data_de, err := GetResData(res) - if err != nil { - return 0, err - } + if err != nil { + return 0, err + } - if res_data_de == "" { - return 0, nil - } + if res_data_de == "" { + return 0, nil + } - var insertId int64 + var insertId int64 - err = json.Unmarshal([]byte(res_data_de), &insertId) + err = json.Unmarshal([]byte(res_data_de), &insertId) - if err != nil { - return 0, err - } + if err != nil { + return 0, err + } - return insertId, nil + return insertId, nil } /** @@ -517,55 +521,55 @@ func AddUserUpgradeLog(dbname, UserId, Upgrade, Before, After, Source, Memo stri * @bin */ func AddUserRedEnvelope(dbname, userId, money string, url ...string) (int64, error) { - if dbname == "" || userId == "" || money == "" { - return 0, errors.New("参数错误") - } + if dbname == "" || userId == "" || money == "" { + return 0, errors.New("参数错误") + } - conn, err := rpc_server_conn(url...) - if err != nil { - return 0, err - } - defer conn.Close() + 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 := GetAddReq{} + data.Dbname = dbname + data.UserId = userId + data.Value = money - req, err := SetReqData(data) - if err != nil { - log.Println("AddUserRedEnvelope crypter error:", err) - return 0, err - } + req, err := SetReqData(data) + if err != nil { + log.Println("AddUserRedEnvelope crypter error:", err) + return 0, err + } - res := &Response{} + res := &Response{} - err = conn.AddUserRedEnvelope(req, res) + err = conn.AddUserRedEnvelope(req, res) - if err != nil { - log.Println("userrpc AddUserRedEnvelope error:", err) - return 0, err - } + if err != nil { + log.Println("userrpc AddUserRedEnvelope error:", err) + return 0, err + } - res_data_de, err := GetResData(res) + res_data_de, err := GetResData(res) - if err != nil { - return 0, err - } + if err != nil { + return 0, err + } - if res_data_de == "" { - return 0, nil - } + if res_data_de == "" { + return 0, nil + } - var insertId int64 + var insertId int64 - err = json.Unmarshal([]byte(res_data_de), &insertId) + err = json.Unmarshal([]byte(res_data_de), &insertId) - if err != nil { - return 0, err - } + if err != nil { + return 0, err + } - return insertId, nil + return insertId, nil } /** @@ -574,56 +578,56 @@ func AddUserRedEnvelope(dbname, userId, money string, url ...string) (int64, err * @bin */ func UpdateUserRedEnvelope(dbname, userId, money, used_money string, url ...string) (bool, error) { - if dbname == "" || userId == "" || money == "" { - return false, errors.New("参数错误") - } + if dbname == "" || userId == "" || money == "" { + return false, errors.New("参数错误") + } - conn, err := rpc_server_conn(url...) - if err != nil { - return false, err - } - defer conn.Close() + 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 + 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 - } + req, err := SetReqData(data) + if err != nil { + log.Println("UpdateUserRedEnvelope crypter error:", err) + return false, err + } - res := &Response{} + res := &Response{} - err = conn.UpdateUserRedEnvelope(req, res) + err = conn.UpdateUserRedEnvelope(req, res) - if err != nil { - log.Println("userrpc UpdateUserRedEnvelope error:", err) - return false, err - } + if err != nil { + log.Println("userrpc UpdateUserRedEnvelope error:", err) + return false, err + } - res_data_de, err := GetResData(res) + res_data_de, err := GetResData(res) - if err != nil { - return false, err - } + if err != nil { + return false, err + } - if res_data_de == "" { - return false, nil - } + if res_data_de == "" { + return false, nil + } - var updateres bool + var updateres bool - err = json.Unmarshal([]byte(res_data_de), &updateres) + err = json.Unmarshal([]byte(res_data_de), &updateres) - if err != nil { - return false, err - } + if err != nil { + return false, err + } - return updateres, nil + return updateres, nil } /** @@ -632,63 +636,63 @@ func UpdateUserRedEnvelope(dbname, userId, money, used_money string, url ...stri * @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 + 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 } /** @@ -697,58 +701,58 @@ func AddUserRedEnvelopeLog(dbname, UserId, Money, Before, After, Source, SourceI * @bin */ func AddUserCoupon(dbname, userId, couponId, expireTime, orderSn, remark string, url ...string) (int64, error) { - if dbname == "" || userId == "" || couponId == "" { - return 0, errors.New("参数错误") - } + if dbname == "" || userId == "" || couponId == "" { + return 0, errors.New("参数错误") + } - conn, err := rpc_server_conn(url...) - if err != nil { - return 0, err - } - defer conn.Close() + 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 + 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 - } + req, err := SetReqData(data) + if err != nil { + log.Println("AddUserCoupon crypter error:", err) + return 0, err + } - res := &Response{} + res := &Response{} - err = conn.AddUserCoupon(req, res) + err = conn.AddUserCoupon(req, res) - if err != nil { - log.Println("userrpc AddUserCoupon error:", err) - return 0, err - } + if err != nil { + log.Println("userrpc AddUserCoupon error:", err) + return 0, err + } - res_data_de, err := GetResData(res) + res_data_de, err := GetResData(res) - if err != nil { - return 0, err - } + if err != nil { + return 0, err + } - if res_data_de == "" { - return 0, nil - } + if res_data_de == "" { + return 0, nil + } - var insertId int64 + var insertId int64 - err = json.Unmarshal([]byte(res_data_de), &insertId) + err = json.Unmarshal([]byte(res_data_de), &insertId) - if err != nil { - return 0, err - } + if err != nil { + return 0, err + } - return insertId, nil + return insertId, nil } /** @@ -757,57 +761,57 @@ func AddUserCoupon(dbname, userId, couponId, expireTime, orderSn, remark string, * @bin */ func UpdateUserCoupon(dbname, userId, couponId, remark, orderSn, isUse, usetime string, url ...string) (bool, error) { - if dbname == "" || userId == "" || couponId == "" { - return false, errors.New("参数错误") - } + if dbname == "" || userId == "" || couponId == "" { + return false, errors.New("参数错误") + } - conn, err := rpc_server_conn(url...) - if err != nil { - return false, err - } - defer conn.Close() + 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 + 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 - } + req, err := SetReqData(data) + if err != nil { + log.Println("UpdateUserCoupon crypter error:", err) + return false, err + } - res := &Response{} + res := &Response{} - err = conn.UpdateUserCoupon(req, res) + err = conn.UpdateUserCoupon(req, res) - if err != nil { - log.Println("userrpc UpdateUserCoupon error:", err) - return false, err - } + if err != nil { + log.Println("userrpc UpdateUserCoupon error:", err) + return false, err + } - res_data_de, err := GetResData(res) + res_data_de, err := GetResData(res) - if err != nil { - return false, err - } + if err != nil { + return false, err + } - if res_data_de == "" { - return false, nil - } + if res_data_de == "" { + return false, nil + } - var updateres bool + var updateres bool - err = json.Unmarshal([]byte(res_data_de), &updateres) + err = json.Unmarshal([]byte(res_data_de), &updateres) - if err != nil { - return false, err - } + if err != nil { + return false, err + } - return updateres, nil + return updateres, nil } From 16de48a135d69e0f057d60c319ee3c9deaf7d084 Mon Sep 17 00:00:00 2001 From: guzeng Date: Wed, 3 Nov 2021 21:40:41 +0800 Subject: [PATCH 21/21] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=88=90=E9=95=BF?= =?UTF-8?q?=E5=80=BC=E6=B7=BB=E5=8A=A0=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account.client.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/account.client.go b/account.client.go index 1d512f0..d12bfc9 100644 --- a/account.client.go +++ b/account.client.go @@ -345,7 +345,7 @@ func AddUserScoreLog(dbname, UserId, Score, Before, After, Source, SourceId, Ord * @2021/09/30 * @bin */ -func AddUserUpgrade(dbname, userId, upgrade string, url ...string) (int64, error) { +func AddUserUpgrade(dbname, userId, upgrade, memo string, url ...string) (int64, error) { if dbname == "" || userId == "" || upgrade == "" { return 0, errors.New("参数错误") } @@ -360,6 +360,7 @@ func AddUserUpgrade(dbname, userId, upgrade string, url ...string) (int64, error data.Dbname = dbname data.UserId = userId data.Value = upgrade + data.Memo = memo req, err := SetReqData(data) if err != nil { @@ -520,7 +521,7 @@ func AddUserUpgradeLog(dbname, UserId, Upgrade, Before, After, Source, Memo stri * @2021/09/30 * @bin */ -func AddUserRedEnvelope(dbname, userId, money string, url ...string) (int64, error) { +func AddUserRedEnvelope(dbname, userId, money, memo string, url ...string) (int64, error) { if dbname == "" || userId == "" || money == "" { return 0, errors.New("参数错误") } @@ -535,6 +536,7 @@ func AddUserRedEnvelope(dbname, userId, money string, url ...string) (int64, err data.Dbname = dbname data.UserId = userId data.Value = money + data.Memo = memo req, err := SetReqData(data) if err != nil {