Commit cdb952ca authored by hujiebin's avatar hujiebin

发送用户道具

parent 1b487799
......@@ -2,6 +2,7 @@ package rpc
import (
"encoding/json"
"errors"
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mylogrus"
......@@ -134,6 +135,121 @@ func GetUserBagId(model *domain.Model, bagId mysql.ID) (CvUserBag, error) {
return response.Data, nil
}
// 发送用户背包
func SendUserBag(model *domain.Model, userId mysql.ID, resType, resId mysql.ID, count, day mysql.Num, reason string) error {
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
}
_url := fmt.Sprintf("%v://%v/inner/prop/bag/send", defaultUserServerScheme, getUserHost())
resp, err := HttpPostForm(model, _url, nil, map[string]string{
"userId": fmt.Sprintf("%d", userId),
"resType": fmt.Sprintf("%d", resType),
"resId": fmt.Sprintf("%d", resId),
"count": fmt.Sprintf("%d", count),
"day": fmt.Sprintf("%d", day),
"reason": reason,
})
if err != nil {
model.Log.Errorf("SendUserBag fail:%v", err)
return err
}
response := new(Response)
if err = json.Unmarshal(resp, response); err != nil {
model.Log.Errorf("SendUserBag json fail:%v", err)
return err
}
if response.Code != 200 {
model.Log.Errorf("SendUserBag fail:%v", *response)
return errors.New(response.Message)
}
return nil
}
// 发送用户贵族
func SendUserNoble(model *domain.Model, userId mysql.ID, level int, day mysql.Num) error {
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
}
_url := fmt.Sprintf("%v://%v/inner/prop/noble/send", defaultUserServerScheme, getUserHost())
resp, err := HttpPostForm(model, _url, nil, map[string]string{
"userId": fmt.Sprintf("%d", userId),
"level": fmt.Sprintf("%d", level),
"day": fmt.Sprintf("%d", day),
})
if err != nil {
model.Log.Errorf("SendUserNoble fail:%v", err)
return err
}
response := new(Response)
if err = json.Unmarshal(resp, response); err != nil {
model.Log.Errorf("SendUserNoble json fail:%v", err)
return err
}
if response.Code != 200 {
model.Log.Errorf("SendUserNoble fail:%v", *response)
return errors.New(response.Message)
}
return nil
}
// 发送用户头饰
func SendUserHeadwear(model *domain.Model, userId mysql.ID, headwearId mysql.ID, day mysql.Num) error {
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
}
_url := fmt.Sprintf("%v://%v/inner/prop/headwear/send", defaultUserServerScheme, getUserHost())
resp, err := HttpPostForm(model, _url, nil, map[string]string{
"userId": fmt.Sprintf("%d", userId),
"headwearId": fmt.Sprintf("%d", headwearId),
"day": fmt.Sprintf("%d", day),
})
if err != nil {
model.Log.Errorf("SendUserHeadwear fail:%v", err)
return err
}
response := new(Response)
if err = json.Unmarshal(resp, response); err != nil {
model.Log.Errorf("SendUserHeadwear json fail:%v", err)
return err
}
if response.Code != 200 {
model.Log.Errorf("SendUserHeadwear fail:%v", *response)
return errors.New(response.Message)
}
return nil
}
// 发送用户座驾
func SendUserRide(model *domain.Model, userId mysql.ID, rideId mysql.ID, day mysql.Num) error {
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
}
_url := fmt.Sprintf("%v://%v/inner/prop/ride/send", defaultUserServerScheme, getUserHost())
resp, err := HttpPostForm(model, _url, nil, map[string]string{
"userId": fmt.Sprintf("%d", userId),
"rideId": fmt.Sprintf("%d", rideId),
"day": fmt.Sprintf("%d", day),
})
if err != nil {
model.Log.Errorf("SendUserRide fail:%v", err)
return err
}
response := new(Response)
if err = json.Unmarshal(resp, response); err != nil {
model.Log.Errorf("SendUserRide json fail:%v", err)
return err
}
if response.Code != 200 {
model.Log.Errorf("SendUserRide fail:%v", *response)
return errors.New(response.Message)
}
return nil
}
func getUserHost() string {
l := len(UserServerHost)
r := rand.Intn(l) // 随机一个
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment