Roc 3 роки тому
батько
коміт
f8815f2f1d
8 змінених файлів з 93 додано та 31 видалено
  1. 3 1
      .gitignore
  2. 3 2
      config/config.go
  3. 28 9
      core/log.go
  4. 4 2
      global/global.go
  5. 6 1
      init_serve/mysql.go
  6. 1 4
      init_serve/redis.go
  7. 7 8
      logic/user/user.go
  8. 41 4
      services/company/permission.go

+ 3 - 1
.gitignore

@@ -4,4 +4,6 @@
 latest_log
 /config/config.yaml
 .DS_Store
-go.sum
+go.sum
+/binlog
+latest_binlog

+ 3 - 2
config/config.go

@@ -22,14 +22,15 @@ type Log struct {
 	Prefix     string `mapstructure:"prefix" json:"prefix" yaml:"prefix" description:"日志输出前缀"`
 	LogFile    bool   `mapstructure:"log-file" json:"logFile" yaml:"log-file" description:""`
 	Stdout     string `mapstructure:"stdout" json:"stdout" yaml:"stdout" description:""`
-	File       string `mapstructure:"file" json:"file" yaml:"file" description:""`
+	FileStdout string `mapstructure:"file-stdout" json:"file-stdout" yaml:"file-stdout" description:""`
 	SaveMaxDay int    `mapstructure:"save-max-day" json:"save-max-day" yaml:"save-max-day" description:"最多保留多少天的日志"`
 	CuttingDay int    `mapstructure:"cutting-day" json:"cutting-day" yaml:"cutting-day" description:"相隔几天切割文件"`
 }
 
 // Mysql 数据库配置
 type Mysql struct {
-	LogMode             bool        `mapstructure:"log-mode" json:"log-mode" yaml:"log-mode" description:"是否开启日志"`
+	//LogMode             bool        `mapstructure:"log-mode" json:"log-mode" yaml:"log-mode" description:"是否开启日志"`
+	Stdout              bool        `mapstructure:"stdout" json:"stdout" yaml:"stdout" description:"日志是否输出在控制台"`
 	DefaultDsnAliasName string      `mapstructure:"default-dsn-alias-name" json:"default-dsn-alias-name" yaml:"default-dsn-alias-name" description:"默认的数据库连接别名"`
 	List                []MysqlConn `mapstructure:"list" json:"list" yaml:"list" description:"数据库链接配置列表"`
 }

+ 28 - 9
core/log.go

@@ -15,9 +15,13 @@ import (
 )
 
 const (
-	logDir      = "log"
-	logSoftLink = "latest_log"
-	module      = "hongze_yb"
+	LogDir      = "log"
+	LogSoftLink = "latest_log"
+	Module      = "hongze_yb"
+
+	//mysql数据库日志
+	BinlogDir      = "binlog"
+	BinlogSoftLink = "latest_binlog"
 )
 
 var (
@@ -26,13 +30,13 @@ var (
 
 func init() {
 	logConfig := global.CONFIG.Log
-	logger := oplogging.MustGetLogger(module)
+	logger := oplogging.MustGetLogger(Module)
 	var backends []oplogging.Backend
 	//注册输出
 	registerStdout(logConfig, &backends)
 
 	//注册框架输出(日志文件)
-	fileWriter := registerFile(logConfig, &backends)
+	fileWriter := registerFile(logConfig, &backends, LogDir, LogSoftLink)
 	if fileWriter != nil {
 		if global.CONFIG.Serve.RunMode == "debug" {
 			gin.DefaultWriter = io.MultiWriter(fileWriter, os.Stdout)
@@ -42,6 +46,21 @@ func init() {
 	}
 	oplogging.SetBackend(backends...)
 	global.LOG = logger
+
+	//初始化mysql数据库日志
+	initMysqlLog()
+}
+
+// initMysqlLog 初始化mysql数据库日志
+func initMysqlLog() {
+	logConfig := global.CONFIG.Log
+	var backends []oplogging.Backend
+	//注册输出
+	registerStdout(logConfig, &backends)
+
+	//注册框架输出(日志文件)
+	fileWriter := registerFile(logConfig, &backends, BinlogDir, BinlogSoftLink)
+	global.MYSQL_LOG = fileWriter
 }
 
 func registerStdout(c config.Log, backends *[]oplogging.Backend) {
@@ -55,8 +74,8 @@ func registerStdout(c config.Log, backends *[]oplogging.Backend) {
 }
 
 // registerFile 注册文件日志
-func registerFile(c config.Log, backends *[]oplogging.Backend) io.Writer {
-	if c.File != "" {
+func registerFile(c config.Log, backends *[]oplogging.Backend, logDir, logSoftLink string) io.Writer {
+	if c.FileStdout != "" {
 		if ok, _ := utils.PathExists(logDir); !ok {
 			// directory not exist
 			fmt.Println("create log directory")
@@ -82,7 +101,7 @@ func registerFile(c config.Log, backends *[]oplogging.Backend) io.Writer {
 		if err != nil {
 			fmt.Println(err)
 		}
-		level, err := oplogging.LogLevel(c.File)
+		level, err := oplogging.LogLevel(c.FileStdout)
 		if err != nil {
 			fmt.Println(err)
 		}
@@ -102,7 +121,7 @@ func createBackend(w io.Writer, c config.Log, level oplogging.Level) oplogging.B
 	}
 	format := getLogFormatter(c, stdoutWriter)
 	backendLeveled := oplogging.AddModuleLevel(oplogging.NewBackendFormatter(backend, format))
-	backendLeveled.SetLevel(level, module)
+	backendLeveled.SetLevel(level, Module)
 	return backendLeveled
 }
 

+ 4 - 2
global/global.go

@@ -5,12 +5,14 @@ import (
 	oplogging "github.com/op/go-logging"
 	"gorm.io/gorm"
 	"hongze/hongze_yb/config"
+	"io"
 )
 
 var (
 	CONFIG        config.Config //配置文件
 	LOG           *oplogging.Logger
 	MYSQL         map[string]*gorm.DB //数据库连接配置
-	DEFAULT_MYSQL *gorm.DB            //默认数据库连接配置
-	Redis         *redis.Client       //redis链接
+	MYSQL_LOG     io.Writer
+	DEFAULT_MYSQL *gorm.DB      //默认数据库连接配置
+	Redis         *redis.Client //redis链接
 )

+ 6 - 1
init_serve/mysql.go

@@ -6,6 +6,7 @@ import (
 	"gorm.io/gorm"
 	"gorm.io/gorm/logger"
 	"hongze/hongze_yb/global"
+	"io"
 	"log"
 	"os"
 	"time"
@@ -20,7 +21,11 @@ func Mysql() {
 	}
 
 	//开启日志
-	newLogger := logger.New(log.New(os.Stdout, "\r\n", log.LstdFlags), logger.Config{
+	logWriter := io.MultiWriter(global.MYSQL_LOG) //binlog日志,记录到文件中去
+	if global.CONFIG.Mysql.Stdout {
+		logWriter = io.MultiWriter(global.MYSQL_LOG, os.Stdout)
+	}
+	newLogger := logger.New(log.New(logWriter, "\r\n", log.LstdFlags), logger.Config{
 		SlowThreshold:             200 * time.Millisecond, //慢sql :200ms
 		LogLevel:                  logger.Info,            //记录的日志类型,info代表所有信息都记录
 		IgnoreRecordNotFoundError: true,                   //是否忽略找不到数据错误信息(只是日志记录记录成err还是普通的输出的区别,并不影响业务代码中的:找不到数据行error)

+ 1 - 4
init_serve/redis.go

@@ -2,7 +2,6 @@ package init_serve
 
 import (
 	"context"
-	"fmt"
 	"github.com/go-redis/redis/v8"
 	"hongze/hongze_yb/global"
 )
@@ -15,12 +14,10 @@ func Redis() {
 		DB:       redisConf.Db,
 		//PoolSize: 10, //连接池最大socket连接数,默认为10倍CPU数, 10 * runtime.NumCPU(暂不配置)
 	})
-	pong, err := client.Ping(context.TODO()).Result()
+	_, err := client.Ping(context.TODO()).Result()
 	if err != nil {
 		global.LOG.Error("redis 链接失败:", err)
 		panic("redis 链接失败:" + err.Error())
-	} else {
-		fmt.Println("redis 链接成功,ping response:", pong)
 	}
 
 	//全局赋值redis链接

+ 7 - 8
logic/user/user.go

@@ -215,7 +215,6 @@ func GetLastApplyInfo(userId int) (record Record, err error) {
 
 // Apply 客户申请
 func Apply(userId int, companyId int64, mobile, email string, applyInfo userReq.ApplyReq) (ybApplyRecord *yb_apply_record.YbApplyRecord, err error) {
-	ficcSelleriD := 0
 	sellerName := ``
 	status := `潜在客户`
 	companyName := applyInfo.CompanyName
@@ -243,12 +242,13 @@ func Apply(userId int, companyId int64, mobile, email string, applyInfo userReq.
 		}
 		sellerNameList := make([]string, 0)
 		statusList := make([]string, 0)
-		for _, companyProduct := range companyProductList {
-			sellerNameList = append(sellerNameList, companyProduct.SellerName)
-			statusList = append(statusList, companyProduct.Status)
-
-			if companyProduct.ProductID == 1 {
-				ficcSelleriD = companyProduct.SellerID
+		for _, companyProductInfo := range companyProductList {
+			if companyProductInfo.ProductID == 2 && status == "潜在客户" {
+				status = "权益客户"
+			}
+			if companyProductInfo.ProductID == 1 {
+				sellerName = companyProductInfo.SellerName
+				status = companyProductInfo.Status
 			}
 		}
 		if len(sellerNameList) > 0 && len(statusList) > 0 {
@@ -264,7 +264,6 @@ func Apply(userId int, companyId int64, mobile, email string, applyInfo userReq.
 		Mobile:          mobile,
 		Email:           email,
 		Permission:      applyInfo.Permission,
-		FiccSellerID:    uint32(ficcSelleriD),
 		SellerName:      sellerName,
 		Status:          status,
 		CompanyIDPay:    int(companyId),

+ 41 - 4
services/company/permission.go

@@ -4,8 +4,10 @@ import (
 	"fmt"
 	"hongze/hongze_yb/models/tables/admin"
 	"hongze/hongze_yb/models/tables/chart_permission"
+	"hongze/hongze_yb/models/tables/company"
 	"hongze/hongze_yb/models/tables/company_product"
 	"hongze/hongze_yb/models/tables/company_report_permission"
+	"hongze/hongze_yb/models/tables/wx_user"
 	"hongze/hongze_yb/utils"
 )
 
@@ -45,9 +47,18 @@ func GetValidPermissionIdListByCompany2ProductId(companyId, productId int64) (li
 
 // PermissionCheckInfo 权限校验完成后的结果
 type PermissionCheckInfo struct {
-	Name   string `json:"name" description:"销售名称"`
-	Mobile string `json:"mobile" description:"手机号"`
-	Type   string `json:"type" description:"校验失败,没有权限,需要让前端处理的类型,枚举值:apply,contact"`
+	Name         string       `json:"name" description:"销售名称"`
+	Mobile       string       `json:"mobile" description:"手机号"`
+	Type         string       `json:"type" description:"校验失败,没有权限,需要让前端处理的类型,枚举值:apply,contact"`
+	CustomerInfo CustomerInfo `json:"customer_info" description:"客户信息"`
+}
+
+// CustomerInfo 客户信息
+type CustomerInfo struct {
+	CompanyName string `json:"company_name" description:"客户(公司)名称"`
+	Name        string `json:"name" description:"联系人名称"`
+	Mobile      string `json:"mobile" description:"手机号"`
+	Status      string `json:"status" description:"状态"`
 }
 
 // CheckPermissionByFicc 权限校验
@@ -107,12 +118,13 @@ func CheckPermissionByFicc(companyId int64, permissionId int) (ok bool, permissi
 }
 
 // CheckPermissionByPermissionIdList2Ficc 根据权限id集合权限校验
-func CheckPermissionByPermissionIdList2Ficc(companyId int64, permissionIdList []int) (ok bool, permissionCheckInfo PermissionCheckInfo, err error) {
+func CheckPermissionByPermissionIdList2Ficc(companyId int64, userId int, permissionIdList []int) (ok bool, permissionCheckInfo PermissionCheckInfo, err error) {
 	//非潜在客户
 	if len(permissionIdList) <= 0 {
 		err = fmt.Errorf("权限异常,请传入需要校验的权限")
 		return
 	}
+
 	permissionMap := make(map[int]bool)
 	for _, permissionId := range permissionIdList {
 		permissionMap[permissionId] = true
@@ -132,6 +144,31 @@ func CheckPermissionByPermissionIdList2Ficc(companyId int64, permissionIdList []
 			return
 		}
 
+		wxUser, err := wx_user.GetByUserId(userId)
+		if err != nil {
+			permissionCheckInfo.Type = "apply"
+			return
+		}
+
+		//客户信息
+		companyInfo, tmpErr := company.GetByCompanyId(companyId)
+		if tmpErr != nil {
+			// 没有开通ficc的客户
+			if tmpErr == utils.ErrNoRow {
+				permissionCheckInfo.Type = "apply"
+				return
+			}
+			err = tmpErr
+			return
+		}
+		customerInfo := CustomerInfo{
+			CompanyName: companyInfo.CompanyName,
+			Status:      companyProductInfo.Status,
+			Name:        wxUser.RealName,
+			Mobile:      wxUser.Mobile,
+		}
+		permissionCheckInfo.CustomerInfo = customerInfo
+
 		// 如果客户ficc产品的状态是流失,那么也是让去申请
 		if companyProductInfo.Status == "流失" {
 			permissionCheckInfo.Type = "apply"