package lottery_service import ( "hudongzhuanjia/models" "hudongzhuanjia/utils/define" "github.com/ouxuanserver/osmanthuswine/src/core" ) func GetOrderLotteryUserIds(repeat string, activityId, ruleId, ladderId, rehearsalId, areaId, archId interface{}) ([]int, error) { var err error var userIds = make([]int, 0) var recordIds = make([]int, 0) if repeat == define.MODULE_BESIDE_REPEAT { //查询已经中奖的用户,剔除已经中奖的用户 err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Select("user_id"). Where("order_draw_rule_id=? and rehearsal_id=? and arch_id=? and is_delete=0", ruleId, rehearsalId, archId).Find(&recordIds) } else { err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Select("user_id"). Where("order_draw_rule_ladder_id=? and rehearsal_id=? and arch_id=? and is_delete=0", ladderId, rehearsalId, archId).Find(&recordIds) } if err != nil { return nil, err } err = core.GetXormAuto().Table(&models.CustomerOrder{}). Select("id, buyer_id as user_id").Distinct("buyer_id"). Where("activity_id=? and rehearsal_id=? and area_id=? and arch_id=? and is_delete=0", activityId, rehearsalId, areaId, archId).NotIn("buyer_id", recordIds). Find(&userIds) if err != nil { return nil, err } return userIds, nil } type OrderWinnersResult struct { UserId int `json:"user_id"` UserName string `json:"user_name"` UserPhone string `json:"user_phone"` Avatar string `json:"avatar"` PrizeName string `json:"prize_name"` EntryPersonName string `json:"entry_person_name"` } func GetOrderWinnersResult(ruleId, rehearsalId, archId interface{}) (result []*OrderWinnersResult, err error) { err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Alias("r"). Select("r.order_entry_person_name as entry_person_name, r.user_id, u.nickname as user_name, "+ " u.phone as user_phone, u.avatar, r.prize_name").Join("LEFT", (&models.User{}).Alias("u"), "u.id=r.user_id and u.is_delete=0"). Where("r.is_delete=0 and r.order_draw_rule_id=? and r.rehearsal_id=? and r.arch_id=?", ruleId, rehearsalId, archId).Find(&result) return }