Przeglądaj źródła

Merge branch '20211122' of http://git.shengws.com/csx/XT_New into 20211122

csx 3 lat temu
rodzic
commit
f106eeae4d

Plik diff jest za duży
+ 1253 - 8
controllers/supply_order_api_contorller.go


+ 137 - 1
models/supply.models.go Wyświetl plik

@@ -1,5 +1,23 @@
1 1
 package models
2 2
 
3
+//供应商联系人
4
+type SpSupplierContacts struct {
5
+	ID           int64  `gorm:"column:id" json:"id" from:"id"`
6
+	Name         string `gorm:"column:name" json:"name" from:"name"`
7
+	Phone        string `gorm:"column:phone" json:"phone" from:"phone"`
8
+	Address      string `gorm:"column:address" json:"address" from:"address"`
9
+	IsFirst      int64  `gorm:"column:is_first" json:"is_first" from:"is_first"`
10
+	SupplierCode string `gorm:"column:supplier_code" json:"supplier_code" from:"supplier_code"`
11
+	UserOrgId    int64  `gorm:"column:user_org_id" json:"user_org_id" from:"user_org_id"`
12
+	Status       int64  `gorm:"column:status" json:"status" from:"status"`
13
+	Ctime        int64  `gorm:"column:ctime" json:"ctime" from:"ctime"`
14
+	Mtime        int64  `gorm:"column:mtime" json:"mtime" from:"mtime"`
15
+}
16
+
17
+func (SpSupplierContacts) TableName() string {
18
+	return "xt_supplier_contacts"
19
+}
20
+
3 21
 type SpBaseDrug struct {
4 22
 	ID                int64                  `gorm:"column:id" json:"id" form:"id"`
5 23
 	DrugName          string                 `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
@@ -80,7 +98,7 @@ type SpSupplierName struct {
80 98
 	BankAccount  string  `gorm:"column:bank_account" json:"bank_account" form:"bank_account"`
81 99
 	UserOrgId    int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
82 100
 	Status       int64   `gorm:"column:status" json:"status" form:"status"`
83
-	ContactsId   string  `gorm:"column:contacts_id" json:"contacts_id" form:"contacts_id"`
101
+	ContactsId   int64   `gorm:"column:contacts_id" json:"contacts_id" form:"contacts_id"`
84 102
 	Ctime        int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
85 103
 	Mtime        int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
86 104
 	Creater      int64   `gorm:"column:creater" json:"creater" form:"creater"`
@@ -112,6 +130,7 @@ type SupplierWarehousingInfoOrder struct {
112 130
 	SupplyManufacturer      string  `gorm:"column:supply_manufacturer" json:"supply_manufacturer" form:"supply_manufacturer"`
113 131
 	Name                    string  `gorm:"column:name" json:"name" form:"name"`
114 132
 	SupplyUnit              string  `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
133
+	ManufacturerId          int64   `gorm:"column:manufacturer_id" json:"manufacturer_id" form:"manufacturer_id"`
115 134
 }
116 135
 
117 136
 func (SupplierWarehousingInfoOrder) TableName() string {
@@ -135,6 +154,7 @@ type SupplierWarehouseInfo struct {
135 154
 	SupplierId       int64   `gorm:"column:supplier_id" json:"supplier_id" form:"supplier_id"`
136 155
 	Checker          int64   `gorm:"column:checker" json:"checker" form:"checker"`
137 156
 	CheckTime        int64   `gorm:"column:check_time" json:"check_time" form:"check_time"`
157
+	IsWarehouse      int64   `gorm:"column:is_warehouse" json:"is_warehouse" form:"is_warehouse"`
138 158
 }
139 159
 
140 160
 func (SupplierWarehouseInfo) TableName() string {
@@ -158,9 +178,125 @@ type VmSupplierWarehouseInfo struct {
158 178
 	SupplierId                   int64                           `gorm:"column:supplier_id" json:"supplier_id" form:"supplier_id"`
159 179
 	Checker                      int64                           `gorm:"column:checker" json:"checker" form:"checker"`
160 180
 	CheckTime                    int64                           `gorm:"column:check_time" json:"check_time" form:"check_time"`
181
+	IsWarehouse                  int64                           `gorm:"column:is_warehouse" json:"is_warehouse" form:"is_warehouse"`
161 182
 	SupplierWarehousingInfoOrder []*SupplierWarehousingInfoOrder `gorm:"ForeignKey:WarehousingId;AssociationForeignKey:ID" json:"orderInfo"`
183
+	SpSupplierWarehouseOut       []*SpSupplierWarehouseOut       `gorm:"ForeignKey:WarehousingId;AssociationForeignKey:ID" json:"orderOut"`
162 184
 }
163 185
 
164 186
 func (VmSupplierWarehouseInfo) TableName() string {
165 187
 	return "xt_supplier_warehouse_info"
166 188
 }
189
+
190
+type SpSupplierWarehousingOutOrder struct {
191
+	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
192
+	OrderNumber             string  `gorm:"column:order_number" json:"order_number" form:"order_number"`
193
+	ProjectId               int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
194
+	IsSource                int64   `gorm:"column:is_source" json:"is_source" form:"is_source"`
195
+	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
196
+	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
197
+	Amount                  float64 `gorm:"column:amount" json:"amount" form:"amount"`
198
+	Remark                  string  `gorm:"column:remark" json:"remark" form:"remark"`
199
+	IsCheck                 int64   `gorm:"column:is_check" json:"is_check" form:"is_check"`
200
+	UserOrgId               int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
201
+	Status                  int64   `gorm:"column:status" json:"status" form:"status"`
202
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
203
+	Mtime                   int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
204
+	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
205
+	Type                    int64   `gorm:"column:type" json:"type" form:"type"`
206
+	SupplyBatchNumber       string  `gorm:"column:supply_batch_number" json:"supply_batch_number" form:"supply_batch_number"`
207
+	SupplyProductDate       int64   `gorm:"column:supply_product_date" json:"supply_product_date" form:"supply_product_date"`
208
+	SupplyExpiryDate        int64   `gorm:"column:supply_expiry_date" json:"supply_expiry_date" form:"supply_expiry_date"`
209
+	WarehousingId           int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
210
+	WarehouseInfoId         int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
211
+	SupplyType              string  `gorm:"column:supply_type" json:"supply_type" form:"supply_type"`
212
+	SupplySpecificationName string  `gorm:"column:supply_specification_name" json:"supply_specification_name" form:"supply_specification_name"`
213
+	SupplyTotal             string  `gorm:"column:supply_total" json:"supply_total" form:"supply_total"`
214
+	SupplyManufacturer      string  `gorm:"column:supply_manufacturer" json:"supply_manufacturer" form:"supply_manufacturer"`
215
+	Name                    string  `gorm:"column:name" json:"name" form:"name"`
216
+	SupplyUnit              string  `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
217
+	ManufacturerId          int64   `gorm:"column:manufacturer_id" json:"manufacturer_id" form:"manufacturer_id"`
218
+	SupplyLicenseNumber     string  `gorm:"column:supply_license_number" json:"supply_license_number" form:"supply_license_number"`
219
+	GoodNumber              string  `gorm:"column:good_number" json:"good_number" form:"good_number"`
220
+}
221
+
222
+func (SpSupplierWarehousingOutOrder) TableName() string {
223
+	return "xt_supplier_warehousing_out_order"
224
+}
225
+
226
+type SpSupplierWarehouseOut struct {
227
+	ID               int64   `gorm:"column:id" json:"id" form:"id"`
228
+	Number           string  `gorm:"column:number" json:"number" form:"number"`
229
+	UserOrgId        int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
230
+	Creater          int64   `gorm:"column:creater" json:"creater" form:"creater"`
231
+	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
232
+	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
233
+	Status           int64   `gorm:"column:status" json:"status" form:"status"`
234
+	RecordDate       int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
235
+	IsCheck          int64   `gorm:"column:is_check" json:"is_check" form:"is_check"`
236
+	WarehousingId    int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
237
+	GoodNumber       string  `gorm:"column:good_number" json:"good_number" form:"good_number"`
238
+	Arrearage        float64 `gorm:"column:arrearage" json:"arrearage" form:"arrearage"`
239
+	Payment          float64 `gorm:"column:payment" json:"payment" form:"payment"`
240
+	RateOfConcession float64 `gorm:"column:rate_of_concession" json:"rate_of_concession" form:"rate_of_concession"`
241
+	DiscountAmount   float64 `gorm:"column:discount_amount" json:"discount_amount" form:"discount_amount"`
242
+	DocumentDate     int64   `gorm:"column:document_date" json:"document_date" form:"document_date"`
243
+	SupplierId       int64   `gorm:"column:supplier_id" json:"supplier_id" form:"supplier_id"`
244
+	Checker          int64   `gorm:"column:checker" json:"checker" form:"checker"`
245
+	CheckTime        int64   `gorm:"column:check_time" json:"check_time" form:"check_time"`
246
+}
247
+
248
+func (SpSupplierWarehouseOut) TableName() string {
249
+	return "xt_supplier_warehouse_out"
250
+}
251
+
252
+type VmSupplierWarehouseOut struct {
253
+	ID                            int64                            `gorm:"column:id" json:"id" form:"id"`
254
+	Number                        string                           `gorm:"column:number" json:"number" form:"number"`
255
+	UserOrgId                     int64                            `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
256
+	Creater                       int64                            `gorm:"column:creater" json:"creater" form:"creater"`
257
+	Ctime                         int64                            `gorm:"column:ctime" json:"ctime" form:"ctime"`
258
+	Mtime                         int64                            `gorm:"column:mtime" json:"mtime" form:"mtime"`
259
+	Status                        int64                            `gorm:"column:status" json:"status" form:"status"`
260
+	RecordDate                    int64                            `gorm:"column:record_date" json:"record_date" form:"record_date"`
261
+	IsCheck                       int64                            `gorm:"column:is_check" json:"is_check" form:"is_check"`
262
+	WarehousingId                 int64                            `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
263
+	GoodNumber                    string                           `gorm:"column:good_number" json:"good_number" form:"good_number"`
264
+	Arrearage                     float64                          `gorm:"column:arrearage" json:"arrearage" form:"arrearage"`
265
+	Payment                       float64                          `gorm:"column:payment" json:"payment" form:"payment"`
266
+	RateOfConcession              float64                          `gorm:"column:rate_of_concession" json:"rate_of_concession" form:"rate_of_concession"`
267
+	DiscountAmount                float64                          `gorm:"column:discount_amount" json:"discount_amount" form:"discount_amount"`
268
+	DocumentDate                  int64                            `gorm:"column:document_date" json:"document_date" form:"document_date"`
269
+	SupplierId                    int64                            `gorm:"column:supplier_id" json:"supplier_id" form:"supplier_id"`
270
+	Checker                       int64                            `gorm:"column:checker" json:"checker" form:"checker"`
271
+	CheckTime                     int64                            `gorm:"column:check_time" json:"check_time" form:"check_time"`
272
+	SpSupplierWarehousingOutOrder []*SpSupplierWarehousingOutOrder `gorm:"ForeignKey:warehouse_out_id;AssociationForeignKey:ID" json:"orderOut"`
273
+}
274
+
275
+func (VmSupplierWarehouseOut) TableName() string {
276
+	return "xt_supplier_warehouse_out"
277
+}
278
+
279
+type VSpSupplierWarehousingOutOrder struct {
280
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
281
+	OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
282
+	ProjectId   int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
283
+	Count       int64  `gorm:"column:count" json:"count" form:"count"`
284
+	Status      int64  `gorm:"column:status" json:"status" form:"status"`
285
+	SupplyUnit  string `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
286
+	IsSource    int64  `gorm:"column:is_source" json:"is_source" form:"is_source"`
287
+}
288
+
289
+func (VSpSupplierWarehousingOutOrder) TableName() string {
290
+	return "xt_supplier_warehousing_out_order"
291
+}
292
+
293
+type VSupplierWarehousingInfoOrder struct {
294
+	Count      int64  `gorm:"column:count" json:"count" form:"count"`
295
+	ProjectId  int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
296
+	SupplyUnit string `gorm:"column:supply_unit" json:"supply_unit" form:"supply_unit"`
297
+	IsSource   int64  `gorm:"column:is_source" json:"is_source" form:"is_source"`
298
+}
299
+
300
+func (VSupplierWarehousingInfoOrder) TableName() string {
301
+	return "xt_supplier_warehousing_info_order"
302
+}

+ 1 - 1
service/patientmanage_service.go Wyświetl plik

@@ -439,7 +439,7 @@ func FindPatientByDialysisNoOne(orgID int64, dialysisNo string, id int64) (patie
439 439
 }
440 440
 
441 441
 func FindPatientByMobileOne(mobile string, orgID int64, id int64) (patient models.XtPatientsNew, err error) {
442
-	//err = readDb.Model(&models.Patients{}).Where(" status=1 and user_org_id=? and   phone=? and id<>?", orgID, mobile, id).First(&patient).Error
442
+	//err = readDb.Model(&models.XtPatientsNew{}).Where(" status=1 and user_org_id=? and   phone=? and id<>?", orgID, mobile, id).First(&patient).Error
443 443
 	//return
444 444
 	db := readDb.Table("xt_patients_new as x")
445 445
 	err = db.Not("phone = ?", mobile).Where("user_org_id = ? and id = ? and status =1", orgID, id).Find(&patient).Error

+ 412 - 9
service/supply_service.go Wyświetl plik

@@ -2,9 +2,285 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_New/models"
5
+	"github.com/jinzhu/gorm"
6
+	"strconv"
5 7
 	"time"
6 8
 )
7 9
 
10
+//根据供应商编号获取首要联系人
11
+func FindName(code string) (fistname models.SpSupplierContacts, err error) {
12
+	err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1", code).First(&fistname).Error
13
+	return fistname, err
14
+}
15
+
16
+//供应商分页
17
+func GetSupplyList(ctype int64, page int64, limit int64, code string, sname string, cname string) (supplylist []*models.SpSupplierName, total int64, err error) {
18
+	db := XTReadDB().Model(&supplylist).Where("sgj_xt.xt_supplier_name.status = 1 ")
19
+
20
+	offset := (page - 1) * limit
21
+
22
+	if cname != "" {
23
+		cname = "%" + cname + "%" //联系人
24
+		db = db.Joins("join sgj_xt.xt_supplier_contacts on sgj_xt.xt_supplier_contacts.supplier_code = sgj_xt.xt_supplier_name.supplier_code")
25
+		db = db.Where("sgj_xt.xt_supplier_contacts.name like ? and sgj_xt.xt_supplier_contacts.status = 1 ", cname).Group("sgj_xt.xt_supplier_name.id")
26
+	}
27
+	if ctype > 0 {
28
+		db = db.Where("sgj_xt.xt_supplier_name.supplier_type = ?", ctype)
29
+	}
30
+	if code != "" {
31
+		code = "%" + code + "%" //供应商编码
32
+		db = db.Where("sgj_xt.xt_supplier_name.supplier_code = ?", code)
33
+	}
34
+	if sname != "" {
35
+		sname = "%" + sname + "%" //供应商名称
36
+		db = db.Where("sgj_xt.xt_supplier_name.supplier_name = ?", sname)
37
+	}
38
+	err = db.Count(&total).Offset(offset).Limit(limit).Find(&supplylist).Error
39
+	return supplylist, total, err
40
+}
41
+
42
+//修改供应商和联系人
43
+func UpdateSupplyAndContact(thisStockIn []interface{}, suid, orgId, supplierType, tcreater int64, supplierCode, supplierName, number, bank, bankAccount string, vatRate float64) error {
44
+	tx := XTWriteDB().Begin()
45
+	defer func() {
46
+		if err != nil {
47
+			tx.Rollback()
48
+		} else {
49
+			tx.Commit()
50
+		}
51
+	}()
52
+	for _, item := range thisStockIn {
53
+		items := item.(map[string]interface{})
54
+		//查询是否
55
+		id, _ := strconv.ParseInt(items["id"].(string), 10, 64)
56
+		name := items["name"].(string)
57
+		phone := items["phone"].(string)
58
+		address := items["address"].(string)
59
+		isfirst, _ := strconv.ParseInt(items["isfirst"].(string), 10, 64)
60
+		updatecontacts := models.SpSupplierContacts{
61
+			ID:           id,
62
+			Name:         name,
63
+			Phone:        phone,
64
+			Address:      address,
65
+			IsFirst:      isfirst,
66
+			SupplierCode: supplierCode,
67
+			UserOrgId:    orgId,
68
+			Status:       1,
69
+			Ctime:        0,
70
+			Mtime:        time.Now().Unix(),
71
+		}
72
+		if id == 0 {
73
+			spcontacts := models.SpSupplierContacts{
74
+				Name:         name,
75
+				Phone:        phone,
76
+				Address:      address,
77
+				IsFirst:      isfirst,
78
+				SupplierCode: supplierCode,
79
+				UserOrgId:    orgId,
80
+				Status:       1,
81
+				Ctime:        time.Now().Unix(),
82
+				Mtime:        0,
83
+			}
84
+			err = SaveContacts(spcontacts, tx)
85
+			if err != nil {
86
+				return err
87
+			}
88
+		} else {
89
+			err = UpdateContact(updatecontacts, tx)
90
+		}
91
+		var tmpid int64
92
+		if isfirst == 1 {
93
+			if id == 0 {
94
+				var spconid []*models.SpSupplierContacts
95
+				spconid, err = SaveContactsId(tx)
96
+
97
+				if err != nil {
98
+					return err
99
+				}
100
+				tmpid = spconid[0].ID
101
+			} else {
102
+				tmpid = id
103
+			}
104
+			//更新供应商
105
+			upsupply := models.SpSupplierName{
106
+				ID:           suid,
107
+				SupplierCode: supplierCode,
108
+				SupplierName: supplierName,
109
+				SupplierType: supplierType,
110
+				VatRate:      vatRate,
111
+				Number:       number,
112
+				Bank:         bank,
113
+				BankAccount:  bankAccount,
114
+				UserOrgId:    orgId,
115
+				Status:       1,
116
+				ContactsId:   tmpid,
117
+				Mtime:        time.Now().Unix(),
118
+				Modify:       tcreater,
119
+			}
120
+			err = UpdateSupplyName(upsupply, tx)
121
+			if err != nil {
122
+				return err
123
+			}
124
+		}
125
+
126
+	}
127
+	return err
128
+}
129
+
130
+//更新一条供应商的信息
131
+func UpdateSupplyName(upsupply models.SpSupplierName, tx *gorm.DB) error {
132
+	err := tx.Model(&models.SpSupplierName{}).Where("id = ? and status = 1", upsupply.ID).Updates(map[string]interface{}{"supplier_code": upsupply.SupplierCode, "supplier_name": upsupply.SupplierName, "supplier_type": upsupply.SupplierType, "vat_rate": upsupply.VatRate, "number": upsupply.Number, "bank": upsupply.Bank, "bank_account": upsupply.BankAccount, "user_org_id": upsupply.UserOrgId, "status": upsupply.Status, "contacts_id": upsupply.ContactsId, "mtime": upsupply.Mtime, "modify": upsupply.Modify}).Error
133
+	return err
134
+}
135
+
136
+//更新一条联系人的信息
137
+func UpdateContact(updatecontacts models.SpSupplierContacts, tx *gorm.DB) error {
138
+	err := tx.Model(&models.SpSupplierContacts{}).Where("id = ? and status = 1", updatecontacts.ID).Updates(map[string]interface{}{"name": updatecontacts.Name, "phone": updatecontacts.Phone, "address": updatecontacts.Address, "is_first": updatecontacts.IsFirst, "supplier_code": updatecontacts.SupplierCode, "user_org_id": updatecontacts.UserOrgId, "status": updatecontacts.Status, "mtime": updatecontacts.Mtime}).Error
139
+	return err
140
+}
141
+
142
+//查询供应商单条记录
143
+func GetSupplyOne(id int64) (supply models.SpSupplierName, err error) {
144
+	err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1", id).First(&supply).Error
145
+	return supply, err
146
+}
147
+
148
+//删除单条联系人记录
149
+func DelContactOne(id int64) error {
150
+	err := XTWriteDB().Model(&models.SpSupplierContacts{}).Where("id = ?", id).Update("status", 0).Error
151
+	return err
152
+}
153
+
154
+//获取单条供应商和涉及到的联系人记录
155
+func GetSupplyAndContactOne(id int64) (supply models.SpSupplierName, contact []*models.SpSupplierContacts, err error) {
156
+	err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1", id).First(&supply).Error
157
+	code := supply.SupplierCode
158
+	err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1", code).Find(&contact).Error
159
+	return supply, contact, err
160
+}
161
+
162
+//删除供应商及联系人
163
+func DelSupply(supply models.SpSupplierName) error {
164
+	err := XTWriteDB().Model(&supply).Update("status", 0).Error
165
+	return err
166
+}
167
+
168
+//保存供应商和联系人
169
+func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreater int64, supplierCode, supplierName, number, bank, bankAccount string, vatRate float64) error {
170
+	tx := XTWriteDB().Begin()
171
+	defer func() {
172
+		if err != nil {
173
+			tx.Rollback()
174
+		} else {
175
+			tx.Commit()
176
+		}
177
+	}()
178
+	for _, item := range thisStockIn {
179
+		items := item.(map[string]interface{})
180
+		name := items["name"].(string)
181
+		phone := items["phone"].(string)
182
+		address := items["address"].(string)
183
+		isfirst, _ := strconv.ParseInt(items["isfirst"].(string), 10, 64)
184
+
185
+		spcontacts := models.SpSupplierContacts{
186
+			Name:         name,
187
+			Phone:        phone,
188
+			Address:      address,
189
+			IsFirst:      isfirst,
190
+			SupplierCode: supplierCode,
191
+			UserOrgId:    orgId,
192
+			Status:       1,
193
+			Ctime:        time.Now().Unix(),
194
+			Mtime:        0,
195
+		}
196
+		err = SaveContacts(spcontacts, tx)
197
+		if isfirst == 1 {
198
+			var spconid []*models.SpSupplierContacts
199
+			spconid, err = SaveContactsId(tx)
200
+
201
+			if err != nil {
202
+				return err
203
+			}
204
+			tmpid := spconid[0].ID
205
+			//保存供应商
206
+			supply := models.SpSupplierName{
207
+				SupplierCode: supplierCode,
208
+				SupplierName: supplierName,
209
+				SupplierType: supplierType,
210
+				VatRate:      vatRate,
211
+				Number:       number,
212
+				Bank:         bank,
213
+				BankAccount:  bankAccount,
214
+				UserOrgId:    orgId,
215
+				Status:       1,
216
+				ContactsId:   tmpid,
217
+				Ctime:        time.Now().Unix(),
218
+				Mtime:        0,
219
+				Creater:      tcreater,
220
+				Modify:       tcreater,
221
+			}
222
+			err = SaveSupply(supply, tx)
223
+			if err != nil {
224
+				return err
225
+			}
226
+
227
+		}
228
+		if err != nil {
229
+			return err
230
+		}
231
+	}
232
+	return err
233
+}
234
+
235
+//获取供应商编码
236
+func GetSuppliyCode() (spcode []*models.SpSupplierName, err error) {
237
+
238
+	err = XTReadDB().Model(&models.SpSupplierName{}).Select("supplier_code").Where("supplier_code like 'gys%' and status = 1 ").Order("supplier_code desc").First(&spcode).Error
239
+	return spcode, err
240
+}
241
+
242
+//查询供应商的名字是否有重复
243
+func FindSupplierName(supplierName string) (sbool bool, err error) {
244
+	var total int
245
+	err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierName).Count(&total).Error
246
+	if total != 0 {
247
+		sbool = true
248
+	} else {
249
+		sbool = false
250
+	}
251
+	return sbool, err
252
+}
253
+
254
+//查询供应商的编号是否有重复
255
+func FindSupplierCode(supplierCode string) (codebool bool, err error) {
256
+	var total int
257
+	err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierCode).Count(&total).Error
258
+	if total != 0 {
259
+		codebool = true
260
+	} else {
261
+		codebool = false
262
+	}
263
+	return codebool, err
264
+}
265
+
266
+//保存一条供应商数据
267
+func SaveSupply(supply models.SpSupplierName, tx *gorm.DB) error {
268
+	err := tx.Create(&supply).Error
269
+	return err
270
+}
271
+
272
+//获取联系人的id
273
+func SaveContactsId(tx *gorm.DB) (spconid []*models.SpSupplierContacts, err error) {
274
+	err = tx.Model(&models.SpSupplierContacts{}).Select("id").Where("and status = 1").Order("id desc").First(&spconid).Error
275
+	return
276
+}
277
+
278
+//保存一条联系人数据
279
+func SaveContacts(spcontacts models.SpSupplierContacts, tx *gorm.DB) error {
280
+	err := tx.Create(&spcontacts).Error
281
+	return err
282
+}
283
+
8 284
 func GetSupplyDrugList(orgid int64) (drug []*models.SpBaseDrug, err error) {
9 285
 
10 286
 	db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
@@ -61,27 +337,27 @@ func CreateSupplyWarehousingOrder(order *models.SupplierWarehousingInfoOrder) er
61 337
 
62 338
 func GetAllPurchaseOrderList(check_id int64, startime int64, endtime int64, keyword string, page int64, limit int64, orgid int64) (info []*models.VmSupplierWarehouseInfo, total int64, err error) {
63 339
 
64
-	db := XTReadDB().Model(&info).Where("status = 1")
340
+	db := XTReadDB().Model(&info).Where("sgj_xt.xt_supplier_warehouse_info.status = 1")
65 341
 	likeKey := "%" + keyword + "%"
66 342
 	offset := (page - 1) * limit
67 343
 	if check_id > 0 {
68
-		db = db.Where("xt_supplier_warehouse_info.is_check = ?", check_id)
344
+		db = db.Where("sgj_xt.xt_supplier_warehouse_info.is_check = ?", check_id)
69 345
 	}
70 346
 	if startime > 0 {
71
-		db = db.Where("xt_supplier_warehouse_info.record_date >= ?", startime)
347
+		db = db.Where("sgj_xt.xt_supplier_warehouse_info.record_date >= ?", startime)
72 348
 	}
73 349
 	if endtime > 0 {
74
-		db = db.Where("xt_supplier_warehouse_info.record_date<=?", endtime)
350
+		db = db.Where("sgj_xt.xt_supplier_warehouse_info.record_date<=?", endtime)
75 351
 	}
76 352
 
77 353
 	if len(keyword) > 0 {
78
-		db.Joins("join xt_supplier_name on xt_supplier_name.id = xt_supplier_warehouse_info.supplier_id")
79
-		db = db.Where("xt_supplier_warehouse_info.number like ? or xt_supplier_name.supplier_name like ? ", likeKey, likeKey).Group("xt_supplier_warehouse_info.id")
354
+		db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_info.supplier_id")
355
+		db = db.Where("sgj_xt.xt_supplier_warehouse_info.number like ? or sgj_xt.xt_supplier_name.supplier_name like ? ", likeKey, likeKey).Group("sgj_xt.xt_supplier_warehouse_info.id")
80 356
 	}
81 357
 	if orgid > 0 {
82
-		db = db.Where("xt_supplier_warehouse_info.user_org_id = ?", orgid)
358
+		db = db.Where("sgj_xt.xt_supplier_warehouse_info.user_org_id = ?", orgid)
83 359
 	}
84
-	err = db.Count(&total).Offset(offset).Limit(limit).Preload("SupplierWarehousingInfoOrder", "status= 1 and user_org_id = ?", orgid).Find(&info).Error
360
+	err = db.Count(&total).Offset(offset).Limit(limit).Preload("SupplierWarehousingInfoOrder", "status= 1 and user_org_id = ?", orgid).Preload("SpSupplierWarehouseOut", "status = 1 and user_org_id =?", orgid).Find(&info).Error
85 361
 	return info, total, err
86 362
 }
87 363
 
@@ -91,6 +367,12 @@ func GetSupplyWarehousingOrderInfo(id int64) (order []*models.SupplierWarehousin
91 367
 	return order, err
92 368
 }
93 369
 
370
+func GetSupplyWarehousingOrderInfoTwo(id int64, ids []string) (order []*models.SupplierWarehousingInfoOrder, err error) {
371
+
372
+	err = XTReadDB().Where("warehousing_id = ? and status = 1 and project_id in(?)", id, ids).Find(&order).Error
373
+	return order, err
374
+}
375
+
94 376
 func ModefySupplyWarehouseInfo(id int64, info models.SupplierWarehouseInfo) error {
95 377
 
96 378
 	err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"rate_of_concession": info.RateOfConcession, "discount_amount": info.DiscountAmount, "document_date": info.DocumentDate, "delivery_date": info.DeliveryDate, "supplier_id": info.SupplierId}).Error
@@ -99,7 +381,7 @@ func ModefySupplyWarehouseInfo(id int64, info models.SupplierWarehouseInfo) erro
99 381
 
100 382
 func ModifySupplyWarehouseOrder(order *models.SupplierWarehousingInfoOrder) error {
101 383
 
102
-	err := XTWriteDB().Model(&models.SupplierWarehousingInfoOrder{}).Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{}).Updates(map[string]interface{}{"is_source": order.IsSource, "count": order.Count, "price": order.Price, "amount": order.Amount, "remark": order.Remark, "project_id": order.ProjectId, "supply_license_number": order.SupplyLicenseNumber, "supply_type": order.SupplyType, "supply_specification_name": order.SupplySpecificationName, "supply_total": order.SupplyTotal, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit}).Error
384
+	err := XTWriteDB().Model(&models.SupplierWarehousingInfoOrder{}).Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{}).Updates(map[string]interface{}{"is_source": order.IsSource, "count": order.Count, "price": order.Price, "amount": order.Amount, "remark": order.Remark, "project_id": order.ProjectId, "supply_license_number": order.SupplyLicenseNumber, "supply_type": order.SupplyType, "supply_specification_name": order.SupplySpecificationName, "supply_total": order.SupplyTotal, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit, "manufacturer_id": order.ManufacturerId}).Error
103 385
 	return err
104 386
 }
105 387
 
@@ -115,3 +397,124 @@ func GetPurchaseOrderDetail(id int64) (models.SupplierWarehouseInfo, error) {
115 397
 	err := XTReadDB().Model(&info).Where("id =? and status =1", id).Find(&info).Error
116 398
 	return info, err
117 399
 }
400
+
401
+func FindAllSupplyWarehouseOutOrder(orgid int64) (total int64, err error) {
402
+	err = XTReadDB().Model(&models.SpSupplierWarehouseOut{}).Where("user_org_id = ? and status = 1", orgid).Count(&total).Error
403
+	return total, err
404
+}
405
+
406
+func FindSupplyWarehouseOutById(orgid int64) (models.SpSupplierWarehouseOut, error) {
407
+	out := models.SpSupplierWarehouseOut{}
408
+	err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Last(&out).Error
409
+	return out, err
410
+}
411
+
412
+func CreateSupplyWarehouseOut(out models.SpSupplierWarehouseOut) error {
413
+
414
+	err := XTWriteDB().Create(&out).Error
415
+	return err
416
+}
417
+
418
+func CreateSupplyWarehousOutOrder(order *models.SpSupplierWarehousingOutOrder) error {
419
+
420
+	err := XTWriteDB().Create(&order).Error
421
+	return err
422
+}
423
+
424
+func GetSupplyWarehouseOutById(id int64, user_org_id int64) (order []*models.SpSupplierWarehousingOutOrder, err error) {
425
+
426
+	err = XTReadDB().Where("warehouse_out_id = ? and status = 1 and user_org_id = ?", id, user_org_id).Find(&order).Error
427
+	return order, err
428
+}
429
+
430
+func GetAllGoodOderList(check_id int64, keyword string, page int64, limit int64, startime int64, endtime int64, orgid int64) (out []*models.VmSupplierWarehouseOut, total int64, err error) {
431
+	db := XTReadDB().Model(&out).Where("status = 1")
432
+	likeKey := "%" + keyword + "%"
433
+	offset := (page - 1) * limit
434
+	if check_id > 0 {
435
+		db = db.Where("xt_supplier_warehouse_out.is_check = ?", check_id)
436
+	}
437
+	if startime > 0 {
438
+		db = db.Where("xt_supplier_warehouse_out.record_date >= ?", startime)
439
+	}
440
+	if endtime > 0 {
441
+		db = db.Where("xt_supplier_warehouse_out.record_date<=?", endtime)
442
+	}
443
+
444
+	if len(keyword) > 0 {
445
+		db.Joins("join xt_supplier_name on xt_supplier_name.id = xt_supplier_warehouse_out.supplier_id")
446
+		db = db.Where("xt_supplier_warehouse_out.number like ? or xt_supplier_name.supplier_name like ? ", likeKey, likeKey).Group("xt_supplier_warehouse_out.id")
447
+	}
448
+	if orgid > 0 {
449
+		db = db.Where("xt_supplier_warehouse_out.user_org_id = ?", orgid)
450
+	}
451
+	err = db.Count(&total).Offset(offset).Limit(limit).Preload("SpSupplierWarehousingOutOrder", "status= 1 and user_org_id = ?", orgid).Find(&out).Error
452
+	return out, total, err
453
+}
454
+
455
+func GetGoodOrderDetail(id int64, orgid int64) (models.SpSupplierWarehouseOut, error) {
456
+	out := models.SpSupplierWarehouseOut{}
457
+	err := XTReadDB().Where("id = ? and user_org_id = ? and status = 1", id, orgid).Find(&out).Error
458
+	return out, err
459
+}
460
+
461
+func UpdateGoodWarehouseOut(id int64, out models.SpSupplierWarehouseOut) error {
462
+
463
+	err := XTWriteDB().Model(&out).Where("id=? and status = 1", id).Updates(map[string]interface{}{"arrearage": out.Arrearage, "payment": out.Payment, "rate_of_concession": out.RateOfConcession, "discount_amount": out.DiscountAmount, "document_date": out.DocumentDate}).Error
464
+	return err
465
+}
466
+
467
+func UpdateGoodWarehouseOutOrder(order *models.SpSupplierWarehousingOutOrder) error {
468
+
469
+	err := XTWriteDB().Model(&order).Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{"project_id": order.ProjectId, "is_source": order.IsSource, "count": order.Count, "price": order.Count, "amount": order.Amount, "remark": order.Amount, "supply_batch_number": order.SupplyBatchNumber, "supply_product_date": order.SupplyProductDate, "supply_expiry_date": order.SupplyExpiryDate, "supply_type": order.SupplyType, "supply_specification_name": order.SupplySpecificationName, "supply_total": order.SupplySpecificationName, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit, "manufacturer_id": order.ManufacturerId, "supply_license_number": order.SupplyLicenseNumber}).Error
470
+	return err
471
+}
472
+
473
+func DeletePurchOrder(id int64, orgid int64) error {
474
+
475
+	err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
476
+	err = XTWriteDB().Model(&models.SupplierWarehousingInfoOrder{}).Where("warehousing_id =? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
477
+	return err
478
+}
479
+
480
+func GetAllPurcaseOrderById(id int64, orgid int64) (order []*models.VSupplierWarehousingInfoOrder, err error) {
481
+
482
+	err = XTReadDB().Model(&order).Where("warehousing_id = ? and user_org_id = ? and status =1", id, orgid).Find(&order).Error
483
+	return order, err
484
+}
485
+
486
+func GetAllGoodOrderById(id int64, orgid int64) (order []*models.VSpSupplierWarehousingOutOrder, err error) {
487
+	db := XTReadDB().Table("xt_supplier_warehousing_out_order as o").Where("o.status = 1")
488
+	if id > 0 {
489
+		db = db.Where("o.warehousing_id = ?", id)
490
+	}
491
+	if orgid > 0 {
492
+		db = db.Where("o.user_org_id =?", orgid)
493
+	}
494
+	err = db.Select("o.id,o.order_number,o.project_id,o.count as count,o.supply_unit,o.is_source").Find(&order).Error
495
+	return order, err
496
+}
497
+
498
+func GetAllGoodOrderByIdTwo(id int64, orgid int64) (order []*models.SpSupplierWarehousingOutOrder, err error) {
499
+
500
+	err = XTReadDB().Where("warehousing_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&order).Error
501
+	return order, err
502
+}
503
+
504
+func GetGoodOrderList(id int64, orgid int64) (info []*models.SpSupplierWarehouseOut, err error) {
505
+
506
+	err = XTReadDB().Where("warehousing_id = ? and status = 1 and user_org_id = ?", id, orgid).Find(&info).Error
507
+	return info, err
508
+}
509
+
510
+func GetReturnOrder(id int64, orgid int64) error {
511
+
512
+	err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgid).Updates(map[string]interface{}{"is_check": 2, "mtime": time.Now().Unix(), "check_time": 0, "checker": 0}).Error
513
+	return err
514
+}
515
+
516
+func CheckGoodOrder(id int64, orgid int64, out models.SpSupplierWarehouseOut) error {
517
+
518
+	err := XTWriteDB().Model(&models.SpSupplierWarehouseOut{}).Where("id = ? and user_org_id =? and status = 1", id, orgid).Updates(map[string]interface{}{"is_check": out.IsCheck, "checker": out.Checker, "check_time": out.CheckTime, "mtime": time.Now().Unix()}).Error
519
+	return err
520
+}