|
|
package pc
import ( "fmt" "github.com/ouxuanserver/osmanthuswine/src/core" "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.GetById(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") }
//开始竞拍
// auction doc
// @Summary auction
// @Description 开始竞拍
// @Tags pc
// @Accept json
// @Produce json
// @Param auction_activity_id query int true "竞拍id"
// @Success 200 {string} string "success"
// @Router /Pc/AuctionCtl/startAuction [get]
func (t *AuctionCtl) StartAuction() { auctionId := t.MustGetInt64("auction_activity_id")
auction := new(models.NewAuctionActivity) exist, err := models.GetById(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 = core.GetXormAuto().Where("is_delete=0 and id=?", auctionId). Cols("status", "auction_end_time", "updated_at").Update(auction) t.CheckErr(err)
t.STRING("操作成功") }
//停止竞拍
// auction doc
// @Summary auction
// @Description 结束竞拍
// @Tags pc
// @Accept json
// @Produce json
// @Param auction_activity_id query int true "竞拍id"
// @Success 200 {string} string "success"
// @Router /Pc/AuctionCtl/stopAuction [get]
func (t *AuctionCtl) StopAuction() { auctionId := t.MustGetInt64("auction_activity_id") rehearsalId := t.MustGetInt64("rehearsal_id") auction := new(models.NewAuctionActivity) exist, err := models.GetById(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 = core.GetXormAuto().Where("is_delete=0 and id=?", auctionId). Cols("status", "auction_end_time", "updated_at").Update(auction) t.CheckErr(err)
// todo: 记录用户最高价
if auction.AuctionModel == define.INCR_AUCTION { history := new(models.AuctionHistory) _, err := history.GetHighestMoney(rehearsalId, auction.Id) // 区分彩排数据
t.CheckErr(err)
user := new(models.User) exist, err := models.GetById(user, history.UserId) t.CheckErr(err) if exist { record := new(models.AuctionResultRecord) record.AuctionActivityId = auctionId record.RehearsalId = 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
go ws_send_service.SendAuction(fmt.Sprintf("%d", record.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, }, }) _, err = core.GetXormAuto().InsertOne(record) t.CheckErr(err) } } 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.STRING("操作成功") }
// 增加数据
func (t *AuctionCtl) History() { auctionId := t.MustGetInt64("auction_activity_id") rehearsalId := t.MustGetInt64("rehearsal_id")
auction := new(models.NewAuctionActivity) exist, err := models.GetById(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 == "加价竞拍" { 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,动态生成二维码
qrcode, err := utils.GenH5Qrcode(define.H5Auction, map[string]interface{}{ "activity_id": t.MustGetInt64("activity_id"), "customer_id": t.MustGetUID(), "auction_id": t.MustGetInt64("auction_activity_id"), "rehearsal_id": t.MustGetInt64("rehearsal_id"), }) t.CheckErr(err) t.JSON(map[string]interface{}{ "qrcode": qrcode, }) }
|