|
@@ -3,12 +3,15 @@ package entity
|
|
|
import (
|
|
|
"database/sql"
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
+ "github.com/google/uuid"
|
|
|
"jy/src/jfw/modules/subscribepay/src/config"
|
|
|
"jy/src/jfw/modules/subscribepay/src/pay"
|
|
|
util "jy/src/jfw/modules/subscribepay/src/util"
|
|
|
"log"
|
|
|
"net/http"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
@@ -20,17 +23,42 @@ import (
|
|
|
"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
)
|
|
|
|
|
|
+const (
|
|
|
+ groupTypeAll = 1 // 用户群组类型 1-全部
|
|
|
+ groupTypeTags = 2 // 用户群组类型 2-标签群组
|
|
|
+ groupTypeBackGroup = 3 // 用户群组类型 3-后台群组
|
|
|
+
|
|
|
+)
|
|
|
+
|
|
|
+const (
|
|
|
+ BackGroupNew = "0" // 后台分组 新用户
|
|
|
+ BackGroupLimitM = "lm" // 后台分组 仅大会员(非超级订阅的大会员)
|
|
|
+ BackGroupLimitV = "lv" // 后台分组 仅超级订阅 (非大会员的超级订阅)
|
|
|
+ BackGroupLimitMv = "lmv" // 后台分组 大会员且超级订阅
|
|
|
+ BackGroupLimitNMV = "nmv" // 后台分组 非大会员非超级订阅
|
|
|
+
|
|
|
+)
|
|
|
+
|
|
|
+var PayBackGroup = map[string]struct{}{BackGroupLimitM: {}, BackGroupLimitMv: {}, BackGroupLimitV: {}}
|
|
|
+
|
|
|
type EquityCode struct {
|
|
|
- Code string //权益码
|
|
|
- UserId string //用户id
|
|
|
- OpenId string //openId
|
|
|
- Phone string //用户手机号
|
|
|
- NickName string //用户昵称
|
|
|
- GiftCode int //活动产品code
|
|
|
- EquityId int //权益id
|
|
|
- R *http.Request //
|
|
|
- OrderCode string //订单编号
|
|
|
- Sess *httpsession.Session
|
|
|
+ Code string //权益码
|
|
|
+ UserId string //用户id
|
|
|
+ OpenId string //openId
|
|
|
+ Phone string //用户手机号
|
|
|
+ NickName string //用户昵称
|
|
|
+ GiftCode int //活动产品code
|
|
|
+ EquityId int //权益id
|
|
|
+ R *http.Request //
|
|
|
+ OrderCode string //订单编号
|
|
|
+ Sess *httpsession.Session
|
|
|
+ userInfo map[string]interface{} // 用于保存mgo用户信息
|
|
|
+ xcxAccountId int
|
|
|
+ groupId string
|
|
|
+ frequencyLimit int
|
|
|
+ groupType int
|
|
|
+ source string // 注册来源企业名称
|
|
|
+ disChannel string // 分销渠道 h5是在外边初始化好的,兑换中心那兑换的时候再处理
|
|
|
}
|
|
|
|
|
|
func GetNewEquityCode(code, userId, phone, nickName, openId string, r *http.Request, sess *httpsession.Session) *EquityCode {
|
|
@@ -127,30 +155,84 @@ func (e *EquityCode) Exchange() (msg string, b bool) {
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+func (e *EquityCode) H5Exchange() (status int, isMemberProduct bool) {
|
|
|
+ var msg string
|
|
|
+ var b bool
|
|
|
+ repeatKey := fmt.Sprintf("equity_action_phone_%s", e.Phone) // h5兑换没有登录 是手机号
|
|
|
+ if ok, err := redis.Exists("other", repeatKey); ok && err == nil {
|
|
|
+ log.Println(fmt.Sprintf("%s 权益码兑换 请求频次过高,请稍后再试", e.Phone))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //方式重复性请求--1秒内 允许请求一次
|
|
|
+ redis.Put("other", repeatKey, "REPEAT", 1)
|
|
|
+ // 验证用户 没有用户则创建用户
|
|
|
+ if e.userInfo == nil || len(e.userInfo) == 0 {
|
|
|
+ e.UserId, _, _, _ = e.CreateUser("权益码创建剑鱼用户", "")
|
|
|
+ if e.UserId == "" {
|
|
|
+ log.Println("创建用户失败:", e.Phone)
|
|
|
+ return 0, false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //订单编号
|
|
|
+ e.OrderCode = pay.GetOrderCode(e.UserId)
|
|
|
+ //更新权益码记录表
|
|
|
+ if b = e.UpdateEquityCode(false); b {
|
|
|
+ //下单并赋权限
|
|
|
+ msg, b, status, isMemberProduct = e.H5UseEquityCodeAndAuthority()
|
|
|
+ //下单失败或者权益开通异常,更新权益码记录表 清除记录
|
|
|
+ if msg != "" || !b {
|
|
|
+ //权限开通异常 回滚数据
|
|
|
+ go func(orderCode string) {
|
|
|
+ if updateBool := e.UpdateEquityCode(true); !updateBool {
|
|
|
+ log.Println(fmt.Sprintf("%s 回退权益码信息异常 ", e.UserId))
|
|
|
+ }
|
|
|
+ if orderCode != "" {
|
|
|
+ util.Mysql.UpdateOrDeleteBySql(`DELETE FROM dataexport_order WHERE order_code = ?`, orderCode)
|
|
|
+ }
|
|
|
+ }(e.OrderCode)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return 0, false
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
|
|
|
// UpdateEquityCode 更新权益码记录信息
|
|
|
func (e *EquityCode) UpdateEquityCode(b bool) bool {
|
|
|
- queryMap := map[string]interface{}{
|
|
|
- "equityCode": e.Code,
|
|
|
- }
|
|
|
- updateMap := map[string]interface{}{
|
|
|
- "userId": e.UserId,
|
|
|
- "receiveTime": NowFormat(Date_Full_Layout),
|
|
|
- "userPerson": qu.If(e.Phone != "", e.Phone, e.NickName).(string),
|
|
|
- "userTime": NowFormat(Date_Full_Layout),
|
|
|
- "orderCode": e.OrderCode,
|
|
|
- }
|
|
|
- //订单异常 或 权益异常
|
|
|
- if b {
|
|
|
- updateMap = map[string]interface{}{
|
|
|
- "userId": "",
|
|
|
- "receiveTime": nil,
|
|
|
- "userPerson": "",
|
|
|
- "orderCode": "",
|
|
|
- "userTime": nil,
|
|
|
- }
|
|
|
- }
|
|
|
- return util.ActivityMysql.Update("equity_record", queryMap, updateMap)
|
|
|
+ f := util.ActivityMysql.ExecTx("更新兑换码信息", func(tx *sql.Tx) bool {
|
|
|
+ q := "SELECT * FROM jyactivities.equity_record where equityCode=? for update"
|
|
|
+ rs := util.ActivityMysql.SelectBySqlByTx(tx, q, e.Code)
|
|
|
+ if rs == nil || len(*rs) == 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ queryMap := map[string]interface{}{
|
|
|
+ "equityCode": e.Code,
|
|
|
+ }
|
|
|
+ updateMap := map[string]interface{}{
|
|
|
+ "userId": e.UserId,
|
|
|
+ "receiveTime": NowFormat(Date_Full_Layout),
|
|
|
+ "userPerson": qu.If(e.Phone != "", e.Phone, e.NickName).(string),
|
|
|
+ "userTime": NowFormat(Date_Full_Layout),
|
|
|
+ "orderCode": e.OrderCode,
|
|
|
+ }
|
|
|
+ //订单异常 或 权益异常
|
|
|
+ if b { // //
|
|
|
+ updateMap = map[string]interface{}{
|
|
|
+ "userId": "",
|
|
|
+ "receiveTime": nil,
|
|
|
+ "userPerson": "",
|
|
|
+ "orderCode": "",
|
|
|
+ "userTime": nil,
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // p719 20250411 添加更新前再次验证兑换码没有被使用
|
|
|
+ if qu.ObjToString((*rs)[0]["userId"]) != "" {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return util.ActivityMysql.UpdateByTx(tx, "equity_record", queryMap, updateMap)
|
|
|
+ })
|
|
|
+ return f
|
|
|
}
|
|
|
|
|
|
type ProductInfoByEquity struct {
|
|
@@ -165,7 +247,7 @@ type ProductInfoByEquity struct {
|
|
|
|
|
|
// UseEquityCodeAndAuthority 权益码使用 并 赋权限
|
|
|
func (e *EquityCode) UseEquityCodeAndAuthority() (m string, flag bool) {
|
|
|
- gifts := util.ActivityMysql.SelectBySql(`SELECT a.entid,b.* FROM equity a LEFT JOIN gift b ON a.giftCode = b.giftCode WHERE a.giftCode = ? AND a.state = 1 AND a.id = ?;`, e.GiftCode, e.EquityId)
|
|
|
+ gifts := util.ActivityMysql.SelectBySql(`SELECT a.entid,b.*,c.name as eName FROM equity a LEFT JOIN gift b ON a.giftCode = b.giftCode left join jyactivities.enterprise c on a.entid = c.id WHERE a.giftCode = ? AND a.state = 1 AND a.id = ?;`, e.GiftCode, e.EquityId)
|
|
|
if gifts != nil && len(*gifts) > 0 {
|
|
|
gift := (*gifts)[0]
|
|
|
productInfo := &ProductInfoByEquity{
|
|
@@ -183,16 +265,13 @@ func (e *EquityCode) UseEquityCodeAndAuthority() (m string, flag bool) {
|
|
|
baseMsg = jy.GetBigVipUserBaseMsg(e.Sess, *config.Middleground)
|
|
|
distributionChannel, orderChannel = util.GetJyOrderChannel("", e.R.Header.Get("User-Agent")) //默认剑鱼标讯
|
|
|
)
|
|
|
- //权益公司
|
|
|
- if productInfo.EntId > 1 {
|
|
|
- //2:青柠平台
|
|
|
- switch productInfo.EntId {
|
|
|
- case 2:
|
|
|
- orderChannel = "xdqd05"
|
|
|
- distributionChannel = "x041"
|
|
|
- }
|
|
|
+ entName := qu.IntAll(gift["eName"])
|
|
|
+ orderChannel = "xdqd05"
|
|
|
+ distributionChannel = "x045"
|
|
|
+ items := util.ActivityMysql.SelectBySql(`select item_code from jianyu.dict_item where parent_code='x04' and item_name=?`, entName)
|
|
|
+ if items != nil && len(*items) > 0 {
|
|
|
+ distributionChannel = qu.ObjToString((*items)[0]["item_code"])
|
|
|
}
|
|
|
-
|
|
|
switch productInfo.ParentCode {
|
|
|
case 101:
|
|
|
/*
|
|
@@ -262,13 +341,7 @@ func (e *EquityCode) UseEquityCodeAndAuthority() (m string, flag bool) {
|
|
|
OrderType: orderType,
|
|
|
Badge: "exchange",
|
|
|
}
|
|
|
- switch distributionChannel {
|
|
|
- case "x041":
|
|
|
- filter.ZeroOrderType = "权益码兑换"
|
|
|
- default:
|
|
|
- filter.ZeroOrderType = "赠送"
|
|
|
- }
|
|
|
-
|
|
|
+ filter.ZeroOrderType = "权益码兑换"
|
|
|
filterStr, _ := json.Marshal(filter)
|
|
|
insertMap["filter"] = string(filterStr)
|
|
|
insertMap["filter_id"] = JyVipSubStruct.SaveSelectLog(e.UserId, e.OpenId, &filter)
|
|
@@ -334,12 +407,8 @@ func (e *EquityCode) UseEquityCodeAndAuthority() (m string, flag bool) {
|
|
|
OrderType: orderType,
|
|
|
Badge: "exchange",
|
|
|
}
|
|
|
- switch distributionChannel {
|
|
|
- case "x041":
|
|
|
- filter.ZeroOrderType = "权益码兑换"
|
|
|
- default:
|
|
|
- filter.ZeroOrderType = "赠送"
|
|
|
- }
|
|
|
+ filter.ZeroOrderType = "权益码兑换"
|
|
|
+
|
|
|
filterStr, _ := json.Marshal(filter)
|
|
|
insertMap["filter"] = string(filterStr)
|
|
|
insertMap["filter_id"] = JyVipSubStruct.SaveSelectLog(e.UserId, e.OpenId, &filter)
|
|
@@ -414,12 +483,7 @@ func (e *EquityCode) UseEquityCodeAndAuthority() (m string, flag bool) {
|
|
|
"level": level,
|
|
|
"badge": "exchange",
|
|
|
}
|
|
|
- switch distributionChannel {
|
|
|
- case "x041":
|
|
|
- filterMap["zeroOrderType"] = "权益码兑换"
|
|
|
- default:
|
|
|
- filterMap["zeroOrderType"] = "赠送"
|
|
|
- }
|
|
|
+ filterMap["zeroOrderType"] = "权益码兑换"
|
|
|
filter, _ := json.Marshal(filterMap)
|
|
|
endDate := time.Date(startTime.Year()+cycle, startTime.Month(), startTime.Day(), 23, 59, 59, 0, time.Local)
|
|
|
insertObj := map[string]interface{}{
|
|
@@ -489,12 +553,7 @@ func (e *EquityCode) UseEquityCodeAndAuthority() (m string, flag bool) {
|
|
|
m = "数据量流量包 计算价格异常"
|
|
|
return
|
|
|
}
|
|
|
- switch distributionChannel {
|
|
|
- case "x041":
|
|
|
- packDetail.ZeroOrderType = "权益码兑换"
|
|
|
- default:
|
|
|
- packDetail.ZeroOrderType = "赠送"
|
|
|
- }
|
|
|
+ packDetail.ZeroOrderType = "权益码兑换"
|
|
|
filter, err := json.Marshal(packDetail)
|
|
|
if err != nil {
|
|
|
m = "数据量流量包 序列化数据异常"
|
|
@@ -534,9 +593,403 @@ func (e *EquityCode) UseEquityCodeAndAuthority() (m string, flag bool) {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+ // 走到这说明前面都成功了
|
|
|
+ // 销售记录表
|
|
|
+ util.Mysql.Insert("order_sale_record", map[string]interface{}{
|
|
|
+ "state": 1,
|
|
|
+ "ordercode": e.OrderCode,
|
|
|
+ "saler_dept": "运营部",
|
|
|
+ "saler_dept_id": 27103,
|
|
|
+ "saler_name": "-",
|
|
|
+ "saler_Id": -1,
|
|
|
+ "money": 0,
|
|
|
+ "change_value": 0,
|
|
|
+ "group_uuid": uuid.New().String(),
|
|
|
+ "operator": "系统自动",
|
|
|
+ "change_reason": "回款成功",
|
|
|
+ "distribution_channel": distributionChannel,
|
|
|
+ "create_time": NowFormat(Date_Full_Layout),
|
|
|
+ "statistics_time": NowFormat(Date_Full_Layout),
|
|
|
+ })
|
|
|
+ return "", flag
|
|
|
}
|
|
|
return "", flag
|
|
|
}
|
|
|
+func (e *EquityCode) H5UseEquityCodeAndAuthority() (m string, flag bool, status int, isMemberProduct bool) {
|
|
|
+ gifts := util.ActivityMysql.SelectBySql(`SELECT a.entid,b.* FROM equity a LEFT JOIN gift b ON a.giftCode = b.giftCode WHERE a.giftCode = ? AND a.state = 1 AND a.id = ?;`, e.GiftCode, e.EquityId)
|
|
|
+ if gifts != nil && len(*gifts) > 0 {
|
|
|
+ gift := (*gifts)[0]
|
|
|
+ productInfo := &ProductInfoByEquity{
|
|
|
+ ParentCode: qu.IntAll(gift["parentCode"]),
|
|
|
+ GiftCode: e.GiftCode,
|
|
|
+ Name: qu.ObjToString(gift["name"]),
|
|
|
+ Num: qu.IntAll(gift["time"]),
|
|
|
+ NumType: qu.IntAll(gift["timeType"]),
|
|
|
+ Province: qu.IntAll(gift["province"]), //0:不做限制;-1:全国;
|
|
|
+ EntId: qu.IntAll(gift["entid"]),
|
|
|
+ }
|
|
|
+ var (
|
|
|
+ startTime = time.Now()
|
|
|
+ endTime = time.Now()
|
|
|
+ )
|
|
|
+ vipStatus := 0
|
|
|
+ bigStatus := 0
|
|
|
+ if len(e.userInfo) > 0 {
|
|
|
+ vipStatus = qu.IntAll(e.userInfo["i_vip_status"])
|
|
|
+ bigStatus = qu.IntAll(e.userInfo["i_member_status"])
|
|
|
+ }
|
|
|
+ orderChannel := "xdqd05"
|
|
|
+ distributionChannel := e.disChannel
|
|
|
+ switch productInfo.ParentCode {
|
|
|
+ case 101:
|
|
|
+ /*
|
|
|
+ // 超级订阅 计算周期
|
|
|
+ //插入订单信息
|
|
|
+ // cycleUnit(1:年 2:月 3:天 4:季)
|
|
|
+ // cycleCount 数字长度
|
|
|
+ */
|
|
|
+ var (
|
|
|
+ area = &map[string]interface{}{"北京": []string{}} //默认
|
|
|
+ //jyactivities 库 》gift 表 标准天和年和支付订单表 天和年单位相反
|
|
|
+ cycleUnit = func(numType int) int {
|
|
|
+ switch numType {
|
|
|
+ case 1:
|
|
|
+ numType = 3 //天
|
|
|
+ case 3:
|
|
|
+ numType = 1 //年
|
|
|
+ }
|
|
|
+ return numType
|
|
|
+ }(productInfo.NumType)
|
|
|
+ //默认设置
|
|
|
+ buySet = JyVipSubStruct.NewBuySet(area, 1, nil, true) //改版后只能购买升级版超级订阅
|
|
|
+ orderType = qu.If(vipStatus > 0, 1, 0).(int) //vip订阅-0:试用 1:续费 2:升级(来自数据库字段说明 -- 为什么没有购买类型)
|
|
|
+ totalPrice int
|
|
|
+ userData *map[string]interface{}
|
|
|
+ )
|
|
|
+ //插入订单
|
|
|
+ insertMap := map[string]interface{}{
|
|
|
+ "order_status": 1,
|
|
|
+ "user_nickname": e.NickName,
|
|
|
+ "order_code": e.OrderCode,
|
|
|
+ "product_type": "VIP订阅",
|
|
|
+ "create_time": FormatDate(&startTime, Date_Full_Layout),
|
|
|
+ "user_id": e.UserId,
|
|
|
+ "user_openid": e.OpenId,
|
|
|
+ "distribution_channel": distributionChannel, //销售渠道
|
|
|
+ "order_channel": orderChannel, //下单渠道
|
|
|
+ "audit_status": 3, //默认审核通过
|
|
|
+ "vip_starttime": FormatDate(&startTime, Date_Full_Layout),
|
|
|
+ "vip_type": orderType,
|
|
|
+ "pay_money": 0, //价格为0
|
|
|
+ //"pay_time": FormatDate(&startTime, Date_Full_Layout), //支付时间 当前时间
|
|
|
+ "user_phone": e.Phone,
|
|
|
+ "is_backstage_order": 1, //线下订单
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ //开通权限
|
|
|
+ */
|
|
|
+ if vipStatus > 0 { //仅续费
|
|
|
+ userData, buySet, _ = JyVipSubStruct.GetVipDetail(e.UserId)
|
|
|
+ //是否需要判断 地区
|
|
|
+ if productInfo.Province != 0 {
|
|
|
+ if buySet.AreaCount != productInfo.Province {
|
|
|
+ m = "兑换权益与当前用户权益不对等,无法兑换。请直接联系吕经理15136295365。"
|
|
|
+ status = -7
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ totalPrice = JyVipSubStruct.GetSubVipPrice(buySet, productInfo.Num, cycleUnit) //价格
|
|
|
+ insertMap["order_money"] = totalPrice
|
|
|
+ insertMap["original_price"] = totalPrice
|
|
|
+ filter := VipSimpleMsg{
|
|
|
+ Area: area,
|
|
|
+ Industry: []string{},
|
|
|
+ Cyclecount: productInfo.Num,
|
|
|
+ Cycleunit: cycleUnit,
|
|
|
+ NewBuyset: buySet,
|
|
|
+ OrderType: orderType,
|
|
|
+ Badge: "exchange",
|
|
|
+ }
|
|
|
+ filter.ZeroOrderType = "权益码兑换"
|
|
|
+ filterStr, _ := json.Marshal(filter)
|
|
|
+ insertMap["filter"] = string(filterStr)
|
|
|
+ insertMap["filter_id"] = JyVipSubStruct.SaveSelectLog(e.UserId, e.OpenId, &filter)
|
|
|
+ //计算续费时间
|
|
|
+ timeStamp := qu.Int64All((*userData)["l_vip_endtime"])
|
|
|
+ //开始时间
|
|
|
+ startTime = time.Unix(timeStamp, 0)
|
|
|
+ //结束时间
|
|
|
+ endTime = util.GetDATE(cycleUnit, productInfo.Num, timeStamp)
|
|
|
+ insertMap["vip_type"] = 1
|
|
|
+ insertMap["vip_starttime"] = FormatDate(&startTime, Date_Full_Layout)
|
|
|
+ insertMap["vip_endtime"] = FormatDate(&endTime, Date_Full_Layout)
|
|
|
+ if flag = util.Mysql.Insert("dataexport_order", insertMap) > 1; !flag {
|
|
|
+ m = "超级订阅 续费 订单入库异常"
|
|
|
+ status = 0
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //超级订阅续费--#####
|
|
|
+ flag = JyVipSubStruct.RenewSubVip(e.UserId, FormatDate(&endTime, Date_Full_Layout))
|
|
|
+ //延长超级订阅到期时间--资源中台
|
|
|
+ updateT := &UpdateVipTimeStruct{
|
|
|
+ AccountId: e.UserId,
|
|
|
+ VipTime: endTime.Unix(),
|
|
|
+ }
|
|
|
+ b, err := updateT.UpdateVipEndTime()
|
|
|
+ if !b || err != nil {
|
|
|
+ log.Println(fmt.Sprintf("%s 更新资源中台 超级订阅到期时间 异常:%s", e.UserId, err.Error()))
|
|
|
+ flag = false
|
|
|
+ m = "超级订阅权限开通失败"
|
|
|
+ status = 0
|
|
|
+ go func(userId string, endTime time.Time) {
|
|
|
+ //调整失败 到期时间复原 对应上面 #####
|
|
|
+ JyVipSubStruct.RenewSubVip(userId, FormatDate(&endTime, Date_Full_Layout))
|
|
|
+ }(e.UserId, startTime)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //修改附件下载包的到期时间
|
|
|
+ b = FilepackEndtime(e.UserId)
|
|
|
+ if !b {
|
|
|
+ log.Println(fmt.Sprintf("%s 更新 附件下载包到期时间 异常", e.UserId))
|
|
|
+ flag = false
|
|
|
+ m = "超级订阅权限开通失败"
|
|
|
+ status = 0
|
|
|
+ go func(userId string, endTime time.Time) {
|
|
|
+ //调整失败 到期时间复原 对应上面 #####
|
|
|
+ JyVipSubStruct.RenewSubVip(userId, FormatDate(&endTime, Date_Full_Layout))
|
|
|
+ }(e.UserId, startTime)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ flag = b
|
|
|
+ } else if vipStatus < 1 { //新订单
|
|
|
+ //兑换 超级订阅 默认一个省
|
|
|
+ buySet.AreaCount = 1
|
|
|
+ if productInfo.Province != 0 {
|
|
|
+ buySet.AreaCount = productInfo.Province
|
|
|
+ }
|
|
|
+ totalPrice = JyVipSubStruct.GetSubVipPrice(buySet, productInfo.Num, cycleUnit) //价格
|
|
|
+ insertMap["order_money"] = totalPrice
|
|
|
+ insertMap["original_price"] = totalPrice
|
|
|
+ filter := VipSimpleMsg{
|
|
|
+ Area: area,
|
|
|
+ Industry: []string{},
|
|
|
+ Cyclecount: productInfo.Num,
|
|
|
+ Cycleunit: cycleUnit,
|
|
|
+ NewBuyset: buySet,
|
|
|
+ OrderType: orderType,
|
|
|
+ Badge: "exchange",
|
|
|
+ }
|
|
|
+ filter.ZeroOrderType = "权益码兑换"
|
|
|
+ filterStr, _ := json.Marshal(filter)
|
|
|
+ insertMap["filter"] = string(filterStr)
|
|
|
+ insertMap["filter_id"] = JyVipSubStruct.SaveSelectLog(e.UserId, e.OpenId, &filter)
|
|
|
+ //计算时长
|
|
|
+ vsm := VipSimpleMsg{
|
|
|
+ OrderType: 1,
|
|
|
+ NewBuyset: &SubvipBuySet{},
|
|
|
+ }
|
|
|
+ //结束时间
|
|
|
+ endTime = util.GetDATE(cycleUnit, productInfo.Num, startTime.Unix())
|
|
|
+ insertMap["vip_endtime"] = FormatDate(&endTime, Date_Full_Layout)
|
|
|
+ if flag = util.Mysql.Insert("dataexport_order", insertMap) > 1; !flag {
|
|
|
+ m = "超级订阅 购买 订单入库异常"
|
|
|
+ status = 0
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //城市 默认 北京
|
|
|
+ vsm.Area = area
|
|
|
+ vsm.NewBuyset.AreaCount = -1
|
|
|
+ if productInfo.Province > 0 {
|
|
|
+ vsm.NewBuyset.AreaCount = productInfo.Province
|
|
|
+ } //-1是全国
|
|
|
+ vsm.NewBuyset.Upgrade = 1 //超级订阅升级版
|
|
|
+ vsm.NewBuyset.BuyerclassCount = -1 //全行业
|
|
|
+ if flag = JyVipSubStruct.StartSubVip(e.UserId, vsm, startTime, endTime, false, 0, 0, 0); !flag {
|
|
|
+ m = "超级订阅权限开通失败"
|
|
|
+ status = 0
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if flag {
|
|
|
+ //取消其他超级订阅 未完成的订单
|
|
|
+ go PayCancel(e.UserId, "VIP订阅", "")
|
|
|
+ }
|
|
|
+ case 104:
|
|
|
+ isMemberProduct = true
|
|
|
+ /*
|
|
|
+ //大会员开通权限
|
|
|
+ */
|
|
|
+ level := productInfo.NumType //1:专业版;2:智慧版;3:商机版;4:试用版 5:试用版 6:商机版2.0 7:专家版2.0
|
|
|
+ cycle := productInfo.Num //默认年
|
|
|
+ //判断当前是否是大会员
|
|
|
+ if bigStatus > 0 && bigStatus != level {
|
|
|
+ m = "兑换权益与当前用户权益不对等,无法兑换。请直接联系吕经理15136295365。"
|
|
|
+ status = -7
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if c := util.Mysql.Count("dataexport_order", map[string]interface{}{
|
|
|
+ "user_id": e.UserId,
|
|
|
+ "product_type": "大会员",
|
|
|
+ "order_status": 0,
|
|
|
+ "course_status": 2,
|
|
|
+ }); c > 0 {
|
|
|
+ m = "大会员有待审核订单"
|
|
|
+ status = 0
|
|
|
+ return
|
|
|
+ }
|
|
|
+ mData, ok := util.MQFW.FindById("user", e.UserId, `{"i_member_status":1,"i_member_endtime":1,"i_member_starttime":1}`)
|
|
|
+ if !ok || len(*mData) == 0 || mData == nil {
|
|
|
+ m = "查询当前用户信息失败"
|
|
|
+ status = 0
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //续费计算时间
|
|
|
+ if (*mData)["i_member_status"] != nil && qu.Int64All((*mData)["i_member_status"]) > 0 {
|
|
|
+ timeStamp := qu.Int64All((*mData)["i_member_endtime"])
|
|
|
+ //开始时间
|
|
|
+ startTime = time.Unix(timeStamp, 0)
|
|
|
+ }
|
|
|
+ //计算价格
|
|
|
+ orderMoney := MemberStruct.GetMoney(e.UserId, level, cycle)
|
|
|
+ filterMap := map[string]interface{}{
|
|
|
+ "cycle": cycle,
|
|
|
+ "level": level,
|
|
|
+ "badge": "exchange",
|
|
|
+ }
|
|
|
+ filterMap["zeroOrderType"] = "权益码兑换"
|
|
|
+ filter, _ := json.Marshal(filterMap)
|
|
|
+ endDate := time.Date(startTime.Year()+cycle, startTime.Month(), startTime.Day(), 23, 59, 59, 0, time.Local)
|
|
|
+ insertObj := map[string]interface{}{
|
|
|
+ "order_money": orderMoney,
|
|
|
+ "filter": string(filter),
|
|
|
+ "order_code": e.OrderCode,
|
|
|
+ "product_type": "大会员",
|
|
|
+ "create_time": NowFormat(Date_Full_Layout),
|
|
|
+ "prepay_time": NowFormat(Date_Full_Layout),
|
|
|
+ "user_id": e.UserId,
|
|
|
+ "pay_way": "",
|
|
|
+ "original_price": orderMoney,
|
|
|
+ "distribution_channel": distributionChannel, //销售渠道
|
|
|
+ "order_channel": orderChannel, //下单渠道
|
|
|
+ "audit_status": 3, //默认审核通过
|
|
|
+ "user_phone": e.Phone,
|
|
|
+ "pay_money": 0,
|
|
|
+ //"pay_time": NowFormat(Date_Full_Layout),
|
|
|
+ "order_status": 1,
|
|
|
+ "vip_starttime": NowFormat(Date_Full_Layout),
|
|
|
+ "vip_endtime": FormatDate(&endDate, Date_Full_Layout),
|
|
|
+ "is_backstage_order": 1, //线下订单
|
|
|
+ }
|
|
|
+ if flag = util.Mysql.Insert("dataexport_order", insertObj) > 1; !flag {
|
|
|
+ m = "大会员 订单入库异常"
|
|
|
+ status = 0
|
|
|
+ return
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ //开通权限
|
|
|
+ */
|
|
|
+ if bigStatus > 0 {
|
|
|
+ //大会员续费
|
|
|
+ memberRenew(endDate, e.UserId)
|
|
|
+ } else {
|
|
|
+ //开通大会员
|
|
|
+ normal_member(level, endDate, e.UserId, 0, 0, 0, cycle)
|
|
|
+ }
|
|
|
+ //取消其他订单
|
|
|
+ go PayCancel(e.UserId, "大会员", "")
|
|
|
+ case 112:
|
|
|
+ /*
|
|
|
+ //数据流量包
|
|
|
+ //生订单
|
|
|
+ */
|
|
|
+ packId := ""
|
|
|
+ switch productInfo.NumType {
|
|
|
+ case 4: //标准
|
|
|
+ packId = fmt.Sprintf("%s_%d", "normal", productInfo.Num)
|
|
|
+ case 5: //高级
|
|
|
+ packId = fmt.Sprintf("%s_%d", "senior", productInfo.Num)
|
|
|
+ }
|
|
|
+ if packId == "" {
|
|
|
+ m = "数据流量包 参数异常"
|
|
|
+ status = 0
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //根据id查询流量包价格
|
|
|
+ packDetail, err := JyDataExportPack.GetPackDetailById(packId)
|
|
|
+ log.Println("packDetail:", packDetail)
|
|
|
+ packDetail.GiveCycle = 0
|
|
|
+ packDetail.DisCountId = 0
|
|
|
+ packDetail.Badge = "exchange"
|
|
|
+ if err != nil {
|
|
|
+ m = "数据量流量包 计算价格异常"
|
|
|
+ status = 0
|
|
|
+ return
|
|
|
+ }
|
|
|
+ packDetail.ZeroOrderType = "权益码兑换"
|
|
|
+ filter, err := json.Marshal(packDetail)
|
|
|
+ if err != nil {
|
|
|
+ m = "数据量流量包 序列化数据异常"
|
|
|
+ status = 0
|
|
|
+ return
|
|
|
+ }
|
|
|
+ log.Println("filter:", string(filter))
|
|
|
+ insertMap := map[string]interface{}{
|
|
|
+ "order_money": packDetail.Price,
|
|
|
+ "service_status": 0,
|
|
|
+ "user_nickname": e.NickName,
|
|
|
+ "user_openid": e.OpenId,
|
|
|
+ "user_phone": e.Phone,
|
|
|
+ "order_code": e.OrderCode,
|
|
|
+ "product_type": "数据流量包",
|
|
|
+ "create_time": FormatDate(&startTime, Date_Full_Layout),
|
|
|
+ "original_price": packDetail.Price,
|
|
|
+ "filter": string(filter),
|
|
|
+ "user_id": e.UserId, //20190719 移动端数据导出 生订单添加用户id
|
|
|
+ "distribution_channel": distributionChannel, //销售渠道
|
|
|
+ "order_channel": orderChannel, //下单渠道
|
|
|
+ "audit_status": 3, //默认审核通过
|
|
|
+ "pay_money": 0,
|
|
|
+ //"pay_time": FormatDate(&startTime, Date_Full_Layout),
|
|
|
+ "order_status": 1,
|
|
|
+ "is_backstage_order": 1, //线下订单
|
|
|
+ }
|
|
|
+ if flag = util.Mysql.Insert("dataexport_order", insertMap) > 0; !flag {
|
|
|
+ m = "数据流量包 创建订单异常"
|
|
|
+ status = 0
|
|
|
+ return
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ //调用中台 增加数据包
|
|
|
+ //开通权限
|
|
|
+ */
|
|
|
+ if flag, err = perRechargePack(e.UserId, startTime.AddDate(2, 0, 0).Format(Date_Short_Layout), &packDetail); !flag || err != nil {
|
|
|
+ m = "资源账户更改异常"
|
|
|
+ status = 0
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 走到这说明前面都成功了
|
|
|
+ // 销售记录表
|
|
|
+ util.Mysql.Insert("order_sale_record", map[string]interface{}{
|
|
|
+ "state": 1,
|
|
|
+ "ordercode": e.OrderCode,
|
|
|
+ "saler_dept": "运营部",
|
|
|
+ "saler_dept_id": 27103,
|
|
|
+ "saler_name": "-",
|
|
|
+ "saler_Id": -1,
|
|
|
+ "money": 0,
|
|
|
+ "change_value": 0,
|
|
|
+ "group_uuid": uuid.New().String(),
|
|
|
+ "operator": "系统自动",
|
|
|
+ "change_reason": "回款成功",
|
|
|
+ "distribution_channel": distributionChannel,
|
|
|
+ "create_time": NowFormat(Date_Full_Layout),
|
|
|
+ "statistics_time": NowFormat(Date_Full_Layout),
|
|
|
+ })
|
|
|
+ return "", flag, 1, isMemberProduct
|
|
|
+ }
|
|
|
+ return "", flag, 0, isMemberProduct
|
|
|
+}
|
|
|
|
|
|
type ExchangeRecords struct {
|
|
|
Count int `json:"count"`
|
|
@@ -666,8 +1119,29 @@ func (e *EquityCode) Submit(codes []string, disChannel, productName, industryCod
|
|
|
return false
|
|
|
}
|
|
|
filter := fmt.Sprintf(`{"xcx_account_id":%d,"baseUserId":%d,"area_count":%d,"buyItemCode":["%s"],"industryCode":"%s","fromMiniCode":"%s","cycleCount":%d,"cycleUnit":%d,"originalAmount":0}`, comAccountId, userId, buyNum, strings.Join(codes, `","`), industryCode, codes[0], number, cycleUnit)
|
|
|
- util.ActivityMysql.InsertBatchByTx(tx, "jianyu.dataexport_order", []string{"order_code", "pay_money", "order_money", "pay_time", "order_status", "create_time", "filter", "original_price", "product_type", "user_phone", "user_id", "vip_starttime", "vip_endtime", "discount_price", "sale_time", "order_channel", "distribution_channel", "audit_status"}, []interface{}{
|
|
|
- orderCode, 0, 0, nowFormat, 1, nowFormat, filter, 0, productName, e.Phone, positionId, FormatDate(&orderStartTime, Date_Full_Layout), FormatDate(&orderEndTime, Date_Full_Layout), 0, nowFormat, "xdqd05", disChannel, 3})
|
|
|
+ if b, _ := util.ActivityMysql.InsertBatchByTx(tx, "jianyu.dataexport_order", []string{"order_code", "pay_money", "order_money", "pay_time", "order_status", "create_time", "filter", "original_price", "product_type", "user_phone", "user_id", "vip_starttime", "vip_endtime", "discount_price", "sale_time", "order_channel", "distribution_channel", "audit_status"}, []interface{}{
|
|
|
+ orderCode, 0, 0, nowFormat, 1, nowFormat, filter, 0, productName, e.Phone, positionId, FormatDate(&orderStartTime, Date_Full_Layout), FormatDate(&orderEndTime, Date_Full_Layout), 0, nowFormat, "xdqd05", disChannel, 3}); b <= 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ // 销售记录表
|
|
|
+ if util.Mysql.InsertByTx(tx, "jianyu.order_sale_record", map[string]interface{}{
|
|
|
+ "state": 1,
|
|
|
+ "ordercode": orderCode,
|
|
|
+ "saler_dept": "运营部",
|
|
|
+ "saler_dept_id": 27103,
|
|
|
+ "saler_name": "-",
|
|
|
+ "saler_Id": -1,
|
|
|
+ "money": 0,
|
|
|
+ "change_value": 0,
|
|
|
+ "group_uuid": uuid.New().String(),
|
|
|
+ "operator": "系统自动",
|
|
|
+ "change_reason": "回款成功",
|
|
|
+ "distribution_channel": disChannel,
|
|
|
+ "create_time": nowFormat,
|
|
|
+ "statistics_time": nowFormat,
|
|
|
+ }) <= 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
return true
|
|
|
}) {
|
|
|
return 1
|
|
@@ -724,37 +1198,40 @@ func (e *EquityCode) CreateUser(msg, miniprogramCode string) (string, int64, int
|
|
|
return false
|
|
|
}
|
|
|
}
|
|
|
- //小程序公用的账户
|
|
|
- if xcxAccountRes := util.BaseMysql.SelectBySqlByTx(tx, `select id from base_service.base_account where person_id=? and type=2 and miniprogram_code is null`, xcxPersonId); xcxAccountRes == nil {
|
|
|
- log.Println(msg, e.Phone, "查询小程序公用的账户失败")
|
|
|
- return false
|
|
|
- } else if len(*xcxAccountRes) == 0 {
|
|
|
- if xcxComAccountId = util.BaseMysql.InsertBySqlByTx(tx, `insert into base_service.base_account (person_id,type) values (?,?)`, xcxPersonId, 2); xcxComAccountId <= 0 {
|
|
|
- log.Println(msg, e.Phone, "小程序公用的账户保存失败")
|
|
|
+ // 非小程序不需要走这
|
|
|
+ if miniprogramCode != "" {
|
|
|
+ //小程序公用的账户
|
|
|
+ if xcxAccountRes := util.BaseMysql.SelectBySqlByTx(tx, `select id from base_service.base_account where person_id=? and type=2 and miniprogram_code is null`, xcxPersonId); xcxAccountRes == nil {
|
|
|
+ log.Println(msg, e.Phone, "查询小程序公用的账户失败")
|
|
|
return false
|
|
|
+ } else if len(*xcxAccountRes) == 0 {
|
|
|
+ if xcxComAccountId = util.BaseMysql.InsertBySqlByTx(tx, `insert into base_service.base_account (person_id,type) values (?,?)`, xcxPersonId, 2); xcxComAccountId <= 0 {
|
|
|
+ log.Println(msg, e.Phone, "小程序公用的账户保存失败")
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ xcxComAccountId = qu.Int64All((*xcxAccountRes)[0]["id"])
|
|
|
}
|
|
|
- } else {
|
|
|
- xcxComAccountId = qu.Int64All((*xcxAccountRes)[0]["id"])
|
|
|
- }
|
|
|
- //小程序的职位
|
|
|
- positionRes := util.BaseMysql.SelectBySqlByTx(tx, `select id from base_service.base_position where user_id=? and type=2 and miniprogram_code=?`, xcxUserId, miniprogramCode)
|
|
|
- if positionRes == nil {
|
|
|
- log.Println(msg, e.Phone, "查询小程序职位失败")
|
|
|
- return false
|
|
|
- }
|
|
|
- if len(*positionRes) == 0 {
|
|
|
- accountId := util.BaseMysql.InsertBySqlByTx(tx, `insert into base_service.base_account (person_id,type,miniprogram_code) values (?,?,?)`, xcxPersonId, 2, miniprogramCode)
|
|
|
- if accountId <= 0 {
|
|
|
- log.Println(msg, e.Phone, miniprogramCode, "小程序的账户保存失败")
|
|
|
+ //小程序的职位
|
|
|
+ positionRes := util.BaseMysql.SelectBySqlByTx(tx, `select id from base_service.base_position where user_id=? and type=2 and miniprogram_code=?`, xcxUserId, miniprogramCode)
|
|
|
+ if positionRes == nil {
|
|
|
+ log.Println(msg, e.Phone, "查询小程序职位失败")
|
|
|
return false
|
|
|
}
|
|
|
- xcxPositionId = util.BaseMysql.InsertBySqlByTx(tx, `insert into base_service.base_position (type,account_id,user_id,miniprogram_code,create_time) values (?,?,?,?,?)`, 2, accountId, xcxUserId, miniprogramCode, nowFormat)
|
|
|
- if xcxPositionId <= 0 {
|
|
|
- log.Println(msg, e.Phone, miniprogramCode, "小程序的职位保存失败")
|
|
|
- return false
|
|
|
+ if len(*positionRes) == 0 {
|
|
|
+ accountId := util.BaseMysql.InsertBySqlByTx(tx, `insert into base_service.base_account (person_id,type,miniprogram_code) values (?,?,?)`, xcxPersonId, 2, miniprogramCode)
|
|
|
+ if accountId <= 0 {
|
|
|
+ log.Println(msg, e.Phone, miniprogramCode, "小程序的账户保存失败")
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ xcxPositionId = util.BaseMysql.InsertBySqlByTx(tx, `insert into base_service.base_position (type,account_id,user_id,miniprogram_code,create_time) values (?,?,?,?,?)`, 2, accountId, xcxUserId, miniprogramCode, nowFormat)
|
|
|
+ if xcxPositionId <= 0 {
|
|
|
+ log.Println(msg, e.Phone, miniprogramCode, "小程序的职位保存失败")
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ xcxPositionId = qu.Int64All((*positionRes)[0]["id"])
|
|
|
}
|
|
|
- } else {
|
|
|
- xcxPositionId = qu.Int64All((*positionRes)[0]["id"])
|
|
|
}
|
|
|
//
|
|
|
if _id == "" {
|
|
@@ -773,7 +1250,7 @@ func (e *EquityCode) CreateUser(msg, miniprogramCode string) (string, int64, int
|
|
|
"phone": e.Phone,
|
|
|
"way": "equityCode",
|
|
|
"system": qu.GetSystem(e.R.UserAgent()),
|
|
|
- "source": "xcx",
|
|
|
+ "source": e.source,
|
|
|
"ip": qu.GetIp(e.R),
|
|
|
"user_agent": e.R.UserAgent(),
|
|
|
"create_time": nowUnix,
|
|
@@ -791,3 +1268,182 @@ func (e *EquityCode) CreateUser(msg, miniprogramCode string) (string, int64, int
|
|
|
}
|
|
|
return "", 0, 0, 0
|
|
|
}
|
|
|
+func (e *EquityCode) InitSource(name string) {
|
|
|
+ e.source = name
|
|
|
+}
|
|
|
+func (e *EquityCode) InitGiftCode(giftCode int) {
|
|
|
+ e.GiftCode = giftCode
|
|
|
+}
|
|
|
+func (e *EquityCode) InitDisChannel(disChannel string) {
|
|
|
+ e.disChannel = disChannel
|
|
|
+}
|
|
|
+func (e *EquityCode) InitUserInfo() error {
|
|
|
+ users, ok := util.MQFW.Find("user", map[string]interface{}{
|
|
|
+ "$or": []map[string]interface{}{
|
|
|
+ map[string]interface{}{
|
|
|
+ "s_phone": e.Phone,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "s_m_phone": e.Phone,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }, `{"s_phone":-1}`, `{"_id":1,"base_user_id":1,"i_vip_status":1,"i_member_status":1}`, false, 0, 1)
|
|
|
+ if !ok {
|
|
|
+ log.Println("GetUserInfo", e.Phone, "查询mog库user表失败")
|
|
|
+ return errors.New("查询mog库user表失败")
|
|
|
+ }
|
|
|
+ if users != nil && len(*users) > 0 {
|
|
|
+ e.userInfo = (*users)[0]
|
|
|
+ e.UserId = BsonIdToSId(e.userInfo["_id"])
|
|
|
+ // 补充用户小程序accountId
|
|
|
+ baseUserId := qu.Int64All(e.userInfo["base_user_id"])
|
|
|
+ baseUserRes := util.BaseMysql.SelectBySql(`select person_id from base_service.base_user where id=?`, baseUserId)
|
|
|
+ if baseUserRes == nil || len(*baseUserRes) == 0 {
|
|
|
+ log.Println("InitUserInfo", e.Phone, "baseUserId不存在", baseUserId)
|
|
|
+ return errors.New("获取用户失败")
|
|
|
+ }
|
|
|
+ xcxPersonId := qu.Int64All((*baseUserRes)[0]["person_id"])
|
|
|
+ if xcxAccountRes := util.BaseMysql.SelectBySql(`select id from base_service.base_account where person_id=? and type=2 and miniprogram_code is null`, xcxPersonId); xcxAccountRes == nil || len(*xcxAccountRes) == 0 {
|
|
|
+ log.Println("InitUserInfo", e.Phone, "查询小程序公用的账户失败 xcxPersonId:", xcxPersonId) // 说明用户没开通小程序账号
|
|
|
+ return nil
|
|
|
+ } else {
|
|
|
+ e.xcxAccountId = qu.IntAll((*xcxAccountRes)[0]["id"])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (e *EquityCode) InitCheckInfo(groupId string, groupType int, frequencyLimit int, equityId int) {
|
|
|
+ e.groupId = groupId
|
|
|
+ e.groupType = groupType
|
|
|
+ e.frequencyLimit = frequencyLimit
|
|
|
+ e.EquityId = equityId
|
|
|
+}
|
|
|
+
|
|
|
+// CheckFrequencyLimit 校验兑换码次数
|
|
|
+func (e *EquityCode) CheckFrequencyLimit() bool {
|
|
|
+ if e.userInfo == nil || len(e.userInfo) == 0 || e.frequencyLimit == 0 {
|
|
|
+ // 没有用户信息 说明是新用户 不用校验 或者没有设置验证
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ _id := qu.ObjToString(e.userInfo["_id"])
|
|
|
+ q := "select count(*) from jyactivities.equity_record where userId=? and equityId=?"
|
|
|
+ if int(util.BaseMysql.CountBySql(q, _id, e.EquityId)) >= e.frequencyLimit {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+// CheckUserGroup 校验用户群组
|
|
|
+func (e *EquityCode) CheckUserGroup() bool {
|
|
|
+ if e.groupType == groupTypeAll { //全部
|
|
|
+ //不用校验
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ groupIdList := strings.Split(e.groupId, ",")
|
|
|
+ if len(groupIdList) == 0 { // 选择群组但是群组id为空 配置有误
|
|
|
+ log.Printf("EquityId[%v]: 群组id有误 \n", e.EquityId)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if e.userInfo == nil || len(e.userInfo) == 0 {
|
|
|
+ // 没有用户信息 说明是还没有创建用户 所以不用匹配标签群组
|
|
|
+ if e.groupType == groupTypeTags { // 直接返回
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ // 判断后台群组是否包含付费群组(目前付费指超级订阅、大会员 后续如果有其他付费群组这里需要同步调整)
|
|
|
+ // 包含付费用户群组则新用户不符合条件 所以直接返回
|
|
|
+ for i := 0; i < len(groupIdList); i++ {
|
|
|
+ if _, ok := PayBackGroup[groupIdList[i]]; ok {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ // 已有用户 正常判断
|
|
|
+ switch e.groupType {
|
|
|
+ case groupTypeTags:
|
|
|
+ return e.checkTagsGroup()
|
|
|
+ case groupTypeBackGroup:
|
|
|
+ return e.checkBackGroup()
|
|
|
+ default:
|
|
|
+ log.Printf("异常分组类型:equityId[%v] 异常类型[%v]\n", e.EquityId, e.groupType)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+}
|
|
|
+func (e *EquityCode) checkTagsGroup() bool {
|
|
|
+ // 用户id 不是mongoId 直接返回
|
|
|
+ // 选择标签分组时 只处理个人身份领取优惠券
|
|
|
+ selectGroupId := []int64{}
|
|
|
+ groupIdList := strings.Split(e.groupId, ",")
|
|
|
+ for i := 0; i < len(groupIdList); i++ {
|
|
|
+ tmpId, err := strconv.ParseInt(groupIdList[i], 10, 64)
|
|
|
+ if err != nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ selectGroupId = append(selectGroupId, tmpId)
|
|
|
+ }
|
|
|
+ if len(selectGroupId) == 0 {
|
|
|
+ log.Println("checkTagsGroup 所选用户分组有误", e.EquityId, e.groupType, e.groupId)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ uic := util.NewUserIdConstructor(selectGroupId, 0, util.ClickhousePubTags, util.ConvertlabMysql)
|
|
|
+ baseUserId := qu.Int64All(e.userInfo["base_user_id"])
|
|
|
+ count := uic.CountUser(baseUserId)
|
|
|
+ return qu.If(count > 0, true, false).(bool)
|
|
|
+}
|
|
|
+func (e *EquityCode) checkBackGroup() bool {
|
|
|
+ groupIdList := strings.Split(e.groupId, ",")
|
|
|
+ xcxNGroupId := []interface{}{}
|
|
|
+ xcxNGroupIdParam := []string{}
|
|
|
+ userAttributesMap := e.findAttributesMap()
|
|
|
+ //xcxHGroupId := []string{}
|
|
|
+ for i := 0; i < len(groupIdList); i++ {
|
|
|
+ if strings.HasPrefix(groupIdList[i], "xcx") {
|
|
|
+ xcxGroupIdList := strings.Split(groupIdList[i], "-")
|
|
|
+ if len(xcxGroupIdList) == 2 && xcxGroupIdList[1] == "n" { // 非xx行业的 多个时匹配上一个即为匹配成功
|
|
|
+ xcxNGroupId = append(xcxNGroupId, xcxGroupIdList[2])
|
|
|
+ xcxNGroupIdParam = append(xcxNGroupIdParam)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if userAttributesMap[groupIdList[i]] { // 匹配上一个就成功 不用再继续了
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 一个都没有匹配上剑鱼会员身份 再来看一下是否有配置小程序的
|
|
|
+ if len(xcxNGroupId) > 0 {
|
|
|
+ if e.xcxAccountId == 0 {
|
|
|
+ // 没有小程序账户 直接匹配上非xx行业
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ // 匹配小程序身份
|
|
|
+ return e.checkXcxNPower(xcxNGroupId, xcxNGroupIdParam)
|
|
|
+ }
|
|
|
+ return false
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// 获取用户身份所属后台群组
|
|
|
+func (e *EquityCode) findAttributesMap() (attributesMap map[string]bool) {
|
|
|
+ attributesMap = map[string]bool{}
|
|
|
+ vipStatus := e.userInfo["i_vip_status"]
|
|
|
+ memberStatus := e.userInfo["i_member_status"]
|
|
|
+ if qu.IntAll(vipStatus) <= 0 && qu.IntAll(memberStatus) > 0 { // 仅大会员
|
|
|
+ attributesMap[BackGroupLimitM] = true
|
|
|
+ } else if qu.IntAll(vipStatus) > 0 && qu.IntAll(memberStatus) <= 0 { // 仅超级订阅
|
|
|
+ attributesMap[BackGroupLimitV] = true
|
|
|
+ } else if qu.IntAll(vipStatus) > 0 && qu.IntAll(memberStatus) > 0 { // 超级订阅且大会员
|
|
|
+ attributesMap[BackGroupLimitMv] = true
|
|
|
+ } else { // 非超级订阅非大会员
|
|
|
+ attributesMap[BackGroupLimitNMV] = true
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 判断非xx行业或非xx。。。行业小程序会员
|
|
|
+func (e *EquityCode) checkXcxNPower(xcxNGroupId []interface{}, xcxNGroupIdParam []string) bool {
|
|
|
+ value := []interface{}{e.xcxAccountId}
|
|
|
+ value = append(value, xcxNGroupId...)
|
|
|
+ q := fmt.Sprintf("select count(distinct(m.industry_code)) from debris_product.user_power up left join debris_product.miniprogram m on (up.miniprogram_code=m.code) where up.start_time<=now() and up.end_time>=now() and up.account_id=? and up.industry_code in (%s) ", strings.Join(xcxNGroupIdParam, ","))
|
|
|
+ //查询结果数量小于查询的行业数量,说明存在不是xx行业的 表示匹配成功
|
|
|
+ return util.BaseMysql.CountBySql(q, xcxNGroupId...) < int64(len(xcxNGroupId))
|
|
|
+}
|