package services import ( "errors" "fmt" "hongze/hongze_web_mfyx/models" "hongze/hongze_web_mfyx/models/order" "hongze/hongze_web_mfyx/utils" "time" ) // 获取日卡、月卡商品配置信息 func GetUserGoodsCardList() (goodsListResp []*order.CygxGoodsResp) { var err error defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg(fmt.Sprint("获取日卡、月卡商品配置信息失败 GetUserGoodsCardList, err:", err.Error()), 2) } }() var condition string var pars []interface{} condition = ` AND goods_id IN (1,2) ` goodsList, e := order.GetCygxGoodsList(condition, pars) if e != nil { err = errors.New("GetCygxGoodsList, Err: " + e.Error()) return } goodsListResp = goodsList return } // 获取单场活动关联的商品配置信息 func GetGoodsInfoByActivity(item *models.ActivityDetail) (goodsListResp []*order.CygxGoodsResp) { var err error defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg(fmt.Sprint("获取单场活动关联的商品配置信息失败 GetGoodsInfoByActivity, err:", err.Error()), 2) } }() if item.IsResearchPoints { //获取活动对用户要扣的点 userPointsNum, e := models.GetCygxActivityPointsSetUserNum(item.ActivityId) if e != nil { err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error()) return } if userPointsNum > 0 { item.IsResearchPointsByUser = true } } var condition string var pars []interface{} if item.ActivityTypeId == 1 && item.IsLimitPeople == 1 { //专家电话会。限制人数, condition = ` AND goods_id IN (3) ` } else if (item.ActivityTypeId == 5 || item.ActivityTypeId == 8) && item.IsResearchPointsByUser { //买方线下交流/专家线下沙龙。参会人扣点, condition = ` AND goods_id IN (4) ` } else if (item.ActivityTypeId == 5 || item.ActivityTypeId == 8) && !item.IsResearchPointsByUser { //买方线下交流/专家线下沙龙。参会人扣点, condition = ` AND goods_id IN (5) ` } else if item.ActivityTypeId == 3 && item.IsResearchPointsByUser { //非易董。公司调研电话会参会人扣点 condition = ` AND goods_id IN (6) ` } else if item.ActivityTypeId == 3 && !item.IsResearchPointsByUser { //非易董。公司调研电话会参会人扣点 condition = ` AND goods_id IN (7) ` } else if item.ActivityTypeId == 1 && item.IsResearchPointsByUser { //专家电话会,不限制人数,研选扣点(1299元) condition = ` AND goods_id IN (8) ` } goodsList, e := order.GetCygxGoodsList(condition, pars) if e != nil { err = errors.New("GetCygxGoodsList, Err: " + e.Error()) return } //如果活动有自定义的价格就优先按照自定义的价格来 if item.ActivityPrice > 0 { for k, _ := range goodsList { goodsList[k].CurrentPrice = fmt.Sprint(item.ActivityPrice) goodsList[k].Price = fmt.Sprint(item.ActivityOriginalPrice) goodsList[k].PopupPriceMsg = fmt.Sprint("¥", item.ActivityOriginalPrice) } } goodsListResp = goodsList return } // 获取单场活动音视频关联的商品配置信息 func GetGoodsInfoByActivityVivo(item *models.ActivityDetail) (goodsListResp []*order.CygxGoodsResp) { var err error defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg(fmt.Sprint("获取单场活动关联的商品配置信息失败 GetGoodsInfoByActivity, err:", err.Error()), 2) } }() activityId := item.ActivityId total, e := models.GetCygxActivityVivoPointsSetCountByActivityId(activityId) if e != nil { err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error()) return } if total == 0 { goodsListResp = make([]*order.CygxGoodsResp, 0) return } vivoPointsSetDetail, e := models.GetCygxActivityVivoPointsSetByActivityId(activityId) if e != nil { err = errors.New("GetCygxActivityVivoPointsSetCountByActivityId, Err: " + e.Error()) return } var condition string var pars []interface{} condition = ` AND goods_id IN (9) ` goodsList, e := order.GetCygxGoodsList(condition, pars) if e != nil { err = errors.New("GetCygxGoodsList, Err: " + e.Error()) return } for k, _ := range goodsList { goodsList[k].CurrentPrice = fmt.Sprint(vivoPointsSetDetail.GoodsMoney) goodsList[k].Price = fmt.Sprint(vivoPointsSetDetail.GoodsMoney) goodsList[k].PopupPriceMsg = fmt.Sprint("¥", vivoPointsSetDetail.GoodsMoney) } goodsListResp = goodsList return } func GetActivityVivoPoints(item *models.ActivityDetail, wxUser *models.WxUserItem, havePower bool) (vivoPointsResp models.VivoPointsResp) { if wxUser.UserId == 0 { return } var err error defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg(fmt.Sprint("获取单场活动关联的商品配置信息失败 GetGoodsInfoByActivity, err:", err.Error()), 2) } }() activityId := item.ActivityId total, e := models.GetCygxActivityVivoPointsSetCountByActivityId(activityId) if e != nil { err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error()) return } if total == 0 { //如果没有设置就直接播放 vivoPointsResp.HavePoint = true return } totalMySuccess, e := models.GetActivitySignupCount(wxUser.UserId, activityId) if e != nil { err = errors.New("GetActivitySignupCount, Err: " + e.Error()) return } totalPayVivo, e := order.GetCygxOrderVirtualAssetdCountByVivo(activityId, wxUser.UserId) if e != nil { err = errors.New("GetCygxOrderVirtualAssetdCountByVivo, Err: " + e.Error()) return } totalPointRecord, e := models.GetCygxActivityVivoPointRecordCount(activityId, wxUser.UserId) if e != nil { err = errors.New("GetCygxActivityVivoPointRecordCount, Err: " + e.Error()) return } //如果报了名,或者付费了,或者单独扣点了;就直接观看 if totalMySuccess > 0 || totalPayVivo > 0 || totalPointRecord > 0 { vivoPointsResp.HavePoint = true } vivoPointsSetDetail, e := models.GetCygxActivityVivoPointsSetByActivityId(activityId) if e != nil { err = errors.New("GetCygxActivityVivoPointsSetCountByActivityId, Err: " + e.Error()) return } vivoPointsResp.ActivityPoints = fmt.Sprint(vivoPointsSetDetail.PointsNum) // 获取用户所在公司剩余的点 companyPointsNum, e := models.GetCompanyPoints(wxUser.CompanyId) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetCompanyPoints, Err: " + e.Error()) return } vivoPointsResp.CompanyPoints = fmt.Sprint(companyPointsNum) havePowerYx, e := GetArticleDetailUserPower(wxUser) if e != nil { err = errors.New("GetArticleDetailUserPower, Err: " + e.Error()) return } if havePower || havePowerYx { if vivoPointsSetDetail.PointsNum == 0 { //有权限情况下,点数为零的时候直接播放 vivoPointsResp.HavePoint = true } if companyPointsNum > 0 { if companyPointsNum >= vivoPointsSetDetail.PointsNum { vivoPointsResp.PointPermission = 1 } else { vivoPointsResp.PointPermission = 2 } } else { //客户剩余点数为0的情况下,直接支付 vivoPointsResp.PointPermission = 3 } } else { if vivoPointsSetDetail.GoodsMoney > 0 { vivoPointsResp.PointPermission = 3 } } return } // 获取用户十分钟之内是否有相同的订单信息 func GetHaverEquallyOrderByUser10Min(userId, goodsId int) (orderCode string) { var err error defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10Min, err:", err.Error()), 2) } }() var condition string var pars []interface{} endTime := time.Now().Add(-10 * time.Minute) condition = ` AND order_status = 1 AND user_id = ? AND goods_id = ? AND create_time > ? ORDER BY order_id DESC ` pars = append(pars, userId, goodsId, endTime) orderList, e := order.GetCygxOrderList(condition, pars, 0, 1) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetCygxOrderList, Err: " + e.Error()) return } if len(orderList) == 0 { return } else { for _, v := range orderList { orderCode = v.OrderCode } } return } // 获取用户十分钟之内是否有相同的订单信息 func GetHaverEquallyOrderByUser10MinByActivty(userId, sourceId int) (orderCode string, seconds int) { var err error defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10MinByActivty, err:", err.Error()), 2) } }() var condition string var pars []interface{} endTime := time.Now().Add(-10 * time.Minute) condition = ` AND order_status = 1 AND source = 'activity' AND user_id = ? AND source_id = ? AND create_time > ? AND register_platform = ? ORDER BY order_id DESC ` pars = append(pars, userId, sourceId, endTime, utils.REGISTER_PLATFORM) orderList, e := order.GetCygxOrderList(condition, pars, 0, 1) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetCygxOrderList, Err: " + e.Error()) return } if len(orderList) == 0 { return } else { for _, v := range orderList { orderCode = v.OrderCode duration := time.Now().Sub(v.CreateTime) // 将时间差转换为秒数 seconds = 600 - int(duration.Seconds()) } } return } // 获取用户十分钟之内是否有相同的订单信息 func GetHaverEquallyOrderByUser10MinByActivtyVivo(userId, sourceId int) (orderCode string, seconds int) { var err error defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10MinByActivty, err:", err.Error()), 2) } }() var condition string var pars []interface{} endTime := time.Now().Add(-10 * time.Minute) condition = ` AND order_status = 1 AND source IN ( 'activityvideo', 'activityvoice') AND user_id = ? AND source_id = ? AND create_time > ? AND register_platform = ? ORDER BY order_id DESC ` pars = append(pars, userId, sourceId, endTime, utils.REGISTER_PLATFORM) orderList, e := order.GetCygxOrderList(condition, pars, 0, 1) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetCygxOrderList, Err: " + e.Error()) return } if len(orderList) == 0 { return } else { for _, v := range orderList { orderCode = v.OrderCode duration := time.Now().Sub(v.CreateTime) // 将时间差转换为秒数 seconds = 600 - int(duration.Seconds()) } } return } // 获取用户十分钟之内是否有相同的文章订单信息 func GetHaverEquallyOrderByUser10MinByArticle(userId, sourceId, goodsId int) (orderCode string, seconds int) { var err error defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的文章订单信息失败 GetHaverEquallyOrderByUser10MinByArticle, err:", err.Error()), 2) } }() var condition string var pars []interface{} endTime := time.Now().Add(-10 * time.Minute) condition = ` AND order_status = 1 AND user_id = ? AND source_id = ? AND goods_id = ? AND create_time > ? AND register_platform = ? ORDER BY order_id DESC ` pars = append(pars, userId, sourceId, goodsId, endTime, utils.REGISTER_PLATFORM) orderList, e := order.GetCygxOrderList(condition, pars, 0, 1) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetCygxOrderList, Err: " + e.Error()) return } if len(orderList) == 0 { return } else { for _, v := range orderList { orderCode = v.OrderCode duration := time.Now().Sub(v.CreateTime) // 将时间差转换为秒数 seconds = 600 - int(duration.Seconds()) } } return } // GetActivityOrderListLabelKeyword 根据活动ID获取活动自定义类型 func GetActivityOrderListLabelKeywordByActivityIds(activityIds []int) (mapResp map[int]string) { lenArr := len(activityIds) if lenArr == 0 { return } var err error defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg("GetActivityOrderListLabelKeywordByActivityIds,根据活动ID获取活动自定义类型 失败Err:"+err.Error(), 2) } }() var condition string var pars []interface{} //获取所有研选类型的活动 condition += ` AND activity_id IN (` + utils.GetOrmInReplace(lenArr) + `) ` pars = append(pars, activityIds) listActivity, e := models.GetActivityListByCondition(condition, pars) if e != nil { err = errors.New("GetActivityListByCondition, Err: " + e.Error()) return } mapResp = make(map[int]string, 0) for _, v := range listActivity { switch v.ActivityTypeId { case 1: mapResp[v.ActivityId] = "专家访谈" case 5: mapResp[v.ActivityId] = "专家访谈" case 3: mapResp[v.ActivityId] = "上市公司小范围" case 8: mapResp[v.ActivityId] = "买方交流" } } return } // 获取支付之后活动相关的弹窗信息 func GetActivityWechatPayMsg(activityId int) (isPublicActivitie, isSignUp bool) { var err error defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg(fmt.Sprint("获取支付之后活动相关的弹窗信息失败 GetActivityWechatPayMsg, err:", err.Error(), "activityId:", activityId), 2) } }() activityInfo, e := models.GetAddActivityInfoById(activityId) if e != nil { err = errors.New("GetAddActivityInfoById, Err: " + e.Error()) return } if (!activityInfo.IsResearchPoints && activityInfo.IsLimitPeople == 0) || activityInfo.YidongActivityId != "" { //易董的活动 或者(不扣点且不限制人数)是公开活动 isPublicActivitie = true //日卡月卡商品信息 } var userPointsNum float64 if activityInfo.IsResearchPoints { //获取活动对用户要扣的点 userPointsNum, e = models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId) if e != nil { err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error()) return } } //专家线下沙龙与买方线下交流、扣点的公司调研电话会自动报名 if activityInfo.ActivityTypeId != 5 && activityInfo.ActivityTypeId != 8 && userPointsNum == 0 { return } else { isSignUp = true } return }