Răsfoiți Sursa

feat: 企业权益状态调整

zhangxinlei1996 2 ani în urmă
părinte
comite
ef0d34675e
2 a modificat fișierele cu 25 adăugiri și 12 ștergeri
  1. 23 11
      service/power.go
  2. 2 1
      service/power_test.go

+ 23 - 11
service/power.go

@@ -3,6 +3,7 @@ package service
 import (
 	"encoding/json"
 	"fmt"
+	"log"
 	"math/rand"
 	"strings"
 	"time"
@@ -179,7 +180,7 @@ func (this *PowerService) Power(userid string, baseUserId, accountId, entId, pos
 		} else if positionType == 1 {
 			entnicheUserId := this.GetEntnicheUserId(entId, phone)
 			//免费
-			fdata, ok := this.Conn.MgoJy.FindOne("entniche_rule", map[string]interface{}{
+			fdata, _ := this.Conn.MgoJy.FindOne("entniche_rule", map[string]interface{}{
 				"i_ent":    entId,
 				"i_userid": entnicheUserId,
 				"i_type":   2, //0:商机管理 1:超级订阅/大会员 2:免费
@@ -191,7 +192,7 @@ func (this *PowerService) Power(userid string, baseUserId, accountId, entId, pos
 				free.IsUpgrade = true //新免费用户
 			}
 			//企业
-			edata, ok := this.Conn.MgoJy.FindOne("entniche_rule", map[string]interface{}{
+			edata, _ := this.Conn.MgoJy.FindOne("entniche_rule", map[string]interface{}{
 				"i_ent":    entId,
 				"i_userid": entnicheUserId,
 				"i_type":   1, //0:商机管理 1:超级订阅/大会员
@@ -199,16 +200,20 @@ func (this *PowerService) Power(userid string, baseUserId, accountId, entId, pos
 					"$gt": time.Now().Unix(),
 				},
 			})
-			if ok && edata != nil && len(*edata) > 0 {
+			eudata, _ := this.Conn.MgoJy.FindOne("ent_user", map[string]interface{}{
+				"i_entid":  entId,
+				"i_userid": entnicheUserId,
+			})
+			if eudata != nil && len(*eudata) > 0 {
 				haskey := false
-				status := common.Int64All((*edata)["i_status"])
-				starttime := common.Int64All((*edata)["l_starttime"])
-				endtime := common.Int64All((*edata)["l_endtime"])
-				o_entniche := common.ObjToMap((*edata)["o_entniche"])
-				if (*o_entniche)["a_items"] != nil {
-					if arr, ok := (*o_entniche)["a_items"].([]interface{}); ok {
-						a_items := common.ObjArrToMapArr(arr)
-						haskey = HasKey(a_items)
+				o_entniche := &map[string]interface{}{}
+				if edata != nil && len(*edata) > 0 {
+					o_entniche = common.ObjToMap((*edata)["o_entniche"])
+					if (*o_entniche)["a_items"] != nil {
+						if arr, ok := (*o_entniche)["a_items"].([]interface{}); ok {
+							a_items := common.ObjArrToMapArr(arr)
+							haskey = HasKey(a_items)
+						}
 					}
 				}
 				//获取用户是什么版本权益
@@ -227,6 +232,9 @@ func (this *PowerService) Power(userid string, baseUserId, accountId, entId, pos
 							buyerclasscount := common.Int64All((*oBuyset)["buyerclasscount"])
 							newcitys, _ := (*oBuyset)["newcitys"].([]interface{})
 							newcitysArr := common.InterfaceArrToint64Arr(newcitys)
+							status := common.Int64All((*eudata)["i_vip_status"])
+							starttime := common.Int64All((*eudata)["l_vip_starttime"])
+							endtime := common.Int64All((*eudata)["l_vip_endtime"])
 							vip = &entity.Vip{
 								Status:          status,
 								StartTime:       starttime,
@@ -241,6 +249,9 @@ func (this *PowerService) Power(userid string, baseUserId, accountId, entId, pos
 							}
 						} else if strings.Contains(product_type, entity.ProductType_member) {
 							member.PowerType = 2
+							status := common.Int64All((*eudata)["i_member_status"])
+							starttime := common.Int64All((*eudata)["l_member_starttime"])
+							endtime := common.Int64All((*eudata)["l_member_endtime"])
 							member = &entity.Member{
 								Status:     status,
 								StartTime:  starttime,
@@ -350,6 +361,7 @@ func (this *PowerService) Power(userid string, baseUserId, accountId, entId, pos
 			free.IsFree = false
 		}
 	}
+	log.Println(vip.Status, vip.StartTime, vip.EndTime)
 	userPower = entity.Power{
 		Vip:      vip,
 		Member:   member,

+ 2 - 1
service/power_test.go

@@ -108,7 +108,8 @@ func TestPowerService_Power(t *testing.T) {
 			this := &PowerService{
 				Conn: NewPowerService.Conn,
 			}
-			if got := this.Power("6103bb722abfa5f4d81bb1d1", 69871, 0, 15051, 0, 2403); !reflect.DeepEqual(got, tt.want) {
+			if got := this.Power("637dd8315c0c8e9c47c9bf0a", 335487, 60052, 15470, 1, 60040); !reflect.DeepEqual(got, tt.want) {
+				log.Println(got.Vip.Status)
 				t.Errorf("Power() = %v, want %v", got, tt.want)
 			}
 		})