From 064b3973f93761af11c2519f6bd38f55b9edb506 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Tue, 26 Nov 2024 15:05:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/md/im/md_send_red_package_ord.go | 49 +++++++++ app/svc/im/svc_customer_service.go | 2 +- app/svc/im/svc_emoticon.go | 2 +- app/svc/im/svc_send_red_package_ord.go | 134 +++++++++++++++++++++++++ 4 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 app/md/im/md_send_red_package_ord.go create mode 100644 app/svc/im/svc_send_red_package_ord.go diff --git a/app/md/im/md_send_red_package_ord.go b/app/md/im/md_send_red_package_ord.go new file mode 100644 index 0000000..ea9c729 --- /dev/null +++ b/app/md/im/md_send_red_package_ord.go @@ -0,0 +1,49 @@ +package md + +type PageSendRedPackageOrdReq struct { + Page int `json:"page"` + PageSize int `json:"page_size"` + State int `json:"state"` //状态 + Uid int `json:"uid"` + RedPacketType int `json:"red_packet_type"` //红包类型 + StartTimeStart string `json:"start_time_start" example:"发送时间-起始"` + StartTimeEnd string `json:"start_time_end" example:"发送时间-截止"` + InviteCode string `json:"invite_code" example:"邀请码"` //邀请码 + Phone string `json:"phone" example:"手机号"` //手机号 + Nickname string `json:"nickname" example:"昵称"` //昵称 + OrdNo string `json:"ord_no" example:"订单号"` //订单号 +} + +type PageSendRedPackageOrdResp struct { + Page int `json:"page"` + PageSize int `json:"page_size"` + Total int64 `json:"total"` + List []struct { + Id int64 `json:"id"` //记录id + Uid int64 `json:"uid"` + Phone string `json:"ord_no" example:"订单号"` + Nickname string `json:"nickname" example:"昵称"` + AvatarUrl string `json:"avatar_url" example:"头像"` + InviteCode string `json:"invite_code" example:"邀请码"` + State int `json:"state"` // 红包状态(0:未领取 1:领取中 2:领取完 3:已过期) + Amount string `json:"amount"` // 金额 + RedPacketBalanceAmount string `json:"red_packet_balance_amount" example:"红包剩余金额"` // 红包剩余金额 + RedPacketType int `json:"red_packet_type" example:"红包类型"` // 红包类型 + RedPacketNums string `json:"red_packet_nums" example:"红包剩余个数"` // 红包剩余个数 + WaitDrawUserIds string `json:"wait_draw_user_ids" example:"待领取用户id"` // 待领取用户id + ReceivedUserIds string `json:"received_user_ids" example:"领取用户id"` // 领取用户id + ReceivedTimes string `json:"received_times" example:"已领取时间"` // 已领取时间 + ReceivedUserAmount string `json:"received_user_amount" example:"已领取用户金额"` // 已领取用户金额 + CreateTime string `json:"create_time" example:"创建时间"` // 创建时间 + UpdateTime string `json:"update_time" example:"更新时间"` // 更新时间 + } `json:"list"` +} + +type RedPackageRecordsDetailResp struct { + Uid int64 `json:"uid"` + InviteCode string `json:"invite_code" example:"邀请码"` + Nickname string `json:"nickname" example:"昵称"` + AvatarUrl string `json:"avatar_url" example:"头像"` + Amount string `json:"amount"` // 金额 + ReceivedTimes string `json:"received_times" example:"领取时间"` // 领取时间 +} diff --git a/app/svc/im/svc_customer_service.go b/app/svc/im/svc_customer_service.go index 8627c14..d77238b 100644 --- a/app/svc/im/svc_customer_service.go +++ b/app/svc/im/svc_customer_service.go @@ -17,7 +17,7 @@ func PageCustomerService(req md.PageCustomerServiceReq) (err error, resp md.Page sess.And("memo = ?", req.State) } var mm []*model.CustomerService - resp.Total, err = sess.Limit(req.PageSize, (req.Page-1)*req.PageSize).Asc("a.id").FindAndCount(&mm) + resp.Total, err = sess.Limit(req.PageSize, (req.Page-1)*req.PageSize).Asc("id").FindAndCount(&mm) if err != nil { return } diff --git a/app/svc/im/svc_emoticon.go b/app/svc/im/svc_emoticon.go index a8e57f5..be75191 100644 --- a/app/svc/im/svc_emoticon.go +++ b/app/svc/im/svc_emoticon.go @@ -17,7 +17,7 @@ func PageEmoticon(req md.PageEmoticonReq) (err error, resp md.PageEmoticonResp) sess.And("memo = ?", req.State) } var mm []*model.Emoticon - resp.Total, err = sess.Limit(req.PageSize, (req.Page-1)*req.PageSize).Asc("a.id").FindAndCount(&mm) + resp.Total, err = sess.Limit(req.PageSize, (req.Page-1)*req.PageSize).Desc("id").FindAndCount(&mm) if err != nil { return } diff --git a/app/svc/im/svc_send_red_package_ord.go b/app/svc/im/svc_send_red_package_ord.go new file mode 100644 index 0000000..252516c --- /dev/null +++ b/app/svc/im/svc_send_red_package_ord.go @@ -0,0 +1,134 @@ +package svc + +import ( + "applet/app/db" + md "applet/app/md/im" + "applet/app/utils" + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + "errors" + "fmt" + "strings" +) + +type PageSendRedPackageOrdJoinUser struct { + model.ImSendRedPackageOrd `xorm:"extends"` + model.User `xorm:"extends"` +} + +func PageSendRedPackageOrd(req md.PageSendRedPackageOrdReq) (err error, resp md.PageSendRedPackageOrdResp) { + sess := db.DbIm.Table("im_send_red_package_ord").Where("1=1") + if req.Phone != "" { + sess.And("user.phone LIKE ?", "%"+req.Phone+"%") + } + if req.Nickname != "" { + sess.And("user.nickname LIKE ?", "%"+req.Nickname+"%") + } + if req.OrdNo != "" { + sess.And("im_send_red_package_ord.ord_no LIKE ?", "%"+req.OrdNo+"%") + } + if req.State != 0 { + sess.And("im_send_red_package_ord.state = ?", req.State) + } + if req.Uid != 0 { + sess.And("im_send_red_package_ord.uid = ?", req.Uid) + } + if req.RedPacketType != 0 { + sess.And("im_send_red_package_ord.red_packet_type = ?", req.RedPacketType) + } + if req.StartTimeStart != "" { + sess.And("im_send_red_package_ord.create_time >= ?", req.StartTimeStart) + } + if req.StartTimeEnd != "" { + sess.And("im_send_red_package_ord.create_time <= ?", req.StartTimeEnd) + } + if req.InviteCode != "" { + sess.And("user.invite_code = ?", req.InviteCode) + } + sess.Join("LEFT", "user", "im_send_red_package_ord.uid = user.id") + + var mm []*PageSendRedPackageOrdJoinUser + resp.Total, err = sess.Limit(req.PageSize, (req.Page-1)*req.PageSize).Desc("im_send_red_package_ord.create_time").FindAndCount(&mm) + sql, _ := sess.LastSQL() + fmt.Println("PageSendRedPackageOrd___SQL:::", sql) + if err != nil { + return + } + resp.Page = req.Page + resp.PageSize = req.PageSize + for _, v := range mm { + resp.List = append(resp.List, struct { + Id int64 `json:"id"` //记录id + Uid int64 `json:"uid"` + Phone string `json:"ord_no" example:"订单号"` + Nickname string `json:"nickname" example:"昵称"` + AvatarUrl string `json:"avatar_url" example:"头像"` + InviteCode string `json:"invite_code" example:"邀请码"` + State int `json:"state"` // 红包状态(0:未领取 1:领取中 2:领取完 3:已过期) + Amount string `json:"amount"` // 金额 + RedPacketBalanceAmount string `json:"red_packet_balance_amount" example:"红包剩余金额"` // 红包剩余金额 + RedPacketType int `json:"red_packet_type" example:"红包类型"` // 红包类型 + RedPacketNums string `json:"red_packet_nums" example:"红包剩余个数"` // 红包剩余个数 + WaitDrawUserIds string `json:"wait_draw_user_ids" example:"待领取用户id"` // 待领取用户id + ReceivedUserIds string `json:"received_user_ids" example:"领取用户id"` // 领取用户id + ReceivedTimes string `json:"received_times" example:"已领取时间"` // 已领取时间 + ReceivedUserAmount string `json:"received_user_amount" example:"已领取用户金额"` // 已领取用户金额 + CreateTime string `json:"create_time" example:"创建时间"` // 创建时间 + UpdateTime string `json:"update_time" example:"更新时间"` // 更新时间 + }{ + Id: v.ImSendRedPackageOrd.Id, + Uid: int64(v.ImSendRedPackageOrd.Uid), + Phone: v.User.Phone, + InviteCode: v.User.SystemInviteCode, + Nickname: v.User.Nickname, + AvatarUrl: v.User.Avatar, + State: v.ImSendRedPackageOrd.State, + Amount: v.ImSendRedPackageOrd.Amount, + RedPacketType: v.ImSendRedPackageOrd.RedPacketType, + WaitDrawUserIds: v.ImSendRedPackageOrd.WaitDrawUserIds, + ReceivedUserIds: v.ImSendRedPackageOrd.ReceivedUserIds, + ReceivedUserAmount: v.ImSendRedPackageOrd.ReceivedUserAmount, + CreateTime: v.ImSendRedPackageOrd.CreateTime, + UpdateTime: v.ImSendRedPackageOrd.UpdateTime, + }) + } + return +} + +func RedPackageRecordsDetail(redPackageId string) (err error, resp []md.RedPackageRecordsDetailResp) { + var imSendRedPackageOrd model.ImSendRedPackageOrd + has, err := db.Db.Where("`id`=?", redPackageId).Get(&imSendRedPackageOrd) + if err != nil { + return + } + if !has { + err = errors.New("红包记录不存在!") + return + } + + if imSendRedPackageOrd.ReceivedUserIds != "" { + uids := strings.Split(imSendRedPackageOrd.ReceivedUserIds, ",") + receivedTimes := strings.Split(imSendRedPackageOrd.ReceivedTimes, ",") + receivedUserAmount := strings.Split(imSendRedPackageOrd.ReceivedUserAmount, ",") + var users []*model.User + err = db.Db.In("id", uids).Find(&users) + if err != nil { + return + } + var usersMap = map[string]model.User{} + for _, v := range users { + usersMap[utils.Int64ToStr(v.Id)] = *v + } + for i, v := range uids { + resp = append(resp, md.RedPackageRecordsDetailResp{ + Uid: utils.StrToInt64(v), + InviteCode: usersMap[v].SystemInviteCode, + Nickname: usersMap[v].Nickname, + AvatarUrl: usersMap[v].Avatar, + Amount: receivedUserAmount[i], + ReceivedTimes: receivedTimes[i], + }) + } + } + + return +}