wangchuanjin 1 ano atrás
pai
commit
d0c6dfcd1b

+ 90 - 0
openPower/config.json

@@ -0,0 +1,90 @@
+{
+	"etcdAddr": ["192.168.3.206:2379"],
+	"mongodb": {
+	    "main": {
+	      "address": "192.168.3.206:27080",
+	      "size": 1,
+	      "dbName": "qfw"
+	    }
+  	},
+  	"mysql": {
+    	"main": {
+	      	"dbName": "jianyu",
+	      	"address": "192.168.3.11:3366",
+	      	"userName": "root",
+	      	"passWord": "Topnet123",
+	      	"maxOpenConns": 2,
+	      	"maxIdleConns": 2
+	    },
+	    "base": {
+	      	"dBName": "base_service",
+	      	"address" : "192.168.3.14:4000",
+	      	"userName": "root",
+	      	"passWord": "=PDT49#80Z!RVv52_z",
+	     	"maxOpenConns": 2,
+	      	"maxIdleConns": 2
+	    }
+  	},
+	"products": {
+		"bi_yllyh": {
+			"Name": "医疗领域化BI",
+			"GoodsCode": "special_nosale_goods",
+			"GoodsSpecId": 14,
+			"All": {"医疗领域化BI": "bi_yllyh"}
+		},
+		"bi_ldx": {
+			"Name": "立达信BI分析工具",
+			"GoodsCode": "special_nosale_goods",
+			"GoodsSpecId": 15,
+			"All": {"立达信BI分析工具": "bi_ldx"}
+		},
+		"bi_hnyd_fx": {
+			"Name": "bi_河南移动_数据分析",
+			"GoodsCode": "special_nosale_goods",
+			"GoodsSpecId": 16,
+			"All": {"bi_河南移动_数据分析": "bi_hnyd_fx"}
+		},
+		"bi_hnyd_gl": {
+			"Name": "bi_河南移动_数据管理",
+			"GoodsCode": "special_nosale_goods",
+			"GoodsSpecId": 17,
+			"All": {"bi_河南移动_数据管理": "bi_hnyd_gl"}
+		},
+		"ai_helper": {
+			"Name": "智能助手",
+			"GoodsCode": "ai_helper",
+			"GoodsSpecId": 18,
+			"All": {"智能助手": "ai_helper"}
+		},
+		"bi_dx_gl": {
+			"Name": "bi_电销系统-管理权限",
+			"GoodsCode": "special_nosale_goods",
+			"GoodsSpecId": 19,
+			"All": {"bi_电销系统-管理权限": "bi_dx_gl"}
+		},
+		"bi_dx_ck": {
+			"Name": "bi_电销系统-查看权限",
+			"GoodsCode": "special_nosale_goods",
+			"GoodsSpecId": 20,
+			"All": {"bi_电销系统-查看权限": "bi_dx_ck"}
+		},
+		"cb_zy_code": {
+			"Name": "参标项目管理",
+			"GoodsCode": "special_nosale_goods",
+			"GoodsSpecId": 22,
+			"All": {"参标项目管理": "cb_zy_code"}
+		},
+		"bi_dx_fx": {
+			"Name": "bi_电销分析",
+			"GoodsCode": "special_nosale_goods",
+			"GoodsSpecId": 23,
+			"All": {"参标项目管理": "bi_dx_fx"}
+		},
+		"bi_yx": {
+			"Name": "bi_营销",
+			"GoodsCode": "special_nosale_goods",
+			"GoodsSpecId": 24,
+			"All": {"bi_营销": "bi_yx"}
+		}
+	}
+}

BIN
openPower/openPower


+ 71 - 86
openPower/openPower.go

@@ -35,44 +35,53 @@ var (
 	middleground *Middleground
 	allEntity    = map[string]Entity{
 		"yxy": &Yxy{},
-		"bi_yllyh": &Common{
-			Name:        "医疗领域化BI",
-			GoodsCode:   "special_nosale_goods",
-			GoodsSpecId: 14,
-			All:         map[string]string{"医疗领域化BI": "bi_yllyh"},
-		},
-		"bi_ldx": &Common{
-			Name:        "立达信BI分析工具",
-			GoodsCode:   "special_nosale_goods",
-			GoodsSpecId: 15,
-			All:         map[string]string{"立达信BI分析工具": "bi_ldx"},
-		},
-		"bi_hnyd_fx": &Common{
-			Name:        "bi_河南移动_数据分析",
-			GoodsCode:   "special_nosale_goods",
-			GoodsSpecId: 16,
-			All:         map[string]string{"bi_河南移动_数据分析": "bi_hnyd_fx"},
-		},
-		"bi_hnyd_gl": &Common{
-			Name:        "bi_河南移动_数据管理",
-			GoodsCode:   "special_nosale_goods",
-			GoodsSpecId: 17,
-			All:         map[string]string{"bi_河南移动_数据管理": "bi_hnyd_gl"},
-		},
-		"ai_helper": &Common{
-			Name:        "智能助手",
-			GoodsCode:   "ai_helper",
-			GoodsSpecId: 18,
-			All:         map[string]string{"智能助手": "ai_helper"},
-		},
 	}
+	c *Config
 )
 
+type Config struct {
+	EtcdAddr []string
+	Mongodb  struct {
+		Main *mgoConf
+	}
+	Mysql struct {
+		Main *mysqlConf
+		Base *mysqlConf
+	}
+	Products map[string]*Common
+}
+
+type mgoConf struct {
+	Address    string
+	Size       int
+	DbName     string
+	ReplSet    string
+	UserName   string
+	Password   string
+	Collection string
+}
+type mysqlConf struct {
+	DbName       string
+	Address      string
+	UserName     string
+	PassWord     string
+	MaxOpenConns int
+	MaxIdleConns int
+}
+
+func init() {
+	ReadConfig(&c)
+}
+
 func main() {
+	allT := "yxy:医械云"
+	for k, v := range c.Products {
+		allEntity[k] = v
+		allT += " " + k + ":" + v.Name
+	}
 	phone := flag.String("p", "", "手机号")
 	m := flag.Int("m", 0, "1:查询权益 2:开通权益 3:取消权益")
-	t := flag.String("t", "", "yxy:医械云 bi_yllyh:医疗领域化BI bi_ldx:立达信BI分析工具 bi_hnyd_fx:河南移动_数据分析 bi_hnyd_gl:河南移动_数据管理 ai_helper:智能助手")
-	isProduct := flag.Int("d", 0, "是否是线上环境;0:否 1:是")
+	t := flag.String("t", "", allT)
 	dayCount := flag.Int("c", 0, "自定义设置需要开通权益的天数,包含今天")
 	entName := flag.String("n", "", "企业名称")
 	isCheck := flag.Int("b", 1, "是否前置校验和后置处理")
@@ -86,63 +95,39 @@ func main() {
 		log.Fatalln("-t 参数无效")
 	}
 	powerType, goodsCode, goodsSpecId, all = entity.init()
-	if *isProduct == 1 {
-		middleground = NewMiddleground([]string{"172.17.4.185:2379", "172.17.4.186:2379", "172.17.148.50:2379"})
-		BaseService = &ml.Mysql{
-			Address:      "172.17.145.164:14000",
-			UserName:     "root",
-			PassWord:     "Tibi#20211222",
-			DBName:       "base_service",
-			MaxOpenConns: 2,
-			MaxIdleConns: 2,
-		}
-		Mgo = &mongodb.MongodbSim{
-			MongodbAddr: "172.17.4.193:27080,172.17.4.83:27080",
-			Size:        1,
-			DbName:      "qfw",
-			ReplSet:     "",
-			UserName:    "",
-			Password:    "",
-		}
-		JyOrder = &ml.Mysql{
-			Address:      "172.17.145.169:3306",
-			UserName:     "root",
-			PassWord:     "TopMysql@123",
-			DBName:       "jianyu",
-			MaxOpenConns: 2,
-			MaxIdleConns: 2,
-		}
-	} else {
-		middleground = NewMiddleground([]string{"192.168.3.149:2379"})
-		BaseService = &ml.Mysql{
-			Address:      "192.168.3.14:4000",
-			UserName:     "root",
-			PassWord:     "=PDT49#80Z!RVv52_z",
-			DBName:       "base_service",
-			MaxOpenConns: 2,
-			MaxIdleConns: 2,
-		}
-		Mgo = &mongodb.MongodbSim{
-			MongodbAddr: "192.168.3.206:27080",
-			Size:        1,
-			DbName:      "qfw",
-			ReplSet:     "",
-			UserName:    "",
-			Password:    "",
-		}
-		JyOrder = &ml.Mysql{
-			Address:      "192.168.3.11:3366",
-			UserName:     "root",
-			PassWord:     "Topnet123",
-			DBName:       "jianyu",
-			MaxOpenConns: 2,
-			MaxIdleConns: 2,
-		}
-	}
+	middleground = NewMiddleground(c.EtcdAddr)
 	middleground.RegResourceCenter("resource.rpc").RegUserCenter("usercenter.rpc")
+	//
+	BaseService = &ml.Mysql{
+		Address:      c.Mysql.Base.Address,
+		UserName:     c.Mysql.Base.UserName,
+		PassWord:     c.Mysql.Base.PassWord,
+		DBName:       c.Mysql.Base.DbName,
+		MaxOpenConns: c.Mysql.Base.MaxOpenConns,
+		MaxIdleConns: c.Mysql.Base.MaxIdleConns,
+	}
 	BaseService.Init()
+	//
+	JyOrder = &ml.Mysql{
+		Address:      c.Mysql.Main.Address,
+		UserName:     c.Mysql.Main.UserName,
+		PassWord:     c.Mysql.Main.PassWord,
+		DBName:       c.Mysql.Main.DbName,
+		MaxOpenConns: c.Mysql.Main.MaxOpenConns,
+		MaxIdleConns: c.Mysql.Main.MaxIdleConns,
+	}
 	JyOrder.Init()
+	//
+	Mgo = &mongodb.MongodbSim{
+		MongodbAddr: c.Mongodb.Main.Address,
+		Size:        c.Mongodb.Main.Size,
+		DbName:      c.Mongodb.Main.DbName,
+		ReplSet:     c.Mongodb.Main.ReplSet,
+		UserName:    c.Mongodb.Main.UserName,
+		Password:    c.Mongodb.Main.Password,
+	}
 	Mgo.InitPool()
+	//
 	ur, _ := Mgo.Find("user", map[string]interface{}{
 		"$or": []map[string]interface{}{
 			map[string]interface{}{
@@ -243,7 +228,7 @@ func main() {
 				} else if r.Status == 1 {
 					log.Println(msg, powerType, "已取消!")
 				} else {
-					log.Println(msg, powerType, "取消失败!")
+					log.Println(msg, powerType, "取消失败!", r.Status)
 				}
 			} else {
 				log.Fatalln("-m 参数无效")

+ 0 - 107
openPower/resource.go

@@ -1,107 +0,0 @@
-package main
-
-import (
-	"context"
-	"flag"
-	"log"
-
-	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
-	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/resource"
-	"github.com/zeromicro/go-zero/core/discov"
-	"github.com/zeromicro/go-zero/zrpc"
-)
-
-var c resource.Resource
-
-func main12() {
-	m := flag.Int("m", 0, "")
-	flag.Parse()
-	c = resource.NewResource(zrpc.MustNewClient(zrpc.RpcClientConf{
-		Etcd: discov.EtcdConf{
-			Hosts: []string{"192.168.3.149:2379"},
-			Key:   "resource.rpc",
-		},
-	}))
-	*m = 5
-	if *m == -1 {
-		CancelPowerHandle()
-	} else if *m == 1 {
-		OpenPowerHandle()
-	} else if *m == 2 {
-		CheckPower()
-	} else if *m == 3 {
-		Deduction()
-	} else if *m == 4 {
-		ReEmpower()
-	} else if *m == 5 {
-		HasPowers()
-	}
-}
-
-//开通或者取消用户/企业权益
-func OpenPowerHandle() {
-	r, err := c.PowerHandle(context.Background(), &pb.PowerReq{
-		Appid:     "10000",
-		GoodsCode: "xxfb_gyxx",
-		EntId:     55,
-		Type:      1,
-	})
-	log.Println("----------", r.Status, err)
-}
-
-//开通或者取消用户/企业权益
-func CancelPowerHandle() {
-	r, err := c.PowerHandle(context.Background(), &pb.PowerReq{
-		Appid:     "10000",
-		GoodsCode: "xxfb_gyxx",
-		EntId:     55,
-		Type:      -1,
-	})
-	log.Println("----------", r.Status, err)
-}
-
-//检查用户/企业权益
-func CheckPower() {
-	r, err := c.CheckPower(context.Background(), &pb.CheckPowerReq{
-		Appid:        "10000",
-		FunctionCode: "znsj_kf_use",
-		EntAccountId: 12664,
-		EntId:        1023,
-		EntUserId:    1308,
-	})
-	log.Println("----------", r.Status, err)
-}
-
-//资源扣减
-func Deduction() {
-	r, err := c.Deduction(context.Background(), &pb.DeductionReq{
-		Appid:        "10000",
-		FunctionCode: "xxfb_gyxx_add",
-		AccountId:    0,
-		Count:        1,
-	})
-	log.Println("----------", r.Status, err)
-}
-
-//资源扣减
-func ReEmpower() {
-	r, err := c.ReEmpower(context.Background(), &pb.EmpowerReq{
-		Appid:        "10000",
-		FunctionCode: "znsj_kf_use",
-		EntId:        14184,
-		EntUserId:    []int64{4271},
-	})
-	log.Println("----------", r.Status, err)
-}
-
-//获取权益
-func HasPowers() {
-	r, err := c.Haspowers(context.Background(), &pb.HaspowersReq{
-		Appid:        "10000",
-		AccountId:    12664,
-		EntAccountId: 205,
-		EntId:        1023,
-		EntUserId:    1308,
-	})
-	log.Println("----------", r.Powers, err)
-}

+ 1 - 1
public/service/power.go

@@ -40,7 +40,7 @@ func OpenPower(appid, goods_code string, goods_spec_id, account_id, ent_id int64
 		}
 	}
 	list := Base_goods_spec.FindById(goods_spec_id, appid, goods_code)
-	if list == nil {
+	if list == nil || len(*list) == 0 {
 		return errors.New("没有找到该商品规格")
 	} else if Base_power.OpenPower(goods_spec_id, appid, goods_code, account_id, ent_id, buy_num, start_time, end_time, list) {
 		return nil

+ 2 - 2
public/service/power_test.go

@@ -27,9 +27,9 @@ func TestCancelPower(t *testing.T) {
 
 func TestHasPowers(t *testing.T) {
 	//企业
-	//powers, err := HasPowers("10000", 0, 12664, 1023, 1308)
+	powers, err := HasPowers("10000", 0, 3, 1, 3870)
 	//个人
-	powers, err := HasPowers("10000", 13485, 0, 0, 0)
+	//powers, err := HasPowers("10000", 13485, 0, 0, 0)
 	assert.Nil(t, err)
 	t.Log(powers)
 }