wanghuidong 4 years ago
parent
commit
56db6b2b34
2 changed files with 49 additions and 8 deletions
  1. 8 1
      lock/interface.go
  2. 41 7
      test/project/project_interface_test.go

+ 8 - 1
lock/interface.go

@@ -7,6 +7,7 @@ type Cost interface {
 	Deduction() //扣费(剩余量|账户余额)
 	Before() bool
 	After()
+	GetData() (interface{}, int, error)
 }
 
 type LeftNumCost struct {
@@ -15,6 +16,7 @@ type LeftNumCost struct {
 	LeftNum              int
 	ProductType          int
 	DataNumLimitOneTimes int
+	GetData1             func() (interface{}, int, error)
 }
 type AccountBalanceCost struct {
 	AppID          string
@@ -23,6 +25,7 @@ type AccountBalanceCost struct {
 }
 
 func (l *LeftNumCost) Deduction() {
+
 }
 
 func (l *LeftNumCost) Before() bool {
@@ -41,6 +44,10 @@ func (l *LeftNumCost) Before() bool {
 	return true
 }
 
+func (l *LeftNumCost) GetData() (interface{}, int, error) {
+	return l.GetData1()
+}
+
 func (l *LeftNumCost) After() {
 	switch l.ProductType {
 	case 0:
@@ -52,7 +59,7 @@ func (a *AccountBalanceCost) Deduction() {
 
 }
 func (a *AccountBalanceCost) Before() bool {
-
+	return false
 }
 func (a *AccountBalanceCost) After() {
 

+ 41 - 7
test/project/project_interface_test.go

@@ -1,17 +1,51 @@
 package project
 
 import (
+	"sfis/db"
 	"sfis/lock"
+	"sfis/model"
+	"sfis/service"
 	"testing"
 )
 
+var (
+	projectNameArray = []string{"河南大学", "工程建设", "医疗器械"}
+	winnerArray      = []string{""}
+	zbRqArray        = []string{""}
+)
+
 func Test_ProjectInterface(t *testing.T) {
-	leftNumCost := &lock.LeftNumCost{
-		AppID:                "sfPQRYRQMAAwcGBwYBCgcA",
-		ProductID:            1003,
-		LeftNum:              199999,
-		ProductType:          1,
-		DataNumLimitOneTimes: 100,
+	appID := "sfPQRYRQMAAwcGBwYBCgcA"
+	//userName := "赛博英杰"
+	productID := 1003
+	lock.MainLock.Lock()
+	userLock := lock.UserLockMap[appID]
+	lock.MainLock.Unlock()
+	userLock.Lock()
+	userProduct := &model.UserProduct{}
+	db.GetSFISDB().First(userProduct, &model.UserProduct{AppID: appID, ProductID: productID})
+
+	check(&lock.LeftNumCost{
+		AppID:                appID,
+		ProductID:            productID,
+		LeftNum:              userProduct.LeftNum,
+		ProductType:          0,
+		DataNumLimitOneTimes: userProduct.DataNumLimitOneTimes,
+		GetData1: func() (i interface{}, i2 int, err error) {
+			return service.ProjectListData("", "", "", false)
+		},
+	})
+}
+
+func check(cost1 lock.Cost) {
+	if b := cost1.Before(); b {
+		data, status, _ := cost1.GetData()
+		if data != nil {
+			data := data.([]map[string]interface{})
+			if len(data) > 0 {
+				cost1.Deduction()
+				cost1.After()
+			}
+		}
 	}
-	leftNumCost.Before()
 }