|
|
package activity_service
import ( "fmt" "github.com/ouxuanserver/osmanthuswine/src/core" "hudongzhuanjia/models" "hudongzhuanjia/utils/define" )
func GetActivitiesByCustomerId(cid int64) ([]*models.Activity, error) { // 登陆限制
// 获取用户拥有的activity
activities := make([]*models.Activity, 0) err := core.GetXormAuto().Where("is_delete=0 and customer_id=?", cid). Desc("created_at").Find(&activities) if err != nil { return nil, err } // customer -> activity -> activity module service -> module service history -> module service
// customer -> activity -> 某次具体的活动(已经启动了的)
aids := make([]int64, 0) for _, activity := range activities { aids = append(aids, activity.Id) }
areaStores := make([]*models.AreaStore, 0) err = core.GetXormAuto().Where("is_delete=0").In("activity_id", aids).Find(&areaStores) if err != nil { return nil, err }
for j := range activities { for i := range areaStores { if areaStores[i].ActivityId == activities[j].Id { activities[j].AreaStores = append(activities[j].AreaStores, areaStores[i]) } } }
services := make([]*models.ActivityModuleService, 0) err = core.GetXormAuto().Where("is_delete=0 and service_module_status=?", "开启"). In("activity_id", aids).Find(&services) if err != nil { return nil, err }
hids := make([]int64, 0) for _, service := range services { hids = append(hids, service.ServiceModuleHistoryId) }
histories := make([]*models.ModuleServiceHistory, 0) err = core.GetXormAuto().Where("is_delete=0").In("id", hids).Find(&histories) if err != nil { return nil, err }
for j := range services { for i := range histories { if histories[i].Id == services[j].ServiceModuleHistoryId { services[j].ServiceModuleName = histories[i].Name break } } }
for j := range activities { for i := range services { if activities[j].Id == services[i].ActivityId { activities[j].Services = append(activities[j].Services, services[i]) } } } return activities, nil }
func GetActivityById(id int64) (*models.Activity, bool, error) { activity := new(models.Activity) exist, err := models.Get(activity, id) if err != nil || !exist { return nil, exist, err } services := make([]*models.ActivityModuleService, 0) err = core.GetXormAuto().Where("is_delete=0 and activity_id=? and service_module_status=?", id, define.StatusOpen). Find(&services) if err != nil { return nil, false, err }
hids := make([]int64, 0) for _, service := range services { hids = append(hids, service.ServiceModuleHistoryId) } histories := make([]*models.ModuleServiceHistory, 0) err = core.GetXormAuto().Where("is_delete=0").In("id", hids).Find(&histories) if err != nil { return nil, false, err }
for j := range services { for i := range histories { if histories[i].Id == services[j].ServiceModuleHistoryId { services[j].ServiceModuleName = histories[i].Name break } } } activity.Services = services
// 增加对上墙 霸屏 弹幕 打赏
mServer := new(models.MsgWallServer) exist, err = mServer.GetByActivityId(id) if err != nil { return nil, false, err } if !exist { activity.UpperWallStatus = define.StatusClose } else { activity.UpperWallStatus = mServer.UpWallStatus }
rServer := new(models.RewardServer) exist, err = rServer.GetByActivityId(id) if err != nil { return nil, false, err } if !exist { activity.RewardStatus = define.StatusClose } else { activity.RewardStatus = rServer.ServerStart }
dServer := new(models.DanMuServer) exist, err = dServer.GetByActivityId(id) if err != nil { return nil, false, err } if !exist { activity.BarrageStatus = define.StatusClose } else { activity.BarrageStatus = dServer.DanmuSwitch }
bServer := new(models.BullyScreenServer) exist, err = bServer.GetByActivityId(id) if err != nil { return nil, false, err } if !exist { activity.BullyScreenStatus = define.StatusClose } else { activity.BullyScreenStatus = bServer.Start } return activity, true, nil }
func ExistModuleByActivityId(aid int64, module string) (bool, error) { switch module { case define.MODULE_TUGWAR: // 拔河
bahe := new(models.TugOfWar) return bahe.GetCurrent(aid) case define.MODULE_ORDER: //下订单
option := new(models.CustomerOrderOption) return option.GetOpen(aid) case define.MODULE_SHAKRB: //摇红包
rule := new(models.ShakeRedEnvelopeRule) return rule.GetCurrent(aid) case define.MODULE_AUCTION: // 竞拍
auction := new(models.NewAuctionActivity) return auction.GetCurrent(aid) case define.MODULE_VOTE: vote := new(models.NewVoteActivity) return vote.GetCurrent(aid) case define.MODULE_CALORIE: calorie := new(models.Calorie) return calorie.GetCurrent(aid) case define.MODULE_BARRAGE: fallthrough case define.MODULE_BULLYS: fallthrough case define.MODULE_REWARD: fallthrough case define.MODULE_UPPERW: return true, nil
default: return false, fmt.Errorf("不存在该活动模块") } }
|