DengBiao pirms 11 mēnešiem
vecāks
revīzija
1741022add
59 mainītis faili ar 2985 papildinājumiem un 25 dzēšanām
  1. +85
    -0
      app/tool/api.go
  2. +29
    -0
      cloud_issuance/db/db_cloud_issuance_basic.go
  3. +31
    -0
      cloud_issuance/db/db_cloud_issuance_copy_writing.go
  4. +85
    -0
      cloud_issuance/db/db_cloud_issuance_goods.go
  5. +71
    -0
      cloud_issuance/db/db_cloud_issuance_goods_category.go
  6. +58
    -0
      cloud_issuance/db/db_cloud_issuance_package.go
  7. +70
    -0
      cloud_issuance/db/db_cloud_issuance_package_ord.go
  8. +61
    -0
      cloud_issuance/db/db_cloud_issuance_user_free_robot_records.go
  9. +103
    -0
      cloud_issuance/db/db_cloud_issuance_user_robot.go
  10. +131
    -0
      cloud_issuance/db/db_cloud_issuance_user_robot_bind_follow.go
  11. +106
    -0
      cloud_issuance/db/db_cloud_issuance_user_robot_bind_follow_group.go
  12. +110
    -0
      cloud_issuance/db/db_cloud_issuance_user_robot_bind_follow_user.go
  13. +88
    -0
      cloud_issuance/db/db_cloud_issuance_user_robot_bind_group.go
  14. +29
    -0
      cloud_issuance/db/model/cloud_issuance_basic.go
  15. +15
    -0
      cloud_issuance/db/model/cloud_issuance_copy_writing.go
  16. +29
    -0
      cloud_issuance/db/model/cloud_issuance_goods.go
  17. +13
    -0
      cloud_issuance/db/model/cloud_issuance_goods_category.go
  18. +20
    -0
      cloud_issuance/db/model/cloud_issuance_master_recharge_ord.go
  19. +19
    -0
      cloud_issuance/db/model/cloud_issuance_package_ord.go
  20. +19
    -0
      cloud_issuance/db/model/cloud_issuance_robot_package.go
  21. +15
    -0
      cloud_issuance/db/model/cloud_issuance_user_free_robot_records.go
  22. +27
    -0
      cloud_issuance/db/model/cloud_issuance_user_robot.go
  23. +20
    -0
      cloud_issuance/db/model/cloud_issuance_user_robot_bind_follow.go
  24. +18
    -0
      cloud_issuance/db/model/cloud_issuance_user_robot_bind_follow_group.go
  25. +15
    -0
      cloud_issuance/db/model/cloud_issuance_user_robot_bind_follow_user.go
  26. +21
    -0
      cloud_issuance/db/model/cloud_issuance_user_robot_bind_group.go
  27. +9
    -0
      cloud_issuance/db/model/demo_data.go
  28. +15
    -0
      cloud_issuance/db/official/db_cloud_issuance_baisc.go
  29. +117
    -0
      cloud_issuance/db/official/db_cloud_issuance_master.go
  30. +62
    -0
      cloud_issuance/db/official/db_cloud_issuance_robot_records.go
  31. +15
    -0
      cloud_issuance/db/official/model/cloud_issuance_basic.go
  32. +14
    -0
      cloud_issuance/db/official/model/cloud_issuance_master.go
  33. +22
    -0
      cloud_issuance/db/official/model/cloud_issuance_master_buy_ord.go
  34. +15
    -0
      cloud_issuance/db/official/model/cloud_issuance_robot.go
  35. +8
    -0
      cloud_issuance/db/official/model/cloud_issuance_robot_records.go
  36. +8
    -0
      cloud_issuance/db/official/model/user_app_list.go
  37. +8
    -0
      cloud_issuance/db/official/model/user_app_member.go
  38. +76
    -0
      cloud_issuance/enum/enum_api.go
  39. +49
    -0
      cloud_issuance/enum/enum_cloud_issuance_user_robot.go
  40. +31
    -0
      cloud_issuance/enum/enum_goods_category.go
  41. +173
    -0
      cloud_issuance/md/md_api.go
  42. +18
    -0
      cloud_issuance/md/md_call_back.go
  43. +1
    -0
      cloud_issuance/md/md_cloud_issuance_user_robot.go
  44. +26
    -0
      cloud_issuance/md/md_package.go
  45. +93
    -0
      cloud_issuance/md/md_request.go
  46. +77
    -0
      cloud_issuance/md/mq.go
  47. +307
    -0
      cloud_issuance/svc/svc_cloud_issuance.go
  48. +141
    -0
      cloud_issuance/svc/svc_deal_call_back.go
  49. +85
    -0
      cloud_issuance/tool/api.go
  50. +26
    -0
      cloud_issuance/utils/algorithm.go
  51. +60
    -0
      cloud_issuance/utils/rpc_client.go
  52. +10
    -0
      cloud_issuance/utils/string.go
  53. +143
    -0
      consume/canal_order_consume.go
  54. +4
    -3
      consume/cloud_issuance_async_mlogin.go
  55. +69
    -0
      consume/cloud_issuance_msg_callback.go
  56. +2
    -0
      consume/init.go
  57. +10
    -0
      consume/md/consume_key.go
  58. +0
    -20
      consume/md/md_cloud_issuance.go
  59. +3
    -2
      go.mod

+ 85
- 0
app/tool/api.go Parādīt failu

@@ -0,0 +1,85 @@
package tool

import (
"applet/app/md"
"applet/app/utils"
"encoding/json"
"errors"
"fmt"
"sort"
"time"
)

const (
RequestUrl = "http://router.itaokecms.com/api?app_key=%s&v=1.0&format=json&sign_method=md5&method=%s&timestamp=%s&domain=%s&client=%s&partner_id=%s&sign=%s"
AppKey = "1091808433"
AppSecret = "bed35c10-ecf1-2d06-477b-f821c227198b"
Domain = "hairuyi.com"
PartnerId = "top-sdk-php-20190618"
)

func SendPost(url string, args interface{}) (data md.CurlResponse, err error) {
utils.FilePutContents("cloud_issuance_send", utils.SerializeStr(map[string]interface{}{
"time": time.Now().Format("2006-01-02 15:04:05.000"),
"args": args,
"url": url,
}))
post, err := utils.CurlPost(url, utils.Serialize(args), map[string]string{})
err = json.Unmarshal(post, &data)
utils.FilePutContents("cloud_issuance_send", utils.SerializeStr(map[string]interface{}{
"time": time.Now().Format("2006-01-02 15:04:05.000"),
"resp": post,
}))
if err != nil {
return
}
if data.Status != "0000" {
err = errors.New(data.Msg)
return
}
return data, err
}

func HttpBuild(methodName, clientIP string, params map[string]string) (httpUrl string) {
timestamp := utils.AnyToString(time.Now().Unix())
params["app_key"] = AppKey
params["v"] = "1.0"
params["format"] = "json"
params["sign_method"] = "md5"
params["method"] = methodName
params["timestamp"] = timestamp
params["domain"] = Domain
params["client"] = clientIP
params["partner_id"] = PartnerId
sign := httpBuildQuery(params, true)
sign = AppSecret + httpBuildQuery(params, true) + AppSecret
sign = utils.MD5ToUpper32(sign)
httpUrl = fmt.Sprintf(RequestUrl, AppKey, methodName, timestamp, Domain, clientIP, PartnerId, sign)
return
}

func httpBuildQuery(args map[string]string, sortAsc ...bool) string {
str := ""
if len(args) == 0 {
return str
}
if len(sortAsc) > 0 {
keys := make([]string, 0, len(args))
for k := range args {
keys = append(keys, k)
}
if sortAsc[0] {
sort.Strings(keys)
} else {
sort.Sort(sort.Reverse(sort.StringSlice(keys)))
}
for _, k := range keys {
str += k + args[k]
}
} else {
for k, v := range args {
str += k + v
}
}
return str
}

+ 29
- 0
cloud_issuance/db/db_cloud_issuance_basic.go Parādīt failu

@@ -0,0 +1,29 @@
package db

import (
commDb "applet/app/db"
"applet/app/utils/logx"
"applet/cloud_issuance/db/model"
"github.com/gin-gonic/gin"
"xorm.io/xorm"
)

type CloudIssuanceBasicDb struct {
Db *xorm.Engine `json:"model"`
}

func (cloudIssuanceBasicDb *CloudIssuanceBasicDb) Set(c *gin.Context) { // set方法
cloudIssuanceBasicDb.Db = commDb.DBs[c.GetString("mid")]
}

func (cloudIssuanceBasicDb *CloudIssuanceBasicDb) GetCloudIssuanceBasic() (m *model.CloudIssuanceBasic, err error) {
m = new(model.CloudIssuanceBasic)
has, err := cloudIssuanceBasicDb.Db.Where("id >= 1").Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

+ 31
- 0
cloud_issuance/db/db_cloud_issuance_copy_writing.go Parādīt failu

@@ -0,0 +1,31 @@
package db

import (
commDb "applet/app/db"
"applet/app/utils/logx"
"applet/cloud_issuance/db/model"
"github.com/gin-gonic/gin"
"xorm.io/xorm"
)

type CloudIssuanceCopyWritingDb struct {
Db *xorm.Engine `json:"model"`
Provider string `json:"provider"`
}

func (cloudIssuanceCopyWritingDb *CloudIssuanceCopyWritingDb) Set(c *gin.Context, provider string) { // set方法
cloudIssuanceCopyWritingDb.Db = commDb.DBs[c.GetString("mid")]
cloudIssuanceCopyWritingDb.Provider = provider
}

func (cloudIssuanceCopyWritingDb *CloudIssuanceCopyWritingDb) GetCloudIssuanceCopyWriting() (m *model.CloudIssuanceCopyWriting, err error) {
m = new(model.CloudIssuanceCopyWriting)
has, err := cloudIssuanceCopyWritingDb.Db.Where("provider = ?", cloudIssuanceCopyWritingDb.Provider).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

+ 85
- 0
cloud_issuance/db/db_cloud_issuance_goods.go Parādīt failu

@@ -0,0 +1,85 @@
package db

import (
commDb "applet/app/db"
"applet/app/utils"
"applet/app/utils/logx"
"applet/cloud_issuance/db/model"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"reflect"
"xorm.io/xorm"
)

type CloudIssuanceGoodsDb struct {
Db *xorm.Engine `json:"model"`
}

func (cloudIssuanceGoodsDb *CloudIssuanceGoodsDb) Set(c *gin.Context) { // set方法
cloudIssuanceGoodsDb.Db = commDb.DBs[c.GetString("mid")]
}

func (cloudIssuanceGoodsDb *CloudIssuanceGoodsDb) GetCloudIssuanceGood(goodsId interface{}) (m *model.CloudIssuanceGoods, err error) {
m = new(model.CloudIssuanceGoods)
has, err := cloudIssuanceGoodsDb.Db.Where("goods_id = ?", goodsId).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceGoodsDb *CloudIssuanceGoodsDb) FindCloudIssuanceGoods(params map[string]interface{}) (m []*model.CloudIssuanceGoods, err error) {
if params["value"] == nil {
return nil, errors.New("参数有误")
}
if params["key"] == nil {
//查询全部数据
err := cloudIssuanceGoodsDb.Db.Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return m, nil
} else {
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
//指定In查询
if err := cloudIssuanceGoodsDb.Db.In(utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
return nil, logx.Warn(err)
}
return m, nil
} else {
var query = fmt.Sprintf("%s =?", params["key"])
err := cloudIssuanceGoodsDb.Db.Where(query, params["value"]).OrderBy("id ASC").Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return m, nil
}
}
}

func (cloudIssuanceGoodsDb *CloudIssuanceGoodsDb) GetCloudIssuanceGoodByCategory(categoryId int) (m *model.CloudIssuanceGoods, err error) {
m = new(model.CloudIssuanceGoods)
has, err := cloudIssuanceGoodsDb.Db.Where("cloud_issuance_category_id = ?", categoryId).OrderBy("id ASC").Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceGoodsDb *CloudIssuanceGoodsDb) DeleteCloudIssuanceGoods(id interface{}) (affected int64, err error) {
utils.FilePutContents("DeleteCloudIssuanceGoods", utils.SerializeStr(map[string]interface{}{
"id": id,
}))
_, err = cloudIssuanceGoodsDb.Db.Where("id=?", id).Delete(model.CloudIssuanceGoods{})
if err != nil {
return 0, err
}
return 1, nil
}

+ 71
- 0
cloud_issuance/db/db_cloud_issuance_goods_category.go Parādīt failu

@@ -0,0 +1,71 @@
package db

import (
commDb "applet/app/db"
"applet/app/utils"
"applet/app/utils/logx"
"applet/cloud_issuance/db/model"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"reflect"
"xorm.io/xorm"
)

type CloudIssuanceGoodsCategoryDb struct {
Db *xorm.Engine `json:"model"`
}

func (cloudIssuanceGoodsCategoryDb *CloudIssuanceGoodsCategoryDb) Set(c *gin.Context) { // set方法
cloudIssuanceGoodsCategoryDb.Db = commDb.DBs[c.GetString("mid")]
}

func (cloudIssuanceGoodsCategoryDb *CloudIssuanceGoodsCategoryDb) GetCloudIssuanceGoodsCategory(id int) (m *model.CloudIssuanceGoodsCategory, err error) {
m = new(model.CloudIssuanceGoodsCategory)
has, err := cloudIssuanceGoodsCategoryDb.Db.Where("id = ?", id).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceGoodsCategoryDb *CloudIssuanceGoodsCategoryDb) GetDefaultCloudIssuanceGoodsCategory() (m *model.CloudIssuanceGoodsCategory, err error) {
m = new(model.CloudIssuanceGoodsCategory)
has, err := cloudIssuanceGoodsCategoryDb.Db.OrderBy("sort DESC").Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, errors.New("未查询到数据源分类")
}
return m, nil
}

func (cloudIssuanceGoodsCategoryDb *CloudIssuanceGoodsCategoryDb) FindCloudIssuanceGoodsCategory(params map[string]interface{}) (m []*model.CloudIssuanceGoodsCategory, err error) {
if params["key"] == nil {
//查询全部数据
err := cloudIssuanceGoodsCategoryDb.Db.OrderBy("sort DESC").Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return m, nil
} else {
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
//指定In查询
if err := cloudIssuanceGoodsCategoryDb.Db.In(utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
return nil, logx.Warn(err)
}
return m, nil
} else {
var query = fmt.Sprintf("%s =?", params["key"])
err := cloudIssuanceGoodsCategoryDb.Db.Where(query, params["value"]).Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return m, nil
}
}
}

+ 58
- 0
cloud_issuance/db/db_cloud_issuance_package.go Parādīt failu

@@ -0,0 +1,58 @@
package db

import (
commDb "applet/app/db"
"applet/app/utils"
"applet/app/utils/logx"
"applet/cloud_issuance/db/model"
"fmt"
"github.com/gin-gonic/gin"
"reflect"
"xorm.io/xorm"
)

type CloudIssuanceRobotPackageDb struct {
Db *xorm.Engine `json:"model"`
}

func (cloudIssuanceRobotPackageDb *CloudIssuanceRobotPackageDb) Set(c *gin.Context) { // set方法
cloudIssuanceRobotPackageDb.Db = commDb.DBs[c.GetString("mid")]
}

func (cloudIssuanceRobotPackageDb *CloudIssuanceRobotPackageDb) GetCloudIssuanceRobotPackage(id int) (m *model.CloudIssuanceRobotPackage, err error) {
m = new(model.CloudIssuanceRobotPackage)
has, err := cloudIssuanceRobotPackageDb.Db.Where("id = ?", id).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceRobotPackageDb *CloudIssuanceRobotPackageDb) FindCloudIssuanceRobotPackage(params map[string]interface{}) (m []*model.CloudIssuanceRobotPackage, err error) {
if params["key"] == nil {
//查询全部数据
err := cloudIssuanceRobotPackageDb.Db.OrderBy("sort DESC").Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return m, nil
} else {
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
//指定In查询
if err := cloudIssuanceRobotPackageDb.Db.In(utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
return nil, logx.Warn(err)
}
return m, nil
} else {
var query = fmt.Sprintf("%s =?", params["key"])
err := cloudIssuanceRobotPackageDb.Db.Where(query, params["value"]).Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return m, nil
}
}
}

+ 70
- 0
cloud_issuance/db/db_cloud_issuance_package_ord.go Parādīt failu

@@ -0,0 +1,70 @@
package db

import (
commDb "applet/app/db"
"applet/app/utils/logx"
"applet/cloud_issuance/db/model"
"applet/cloud_issuance/md"
"github.com/gin-gonic/gin"
"xorm.io/xorm"
)

type CloudIssuancePackageOrdDb struct {
Db *xorm.Engine `json:"model"`
}

func (cloudIssuancePackageOrdDb *CloudIssuancePackageOrdDb) Set(c *gin.Context) { // set方法
cloudIssuancePackageOrdDb.Db = commDb.DBs[c.GetString("mid")]
}

func (cloudIssuancePackageOrdDb *CloudIssuancePackageOrdDb) GetCloudIssuancePackageOrd(ordNo string) (m *model.CloudIssuancePackageOrd, err error) {
m = new(model.CloudIssuancePackageOrd)
has, err := cloudIssuancePackageOrdDb.Db.Where("ord_no =?", ordNo).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuancePackageOrdDb *CloudIssuancePackageOrdDb) GetCloudIssuancePackageOrdByUid(uid interface{}) (m *model.CloudIssuancePackageOrd, err error) {
m = new(model.CloudIssuancePackageOrd)
has, err := cloudIssuancePackageOrdDb.Db.Where("uid =?", uid).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuancePackageOrdDb *CloudIssuancePackageOrdDb) InsertCloudIssuancePackageOrd(m *model.CloudIssuancePackageOrd) (id int, err error) {
_, err = cloudIssuancePackageOrdDb.Db.InsertOne(m)
if err != nil {
return 0, err
}
id = m.Id
return id, nil
}

func (cloudIssuancePackageOrdDb *CloudIssuancePackageOrdDb) SaveCloudIssuancePackageOrd(id interface{}, m *model.CloudIssuancePackageOrd, forceColums ...string) (affected int64, err error) {
if forceColums != nil {
affected, err = cloudIssuancePackageOrdDb.Db.Where("id=?", id).Cols(forceColums...).Update(m)
} else {
affected, err = cloudIssuancePackageOrdDb.Db.Where("id=?", id).Update(m)
}
return
}

func (cloudIssuancePackageOrdDb *CloudIssuancePackageOrdDb) UserOrdList(uid interface{}, req md.BuyPackageRecordsRequest) (resp []*md.BuyPackageRecordsResponse, total int64, err error) {
total, err = cloudIssuancePackageOrdDb.Db.Table("cloud_issuance_package_ord").
Join("INNER", "cloud_issuance_robot_package", "cloud_issuance_package_ord.package_id = cloud_issuance_robot_package.id").
Where("cloud_issuance_package_ord.uid = ?", uid).
OrderBy("cloud_issuance_package_ord.id DESC").
Cols("cloud_issuance_package_ord.*, cloud_issuance_robot_package.name as package_name").
Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&resp)
return
}

+ 61
- 0
cloud_issuance/db/db_cloud_issuance_user_free_robot_records.go Parādīt failu

@@ -0,0 +1,61 @@
package db

import (
commDb "applet/app/db"
"applet/app/utils/logx"
"applet/cloud_issuance/db/model"
"github.com/gin-gonic/gin"
"xorm.io/xorm"
)

type CloudIssuanceUserFreeRobotRecordsDb struct {
Db *xorm.Engine `json:"model"`
Uid int `json:"uid"`
}

func (cloudIssuanceUserFreeRobotRecordsDb *CloudIssuanceUserFreeRobotRecordsDb) Set(c *gin.Context, uid int) { // set方法
cloudIssuanceUserFreeRobotRecordsDb.Db = commDb.DBs[c.GetString("mid")]
cloudIssuanceUserFreeRobotRecordsDb.Uid = uid
}

func (cloudIssuanceUserFreeRobotRecordsDb *CloudIssuanceUserFreeRobotRecordsDb) GetCloudIssuanceUserFreeRobotRecord() (m *model.CloudIssuanceUserFreeRobotRecords, err error) {
m = new(model.CloudIssuanceUserFreeRobotRecords)
has, err := cloudIssuanceUserFreeRobotRecordsDb.Db.Where("uid = ?", cloudIssuanceUserFreeRobotRecordsDb.Uid).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceUserFreeRobotRecordsDb *CloudIssuanceUserFreeRobotRecordsDb) GetCloudIssuanceUserFreeRobotRecordByRobotId(robotId int) (m *model.CloudIssuanceUserFreeRobotRecords, err error) {
m = new(model.CloudIssuanceUserFreeRobotRecords)
has, err := cloudIssuanceUserFreeRobotRecordsDb.Db.Where("robot_id = ?", robotId).And("uid = ?", cloudIssuanceUserFreeRobotRecordsDb.Uid).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceUserFreeRobotRecordsDb *CloudIssuanceUserFreeRobotRecordsDb) InsertCloudIssuanceUserFreeRobotRecord(m *model.CloudIssuanceUserFreeRobotRecords) (id int, err error) {
_, err = cloudIssuanceUserFreeRobotRecordsDb.Db.InsertOne(m)
if err != nil {
return 0, err
}
id = m.Id
return id, nil
}

func (cloudIssuanceUserFreeRobotRecordsDb *CloudIssuanceUserFreeRobotRecordsDb) SaveCloudIssuanceUserFreeRobotRecord(id interface{}, m *model.CloudIssuanceUserFreeRobotRecords, forceColums ...string) (affected int64, err error) {
if forceColums != nil {
affected, err = cloudIssuanceUserFreeRobotRecordsDb.Db.Where("id=?", id).Cols(forceColums...).Update(m)
} else {
affected, err = cloudIssuanceUserFreeRobotRecordsDb.Db.Where("id=?", id).Update(m)
}
return
}

+ 103
- 0
cloud_issuance/db/db_cloud_issuance_user_robot.go Parādīt failu

@@ -0,0 +1,103 @@
package db

import (
commDb "applet/app/db"
"applet/app/utils/logx"
"applet/cloud_issuance/db/model"
db "applet/cloud_issuance/db/official"
model2 "applet/cloud_issuance/db/official/model"
"applet/cloud_issuance/enum"
"github.com/gin-gonic/gin"
"strconv"
"time"
"xorm.io/xorm"
)

type CloudIssuanceUserRobotDb struct {
Db *xorm.Engine `json:"model"`
Uid int `json:"uid"`
MasterId string `json:"master_id"`
}

func (cloudIssuanceUserRobotDb *CloudIssuanceUserRobotDb) Set(c *gin.Context, uid int) { // set方法
cloudIssuanceUserRobotDb.Db = commDb.DBs[c.GetString("mid")]
cloudIssuanceUserRobotDb.Uid = uid
cloudIssuanceUserRobotDb.MasterId = c.GetString("mid")
}

func (cloudIssuanceUserRobotDb *CloudIssuanceUserRobotDb) GetCloudIssuanceUserRobot() (m *model.CloudIssuanceUserRobot, err error) {
m = new(model.CloudIssuanceUserRobot)
has, err := cloudIssuanceUserRobotDb.Db.Where("uid = ?", cloudIssuanceUserRobotDb.Uid).
And("is_enabled = 0").Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceUserRobotDb *CloudIssuanceUserRobotDb) GetCloudIssuanceUserFreeRobot() (m *model.CloudIssuanceUserRobot, err error) {
//TODO::先将所有已过期的状态改变
timeStamp := time.Now().Unix()
sql := "update cloud_issuance_user_robot set is_enabled = ? where end_time <= ? and robot_kind =?"
_, err = cloudIssuanceUserRobotDb.Db.Exec(sql, 3, timeStamp, enum.ShareRobot)
if err != nil {
return nil, logx.Error(err)
}

m = new(model.CloudIssuanceUserRobot)
has, err := cloudIssuanceUserRobotDb.Db.Where("uid = -1").
And("robot_kind =?", enum.ShareRobot).
And("is_enabled = 0").Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceUserRobotDb *CloudIssuanceUserRobotDb) InsertCloudIssuanceUserRobot(m *model.CloudIssuanceUserRobot) (id int, err error) {
_, err = cloudIssuanceUserRobotDb.Db.InsertOne(m)
if err != nil {
return 0, err
}
id = m.Id
//顺便新增一份数据到总后台的 `cloud_issuance_robot_records` 表
db.CloudIssuanceRobotRecordsInsert(&model2.CloudIssuanceRobotRecords{
MasterId: cloudIssuanceUserRobotDb.MasterId,
RobotId: strconv.Itoa(m.RobotId),
Uid: cloudIssuanceUserRobotDb.Uid,
})
return id, nil
}

func (cloudIssuanceUserRobotDb *CloudIssuanceUserRobotDb) SaveCloudIssuanceUserRobot(id interface{}, m *model.CloudIssuanceUserRobot, forceColums ...string) (affected int64, err error) {
if forceColums != nil {
affected, err = cloudIssuanceUserRobotDb.Db.Where("id=?", id).Cols(forceColums...).Update(m)
} else {
affected, err = cloudIssuanceUserRobotDb.Db.Where("id=?", id).Update(m)
}
return
}

func (cloudIssuanceUserRobotDb *CloudIssuanceUserRobotDb) FindOnLineCloudIssuanceUserRobot() (m []*model.CloudIssuanceUserRobot, err error) {
err = cloudIssuanceUserRobotDb.Db.Where("login_status =? AND is_enabled =0", enum.AlreadyLogin).OrderBy("id ASC").Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return m, nil
}

func (cloudIssuanceUserRobotDb *CloudIssuanceUserRobotDb) GetCloudIssuanceUsingFreeRobot() (m []*model.CloudIssuanceUserRobot, err error) {
err = cloudIssuanceUserRobotDb.Db.Where("uid != -1").
And("robot_kind =?", enum.ShareRobot).
And("is_enabled = 0").OrderBy("id ASC").Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return m, nil
}

+ 131
- 0
cloud_issuance/db/db_cloud_issuance_user_robot_bind_follow.go Parādīt failu

@@ -0,0 +1,131 @@
package db

import (
commDb "applet/app/db"
"applet/app/utils/logx"
"applet/cloud_issuance/db/model"
"github.com/gin-gonic/gin"
"github.com/jinzhu/copier"
"time"
"xorm.io/xorm"
)

type CloudIssuanceUserRobotBindFollowDb struct {
Db *xorm.Engine `json:"model"`
Uid int `json:"uid"`
}
type CloudIssuanceUserRobotBindFollowList struct {
Id int `json:"id" xorm:"pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"`
Name string `json:"name" xorm:"comment('群名称')"`
RobotId int `json:"robot_id" xorm:"comment('机器人id')"`
ChatRoomId string `json:"chat_room_id" xorm:"comment('发送微信好友/群id')"`
ChatRoomOwner string `json:"chat_room_owner" xorm:"comment('群所有者')"`
MemberCount int `json:"member_count" xorm:"comment('群成员数')"`
BigHeadImgUrl string `json:"big_head_img_url" xorm:"comment('大的群头像')"`
SmallHeadImgUrl string `json:"small_head_img_url" xorm:"comment('小的群头像')"`
State int `json:"state" xorm:"not null default 1 comment('状态(1正常 2暂停)') TINYINT(1)"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
FollowUserList []*model.CloudIssuanceUserRobotBindFollowUser `json:"follow_user_list"`
FollowGroupList []*model.CloudIssuanceUserRobotBindFollowGroup `json:"follow_group_list"`
}

func (cloudIssuanceUserRobotBindFollowDb *CloudIssuanceUserRobotBindFollowDb) Set(c *gin.Context, uid int) { // set方法
cloudIssuanceUserRobotBindFollowDb.Uid = uid
cloudIssuanceUserRobotBindFollowDb.Db = commDb.DBs[c.GetString("mid")]
}

func (cloudIssuanceUserRobotBindFollowDb *CloudIssuanceUserRobotBindFollowDb) GetCloudIssuanceUserRobotBindFollow(id int) (m *model.CloudIssuanceUserRobotBindFollow, err error) {
m = new(model.CloudIssuanceUserRobotBindFollow)
has, err := cloudIssuanceUserRobotBindFollowDb.Db.Where("id =?", id).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceUserRobotBindFollowDb *CloudIssuanceUserRobotBindFollowDb) GetCloudIssuanceUserRobotBindFollowByChatRoomId(chatRoomId string, robotId int) (m *model.CloudIssuanceUserRobotBindFollow, err error) {
time.Sleep(time.Millisecond * 50) // 等待50毫秒
m = new(model.CloudIssuanceUserRobotBindFollow)
has, err := cloudIssuanceUserRobotBindFollowDb.Db.Where("chat_room_id =? AND robot_id = ? AND state = 1", chatRoomId, robotId).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceUserRobotBindFollowDb *CloudIssuanceUserRobotBindFollowDb) InsertCloudIssuanceUserRobotBindFollow(m *model.CloudIssuanceUserRobotBindFollow) (id int, err error) {
_, err = cloudIssuanceUserRobotBindFollowDb.Db.InsertOne(m)
if err != nil {
return 0, err
}
id = m.Id
return id, nil
}

func (cloudIssuanceUserRobotBindFollowDb *CloudIssuanceUserRobotBindFollowDb) SaveCloudIssuanceUserRobotBindFollow(id interface{}, m *model.CloudIssuanceUserRobotBindFollow, forceColums ...string) (affected int64, err error) {
if forceColums != nil {
affected, err = cloudIssuanceUserRobotBindFollowDb.Db.Where("id=?", id).Cols(forceColums...).Update(m)
} else {
affected, err = cloudIssuanceUserRobotBindFollowDb.Db.Where("id=?", id).Update(m)
}
return
}

func (cloudIssuanceUserRobotBindFollowDb *CloudIssuanceUserRobotBindFollowDb) DeleteCloudIssuanceUserRobotBindFollow(id interface{}) (affected int64, err error) {
_, err = cloudIssuanceUserRobotBindFollowDb.Db.Where("id=?", id).Delete(model.CloudIssuanceUserRobotBindFollow{})
if err != nil {
return 0, err
}
return 1, nil
}

func (cloudIssuanceUserRobotBindFollowDb *CloudIssuanceUserRobotBindFollowDb) CountCloudIssuanceUserRobotBindFollow() (total int64, err error) {
var m []*model.CloudIssuanceUserRobotBindFollow
total, err = cloudIssuanceUserRobotBindFollowDb.Db.Where("uid=?", cloudIssuanceUserRobotBindFollowDb.Uid).OrderBy("id DESC").FindAndCount(&m)
return
}

func (cloudIssuanceUserRobotBindFollowDb *CloudIssuanceUserRobotBindFollowDb) FindCloudIssuanceUserRobotBindFollow() (list []*CloudIssuanceUserRobotBindFollowList, err error) {
var m []*model.CloudIssuanceUserRobotBindFollow
err = cloudIssuanceUserRobotBindFollowDb.Db.Where("uid=?", cloudIssuanceUserRobotBindFollowDb.Uid).OrderBy("id DESC").Find(&m)
if err != nil {
return
}

for _, v := range m {
var tmp CloudIssuanceUserRobotBindFollowList
copier.Copy(&tmp, v)

cloudIssuanceUserRobotBindFollowGroupDb := CloudIssuanceUserRobotBindFollowGroupDb{Db: cloudIssuanceUserRobotBindFollowDb.Db}
groups, err := cloudIssuanceUserRobotBindFollowGroupDb.FindCloudIssuanceUserRobotBindFollowGroup(map[string]interface{}{
"key": "bind_id",
"value": v.Id,
})
if err != nil {
return list, err
}
tmp.FollowGroupList = groups

cloudIssuanceUserRobotBindFollowUserDb := CloudIssuanceUserRobotBindFollowUserDb{Db: cloudIssuanceUserRobotBindFollowDb.Db}
users, err := cloudIssuanceUserRobotBindFollowUserDb.FindCloudIssuanceUserRobotBindFollowUser(map[string]interface{}{
"key": "bind_id",
"value": v.Id,
})
if err != nil {
return list, err
}
tmp.FollowGroupList = groups
tmp.FollowUserList = users

list = append(list, &tmp)
}
return
}

+ 106
- 0
cloud_issuance/db/db_cloud_issuance_user_robot_bind_follow_group.go Parādīt failu

@@ -0,0 +1,106 @@
package db

import (
commDb "applet/app/db"
"applet/app/utils"
"applet/app/utils/logx"
"applet/cloud_issuance/db/model"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"reflect"
"xorm.io/xorm"
)

type CloudIssuanceUserRobotBindFollowGroupDb struct {
Db *xorm.Engine `json:"model"`
}

func (cloudIssuanceUserRobotBindFollowGroupDb *CloudIssuanceUserRobotBindFollowGroupDb) Set(c *gin.Context) { // set方法
cloudIssuanceUserRobotBindFollowGroupDb.Db = commDb.DBs[c.GetString("mid")]
}

func (cloudIssuanceUserRobotBindFollowGroupDb *CloudIssuanceUserRobotBindFollowGroupDb) GetCloudIssuanceUserRobotBindFollowGroup(id int) (m *model.CloudIssuanceUserRobotBindFollowGroup, err error) {
m = new(model.CloudIssuanceUserRobotBindFollowGroup)
has, err := cloudIssuanceUserRobotBindFollowGroupDb.Db.Where("id =?", id).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceUserRobotBindFollowGroupDb *CloudIssuanceUserRobotBindFollowGroupDb) GetCloudIssuanceUserRobotBindFollowGroupByBindId(bandId int) (m []*model.CloudIssuanceUserRobotBindFollowGroup, err error) {
err = cloudIssuanceUserRobotBindFollowGroupDb.Db.Where("bind_id =?", bandId).Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return m, nil
}

func (cloudIssuanceUserRobotBindFollowGroupDb *CloudIssuanceUserRobotBindFollowGroupDb) InsertCloudIssuanceUserRobotBindFollowGroup(m *model.CloudIssuanceUserRobotBindFollowGroup) (id int, err error) {
_, err = cloudIssuanceUserRobotBindFollowGroupDb.Db.InsertOne(m)
if err != nil {
return 0, err
}
id = m.Id
return id, nil
}

func (cloudIssuanceUserRobotBindFollowGroupDb *CloudIssuanceUserRobotBindFollowGroupDb) BatchAddCloudIssuanceUserRobotBindFollowGroups(data []*model.CloudIssuanceUserRobotBindFollowGroup) (int64, error) {
affected, err := cloudIssuanceUserRobotBindFollowGroupDb.Db.Insert(data)
if err != nil {
return 0, err
}
return affected, nil
}

func (cloudIssuanceUserRobotBindFollowGroupDb *CloudIssuanceUserRobotBindFollowGroupDb) SaveCloudIssuanceUserRobotBindFollowGroup(id interface{}, m *model.CloudIssuanceUserRobotBindFollowGroup, forceColums ...string) (affected int64, err error) {
if forceColums != nil {
affected, err = cloudIssuanceUserRobotBindFollowGroupDb.Db.Where("id=?", id).Cols(forceColums...).Update(m)
} else {
affected, err = cloudIssuanceUserRobotBindFollowGroupDb.Db.Where("id=?", id).Update(m)
}
return
}

func (cloudIssuanceUserRobotBindFollowGroupDb *CloudIssuanceUserRobotBindFollowGroupDb) DeleteCloudIssuanceUserRobotBindFollowGroup(bindId interface{}) (affected int64, err error) {
_, err = cloudIssuanceUserRobotBindFollowGroupDb.Db.Where("bind_id=?", bindId).Delete(model.CloudIssuanceUserRobotBindFollowGroup{})
if err != nil {
return 0, err
}
return 1, nil
}

func (cloudIssuanceUserRobotBindFollowGroupDb *CloudIssuanceUserRobotBindFollowGroupDb) FindCloudIssuanceUserRobotBindFollowGroup(params map[string]interface{}) ([]*model.CloudIssuanceUserRobotBindFollowGroup, error) {
var m []*model.CloudIssuanceUserRobotBindFollowGroup
if params["value"] == nil {
return nil, errors.New("参数有误")
}
if params["key"] == nil {
//查询全部数据
err := cloudIssuanceUserRobotBindFollowGroupDb.Db.Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return m, nil
} else {
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
//指定In查询
if err := cloudIssuanceUserRobotBindFollowGroupDb.Db.In(utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
return nil, logx.Warn(err)
}
return m, nil
} else {
var query = fmt.Sprintf("%s =?", params["key"])
err := cloudIssuanceUserRobotBindFollowGroupDb.Db.Where(query, params["value"]).Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return m, nil
}

}
}

+ 110
- 0
cloud_issuance/db/db_cloud_issuance_user_robot_bind_follow_user.go Parādīt failu

@@ -0,0 +1,110 @@
package db

import (
commDb "applet/app/db"
"applet/app/utils"
"applet/app/utils/logx"
"applet/cloud_issuance/db/model"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"reflect"
"xorm.io/xorm"
)

type CloudIssuanceUserRobotBindFollowUserDb struct {
Db *xorm.Engine `json:"model"`
}

func (cloudIssuanceUserRobotBindFollowUserDb *CloudIssuanceUserRobotBindFollowUserDb) Set(c *gin.Context) { // set方法
cloudIssuanceUserRobotBindFollowUserDb.Db = commDb.DBs[c.GetString("mid")]
}

func (cloudIssuanceUserRobotBindFollowUserDb *CloudIssuanceUserRobotBindFollowUserDb) GetCloudIssuanceUserRobotBindFollowUser(id int) (m *model.CloudIssuanceUserRobotBindFollowUser, err error) {
m = new(model.CloudIssuanceUserRobotBindFollowUser)
has, err := cloudIssuanceUserRobotBindFollowUserDb.Db.Where("id =?", id).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceUserRobotBindFollowUserDb *CloudIssuanceUserRobotBindFollowUserDb) GetCloudIssuanceUserRobotBindFollowUserByWxId(wxId string) (m *model.CloudIssuanceUserRobotBindFollowUser, err error) {
m = new(model.CloudIssuanceUserRobotBindFollowUser)
has, err := cloudIssuanceUserRobotBindFollowUserDb.Db.Where("monitor_host_wx_id =?", wxId).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceUserRobotBindFollowUserDb *CloudIssuanceUserRobotBindFollowUserDb) InsertCloudIssuanceUserRobotBindFollowUser(m *model.CloudIssuanceUserRobotBindFollowUser) (id int, err error) {
_, err = cloudIssuanceUserRobotBindFollowUserDb.Db.InsertOne(m)
if err != nil {
return 0, err
}
id = m.Id
return id, nil
}

func (cloudIssuanceUserRobotBindFollowUserDb *CloudIssuanceUserRobotBindFollowUserDb) BatchAddCloudIssuanceUserRobotBindFollowUsers(data []*model.CloudIssuanceUserRobotBindFollowUser) (int64, error) {
affected, err := cloudIssuanceUserRobotBindFollowUserDb.Db.Insert(data)
if err != nil {
return 0, err
}
return affected, nil
}

func (cloudIssuanceUserRobotBindFollowUserDb *CloudIssuanceUserRobotBindFollowUserDb) SaveCloudIssuanceUserRobotBindFollowUser(id interface{}, m *model.CloudIssuanceUserRobotBindFollowUser, forceColums ...string) (affected int64, err error) {
if forceColums != nil {
affected, err = cloudIssuanceUserRobotBindFollowUserDb.Db.Where("id=?", id).Cols(forceColums...).Update(m)
} else {
affected, err = cloudIssuanceUserRobotBindFollowUserDb.Db.Where("id=?", id).Update(m)
}
return
}

func (cloudIssuanceUserRobotBindFollowUserDb *CloudIssuanceUserRobotBindFollowUserDb) DeleteCloudIssuanceUserRobotBindFollowUser(bindId interface{}) (affected int64, err error) {
_, err = cloudIssuanceUserRobotBindFollowUserDb.Db.Where("bind_id=?", bindId).Delete(model.CloudIssuanceUserRobotBindFollowUser{})
if err != nil {
return 0, err
}
return 1, nil
}

func (cloudIssuanceUserRobotBindFollowUserDb *CloudIssuanceUserRobotBindFollowUserDb) FindCloudIssuanceUserRobotBindFollowUser(params map[string]interface{}) ([]*model.CloudIssuanceUserRobotBindFollowUser, error) {
var m []*model.CloudIssuanceUserRobotBindFollowUser
if params["value"] == nil {
return nil, errors.New("参数有误")
}
if params["key"] == nil {
//查询全部数据
err := cloudIssuanceUserRobotBindFollowUserDb.Db.Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return m, nil
} else {
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
//指定In查询
if err := cloudIssuanceUserRobotBindFollowUserDb.Db.In(utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
return nil, logx.Warn(err)
}
return m, nil
} else {
var query = fmt.Sprintf("%s =?", params["key"])
err := cloudIssuanceUserRobotBindFollowUserDb.Db.Where(query, params["value"]).Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return m, nil
}

}
}

+ 88
- 0
cloud_issuance/db/db_cloud_issuance_user_robot_bind_group.go Parādīt failu

@@ -0,0 +1,88 @@
package db

import (
commDb "applet/app/db"
"applet/app/utils/logx"
"applet/cloud_issuance/db/model"
"applet/cloud_issuance/md"
"github.com/gin-gonic/gin"
"xorm.io/xorm"
)

type CloudIssuanceUserRobotBindGroupDb struct {
Db *xorm.Engine `json:"model"`
Uid int `json:"uid"`
}

func (cloudIssuanceUserRobotBindGroupDb *CloudIssuanceUserRobotBindGroupDb) Set(c *gin.Context, uid int) { // set方法
cloudIssuanceUserRobotBindGroupDb.Uid = uid
cloudIssuanceUserRobotBindGroupDb.Db = commDb.DBs[c.GetString("mid")]
}

func (cloudIssuanceUserRobotBindGroupDb *CloudIssuanceUserRobotBindGroupDb) GetCloudIssuanceUserRobotBindGroup(id int) (m *model.CloudIssuanceUserRobotBindGroup, err error) {
m = new(model.CloudIssuanceUserRobotBindGroup)
has, err := cloudIssuanceUserRobotBindGroupDb.Db.Where("id =?", id).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceUserRobotBindGroupDb *CloudIssuanceUserRobotBindGroupDb) GetCloudIssuanceUserRobotBindGroupByChatRoomId(chatRoomId string) (m *model.CloudIssuanceUserRobotBindGroup, err error) {
m = new(model.CloudIssuanceUserRobotBindGroup)
has, err := cloudIssuanceUserRobotBindGroupDb.Db.Where("chat_room_id =?", chatRoomId).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (cloudIssuanceUserRobotBindGroupDb *CloudIssuanceUserRobotBindGroupDb) InsertCloudIssuanceUserRobotBindGroup(m *model.CloudIssuanceUserRobotBindGroup) (id int, err error) {
_, err = cloudIssuanceUserRobotBindGroupDb.Db.InsertOne(m)
if err != nil {
return 0, err
}
id = m.Id
return id, nil
}

func (cloudIssuanceUserRobotBindGroupDb *CloudIssuanceUserRobotBindGroupDb) SaveCloudIssuanceUserRobotBindGroup(id interface{}, m *model.CloudIssuanceUserRobotBindGroup, forceColums ...string) (affected int64, err error) {
if forceColums != nil {
affected, err = cloudIssuanceUserRobotBindGroupDb.Db.Where("id=?", id).Cols(forceColums...).Update(m)
} else {
affected, err = cloudIssuanceUserRobotBindGroupDb.Db.Where("id=?", id).Update(m)
}
return
}

func (cloudIssuanceUserRobotBindGroupDb *CloudIssuanceUserRobotBindGroupDb) DeleteCloudIssuanceUserRobotBindGroup(id interface{}) (affected int64, err error) {
_, err = cloudIssuanceUserRobotBindGroupDb.Db.Where("id=?", id).Delete(model.CloudIssuanceUserRobotBindGroup{})
if err != nil {
return 0, err
}
return 1, nil
}

func (cloudIssuanceUserRobotBindGroupDb *CloudIssuanceUserRobotBindGroupDb) FindCloudIssuanceUserRobotBindGroup() (resp []*md.FindCloudIssuanceUserRobotBindGroupResponse, total int64, err error) {
total, err = cloudIssuanceUserRobotBindGroupDb.Db.Table("cloud_issuance_user_robot_bind_group").
Join("LEFT", "cloud_issuance_goods_category", "cloud_issuance_user_robot_bind_group.goods_category_id = cloud_issuance_goods_category.id").
Where("cloud_issuance_user_robot_bind_group.uid = ?", cloudIssuanceUserRobotBindGroupDb.Uid).
OrderBy("cloud_issuance_user_robot_bind_group.id DESC").
Cols("cloud_issuance_user_robot_bind_group.*, cloud_issuance_goods_category.name as goods_category_name").
FindAndCount(&resp)
return
}

func (cloudIssuanceUserRobotBindGroupDb *CloudIssuanceUserRobotBindGroupDb) FindCloudIssuanceUserRobotBindGroupByCategory(categoryId int) (m []*model.CloudIssuanceUserRobotBindGroup, err error) {
err = cloudIssuanceUserRobotBindGroupDb.Db.Where("uid =? AND goods_category_id =? AND state =1", cloudIssuanceUserRobotBindGroupDb.Uid, categoryId).OrderBy("id ASC").Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return m, nil
}

+ 29
- 0
cloud_issuance/db/model/cloud_issuance_basic.go Parādīt failu

@@ -0,0 +1,29 @@
package model

import (
"time"
)

type CloudIssuanceBasic struct {
Id int `json:"id" xorm:"pk autoincr INT(11)"`
IsOpenFreeAccess int32 `json:"is_open_free_access" xorm:"comment('是否开启-免费使用权限')"`
FreeAccess string `json:"free_access" xorm:"comment('免费使用权限')"`
UseAccess int32 `json:"use_access" xorm:"comment('使用权限(会员等级)')"`
TimeIntervalIssuanceOnCircleOfFriends int32 `json:"time_interval_issuance_on_circle_of_friends" xorm:"comment('朋友圈发单时间间隔(分钟)')"`
TimeIntervalIssuanceOnGroups int32 `json:"time_interval_issuance_on_groups" xorm:"comment('群发单时间间隔(分钟)')"`
TimeSlotIssuanceOnDefault string `json:"time_slot_issuance_on_default" xorm:"comment('默认发单时间段')"`
SendGroupFormat int32 `json:"send_group_format" xorm:"comment('发群格式(1:先商品图片后商品文案 2:先商品文案后商品图片)')"`
DefaultAddGroupWelcomeMessage string `json:"default_add_group_welcome_message" xorm:"comment('默认加群欢迎语')"`
DefaultNewFriendGreeted string `json:"default_new_friend_greeted" xorm:"comment('默认新好友打招呼')"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

type TimeSlotIssuanceOnDefaultStruct struct {
Nums string `json:"nums"`
Range []struct {
From string `json:"from"`
To string `json:"to"`
Times string `json:"times"`
} `json:"range"`
}

+ 15
- 0
cloud_issuance/db/model/cloud_issuance_copy_writing.go Parādīt failu

@@ -0,0 +1,15 @@
package model

import (
"time"
)

type CloudIssuanceCopyWriting struct {
Id int `json:"id" xorm:"pk autoincr INT(11)"`
Provider string `json:"provider"`
ProviderName string `json:"provider_name"`
CloudIssuanceCopyWritingForFriendsCircle string `json:"cloud_issuance_copy_writing_for_friends_circle"`
CloudIssuanceCopyWritingForGroup string `json:"cloud_issuance_copy_writing_for_group"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 29
- 0
cloud_issuance/db/model/cloud_issuance_goods.go Parādīt failu

@@ -0,0 +1,29 @@
package model

import (
"time"
)

type CloudIssuanceGoods struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
GoodsUrl string `json:"goods_url" xorm:"not null comment('传进来的商品链接') VARCHAR(50)"`
ItemUrl string `json:"item_url" xorm:"not null default 0 comment('搜索出来的商品链接') VARCHAR(50)"`
GoodsId string `json:"goods_id" xorm:"not null default 0 comment('商品id') VARCHAR(50)"`
Provider string `json:"provider" xorm:"not null default 0 comment('渠道key') VARCHAR(50)"`
ProviderName string `json:"provider_name" xorm:"not null default 0.0000 comment('渠道') VARCHAR(50)"`
ProviderImgUrl string `json:"provider_img_url" xorm:"not null default 0 comment('渠道图片Url') VARCHAR(50)"`
GoodsTitle string `json:"goods_title" xorm:"not null default 0.0000 comment('商品标题') VARCHAR(50)"`
GoodsPrice string `json:"goods_price" xorm:"not null default 1 comment('商品原价') VARCHAR(50)"`
WlGoodsPrice string `json:"wl_goods_price" xorm:"not null default 1 comment('商品卷后价') VARCHAR(50)"`
CouponPrice string `json:"coupon_price" xorm:"not null default 1 comment('优惠劵金额') VARCHAR(50)"`
CouponUrl string `json:"coupon_url" xorm:"not null default 1 comment('优惠劵Url') VARCHAR(50)"`
InOrderCount string `json:"in_order_count" xorm:"not null default 1 comment('销量') VARCHAR(50)"`
GoodsDesc string `json:"goods_desc" xorm:"not null default 0.0000 comment('商品描述') VARCHAR(50)"`
GoodsContent string `json:"goods_content" xorm:"not null default 0.0000 comment('商品文案(以json存)') VARCHAR(50)"`
GoodsImg string `json:"goods_img" xorm:"not null default 0.0000 comment('商品主图') VARCHAR(50)"`
GoodsImgList string `json:"goods_img_list" xorm:"not null default '' comment('商品主图') VARCHAR(50)"`
GoodsImgUrl string `json:"goods_img_url" xorm:"not null default 0.0000 comment('商品主图URL') VARCHAR(50)"`
CreateAt time.Time `xorm:"not null default 0 comment('创建时间') datetime"`
UpdateAt time.Time `xorm:"not null default 0 comment('更新时间') datetime"`
CloudIssuanceCategoryId int `json:"cloud_issuance_category_id" xorm:"not null default 0 comment('云发单所属分类id') Int(11)"`
}

+ 13
- 0
cloud_issuance/db/model/cloud_issuance_goods_category.go Parādīt failu

@@ -0,0 +1,13 @@
package model

import (
"time"
)

type CloudIssuanceGoodsCategory struct {
Id int `json:"id" xorm:"pk autoincr INT(11)"`
Name string `json:"name" xorm:"not null default '' comment('分类名称') VARCHAR(255)"`
Sort int `json:"sort" xorm:"not null default 0 comment('排序') INT(11)"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 20
- 0
cloud_issuance/db/model/cloud_issuance_master_recharge_ord.go Parādīt failu

@@ -0,0 +1,20 @@
package model

import (
"time"
)

type CloudIssuanceMasterRechargeOrd struct {
Id int `json:"id" xorm:"pk autoincr INT(11)"`
MasterId int `json:"master_id" xorm:"not null default 0 comment('主用户id') INT(11)"`
Phone int64 `json:"phone" xorm:"not null default 0 comment('主账号-手机号码') BIGINT(13)"`
Nickname string `json:"nickname" xorm:"not null default '' comment('主账号-昵称') VARCHAR(255)"`
Amount string `json:"amount" xorm:"not null default 0 comment('充值金额') VARCHAR(255)"`
CostPrice string `json:"cost_price" xorm:"not null default 0 comment('付费价格') VARCHAR(255)"`
Balance string `json:"balance" xorm:"not null default 0 comment('当前余额(充值完当前余额)') VARCHAR(255)"`
PayWay int `json:"pay_way" xorm:"not null default 1 comment('支付方式(1:支付宝 2:微信)') TINYINT(1)"`
State int `json:"state" xorm:"not null default 1 comment('状态(0:待付款 1:已付款 2:付款失败)') TINYINT(2)"`
Memo string `json:"memo" xorm:"not null default '' comment('备注') BIGINT(13)"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 19
- 0
cloud_issuance/db/model/cloud_issuance_package_ord.go Parādīt failu

@@ -0,0 +1,19 @@
package model

import (
"time"
)

type CloudIssuancePackageOrd struct {
Id int `json:"id" xorm:"pk autoincr INT(11)"`
OrdNo string `json:"ord_no" xorm:"not null default '' comment('订单号') VARCHAR(255)"`
TradeNo string `json:"trade_no" xorm:"not null default '' comment('支付平台(支付宝/微信)订单号') VARCHAR(255)"`
PackageId int `json:"package_id" xorm:"not null default 0 comment('套餐id') INT(11)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"`
Amount string `json:"amount" xorm:"not null default 0 comment('金额') DECIMAL(5,2)"`
State int `json:"state" xorm:"not null default 1 comment('状态(0:未支付 1:已支付 2:支付失败)') TINYINT(1)"`
PayChannel int `json:"pay_channel" xorm:"not null default 1 comment('状态(支付渠道(1:支付宝 2:微信 3:余额))') TINYINT(1)"`
Months int `json:"months" xorm:"not null default 1 comment('月份(次数)') INT(11)"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 19
- 0
cloud_issuance/db/model/cloud_issuance_robot_package.go Parādīt failu

@@ -0,0 +1,19 @@
package model

import (
"time"
)

type CloudIssuanceRobotPackage struct {
Id int `json:"id" xorm:"pk autoincr INT(11)"`
Name string `json:"name" xorm:"not null default '' comment('套餐名称') VARCHAR(255)"`
Price string `json:"price" xorm:"not null default 0 comment('单价(元)') VARCHAR(255)"`
OriginalPrice string `json:"original_price" xorm:"not null default 0 comment('单价(元)') VARCHAR(255)"`
Month int `json:"month" xorm:"not null default 0 comment('月份') BIGINT(13)"`
Type string `json:"type" xorm:"not null default 0 comment('类型(1 发单机器人 2转发机器人 3 返利机器人 4全能机器人 5小型机器人 6发圈机器人)') BIGINT(13)"`
Memo string `json:"memo" xorm:"not null default '' comment('备注') BIGINT(13)"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
State int `json:"state" xorm:"not null default 1 comment('状态(0关闭,1开启)') TINYINT(2)"`
Sort int `json:"sort" xorm:"not null default 0 comment('排序') INT(11)"`
}

+ 15
- 0
cloud_issuance/db/model/cloud_issuance_user_free_robot_records.go Parādīt failu

@@ -0,0 +1,15 @@
package model

import (
"time"
)

type CloudIssuanceUserFreeRobotRecords struct {
Id int `json:"id" xorm:"pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"`
RobotId int `json:"robot_id" xorm:"not null default 0 comment('机器人id') INT(11)"`
State int `json:"state" xorm:"not null default 1 comment('状态(1 正在使用 2已过期)') TINYINT(1)"`
EndTime time.Time `json:"end_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('过期时间') DATETIME"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 27
- 0
cloud_issuance/db/model/cloud_issuance_user_robot.go Parādīt failu

@@ -0,0 +1,27 @@
package model

import (
"time"
)

type CloudIssuanceUserRobot struct {
Id int `json:"id" xorm:"pk autoincr INT(11)"`
Uid int `json:"uid"`
RobotId int `json:"robot_id" xorm:"not null default 0 comment('机器人id') INT(11)"`
RobotType int `json:"robot_type" xorm:"not null default 4 comment('机器人类型(1 发单机器人 2转发机器人 3 返利机器人 4全能机器人 5小型机器人 6发圈机器人)') TINYINT(1)"`
RobotKind int `json:"robot_kind" xorm:"not null default 1 comment('机器人种类(1 独享机器人 2 共享机器人)') TINYINT(1)"`
WechatRobot string `json:"wechat_robot" xorm:"not null default '' comment('微信号') VARCHAR(255)"`
GroupNum int `json:"group_num" xorm:"not null default 5 comment('最大群数') TINYINT(3)"`
LoginStatus int `json:"login_status" xorm:"not null default 0 comment('登录状态(0:未登录 1:登录)') TINYINT(1)"`
EndTime string `json:"end_time" xorm:"not null default '' comment('到期时间') VARCHAR(255)"`
Remark string `json:"remark" xorm:"not null default '' comment('备注') VARCHAR(255)"`
WId string `json:"w_id" xorm:"not null default '' comment('机器人实例id') VARCHAR(255)"`
WcId string `json:"wc_id" xorm:"not null default '' comment('微信id') VARCHAR(255)"`
WcNickname string `json:"wc_nickname" xorm:"not null default '' comment('微信昵称') VARCHAR(255)"`
WcHeadUrl string `json:"wc_head_url" xorm:"not null default '' comment('微信头像') VARCHAR(255)"`
QrCodeUrl string `json:"qr_code_url" xorm:"not null default '' comment('登录二维码url') VARCHAR(255)"`
ClientIp string `json:"client_ip" xorm:"not null default '' comment('客户端ip') VARCHAR(50)"`
IsEnabled int `json:"is_enabled" xorm:"not null default 0 comment('机器人状态(0 正常 1暂停 2已过期)') TINYINT(1)"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 20
- 0
cloud_issuance/db/model/cloud_issuance_user_robot_bind_follow.go Parādīt failu

@@ -0,0 +1,20 @@
package model

import (
"time"
)

type CloudIssuanceUserRobotBindFollow struct {
Id int `json:"id" xorm:"pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"`
Name string `json:"name" xorm:"comment('群名称')"`
RobotId int `json:"robot_id" xorm:"comment('机器人id')"`
ChatRoomId string `json:"chat_room_id" xorm:"comment('发送微信好友/群id')"`
ChatRoomOwner string `json:"chat_room_owner" xorm:"comment('群所有者')"`
MemberCount int `json:"member_count" xorm:"comment('群成员数')"`
BigHeadImgUrl string `json:"big_head_img_url" xorm:"comment('大的群头像')"`
SmallHeadImgUrl string `json:"small_head_img_url" xorm:"comment('小的群头像')"`
State int `json:"state" xorm:"not null default 1 comment('状态(1正常 2暂停)') TINYINT(1)"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 18
- 0
cloud_issuance/db/model/cloud_issuance_user_robot_bind_follow_group.go Parādīt failu

@@ -0,0 +1,18 @@
package model

import (
"time"
)

type CloudIssuanceUserRobotBindFollowGroup struct {
Id int `json:"id" xorm:"pk autoincr INT(11)"`
BindId int `json:"bind_id" xorm:"comment('绑定id')"`
Name string `json:"name" xorm:"comment('跟发-群名称')"`
FollowChatRoomId string `json:"follow_chat_room_id" xorm:"comment('跟发-微信群id')"`
FollowChatRoomOwner string `json:"follow_chat_room_owner" xorm:"comment('跟发-群所有者')"`
FollowChatMemberCount int `json:"follow_chat_member_count" xorm:"comment('跟发-群成员数')"`
FollowBigHeadImgUrl string `json:"follow_big_head_img_url" xorm:"comment('跟发-大的群头像')"`
FollowSmallHeadImgUrl string `json:"follow_small_head_img_url" xorm:"comment('跟发-小的群头像')"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 15
- 0
cloud_issuance/db/model/cloud_issuance_user_robot_bind_follow_user.go Parādīt failu

@@ -0,0 +1,15 @@
package model

import (
"time"
)

type CloudIssuanceUserRobotBindFollowUser struct {
Id int `json:"id" xorm:"pk autoincr INT(11)"`
BindId int `json:"bind_id" xorm:"comment('绑定id')"`
MonitorHostWxId string `json:"monitor_host_wx_id" xorm:"comment('监听主持人微信id')"`
MonitorHostWxNickname string `json:"monitor_host_wx_nickname" xorm:"comment('监听主持人微信昵称')"`
MonitorHostWxHeadUrl string `json:"monitor_host_wx_head_url" xorm:"comment('监听主持人微信头像')"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 21
- 0
cloud_issuance/db/model/cloud_issuance_user_robot_bind_group.go Parādīt failu

@@ -0,0 +1,21 @@
package model

import (
"time"
)

type CloudIssuanceUserRobotBindGroup struct {
Id int `json:"id" xorm:"pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"`
Name string `json:"name" xorm:"comment('群名称')"`
RobotId int `json:"robot_id" xorm:"comment('机器人id')"`
ChatRoomId string `json:"chat_room_id" xorm:"comment('发送微信好友/群id')"`
ChatRoomOwner string `json:"chat_room_owner" xorm:"comment('群所有者')"`
MemberCount int `json:"member_count" xorm:"comment('群成员数')"`
BigHeadImgUrl string `json:"big_head_img_url" xorm:"comment('大的群头像')"`
SmallHeadImgUrl string `json:"small_head_img_url" xorm:"comment('小的群头像')"`
GoodsCategoryId int `json:"goods_category_id" xorm:"comment('小的群头像')"`
State int `json:"state" xorm:"not null default 1 comment('状态(1正常 2暂停)') TINYINT(1)"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 9
- 0
cloud_issuance/db/model/demo_data.go Parādīt failu

@@ -0,0 +1,9 @@
package model

type DemoData struct {
Id int `json:"id"`
Uid int `json:"uid"`
ParentUid int `json:"parent_uid"`
Phone string `json:"phone"`
ParentPhone string `json:"parent_phone"`
}

+ 15
- 0
cloud_issuance/db/official/db_cloud_issuance_baisc.go Parādīt failu

@@ -0,0 +1,15 @@
package db

import (
"applet/app/db"
"applet/app/utils/logx"
"applet/cloud_issuance/db/model"
)

func GetCloudIssuanceBasic() (*model.CloudIssuanceBasic, error) {
var m model.CloudIssuanceBasic
if has, err := db.Db.Where("id >=1").Get(&m); err != nil || has == false {
return nil, logx.Error(err)
}
return &m, nil
}

+ 117
- 0
cloud_issuance/db/official/db_cloud_issuance_master.go Parādīt failu

@@ -0,0 +1,117 @@
package db

import (
"applet/app/db"
"applet/app/utils"
"applet/app/utils/logx"
"applet/cloud_issuance/db/official/model"
"errors"
"fmt"
"reflect"
)

// BatchSelectCloudIssuanceMaster 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `CloudIssuanceMasterFindByParams` 方法
func BatchSelectCloudIssuanceMaster(params map[string]interface{}) (*[]model.CloudIssuanceMaster, error) {
var CloudIssuanceMasterData []model.CloudIssuanceMaster
if err := db.Db.In(utils.AnyToString(params["key"]), params["value"]).
Find(&CloudIssuanceMasterData); err != nil {
return nil, logx.Warn(err)
}
return &CloudIssuanceMasterData, nil
}

// CloudIssuanceMasterInsert 插入单条数据
func CloudIssuanceMasterInsert(CloudIssuanceMaster *model.CloudIssuanceMaster) (int, error) {
_, err := db.Db.InsertOne(CloudIssuanceMaster)
if err != nil {
return 0, err
}
return CloudIssuanceMaster.Id, nil
}

// BatchAddCloudIssuanceMaster 批量新增数据
func BatchAddCloudIssuanceMaster(CloudIssuanceMasterData []*model.CloudIssuanceMaster) (int64, error) {
affected, err := db.Db.Insert(CloudIssuanceMasterData)
if err != nil {
return 0, err
}
return affected, nil
}

func GetCloudIssuanceMasterCount() int {
var CloudIssuanceMaster model.CloudIssuanceMaster
session := db.Db.Where("")
count, err := session.Count(&CloudIssuanceMaster)
if err != nil {
return 0
}
return int(count)
}

// CloudIssuanceMasterDelete 删除记录
func CloudIssuanceMasterDelete(id interface{}) (int64, error) {
if reflect.TypeOf(id).Kind() == reflect.Slice {
return db.Db.In("id", id).Delete(model.CloudIssuanceMaster{})
} else {
return db.Db.Where("id = ?", id).Delete(model.CloudIssuanceMaster{})
}
}

// CloudIssuanceMasterUpdate 更新记录
func CloudIssuanceMasterUpdate(id interface{}, CloudIssuanceMaster *model.CloudIssuanceMaster, forceColums ...string) (int64, error) {
var (
affected int64
err error
)
if forceColums != nil {
affected, err = db.Db.Where("id=?", id).Cols(forceColums...).Update(CloudIssuanceMaster)
} else {
affected, err = db.Db.Where("id=?", id).Update(CloudIssuanceMaster)
}
if err != nil {
return 0, err
}
return affected, nil
}

// CloudIssuanceMasterGetOneByParams 通过传入的参数查询数据(单条)
func CloudIssuanceMasterGetOneByParams(params map[string]interface{}) (*model.CloudIssuanceMaster, error) {
var m model.CloudIssuanceMaster
var query = fmt.Sprintf("%s =?", params["key"])
if has, err := db.Db.Where(query, params["value"]).Get(&m); err != nil || has == false {
return nil, logx.Error(err)
}
return &m, nil
}

// CloudIssuanceMasterFindByParams 通过传入的参数查询数据(多条)
func CloudIssuanceMasterFindByParams(params map[string]interface{}) (*[]model.CloudIssuanceMaster, error) {
var m []model.CloudIssuanceMaster
if params["value"] == nil {
return nil, errors.New("参数有误")
}
if params["key"] == nil {
//查询全部数据
err := db.Db.Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return &m, nil
} else {
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
//指定In查询
if err := db.Db.In(utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
return nil, logx.Warn(err)
}
return &m, nil
} else {
var query = fmt.Sprintf("%s =?", params["key"])
err := db.Db.Where(query, params["value"]).Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return &m, nil
}

}
}

+ 62
- 0
cloud_issuance/db/official/db_cloud_issuance_robot_records.go Parādīt failu

@@ -0,0 +1,62 @@
package db

import (
"applet/app/db"
"applet/app/utils"
"applet/app/utils/logx"
"applet/cloud_issuance/db/official/model"
"errors"
"fmt"
"reflect"
)

// CloudIssuanceRobotRecordsInsert 插入单条数据
func CloudIssuanceRobotRecordsInsert(CloudIssuanceRobotRecords *model.CloudIssuanceRobotRecords) (int, error) {
_, err := db.Db.InsertOne(CloudIssuanceRobotRecords)
if err != nil {
return 0, err
}
return CloudIssuanceRobotRecords.Id, nil
}

// CloudIssuanceRobotRecordsGetOneByParams 通过传入的参数查询数据(单条)
func CloudIssuanceRobotRecordsGetOneByParams(params map[string]interface{}) (*model.CloudIssuanceRobotRecords, error) {
var m model.CloudIssuanceRobotRecords
var query = fmt.Sprintf("%s =?", params["key"])
if has, err := db.Db.Where(query, params["value"]).Get(&m); err != nil || has == false {
return nil, logx.Error(err)
}
return &m, nil
}

// CloudIssuanceRobotRecordsFindByParams 通过传入的参数查询数据(多条)
func CloudIssuanceRobotRecordsFindByParams(params map[string]interface{}) (*[]model.CloudIssuanceRobotRecords, error) {
var m []model.CloudIssuanceRobotRecords
if params["value"] == nil {
return nil, errors.New("参数有误")
}
if params["key"] == nil {
//查询全部数据
err := db.Db.Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return &m, nil
} else {
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
//指定In查询
if err := db.Db.In(utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
return nil, logx.Warn(err)
}
return &m, nil
} else {
var query = fmt.Sprintf("%s =?", params["key"])
err := db.Db.Where(query, params["value"]).Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return &m, nil
}

}
}

+ 15
- 0
cloud_issuance/db/official/model/cloud_issuance_basic.go Parādīt failu

@@ -0,0 +1,15 @@
package model

import "time"

type CloudIssuanceBasic struct {
Id int `json:"id"`
ImageNumsLimitIssuanceOnCircleOfFriends int `json:"image_nums_limit_issuance_on_circle_of_friends"`
ImageNumsLimitIssuanceOnGroups int `json:"image_nums_limit_issuance_on_groups"`
BindNums int `json:"bind_nums"`
FollowGroupUserNums int `json:"follow_group_user_nums"`
FollowGroupBindNums int `json:"follow_group_bind_nums"`
FollowGroupRelayNums int `json:"follow_group_relay_nums"`
CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"`
UpdateAt time.Time `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
}

+ 14
- 0
cloud_issuance/db/official/model/cloud_issuance_master.go Parādīt failu

@@ -0,0 +1,14 @@
package model

import "time"

type CloudIssuanceMaster struct {
Id int `json:"id"`
MasterId int `json:"master_id"`
Amount string `json:"amount"`
CreditAmount string `json:"credit_amount"`
Memo string `json:"memo"`
State int `json:"state"`
CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"`
UpdateAt time.Time `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
}

+ 22
- 0
cloud_issuance/db/official/model/cloud_issuance_master_buy_ord.go Parādīt failu

@@ -0,0 +1,22 @@
package model

import "time"

type CloudIssuanceMasterBuyOrd struct {
Id int `json:"id"`
OrdId string `json:"ord_id"`
MasterId int `json:"master_id"`
Nickname string `json:"nickname"`
Phone int64 `json:"phone"`
Uid int `json:"uid"`
UserPhone string `json:"user_phone"`
RobotId int `json:"robot_id"`
Month int `json:"month"`
CostPrice string `json:"cost_price"`
BeforeBalance string `json:"before_balance"`
Balance string `json:"balance"`
Memo string `json:"memo"`
State int `json:"state"`
CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"`
UpdateAt time.Time `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
}

+ 15
- 0
cloud_issuance/db/official/model/cloud_issuance_robot.go Parādīt failu

@@ -0,0 +1,15 @@
package model

import "time"

type CloudIssuanceRobot struct {
Id int `json:"id"`
Name string `json:"name"`
Price string `json:"price"`
Type int32 `json:"type"`
State int32 `json:"state"`
Sort int `json:"sort"`
Memo string `json:"memo"`
CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"`
UpdateAt time.Time `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
}

+ 8
- 0
cloud_issuance/db/official/model/cloud_issuance_robot_records.go Parādīt failu

@@ -0,0 +1,8 @@
package model

type CloudIssuanceRobotRecords struct {
Id int `json:"id"`
MasterId string `json:"master_id"`
RobotId string `json:"robot_id"`
Uid int `json:"uid"`
}

+ 8
- 0
cloud_issuance/db/official/model/user_app_list.go Parādīt failu

@@ -0,0 +1,8 @@
package model

type UserAppList struct {
Id int `json:"id" xorm:"int(11) NOT NULL "`
Uuid int64 `json:"uuid" xorm:"int(10) NOT NULL "`
AppId int64 `json:"app_id" xorm:"int(10) NOT NULL "`
Name string `json:"name" xorm:"varchar(255) DEFAULT '' "`
}

+ 8
- 0
cloud_issuance/db/official/model/user_app_member.go Parādīt failu

@@ -0,0 +1,8 @@
package model

type UserAppMember struct {
Id int `json:"id" xorm:"int(11) NOT NULL "`
Uuid int64 `json:"uuid" xorm:"int(10) NOT NULL "`
Uid int64 `json:"uid" xorm:"int(10) NOT NULL "`
Phone int64 `json:"phone" xorm:"int(10) NOT NULL "`
}

+ 76
- 0
cloud_issuance/enum/enum_api.go Parādīt failu

@@ -0,0 +1,76 @@
package enum

type CloudIssuanceMethodName string

const (
RobotCreateMethodName = "itaoke.robot.create.get"
QrcodeMacLoginMethodName = "itaoke.robot.qrcode.maclogin"
RobotAsyncMacLoginMethodName = "itaoke.robot.async.mlogin"
RobotForceOfflineMethodName = "itaoke.robot.force.offline"
RobotSecondLoginMethodName = "itaoke.robot.second.login"
RobotChangeMethodName = "itaoke.robot.change.get"
RobotResetMethodName = "itaoke.robot.reset.get"
RobotRoomListMethodName = "itaoke.robot.room.list"
RobotGroupListMethodName = "itaoke.robot.group.list"
RobotRoomDetailMethodName = "itaoke.robot.room.detail"
RobotMacGetChatRoomMemberMethodName = "itaoke.robot.macget.chatroommember"
RobotMacSendCardMethodName = "itaoke.robot.macsend.card"
RobotMacSendUriMethodName = "itaoke.robot.macsend.image"
RobotMacSendTextMethodName = "itaoke.robot.macsend.text"
RobotMacSendRecvImageMethodName = "itaoke.robot.macsend.recvimage"
)

func (gt CloudIssuanceMethodName) String() string {
switch gt {
case RobotCreateMethodName:
return "云发单添加机器人"
case QrcodeMacLoginMethodName:
return "获取登录二维码"
case RobotAsyncMacLoginMethodName:
return "循环是否登陆"
case RobotForceOfflineMethodName:
return "强制下线"
case RobotSecondLoginMethodName:
return "二次登录(阻塞式)"
case RobotChangeMethodName:
return "机器人修改/续费"
case RobotResetMethodName:
return "重置机器人"
case RobotRoomListMethodName:
return "获取群列表"
case RobotGroupListMethodName:
return "获取群列表(优惠狗端)"
case RobotRoomDetailMethodName:
return "获取群详情"
case RobotMacGetChatRoomMemberMethodName:
return "获取群成员"
case RobotMacSendCardMethodName:
return "发链接消息"
case RobotMacSendUriMethodName:
return "根据url发图"
case RobotMacSendTextMethodName:
return "发文本消息"
case RobotMacSendRecvImageMethodName:
return "转发图片"
default:
return "未知"
}
}

type CloudIssuanceLoginStatus int

const (
NotLogin = 0
AlreadyLogin = 1
)

func (gt CloudIssuanceLoginStatus) String() string {
switch gt {
case NotLogin:
return "未登录"
case AlreadyLogin:
return "已登录"
default:
return "未知"
}
}

+ 49
- 0
cloud_issuance/enum/enum_cloud_issuance_user_robot.go Parādīt failu

@@ -0,0 +1,49 @@
package enum

type CloudIssuanceUserRobotKind int

const (
ExclusiveRobot = 1
ShareRobot = 2
)

func (gt CloudIssuanceUserRobotKind) String() string {
switch gt {
case ExclusiveRobot:
return "独享机器人"
case ShareRobot:
return "共享机器人"
default:
return "未知"
}
}

type CloudIssuanceUserRobotType int

const (
IssuingRobot = 1
ForwardRobot = 2
RebateRobot = 3
AllAroundRobot = 4
SmallRobot = 5
SendToMomentsRobot = 6
)

func (gt CloudIssuanceUserRobotType) String() string {
switch gt {
case IssuingRobot:
return "发单机器人"
case ForwardRobot:
return "转发机器人"
case RebateRobot:
return "返利机器人"
case AllAroundRobot:
return "全能机器人"
case SmallRobot:
return "小型机器人"
case SendToMomentsRobot:
return "发圈机器人"
default:
return "未知"
}
}

+ 31
- 0
cloud_issuance/enum/enum_goods_category.go Parādīt failu

@@ -0,0 +1,31 @@
package enum

type CloudIssuanceGoodsProvider string

const (
ProviderForJd = "jd"
ProviderForTaoBao = "taobao"
ProviderForSuNing = "suning"
ProviderForPdd = "pdd"
ProviderForKaoLa = "kaola"
ProviderForVip = "vip"
)

func (gt CloudIssuanceGoodsProvider) String() string {
switch gt {
case ProviderForJd:
return "京东"
case ProviderForTaoBao:
return "淘宝"
case ProviderForSuNing:
return "苏宁"
case ProviderForPdd:
return "拼多多"
case ProviderForKaoLa:
return "考拉"
case ProviderForVip:
return "唯品会"
default:
return "未知"
}
}

+ 173
- 0
cloud_issuance/md/md_api.go Parādīt failu

@@ -0,0 +1,173 @@
package md

type CurlResponse struct {
Status string `json:"status"`
Data interface{} `json:"data"`
Msg string `json:"msg"`
}

type RobotCreateRequest struct {
Month int `json:"month"` //新增月份,默认1
RobotType string `json:"robot_type"` //机器人类型 1 发单机器人 2转发机器人 3 返利机器人 4全能机器人 5小型机器人 6发圈机器人
WechatRobot string `json:"wechatrobot"` //微信号
Remark string `json:"remark"` //备注
}
type RobotCreateResponse struct {
Id float64 `json:"id"`
Uid float64 `json:"uid"`
WechatRobot string `json:"wechatrobot"`
//NickName string `json:"nickname"`
LoginStatus float64 `json:"login_status"`
EndTime int64 `json:"end_time"` //到期时间
Remark string `json:"remark"`
WcId string `json:"wc_id"` //微信实例id
IsEnabled float64 `json:"is_enabled"` //0 正常 1暂停 2已过期
}

type RobotQrcodeMacLoginRequest struct {
RobotId int `json:"robot_id"` //机器人id
}
type RobotQrcodeMacLoginResponse struct {
WId string `json:"wId"` //实例id
QrCodeUrl string `json:"qrCodeUrl"`
}

type RobotAsyncMacLoginRequest struct {
WId string `json:"wId"` //实例id
RobotId int `json:"robot_id"` //机器人id
}
type RobotAsyncMacLoginResponse struct {
WId string `json:"wId"` //实例id
WcId string `json:"wcId"` //微信id
NickName string `json:"nickName"` //微信昵称
HeadUrl string `json:"headUrl"` //微信头像
}

type RobotForceOfflineRequest struct {
RobotId int `json:"robot_id"` //机器人id
}

type RobotSecondLoginRequest struct {
RobotId int `json:"robot_id"` //机器人id
}
type RobotSecondLoginResponse struct {
WId string `json:"wId"` //实例id
WcId string `json:"wcId"` //微信id
NickName string `json:"nickName"` //微信昵称
HeadUrl string `json:"headUrl"` //微信头像
}

type RobotChangeRequest struct {
RobotId int `json:"robot_id"` //机器人id
Month int `json:"month"` //续费月数
//WechatRobot int `json:"wechatrobot"` //微信号 更换号的时候传 (TODO::暂时用不到)
}
type RobotChangeResponse struct {
Uid float64 `json:"uid"`
WechatRobot string `json:"wechatrobot"`
LoginStatus float64 `json:"login_status"`
EndTime int64 `json:"end_time"` //到期时间
Remark string `json:"remark"`
WcId string `json:"wc_id"` //微信实例id
IsEnabled float64 `json:"is_enabled"` //0 正常 1暂停 2已过期
}

type RobotResetRequest struct {
RobotId int `json:"robot_id"` //机器人id
}

type RobotRoomListRequest struct {
RobotId int `json:"robot_id"` //机器人id
//RoomContactSeq int `json:"room_contact_seq"` // 首次传0, 后面接口返回, 不传默认全部
//WxContactSeq int `json:"wx_contact_seq"` // 首次传0, 后面接口返回, 不传默认全部
}
type RobotRoomListResponse []string

type RobotRoomDetailRequest struct {
RobotId int `json:"robot_id"` //机器人id
RoomId string `json:"room_id"` // 群的id ,多个用逗号隔开
}
type RobotRoomDetailResponse struct {
ChatRoomId string `json:"chatRoomId"`
NickName string `json:"nickName"`
ChatRoomOwner string `json:"chatRoomOwner"`
BigHeadImgUrl string `json:"bigHeadImgUrl"`
SmallHeadImgUrl string `json:"smallHeadImgUrl"`
V1 string `json:"v1"`
MemberCount string `json:"memberCount"`
ChatRoomMembers []ChatRoomMember `json:"chatRoomMembers"`
}
type ChatRoomMember struct {
UserName string `json:"userName"`
NikeName string `json:"nikeName"`
InviterUserName string `json:"inviterUserName"`
}

type RobotMacSendCardRequest struct {
RobotId int `json:"robot_id"` //机器人id
WxId string `json:"wx_id"` //发送微信好友/群id。一般wxid_开头
Title string `json:"title"` //标题
Url string `json:"url"` //链接
Description string `json:"description"` //描述
ThumbUrl string `json:"thumbUrl"` //图片
}

type RobotMacSendUriRequest struct {
RobotId int `json:"robot_id"` //机器人id
WxId string `json:"toWxId"` //发送微信好友/群id。一般wxid_开头
PicUrl string `json:"pic_url"` //图片地址
}

type RobotMacSendTextRequest struct {
RobotId int `json:"robot_id"` //机器人id
WxId string `json:"toWxId"` //发送微信好友/群id。一般wxid_开头
Content string `json:"content"` //内容
}

type RobotMacSendRecvImageRequest struct {
RobotId int `json:"robot_id"` //机器人id
WxId string `json:"wx_id"` //发送微信好友/群id。一般wxid_开头
Content string `json:"content"` //消息xml内容
}

type GetUserInfoResponse struct {
User interface{} `json:"user"`
State int `json:"state"` //状态(0:未开通 1:未绑定 2:未登录 3:已登录)
EndTime string `json:"end_time"` //到期时间
OpenTime string `json:"open_time"` //开通时间
BalanceDay int `json:"balance_day"` //剩余天数
WcNickname string `json:"wc_nickname"` //微信昵称
WcHeadUrl string `json:"wc_head_url"` //微信头像
GroupNum int `json:"group_num"` //最大群数
AlreadyBindGroupNum int `json:"already_bind_group_num"` //已绑定群数
}

type RobotMacGetChatRoomMemberRequest struct {
RobotId int `json:"robot_id"` //机器人id
RoomId string `json:"room_id"` // 群的id
}

type RobotMacGetChatRoomMemberResponseV1 struct {
UserName string `json:"userName"` //微信号
NickName string `json:"nickName"` //昵称
DisplayName string `json:"displayName"` //群昵称
BigHeadImgUrl string `json:"bigHeadImgUrl"` //头像
SmallHeadImgUrl string `json:"smallHeadImgUrl"` //头像(缩略图)
InviteUser string `json:"inviteUser"` //邀请人微信号
}
type RobotMacGetChatRoomMemberResponse struct {
UserName string `json:"user_name"` //微信号
NickName string `json:"nick_name"` //昵称
DisplayName string `json:"display_name"` //群昵称
BigHeadImgUrl string `json:"big_head_img_url"` //头像
SmallHeadImgUrl string `json:"small_head_img_url"` //头像(缩略图)
InviteUser string `json:"invite_user"` //邀请人微信号
}

type FollowGroupIndexResponse struct {
List []FollowGroupAddRequest `json:"list"`
FollowGroupUserNums int `json:"follow_group_user_nums"` //群跟发用户数量
FollowGroupRelayNums int `json:"follow_group_relay_nums"` //群跟发可转发群数
FollowGroupBindNums int `json:"follow_group_bind_nums"` //群跟发可绑定群数
AlreadyFollowGroupBindNums int `json:"already_follow_group_bind_nums"` //群跟发已绑定群数
}

+ 18
- 0
cloud_issuance/md/md_call_back.go Parādīt failu

@@ -0,0 +1,18 @@
package md

type CallbackRequest struct {
Account string `json:"account"` //账号
MessageType int `json:"messageType"` //消息类型(0:好友请求 1:群邀请 2: 群名片 3:个人名片 4:下线 5:私聊文本消息 6:私聊图片消息 7:聊视频消息 8:私聊语音消息 9:群聊文本消息 10:群聊图片消息 11:群聊视频消息 12:群语音消息 13:私其他类型消息 4:群聊其他类型消)
RobotId int `json:"robotId"` //机器人id
WcId string `json:"wcId"` //微信号
Data struct {
Content string `json:"content"` //消息体
FromGroup string `json:"fromGroup"` //发送群号
FromUser string `json:"fromUser"` //发送微信号
ToUser string `json:"toUser"` //接收微信号
MsgId string `json:"msgId"` //消息id
MsgType string `json:"msgType"` //其他消息具体类型
IsGroup bool `json:"isGroup"` //是否为群组消息
Timestamp string `json:"timestamp"` //时间
} `json:"data"`
}

+ 1
- 0
cloud_issuance/md/md_cloud_issuance_user_robot.go Parādīt failu

@@ -0,0 +1 @@
package md

+ 26
- 0
cloud_issuance/md/md_package.go Parādīt failu

@@ -0,0 +1,26 @@
package md

type BuyPackageReq struct {
PackageId int `json:"package_id"` //套餐id
}

type GrabRedPackageReq struct {
UserId string `json:"user_id"` //im用户id
SendRedPackageUserNikeName string `json:"send_red_package_user_nike_name"` //红包发送者-im用户昵称
SendRedPacketAvatarUrl string `json:"send_red_packet_avatar_url"` //红包发送者-im用户头像
DeviceId string `json:"device_id"` //设备id
Token string `json:"token"` //im-token
ReceiverType int `json:"receiver_type"` //接收者类型,1:user;2:group
ReceiverId int64 `json:"receiver_id"` //用户id或者群组id
SendTime int64 `json:"send_time"` //消息发送时间戳,精确到毫秒
RedPackageId int `json:"red_package_id"` //红包id
RedPackageCover string `json:"red_package_cover"` //红包封面
}

type RedPackageDetailResp struct {
ImUserId string `json:"im_user_id"` //im用户id
UserNickName string `json:"user_nick_name"` //im用户昵称
UserAvatarUrl string `json:"user_avatar_url"` //im用户昵称
Amount string `json:"amount"` //金额
ReceiveAt string `json:"received_at"` //领取时间
}

+ 93
- 0
cloud_issuance/md/md_request.go Parādīt failu

@@ -0,0 +1,93 @@
package md

import "time"

type AddGroupRequest struct {
Data []*GroupRequest `json:"data"`
}
type GroupRequest struct {
ChatRoomId string `json:"chatRoomId"`
NickName string `json:"nickName"`
ChatRoomOwner string `json:"chatRoomOwner"`
BigHeadImgUrl string `json:"bigHeadImgUrl"`
SmallHeadImgUrl string `json:"smallHeadImgUrl"`
MemberCount string `json:"memberCount"`
}

type UpdateStateBindGroupRequest struct {
Id int `json:"id"`
State int `json:"state"`
}

type UpdateGoodsCategoryBindGroupRequest struct {
Id int `json:"id"`
CategoryId int `json:"category_id"`
}

type DeleteBindGroupRequest struct {
Id int `json:"id"`
}

type BuyPackageRecordsRequest struct {
Page int `json:"page"`
Limit int `json:"limit"`
}
type BuyPackageRecordsResponse struct {
Id int `json:"id"`
OrdNo string `json:"ord_no"`
TradeNo string `json:"trade_no"`
PackageId int `json:"package_id"`
Uid int `json:"uid"`
Amount string `json:"amount"`
State int `json:"state"`
PayChannel int `json:"pay_channel"`
Months int `json:"months"`
PackageName string `json:"package_name"`
CreateAt string `json:"create_at" `
UpdateAt string `json:"update_at" `
}

type FindCloudIssuanceUserRobotBindGroupResponse struct {
Id int `json:"id" `
Uid int `json:"uid"`
Name string `json:"name"`
RobotId int `json:"robot_id"`
ChatRoomId string `json:"chat_room_id"`
ChatRoomOwner string `json:"chat_room_owner"`
MemberCount int `json:"member_count"`
BigHeadImgUrl string `json:"big_head_img_url"`
SmallHeadImgUrl string `json:"small_head_img_url"`
GoodsCategoryId int `json:"goods_category_id"`
State int `json:"state"`
GoodsCategoryName string `json:"goods_category_name"`
CreateAt time.Time `json:"create_at"`
UpdateAt time.Time `json:"update_at"`
}

type FollowGroupIsUseRequest struct {
Id int `json:"id"`
State int `json:"state"`
}
type FollowGroupDeleteRequest struct {
Id int `json:"id"`
}

type FollowGroupAddRequest struct {
Id int `json:"id"`
ChatRoomId string `json:"chat_room_id"`
Name string `json:"name"`
ChatRoomOwner string `json:"chat_room_owner"`
BigHeadImgUrl string `json:"big_head_img_url"`
SmallHeadImgUrl string `json:"small_head_img_url"`
MemberCount string `json:"member_count"`
State int `json:"state"`
FollowUserList []RobotMacGetChatRoomMemberResponse `json:"follow_user_list"`
FollowGroupList []struct {
ChatRoomId string `json:"chat_room_id"`
NickName string `json:"nick_name"`
ChatRoomOwner string `json:"chat_room_owner"`
BigHeadImgUrl string `json:"big_head_img_url"`
SmallHeadImgUrl string `json:"small_head_img_url"`
MemberCount string `json:"member_count"`
} `json:"follow_group_list"`
}

+ 77
- 0
cloud_issuance/md/mq.go Parādīt failu

@@ -0,0 +1,77 @@
package md

const RobotQrcodeMacLoginQueue = "cloud_issuance_async_mlogin"
const CloudIssuanceMsgCallBackQueue = "cloud_issuance_msg_call_back" //云发单消息回调

type CloudIssuanceAsyncMLogin struct {
UserId string `json:"user_id"` //用户id
MasterId string `json:"master_id"` //站长id
WId string `json:"wId"` //实例id
RobotId int `json:"robot_id"` //机器人id
QrCodeUrl string `json:"qrCodeUrl"`
}

const UserWithdrawApplyExchange = "zhios.app.user.withdraw.apply.exchange"
const ZhiosCapitalPoolOrderTotalExchange = "zhios.capital_pool.order_total.exchange"
const CloudIssuanceMsgCallBackExchange = "zhios.cloud.issuance.msg.callback.exchange"

const DouShenUserRegisterExchange = "zhios.doushen.user.register.exchange"
const FastReturnOrder = "zhios.order.fast.return.exchange"

const (
DouShenUserRegisterRoutKeyForOfficial = "official" // 官方
DouShenUserRegisterRoutKeyForOperationCenter = "operation_center" // 运营中心
DouShenUserRegisterRoutKeyForMyRecommender = "my_recommender" // 我的推荐人
DouShenUserRegisterRoutKeyForMyFans = "my_fans" // 我的粉丝
DouShenUserRegisterRoutKeyForUserRegisterCommUpLv = "user_register_comm_up_lv" // 用户注册自动升级(给推荐人)
FastReturnOrderRoutKeyForOrderPay = "order_pay"
FastReturnOrderRoutKeyForOrderRefund = "order_refund"
FastReturnOrderRoutKeyForOrderSuccess = "order_success"
ZhiosCapitalPoolOrderTotalStr = "order_total"
)

type DouShenUserRegisterMessageStructForOfficial struct {
MasterId string `json:"master_id"`
Phone int64 `json:"phone"`
Uid int64 `json:"uid"`
}
type DouShenUserRegisterMessageStructForMyFans struct {
MasterId string `json:"master_id"`
Phone int64 `json:"phone"`
Uid int64 `json:"uid"`
}
type DouShenUserRegisterMessageStructForMyRecommender struct {
MasterId string `json:"master_id"`
Phone int64 `json:"phone"`
Uid int64 `json:"uid"`
RecommenderUid int64 `json:"recommender_uid"`
RecommenderPhone string `json:"recommender_phone"`
}
type DouShenUserRegisterMessageStructForOperationCenter struct {
MasterId string `json:"master_id"`
Phone int64 `json:"phone"`
Uid int64 `json:"uid"`
OperationCenterUid int64 `json:"operation_center_uid"`
OperationCenterPhone string `json:"operation_center_phone"`
}
type DouShenUserRegisterMessageStructForCommUpLv struct {
MasterId string `json:"master_id"`
Uid int64 `json:"uid"`
}

type ZhiosFatReturnOrderPay struct {
Uid string `json:"uid"`
Mid string `json:"mid"`
Oid string `json:"oid"`
Name string `json:"name"`
Prd string `json:"prd"`
}

type ZhiosCapitalPoolOrderTotal struct {
Uid []string `json:"uid"`
Mid string `json:"mid"`
Runtime int64 `json:"runtime"`
TotalTime int64 `json:"totalTime"`
BonusLevelType int `json:"bonusLevelType"`
Level string `json:"level"`
}

+ 307
- 0
cloud_issuance/svc/svc_cloud_issuance.go Parādīt failu

@@ -0,0 +1,307 @@
package svc

import (
"applet/app/cfg"
"applet/app/utils"
"applet/cloud_issuance/enum"
"applet/cloud_issuance/md"
"applet/cloud_issuance/tool"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"strconv"
"strings"
)

type CloudIssuanceService struct {
Context *gin.Context `json:"context"`
RequestMethodName string `json:"request_method_name"`
RequestClientIp string `json:"request_client_ip"`
}

func (svcCloudIssuance *CloudIssuanceService) Set(c *gin.Context, methodName, clientIp string) { // set方法
svcCloudIssuance.Context = c
svcCloudIssuance.RequestMethodName = methodName
svcCloudIssuance.RequestClientIp = clientIp
}

func (svcCloudIssuance *CloudIssuanceService) RobotCreate(args md.RobotCreateRequest) (err error, result md.RobotCreateResponse) { // 添加机器人
if !cfg.Prd {
//TODO::测试环境不用买
return
}
url := tool.HttpBuild(svcCloudIssuance.RequestMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"month": strconv.Itoa(args.Month),
"robot_type": args.RobotType,
"wechatrobot": args.WechatRobot,
"remark": args.Remark,
})
data, err := svcCloudIssuance.SendPost(url, args)
if err != nil {
return
}
resByte, err := json.Marshal(data.Data)
if err != nil {
return
}
err = json.Unmarshal(resByte, &result)
if err != nil {
return
}

return
}

func (svcCloudIssuance *CloudIssuanceService) QrcodeMacLogin(args md.RobotQrcodeMacLoginRequest) (err error, result md.RobotQrcodeMacLoginResponse) { // 获取登录二维码
url := tool.HttpBuild(svcCloudIssuance.RequestMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
})
data, err := svcCloudIssuance.SendPost(url, args)
if err != nil {
return
}
resByte, err := json.Marshal(data.Data)
if err != nil {
return
}
err = json.Unmarshal(resByte, &result)
if err != nil {
return
}
return
}

func (svcCloudIssuance *CloudIssuanceService) RobotAsyncMacLogin(args md.RobotAsyncMacLoginRequest) (err error, result md.RobotAsyncMacLoginResponse) { // 同步登录状态
url := tool.HttpBuild(svcCloudIssuance.RequestMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
"wId": args.WId,
})
data, err := svcCloudIssuance.SendPost(url, args)
if err != nil {
return
}
resByte, err := json.Marshal(data.Data)
if err != nil {
return
}
err = json.Unmarshal(resByte, &result)
if err != nil {
return
}
return
}

func (svcCloudIssuance *CloudIssuanceService) RobotForceOffline(args md.RobotForceOfflineRequest) (err error) { // 下线机器人
url := tool.HttpBuild(svcCloudIssuance.RequestMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
})
_, err = svcCloudIssuance.SendPost(url, args)
return
}

func (svcCloudIssuance *CloudIssuanceService) RobotSecondLogin(args md.RobotSecondLoginRequest) (err error, result md.RobotSecondLoginResponse) { // 二次登录
url := tool.HttpBuild(svcCloudIssuance.RequestMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
})
data, err := svcCloudIssuance.SendPost(url, args)
if err != nil {
return
}
resByte, err := json.Marshal(data.Data)
if err != nil {
return
}
err = json.Unmarshal(resByte, &result)
if err != nil {
return
}
return
}

func (svcCloudIssuance *CloudIssuanceService) RobotChange(args md.RobotChangeRequest) (err error, result md.RobotChangeResponse) { // 机器人修改/续费
if !cfg.Prd {
//TODO::测试环境不用买
return
}
url := tool.HttpBuild(svcCloudIssuance.RequestMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
"month": strconv.Itoa(args.Month),
})
data, err := svcCloudIssuance.SendPost(url, args)
if err != nil {
return
}
resByte, err := json.Marshal(data.Data)
if err != nil {
return
}
err = json.Unmarshal(resByte, &result)
if err != nil {
return
}
return
}

func (svcCloudIssuance *CloudIssuanceService) RobotReset(args md.RobotResetRequest) (err error) { // 重置机器人
url := tool.HttpBuild(svcCloudIssuance.RequestMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
})
_, err = svcCloudIssuance.SendPost(url, args)
return
}

func (svcCloudIssuance *CloudIssuanceService) RobotRoomList(args md.RobotRoomListRequest) (err error, result []md.RobotRoomDetailResponse) { // 群组列表
url := tool.HttpBuild(svcCloudIssuance.RequestMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
})
data, err := svcCloudIssuance.SendPost(url, args)
if err != nil {
return
}
resByte, err := json.Marshal(data.Data)
if err != nil {
return
}
var list = md.RobotRoomListResponse{}
err = json.Unmarshal(resByte, &list)
if err != nil {
return
}

//TODO::每次最多5个 调用"群组详情"接口
i := 0
var tmpList = md.RobotRoomListResponse{}
var tmpResult []md.RobotRoomDetailResponse
for i < len(list) {
tmpList = append(tmpList, list[i])
i++
if len(tmpList) == 1 {
roomId := strings.Join(tmpList, ",")
requestUrl := tool.HttpBuild(enum.RobotRoomDetailMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
"room_id": roomId,
})
data, err = svcCloudIssuance.SendPost(requestUrl, md.RobotRoomDetailRequest{
RobotId: args.RobotId,
RoomId: roomId,
})
resByte, err = json.Marshal(data.Data)
if err != nil {
return
}
err = json.Unmarshal(resByte, &tmpResult)
if err != nil {
return
}
result = append(result, tmpResult...)
tmpList = md.RobotRoomListResponse{}
}
}

if len(tmpList) > 0 {
roomId := strings.Join(list, ",")
requestUrl := tool.HttpBuild(enum.RobotRoomDetailMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
"room_id": roomId,
})
data, err = svcCloudIssuance.SendPost(requestUrl, md.RobotRoomDetailRequest{
RobotId: args.RobotId,
RoomId: roomId,
})
resByte, err = json.Marshal(data.Data)
if err != nil {
return
}
err = json.Unmarshal(resByte, &tmpResult)
if err != nil {
return
}
result = append(result, tmpResult...)
tmpList = md.RobotRoomListResponse{}
}

return
}

func (svcCloudIssuance *CloudIssuanceService) RobotMacGetChatRoomMember(args md.RobotMacGetChatRoomMemberRequest) (err error, result []md.RobotMacGetChatRoomMemberResponseV1) { // 获取群成员
url := tool.HttpBuild(svcCloudIssuance.RequestMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
"room_id": args.RoomId,
})
data, err := svcCloudIssuance.SendPost(url, args)
if err != nil {
return
}
resByte, err := json.Marshal(data.Data)
if err != nil {
return
}
err = json.Unmarshal(resByte, &result)
if err != nil {
return
}
return
}

func (svcCloudIssuance *CloudIssuanceService) RobotMacSendCard(args md.RobotMacSendCardRequest) (err error) { // 发送链接消息
url := tool.HttpBuild(svcCloudIssuance.RequestMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
"wx_id": args.WxId,
"title": args.Title,
"url": args.Url,
"description": args.Description,
"thumbUrl": args.ThumbUrl,
})
_, err = svcCloudIssuance.SendPost(url, args)
return
}

func (svcCloudIssuance *CloudIssuanceService) RobotMacSendUri(args md.RobotMacSendUriRequest) (err error) { // 发送uri图片消息
url := tool.HttpBuild(svcCloudIssuance.RequestMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
"toWxId": args.WxId,
"pic_url": args.PicUrl,
})
_, err = svcCloudIssuance.SendPost(url, args)
return
}

func (svcCloudIssuance *CloudIssuanceService) RobotMacSendText(args md.RobotMacSendTextRequest) (err error) { // 发送文本消息
url := tool.HttpBuild(svcCloudIssuance.RequestMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
"toWxId": args.WxId,
"content": args.Content,
})
resp, err := svcCloudIssuance.SendPost(url, args)
if args.RobotId == 487259 {
utils.FilePutContents("RobotMacSendText_487259", utils.SerializeStr(resp))
}
return
}

func (svcCloudIssuance *CloudIssuanceService) RobotMacSendRecvImage(args md.RobotMacSendRecvImageRequest) (err error) { // 发送文本消息
url := tool.HttpBuild(svcCloudIssuance.RequestMethodName, svcCloudIssuance.RequestClientIp, map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
"wx_id": args.WxId,
"content": args.Content,
})
_, err = svcCloudIssuance.SendPost(url, args)
return
}

func (svcCloudIssuance *CloudIssuanceService) SendPost(url string, args interface{}) (data md.CurlResponse, err error) {
data, err = tool.SendPost(url, args)
if data.Status == "1123" && data.Msg == "当前机器人不在线" && svcCloudIssuance.Context != nil {
fmt.Println(">>>>>>>>>>>>>>>>>>当前机器人不在线<<<<<<<<<<<<<<<<<<<<<<", data.Data)
//cloudIssuanceUserRobotDb := db.CloudIssuanceUserRobotDb{}
//user := svcComm.GetUser(svcCloudIssuance.Context)
//cloudIssuanceUserRobotDb.Set(svcCloudIssuance.Context, user.Info.Uid)
//robot, err := cloudIssuanceUserRobotDb.GetCloudIssuanceUserRobot()
//if err != nil {
// panic(err)
//}
//robot.LoginStatus = enum.NotLogin
//cloudIssuanceUserRobotDb.SaveCloudIssuanceUserRobot(robot.Id, robot, "login_status")
}
return
}

+ 141
- 0
cloud_issuance/svc/svc_deal_call_back.go Parādīt failu

@@ -0,0 +1,141 @@
package svc

import (
"applet/app/cfg"
db2 "applet/app/db"
"applet/app/svc"
"applet/app/utils"
"applet/cloud_issuance/db"
"applet/cloud_issuance/enum"
"applet/cloud_issuance/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/chain_transfer"
cache2 "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils/cache"
"fmt"
"github.com/gin-gonic/gin"
"time"
)

type DealCloudIssuanceCallBackService struct {
Context *gin.Context `json:"context"`
}

func (dealCloudIssuanceCallBackService *DealCloudIssuanceCallBackService) Set(c *gin.Context) { // set方法
dealCloudIssuanceCallBackService.Context = c
}

func (dealCloudIssuanceCallBackService *DealCloudIssuanceCallBackService) DealCallBack(c *gin.Context, req md.CallbackRequest) {
//1、初始化云发单类
cloudIssuanceService := CloudIssuanceService{}

//1、判断是否为群组消息
if req.Data.IsGroup {
//2、判断消息类型
switch req.MessageType {
case 9:
//群聊文本消息
bindId := dealCloudIssuanceCallBackService.IsNeedDealGroupMessage(req.Data.FromGroup, req.Data.FromUser, req.RobotId)
if bindId == 0 {
return
}
//3、查询需转发的群
cloudIssuanceUserRobotBindFollowGroupDb := db.CloudIssuanceUserRobotBindFollowGroupDb{}
cloudIssuanceUserRobotBindFollowGroupDb.Set(dealCloudIssuanceCallBackService.Context)
cloudIssuanceUserRobotBindFollowGroups, err := cloudIssuanceUserRobotBindFollowGroupDb.GetCloudIssuanceUserRobotBindFollowGroupByBindId(bindId)
if err != nil {
fmt.Println("DealCallBack_err::::", err.Error())
return
}
cache2.NewRedis(cfg.RedisAddr)
cloudIssuanceUserRobotBindFollowDb := db.CloudIssuanceUserRobotBindFollowDb{}
cloudIssuanceUserRobotBindFollowDb.Set(dealCloudIssuanceCallBackService.Context, 0)
cloudIssuanceUserRobotBindFollow, err := cloudIssuanceUserRobotBindFollowDb.GetCloudIssuanceUserRobotBindFollow(bindId)
for _, cloudIssuanceUserRobotBindFollowGroup := range cloudIssuanceUserRobotBindFollowGroups {
fmt.Println(cloudIssuanceUserRobotBindFollowGroup)
cloudIssuanceService.Set(nil, enum.RobotMacSendTextMethodName, "127.0.0.1")
//转链
if cloudIssuanceUserRobotBindFollow.Uid > 0 {
args := map[string]string{
"uid": utils.IntToStr(cloudIssuanceUserRobotBindFollow.Uid),
"platform": "",
"master_id": c.GetString("mid"),
"content": req.Data.Content,
}
utils.FilePutContents("cloud", utils.SerializeStr(args))
time.Sleep(time.Microsecond * 500) // 等待500微妙
chain := chain_transfer.TurnChain(svc.MasterDb(c), db2.Db, args)
utils.FilePutContents("cloud", utils.SerializeStr(chain))
if chain.Count != "" {
req.Data.Content = chain.Count
}
}
utils.FilePutContents("cloud", req.Data.Content)
err = cloudIssuanceService.RobotMacSendText(md.RobotMacSendTextRequest{
RobotId: req.RobotId,
WxId: cloudIssuanceUserRobotBindFollowGroup.FollowChatRoomId,
Content: req.Data.Content,
})
if err != nil {
fmt.Println("DealCallBack_err::::", err.Error())
return
}
}
break
case 10:
//群聊图片消息
bindId := dealCloudIssuanceCallBackService.IsNeedDealGroupMessage(req.Data.FromGroup, req.Data.FromUser, req.RobotId)
if bindId == 0 {
return
}
//3、查询需转发的群
cloudIssuanceUserRobotBindFollowGroupDb := db.CloudIssuanceUserRobotBindFollowGroupDb{}
cloudIssuanceUserRobotBindFollowGroupDb.Set(dealCloudIssuanceCallBackService.Context)
cloudIssuanceUserRobotBindFollowGroups, err := cloudIssuanceUserRobotBindFollowGroupDb.GetCloudIssuanceUserRobotBindFollowGroupByBindId(bindId)
if err != nil {
fmt.Println("DealCallBack_err::::", err.Error())
return
}
for _, cloudIssuanceUserRobotBindFollowGroup := range cloudIssuanceUserRobotBindFollowGroups {
cloudIssuanceService.Set(nil, enum.RobotMacSendRecvImageMethodName, "127.0.0.1")
err = cloudIssuanceService.RobotMacSendRecvImage(md.RobotMacSendRecvImageRequest{
RobotId: req.RobotId,
WxId: cloudIssuanceUserRobotBindFollowGroup.FollowChatRoomId,
Content: req.Data.Content,
})
if err != nil {
fmt.Println("DealCallBack_err::::", err.Error())
return
}
}
break
}
}
}

func (dealCloudIssuanceCallBackService *DealCloudIssuanceCallBackService) IsNeedDealGroupMessage(fromGroup, fromUser string, robotId int) (bindId int) {
//查询 "发送群号" 是否被监听
cloudIssuanceUserRobotBindFollowDb := db.CloudIssuanceUserRobotBindFollowDb{}
cloudIssuanceUserRobotBindFollowDb.Set(dealCloudIssuanceCallBackService.Context, 0)
cloudIssuanceUserRobotBindFollow, err := cloudIssuanceUserRobotBindFollowDb.GetCloudIssuanceUserRobotBindFollowByChatRoomId(fromGroup, robotId)
if err != nil {
fmt.Println("IsNeedDealGroupMessage_Err:::::", err.Error())
return
}
if cloudIssuanceUserRobotBindFollow == nil {
return
}

//查询 "发送微信号" 是否被监听
cloudIssuanceUserRobotBindFollowUserDb := db.CloudIssuanceUserRobotBindFollowUserDb{}
cloudIssuanceUserRobotBindFollowUserDb.Set(dealCloudIssuanceCallBackService.Context)
cloudIssuanceUserRobotBindFollowUser, err := cloudIssuanceUserRobotBindFollowUserDb.GetCloudIssuanceUserRobotBindFollowUserByWxId(fromUser)
if err != nil {
fmt.Println("IsNeedDealGroupMessage_Err:::::", err.Error())
return
}
if cloudIssuanceUserRobotBindFollowUser == nil {
return
}

bindId = cloudIssuanceUserRobotBindFollow.Id
return
}

+ 85
- 0
cloud_issuance/tool/api.go Parādīt failu

@@ -0,0 +1,85 @@
package tool

import (
"applet/app/utils"
"applet/cloud_issuance/md"
"encoding/json"
"errors"
"fmt"
"sort"
"time"
)

const (
RequestUrl = "http://router.itaokecms.com/api?app_key=%s&v=1.0&format=json&sign_method=md5&method=%s&timestamp=%s&domain=%s&client=%s&partner_id=%s&sign=%s"
AppKey = "1091808433"
AppSecret = "bed35c10-ecf1-2d06-477b-f821c227198b"
Domain = "hairuyi.com"
PartnerId = "top-sdk-php-20190618"
)

func SendPost(url string, args interface{}) (data md.CurlResponse, err error) {
utils.FilePutContents("cloud_issuance_send", utils.SerializeStr(map[string]interface{}{
"time": time.Now().Format("2006-01-02 15:04:05.000"),
"args": args,
"url": url,
}))
post, err := utils.CurlPost(url, utils.Serialize(args), map[string]string{})
err = json.Unmarshal(post, &data)
utils.FilePutContents("cloud_issuance_send", utils.SerializeStr(map[string]interface{}{
"time": time.Now().Format("2006-01-02 15:04:05.000"),
"resp": post,
}))
if err != nil {
return
}
if data.Status != "0000" {
err = errors.New(data.Msg)
return
}
return data, err
}

func HttpBuild(methodName, clientIP string, params map[string]string) (httpUrl string) {
timestamp := utils.AnyToString(time.Now().Unix())
params["app_key"] = AppKey
params["v"] = "1.0"
params["format"] = "json"
params["sign_method"] = "md5"
params["method"] = methodName
params["timestamp"] = timestamp
params["domain"] = Domain
params["client"] = clientIP
params["partner_id"] = PartnerId
sign := httpBuildQuery(params, true)
sign = AppSecret + httpBuildQuery(params, true) + AppSecret
sign = utils.MD5ToUpper32(sign)
httpUrl = fmt.Sprintf(RequestUrl, AppKey, methodName, timestamp, Domain, clientIP, PartnerId, sign)
return
}

func httpBuildQuery(args map[string]string, sortAsc ...bool) string {
str := ""
if len(args) == 0 {
return str
}
if len(sortAsc) > 0 {
keys := make([]string, 0, len(args))
for k := range args {
keys = append(keys, k)
}
if sortAsc[0] {
sort.Strings(keys)
} else {
sort.Sort(sort.Reverse(sort.StringSlice(keys)))
}
for _, k := range keys {
str += k + args[k]
}
} else {
for k, v := range args {
str += k + v
}
}
return str
}

+ 26
- 0
cloud_issuance/utils/algorithm.go Parādīt failu

@@ -0,0 +1,26 @@
package utils

import (
"math/rand"
"time"
)

//RED_PACKET_MIN_MONEY 红包最小金额(单位:分)
const RED_PACKET_MIN_MONEY = 1

//DoubleAverage 二倍均值算法
func DoubleAverage(count, amount int64) int64 {
if count == 1 {
return amount
}
//计算出最大可用金额
max := amount - RED_PACKET_MIN_MONEY*count
//计算出最大可用平均值
avg := max / count
//二倍均值基础上再加上最小金额 防止出现金额为0
avg2 := 2*avg + RED_PACKET_MIN_MONEY
//随机红包金额序列元素,把二倍均值作为随机的最大数
rand.Seed(time.Now().UnixNano())
x := rand.Int63n(avg2) + RED_PACKET_MIN_MONEY
return x
}

+ 60
- 0
cloud_issuance/utils/rpc_client.go Parādīt failu

@@ -0,0 +1,60 @@
package utils

import (
"applet/pkg/pb"
"context"
"fmt"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"strconv"
"time"
)

func GetBusinessIntClient(url, port string) pb.BusinessIntClient {
target := fmt.Sprintf("%s:%s", url, port)
conn, err := grpc.Dial(target, grpc.WithInsecure())
if err != nil {
fmt.Println(err)
return nil
}
return pb.NewBusinessIntClient(conn)
}

func GetBusinessExtClient(url, port string) pb.BusinessExtClient {
target := fmt.Sprintf("%s:%s", url, port)
conn, err := grpc.Dial(target, grpc.WithInsecure())
//defer conn.Close()
if err != nil {
fmt.Println(err)
return nil
}
return pb.NewBusinessExtClient(conn)
}

func GetLogicExtClient(url, port string) pb.LogicExtClient {
target := fmt.Sprintf("%s:%s", url, port)
conn, err := grpc.Dial(target, grpc.WithInsecure())
if err != nil {
fmt.Println(err)
return nil
}
return pb.NewLogicExtClient(conn)
}

func GetCtx(token, userId, deviceId, masterId string) context.Context {
if userId == "" {
userId = "1"
}
if deviceId == "" {
deviceId = "1"
}
if token == "" {
token = "0"
}
return metadata.NewOutgoingContext(context.TODO(), metadata.Pairs(
"user_id", userId,
"device_id", deviceId,
"token", token,
"master_id", masterId,
"request_id", strconv.FormatInt(time.Now().UnixNano(), 10)))
}

+ 10
- 0
cloud_issuance/utils/string.go Parādīt failu

@@ -0,0 +1,10 @@
package utils

func ContainerStr(slice []string, element string) bool {
for _, e := range slice {
if e == element {
return true
}
}
return false
}

+ 143
- 0
consume/canal_order_consume.go Parādīt failu

@@ -2,6 +2,8 @@ package consume

import (
"applet/app/db"
model2 "applet/app/db/gim/model"
"applet/app/db/model"
"applet/app/utils"
"applet/app/utils/logx"
"applet/consume/md"
@@ -12,11 +14,152 @@ import (
"errors"
"fmt"
"github.com/streadway/amqp"
"regexp"
"strconv"
"strings"
"time"
)

func CanalOrderConsumev2(queue md.MqQueue) {
var list []model.DouShenImGroup
err := db.Db.Where("kind =2 and id = 43140").Find(&list)
eg := db.DBs["68823769"]
for _, v := range list {
var m model.RegionalAgentUser
has, err := eg.Where("uid =?", v.Uid).Get(&m)
if err != nil {
panic(err)
}
if !has {
fmt.Println(">>>", v)
}
var group model2.Group
has, err = db.ImDb.Where("id =?", v.GroupId).Get(&group)
if err != nil {
panic(err)
}
if !has {
fmt.Println("<<<", v)
}
regionalAgentRegion, err := db.RegionalAgentRegionGetOneByParams(eg, map[string]interface{}{
"key": "id",
"value": m.RegionId,
})
if err != nil {
panic(err)
}
groupName := "抖省" + regionalAgentRegion.Name + "运营中心【1】群"
group.Name = groupName
_, err = db.ImDb.Where("id =?", v.GroupId).Cols("name").Update(group)
if err != nil {
panic(err)
}

v.Name = groupName
_, err = db.Db.Where("id =?", v.Id).Cols("name").Update(v)
if err != nil {
panic(err)
}
}

return
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>")
ch, err := rabbit.Cfg.Pool.GetChannel()
if err != nil {
logx.Error(err)
return
}
defer ch.Release()
//1、将自己绑定到交换机上
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
//2、取出数据进行消费
ch.Qos(1)
delivery := ch.Consume(queue.Name, false)

var res amqp.Delivery
var ok bool
for {
res, ok = <-delivery
if ok == true {
//fmt.Println(string(res.Body))
fmt.Println(">>>>>>>>>>>>>>>>CanalOrderConsume<<<<<<<<<<<<<<<<<<<<<<<<<")
err = handleMallOrdTable(res.Body)
//_ = res.Reject(false)
_ = res.Ack(true)
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func CanalOrderConsume(queue md.MqQueue) {
now := time.Now()
var list []model2.Group
err := db.ImDb.Where("master_id = 68823769").And("user_num > ?", 500).Find(&list)
//eg := db.DBs["68823769"]
for _, v := range list {
var groupUsers []model2.GroupUser
var groupLeader model2.GroupUser
err = db.ImDb.Where("group_id = ?", v.Id).And("member_type = 2").Limit(10000, 499).Find(&groupUsers)
db.ImDb.Where("group_id = ?", v.Id).And("member_type = 1").Get(&groupLeader)

//新增一个群
re := regexp.MustCompile("[0-9]+")
num := re.FindAllString(v.Name, -1)[0]
name := strings.Replace(v.Name, num, strconv.Itoa(utils.StrToInt(num)+1), 1)
temGroup := model2.Group{
Name: name,
AvatarUrl: "",
Introduction: "",
UserNum: int32(len(groupUsers)) + 1,
IsAllMemberBanned: 0,
MasterId: v.MasterId,
Extra: "",
CreateTime: now,
UpdateTime: now,
}
_, err := db.ImDb.InsertOne(&temGroup)
if err != nil {
panic(err)
}
groupId := temGroup.Id

//新增群主
_, err = db.ImDb.InsertOne(model2.GroupUser{
GroupId: groupId,
UserId: groupLeader.UserId,
MemberType: 1,
Status: 0,
CreateTime: now.Format("2006-01-02 15:04:05"),
UpdateTime: now.Format("2006-01-02 15:04:05"),
})
if err != nil {
panic(err)
}

for _, groupUser := range groupUsers {
groupUser.GroupId = groupId
db.ImDb.ID(groupUser.Id).Update(groupUser)
}
v.UserNum = 500
db.ImDb.ID(v.Id).Update(v)
var oldDouShenImGroup model.DouShenImGroup
if has, err := db.Db.Where("group_id =?", v.Id).Get(&oldDouShenImGroup); err != nil || has == false {
panic(err)
}
_, err = db.DouShenImGroupInsert(db.Db, &model.DouShenImGroup{
Kind: oldDouShenImGroup.Kind,
Uid: int(oldDouShenImGroup.Uid),
GroupId: int(groupId),
IsFull: 0,
Name: name,
CreateTime: now,
UpdateTime: now,
})
}

return
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>")
ch, err := rabbit.Cfg.Pool.GetChannel()
if err != nil {


+ 4
- 3
consume/cloud_issuance_async_mlogin.go Parādīt failu

@@ -7,6 +7,7 @@ import (
"applet/app/utils/cache"
tool "applet/app/utils/cloud_issuance"
"applet/app/utils/logx"
md2 "applet/cloud_issuance/md"
"applet/consume/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"encoding/json"
@@ -36,7 +37,7 @@ func CloudIssuanceAsyncMLoginConsume(queue md.MqQueue) {
if ok == true {
fmt.Println(">>>>>>>>>>>>>>>>CloudIssuanceAsyncMLoginConsume<<<<<<<<<<<<<<<<<<<<<<<<<")
//解析mq中queue的数据结构体
var msg *md.CloudIssuanceAsyncMLogin
var msg *md2.CloudIssuanceAsyncMLogin
err = json.Unmarshal(res.Body, &msg)
if err != nil {
panic(err)
@@ -58,7 +59,7 @@ func CloudIssuanceAsyncMLoginConsume(queue md.MqQueue) {
func handleAsyncMLogin(wId, masterId, userId string, robotId int) error {
var timeTotal = 0
for {
err, resp := robotAsyncMacLogin(md.RobotAsyncMacLoginRequest{
err, resp := robotAsyncMacLogin(md2.RobotAsyncMacLoginRequest{
WId: wId,
RobotId: robotId,
})
@@ -103,7 +104,7 @@ func handleAsyncMLogin(wId, masterId, userId string, robotId int) error {
}
}

func robotAsyncMacLogin(args md.RobotAsyncMacLoginRequest) (err error, result md.RobotAsyncMacLoginResponse) { // 同步登录状态
func robotAsyncMacLogin(args md2.RobotAsyncMacLoginRequest) (err error, result md2.RobotAsyncMacLoginResponse) { // 同步登录状态
url := tool.HttpBuild("itaoke.robot.async.mlogin", "127.0.0.1", map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
"wId": args.WId,


+ 69
- 0
consume/cloud_issuance_msg_callback.go Parādīt failu

@@ -0,0 +1,69 @@
package consume

import (
"applet/app/utils"
"applet/app/utils/logx"
db "applet/cloud_issuance/db/official"
md2 "applet/cloud_issuance/md"
"applet/cloud_issuance/svc"
"applet/consume/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"encoding/json"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"github.com/streadway/amqp"
)

func CloudIssuanceMsgCallBackConsume(queue md.MqQueue) {
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>")
ch, err := rabbit.Cfg.Pool.GetChannel()
if err != nil {
logx.Error(err)
return
}
defer ch.Release()
//2、取出数据进行消费
ch.Qos(1)
delivery := ch.Consume(queue.Name, false)

var res amqp.Delivery
var ok bool
for {
res, ok = <-delivery
if ok == true {
fmt.Println(">>>>>>>>>>>>>>>>CloudIssuanceMsgCallBackConsume<<<<<<<<<<<<<<<<<<<<<<<<<")
//解析mq中queue的数据结构体
var msg *md2.CallbackRequest
err = json.Unmarshal(res.Body, &msg)
if err != nil {
panic(err)
}
go func() {
//设置masterId
cloudIssuanceRobotRecords, err := db.CloudIssuanceRobotRecordsGetOneByParams(map[string]interface{}{
"key": "robot_id",
"value": msg.RobotId,
})
if err != nil {
fmt.Println("CallBackErr:::::", err.Error())
return
}
if cloudIssuanceRobotRecords == nil {
//TODO::未查询到机器人,不需要处理
utils.FilePutContents("cloud_issuance_call_back_not_found", utils.SerializeStr(msg))
return
}
var c = &gin.Context{}
c.Set("mid", cloudIssuanceRobotRecords.MasterId)
dealCloudIssuanceCallBackService := svc.DealCloudIssuanceCallBackService{}
dealCloudIssuanceCallBackService.Set(c)
dealCloudIssuanceCallBackService.DealCallBack(c, *msg)
}()
_ = res.Ack(true)
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

+ 2
- 0
consume/init.go Parādīt failu

@@ -65,6 +65,8 @@ func initConsumes() {

//jobs[consumeMd.ZhiosRechargeOrderFailDevFunName] = ZhiosRechargeOrderFailDev

jobs[consumeMd.CloudIssuanceMsgCallBackFunName] = CloudIssuanceMsgCallBackConsume

}

func Run() {


+ 10
- 0
consume/md/consume_key.go Parādīt failu

@@ -20,6 +20,15 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "CloudIssuanceAsyncMLoginConsume",
},
{
ExchangeName: "",
Name: "cloud_issuance_msg_call_back",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "",
BindKey: "",
ConsumeFunName: "CloudIssuanceMsgCallBackConsume",
},
{
ExchangeName: "canal.topic",
Name: "canal_order",
@@ -357,6 +366,7 @@ const (
ZhiosTikTokUpdateFunName = "ZhiosTikTokUpdate"
ZhiosTikTokAllUpdateFunName = "ZhiosTikTokAllUpdate"
CloudIssuanceAsyncMLoginFunName = "CloudIssuanceAsyncMLoginConsume"
CloudIssuanceMsgCallBackFunName = "CloudIssuanceMsgCallBackConsume"
ZhiosAcquisitionConditionFunName = "ZhiosAcquisitionCondition"
ZhiosValidUserFunName = "ZhiosValidUser"
ZhiosAppreciationFunName = "ZhiosAppreciation"


+ 0
- 20
consume/md/md_cloud_issuance.go Parādīt failu

@@ -1,20 +0,0 @@
package md

type CloudIssuanceAsyncMLogin struct {
MasterId string `json:"master_id"` //站长id
WId string `json:"wId"` //实例id
RobotId int `json:"robot_id"` //机器人id
UserId string `json:"user_id"` //用户id
QrCodeUrl string `json:"qrCodeUrl"`
}

type RobotAsyncMacLoginRequest struct {
WId string `json:"wId"` //实例id
RobotId int `json:"robot_id"` //机器人id
}
type RobotAsyncMacLoginResponse struct {
WId string `json:"wId"` //实例id
WcId string `json:"wcId"` //微信id
NickName string `json:"nickName"` //微信昵称
HeadUrl string `json:"headUrl"` //微信头像
}

+ 3
- 2
go.mod Parādīt failu

@@ -8,7 +8,7 @@ require (
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.4
code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20231213085413-6f5ba418f36c
code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.2-0.20231116085701-9ba6e19f877b
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20230911014653-22cc8e626d17
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20231221064048-3937c0824e59
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/boombuler/barcode v1.0.1
@@ -24,6 +24,7 @@ require (
github.com/go-redis/redis v6.15.9+incompatible
github.com/go-sql-driver/mysql v1.6.0
github.com/gomodule/redigo v2.0.0+incompatible
github.com/iGoogle-ink/gopay v1.5.36
github.com/jinzhu/copier v0.3.5
github.com/json-iterator/go v1.1.12
github.com/makiuchi-d/gozxing v0.1.1
@@ -58,13 +59,13 @@ require (
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1 // indirect
github.com/iGoogle-ink/gopay v1.5.36 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mvdan/xurls v1.1.0 // indirect
github.com/nilorg/sdk v0.0.0-20221104025912-4b6ccb7004d8 // indirect
github.com/olivere/elastic/v7 v7.0.32 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect


Notiek ielāde…
Atcelt
Saglabāt