|
@@ -1,18 +1,18 @@
|
|
|
package entity
|
|
|
|
|
|
import (
|
|
|
- "encoding/json"
|
|
|
- "fmt"
|
|
|
- "jy/src/jfw/modules/subscribepay/src/config"
|
|
|
- "jy/src/jfw/modules/subscribepay/src/util"
|
|
|
- "log"
|
|
|
- "strconv"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "jy/src/jfw/modules/subscribepay/src/config"
|
|
|
+ "jy/src/jfw/modules/subscribepay/src/util"
|
|
|
+ "log"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
|
|
|
- qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
- . "app.yhyue.com/moapp/jybase/date"
|
|
|
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
+ qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
+ . "app.yhyue.com/moapp/jybase/date"
|
|
|
+ "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
)
|
|
|
|
|
|
type memberStruct struct{}
|
|
@@ -21,197 +21,178 @@ var MemberStruct memberStruct
|
|
|
var Bigmember_serice map[int]map[int]int //权益 k:子id ; v:map[int]int{父id:年数量}
|
|
|
|
|
|
func init() {
|
|
|
- log.Println("初始化大会员权益")
|
|
|
- //初始化用户权益
|
|
|
- member_serice := map[int]map[int]int{}
|
|
|
- if rdata := util.Mysql.SelectBySql(`SELECT id,s_name,i_pid,s_count_year FROM bigmember_service`); rdata != nil && len(*rdata) > 0 {
|
|
|
- for _, v := range *rdata {
|
|
|
- sid := qutil.IntAll(v["id"])
|
|
|
- pid := qutil.IntAll(v["i_pid"])
|
|
|
- count_year := qutil.IntAll(v["s_count_year"])
|
|
|
- // log.Println(pid, sid, count_year)
|
|
|
- if pid != 0 {
|
|
|
- member_serice[sid] = map[int]int{
|
|
|
- pid: count_year,
|
|
|
- }
|
|
|
- } else {
|
|
|
- member_serice[sid] = map[int]int{
|
|
|
- sid: count_year,
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- Bigmember_serice = member_serice
|
|
|
- log.Println("初始化大会员权益已结束")
|
|
|
+ log.Println("初始化大会员权益")
|
|
|
+ //初始化用户权益
|
|
|
+ member_serice := map[int]map[int]int{}
|
|
|
+ if rdata := util.Mysql.SelectBySql(`SELECT id,s_name,i_pid,s_count_year FROM bigmember_service`); rdata != nil && len(*rdata) > 0 {
|
|
|
+ for _, v := range *rdata {
|
|
|
+ sid := qutil.IntAll(v["id"])
|
|
|
+ pid := qutil.IntAll(v["i_pid"])
|
|
|
+ count_year := qutil.IntAll(v["s_count_year"])
|
|
|
+ // log.Println(pid, sid, count_year)
|
|
|
+ if pid != 0 {
|
|
|
+ member_serice[sid] = map[int]int{
|
|
|
+ pid: count_year,
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ member_serice[sid] = map[int]int{
|
|
|
+ sid: count_year,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Bigmember_serice = member_serice
|
|
|
+ log.Println("初始化大会员权益已结束")
|
|
|
}
|
|
|
|
|
|
// 大会员支付完成回调方法
|
|
|
func (m *memberStruct) PayCallBack(param *CallBackParam) bool {
|
|
|
- orderdata := util.Mysql.FindOne("dataexport_order", param.GetPaySuccessOrderQuery(), "id,filter,order_code,order_status,user_id,vip_type,prepay_time", "")
|
|
|
- if orderdata == nil {
|
|
|
- return false
|
|
|
- }
|
|
|
- userId := qutil.ObjToString((*orderdata)["user_id"])
|
|
|
- if qutil.IntAll((*orderdata)["order_status"]) == 0 {
|
|
|
- now := time.Now()
|
|
|
- nowFormat := FormatDate(&now, Date_Full_Layout)
|
|
|
- var filter map[string]interface{}
|
|
|
- if err := json.Unmarshal([]byte(qutil.ObjToString((*orderdata)["filter"])), &filter); err != nil {
|
|
|
- log.Println("大会员支付成功json.Unmarshal出错", err)
|
|
|
- } else {
|
|
|
- cycle := qutil.IntAll(filter["cycle"])
|
|
|
- level := qutil.IntAll(filter["level"])
|
|
|
- var enddate = time.Now()
|
|
|
- if level == 4 { //试用用户 试用七天
|
|
|
- enddate = time.Date(now.Year(), now.Month(), now.Day()+cycle, 23, 59, 59, 0, time.Local)
|
|
|
- } else {
|
|
|
- enddate = time.Date(now.Year()+cycle, now.Month(), now.Day(), 23, 59, 59, 0, time.Local)
|
|
|
- }
|
|
|
- normal_member(level, enddate, userId, 0, 0, 0)
|
|
|
- update := util.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
- "id": (*orderdata)["id"],
|
|
|
- }, map[string]interface{}{
|
|
|
- "pay_money": param.CashFee,
|
|
|
- "pay_time": nowFormat,
|
|
|
- "order_status": 1,
|
|
|
- "vip_starttime": nowFormat,
|
|
|
- "vip_endtime": FormatDate(&enddate, Date_Full_Layout),
|
|
|
- //支付成功后更新成支付成功的out_trade_no 避免多人支付重复刷新字段
|
|
|
- "out_trade_no": param.OutTradeno,
|
|
|
- })
|
|
|
- if update {
|
|
|
- util.MsgRemind.BigMemberPaySuccess(qutil.IntAll((*orderdata)["id"]), qutil.ObjToString((*orderdata)["order_code"]), qutil.ObjToString((*orderdata)["user_id"]), qutil.ObjToString((*orderdata)["prepay_time"]), qutil.IntAllDef((*orderdata)["vip_type"], -1))
|
|
|
- //取消其他订单
|
|
|
- go PayCancel(userId, "大会员", "")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return true
|
|
|
+ orderdata := util.Mysql.FindOne("dataexport_order", param.GetPaySuccessOrderQuery(), "id,filter,order_code,order_status,user_id,vip_type,prepay_time", "")
|
|
|
+ if orderdata == nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ userId := qutil.ObjToString((*orderdata)["user_id"])
|
|
|
+ if qutil.IntAll((*orderdata)["order_status"]) == 0 {
|
|
|
+ now := time.Now()
|
|
|
+ nowFormat := FormatDate(&now, Date_Full_Layout)
|
|
|
+ var filter map[string]interface{}
|
|
|
+ if err := json.Unmarshal([]byte(qutil.ObjToString((*orderdata)["filter"])), &filter); err != nil {
|
|
|
+ log.Println("大会员支付成功json.Unmarshal出错", err)
|
|
|
+ } else {
|
|
|
+ cycle := qutil.IntAll(filter["cycle"])
|
|
|
+ level := qutil.IntAll(filter["level"])
|
|
|
+ var enddate = time.Now()
|
|
|
+ if level == 4 { //试用用户 试用七天
|
|
|
+ enddate = time.Date(now.Year(), now.Month(), now.Day()+cycle, 23, 59, 59, 0, time.Local)
|
|
|
+ } else {
|
|
|
+ enddate = time.Date(now.Year()+cycle, now.Month(), now.Day(), 23, 59, 59, 0, time.Local)
|
|
|
+ }
|
|
|
+ normal_member(level, enddate, userId, 0, 0, 0)
|
|
|
+ update := util.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
+ "id": (*orderdata)["id"],
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "pay_money": param.CashFee,
|
|
|
+ "pay_time": nowFormat,
|
|
|
+ "order_status": 1,
|
|
|
+ "vip_starttime": nowFormat,
|
|
|
+ "vip_endtime": FormatDate(&enddate, Date_Full_Layout),
|
|
|
+ //支付成功后更新成支付成功的out_trade_no 避免多人支付重复刷新字段
|
|
|
+ "out_trade_no": param.OutTradeno,
|
|
|
+ })
|
|
|
+ if update {
|
|
|
+ util.MsgRemind.BigMemberPaySuccess(qutil.IntAll((*orderdata)["id"]), qutil.ObjToString((*orderdata)["order_code"]), qutil.ObjToString((*orderdata)["user_id"]), qutil.ObjToString((*orderdata)["prepay_time"]), qutil.IntAllDef((*orderdata)["vip_type"], -1))
|
|
|
+ //取消其他订单
|
|
|
+ go PayCancel(userId, "大会员", "")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
func normal_member(level int, enddate time.Time, userId string, positionType, entId, entUserId int64) {
|
|
|
- //修改用户表权限
|
|
|
- set := map[string]interface{}{}
|
|
|
- if positionType == 0 {
|
|
|
- set = map[string]interface{}{
|
|
|
- "i_member_status": level,
|
|
|
- "i_member_starttime": time.Now().Unix(),
|
|
|
- "i_member_endtime": enddate.Unix(),
|
|
|
- "o_member_jy.i_wxpush": 1,
|
|
|
- }
|
|
|
- } else {
|
|
|
- set = map[string]interface{}{
|
|
|
- "i_status": level,
|
|
|
- "i_starttime": time.Now().Unix(),
|
|
|
- "i_endtime": enddate.Unix(),
|
|
|
- "o_entniche.i_wxpush": 1,
|
|
|
- }
|
|
|
- }
|
|
|
- if level == 4 { //试用用户
|
|
|
- set["i_member_trial"] = 1 //试用标识
|
|
|
- } else {
|
|
|
- //查看当前用户是否是试用用户 正在试用中(大会员状态ing)
|
|
|
- userInfo := util.Compatible.Select(userId, `{"o_vipjy"}`)
|
|
|
- if userInfo != nil && *userInfo != nil {
|
|
|
- if (*userInfo)["i_member_status"] != nil && qutil.IntAll((*userInfo)["i_member_status"]) > 0 {
|
|
|
- //禁用当前大会员服务
|
|
|
- util.Mysql.UpdateOrDeleteBySql(`UPDATE `+jy.BigmemberUserPowerTable+` a SET a.i_frequency = 0 , a.i_status = -1, a.l_updatetime=? WHERE a.s_userid = ?`, NowFormat(Date_Full_Layout), userId)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if positionType == 0 {
|
|
|
- util.MQFW.UpdateById("user", userId, map[string]interface{}{
|
|
|
- "$set": set,
|
|
|
- })
|
|
|
- } else {
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": entUserId,
|
|
|
- "i_entid": entId,
|
|
|
- "i_type": 1,
|
|
|
- }
|
|
|
- util.MQFW.Update("entniche_rule", query, map[string]interface{}{
|
|
|
- "$set": set,
|
|
|
- }, true, false)
|
|
|
- }
|
|
|
- //更新大会员用户服务表
|
|
|
- bigmember_combo_list := util.Mysql.SelectBySql(`SELECT * FROM bigmember_combo a WHERE a.id = ?`, level)
|
|
|
- serviceCode := "" //大会员服务id集合
|
|
|
- if len(*bigmember_combo_list) > 0 {
|
|
|
- list := (*bigmember_combo_list)[0]
|
|
|
- serviceCode = list["s_servers"].(string)
|
|
|
- }
|
|
|
- if serviceCode != "" {
|
|
|
- for _, v := range strings.Split(serviceCode, ",") {
|
|
|
- var s_serviceid = v
|
|
|
- var frequency = 0
|
|
|
- sid, _ := strconv.Atoi(v)
|
|
|
- if Bigmember_serice[sid] != nil {
|
|
|
- for k, v := range Bigmember_serice[sid] {
|
|
|
- s_serviceid = strconv.Itoa(k)
|
|
|
- frequency = v
|
|
|
- }
|
|
|
- }
|
|
|
- if util.Mysql.CountBySql(`select count(*) from `+jy.BigmemberUserPowerTable+` where s_userid=? and s_serviceid=?`, userId, v) == 0 {
|
|
|
- insert := map[string]interface{}{
|
|
|
- "s_userid": userId,
|
|
|
- "s_serviceid": s_serviceid,
|
|
|
- "i_frequency": frequency,
|
|
|
- "l_starttime": NowFormat(Date_Full_Layout),
|
|
|
- "l_endtime": FormatDate(&enddate, Date_Full_Layout),
|
|
|
- "i_status": 0,
|
|
|
- "l_createtime": NowFormat(Date_Full_Layout),
|
|
|
- "l_updatetime": NowFormat(Date_Full_Layout),
|
|
|
- "s_smainid": v,
|
|
|
- }
|
|
|
- order_id := util.Mysql.Insert(jy.BigmemberUserPowerTable, insert)
|
|
|
- if order_id == 0 {
|
|
|
- log.Println("保存出错:", userId, "---", v)
|
|
|
- }
|
|
|
- } else {
|
|
|
- query := map[string]interface{}{
|
|
|
- "s_userid": userId,
|
|
|
- "s_serviceid": s_serviceid,
|
|
|
- }
|
|
|
- update := map[string]interface{}{
|
|
|
- "i_status": 0,
|
|
|
- "i_frequency": frequency,
|
|
|
- "l_updatetime": NowFormat(Date_Full_Layout),
|
|
|
- "l_endtime": FormatDate(&enddate, Date_Full_Layout),
|
|
|
- "s_smainid": v,
|
|
|
- }
|
|
|
- if !util.Mysql.Update(jy.BigmemberUserPowerTable, query, update) {
|
|
|
- log.Println("更新大会员用户服务表出错:", userId, v)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //redis 存储缓存
|
|
|
- go func() {
|
|
|
- if !jy.ClearBigVipUserPower(userId) {
|
|
|
- log.Println("userid:", userId, "清除redis缓存失败-")
|
|
|
- }
|
|
|
- }()
|
|
|
- } else {
|
|
|
- log.Println("查询 大会员套餐 信息出错:", userId, ";大会员等级:", level)
|
|
|
- }
|
|
|
+ //修改用户表权限
|
|
|
+ set := map[string]interface{}{}
|
|
|
+ set = map[string]interface{}{
|
|
|
+ "i_member_status": level,
|
|
|
+ "i_member_starttime": time.Now().Unix(),
|
|
|
+ "i_member_endtime": enddate.Unix(),
|
|
|
+ "o_member_jy.i_wxpush": 1,
|
|
|
+ }
|
|
|
+
|
|
|
+ if level == 4 { //试用用户
|
|
|
+ set["i_member_trial"] = 1 //试用标识
|
|
|
+ } else {
|
|
|
+ //查看当前用户是否是试用用户 正在试用中(大会员状态ing)
|
|
|
+ userInfo := util.Compatible.Select(userId, `{"o_vipjy"}`)
|
|
|
+ if userInfo != nil && *userInfo != nil {
|
|
|
+ if (*userInfo)["i_member_status"] != nil && qutil.IntAll((*userInfo)["i_member_status"]) > 0 {
|
|
|
+ //禁用当前大会员服务
|
|
|
+ util.Mysql.UpdateOrDeleteBySql(`UPDATE `+jy.BigmemberUserPowerTable+` a SET a.i_frequency = 0 , a.i_status = -1, a.l_updatetime=? WHERE a.s_userid = ?`, NowFormat(Date_Full_Layout), userId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ util.Compatible.Update(userId, map[string]interface{}{
|
|
|
+ "$set": set,
|
|
|
+ })
|
|
|
+ //更新大会员用户服务表
|
|
|
+ bigmember_combo_list := util.Mysql.SelectBySql(`SELECT * FROM bigmember_combo a WHERE a.id = ?`, level)
|
|
|
+ serviceCode := "" //大会员服务id集合
|
|
|
+ if len(*bigmember_combo_list) > 0 {
|
|
|
+ list := (*bigmember_combo_list)[0]
|
|
|
+ serviceCode = list["s_servers"].(string)
|
|
|
+ }
|
|
|
+ if serviceCode != "" {
|
|
|
+ for _, v := range strings.Split(serviceCode, ",") {
|
|
|
+ var s_serviceid = v
|
|
|
+ var frequency = 0
|
|
|
+ sid, _ := strconv.Atoi(v)
|
|
|
+ if Bigmember_serice[sid] != nil {
|
|
|
+ for k, v := range Bigmember_serice[sid] {
|
|
|
+ s_serviceid = strconv.Itoa(k)
|
|
|
+ frequency = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if util.Mysql.CountBySql(`select count(*) from `+jy.BigmemberUserPowerTable+` where s_userid=? and s_serviceid=?`, userId, v) == 0 {
|
|
|
+ insert := map[string]interface{}{
|
|
|
+ "s_userid": userId,
|
|
|
+ "s_serviceid": s_serviceid,
|
|
|
+ "i_frequency": frequency,
|
|
|
+ "l_starttime": NowFormat(Date_Full_Layout),
|
|
|
+ "l_endtime": FormatDate(&enddate, Date_Full_Layout),
|
|
|
+ "i_status": 0,
|
|
|
+ "l_createtime": NowFormat(Date_Full_Layout),
|
|
|
+ "l_updatetime": NowFormat(Date_Full_Layout),
|
|
|
+ "s_smainid": v,
|
|
|
+ }
|
|
|
+ order_id := util.Mysql.Insert(jy.BigmemberUserPowerTable, insert)
|
|
|
+ if order_id == 0 {
|
|
|
+ log.Println("保存出错:", userId, "---", v)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "s_userid": userId,
|
|
|
+ "s_serviceid": s_serviceid,
|
|
|
+ }
|
|
|
+ update := map[string]interface{}{
|
|
|
+ "i_status": 0,
|
|
|
+ "i_frequency": frequency,
|
|
|
+ "l_updatetime": NowFormat(Date_Full_Layout),
|
|
|
+ "l_endtime": FormatDate(&enddate, Date_Full_Layout),
|
|
|
+ "s_smainid": v,
|
|
|
+ }
|
|
|
+ if !util.Mysql.Update(jy.BigmemberUserPowerTable, query, update) {
|
|
|
+ log.Println("更新大会员用户服务表出错:", userId, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //redis 存储缓存
|
|
|
+ go func() {
|
|
|
+ if !jy.ClearBigVipUserPower(userId) {
|
|
|
+ log.Println("userid:", userId, "清除redis缓存失败-")
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ } else {
|
|
|
+ log.Println("查询 大会员套餐 信息出错:", userId, ";大会员等级:", level)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func (m *memberStruct) GetMoney(userId string, level, cycle int) int {
|
|
|
- if level > 7 || cycle < 1 {
|
|
|
- log.Println(userId, "大会员订单level、cycle参数不合法", level, cycle)
|
|
|
- return -1
|
|
|
- }
|
|
|
- var price float64
|
|
|
- price = config.MemberConfig.Price[fmt.Sprintf("%v", level)] * float64(cycle)
|
|
|
- if level == 4 {
|
|
|
- price = config.MemberConfig.Price[fmt.Sprintf("%v", level)]
|
|
|
- }
|
|
|
- log.Println(level, " : ", price)
|
|
|
- if price == 0 {
|
|
|
- log.Println(userId, "大会员订单获取price错误")
|
|
|
- return -1
|
|
|
- }
|
|
|
- if price < 1 {
|
|
|
- price = 1
|
|
|
- }
|
|
|
- return int(price)
|
|
|
+ if level > 7 || cycle < 1 {
|
|
|
+ log.Println(userId, "大会员订单level、cycle参数不合法", level, cycle)
|
|
|
+ return -1
|
|
|
+ }
|
|
|
+ var price float64
|
|
|
+ price = config.MemberConfig.Price[fmt.Sprintf("%v", level)] * float64(cycle)
|
|
|
+ if level == 4 {
|
|
|
+ price = config.MemberConfig.Price[fmt.Sprintf("%v", level)]
|
|
|
+ }
|
|
|
+ log.Println(level, " : ", price)
|
|
|
+ if price == 0 {
|
|
|
+ log.Println(userId, "大会员订单获取price错误")
|
|
|
+ return -1
|
|
|
+ }
|
|
|
+ if price < 1 {
|
|
|
+ price = 1
|
|
|
+ }
|
|
|
+ return int(price)
|
|
|
}
|