-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.go
141 lines (113 loc) · 3.37 KB
/
db.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package main
import (
"log"
"os"
"path/filepath"
"time"
"github.com/astaxie/beego/orm"
_ "github.com/mattn/go-sqlite3"
)
var (
dborm orm.Ormer
)
func init() {
// orm.RegisterDriver("sqlite3", orm.DRSqlite)
dbfile := filepath.Join(filepath.Dir(os.Args[0]), "data.db") // macos app 访问文件必须用路径; 否则,编译的可执行程序能打开,但打包成app后,app双击打开立即闪退.
err := orm.RegisterDataBase("default", "sqlite3", dbfile)
if err != nil {
log.Fatalln(err)
}
// orm.ResetModelCache()
orm.RegisterModelWithPrefix("t_", new(User), new(PurchaseRecord), new(SaleRecord), new(CostRecord), new(StockRecord), new(FinanceStatics))
orm.RunSyncdb("default", false, false)
dborm = orm.NewOrm()
}
type User struct {
Id int
Name string
Password string
Deleted int // 删除标志
Created time.Time `orm:"auto_now_add"`
Updated time.Time `orm:"auto_now"`
}
// type Record struct {
// Id int `orm:"pk;auto;null"`
// Date string
// }
// func (r *Record) VerifyDate() bool {
// return verifyDate(r.Date) == nil
// }
type PurchaseRecord struct {
// Record
Id int
Date string
Provider string // 供应商
Logistics string // 物流
Specifications string // 规格
Number int // 件数
Weight, Price, Total float64
Deleted int // 删除标志
Created time.Time `orm:"auto_now_add"`
Updated time.Time `orm:"auto_now"`
}
func (p *PurchaseRecord) CalcTotal() float64 {
return FloatMul(p.Weight, p.Price)
}
type SaleRecord struct {
// Record
Id int `orm:"pk;auto;null"`
Date string
Customer string // 客户名
Logistics string // 物流
Specifications string
Number int
Weight, Price, Total float64
Deleted int // 删除标志
Created time.Time `orm:"auto_now_add"`
Updated time.Time `orm:"auto_now"`
}
func (p *SaleRecord) CalcTotal() float64 {
return FloatMul(p.Weight, p.Price)
}
type CostRecord struct {
// Record
Id int `orm:"pk;auto;null"`
Date string
TeaCost, LaborCost, Freight, Postage, CartonCost float64 // postage意义更改为油费了
Consumables, PackingCharges float64
Total float64
Deleted int // 删除标志
Created time.Time `orm:"auto_now_add"`
Updated time.Time `orm:"auto_now"`
}
func (r *CostRecord) CalcTotal() float64 {
return FloatSum(r.TeaCost, r.LaborCost, r.Freight, r.Postage, r.CartonCost, +r.Consumables, +r.PackingCharges)
}
type StockRecord struct {
// Record
Id int `orm:"pk;auto;null"`
Date string
Specifications string
Operation string
Weight, Money float64
SurplusStock float64 // 剩余库存
Deleted int // 删除标志
Created time.Time `orm:"auto_now_add"`
Updated time.Time `orm:"auto_now"`
}
type FinanceStatics struct {
// Record
Id int `orm:"pk;auto;null"`
Date string
Purchase, Sale, Cost, LastBalance, Total float64
PurchasedStock, SaledStock, LastStock, TotalStock float64 // 今日消耗库存, 昨日库存, 剩余库存
Deleted int // 删除标志
Created time.Time `orm:"auto_now_add"`
Updated time.Time `orm:"auto_now"`
}
func (r *FinanceStatics) CalcTotal() float64 {
return FloatSum(r.Sale, -r.Purchase, -r.Cost, +r.LastBalance)
}
func (r *FinanceStatics) CalcStock() float64 {
return FloatSum(r.PurchasedStock, r.LastStock, -r.SaledStock)
}