胡轶钦 6 anos atrás
pai
commit
de99c0e22a

+ 130
- 0
models/book/book.go Ver arquivo

@@ -0,0 +1,130 @@
1
+package book
2
+
3
+import (
4
+	"spaceofcheng/services/models"
5
+	"spaceofcheng/services/models/model"
6
+	"spaceofcheng/services/utils"
7
+	"strconv"
8
+	"strings"
9
+	"time"
10
+
11
+	"github.com/go-xorm/xorm"
12
+)
13
+
14
+// BookDAO 当前数据库操作对象
15
+type BookDAO struct {
16
+	ctx *utils.Context
17
+	db  *xorm.Session
18
+}
19
+
20
+// NewBookDAO New Inst
21
+func NewBookDAO(ctx *utils.Context) *BookDAO {
22
+	return &BookDAO{
23
+		ctx: ctx,
24
+		db:  ctx.DB,
25
+	}
26
+}
27
+
28
+func (m *BookDAO) GetBookList(bookType, caseid string, page, pageSize int) ([]model.TaBook, error) {
29
+	var book []model.TaBook
30
+	sql := `select * from ta_book where status = '` + strconv.Itoa(models.STATUS_NORMAL) + `'
31
+	and a.case_id in('` + strings.Replace(caseid, ",", "','", -1) + `')`
32
+	if bookType != "" {
33
+		sql += ` and book_type_id = '` + bookType + `'`
34
+	}
35
+	sql += ` order by create_date desc limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
36
+	err := m.db.Sql(sql).Find(&book)
37
+	return book, err
38
+
39
+}
40
+
41
+func (m *BookDAO) GetBookById(bookId string) (*model.TaBook, error) {
42
+	var book []model.TaBook
43
+	sql := `select * from ta_book where book_id = '` + bookId + `'`
44
+	err := m.db.Sql(sql).Find(&book)
45
+	if len(book) >= 0 {
46
+		return &book[0], err
47
+	}
48
+	return nil, err
49
+}
50
+
51
+func (m *BookDAO) AddBook(book model.TaBook) (*model.TaBook, error) {
52
+	book.Status = models.STATUS_NORMAL
53
+	book.BookId = utils.GetGUID()
54
+	book.CreateDate = time.Now()
55
+	_, err := m.db.Insert(book)
56
+	return &book, err
57
+}
58
+func (m *BookDAO) EditBook(book model.TaBook) error {
59
+	var cols = []string{
60
+		"book_type_id",
61
+		"book_name",
62
+		"book_img",
63
+		"author",
64
+		"publisher",
65
+		"price",
66
+		"book_description",
67
+	}
68
+	_, err := m.db.Cols(cols...).Where("book_id = ?", book.BookId).Update(book)
69
+	return err
70
+}
71
+func (m *BookDAO) AddBookRecord(record model.TaBookBorrowRecord) (*model.TaBookBorrowRecord, error) {
72
+	record.BookBorrowRecordId = utils.GetGUID()
73
+	_, err := m.db.Insert(record)
74
+	return &record, err
75
+}
76
+func (m *BookDAO) UpdateBookRecord(record model.TaBookBorrowRecord) error {
77
+	var cols = []string{
78
+		"borrow_date",
79
+		"return_date",
80
+		"borrow_status",
81
+		"end_date",
82
+	}
83
+	_, err := m.db.Cols(cols...).Where("book_borrow_record_id = ?", record.BookBorrowRecordId).Update(record)
84
+	return err
85
+}
86
+func (m *BookDAO) UpdateInStockBook(book model.TaBook) error {
87
+	var cols = []string{
88
+		"in_stock",
89
+		"left_num",
90
+	}
91
+	_, err := m.db.Cols(cols...).Where("book_id = ?", book.BookId).Update(book)
92
+	return err
93
+}
94
+
95
+type BorrowRecord struct {
96
+	model.TaBookBorrowRecord `xorm:"extends"`
97
+	BookBarcode              string
98
+	BookName                 string
99
+}
100
+
101
+func (m *BookDAO) GetRecordList(borrowStatus, caseid, customerName, customerPhone, bookName, barcode string, page, pageSize int) ([]BorrowRecord, error) {
102
+	var record []BorrowRecord
103
+	sql := `SELECT
104
+	a.*,
105
+	b.book_name,
106
+	b.book_barcode
107
+FROM
108
+	ta_book_borrow_record a
109
+	INNER JOIN ta_book b ON a.book_id = b.book_id
110
+	where a.case_id in('` + strings.Replace(caseid, ",", "','", -1) + `')`
111
+	if borrowStatus != "" {
112
+		sql += ` and a.borrow_status = '` + borrowStatus + `' `
113
+	}
114
+	if customerName != "" {
115
+		sql += ` and a.customer_name = '` + customerName + `' `
116
+	}
117
+	if customerPhone != "" {
118
+		sql += ` and a.customer_phone ='` + customerPhone + `' `
119
+	}
120
+	if bookName != "" {
121
+		sql += ` and b.book_name = '` + bookName + `' `
122
+	}
123
+	if barcode != "" {
124
+		sql += ` and b.book_barcode = '` + barcode + `'`
125
+	}
126
+	sql += ` order by a.create_date desc limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
127
+	err := m.db.Sql(sql).Find(&record)
128
+	return record, err
129
+
130
+}

+ 40
- 0
models/booktype/booktype.go Ver arquivo

@@ -1,7 +1,12 @@
1 1
 package booktype
2 2
 
3 3
 import (
4
+	"spaceofcheng/services/models"
5
+	"spaceofcheng/services/models/model"
4 6
 	"spaceofcheng/services/utils"
7
+	"strconv"
8
+	"strings"
9
+	"time"
5 10
 
6 11
 	"github.com/go-xorm/xorm"
7 12
 )
@@ -19,3 +24,38 @@ func NewBooktypeDAO(ctx *utils.Context) *BooktypeDAO {
19 24
 		db:  ctx.DB,
20 25
 	}
21 26
 }
27
+
28
+func (m *BooktypeDAO) GetBookTypeList(caseid string, page, pageSize int) ([]model.TaBookType, error) {
29
+	var booktype []model.TaBookType
30
+	sql := `select * from ta_book_type where status = '` + strconv.Itoa(models.STATUS_NORMAL) + `'
31
+	and a.case_id in('` + strings.Replace(caseid, ",", "','", -1) + `')
32
+	order by create_date desc limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
33
+	err := m.db.Sql(sql).Find(&booktype)
34
+	return booktype, err
35
+}
36
+
37
+func (m *BooktypeDAO) GetBookTypeById(bookTypeId string) (*model.TaBookType, error) {
38
+	var booktype []model.TaBookType
39
+	sql := `select * from ta_book_type where book_type_id = '` + bookTypeId + `'`
40
+	err := m.db.Sql(sql).Find(&booktype)
41
+	if len(booktype) <= 0 {
42
+		return nil, err
43
+	}
44
+	return &booktype[0], err
45
+}
46
+func (m *BooktypeDAO) AddBookType(booktype model.TaBookType) (*model.TaBookType, error) {
47
+	booktype.Status = models.STATUS_NORMAL
48
+	booktype.CreateDate = time.Now()
49
+	booktype.BookTypeId = utils.GetGUID()
50
+	_, err := m.db.Insert(booktype)
51
+	return &booktype, err
52
+}
53
+func (m *BooktypeDAO) EditBookType(booktype model.TaBookType) error {
54
+	var cols = []string{
55
+		"book_type_name",
56
+		"book_type_img",
57
+	}
58
+	_, err := m.db.Cols(cols...).Where("book_type_id =?", booktype.BookTypeId).Update(booktype)
59
+	return err
60
+
61
+}

+ 1
- 0
models/calendar/calendar.go Ver arquivo

@@ -146,6 +146,7 @@ WHERE
146 146
 	return calendar, err
147 147
 }
148 148
 
149
+
149 150
 // GetCalendarFrontImgDetailById 获取日历详情图片
150 151
 func (m *CalendarDAO) GetCalendarFrontImgDetailById(calendarId string) ([]model.TaCalendarImg, error) {
151 152
 	var imgs []model.TaCalendarImg

+ 9
- 0
models/constant.go Ver arquivo

@@ -252,3 +252,12 @@ const (
252 252
 	CALENDAR_MAKING = "making"
253 253
 	CALENDAR_FINISH = "finish"
254 254
 )
255
+
256
+// 借书状态
257
+const (
258
+	BORROW_TYPE_RESERVE  = "reserve"
259
+	BORROW_TYPE_BORROWED = "borrowed"
260
+	BORROW_TYPE_RETURN   = "return"
261
+	BORROW_TYPE_EXPIRE   = "expire"
262
+	BORROW_TYPE_LATE     = "late"
263
+)

+ 2
- 0
models/model/ta_book_borrow_record.go Ver arquivo

@@ -10,9 +10,11 @@ type TaBookBorrowRecord struct {
10 10
 	CustomerId         string    `xorm:"VARCHAR(64)"`
11 11
 	CustomerName       string    `xorm:"VARCHAR(32)"`
12 12
 	CustomerPhone      string    `xorm:"VARCHAR(32)"`
13
+	ReserveDate        time.Time `xorm:"DATETIME"`
13 14
 	BorrowDate         time.Time `xorm:"DATETIME"`
14 15
 	ReturnDate         time.Time `xorm:"DATETIME"`
15 16
 	EndDate            time.Time `xorm:"DATETIME"`
17
+	CreateDate         time.Time `xorm:"DATETIME"`
16 18
 	BorrowStatus       string    `xorm:"VARCHAR(32)"`
17 19
 	CaseId             string    `xorm:"VARCHAR(64)"`
18 20
 	OrgId              string    `xorm:"VARCHAR(64)"`