ext
This commit is contained in:
parent
6ae64b443b
commit
593bf8e46a
|
|
@ -0,0 +1,53 @@
|
||||||
|
package erp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"git.u8t.cn/open/goutil"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ApprovalProfitAmountTypeCost = "消耗"
|
||||||
|
ApprovalProfitAmountTypeProfit = "利润"
|
||||||
|
ApprovalProfitAmountTypeAward = "奖励"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ApprovalProfitCreate struct {
|
||||||
|
SpNo string `json:"sp_no"` //申请单号,相同的单号数据将会被替换
|
||||||
|
Month string `json:"month"` //业绩对应月份
|
||||||
|
Username string `json:"username"` //业绩对应责任人
|
||||||
|
AmountType string `json:"amount_type"` //业绩类型
|
||||||
|
Amount string `json:"amount"` //业绩金额 单位元
|
||||||
|
Description string `json:"description"` //业绩描述
|
||||||
|
AppId string `json:"app_id"` //业绩对应的业务ID
|
||||||
|
}
|
||||||
|
|
||||||
|
type ApprovalProfit struct {
|
||||||
|
Erp
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewApprovalProfit(baseUrl, token string) *ApprovalProfit {
|
||||||
|
return &ApprovalProfit{
|
||||||
|
Erp: Erp{
|
||||||
|
baseUrl: baseUrl,
|
||||||
|
token: token,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *ApprovalProfit) Create(req *ApprovalProfitCreate) error {
|
||||||
|
var reqBody string
|
||||||
|
reqBody = goutil.EncodeJSON(req)
|
||||||
|
reqUrl := e.GetBaseUrl() + "/ext/staff/profit"
|
||||||
|
|
||||||
|
body, err := goutil.HttpPost(reqUrl, e.GetHeader(), []byte(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
g := gjson.ParseBytes(body)
|
||||||
|
if g.Get("code").Int() != 0 {
|
||||||
|
return errors.New(string(body))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package erp
|
||||||
|
|
||||||
|
type Erp struct {
|
||||||
|
token string
|
||||||
|
baseUrl string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Erp) GetHeader() map[string]string {
|
||||||
|
return map[string]string{
|
||||||
|
"x-token": e.token,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Erp) GetBaseUrl() string {
|
||||||
|
if e.baseUrl != "" {
|
||||||
|
return e.baseUrl
|
||||||
|
}
|
||||||
|
return "http://eapi.batiao8.com"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package erp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"git.u8t.cn/open/goutil"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StaffTarget struct {
|
||||||
|
Erp
|
||||||
|
}
|
||||||
|
|
||||||
|
type StaffTargetCreate struct {
|
||||||
|
Username string `json:"username"`
|
||||||
|
Month string `json:"month"`
|
||||||
|
Day string `json:"day"`
|
||||||
|
Score string `json:"score"`
|
||||||
|
Comment string `json:"comment"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStaffTarget(baseUrl, token string) *StaffTarget {
|
||||||
|
return &StaffTarget{
|
||||||
|
Erp: Erp{
|
||||||
|
baseUrl: baseUrl,
|
||||||
|
token: token,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *StaffTarget) Create(req *StaffTargetCreate) error {
|
||||||
|
reqUrl := e.GetBaseUrl() + "/ext/staff/target"
|
||||||
|
body, err := goutil.HttpPost(reqUrl, e.GetHeader(), []byte(goutil.EncodeJSON(req)))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
g := gjson.ParseBytes(body)
|
||||||
|
if g.Get("code").Int() != 0 {
|
||||||
|
return errors.New(string(body))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
package erp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.u8t.cn/open/goutil"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StaffCode struct {
|
||||||
|
Timestamp string `json:"timestamp"`
|
||||||
|
}
|
||||||
|
type StaffInfo struct {
|
||||||
|
Username string `json:"username"`
|
||||||
|
Realname string `json:"realname"`
|
||||||
|
Phone string `json:"phone"`
|
||||||
|
}
|
||||||
|
type StaffUser struct {
|
||||||
|
Erp
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStaffUser(baseUrl, token string) *StaffUser {
|
||||||
|
return &StaffUser{
|
||||||
|
Erp: Erp{
|
||||||
|
baseUrl: baseUrl,
|
||||||
|
token: token,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *StaffUser) SendCode(username, scene string) (*StaffCode, error) {
|
||||||
|
var reqBody string
|
||||||
|
reqBody = fmt.Sprintf(`{"username":"%s","scene":"%s"}`, username, scene)
|
||||||
|
reqUrl := e.GetBaseUrl() + "/ext/staff/user/code"
|
||||||
|
|
||||||
|
body, err := goutil.HttpPost(reqUrl, e.GetHeader(), []byte(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
g := gjson.ParseBytes(body)
|
||||||
|
if g.Get("code").Int() != 0 {
|
||||||
|
return nil, errors.New(string(body))
|
||||||
|
}
|
||||||
|
r := new(StaffCode)
|
||||||
|
r.Timestamp = g.Get("data.timestamp").String()
|
||||||
|
|
||||||
|
return r, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *StaffUser) Login(username, timestamp, code string) (*StaffInfo, error) {
|
||||||
|
reqBody := fmt.Sprintf(`{"username":"%s","timestamp":"%s","code":"%s"}`, username, timestamp, code)
|
||||||
|
reqUrl := e.GetBaseUrl() + "/ext/staff/login"
|
||||||
|
body, err := goutil.HttpPost(reqUrl, e.GetHeader(), []byte(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
g := gjson.ParseBytes(body)
|
||||||
|
if g.Get("code").Int() != 0 {
|
||||||
|
return nil, errors.New(string(body))
|
||||||
|
}
|
||||||
|
|
||||||
|
r := new(StaffInfo)
|
||||||
|
r.Realname = g.Get("data.realname").String()
|
||||||
|
r.Username = g.Get("data.username").String()
|
||||||
|
r.Phone = g.Get("data.phone").String()
|
||||||
|
|
||||||
|
return r, nil
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue