123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738 |
- package services
- import (
- "encoding/json"
- "errors"
- "fmt"
- "hongze/hongze_mfyx/models"
- "hongze/hongze_mfyx/models/order"
- "hongze/hongze_mfyx/utils"
- "time"
- )
- // 获取日卡、月卡商品配置信息
- func GetUserGoodsCardList() (goodsListResp []*order.CygxGoodsResp) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("判断用户是否开通了个人研选权限失败 GetCygxGoodsList, 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.IsResearchPoints { //买方线下交流/专家线下沙龙。参会人扣点,
- condition = ` AND goods_id IN (4) `
- } else if (item.ActivityTypeId == 5 || item.ActivityTypeId == 8) && !item.IsResearchPoints { //买方线下交流/专家线下沙龙。参会人扣点,
- condition = ` AND goods_id IN (5) `
- } else if item.ActivityTypeId == 3 && item.IsResearchPoints { //非易董。公司调研电话会参会人扣点
- condition = ` AND goods_id IN (6) `
- } else if item.ActivityTypeId == 3 && !item.IsResearchPoints { //非易董。公司调研电话会参会人扣点
- condition = ` AND goods_id IN (7) `
- } else if item.ActivityTypeId == 1 && item.IsResearchPoints { //专家电话会,不限制人数,研选扣点(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) {
- 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("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
- return
- }
- totalPayVivo, e := order.GetCygxOrderVirtualAssetdCountByVivo(activityId, wxUser.UserId)
- if e != nil {
- err = errors.New("GetCygxActivityPointsSetUserNum, 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 > ? AND register_platform = ? ORDER BY order_id DESC `
- pars = append(pars, userId, 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
- }
- }
- 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("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10Min, 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 HandleOrderByWechatPay(itemCallback *WechatPayCallback) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("处理订单回调信息失败 HandleOrderByWechatPay, err:", err.Error()), 2)
- }
- }()
- outTradeNo := itemCallback.OutTradeNo
- orderDetail, e := order.GetCygxOrderDetailByOutTradeNo(outTradeNo)
- if e != nil {
- err = errors.New("GetCygxOrderDetailByOrderCode, Err: " + e.Error())
- return
- }
- //修改过状态的不再二次处理
- if orderDetail.OrderStatus == 2 {
- return
- }
- tradeState, _, _ := GetQueryOrderByOutTradeNo(outTradeNo) //主动查询微信支付信息
- if tradeState != "SUCCESS" {
- return
- }
- go AddCygxOrderPayment(itemCallback) // 记录支付交易信息
- if itemCallback.TradeState != "SUCCESS" { // 回调显示支付不成功,模版消息推送
- if e != nil {
- err = errors.New("支付失败, OutTradeNo: " + outTradeNo)
- return
- }
- }
- itemOrder := new(order.CygxOrder)
- itemOrder.OrderCode = orderDetail.OrderCode
- itemOrder.PayTime = itemCallback.SuccessTime
- itemOrder.PayMoney = float64(float64(itemCallback.Amount.PayerTotal) / 100) // 金额分转换处理
- itemOrder.OrderStatus = 2
- itemOrder.OutTradeCode = itemCallback.TransactionID
- itemOrder.TradeType = itemCallback.TradeType
- //文章处理逻辑 OrderType int `comment:"订单类型,1:畅读卡订单,2:单场付费订单"`
- if orderDetail.OrderType == 1 {
- itemUserCard := new(order.CygxOrderUserCard)
- itemUserCard.OrderCode = orderDetail.OrderCode
- itemUserCard.UserId = orderDetail.UserId
- itemUserCard.Mobile = orderDetail.Mobile
- itemUserCard.Email = orderDetail.Email
- itemUserCard.CompanyId = orderDetail.CompanyId
- itemUserCard.CompanyName = orderDetail.CompanyName
- itemUserCard.RealName = orderDetail.RealName
- itemUserCard.SellerName = orderDetail.SellerName
- itemUserCard.CreateTime = time.Now()
- itemUserCard.ModifyTime = time.Now()
- itemUserCard.RegisterPlatform = orderDetail.RegisterPlatform
- if orderDetail.GoodsId == 1 {
- itemUserCard.StartDate = itemOrder.PayTime
- itemUserCard.EndDate = itemOrder.PayTime.AddDate(0, 0, 1)
- itemUserCard.CardType = "日卡"
- } else {
- now := time.Now()
- itemUserCard.StartDate = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
- itemUserCard.EndDate = itemUserCard.StartDate.AddDate(0, 1, 0)
- itemUserCard.CardType = "月卡"
- }
- e = order.AddCygxOrderUserCard(itemUserCard, itemOrder)
- if e != nil {
- err = errors.New("AddCygxOrderUserCard, Err: " + e.Error())
- return
- }
- } else if orderDetail.OrderType == 2 || orderDetail.OrderType == 3 {
- //如果是活动,把单场付费信息的活动写入 用户虚拟资产表
- itemOrderVirtualAsset := new(order.CygxOrderVirtualAsset)
- itemOrderVirtualAsset.OrderCode = orderDetail.OrderCode
- itemOrderVirtualAsset.UserId = orderDetail.UserId
- itemOrderVirtualAsset.Mobile = orderDetail.Mobile
- itemOrderVirtualAsset.Email = orderDetail.Email
- itemOrderVirtualAsset.CompanyId = orderDetail.CompanyId
- itemOrderVirtualAsset.CompanyName = orderDetail.CompanyName
- itemOrderVirtualAsset.RealName = orderDetail.RealName
- itemOrderVirtualAsset.SellerName = orderDetail.SellerName
- itemOrderVirtualAsset.Source = orderDetail.Source
- itemOrderVirtualAsset.SourceId = orderDetail.SourceId
- itemOrderVirtualAsset.CreateTime = time.Now()
- itemOrderVirtualAsset.ModifyTime = time.Now()
- e = order.AddCygxOrderVirtualAsset(itemOrderVirtualAsset, itemOrder)
- if e != nil {
- err = errors.New("AddCygxOrderVirtualAsset, Err: " + e.Error())
- return
- }
- }
- if orderDetail.Source == utils.CYGX_OBJ_ACTIVITY {
- go AddActivitySignupByWechatPay(orderDetail.SourceId, orderDetail.UserId) //微信付款成功自动添加报名
- }
- go CancelOtherOrder(orderDetail) //付款成功之后自动取消其他相同的订单
- go SendWxCategoryMsgWxPay(orderDetail) //有人支付成功时,模板消息发送给王芳、沈涛和推荐人(没有推荐人时给销售)
- return
- }
- func AddCygxOrderPayment(itemCallback *WechatPayCallback) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("处理订单回调信息失败 HandleOrderHandle, err:", err.Error()), 2)
- }
- }()
- itemPay := new(order.CygxOrderPayment)
- itemPay.OrderCode = itemCallback.OutTradeNo
- itemPay.OutTradeCode = itemCallback.TransactionID
- itemPay.PayBody = itemCallback.TradeStateDesc
- jsonData, _ := json.Marshal(itemCallback)
- itemPay.PayDetail = string(jsonData)
- itemPay.PayMoney = float64(float64(itemCallback.Amount.PayerTotal) / 100) // 金额分转换处理
- itemPay.PayStatus = itemCallback.TradeState
- itemPay.CreateTime = time.Now()
- itemPay.PaymentType = 1
- e := order.AddCygxOrderPayment(itemPay)
- if e != nil {
- err = errors.New("AddCygxOrderPayment, Err: " + e.Error())
- return
- }
- 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 HandleOrderRefundByWechatPay(itemCallback *WechatPayCallback) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("处理退款订单回调信息失败 HandleOrderRefundByWechatPay, err:", err.Error()), 2)
- }
- }()
- outTradeNo := itemCallback.OutTradeNo
- orderDetail, e := order.GetCygxOrderDetailByOutTradeNo(outTradeNo)
- if e != nil {
- err = errors.New("GetCygxOrderDetailByOrderCode, Err: " + e.Error())
- return
- }
- //go AddCygxOrderPayment(itemCallback) // 记录支付交易信息
- //修改过状态的不再二次处理
- if orderDetail.OrderStatus == 3 {
- return
- }
- itemOrder := new(order.CygxOrder)
- itemOrder.OrderCode = orderDetail.OrderCode
- itemOrder.RefundTime = itemCallback.SuccessTime
- itemOrder.RefundMoney = float64(float64(itemCallback.Amount.PayerTotal) / 100) // 金额分转换处理
- itemOrder.OrderStatus = 3
- //文章处理逻辑 OrderType int `comment:"订单类型,1:畅读卡订单,2:单场付费订单"`
- if orderDetail.OrderType == 1 {
- itemUserCard := new(order.CygxOrderUserCard)
- itemUserCard.OrderCode = orderDetail.OrderCode
- itemUserCard.UserId = orderDetail.UserId
- itemUserCard.Mobile = orderDetail.Mobile
- itemUserCard.Email = orderDetail.Email
- itemUserCard.CompanyId = orderDetail.CompanyId
- itemUserCard.CompanyName = orderDetail.CompanyName
- itemUserCard.RealName = orderDetail.RealName
- itemUserCard.SellerName = orderDetail.SellerName
- itemUserCard.CreateTime = time.Now()
- itemUserCard.ModifyTime = time.Now()
- itemUserCard.RegisterPlatform = orderDetail.RegisterPlatform
- if orderDetail.GoodsId == 1 {
- itemUserCard.CardType = "日卡"
- } else {
- itemUserCard.CardType = "月卡"
- }
- e = order.RemoveCygxOrderUserCard(itemUserCard, itemOrder) // 移除用户
- if e != nil {
- err = errors.New("RemoveCygxOrderUserCard, Err: " + e.Error())
- return
- }
- } else if orderDetail.OrderType == 2 || orderDetail.OrderType == 3 {
- //如果是活动,把单场付费信息的活动写入 用户虚拟资产表
- itemOrderVirtualAsset := new(order.CygxOrderVirtualAsset)
- itemOrderVirtualAsset.OrderCode = orderDetail.OrderCode
- itemOrderVirtualAsset.UserId = orderDetail.UserId
- itemOrderVirtualAsset.Mobile = orderDetail.Mobile
- itemOrderVirtualAsset.Email = orderDetail.Email
- itemOrderVirtualAsset.CompanyId = orderDetail.CompanyId
- itemOrderVirtualAsset.CompanyName = orderDetail.CompanyName
- itemOrderVirtualAsset.RealName = orderDetail.RealName
- itemOrderVirtualAsset.SellerName = orderDetail.SellerName
- itemOrderVirtualAsset.Source = orderDetail.Source
- itemOrderVirtualAsset.SourceId = orderDetail.SourceId
- itemOrderVirtualAsset.CreateTime = time.Now()
- itemOrderVirtualAsset.ModifyTime = time.Now()
- e = order.RemoveCygxOrderVirtualAsset(itemOrderVirtualAsset, itemOrder)
- if e != nil {
- err = errors.New("AddCygxOrderVirtualAsset, Err: " + e.Error())
- return
- }
- }
- //if orderDetail.Source == utils.CYGX_OBJ_ACTIVITY {
- // go CancelActivitySignupByWechatPay(orderDetail.SourceId, orderDetail.UserId) //微信退款成功自动取消报名
- //}
- return
- }
- // 微信付款成功自动添加报名
- func AddActivitySignupByWechatPay(activityId, userId int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("微信付款成功自动添加报名失败 AddActivitySignupByWechatPay, err:", err.Error(), "activityId:", activityId, "userId:", userId), 2)
- }
- }()
- activityInfo, e := models.GetAddActivityInfoById(activityId)
- if e != nil {
- err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
- return
- }
- 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
- }
- user, e := models.GetWxUserItemByUserId(userId)
- if e != nil {
- err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
- return
- }
- var sellerName string
- sellerName, e = models.GetCompanySellerName(user.CompanyId)
- if e != nil {
- err = errors.New("GetCompanySellerName, Err: " + e.Error())
- return
- }
- item := new(models.CygxActivitySignup)
- totalMySuccess, e := models.GetActivitySignupCount(userId, activityId)
- if e != nil {
- err = errors.New("AddActivitySignup, Err: " + e.Error())
- return
- }
- if totalMySuccess > 0 { //已报名这个活动
- return
- }
- item.UserId = userId
- item.RealName = user.RealName
- item.SellerName = sellerName
- item.ActivityId = activityId
- item.CreateTime = time.Now()
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.SignupType = 3
- item.FailType = 0
- item.DoFailType = 0
- item.OutboundMobile = user.Mobile
- if user.OutboundMobile != "" {
- item.OutboundMobile = user.OutboundMobile
- if user.OutboundCountryCode == "" {
- item.CountryCode = "86"
- } else {
- item.CountryCode = user.OutboundCountryCode
- }
- } else {
- item.OutboundMobile = user.Mobile
- if user.CountryCode == "" {
- item.CountryCode = "86"
- } else {
- item.CountryCode = user.CountryCode
- }
- }
- _, e = models.AddActivitySignup(item)
- if e != nil {
- err = errors.New("AddActivitySignup, Err: " + e.Error())
- return
- }
- fmt.Println("报名成功")
- go ActivityUserRemind(user, activityInfo, 4)
- return
- }
- // 微信退款成功自动取消报名
- func CancelActivitySignupByWechatPay(activityId, userId int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("微信退款成功自动取消报名失败 CancelActivitySignupByWechatPay, err:", err.Error(), "activityId:", activityId, "userId:", userId), 2)
- }
- }()
- activityInfo, e := models.GetAddActivityInfoById(activityId)
- if e != nil {
- err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
- return
- }
- user, e := models.GetWxUserItemByUserId(userId)
- if e != nil {
- err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
- return
- }
- item := new(models.CygxActivitySignup)
- item.UserId = userId
- item.ActivityId = activityId
- item.CreateTime = time.Now()
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- resp := new(models.SignupStatus)
- resp.ActivityId = activityId
- _, e = models.CancelActivitySignup(item)
- if e != nil {
- err = errors.New("CancelActivitySignup, Err: " + e.Error())
- return
- }
- // 如果是买方研选下的专家沙龙,同时推给内容组四人
- if activityInfo.ActivityTypeId == 5 {
- go SendActivitieCancelSignTemplateMsg(user, activityInfo)
- }
- go SendResearchActivitiesTemplateMsg(user, activityInfo, "取消报名") //公司线下调研活动客户报名后给建会人,所属销售推送模板信息
- 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
- }
- // 付款成功之后自动取消其他相同的订单
- func CancelOtherOrder(item *order.CygxOrder) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("付款成功之后自动取消其他相同的订单失败 CancelOtherOrder, err:", err.Error(), "order_id:", item.OrderId), 2)
- }
- }()
- var condition string
- var pars []interface{}
- userId := item.UserId
- //判断是日卡月卡还是单场付费活动
- if item.GoodsId == 1 || item.GoodsId == 2 {
- condition += ` AND user_id = ? AND goods_id IN (1,2) AND order_id != ? AND order_status = 1 `
- pars = append(pars, userId, item.OrderId)
- } else {
- condition += ` AND user_id = ? AND source_id = ? AND source = ? AND order_id != ? AND order_status = 1 `
- pars = append(pars, userId, item.SourceId, item.Source, item.OrderId)
- }
- listOrder, e := order.GetCygxOrderDetailList(condition, pars) // 这里就一条数据
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCygxOrderDetailList, Err: " + e.Error())
- return
- }
- if len(listOrder) == 0 {
- err = nil
- return
- }
- for _, v := range listOrder {
- e = order.CancelCygxOrder(v)
- if e != nil {
- return
- }
- }
- return
- }
|