|
|
@ -1,24 +1,76 @@ |
|
|
|
package client |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"github.com/ouxuanserver/osmanthuswine/src/core" |
|
|
|
"hudongzhuanjia/controllers" |
|
|
|
"hudongzhuanjia/libs/filter" |
|
|
|
"hudongzhuanjia/libs/im" |
|
|
|
"hudongzhuanjia/models" |
|
|
|
pay_service "hudongzhuanjia/services/pay" |
|
|
|
red_envelope_service "hudongzhuanjia/services/red_envelope" |
|
|
|
"hudongzhuanjia/utils" |
|
|
|
"hudongzhuanjia/utils/code" |
|
|
|
"hudongzhuanjia/utils/define" |
|
|
|
"sync" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
type NoticeRedPackEvent struct { |
|
|
|
OutTradeNo string `json:"out_trade_no"` |
|
|
|
Prompt string `json:"prompt"` |
|
|
|
RedPackInfoId int64 `json:"red_pack_info_id"` |
|
|
|
ActivityId int64 `json:"activity_id"` |
|
|
|
Status int `json:"status"` |
|
|
|
// 轮询接口
|
|
|
|
func init() { |
|
|
|
go utils.HandleTicker(10*time.Second, QueryOnline) |
|
|
|
} |
|
|
|
|
|
|
|
func QueryOnline() error { |
|
|
|
lives, err := models.GetLiveConfigByStatus(2) // 进行中的直播
|
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
liveIds := make([]int64, 0) |
|
|
|
for _, live := range lives { // 查询在线人数
|
|
|
|
liveIds = append(liveIds, live.Id) |
|
|
|
} |
|
|
|
viewers, err := models.GetLiveViewerByLiveConfigIds(liveIds) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
var idm = make(map[int64][]string, 0) |
|
|
|
for _, live := range lives { |
|
|
|
for _, viewer := range viewers { |
|
|
|
if live.Id == viewer.LiveConfigId { |
|
|
|
if _, ok := idm[live.Id]; !ok { |
|
|
|
idm[live.Id] = make([]string, 0) |
|
|
|
} |
|
|
|
idm[live.Id] = append(idm[live.Id], fmt.Sprint(viewer.UserId)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
var wg sync.WaitGroup |
|
|
|
wg.Add(len(idm)) |
|
|
|
var errs []error |
|
|
|
for lid, ids := range idm { |
|
|
|
go func(int64, []string) { |
|
|
|
defer func() { recover() }() |
|
|
|
defer wg.Done() |
|
|
|
res, err := im.QueryState(ids) |
|
|
|
if err != nil { |
|
|
|
errs = append(errs, err) |
|
|
|
} |
|
|
|
var count int |
|
|
|
for _, item := range res.QueryResult { |
|
|
|
if item.Status != "Offline" { |
|
|
|
count++ |
|
|
|
} |
|
|
|
} |
|
|
|
_, err = models.Update(lid, &models.LiveConfig{WatchNum: count}, "watch_num") |
|
|
|
if err != nil { |
|
|
|
errs = append(errs, err) |
|
|
|
} |
|
|
|
}(lid, ids) |
|
|
|
} |
|
|
|
wg.Wait() |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
type LiveCtl struct { |
|
|
@ -31,13 +83,17 @@ func (t *LiveCtl) Detail() { |
|
|
|
areaId := t.MustGetInt64("area_id") |
|
|
|
userId := t.MustGetUID() |
|
|
|
|
|
|
|
err := new(models.LiveViewer).Record(userId, activityId) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
live := new(models.LiveConfig) |
|
|
|
exist, err := live.GetByActivityId(activityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_LIVE_CONFIG_NOT_EXIST, "直播活动不存在") |
|
|
|
if live.WatchNum+1 >= live.Limit { |
|
|
|
t.ERROR("直播人数已满", code.MSG_LIVE_LIMIT_ENOUGH) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
err = new(models.LiveViewer).Record(userId, activityId, live.Id) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
fs := make(map[string]int, 0) |
|
|
|
fs["is_shake"] = 0 |
|
|
@ -203,3 +259,5 @@ func (t *LiveCtl) GetLiveRedPack() { |
|
|
|
models.Update(record.Id, record, "mch_billno", "is_draw") |
|
|
|
t.JSON(record) |
|
|
|
} |
|
|
|
|
|
|
|
// 订单
|