123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573 |
- package eta_trial
- import (
- "encoding/json"
- "eta/eta_mobile/models"
- "eta/eta_mobile/models/eta_trial"
- "eta/eta_mobile/utils"
- "fmt"
- "io/ioutil"
- "net/http"
- "strings"
- )
- // EtaTrialUserReq 更新试用客户最后登录时间和次数请求体
- type EtaTrialUserReq struct {
- Mobile string `description:"手机号"`
- }
- // UpdateEtaTrialUserLogin CRM_ETA服务-更新试用客户最后登录时间和次数
- func UpdateEtaTrialUserLogin(pars EtaTrialUserReq) (res bool, err error) {
- url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta_trial/user/update_login")
- params, e := json.Marshal(pars)
- if e != nil {
- err = fmt.Errorf("data json marshal err: %s", e.Error())
- return
- }
- body := ioutil.NopCloser(strings.NewReader(string(params)))
- client := &http.Client{}
- req, e := http.NewRequest("POST", url, body)
- if e != nil {
- err = fmt.Errorf("http create request err: %s", e.Error())
- return
- }
- contentType := "application/json;charset=utf-8"
- req.Header.Set("Content-Type", contentType)
- req.Header.Set("Authorization", utils.CrmEtaAuthorization)
- resp, e := client.Do(req)
- if e != nil {
- err = fmt.Errorf("http client do err: %s", e.Error())
- return
- }
- defer func() {
- _ = resp.Body.Close()
- }()
- b, e := ioutil.ReadAll(resp.Body)
- if e != nil {
- err = fmt.Errorf("resp body read err: %s", e.Error())
- return
- }
- if len(b) == 0 {
- err = fmt.Errorf("resp body is empty")
- return
- }
- // 生产环境解密, 注意有个坑前后的双引号
- if utils.RunMode == "release" {
- str := string(b)
- str = strings.Trim(str, `"`)
- b = utils.DesBase64Decrypt([]byte(str), utils.CrmEtaServerDes3Key)
- }
- result := new(models.ResultData)
- if e = json.Unmarshal(b, &result); e != nil {
- err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
- return
- }
- if result.Code != 200 {
- err = fmt.Errorf("result: %s", string(b))
- return
- }
- res = true
- return
- }
- // GetEtaTrialUserReq 获取试用客户请求体
- type GetEtaTrialUserReq struct {
- Mobile string `description:"手机号"`
- }
- type EtaTrialUserResp struct {
- Code int `json:"code" description:"状态码"`
- Msg string `json:"msg" description:"提示信息"`
- Data eta_trial.EtaTrialUserItem `json:"data" description:"返回数据"`
- ErrMsg string `json:"-" description:"错误信息,不用返回给前端,只是做日志记录"`
- }
- // GetEtaTrialUser CRM_ETA服务-获取试用客户信息
- func GetEtaTrialUser(pars GetEtaTrialUserReq) (res eta_trial.EtaTrialUserItem, err error) {
- url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta_trial/user/mobile_fetch")
- params, e := json.Marshal(pars)
- if e != nil {
- err = fmt.Errorf("data json marshal err: %s", e.Error())
- return
- }
- body := ioutil.NopCloser(strings.NewReader(string(params)))
- client := &http.Client{}
- req, e := http.NewRequest("POST", url, body)
- if e != nil {
- err = fmt.Errorf("http create request err: %s", e.Error())
- return
- }
- contentType := "application/json;charset=utf-8"
- req.Header.Set("Content-Type", contentType)
- req.Header.Set("Authorization", utils.CrmEtaAuthorization)
- resp, e := client.Do(req)
- if e != nil {
- err = fmt.Errorf("http client do err: %s", e.Error())
- return
- }
- defer func() {
- _ = resp.Body.Close()
- }()
- b, e := ioutil.ReadAll(resp.Body)
- if e != nil {
- err = fmt.Errorf("resp body read err: %s", e.Error())
- return
- }
- if len(b) == 0 {
- err = fmt.Errorf("resp body is empty")
- return
- }
- // 生产环境解密, 注意有个坑前后的双引号
- if utils.RunMode == "release" {
- str := string(b)
- str = strings.Trim(str, `"`)
- b = utils.DesBase64Decrypt([]byte(str), utils.CrmEtaServerDes3Key)
- }
- //result := new(models.ResultData)
- result := new(EtaTrialUserResp)
- if e = json.Unmarshal(b, &result); e != nil {
- err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
- return
- }
- utils.FileLog.Info("%s", string(b))
- if result.Code != 200 {
- err = fmt.Errorf("result: %s", string(b))
- return
- }
- res = result.Data
- //r, ok := result.Data.(eta_trial.EtaTrialUserResp)
- //if !ok {
- // err = fmt.Errorf("result data err")
- // return
- //}
- //res = r
- return
- }
- // DisableEtaTrialUser CRM_ETA服务-禁用试用客户
- func DisableEtaTrialUser(pars EtaTrialUserReq) (res bool, err error) {
- url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta_trial/user/disable")
- params, e := json.Marshal(pars)
- if e != nil {
- err = fmt.Errorf("data json marshal err: %s", e.Error())
- return
- }
- body := ioutil.NopCloser(strings.NewReader(string(params)))
- client := &http.Client{}
- req, e := http.NewRequest("POST", url, body)
- if e != nil {
- err = fmt.Errorf("http create request err: %s", e.Error())
- return
- }
- contentType := "application/json;charset=utf-8"
- req.Header.Set("Content-Type", contentType)
- req.Header.Set("Authorization", utils.CrmEtaAuthorization)
- resp, e := client.Do(req)
- if e != nil {
- err = fmt.Errorf("http client do err: %s", e.Error())
- return
- }
- defer func() {
- _ = resp.Body.Close()
- }()
- b, e := ioutil.ReadAll(resp.Body)
- if e != nil {
- err = fmt.Errorf("resp body read err: %s", e.Error())
- return
- }
- if len(b) == 0 {
- err = fmt.Errorf("resp body is empty")
- return
- }
- // 生产环境解密, 注意有个坑前后的双引号
- if utils.RunMode == "release" {
- str := string(b)
- str = strings.Trim(str, `"`)
- b = utils.DesBase64Decrypt([]byte(str), utils.CrmEtaServerDes3Key)
- }
- result := new(models.ResultData)
- if e = json.Unmarshal(b, &result); e != nil {
- err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
- return
- }
- if result.Code != 200 {
- err = fmt.Errorf("result: %s", string(b))
- return
- }
- res = true
- return
- }
- // RemoveEtaTrialUser CRM_ETA服务-删除试用客户
- func RemoveEtaTrialUser(pars EtaTrialUserReq) (res bool, err error) {
- url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta_trial/user/remove")
- params, e := json.Marshal(pars)
- if e != nil {
- err = fmt.Errorf("data json marshal err: %s", e.Error())
- return
- }
- body := ioutil.NopCloser(strings.NewReader(string(params)))
- client := &http.Client{}
- req, e := http.NewRequest("POST", url, body)
- if e != nil {
- err = fmt.Errorf("http create request err: %s", e.Error())
- return
- }
- contentType := "application/json;charset=utf-8"
- req.Header.Set("Content-Type", contentType)
- req.Header.Set("Authorization", utils.CrmEtaAuthorization)
- resp, e := client.Do(req)
- if e != nil {
- err = fmt.Errorf("http client do err: %s", e.Error())
- return
- }
- defer func() {
- _ = resp.Body.Close()
- }()
- b, e := ioutil.ReadAll(resp.Body)
- if e != nil {
- err = fmt.Errorf("resp body read err: %s", e.Error())
- return
- }
- if len(b) == 0 {
- err = fmt.Errorf("resp body is empty")
- return
- }
- // 生产环境解密, 注意有个坑前后的双引号
- if utils.RunMode == "release" {
- str := string(b)
- str = strings.Trim(str, `"`)
- b = utils.DesBase64Decrypt([]byte(str), utils.CrmEtaServerDes3Key)
- }
- result := new(models.ResultData)
- if e = json.Unmarshal(b, &result); e != nil {
- err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
- return
- }
- if result.Code != 200 {
- err = fmt.Errorf("result: %s", string(b))
- return
- }
- res = true
- return
- }
- // EtaTrialUserEditReq 更新用户信息请求体
- type EtaTrialUserEditReq struct {
- RealName string `description:"姓名"`
- Position string `description:"职务"`
- Mobile string `description:"手机号"`
- Enabled int `description:"禁启用"`
- }
- // EditEtaTrialUser CRM_ETA服务-编辑试用客户
- func EditEtaTrialUser(pars EtaTrialUserEditReq) (res bool, err error) {
- url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta_trial/user/edit")
- params, e := json.Marshal(pars)
- if e != nil {
- err = fmt.Errorf("data json marshal err: %s", e.Error())
- return
- }
- body := ioutil.NopCloser(strings.NewReader(string(params)))
- client := &http.Client{}
- req, e := http.NewRequest("POST", url, body)
- if e != nil {
- err = fmt.Errorf("http create request err: %s", e.Error())
- return
- }
- contentType := "application/json;charset=utf-8"
- req.Header.Set("Content-Type", contentType)
- req.Header.Set("Authorization", utils.CrmEtaAuthorization)
- resp, e := client.Do(req)
- if e != nil {
- err = fmt.Errorf("http client do err: %s", e.Error())
- return
- }
- defer func() {
- _ = resp.Body.Close()
- }()
- b, e := ioutil.ReadAll(resp.Body)
- if e != nil {
- err = fmt.Errorf("resp body read err: %s", e.Error())
- return
- }
- if len(b) == 0 {
- err = fmt.Errorf("resp body is empty")
- return
- }
- // 生产环境解密, 注意有个坑前后的双引号
- if utils.RunMode == "release" {
- str := string(b)
- str = strings.Trim(str, `"`)
- b = utils.DesBase64Decrypt([]byte(str), utils.CrmEtaServerDes3Key)
- }
- result := new(models.ResultData)
- if e = json.Unmarshal(b, &result); e != nil {
- err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
- return
- }
- if result.Code != 200 {
- err = fmt.Errorf("result: %s", string(b))
- return
- }
- res = true
- return
- }
- // UpdateUserIndexNum CRM_ETA服务-更新用户累计新增指标数
- func UpdateUserIndexNum(pars EtaTrialUserReq) (res bool, err error) {
- url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta_trial/user/update_index_num")
- params, e := json.Marshal(pars)
- if e != nil {
- err = fmt.Errorf("data json marshal err: %s", e.Error())
- return
- }
- body := ioutil.NopCloser(strings.NewReader(string(params)))
- client := &http.Client{}
- req, e := http.NewRequest("POST", url, body)
- if e != nil {
- err = fmt.Errorf("http create request err: %s", e.Error())
- return
- }
- contentType := "application/json;charset=utf-8"
- req.Header.Set("Content-Type", contentType)
- req.Header.Set("Authorization", utils.CrmEtaAuthorization)
- resp, e := client.Do(req)
- if e != nil {
- err = fmt.Errorf("http client do err: %s", e.Error())
- return
- }
- defer func() {
- _ = resp.Body.Close()
- }()
- b, e := ioutil.ReadAll(resp.Body)
- if e != nil {
- err = fmt.Errorf("resp body read err: %s", e.Error())
- return
- }
- if len(b) == 0 {
- err = fmt.Errorf("resp body is empty")
- return
- }
- // 生产环境解密, 注意有个坑前后的双引号
- if utils.RunMode == "release" {
- str := string(b)
- str = strings.Trim(str, `"`)
- b = utils.DesBase64Decrypt([]byte(str), utils.CrmEtaServerDes3Key)
- }
- result := new(models.ResultData)
- if e = json.Unmarshal(b, &result); e != nil {
- err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
- return
- }
- if result.Code != 200 {
- err = fmt.Errorf("result: %s", string(b))
- return
- }
- res = true
- return
- }
- // UpdateUserChartNum CRM_ETA服务-更新用户累计新增图表数
- func UpdateUserChartNum(pars EtaTrialUserReq) (res bool, err error) {
- url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta_trial/user/update_chart_num")
- params, e := json.Marshal(pars)
- if e != nil {
- err = fmt.Errorf("data json marshal err: %s", e.Error())
- return
- }
- body := ioutil.NopCloser(strings.NewReader(string(params)))
- client := &http.Client{}
- req, e := http.NewRequest("POST", url, body)
- if e != nil {
- err = fmt.Errorf("http create request err: %s", e.Error())
- return
- }
- contentType := "application/json;charset=utf-8"
- req.Header.Set("Content-Type", contentType)
- req.Header.Set("Authorization", utils.CrmEtaAuthorization)
- resp, e := client.Do(req)
- if e != nil {
- err = fmt.Errorf("http client do err: %s", e.Error())
- return
- }
- defer func() {
- _ = resp.Body.Close()
- }()
- b, e := ioutil.ReadAll(resp.Body)
- if e != nil {
- err = fmt.Errorf("resp body read err: %s", e.Error())
- return
- }
- if len(b) == 0 {
- err = fmt.Errorf("resp body is empty")
- return
- }
- // 生产环境解密, 注意有个坑前后的双引号
- if utils.RunMode == "release" {
- str := string(b)
- str = strings.Trim(str, `"`)
- b = utils.DesBase64Decrypt([]byte(str), utils.CrmEtaServerDes3Key)
- }
- result := new(models.ResultData)
- if e = json.Unmarshal(b, &result); e != nil {
- err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
- return
- }
- if result.Code != 200 {
- err = fmt.Errorf("result: %s", string(b))
- return
- }
- res = true
- return
- }
- // UpdateEtaTrialUserActiveTimeReq 更新试用客户活跃时长请求体
- type UpdateEtaTrialUserActiveTimeReq struct {
- Mobile string `description:"手机号"`
- UserName string `description:"用户姓名"`
- ActiveTime int `description:"活跃时长, 单位秒"`
- Part string `description:"活跃板块"`
- }
- // UpdateEtaTrialUserActiveTime CRM_ETA服务-更新试用客户活跃时长
- func UpdateEtaTrialUserActiveTime(pars UpdateEtaTrialUserActiveTimeReq) (res bool, err error) {
- url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta_trial/user/update_active_time")
- params, e := json.Marshal(pars)
- if e != nil {
- err = fmt.Errorf("data json marshal err: %s", e.Error())
- return
- }
- body := ioutil.NopCloser(strings.NewReader(string(params)))
- client := &http.Client{}
- req, e := http.NewRequest("POST", url, body)
- if e != nil {
- err = fmt.Errorf("http create request err: %s", e.Error())
- return
- }
- contentType := "application/json;charset=utf-8"
- req.Header.Set("Content-Type", contentType)
- req.Header.Set("Authorization", utils.CrmEtaAuthorization)
- resp, e := client.Do(req)
- if e != nil {
- err = fmt.Errorf("http client do err: %s", e.Error())
- return
- }
- defer func() {
- _ = resp.Body.Close()
- }()
- b, e := ioutil.ReadAll(resp.Body)
- if e != nil {
- err = fmt.Errorf("resp body read err: %s", e.Error())
- return
- }
- if len(b) == 0 {
- err = fmt.Errorf("resp body is empty")
- return
- }
- // 生产环境解密, 注意有个坑前后的双引号
- if utils.RunMode == "release" {
- str := string(b)
- str = strings.Trim(str, `"`)
- b = utils.DesBase64Decrypt([]byte(str), utils.CrmEtaServerDes3Key)
- }
- result := new(models.ResultData)
- if e = json.Unmarshal(b, &result); e != nil {
- err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
- return
- }
- if result.Code != 200 {
- err = fmt.Errorf("result: %s", string(b))
- return
- }
- res = true
- return
- }
- // UpdateEtaTrialUserLoginDurationReq 更新试用客户登录时长请求体
- type UpdateEtaTrialUserLoginDurationReq struct {
- Mobile string `description:"手机号"`
- UserName string `description:"用户姓名"`
- ActiveTime int `description:"活跃时长, 单位秒"`
- }
- // UpdateEtaTrialUserLoginDuration CRM_ETA服务-更新试用客户登录时长
- func UpdateEtaTrialUserLoginDuration(pars UpdateEtaTrialUserLoginDurationReq) (res bool, err error) {
- url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta_trial/user/update_login_duration")
- params, e := json.Marshal(pars)
- if e != nil {
- err = fmt.Errorf("data json marshal err: %s", e.Error())
- return
- }
- body := ioutil.NopCloser(strings.NewReader(string(params)))
- client := &http.Client{}
- req, e := http.NewRequest("POST", url, body)
- if e != nil {
- err = fmt.Errorf("http create request err: %s", e.Error())
- return
- }
- contentType := "application/json;charset=utf-8"
- req.Header.Set("Content-Type", contentType)
- req.Header.Set("Authorization", utils.CrmEtaAuthorization)
- resp, e := client.Do(req)
- if e != nil {
- err = fmt.Errorf("http client do err: %s", e.Error())
- return
- }
- defer func() {
- _ = resp.Body.Close()
- }()
- b, e := ioutil.ReadAll(resp.Body)
- if e != nil {
- err = fmt.Errorf("resp body read err: %s", e.Error())
- return
- }
- if len(b) == 0 {
- err = fmt.Errorf("resp body is empty")
- return
- }
- // 生产环境解密, 注意有个坑前后的双引号
- if utils.RunMode == "release" {
- str := string(b)
- str = strings.Trim(str, `"`)
- b = utils.DesBase64Decrypt([]byte(str), utils.CrmEtaServerDes3Key)
- }
- result := new(models.ResultData)
- if e = json.Unmarshal(b, &result); e != nil {
- err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
- return
- }
- if result.Code != 200 {
- err = fmt.Errorf("result: %s", string(b))
- return
- }
- res = true
- return
- }
|