shenjiachi vor 3 Tagen
Ursprung
Commit
04b05d09c0
13 geänderte Dateien mit 399 neuen und 182 gelöschten Zeilen
  1. +38
    -1
      app/db/db.go
  2. +1
    -0
      app/db/im/db_customer_service.go
  3. +46
    -0
      app/db/im/db_sys_cfg.go
  4. +15
    -0
      app/db/im/model/customer_service.go
  5. +12
    -0
      app/db/im/model/emoticon.go
  6. +37
    -0
      app/db/im/model/group.go
  7. +7
    -0
      app/db/im/model/sys_cfg.go
  8. +18
    -0
      app/db/im/model/user.go
  9. +0
    -1
      app/hdl/hdl_im.go
  10. +51
    -2
      app/svc/svc_im.go
  11. +67
    -68
      docs/docs.go
  12. +64
    -66
      docs/swagger.json
  13. +43
    -44
      docs/swagger.yaml

+ 38
- 1
app/db/db.go Datei anzeigen

@@ -16,7 +16,7 @@ import (

var Db *xorm.Engine

//根据DB配置文件初始化数据库
// 根据DB配置文件初始化数据库
func InitDB(c *cfg.DBCfg) error {
var (
err error
@@ -51,6 +51,43 @@ func InitDB(c *cfg.DBCfg) error {
return nil
}

var DbIm *xorm.Engine

// 根据DB配置文件初始化数据库
func InitImDB(c *cfg.DBCfg) error {
var (
err error
f *os.File
)
//创建Orm引擎
if DbIm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4", c.User, c.Psw, c.Host, c.Name)); err != nil {
return err
}
DbIm.SetConnMaxLifetime(c.MaxLifetime * time.Second) //设置最长连接时间
DbIm.SetMaxOpenConns(c.MaxOpenConns) //设置最大打开连接数
DbIm.SetMaxIdleConns(c.MaxIdleConns) //设置连接池的空闲数大小
if err = DbIm.Ping(); err != nil { //尝试ping数据库
return err
}
if c.ShowLog { //根据配置文件设置日志
DbIm.ShowSQL(true) //设置是否打印sql
DbIm.Logger().SetLevel(0) //设置日志等级
//修改日志文件存放路径文件名是%s.log
path := fmt.Sprintf(c.Path, c.Name)
f, err = os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777)
if err != nil {
os.RemoveAll(c.Path)
if f, err = os.OpenFile(c.Path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777); err != nil {
return err
}
}
logger := log.NewSimpleLogger(f)
logger.ShowSQL(true)
DbIm.SetLogger(logger)
}
return nil
}

/********************************************* 公用方法 *********************************************/

// 数据批量插入


+ 1
- 0
app/db/im/db_customer_service.go Datei anzeigen

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

+ 46
- 0
app/db/im/db_sys_cfg.go Datei anzeigen

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

import (
"applet/app/db/model"
"applet/app/utils/logx"
"xorm.io/xorm"
)

// 系统配置get
func SysCfgGetAll(Db *xorm.Engine) (*[]model.SysCfg, error) {
var cfgList []model.SysCfg
if err := Db.Cols("key,val,memo").Find(&cfgList); err != nil {
return nil, logx.Error(err)
}
return &cfgList, nil
}

// 获取一条记录
func SysCfgGetOne(Db *xorm.Engine, key string) (*model.SysCfg, error) {
var cfgList model.SysCfg
if has, err := Db.Where("`key`=?", key).Get(&cfgList); err != nil || has == false {
return nil, logx.Error(err)
}
return &cfgList, nil
}

// 返回最后插入id
func SysCfgInsert(Db *xorm.Engine, key, val, memo string) bool {
cfg := model.SysCfg{Key: key, Val: val, Memo: memo}
_, err := Db.InsertOne(&cfg)
if err != nil {
logx.Error(err)
return false
}
return true
}

func SysCfgUpdate(Db *xorm.Engine, key, val, memo string) bool {
cfg := model.SysCfg{Key: key, Val: val, Memo: memo}
_, err := Db.Where("`key`=?", key).Cols("val,memo").Update(&cfg)
if err != nil {
logx.Error(err)
return false
}
return true
}

+ 15
- 0
app/db/im/model/customer_service.go Datei anzeigen

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

import "time"

// CustomerService 客服表
type CustomerService struct {
Id int64
Uid int64 // 用户id
Weight int32 // 权重
State int32 // 状态
HasUserNums int // 拥有用户数量
Memo string // 备注
CreateTime time.Time // 创建时间
UpdateTime time.Time // 更新时间
}

+ 12
- 0
app/db/im/model/emoticon.go Datei anzeigen

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

type Emoticon struct {
Id int64
Name string // 名称
ImgUrl string // 图片地址
Memo string // 备注
Sort int // 排序
State int // 状态0关闭,1开启
CreateAt string // 创建时间
UpdateAt string // 更新时间
}

+ 37
- 0
app/db/im/model/group.go Datei anzeigen

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

// Group 群组
type Group struct {
Id int64 // 群组id
Name string // 组名
AvatarUrl string // 头像
Introduction string // 群简介
UserNum int32 // 群组人数
IsAllMemberBanned int32 // 是否全员禁言(1:是 2:否)
IsAllAddFriend int32 // 是否允许加好友(1:是 2:否)
Extra string // 附加字段
CreateTime string // 创建时间
UpdateTime string // 更新时间
}

type GroupUser struct {
Id int64 // 自增主键
GroupId int64 // 群组id
UserId int64 // 用户id
MemberType int // 群组类型
Remarks string // 备注
Extra string // 附加属性
Status int // 状态
CreateTime string // 创建时间
UpdateTime string // 更新时间
}

type GroupWithOwner struct {
GroupID int64 `json:"group_user.group_id"`
OwnerID int64 `json:"group_user.owner_id"`
}

type CustomerServiceWithUser struct {
CustomerServiceUID int64 `json:"customer_service.uid"`
UserIMID int64 `json:"user.id"`
}

+ 7
- 0
app/db/im/model/sys_cfg.go Datei anzeigen

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

type SysCfg struct {
Key string `json:"key" xorm:"not null pk comment('键') VARCHAR(127)"`
Val string `json:"val" xorm:"comment('值') TEXT"`
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(255)"`
}

+ 18
- 0
app/db/im/model/user.go Datei anzeigen

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

import (
"time"
)

// User 账户
type User struct {
Id int64 // 用户id
PhoneNumber string // 手机号
Nickname string // 昵称
Sex int32 // 性别,1:男;2:女
AvatarUrl string // 用户头像
Extra string // 附加属性
CreateTime time.Time // 创建时间
UpdateTime time.Time // 更新时间
IsAutoAddedFriends int // 是否自动被添加好友
}

+ 0
- 1
app/hdl/hdl_im.go Datei anzeigen

@@ -104,7 +104,6 @@ func GrabRedPackage(c *gin.Context) {
}

//TODO::调用im GRPC 接口
// masterID := c.GetHeader("master_id")
res, err := utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).SendRedPacket(utils.GetCtx(req.Token, req.UserId, req.DeviceId), &pb.SendRedPacketReq{
ReceiverType: pb.ReceiverType(req.ReceiverType),
ReceiverId: req.ReceiverId,


+ 51
- 2
app/svc/svc_im.go Datei anzeigen

@@ -1,13 +1,16 @@
package svc

import (
"applet/app/cfg"
"applet/app/db"
model2 "applet/app/db/im/model"
"applet/app/md"
"applet/app/pkg/pb"
"applet/app/utils"
"applet/app/utils/cache"
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
rule2 "code.fnuoos.com/EggPlanet/egg_system_rules.git"
md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/svc"
@@ -221,11 +224,13 @@ func DetailGrabRedPackage(redPackageId string) (resp []md.RedPackageDetailUserNo
receivedTimes := strings.Split(imSendRedPackageOrd.ReceivedTimes, ",")
receivedUserAmount := strings.Split(imSendRedPackageOrd.ReceivedUserAmount, ",")

redisConn := cache.GetPool().Get()
scheme, domain := svc.ImageBucket(db.Db, redisConn)
for k, v := range receivedUserIds {
resp = append(resp, md.RedPackageDetailUserNode{
ImUserId: receivedImUserIds[k],
UserNickName: usersMap[v].Nickname,
UserAvatarUrl: usersMap[v].Avatar,
UserAvatarUrl: svc.ImageFormatWithBucket(scheme, domain, usersMap[v].Avatar),
Amount: receivedUserAmount[k],
ReceiveAt: receivedTimes[k],
})
@@ -246,6 +251,7 @@ func BalancePayForRedPackage(user *model.User, money string, req md.SendRedPacka
Uid: user.Id,
Amount: utils.StrToFloat64(money),
}
rule2.Init(cfg.RedisAddr)
err = rule.DealUserWallet(session, dealUserWalletReq)
if err != nil {
session.Rollback()
@@ -253,21 +259,60 @@ func BalancePayForRedPackage(user *model.User, money string, req md.SendRedPacka
}

// 新增红包记录
var imUid int
if req.UserId != "" {
imUid = utils.StrToInt(req.UserId)
} else {
//TODO::请求rpc接口,同步用户数据
resp, err := utils.GetBusinessExtClient(cfg.ImBusinessRpc.URL, cfg.ImBusinessRpc.PORT).GetUser(utils.GetCtx("", "", ""), &pb.GetUserReq{
UserId: 0,
Phone: user.Phone,
})
if err != nil {
return nil, redPackageId, err
}
imUid = int(resp.User.UserId)
}

now := time.Now()
ordNo := uuid.New().String()
var waitDrawUserIds string
var waitDrawImUserIds string
if req.RedPacketType == int(pb.RedPacketType_RPT_GROUP_SPECIALLY) {
var toUserIds []string
for _, v := range req.ToUserIds {
toUserIds = append(toUserIds, utils.AnyToString(v))
}
waitDrawUserIds = strings.Join(toUserIds, ",")
userDb := implement.NewUserDb(db.Db)
waitDrawUsers, err1 := userDb.UserFindByParams(map[string]interface{}{
"key": "id",
"value": toUserIds,
})
if err1 != nil {
return nil, 0, err1
}
var waitDrawUserPhones []string
for _, v := range waitDrawUsers {
waitDrawUserPhones = append(waitDrawUserPhones, v.Phone)
}
var waitDrawImUsers []model2.User
err = db.DbIm.Table("user").In("phone_number", waitDrawUserPhones).Find(&waitDrawUsers)
if err != nil {
return nil, 0, err
}
var toUserIMIDs []string
for _, v := range waitDrawImUsers {
toUserIMIDs = append(toUserIMIDs, utils.AnyToString(v.Id))
}
waitDrawImUserIds = strings.Join(toUserIMIDs, ",")
}

ordDb := implement.NewImSendRedPackageOrdDb(db.Db)
m := model.ImSendRedPackageOrd{
OrdNo: ordNo,
Uid: utils.StrToInt(req.UserId),
Uid: int(user.Id),
ImUid: imUid,
Amount: req.Amount,
RedPacketBalanceAmount: req.Amount,
RedPacketType: req.RedPacketType,
@@ -275,6 +320,10 @@ func BalancePayForRedPackage(user *model.User, money string, req md.SendRedPacka
RedPacketBalanceNums: req.RedPacketNums,
State: 0,
WaitDrawUserIds: waitDrawUserIds,
WaitDrawImUserIds: waitDrawImUserIds,
ReceivedUserIds: "",
ReceivedImUserIds: "",
ReceivedUserAmount: "",
CreateTime: now.Format("2006-01-02 15:04:05"),
UpdateTime: now.Format("2006-01-02 15:04:05"),
}


+ 67
- 68
docs/docs.go Datei anzeigen

@@ -1,5 +1,4 @@
// Code generated by swaggo/swag. DO NOT EDIT.

// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs

import "github.com/swaggo/swag"
@@ -2064,9 +2063,7 @@ const docTemplate = `{
"name": "req",
"in": "body",
"required": true,
"schema": {
"type": "object"
}
"schema": {}
}
],
"responses": {
@@ -2555,68 +2552,6 @@ const docTemplate = `{
}
}
},
"code_fnuoos_com_EggPlanet_egg_models_git_src_model.ImSendRedPackageOrd": {
"type": "object",
"properties": {
"amount": {
"type": "string"
},
"create_time": {
"type": "string"
},
"id": {
"type": "integer"
},
"im_data": {
"type": "string"
},
"im_uid": {
"type": "integer"
},
"ord_no": {
"type": "string"
},
"received_im_user_ids": {
"type": "string"
},
"received_times": {
"type": "string"
},
"received_user_amount": {
"type": "string"
},
"received_user_ids": {
"type": "string"
},
"red_packet_balance_amount": {
"type": "string"
},
"red_packet_balance_nums": {
"type": "integer"
},
"red_packet_nums": {
"type": "integer"
},
"red_packet_type": {
"type": "integer"
},
"state": {
"type": "integer"
},
"uid": {
"type": "integer"
},
"update_time": {
"type": "string"
},
"wait_draw_im_user_ids": {
"type": "string"
},
"wait_draw_user_ids": {
"type": "string"
}
}
},
"comm.AccessRecordsReq": {
"type": "object",
"properties": {
@@ -3837,7 +3772,7 @@ const docTemplate = `{
"description": "红包详情信息",
"allOf": [
{
"$ref": "#/definitions/code_fnuoos_com_EggPlanet_egg_models_git_src_model.ImSendRedPackageOrd"
"$ref": "#/definitions/model.ImSendRedPackageOrd"
}
]
},
@@ -4420,6 +4355,68 @@ const docTemplate = `{
}
}
},
"model.ImSendRedPackageOrd": {
"type": "object",
"properties": {
"amount": {
"type": "string"
},
"create_time": {
"type": "string"
},
"id": {
"type": "integer"
},
"im_data": {
"type": "string"
},
"im_uid": {
"type": "integer"
},
"ord_no": {
"type": "string"
},
"received_im_user_ids": {
"type": "string"
},
"received_times": {
"type": "string"
},
"received_user_amount": {
"type": "string"
},
"received_user_ids": {
"type": "string"
},
"red_packet_balance_amount": {
"type": "string"
},
"red_packet_balance_nums": {
"type": "integer"
},
"red_packet_nums": {
"type": "integer"
},
"red_packet_type": {
"type": "integer"
},
"state": {
"type": "integer"
},
"uid": {
"type": "integer"
},
"update_time": {
"type": "string"
},
"wait_draw_im_user_ids": {
"type": "string"
},
"wait_draw_user_ids": {
"type": "string"
}
}
},
"pb.SendRedPacketResp": {
"type": "object",
"properties": {
@@ -4442,6 +4439,8 @@ var SwaggerInfo = &swag.Spec{
Description: "APP客户端-Api接口",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {


+ 64
- 66
docs/swagger.json Datei anzeigen

@@ -2057,9 +2057,7 @@
"name": "req",
"in": "body",
"required": true,
"schema": {
"type": "object"
}
"schema": {}
}
],
"responses": {
@@ -2548,68 +2546,6 @@
}
}
},
"code_fnuoos_com_EggPlanet_egg_models_git_src_model.ImSendRedPackageOrd": {
"type": "object",
"properties": {
"amount": {
"type": "string"
},
"create_time": {
"type": "string"
},
"id": {
"type": "integer"
},
"im_data": {
"type": "string"
},
"im_uid": {
"type": "integer"
},
"ord_no": {
"type": "string"
},
"received_im_user_ids": {
"type": "string"
},
"received_times": {
"type": "string"
},
"received_user_amount": {
"type": "string"
},
"received_user_ids": {
"type": "string"
},
"red_packet_balance_amount": {
"type": "string"
},
"red_packet_balance_nums": {
"type": "integer"
},
"red_packet_nums": {
"type": "integer"
},
"red_packet_type": {
"type": "integer"
},
"state": {
"type": "integer"
},
"uid": {
"type": "integer"
},
"update_time": {
"type": "string"
},
"wait_draw_im_user_ids": {
"type": "string"
},
"wait_draw_user_ids": {
"type": "string"
}
}
},
"comm.AccessRecordsReq": {
"type": "object",
"properties": {
@@ -3830,7 +3766,7 @@
"description": "红包详情信息",
"allOf": [
{
"$ref": "#/definitions/code_fnuoos_com_EggPlanet_egg_models_git_src_model.ImSendRedPackageOrd"
"$ref": "#/definitions/model.ImSendRedPackageOrd"
}
]
},
@@ -4413,6 +4349,68 @@
}
}
},
"model.ImSendRedPackageOrd": {
"type": "object",
"properties": {
"amount": {
"type": "string"
},
"create_time": {
"type": "string"
},
"id": {
"type": "integer"
},
"im_data": {
"type": "string"
},
"im_uid": {
"type": "integer"
},
"ord_no": {
"type": "string"
},
"received_im_user_ids": {
"type": "string"
},
"received_times": {
"type": "string"
},
"received_user_amount": {
"type": "string"
},
"received_user_ids": {
"type": "string"
},
"red_packet_balance_amount": {
"type": "string"
},
"red_packet_balance_nums": {
"type": "integer"
},
"red_packet_nums": {
"type": "integer"
},
"red_packet_type": {
"type": "integer"
},
"state": {
"type": "integer"
},
"uid": {
"type": "integer"
},
"update_time": {
"type": "string"
},
"wait_draw_im_user_ids": {
"type": "string"
},
"wait_draw_user_ids": {
"type": "string"
}
}
},
"pb.SendRedPacketResp": {
"type": "object",
"properties": {


+ 43
- 44
docs/swagger.yaml Datei anzeigen

@@ -12,47 +12,6 @@ definitions:
description: 总数据量
type: integer
type: object
code_fnuoos_com_EggPlanet_egg_models_git_src_model.ImSendRedPackageOrd:
properties:
amount:
type: string
create_time:
type: string
id:
type: integer
im_data:
type: string
im_uid:
type: integer
ord_no:
type: string
received_im_user_ids:
type: string
received_times:
type: string
received_user_amount:
type: string
received_user_ids:
type: string
red_packet_balance_amount:
type: string
red_packet_balance_nums:
type: integer
red_packet_nums:
type: integer
red_packet_type:
type: integer
state:
type: integer
uid:
type: integer
update_time:
type: string
wait_draw_im_user_ids:
type: string
wait_draw_user_ids:
type: string
type: object
comm.AccessRecordsReq:
properties:
index:
@@ -901,7 +860,7 @@ definitions:
properties:
detail:
allOf:
- $ref: '#/definitions/code_fnuoos_com_EggPlanet_egg_models_git_src_model.ImSendRedPackageOrd'
- $ref: '#/definitions/model.ImSendRedPackageOrd'
description: 红包详情信息
list:
description: 领取红包用户列表
@@ -1302,6 +1261,47 @@ definitions:
description: 余额
type: string
type: object
model.ImSendRedPackageOrd:
properties:
amount:
type: string
create_time:
type: string
id:
type: integer
im_data:
type: string
im_uid:
type: integer
ord_no:
type: string
received_im_user_ids:
type: string
received_times:
type: string
received_user_amount:
type: string
received_user_ids:
type: string
red_packet_balance_amount:
type: string
red_packet_balance_nums:
type: integer
red_packet_nums:
type: integer
red_packet_type:
type: integer
state:
type: integer
uid:
type: integer
update_time:
type: string
wait_draw_im_user_ids:
type: string
wait_draw_user_ids:
type: string
type: object
pb.SendRedPacketResp:
properties:
seq:
@@ -2665,8 +2665,7 @@ paths:
in: body
name: req
required: true
schema:
type: object
schema: {}
produces:
- application/json
responses:


Laden…
Abbrechen
Speichern