|
|
@@ -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 |
|
|
|
} |