business.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strconv"
  7. "time"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. "github.com/pkg/errors"
  11. )
  12. const (
  13. _SendUserNotify = "/api/notify/send.user.notify.do"
  14. _PayAPIAdd = "/api/coupon/regular/add"
  15. _CleanCache = "/notify/cleanCacheAndNotify"
  16. _loginout = "/intranet/acc/security/mid"
  17. )
  18. //Loginout login out
  19. func (d *Dao) Loginout(c context.Context, mid int64) (err error) {
  20. val := url.Values{}
  21. val.Add("mids", strconv.FormatInt(mid, 10))
  22. val.Add("operator", strconv.FormatInt(mid, 10))
  23. val.Add("desc", "大会员解冻")
  24. resp := new(struct {
  25. Code int `json:"code"`
  26. Msg string `json:"msg"`
  27. })
  28. defer func() {
  29. log.Info("vip Loginout url:%+v params:%+v return:%+v", d.loginOutURL, val, resp)
  30. }()
  31. if err = d.client.Post(c, d.loginOutURL, "", val, resp); err != nil {
  32. err = errors.Errorf("vip Loginout url:%+v params:%+v return:%+v,err:%+v", d.loginOutURL, val, resp, err)
  33. return
  34. }
  35. if resp.Code != ecode.OK.Code() {
  36. err = ecode.Int(resp.Code)
  37. }
  38. return
  39. }
  40. //SendCleanCache clean cache
  41. func (d *Dao) SendCleanCache(c context.Context, mid int64, months int16, days int64, t int, ip string) (err error) {
  42. params := url.Values{}
  43. params.Set("mid", strconv.FormatInt(int64(mid), 10))
  44. params.Set("months", strconv.FormatInt(int64(months), 10))
  45. params.Set("days", strconv.FormatInt(int64(days), 10))
  46. params.Set("type", strconv.FormatInt(int64(t), 10))
  47. if err = d.client.Get(c, d.vipURI, ip, params, nil); err != nil {
  48. log.Error("SendCleanCache error(%v) url(%v)", err, d.vipURI)
  49. return
  50. }
  51. return
  52. }
  53. //SendMultipMsg send multip msg
  54. func (d *Dao) SendMultipMsg(c context.Context, mids, content, title, mc, ip string, dataType int) (err error) {
  55. params := url.Values{}
  56. params.Set("mc", mc)
  57. params.Set("title", title)
  58. params.Set("context", content)
  59. params.Set("data_type", strconv.FormatInt(int64(dataType), 10))
  60. params.Set("mid_list", mids)
  61. if err = d.client.Post(c, d.msgURI, ip, params, nil); err != nil {
  62. log.Error("SendMultipMsg error(%v)", err)
  63. return
  64. }
  65. return
  66. }
  67. //SendBcoinCoupon send bcoin coupon
  68. func (d *Dao) SendBcoinCoupon(c context.Context, mids, activityID string, money int64, dueTime time.Time) (err error) {
  69. params := url.Values{}
  70. params.Set("activity_id", activityID)
  71. params.Set("mids", mids)
  72. params.Set("money", strconv.FormatInt(int64(money), 10))
  73. params.Set("due_time", dueTime.Format("2006-01-02"))
  74. if err = d.client.Post(c, d.payURI, "127.0.0.1", params, nil); err != nil {
  75. log.Error("SendBcoinCoupon error(%v)", err)
  76. fmt.Printf("SendBcoinCoupon error(%v)", err)
  77. return
  78. }
  79. return
  80. }