You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
255 lines
7.4 KiB
255 lines
7.4 KiB
package pc
|
|
|
|
import (
|
|
"fmt"
|
|
"hudongzhuanjia/controllers"
|
|
"hudongzhuanjia/models"
|
|
ws_send_service "hudongzhuanjia/services/ws_send"
|
|
"hudongzhuanjia/utils"
|
|
"hudongzhuanjia/utils/code"
|
|
"hudongzhuanjia/utils/define"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
//竞拍
|
|
type AuctionCtl struct {
|
|
controllers.AuthorCtl
|
|
}
|
|
|
|
// 竞拍准备状态
|
|
func (t *AuctionCtl) ReadyAuction() {
|
|
auctionId := t.MustGetInt64("auction_activity_id")
|
|
auction := new(models.NewAuctionActivity)
|
|
exist, err := models.Get(auction, auctionId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "竞拍活动不存在")
|
|
if auction.Status != define.StatusNotBegin {
|
|
t.ERROR(fmt.Sprintf("该活动%s", auction.Status), code.MSG_ERR)
|
|
}
|
|
_, err = auction.UpdateToStatusByAid(auction.ActivityId, define.StatusReady, define.StatusNotBegin)
|
|
t.CheckErr(err)
|
|
|
|
_, err = auction.UpdateStatusById(auction.Id, define.StatusReady)
|
|
t.CheckErr(err)
|
|
t.SUCCESS("success")
|
|
}
|
|
|
|
func (t *AuctionCtl) StartAuction() {
|
|
auctionId := t.MustGetInt64("auction_activity_id")
|
|
|
|
auction := new(models.NewAuctionActivity)
|
|
exist, err := models.Get(auction, auctionId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "竞拍活动不存在")
|
|
//彩排
|
|
if auction.Status != define.StatusReady {
|
|
t.ERROR(fmt.Sprintf("该活动%s", auction.Status), code.MSG_ERR)
|
|
}
|
|
auction.Status = define.StatusRunning
|
|
auction.UpdatedAt = time.Now()
|
|
duration, _ := strconv.ParseInt(auction.AuctionDuration, 10, 64)
|
|
auction.AuctionEndTime = time.Now().Unix() + duration
|
|
_, err = models.Update(auction.Id, auction, "status", "auction_end_time")
|
|
t.CheckErr(err)
|
|
|
|
t.SUCCESS("操作成功")
|
|
}
|
|
|
|
func (t *AuctionCtl) StopAuction() {
|
|
auctionId := t.MustGetInt64("auction_activity_id")
|
|
|
|
auction := new(models.NewAuctionActivity)
|
|
exist, err := models.Get(auction, auctionId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "竞拍活动不存在")
|
|
|
|
if auction.Status != define.StatusRunning {
|
|
t.ERROR(fmt.Sprintf("该活动%s", auction.Status), code.MSG_ERR)
|
|
}
|
|
auction.Status = define.StatusEnding
|
|
auction.UpdatedAt = time.Now()
|
|
auction.AuctionEndTime = 0 // 消除结束时间计时
|
|
_, err = models.Update(auction.Id, auction, "status", "auction_end_time")
|
|
t.CheckErr(err)
|
|
|
|
activity := new(models.Activity)
|
|
_, err = models.Get(activity, auction.ActivityId)
|
|
t.CheckErr(err)
|
|
|
|
// todo: 记录用户最高价
|
|
if auction.AuctionModel == define.INCR_AUCTION {
|
|
history := new(models.AuctionHistory)
|
|
_, err := history.GetHighestMoney(activity.RehearsalId, auction.Id) // 区分彩排数据
|
|
t.CheckErr(err)
|
|
|
|
user := new(models.User)
|
|
exist, err := models.Get(user, history.UserId)
|
|
t.CheckErr(err)
|
|
record := new(models.AuctionResultRecord)
|
|
if exist {
|
|
record.AuctionActivityId = auctionId
|
|
record.RehearsalId = history.RehearsalId // 彩排
|
|
record.AuctionGoodsName = auction.AuctionGoodsName
|
|
record.ActivityId = auction.ActivityId
|
|
record.UserId = history.UserId
|
|
record.UserPhone = user.Phone
|
|
record.UserName = user.Nickname
|
|
record.Unit = history.Unit
|
|
record.DealPrice = history.Money
|
|
record.PlayerCode = history.PlayerCode
|
|
record.UpdatedAt = time.Now()
|
|
record.CreatedAt = time.Now()
|
|
record.IsDelete = false
|
|
_, err = models.Add(record)
|
|
t.CheckErr(err)
|
|
}
|
|
go ws_send_service.SendAuction(fmt.Sprintf("%d", auction.ActivityId),
|
|
"", 0, map[string]interface{}{
|
|
"type": "auction",
|
|
"data": map[string]interface{}{
|
|
"auction_activity_id": auction.Id,
|
|
"activity_id": auction.ActivityId,
|
|
"max_money": history.Money,
|
|
"user_id": user.Id,
|
|
"avatar": user.Avatar,
|
|
"nickname": user.Nickname,
|
|
"num": 0,
|
|
"status": "已结束",
|
|
"model": auction.AuctionModel,
|
|
},
|
|
})
|
|
} else {
|
|
go ws_send_service.SendAuction(fmt.Sprintf("%d", auction.ActivityId),
|
|
"", 0, map[string]interface{}{
|
|
"type": "auction",
|
|
"customer_id": 0,
|
|
"user_id": 0,
|
|
"data": map[string]interface{}{
|
|
"auction_activity_id": auction.Id,
|
|
"activity_id": auction.ActivityId,
|
|
"max_money": 0,
|
|
"user_id": 0,
|
|
"avatar": "",
|
|
"nickname": "",
|
|
"num": 0,
|
|
"status": "已结束",
|
|
"model": auction.AuctionModel,
|
|
},
|
|
})
|
|
}
|
|
|
|
t.SUCCESS("操作成功")
|
|
}
|
|
|
|
// 增加数据
|
|
func (t *AuctionCtl) History() {
|
|
auctionId := t.MustGetInt64("auction_activity_id")
|
|
rehearsalId := t.MustGetInt64("rehearsal_id")
|
|
|
|
auction := new(models.NewAuctionActivity)
|
|
exist, err := models.Get(auction, auctionId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_AUCTION_NOT_EXIST, "竞拍不存在")
|
|
|
|
orderBy := "money asc"
|
|
if auction.AuctionModel == "加价竞拍" {
|
|
orderBy = "money desc"
|
|
}
|
|
|
|
histories, err := models.GetAuctionHistoriesByAuctionId(auctionId, rehearsalId, orderBy)
|
|
t.CheckErr(err)
|
|
|
|
userIdMap := make(map[int64]struct{}, 0) // 去重操作
|
|
for u := range histories {
|
|
if _, ok := userIdMap[histories[u].UserId]; ok {
|
|
//去掉重复的
|
|
continue
|
|
} else {
|
|
userIdMap[histories[u].UserId] = struct{}{} // 增加,下次进行检测
|
|
}
|
|
auction.Histories = append(auction.Histories, histories[u])
|
|
}
|
|
|
|
t.JSON(map[string]interface{}{
|
|
"auction": auction,
|
|
})
|
|
}
|
|
|
|
func (t *AuctionCtl) List() {
|
|
activityId := t.MustGetInt64("activity_id")
|
|
rehearsalId := t.MustGetInt64("rehearsal_id")
|
|
|
|
auctions, err := models.GetAuctionsByActivityId(activityId, "created_at asc")
|
|
t.CheckErr(err)
|
|
// 更具某个数据进行
|
|
upIds := make([]int64, 0)
|
|
for _, item := range auctions {
|
|
if item.AuctionModel == "加价竞拍" {
|
|
upIds = append(upIds, item.Id)
|
|
}
|
|
}
|
|
upH, err := models.GetAuctionHistoriesByAuctionIds(upIds, rehearsalId, "money desc")
|
|
t.CheckErr(err)
|
|
|
|
for i := range auctions {
|
|
if auctions[i].AuctionModel == define.INCR_AUCTION {
|
|
userIdMap := make(map[int64]struct{}, 0) // 去重操作
|
|
for u := range upH {
|
|
if _, ok := userIdMap[upH[u].UserId]; ok {
|
|
//去掉重复的
|
|
continue
|
|
}
|
|
|
|
if auctions[i].Id == upH[u].AuctionActivityId && len(auctions[i].Histories) <= 3 {
|
|
auctions[i].Histories = append(auctions[i].Histories, upH[u])
|
|
userIdMap[upH[u].UserId] = struct{}{} // 增加,下次进行检测
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
t.JSON(map[string]interface{}{
|
|
"total": len(auctions),
|
|
"list": auctions,
|
|
})
|
|
}
|
|
|
|
// 成交记录
|
|
func (t *AuctionCtl) Records() {
|
|
rehearsalId := t.MustGetInt64("rehearsal_id") // 彩排
|
|
auctionId := t.MustGetInt64("auction_activity_id")
|
|
|
|
records, err := models.GetAuctionRecordsByAuctionId(auctionId, rehearsalId, "created_at desc")
|
|
t.CheckErr(err)
|
|
t.JSON(map[string]interface{}{
|
|
"records": records,
|
|
"total": len(records),
|
|
})
|
|
}
|
|
|
|
//获取二维码
|
|
func (t *AuctionCtl) Qrcode() {
|
|
//将服务器得地址和activity_id,动态生成二维码
|
|
uid := t.MustGetUID()
|
|
activityId := t.MustGetInt64("activity_id")
|
|
auctionId := t.MustGetInt64("auction_activity_id")
|
|
rehearsalId := t.MustGetInt("rehearsal_id")
|
|
|
|
area := new(models.AreaStore)
|
|
exist, err := area.GetByCustomerId(uid, activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
|
|
|
|
qrcode, err := utils.GenH5Qrcode(define.H5Auction, map[string]interface{}{
|
|
"activity_id": activityId,
|
|
"area_id": area.Id,
|
|
"customer_id": uid,
|
|
"auction_id": auctionId,
|
|
"rehearsal_id": rehearsalId,
|
|
})
|
|
t.CheckErr(err)
|
|
t.JSON(map[string]interface{}{
|
|
"qrcode": qrcode,
|
|
})
|
|
}
|