wangchuanjin vor 2 Monaten
Ursprung
Commit
c47f7a86d9
6 geänderte Dateien mit 784 neuen und 264 gelöschten Zeilen
  1. 12 5
      openPower/config.json
  2. 89 70
      openPower/go.mod
  3. 351 136
      openPower/go.sum
  4. 330 51
      openPower/openPower.go
  5. 1 1
      public/service/init_test.go
  6. 1 1
      public/service/power_test.go

+ 12 - 5
openPower/config.json

@@ -1,21 +1,28 @@
 {
-	"etcdAddr": ["192.168.3.207:2379","192.168.3.165:2379","192.168.3.204:2379"],
+	"etcdAddr": ["172.31.31.203:2379"],
 	"mongodb": {
 	    "main": {
-	      "address": "192.168.3.149:27180",
+	      "address": "172.20.45.129:27002",
 	      "size": 1,
 	      "dbName": "qfw"
-	    }
+	    },
+		"log": {
+			"address": "172.20.45.129:27002",
+			"size": 1,
+			"dbName": "qfw"
+		}
   	},
   	"mysql": {
     	"main": {
 	      	"dbName": "jianyu",
-	 		"address" : "192.168.3.217:4000",
+	 		"address" : "172.20.45.129:4000",
 	      	"userName": "root",
 	      	"passWord": "=PDT49#80Z!RVv52_z",
 	      	"maxOpenConns": 2,
 	      	"maxIdleConns": 2
 	    }
   	},
-	"products": [14,15,16,17,18,19,20,22,23,24,27,28,25,26,29,30,31,32,33,34,35]
+	"products": [14,15,16,17,18,19,20,22,23,24,27,28,25,26,29,30,31,32,33,34,35],
+	"redis": "session=172.20.45.129:1713",
+	"domain": "https://jybx-webtest.jydev.jianyu360.com"
 }

+ 89 - 70
openPower/go.mod

@@ -1,112 +1,131 @@
 module openPower
 
-go 1.18
+go 1.21
+
+toolchain go1.23.4
 
 require (
-	app.yhyue.com/moapp/jybase v0.0.0-20230523020646-528a068dac39
-	app.yhyue.com/moapp/jypkg v0.0.0-20230218064127-1de4f4f3e6a3
-	bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.1.1-0.20240108101737-86c53d74548d
-	bp.jydev.jianyu360.cn/BaseService/userCenter v1.2.14
+	app.yhyue.com/moapp/jybase v0.0.0-20240226084952-7e7b38ef8a66
+	app.yhyue.com/moapp/jypkg v1.19.7
+	bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.1.3
+	bp.jydev.jianyu360.cn/BaseService/userCenter v1.2.21
+	github.com/gogf/gf/v2 v2.7.0
 )
 
 require (
-	bp.jydev.jianyu360.cn/BaseService/entManageApplication v0.0.0-20230209051900-1e7dcb8f83b7 // indirect
-	bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20230225125145-431a4f70093a // indirect
+	app.yhyue.com/moapp/jyMarketing v0.0.2-0.20230304035551-21bb1eedf547 // indirect
+	app.yhyue.com/moapp/jyPoints v1.1.2-0.20231020023521-1a4b1bbf9736 // indirect
+	bp.jydev.jianyu360.cn/BaseService/entManageApplication v0.0.0-20231226074509-942d80dc34eb // indirect
+	bp.jydev.jianyu360.cn/BaseService/jyMicroservices v0.0.2 // indirect
+	bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20231222060155-36e225b61353 // indirect
+	filippo.io/edwards25519 v1.1.0 // indirect
+	github.com/BurntSushi/toml v1.2.0 // indirect
 	github.com/beorn7/perks v1.0.1 // indirect
-	github.com/cenkalti/backoff/v4 v4.2.0 // indirect
+	github.com/cenkalti/backoff/v4 v4.2.1 // indirect
 	github.com/cespare/xxhash/v2 v2.2.0 // indirect
+	github.com/clbanning/mxj/v2 v2.7.0 // indirect
 	github.com/coreos/go-semver v0.3.1 // indirect
 	github.com/coreos/go-systemd/v22 v22.5.0 // indirect
 	github.com/davecgh/go-spew v1.1.1 // indirect
-	github.com/dchest/captcha v0.0.0-20200903113550-03f5f0333e1f // indirect
 	github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
-	github.com/emicklei/go-restful/v3 v3.9.0 // indirect
-	github.com/fatih/color v1.15.0 // indirect
-	github.com/felixge/fgprof v0.9.3 // indirect
-	github.com/go-logr/logr v1.2.3 // indirect
+	github.com/emicklei/go-restful/v3 v3.11.0 // indirect
+	github.com/fatih/color v1.16.0 // indirect
+	github.com/fsnotify/fsnotify v1.7.0 // indirect
+	github.com/garyburd/redigo v1.6.2 // indirect
+	github.com/go-logr/logr v1.3.0 // indirect
 	github.com/go-logr/stdr v1.2.2 // indirect
 	github.com/go-openapi/jsonpointer v0.19.6 // indirect
-	github.com/go-openapi/jsonreference v0.20.1 // indirect
-	github.com/go-openapi/swag v0.22.3 // indirect
-	github.com/go-redis/redis/v8 v8.11.5 // indirect
-	github.com/go-sql-driver/mysql v1.7.0 // indirect
+	github.com/go-openapi/jsonreference v0.20.2 // indirect
+	github.com/go-openapi/swag v0.22.4 // indirect
+	github.com/go-sql-driver/mysql v1.8.1 // indirect
 	github.com/gogo/protobuf v1.3.2 // indirect
 	github.com/golang/mock v1.6.0 // indirect
-	github.com/golang/protobuf v1.5.3 // indirect
+	github.com/golang/protobuf v1.5.4 // indirect
 	github.com/golang/snappy v0.0.4 // indirect
-	github.com/google/gnostic v0.5.7-v3refs // indirect
-	github.com/google/go-cmp v0.5.9 // indirect
+	github.com/gomodule/redigo v2.0.0+incompatible // indirect
+	github.com/google/gnostic-models v0.6.8 // indirect
+	github.com/google/go-cmp v0.6.0 // indirect
 	github.com/google/gofuzz v1.2.0 // indirect
-	github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect
-	github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 // indirect
+	github.com/google/uuid v1.6.0 // indirect
+	github.com/gorilla/websocket v1.5.0 // indirect
+	github.com/grokify/html-strip-tags-go v0.0.1 // indirect
+	github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
 	github.com/jinzhu/inflection v1.0.0 // indirect
 	github.com/jinzhu/now v1.1.1 // indirect
 	github.com/josharian/intern v1.0.0 // indirect
 	github.com/json-iterator/go v1.1.12 // indirect
-	github.com/klauspost/compress v1.15.15 // indirect
+	github.com/klauspost/compress v1.16.7 // indirect
+	github.com/magiconair/properties v1.8.7 // indirect
 	github.com/mailru/easyjson v0.7.7 // indirect
 	github.com/mattn/go-colorable v0.1.13 // indirect
-	github.com/mattn/go-isatty v0.0.17 // indirect
-	github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
+	github.com/mattn/go-isatty v0.0.20 // indirect
+	github.com/mattn/go-runewidth v0.0.15 // indirect
+	github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
 	github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
-	github.com/openzipkin/zipkin-go v0.4.1 // indirect
-	github.com/pelletier/go-toml/v2 v2.0.7 // indirect
-	github.com/pkg/errors v0.9.1 // indirect
-	github.com/prometheus/client_golang v1.15.0 // indirect
-	github.com/prometheus/client_model v0.3.0 // indirect
-	github.com/prometheus/common v0.42.0 // indirect
-	github.com/prometheus/procfs v0.9.0 // indirect
+	github.com/olekukonko/tablewriter v0.0.5 // indirect
+	github.com/openzipkin/zipkin-go v0.4.2 // indirect
+	github.com/pelletier/go-toml/v2 v2.2.0 // indirect
+	github.com/prometheus/client_golang v1.18.0 // indirect
+	github.com/prometheus/client_model v0.5.0 // indirect
+	github.com/prometheus/common v0.45.0 // indirect
+	github.com/prometheus/procfs v0.12.0 // indirect
+	github.com/redis/go-redis/v9 v9.4.0 // indirect
+	github.com/rivo/uniseg v0.2.0 // indirect
 	github.com/spaolacci/murmur3 v1.1.0 // indirect
 	github.com/xdg-go/pbkdf2 v1.0.0 // indirect
-	github.com/xdg-go/scram v1.1.1 // indirect
-	github.com/xdg-go/stringprep v1.0.3 // indirect
-	github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
-	github.com/zeromicro/go-zero v1.5.2 // indirect
-	go.etcd.io/etcd/api/v3 v3.5.8 // indirect
-	go.etcd.io/etcd/client/pkg/v3 v3.5.8 // indirect
-	go.etcd.io/etcd/client/v3 v3.5.8 // indirect
-	go.mongodb.org/mongo-driver v1.11.4 // indirect
-	go.opentelemetry.io/otel v1.14.0 // indirect
-	go.opentelemetry.io/otel/exporters/jaeger v1.14.0 // indirect
-	go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 // indirect
-	go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.14.0 // indirect
-	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0 // indirect
-	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.14.0 // indirect
-	go.opentelemetry.io/otel/exporters/zipkin v1.14.0 // indirect
-	go.opentelemetry.io/otel/sdk v1.14.0 // indirect
-	go.opentelemetry.io/otel/trace v1.14.0 // indirect
-	go.opentelemetry.io/proto/otlp v0.19.0 // indirect
+	github.com/xdg-go/scram v1.1.2 // indirect
+	github.com/xdg-go/stringprep v1.0.4 // indirect
+	github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
+	github.com/zeromicro/go-zero v1.6.4 // indirect
+	go.etcd.io/etcd/api/v3 v3.5.13 // indirect
+	go.etcd.io/etcd/client/pkg/v3 v3.5.13 // indirect
+	go.etcd.io/etcd/client/v3 v3.5.13 // indirect
+	go.mongodb.org/mongo-driver v1.14.0 // indirect
+	go.opentelemetry.io/otel v1.19.0 // indirect
+	go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
+	go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
+	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 // indirect
+	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 // indirect
+	go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 // indirect
+	go.opentelemetry.io/otel/exporters/zipkin v1.19.0 // indirect
+	go.opentelemetry.io/otel/metric v1.19.0 // indirect
+	go.opentelemetry.io/otel/sdk v1.19.0 // indirect
+	go.opentelemetry.io/otel/trace v1.19.0 // indirect
+	go.opentelemetry.io/proto/otlp v1.0.0 // indirect
 	go.uber.org/atomic v1.10.0 // indirect
-	go.uber.org/automaxprocs v1.5.2 // indirect
+	go.uber.org/automaxprocs v1.5.3 // indirect
 	go.uber.org/multierr v1.9.0 // indirect
 	go.uber.org/zap v1.24.0 // indirect
-	golang.org/x/crypto v0.6.0 // indirect
-	golang.org/x/net v0.9.0 // indirect
-	golang.org/x/oauth2 v0.6.0 // indirect
-	golang.org/x/sync v0.1.0 // indirect
-	golang.org/x/sys v0.7.0 // indirect
-	golang.org/x/term v0.7.0 // indirect
-	golang.org/x/text v0.9.0 // indirect
-	golang.org/x/time v0.3.0 // indirect
-	google.golang.org/appengine v1.6.7 // indirect
-	google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
-	google.golang.org/grpc v1.55.0 // indirect
-	google.golang.org/protobuf v1.30.0 // indirect
+	golang.org/x/crypto v0.22.0 // indirect
+	golang.org/x/net v0.24.0 // indirect
+	golang.org/x/oauth2 v0.17.0 // indirect
+	golang.org/x/sync v0.6.0 // indirect
+	golang.org/x/sys v0.19.0 // indirect
+	golang.org/x/term v0.19.0 // indirect
+	golang.org/x/text v0.14.0 // indirect
+	golang.org/x/time v0.5.0 // indirect
+	google.golang.org/appengine v1.6.8 // indirect
+	google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
+	google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
+	google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
+	google.golang.org/grpc v1.63.2 // indirect
+	google.golang.org/protobuf v1.33.0 // indirect
 	gopkg.in/inf.v0 v0.9.1 // indirect
 	gopkg.in/yaml.v2 v2.4.0 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect
 	gorm.io/driver/mysql v1.0.5 // indirect
 	gorm.io/gorm v1.21.3 // indirect
-	k8s.io/api v0.26.3 // indirect
-	k8s.io/apimachinery v0.27.0-alpha.3 // indirect
-	k8s.io/client-go v0.26.3 // indirect
-	k8s.io/klog/v2 v2.90.1 // indirect
-	k8s.io/kube-openapi v0.0.0-20230307230338-69ee2d25a840 // indirect
-	k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
+	jygit.jydev.jianyu360.cn/ApplicationCenter/publicService v0.0.0-20231023011746-38dc3b6aded8 // indirect
+	k8s.io/api v0.29.3 // indirect
+	k8s.io/apimachinery v0.29.3 // indirect
+	k8s.io/client-go v0.29.3 // indirect
+	k8s.io/klog/v2 v2.110.1 // indirect
+	k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
+	k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
 	sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
-	sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
+	sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
 	sigs.k8s.io/yaml v1.3.0 // indirect
 )

Datei-Diff unterdrückt, da er zu groß ist
+ 351 - 136
openPower/go.sum


+ 330 - 51
openPower/openPower.go

@@ -1,33 +1,43 @@
 package main
 
 import (
-	"context"
-	"encoding/json"
-	"flag"
-	"fmt"
-	"log"
-	"strings"
-	"time"
-
 	. "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/date"
+	"app.yhyue.com/moapp/jybase/encrypt"
 	"app.yhyue.com/moapp/jybase/mongodb"
 	ml "app.yhyue.com/moapp/jybase/mysql"
+	"app.yhyue.com/moapp/jybase/redis"
 	. "app.yhyue.com/moapp/jypkg/middleground"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/resource"
 	upb "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
+	"context"
+	"encoding/json"
+	"flag"
+	"fmt"
+	"github.com/gogf/gf/v2/container/garray"
+	"github.com/gogf/gf/v2/container/gvar"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/os/gctx"
+	"github.com/gogf/gf/v2/os/gtime"
+	"github.com/gogf/gf/v2/util/gconv"
+	"io/ioutil"
+	"log"
+	"regexp"
+	"strings"
+	"time"
 )
 
 const (
-	appid = "10000"
+	appid     = "10000"
+	sessionId = "openPowerVirtualSessionId"
 )
 
 var (
 	etcdAddress  []string
-	BaseService  *ml.Mysql
 	Mgo          *mongodb.MongodbSim
+	MgoLog       *mongodb.MongodbSim
 	MysqlMain    *ml.Mysql
 	goodsCode    string
 	goodsSpecId  int64
@@ -35,18 +45,22 @@ var (
 	powerType    string
 	middleground *Middleground
 	c            *Config
+	whether      string
 )
 
 type Config struct {
 	EtcdAddr []string
 	Mongodb  struct {
 		Main *mgoConf
+		Log  *mgoConf
 	}
 	Mysql struct {
 		Main *mysqlConf
 		Base *mysqlConf
 	}
 	Products []int64
+	Redis    string
+	Domain   string
 }
 
 type mgoConf struct {
@@ -80,11 +94,11 @@ func main() {
 		MaxOpenConns: c.Mysql.Main.MaxOpenConns,
 		MaxIdleConns: c.Mysql.Main.MaxIdleConns,
 	}
+	MysqlMain.Init()
 	filterSpec := map[int64]bool{}
 	for _, v := range c.Products {
 		filterSpec[v] = true
 	}
-	MysqlMain.Init()
 	allEntity := map[int64]Entity{}
 	allEntity[-1] = &Yxy{}
 	allT := "-1:医械通"
@@ -122,10 +136,49 @@ func main() {
 	entName := flag.String("n", "", "企业名称")
 	isCheck := flag.Int("b", 1, "是否前置校验和后置处理")
 	powerWay := flag.Int("a", 0, "权益开通/取消方式;0:一个身份 1:全部身份 2:仅仅企业上")
+	isCreateUser := flag.Bool("cu", false, "是否创建用户")
+	inputOrderCode := flag.String("oc", "", "订单号")
+	inputStartTime := flag.Int64("st", 0, "unix类型的开始时间")
+	inputEndTime := flag.Int64("et", 0, "unix类型的结束时间")
+	resetPower := flag.Bool("rp", false, "是否重新开通权益")
 	flag.Parse()
+	//*phone = "15037870753"
+	//*t = 22
+	//*entName = "王传进的测试企业99"
+	//*isCreateUser = true
+	//*inputOrderCode = "259519348822"
+	//*inputStartTime = 1746028800
+	//*inputEndTime = 1747584000
+	//*m = 2
+	//
 	if *phone == "" {
 		log.Fatalln("-p 参数无效")
 	}
+	if *inputOrderCode != "" {
+		*isCreateUser = true
+		if *inputStartTime == 0 {
+			log.Fatalln("-st 参数无效")
+		}
+		if *inputEndTime == 0 {
+			log.Fatalln("-et 参数无效")
+		}
+	}
+	if *m != 2 {
+		*isCreateUser = false
+	}
+	var inputStartTimeStr, inputEndTimeStr string
+	if *inputStartTime > 0 {
+		inputStartTimeStr = gtime.NewFromTimeStamp(*inputStartTime).String()
+		if inputStartTimeStr == "" {
+			log.Fatalln("-st 参数无效")
+		}
+	}
+	if *inputEndTime > 0 {
+		inputEndTimeStr = gtime.NewFromTimeStamp(*inputEndTime).String()
+		if inputEndTimeStr == "" {
+			log.Fatalln("-et 参数无效")
+		}
+	}
 	entity := allEntity[*t]
 	if entity == nil {
 		log.Fatalln("-t 参数无效")
@@ -134,6 +187,7 @@ func main() {
 	middleground = NewMiddleground(c.EtcdAddr)
 	middleground.RegResourceCenter("resource.rpc").RegUserCenter("usercenter.rpc")
 	//
+	redis.InitRedis(c.Redis)
 	Mgo = &mongodb.MongodbSim{
 		MongodbAddr: c.Mongodb.Main.Address,
 		Size:        c.Mongodb.Main.Size,
@@ -143,21 +197,64 @@ func main() {
 		Password:    c.Mongodb.Main.Password,
 	}
 	Mgo.InitPool()
+	MgoLog = &mongodb.MongodbSim{
+		MongodbAddr: c.Mongodb.Log.Address,
+		Size:        c.Mongodb.Log.Size,
+		DbName:      c.Mongodb.Log.DbName,
+		ReplSet:     c.Mongodb.Log.ReplSet,
+		UserName:    c.Mongodb.Log.UserName,
+		Password:    c.Mongodb.Log.Password,
+	}
+	MgoLog.InitPool()
 	//
-	ur, _ := Mgo.Find("user", map[string]interface{}{
-		"$or": []map[string]interface{}{
-			map[string]interface{}{
-				"s_phone": *phone,
-			},
-			map[string]interface{}{
-				"s_m_phone": *phone,
-			},
-		},
-		"i_appid": 2,
-	}, nil, `{"base_user_id":1}`, false, -1, -1)
-	if ur == nil || len(*ur) <= 0 {
-		log.Fatalln("没有找到该用户!")
+	createUserOk, ur, newUserId, newBaseUserId := createUser(*phone, *isCreateUser)
+	if !createUserOk {
+		return
+	}
+	//是否创建企业
+	if *isCreateUser && *entName != "" {
+		isInEnt := MysqlMain.CountBySql(`select count(1) as count from jianyu.entniche_info a inner join jianyu.entniche_user b on (a.name=? and b.phone=? and a.id=b.ent_id)`, *entName, *phone)
+		if isInEnt == 0 {
+			log.Println("该手机号是否是企业管理员(y/n)?")
+			fmt.Scan(&whether)
+			if whether == "y" {
+				if createEntOk, _, _, _ := createEnt(newUserId, *phone, *entName, newBaseUserId); !createEntOk {
+					return
+				}
+			} else {
+				var entAdminPhone string
+				log.Println("请输入管理员手机号")
+				for {
+					fmt.Scan(&entAdminPhone)
+					entAdminPhone = strings.TrimSpace(entAdminPhone)
+					if !regexp.MustCompile("^[0-9]+$").MatchString(entAdminPhone) {
+						log.Println("手机号格式错误,请重新输入!")
+					} else {
+						break
+					}
+				}
+				createUserOk, _, adminUserId, adminBaseUserId := createUser(entAdminPhone, *isCreateUser)
+				if !createUserOk {
+					return
+				}
+				createEntOk, newEntId, newDeptId, nweEntUserId := createEnt(adminUserId, entAdminPhone, *entName, adminBaseUserId)
+				if !createEntOk {
+					return
+				}
+				log.Println("该手机号未在企业下,是否添加为员工(y/n)?")
+				fmt.Scan(&whether)
+				if whether != "y" {
+					return
+				}
+				addToEnt(newEntId, newDeptId, nweEntUserId, newUserId, *phone)
+			}
+		} else if isInEnt < 0 {
+			log.Fatalln("查询手机号是否在企业下失败!")
+		}
 	}
+	//
+	isFindIdentity := false
+	var updateOrderUserId string
 	for _, v := range *ur {
 		id := Int64All(v["base_user_id"])
 		for _, identity := range middleground.UserCenter.IdentityList(id) {
@@ -174,9 +271,10 @@ func main() {
 					continue
 				}
 			}
+			isFindIdentity = true
 			msg := "身份信息:" + fmt.Sprintf("%+v", identity) + " 手机号:" + *phone
 			var resClient = resource.NewResource(middleground.ResourceCenter.NewClient())
-			if *m == 1 {
+			var getPowers = func() *garray.StrArray {
 				r, err := resClient.Haspowers(context.Background(), &pb.HaspowersReq{
 					Appid:        "10000",
 					EntId:        identity.EntId,
@@ -185,32 +283,45 @@ func main() {
 					EntAccountId: identity.EntAccountId,
 				})
 				if err != nil {
-					log.Println(msg, "查询", powerType, "权益失败!", err)
-				} else {
-					mp := map[string]bool{}
-					for _, v := range r.Powers {
-						mp[v] = true
-					}
-					flag := true
-					for k, v := range all {
-						if !mp[v] {
-							log.Println(msg, powerType, "权益异常,缺少权益:", k)
-							flag = false
-							continue
-						}
+					log.Fatalln(msg, "查询", powerType, "权益失败!", err)
+				}
+				return garray.NewStrArrayFrom(r.Powers)
+			}
+			var notHavePowers = func() []string {
+				array := []string{}
+				powers := getPowers()
+				for k, v := range all {
+					if powers.Contains(v) {
+						continue
 					}
-					if flag {
-						for k, _ := range all {
-							log.Println(msg, "拥有", powerType, "权益:", k)
-						}
+					array = append(array, k)
+				}
+				return array
+			}
+			if *m == 1 {
+				if array := notHavePowers(); len(array) > 0 {
+					log.Println(msg, powerType, "权益异常,缺少权益:", strings.Join(array, ","))
+				} else {
+					for k, _ := range all {
+						log.Println(msg, "拥有", powerType, "权益:", k)
 					}
 				}
 			} else if *m == 2 {
+				if identity.PositionType == 1 {
+					updateOrderUserId = gconv.String(identity.PositionId)
+				} else {
+					updateOrderUserId = newUserId
+				}
 				if *isCheck == 1 && !entity.beforeOpen(phone, identity) {
 					return
 				}
-				endTime := ""
-				if *dayCount > 0 {
+				startTime, endTime := "", ""
+				if inputStartTimeStr != "" {
+					startTime = inputStartTimeStr
+				}
+				if inputEndTimeStr != "" {
+					endTime = inputEndTimeStr
+				} else if *dayCount > 0 {
 					now := time.Now()
 					end_time := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 0, time.Local)
 					end_time = end_time.AddDate(0, 0, *dayCount-1)
@@ -251,6 +362,10 @@ func main() {
 					// 	break
 					// }
 				}
+				if len(notHavePowers()) == 0 && !*resetPower {
+					log.Println(msg, powerType, "权益已存在,无需开通")
+					continue
+				}
 				var r *pb.Resp
 				var err error
 				if isEmpower {
@@ -270,6 +385,7 @@ func main() {
 						BuyNum:      1,
 						Type:        1,
 						EndTime:     endTime,
+						StartTime:   startTime,
 					}
 					if *powerWay == 2 {
 						powerReq.EntAccountId = identity.EntAccountId
@@ -327,6 +443,50 @@ func main() {
 			}
 		}
 	}
+	if !isFindIdentity {
+		log.Fatalln("没有找到身份信息!")
+	}
+	if *inputOrderCode != "" && updateOrderUserId != "" {
+		orderData := MysqlMain.SelectBySql(`select user_id,vip_starttime,vip_endtime from jianyu.dataexport_order where order_code=?`, inputOrderCode)
+		if orderData == nil || len(*orderData) == 0 {
+			log.Fatalln("没有找到该订单,更新订单失败!")
+		} else if len(*orderData) > 1 {
+			log.Fatalln("找到多个订单,需要手动处理!")
+		}
+		updateArgs := []interface{}{}
+		odVar := gvar.New((*orderData)[0]).MapStrVar()
+		updateFields := []string{}
+		array := []string{}
+		if odVar["user_id"].IsEmpty() {
+			updateFields = append(updateFields, "用户id")
+			array = append(array, "user_id=?")
+			updateArgs = append(updateArgs, updateOrderUserId)
+		} else {
+			log.Println("订单表用户id存在,无需更新")
+		}
+		if odVar["vip_starttime"].IsEmpty() {
+			updateFields = append(updateFields, "服务开始时间")
+			array = append(array, "vip_starttime=?")
+			updateArgs = append(updateArgs, inputStartTimeStr)
+		} else {
+			log.Println("订单表服务开始时间存在,无需更新")
+		}
+		if odVar["vip_endtime"].IsEmpty() {
+			updateFields = append(updateFields, "服务截止时间")
+			array = append(array, "vip_endtime=?")
+			updateArgs = append(updateArgs, inputEndTimeStr)
+		} else {
+			log.Println("订单表服务截止时间存在,无需更新")
+		}
+		if len(array) > 0 {
+			updateArgs = append(updateArgs, *inputOrderCode)
+			if MysqlMain.UpdateOrDeleteBySql(`update jianyu.dataexport_order set `+strings.Join(array, ",")+` where order_code=?`, updateArgs...) < 0 {
+				log.Fatalln("更新订单表" + strings.Join(updateFields, "、") + "失败!")
+			} else {
+				log.Fatalln("更新订单表" + strings.Join(updateFields, "、") + "成功!")
+			}
+		}
+	}
 }
 
 type Entity interface {
@@ -342,17 +502,14 @@ type Common struct {
 	All         map[string]string
 }
 
-//
 func (c *Common) init() (string, string, int64, map[string]string) {
 	return c.Name, c.GoodsCode, c.GoodsSpecId, c.All
 }
 
-//
 func (c *Common) beforeOpen(phone *string, identity *upb.Identity) bool {
 	return true
 }
 
-//
 func (c *Common) afterOpen(phone *string, identity *upb.Identity) {
 }
 
@@ -360,7 +517,6 @@ func (c *Common) afterOpen(phone *string, identity *upb.Identity) {
 type Yxy struct {
 }
 
-//
 func (y *Yxy) init() (string, string, int64, map[string]string) {
 	return "医械云权益", "lyh", 13, map[string]string{
 		"医疗标讯搜索": "lyh_yl_ylbxss",
@@ -373,7 +529,6 @@ func (y *Yxy) init() (string, string, int64, map[string]string) {
 	}
 }
 
-//
 func (y *Yxy) beforeOpen(phone *string, identity *upb.Identity) bool {
 	order_user_id, u := y.getUser(identity)
 	if u == nil {
@@ -383,7 +538,6 @@ func (y *Yxy) beforeOpen(phone *string, identity *upb.Identity) bool {
 	return ok
 }
 
-//
 func (y *Yxy) getUser(identity *upb.Identity) (string, *map[string]interface{}) {
 	if identity.PositionType == 0 {
 		u, _ := Mgo.FindOneByField("user", map[string]interface{}{"base_user_id": identity.UserId}, `{"_id":1,"l_vip_endtime":1,"i_member_endtime":1,"s_member_mainid":1,"i_member_sub_status":1}`)
@@ -402,7 +556,6 @@ func (y *Yxy) getUser(identity *upb.Identity) (string, *map[string]interface{})
 	}
 }
 
-//
 func (y *Yxy) afterOpen(phone *string, identity *upb.Identity) {
 	order_user_id, u := y.getUser(identity)
 	if u == nil {
@@ -560,3 +713,129 @@ func (y *Yxy) getPriceBack(orderMoney float64, endTime time.Time, cycle, cycleUn
 	money := unitPrice * float64(int(days))
 	return int(money)
 }
+func createUser(phone string, isCreateUser bool) (bool, *[]map[string]interface{}, string, int64) {
+	ur, userOk := Mgo.Find("user", map[string]interface{}{
+		"$or": []map[string]interface{}{
+			map[string]interface{}{
+				"s_phone": phone,
+			},
+			map[string]interface{}{
+				"s_m_phone": phone,
+			},
+		},
+		"i_appid": 2,
+	}, nil, `{"_id":1,"base_user_id":1}`, false, -1, -1)
+	var newBaseUserId int64
+	var newUserId string
+	if !userOk {
+		log.Fatalln("mgo user 查询失败")
+	} else if ur == nil || len(*ur) <= 0 {
+		if isCreateUser {
+			log.Println("没有找到该用户!是否创建(y/n)?")
+			fmt.Scan(&whether)
+			if whether != "y" {
+				return false, nil, "", 0
+			}
+		} else {
+			log.Fatalln("没有找到该用户!")
+		}
+		resp := middleground.UserCenter.UserAdd(upb.UserAddReq{Appid: appid, Phone: phone})
+		if resp == nil || resp.Data.Status != 1 {
+			log.Fatalln("创建用户失败")
+		}
+		newBaseUserId = resp.Data.Id
+		newUserId = Mgo.Save("user", map[string]interface{}{
+			"i_appid":       2,
+			"s_phone":       phone,
+			"base_user_id":  resp.Data.Id,
+			"l_registedate": time.Now().Unix(),
+			"s_regsource":   "openpower",
+		})
+		MgoLog.Save("user", map[string]interface{}{
+			"userid":      newUserId,
+			"phone":       phone,
+			"way":         "phone",
+			"system":      "pc",
+			"source":      "openpower",
+			"create_time": date.NowFormat(date.Date_Full_Layout),
+		})
+		*ur = append(*ur, map[string]interface{}{
+			"_id":          mongodb.StringTOBsonId(newUserId),
+			"base_user_id": newBaseUserId,
+		})
+	} else {
+		newUserId = mongodb.BsonIdToSId((*ur)[0]["_id"])
+		newBaseUserId = gconv.Int64((*ur)[0]["base_user_id"])
+	}
+	return true, ur, newUserId, newBaseUserId
+}
+func createEnt(mgoUserId, phone, entName string, baseUserId int64) (bool, int64, int64, int64) {
+	entDept := MysqlMain.SelectBySql(`select a.id as eid,b.id as did,c.id as uid from jianyu.entniche_info a inner join entniche_department b on (a.id=b.ent_id and b.pid=0) inner join entniche_user c on (a.id=c.ent_id and c.phone=?) where a.phone=? and a.name=?`, phone, phone, entName)
+	if entDept == nil {
+		log.Fatalln("查询企业是否存在失败!")
+	} else if len(*entDept) > 0 {
+		return true, gconv.Int64((*entDept)[0]["eid"]), gconv.Int64((*entDept)[0]["did"]), gconv.Int64((*entDept)[0]["uid"])
+	}
+	log.Println("没有找到该企业!是否创建(y/n)?")
+	fmt.Scan(&whether)
+	if whether != "y" {
+		return false, 0, 0, 0
+	}
+	//创建企业
+	redis.Put("session", sessionId, map[string]interface{}{
+		"userId":       mgoUserId,
+		"mgoUserId":    mgoUserId,
+		"base_user_id": baseUserId,
+	}, 60)
+	resp, err := g.Client().SetCookie("SESSIONID", sessionId).Post(gctx.New(), c.Domain+"/entbase/ent/add", g.Map{
+		"switch": true,
+		"name":   entName,
+	})
+	if err != nil {
+		log.Fatalln(err)
+	}
+	defer resp.Body.Close()
+	b, _ := ioutil.ReadAll(resp.Body)
+	eId := gvar.New(b).MapStrVar()["data"].MapStrVar()["entid"].String()
+	if eId == "" {
+		log.Fatalln("创建企业失败", string(b))
+	}
+	entId := gconv.Int64(encrypt.SE.Decode4HexByCheck(eId))
+	if entId <= 0 {
+		log.Fatalln("创建企业失败", string(b))
+	}
+	resp1, err1 := g.Client().SetCookie("SESSIONID", sessionId).Post(gctx.New(), c.Domain+"/entbase/ent/entinfo")
+	if err1 != nil {
+		log.Fatalln(err)
+	}
+	defer resp1.Body.Close()
+	b1, _ := ioutil.ReadAll(resp1.Body)
+	deptId := gvar.New(b1).MapStrVar()["data"].MapStrVar()["dept_id"].Int64()
+	entUserId := gconv.Int64(encrypt.SE.Decode4HexByCheck(gvar.New(b1).MapStrVar()["data"].MapStrVar()["user_id"].String()))
+	if deptId <= 0 {
+		log.Fatalln("创建企业后,获取部门id失败", string(b1))
+	}
+	return true, entId, deptId, entUserId
+}
+
+func addToEnt(entId, deptId, entUserId int64, userId, phone string) {
+	redis.Put("session", sessionId, map[string]interface{}{
+		"entId":          entId,
+		"entUserId":      entUserId,
+		"frameworkEntId": entId,
+		"userId":         userId,
+	}, 60)
+	resp, err := g.Client().SetCookie("SESSIONID", sessionId).Post(gctx.New(), c.Domain+"/entbase/person/add", g.Map{
+		"id":    deptId,
+		"name":  phone,
+		"phone": phone,
+	})
+	if err != nil {
+		log.Fatalln(err)
+	}
+	defer resp.Body.Close()
+	b, _ := ioutil.ReadAll(resp.Body)
+	if gvar.New(b).MapStrVar()["data"].MapStrVar()["status"].Int() != 1 {
+		log.Fatalln("人员添加到企业下失败", string(b))
+	}
+}

+ 1 - 1
public/service/init_test.go

@@ -7,7 +7,7 @@ import (
 
 func init() {
 	InitMysql(&Mysql{
-		Address:      "192.168.3.217:4000", //数据库地址:端口
+		Address:      "172.20.45.129:4000", //数据库地址:端口
 		UserName:     "root",               //用户名
 		PassWord:     "=PDT49#80Z!RVv52_z", //密码
 		DBName:       "base_service",       //数据库名

+ 1 - 1
public/service/power_test.go

@@ -28,7 +28,7 @@ func TestCancelPower(t *testing.T) {
 
 func TestHasPowers(t *testing.T) {
 	//企业
-	powers, err := HasPowers("10000", 13496, 3, 1, 3870)
+	powers, err := HasPowers("10000", 1080194, 1080192, 356303, 96589)
 	//个人
 	//powers, err := HasPowers("10000", 13485, 0, 0, 0)
 	assert.Nil(t, err)

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.