corp
This commit is contained in:
parent
509da2d4ef
commit
d151cfcaba
|
@ -58,6 +58,7 @@ type Config struct {
|
|||
Server *Server `toml:"server"`
|
||||
Mysql *Mysql `toml:"mysql"`
|
||||
UnifyMysql *Mysql `toml:"unify_mysql"`
|
||||
CorpMysql *Mysql `toml:"corp_mysql"`
|
||||
Redis *Redis `toml:"redis"`
|
||||
QyWeixin *QyWeixin `toml:"qyweixin"`
|
||||
WxPay *WxPay `toml:"wxpay"`
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package dao
|
||||
|
||||
import (
|
||||
"enterprise/common/model"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type CorpOrderData struct {
|
||||
}
|
||||
|
||||
func NewCorpOrderData() *CorpOrderData {
|
||||
return &CorpOrderData{}
|
||||
}
|
||||
|
||||
func (d *CorpOrderData) TableName() string {
|
||||
return "cp_order"
|
||||
}
|
||||
|
||||
func (d *CorpOrderData) QueryOwnerData(owner, startDay, endDay string) (*model.CorpOrderData, error) {
|
||||
tx := corpDB.Table(d.TableName())
|
||||
|
||||
var o model.CorpOrderData
|
||||
|
||||
tx = tx.Where("data_type = ?", "account_report")
|
||||
tx = tx.Where("owner = ?", owner)
|
||||
if startDay != "" {
|
||||
tx = tx.Where("day >= ?", startDay)
|
||||
}
|
||||
if endDay != "" {
|
||||
tx = tx.Where("day <= ?", endDay)
|
||||
}
|
||||
|
||||
tx = tx.First(&o)
|
||||
if tx.Error == gorm.ErrRecordNotFound {
|
||||
return &o, nil
|
||||
}
|
||||
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
return &o, nil
|
||||
}
|
|
@ -5,6 +5,7 @@ import "gorm.io/gorm"
|
|||
var (
|
||||
db *gorm.DB
|
||||
unifyDB *gorm.DB
|
||||
corpDB *gorm.DB
|
||||
)
|
||||
|
||||
func SetDB(d *gorm.DB) {
|
||||
|
@ -14,6 +15,9 @@ func SetDB(d *gorm.DB) {
|
|||
func SetUnifyDB(d *gorm.DB) {
|
||||
unifyDB = d
|
||||
}
|
||||
func SetCorpDB(d *gorm.DB) {
|
||||
corpDB = d
|
||||
}
|
||||
|
||||
func GetDB() *gorm.DB {
|
||||
return db
|
||||
|
|
|
@ -70,6 +70,7 @@ func initDB() error {
|
|||
db.Logger = &DBLogger{threshold: int64(2000)}
|
||||
dao.SetDB(db)
|
||||
|
||||
//unify
|
||||
unifyDsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", cfg.UnifyMysql.User,
|
||||
cfg.UnifyMysql.Pass, cfg.UnifyMysql.Host, cfg.UnifyMysql.Port, cfg.UnifyMysql.Db)
|
||||
db, err = gorm.Open(mysql.Open(unifyDsn), &gorm.Config{})
|
||||
|
@ -79,6 +80,17 @@ func initDB() error {
|
|||
}
|
||||
db.Logger = &DBLogger{threshold: int64(2000)}
|
||||
dao.SetUnifyDB(db)
|
||||
|
||||
//corpy
|
||||
corpDsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", cfg.CorpMysql.User,
|
||||
cfg.CorpMysql.Pass, cfg.CorpMysql.Host, cfg.CorpMysql.Port, cfg.CorpMysql.Db)
|
||||
db, err = gorm.Open(mysql.Open(corpDsn), &gorm.Config{})
|
||||
if err != nil {
|
||||
log.Errorf("open dsn[%s] error[%s]", dsn, err)
|
||||
return err
|
||||
}
|
||||
db.Logger = &DBLogger{threshold: int64(2000)}
|
||||
dao.SetCorpDB(db)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package model
|
||||
|
||||
type CorpOrderData struct {
|
||||
PayCount int64
|
||||
PayAmount int64
|
||||
RefundCount int64
|
||||
RefundAmount int64
|
||||
}
|
|
@ -18,6 +18,14 @@ pass = "MDE2LCJIYXNoSWQiOjY"
|
|||
db = "unify"
|
||||
threshold = 5000
|
||||
|
||||
[corp_mysql]
|
||||
host = "10.0.2.157"
|
||||
port = 13307
|
||||
user = "corp"
|
||||
pass = "UvFwai9N_Nx2zgny"
|
||||
db = "corp"
|
||||
threshold = 10000
|
||||
|
||||
[redis]
|
||||
addr="192.168.2.50:6379"
|
||||
db=0
|
||||
|
|
|
@ -18,6 +18,14 @@ pass = "MDE2LCJIYXNoSWQiOjY"
|
|||
db = "unify"
|
||||
threshold = 5000
|
||||
|
||||
[corp_mysql]
|
||||
host = "10.0.2.157"
|
||||
port = 3307
|
||||
user = "corp"
|
||||
pass = "UvFwai9N_Nx2zgny"
|
||||
db = "corp"
|
||||
threshold = 10000
|
||||
|
||||
[redis]
|
||||
addr="127.0.0.1:6379"
|
||||
db=0
|
||||
|
|
Loading…
Reference in New Issue