|
|
/**
|
|
|
@author: stevechan
|
|
|
@date: 2021/2/1
|
|
|
@note:
|
|
|
**/
|
|
|
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"time"
|
|
|
|
|
|
"github.com/go-pg/pg/v10"
|
|
|
"github.com/go-pg/pg/v10/orm"
|
|
|
)
|
|
|
|
|
|
// 默认选中栏目
|
|
|
var DefaultColumns = []Column{
|
|
|
{
|
|
|
Id: "index",
|
|
|
ParamCn: "序号",
|
|
|
ParamFix: 1,
|
|
|
}, {
|
|
|
Id: "orderId",
|
|
|
ParamCn: "订单号",
|
|
|
ParamFix: 2,
|
|
|
}, {
|
|
|
Id: "shipmentsId",
|
|
|
ParamCn: "发货单号",
|
|
|
ParamFix: 2,
|
|
|
}, {
|
|
|
Id: "saleDate",
|
|
|
ParamCn: "销售日期",
|
|
|
ParamFix: 2,
|
|
|
}, {
|
|
|
Id: "orderNum",
|
|
|
ParamCn: "订单数量",
|
|
|
ParamFix: 2,
|
|
|
}, {
|
|
|
Id: "quantityControl",
|
|
|
ParamCn: "数量调整",
|
|
|
ParamFix: 2,
|
|
|
}, {
|
|
|
Id: "orderPrice",
|
|
|
ParamCn: "订单金额",
|
|
|
ParamFix: 2,
|
|
|
}, {
|
|
|
Id: "priceControl",
|
|
|
ParamCn: "金额调整",
|
|
|
ParamFix: 2,
|
|
|
}, {
|
|
|
Id: "orderDist",
|
|
|
ParamCn: "订单区域",
|
|
|
ParamFix: 2,
|
|
|
}, {
|
|
|
Id: "partnerCategory",
|
|
|
ParamCn: "合伙人类型",
|
|
|
ParamFix: 2,
|
|
|
}, {
|
|
|
Id: "buyer",
|
|
|
ParamCn: "客户",
|
|
|
ParamFix: 2,
|
|
|
}, {
|
|
|
Id: "partner",
|
|
|
ParamCn: "合伙人",
|
|
|
ParamFix: 2,
|
|
|
},
|
|
|
}
|
|
|
|
|
|
// 默认未选中栏目
|
|
|
var DefaultInvalidColumns = []Column{
|
|
|
{
|
|
|
Id: "updateTime",
|
|
|
ParamCn: "更新时间",
|
|
|
ParamFix: 2,
|
|
|
}, {
|
|
|
Id: "createTime",
|
|
|
ParamCn: "创建时间",
|
|
|
ParamFix: 2,
|
|
|
},
|
|
|
}
|
|
|
|
|
|
// 栏目项值对象
|
|
|
type Column struct {
|
|
|
// 列标记
|
|
|
Id string `json:"id"`
|
|
|
// 列标记中文
|
|
|
ParamCn string `json:"paramCn"`
|
|
|
// 列标记是否固定,1:固定,2:不固定
|
|
|
ParamFix int `json:"paramFix"`
|
|
|
}
|
|
|
|
|
|
type ColumnSetting struct {
|
|
|
// 栏目设置id
|
|
|
Id int64
|
|
|
// 栏目设置关联用户公司id
|
|
|
CompanyId int
|
|
|
// 栏目设置创建时间
|
|
|
CreatedAt time.Time
|
|
|
// 栏目设置描述
|
|
|
Description string
|
|
|
// 栏目设置模块名称
|
|
|
Key string
|
|
|
// 栏目设置关联用户uid
|
|
|
Uid int64
|
|
|
// 栏目设置更新时间
|
|
|
UpdatedAt time.Time
|
|
|
// 栏目设置关联用户名称
|
|
|
UserName string
|
|
|
// 栏目数组
|
|
|
Value []Column `pg:",array"`
|
|
|
// 无效栏目数组
|
|
|
InvalidValue []Column `pg:",array"`
|
|
|
}
|
|
|
|
|
|
func (c ColumnSetting) String() string {
|
|
|
return fmt.Sprintf("Story<%d %v %v>", c.Id, c.CompanyId, c.Uid)
|
|
|
}
|
|
|
|
|
|
type AdminPermissionBase struct {
|
|
|
Id int64 `json:"id"`
|
|
|
Code string `json:"code"`
|
|
|
}
|
|
|
|
|
|
type Partner struct {
|
|
|
// 合伙人ID
|
|
|
Id int64 `json:"id"`
|
|
|
// 合伙人姓名
|
|
|
PartnerName string `json:"partnerName"`
|
|
|
// 登录账号
|
|
|
Account string `json:"account"`
|
|
|
}
|
|
|
|
|
|
type Users struct {
|
|
|
tableName struct{} `pg:"users"`
|
|
|
Id int64 `pg:",pk"` //用户id
|
|
|
CompanyId int64 //公司id
|
|
|
OpenId int64 //统一用户中心
|
|
|
Name string //用户名称
|
|
|
Sex int8 //性别:【0:未知】【1:男】【2:女】
|
|
|
JobNum string //工号
|
|
|
Phone string //手机号,同账号
|
|
|
PrivatePhone string //私人手机号
|
|
|
Email string //邮件
|
|
|
ExtensionNum string //分机号
|
|
|
EntryTime time.Time //入职时间
|
|
|
Workspace string //工作地
|
|
|
Status int8 //状态:【1:正常】【 2:禁用】
|
|
|
Avatar string ///头像
|
|
|
Remarks string //备注
|
|
|
AdminType int8 //是否为当前公司负责人 【1:是】【2:否】
|
|
|
ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】
|
|
|
Permission []AdminPermissionBase //权限
|
|
|
AccessPartners []Partner //可查看的合伙人
|
|
|
IsSenior int8 //是否是公司高管【1:是】【2:否】;用于确定是否可以拥有“可查看的合伙人”
|
|
|
CreateAt time.Time
|
|
|
UpdateAt time.Time
|
|
|
DeleteAt time.Time
|
|
|
}
|
|
|
|
|
|
func (u Users) String() string {
|
|
|
return fmt.Sprintf("User<%d %s %v>", u.Id, u.Name, u.CompanyId)
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
// 本地开发
|
|
|
//db := pg.Connect(&pg.Options{
|
|
|
// User: "postgres",
|
|
|
// Addr: ":5432",
|
|
|
// Password: "1993618jack",
|
|
|
// Database: "partner_test",
|
|
|
//})
|
|
|
// 测试环境
|
|
|
db := pg.Connect(&pg.Options{
|
|
|
User: "postgres",
|
|
|
Addr: "114.55.200.59:31543",
|
|
|
Password: "eagle1010",
|
|
|
Database: "partner_test",
|
|
|
})
|
|
|
defer db.Close()
|
|
|
|
|
|
err := createSchema(db)
|
|
|
if err != nil {
|
|
|
panic(err)
|
|
|
}
|
|
|
|
|
|
// Select all users.
|
|
|
var users []Users
|
|
|
err = db.Model(&users).Select()
|
|
|
if err != nil {
|
|
|
panic(err)
|
|
|
}
|
|
|
|
|
|
var companyUidMap = map[int64]int64{}
|
|
|
|
|
|
for _, user := range users {
|
|
|
companyUidMap[user.CompanyId] = user.Id
|
|
|
}
|
|
|
|
|
|
for companyId, uid := range companyUidMap {
|
|
|
newColumnSetting := &ColumnSetting{
|
|
|
CompanyId: int(companyId),
|
|
|
CreatedAt: time.Now(),
|
|
|
Description: "订单栏目设置",
|
|
|
Key: "order_base",
|
|
|
Uid: uid,
|
|
|
UpdatedAt: time.Now(),
|
|
|
UserName: "",
|
|
|
Value: DefaultColumns,
|
|
|
InvalidValue: DefaultInvalidColumns,
|
|
|
}
|
|
|
|
|
|
_, err = db.Model(newColumnSetting).Insert()
|
|
|
if err != nil {
|
|
|
panic(err)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// createSchema creates database schema for User and Story models.
|
|
|
func createSchema(db *pg.DB) error {
|
|
|
models := []interface{}{
|
|
|
(*Users)(nil),
|
|
|
(*ColumnSetting)(nil),
|
|
|
}
|
|
|
|
|
|
for _, model := range models {
|
|
|
err := db.Model(model).CreateTable(&orm.CreateTableOptions{
|
|
|
Temp: false,
|
|
|
IfNotExists: true,
|
|
|
FKConstraints: true,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
} |