123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- 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
- }
|