用户接口远程调用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

819 lines
14 KiB

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