|
@@ -172,6 +172,7 @@ func AddSigleGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
|
172
|
172
|
}
|
173
|
173
|
|
174
|
174
|
func ModifyGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
|
|
175
|
+
|
175
|
176
|
err := writeDb.Model(&models.GoodInfo{}).Where("id = ? AND status = 1", goodInfo.ID).Updates(map[string]interface{}{
|
176
|
177
|
"good_type_id": goodInfo.GoodTypeId,
|
177
|
178
|
"modifier": goodInfo.Modifier,
|
|
@@ -186,6 +187,27 @@ func ModifyGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
|
186
|
187
|
"expiry_date_warn_day_count": goodInfo.ExpiryDateWarnDayCount,
|
187
|
188
|
"stock_warn_count": goodInfo.StockWarnCount,
|
188
|
189
|
"is_reuse": goodInfo.IsReuse,
|
|
190
|
+ "good_name": goodInfo.GoodName,
|
|
191
|
+ "pinyin": goodInfo.Pinyin,
|
|
192
|
+ "wubi": goodInfo.Wubi,
|
|
193
|
+ "good_kind": goodInfo.GoodKind,
|
|
194
|
+ "medical_insurance_level": goodInfo.MedicalInsuranceLevel,
|
|
195
|
+ "retail_price": goodInfo.RetailPrice,
|
|
196
|
+ "medical_insurance_number": goodInfo.MedicalInsuranceNumber,
|
|
197
|
+ "is_special_diseases": goodInfo.IsSpecialDiseases,
|
|
198
|
+ "is_record": goodInfo.IsRecord,
|
|
199
|
+ "statistics_category": goodInfo.StatisticsCategory,
|
|
200
|
+ "good_status": goodInfo.GoodStatus,
|
|
201
|
+ "default_count": goodInfo.DefaultCount,
|
|
202
|
+ "sign": goodInfo.Sign,
|
|
203
|
+ "is_default": goodInfo.IsDefault,
|
|
204
|
+ "is_charge_use": goodInfo.IsChargeUse,
|
|
205
|
+ "is_charge_predict": goodInfo.IsChargePredict,
|
|
206
|
+ "is_statistics_work": goodInfo.IsStatisticsWork,
|
|
207
|
+ "sort": goodInfo.Sort,
|
|
208
|
+ "is_doctor_use": goodInfo.IsDoctorUse,
|
|
209
|
+ "agent": goodInfo.Agent,
|
|
210
|
+ "good_number": goodInfo.GoodNumber,
|
189
|
211
|
}).Error
|
190
|
212
|
|
191
|
213
|
writeDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND org_id = ?", goodInfo.ID, goodInfo.OrgId).Updates(map[string]interface{}{"good_type_id": goodInfo.GoodTypeId})
|
|
@@ -198,14 +220,26 @@ func ModifyGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
|
198
|
220
|
|
199
|
221
|
}
|
200
|
222
|
|
201
|
|
-func FindGoodInfoList(orgId int64, page int64, limit int64, keyword string) (list []*models.GoodInfo, total int64, err error) {
|
|
223
|
+func FindGoodInfoList(orgId int64, page int64, limit int64, keyword string, is_use int64, is_charge int64, good_kind int64) (list []*models.GoodInfo, total int64, err error) {
|
202
|
224
|
offset := (page - 1) * limit
|
203
|
225
|
db := readDb.Model(&models.GoodInfo{})
|
204
|
226
|
db = db.Where("org_id = ? AND status = 1", orgId)
|
205
|
227
|
if len(keyword) > 0 {
|
206
|
228
|
likeKey := "%" + keyword + "%"
|
207
|
229
|
db = db.Where("good_code LIKE ? OR specification_name LIKE ?", likeKey, likeKey)
|
|
230
|
+ } else {
|
|
231
|
+ if is_use > 0 {
|
|
232
|
+ db = db.Where("good_status = ?", is_use)
|
|
233
|
+ }
|
|
234
|
+ if is_charge > 0 {
|
|
235
|
+ db = db.Where(" good_status = ?", is_charge)
|
|
236
|
+ }
|
|
237
|
+ if good_kind > 0 {
|
|
238
|
+ db = db.Where(" good_kind = ?", good_kind)
|
|
239
|
+ }
|
|
240
|
+
|
208
|
241
|
}
|
|
242
|
+
|
209
|
243
|
err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
|
210
|
244
|
return
|
211
|
245
|
}
|
|
@@ -251,12 +285,24 @@ func AddSigleWarehouse(warehouse *models.Warehousing) error {
|
251
|
285
|
|
252
|
286
|
}
|
253
|
287
|
|
|
288
|
+func AddSigleDrugWarehouse(warehouse *models.DrugWarehouse) error {
|
|
289
|
+ err := writeDb.Create(&warehouse).Error
|
|
290
|
+ return err
|
|
291
|
+
|
|
292
|
+}
|
|
293
|
+
|
254
|
294
|
func AddSigleSalesReturn(salesReturn *models.SalesReturn) error {
|
255
|
295
|
err := writeDb.Create(&salesReturn).Error
|
256
|
296
|
return err
|
257
|
297
|
|
258
|
298
|
}
|
259
|
299
|
|
|
300
|
+func AddSigleDrugSalesReturn(salesReturn *models.DrugSalesReturn) error {
|
|
301
|
+ err := writeDb.Create(&salesReturn).Error
|
|
302
|
+ return err
|
|
303
|
+
|
|
304
|
+}
|
|
305
|
+
|
260
|
306
|
func UpDateGoodReturnStatus(ids []string) {
|
261
|
307
|
writeDb.Model(&models.WarehousingInfo{}).Where("id IN (?)", ids).Update(map[string]interface{}{"is_return": 1})
|
262
|
308
|
|
|
@@ -309,6 +355,49 @@ func CreateWarehousingInfo(warehousingInfo []*models.WarehousingInfo) (err error
|
309
|
355
|
|
310
|
356
|
}
|
311
|
357
|
|
|
358
|
+func CreateDrugWarehousingInfo(warehousingInfo []*models.DrugWarehouseInfo) (err error) {
|
|
359
|
+ if len(warehousingInfo) > 0 {
|
|
360
|
+ utx := writeDb.Begin()
|
|
361
|
+ if len(warehousingInfo) > 0 {
|
|
362
|
+ thisSQL := "INSERT INTO xt_warehouse_info (warehousing_id, drug_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,retail_price,retail_total_price) VALUES "
|
|
363
|
+ insertParams := make([]string, 0)
|
|
364
|
+ insertData := make([]interface{}, 0)
|
|
365
|
+ for _, info := range warehousingInfo {
|
|
366
|
+ insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
|
367
|
+ insertData = append(insertData, info.WarehousingId)
|
|
368
|
+ insertData = append(insertData, info.DrugId)
|
|
369
|
+ insertData = append(insertData, info.Number)
|
|
370
|
+ insertData = append(insertData, info.ProductDate)
|
|
371
|
+ insertData = append(insertData, info.ExpiryDate)
|
|
372
|
+ insertData = append(insertData, info.WarehousingCount)
|
|
373
|
+ insertData = append(insertData, info.Price)
|
|
374
|
+ insertData = append(insertData, info.TotalPrice)
|
|
375
|
+ insertData = append(insertData, info.Dealer)
|
|
376
|
+ insertData = append(insertData, info.Manufacturer)
|
|
377
|
+ insertData = append(insertData, info.Remark)
|
|
378
|
+ insertData = append(insertData, info.Ctime)
|
|
379
|
+ insertData = append(insertData, info.Mtime)
|
|
380
|
+ insertData = append(insertData, info.Status)
|
|
381
|
+ insertData = append(insertData, info.OrgId)
|
|
382
|
+ insertData = append(insertData, info.WarehousingOrder)
|
|
383
|
+ insertData = append(insertData, info.Type)
|
|
384
|
+ insertData = append(insertData, info.RetailPrice)
|
|
385
|
+ insertData = append(insertData, info.RetailTotalPrice)
|
|
386
|
+
|
|
387
|
+ }
|
|
388
|
+ thisSQL += strings.Join(insertParams, ", ")
|
|
389
|
+ err = utx.Exec(thisSQL, insertData...).Error
|
|
390
|
+ if err != nil {
|
|
391
|
+ utx.Rollback()
|
|
392
|
+ return
|
|
393
|
+ }
|
|
394
|
+ }
|
|
395
|
+ utx.Commit()
|
|
396
|
+ }
|
|
397
|
+ return
|
|
398
|
+
|
|
399
|
+}
|
|
400
|
+
|
312
|
401
|
func FindLastWarehousingInfo(order string) (info models.WarehousingInfo, err error) {
|
313
|
402
|
err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_order = ? AND status = 1", order).Last(&info).Error
|
314
|
403
|
|
|
@@ -316,6 +405,13 @@ func FindLastWarehousingInfo(order string) (info models.WarehousingInfo, err err
|
316
|
405
|
|
317
|
406
|
}
|
318
|
407
|
|
|
408
|
+func FindLastDrugWarehousingInfo(order string) (info models.DrugWarehouseInfo, err error) {
|
|
409
|
+ err = readDb.Model(&models.DrugWarehouseInfo{}).Where("warehousing_order = ? AND status = 1", order).Last(&info).Error
|
|
410
|
+
|
|
411
|
+ return info, err
|
|
412
|
+
|
|
413
|
+}
|
|
414
|
+
|
319
|
415
|
func FindAllWarehousingList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.Warehousing, total int64, err error) {
|
320
|
416
|
db := readDb.Model(&models.Warehousing{})
|
321
|
417
|
db = db.Where("xt_warehouse.org_id = ? AND xt_warehouse.status = 1 AND xt_warehouse.type = ?", orgId, types)
|
|
@@ -339,17 +435,128 @@ func FindAllWarehousingList(orgId int64, page int64, limit int64, startTime int6
|
339
|
435
|
return
|
340
|
436
|
}
|
341
|
437
|
|
|
438
|
+type VMDrugWarehouse struct {
|
|
439
|
+ ID int64 `gorm:"column:id" json:"id" form:"id"`
|
|
440
|
+ WarehousingOrder string `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
|
|
441
|
+ OperationTime int64 `gorm:"column:operation_time" json:"operation_time" form:"operation_time"`
|
|
442
|
+ OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
|
|
443
|
+ Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
|
|
444
|
+ Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
|
|
445
|
+ Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
|
|
446
|
+ Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
|
|
447
|
+ Status int64 `gorm:"column:status" json:"status" form:"status"`
|
|
448
|
+ WarehousingTime int64 `gorm:"column:warehousing_time" json:"warehousing_time" form:"warehousing_time"`
|
|
449
|
+ Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
|
|
450
|
+ Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
|
|
451
|
+ Type int64 `gorm:"column:type" json:"type" form:"type"`
|
|
452
|
+ Manufacturers *models.Manufacturer `gorm:"ForeignKey:Manufacturer;AssociationForeignKey:ID" json:"manufacturers"`
|
|
453
|
+ Dealers *models.Dealer `gorm:"ForeignKey:Dealer;AssociationForeignKey:ID" json:"dealers"`
|
|
454
|
+}
|
|
455
|
+
|
|
456
|
+func (VMDrugWarehouse) TableName() string {
|
|
457
|
+ return "xt_drug_warehouse"
|
|
458
|
+}
|
|
459
|
+
|
|
460
|
+type VMDrugWarehouseInfo struct {
|
|
461
|
+ ID int64 `gorm:"column:id" json:"id" form:"id"`
|
|
462
|
+ WarehousingId int64 `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
|
|
463
|
+ DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
|
|
464
|
+ Number string `gorm:"column:number" json:"number" form:"number"`
|
|
465
|
+ ProductDate int64 `gorm:"column:product_date" json:"product_date" form:"product_date"`
|
|
466
|
+ ExpiryDate int64 `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
|
|
467
|
+ WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
|
|
468
|
+ Price float64 `gorm:"column:price" json:"price" form:"price"`
|
|
469
|
+ TotalPrice float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
|
|
470
|
+ Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
|
|
471
|
+ Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
|
|
472
|
+ Remark string `gorm:"column:remark" json:"remark" form:"remark"`
|
|
473
|
+ Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
|
|
474
|
+ Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
|
|
475
|
+ Status int64 `gorm:"column:status" json:"status" form:"status"`
|
|
476
|
+ OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
|
|
477
|
+ IsReturn int64 `gorm:"column:is_return" json:"is_return" form:"is_return"`
|
|
478
|
+ WarehousingOrder string `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
|
|
479
|
+ Type int64 `gorm:"column:type" json:"type" form:"type"`
|
|
480
|
+ RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
|
|
481
|
+ RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
|
|
482
|
+ Drug *Drug `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
|
|
483
|
+}
|
|
484
|
+
|
|
485
|
+func (VMDrugWarehouseInfo) TableName() string {
|
|
486
|
+ return "xt_drug_warehouse_info"
|
|
487
|
+}
|
|
488
|
+
|
|
489
|
+type Drug struct {
|
|
490
|
+ ID int64 `gorm:"column:id" json:"id" form:"id"`
|
|
491
|
+ DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
|
|
492
|
+ DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
|
|
493
|
+ DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
|
|
494
|
+ DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
|
|
495
|
+ DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
|
|
496
|
+ DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
|
|
497
|
+ Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
|
|
498
|
+ Status int64 `gorm:"column:status" json:"status" form:"status"`
|
|
499
|
+ Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
|
|
500
|
+ Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
|
|
501
|
+ OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
|
|
502
|
+ DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
|
|
503
|
+}
|
|
504
|
+
|
|
505
|
+func (Drug) TableName() string {
|
|
506
|
+ return "xt_base_drug"
|
|
507
|
+}
|
|
508
|
+
|
|
509
|
+func FindAllDrugWarehousingList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*VMDrugWarehouse, total int64, err error) {
|
|
510
|
+ db := readDb.Model(&VMDrugWarehouse{})
|
|
511
|
+ db = db.Where("xt_drug_warehouse.org_id = ? AND xt_drug_warehouse.status = 1", orgId)
|
|
512
|
+ db = db.Preload("Manufacturers", "status = 1 AND org_id = ?", orgId)
|
|
513
|
+ db = db.Preload("Dealers", "status = 1 AND org_id = ?", orgId)
|
|
514
|
+ if len(keywords) > 0 {
|
|
515
|
+ likeKey := "%" + keywords + "%"
|
|
516
|
+ db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_warehouse.creater")
|
|
517
|
+ db = db.Joins("join xt_manufacturer on xt_manufacturer.id = xt_drug_warehouse.manufacturer")
|
|
518
|
+ db = db.Where("xt_manufacturer.manufacturer_name LIKE ? OR sgj_user_admin_role.user_name LIKE ? OR xt_drug_warehouse.warehousing_order LIKE ?", likeKey, likeKey, likeKey).Group("xt_drug_warehouse.id")
|
|
519
|
+ }
|
|
520
|
+ if startTime > 0 {
|
|
521
|
+ db = db.Where("xt_drug_warehouse.operation_time >=?", startTime)
|
|
522
|
+ }
|
|
523
|
+ if endTime > 0 {
|
|
524
|
+ db = db.Where("xt_drug_warehouse.operation_time<= ?", endTime)
|
|
525
|
+ }
|
|
526
|
+ db = db.Count(&total)
|
|
527
|
+ offset := (page - 1) * limit
|
|
528
|
+ err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse.ctime desc").Find(&list).Error
|
|
529
|
+ return
|
|
530
|
+}
|
|
531
|
+
|
342
|
532
|
func FindWarehousingInfoById(id int64) (list []*models.WarehousingInfo, err error) {
|
343
|
533
|
err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_id = ? AND status = 1", id).Find(&list).Error
|
344
|
534
|
return list, err
|
345
|
535
|
}
|
346
|
536
|
|
|
537
|
+func FindDrugWarehousingInfoById(id int64, org_id int64) (list []*VMDrugWarehouseInfo, err error) {
|
|
538
|
+ err = readDb.Model(&VMDrugWarehouseInfo{}).Preload("Drug", "status = 1 AND org_id = ? AND find_in_set('停用',drug_status) = 0", org_id).Where("warehousing_id = ? AND status = 1", id).Find(&list).Error
|
|
539
|
+ return list, err
|
|
540
|
+}
|
|
541
|
+
|
347
|
542
|
func FindWarehousingById(id int64) (warehousing models.Warehousing, err error) {
|
348
|
543
|
err = readDb.Model(&models.Warehousing{}).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
|
349
|
544
|
return warehousing, err
|
350
|
545
|
|
351
|
546
|
}
|
352
|
547
|
|
|
548
|
+func FindDrugWarehousingById(id int64, org_id int64) (warehousing VMDrugWarehouse, err error) {
|
|
549
|
+ err = readDb.Model(&VMDrugWarehouse{}).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
|
|
550
|
+ return warehousing, err
|
|
551
|
+
|
|
552
|
+}
|
|
553
|
+
|
|
554
|
+//func FindDrugWarehousingById(id int64) (warehousing models.DrugWarehouse, err error) {
|
|
555
|
+// err = readDb.Model(&models.DrugWarehouse{}).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
|
|
556
|
+// return warehousing, err
|
|
557
|
+//
|
|
558
|
+//}
|
|
559
|
+
|
353
|
560
|
func GetInfoByIds(ids []string) (info []*models.WarehousingInfo, err error) {
|
354
|
561
|
err = readDb.Model(&models.WarehousingInfo{}).Preload("Warehousing", "status = 1").Where("id in (?) AND status = 1", ids).Find(&info).Error
|
355
|
562
|
return
|
|
@@ -396,6 +603,44 @@ func CreateSalesReturnInfo(salesReturnInfo []*models.SalesReturnInfo) (err error
|
396
|
603
|
|
397
|
604
|
}
|
398
|
605
|
|
|
606
|
+func CreateDrugSalesReturnInfo(salesReturnInfo []*models.DrugSalesReturnInfo) (err error) {
|
|
607
|
+ if len(salesReturnInfo) > 0 {
|
|
608
|
+ utx := writeDb.Begin()
|
|
609
|
+ if len(salesReturnInfo) > 0 {
|
|
610
|
+ thisSQL := "INSERT INTO xt_sales_return_info (drug_id,sales_return_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer,retail_price,retail_total_price) VALUES "
|
|
611
|
+ insertParams := make([]string, 0)
|
|
612
|
+ insertData := make([]interface{}, 0)
|
|
613
|
+ for _, info := range salesReturnInfo {
|
|
614
|
+ insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
|
615
|
+ insertData = append(insertData, info.DrugId)
|
|
616
|
+ insertData = append(insertData, info.SalesReturnId)
|
|
617
|
+ insertData = append(insertData, info.Count)
|
|
618
|
+ insertData = append(insertData, info.Price)
|
|
619
|
+ insertData = append(insertData, info.Total)
|
|
620
|
+ insertData = append(insertData, info.Ctime)
|
|
621
|
+ insertData = append(insertData, info.Status)
|
|
622
|
+ insertData = append(insertData, info.OrgId)
|
|
623
|
+ insertData = append(insertData, info.OrderNumber)
|
|
624
|
+ insertData = append(insertData, info.Type)
|
|
625
|
+ insertData = append(insertData, info.Dealer)
|
|
626
|
+ insertData = append(insertData, info.Manufacturer)
|
|
627
|
+ insertData = append(insertData, info.RetailPrice)
|
|
628
|
+ insertData = append(insertData, info.RetailTotalPrice)
|
|
629
|
+
|
|
630
|
+ }
|
|
631
|
+ thisSQL += strings.Join(insertParams, ", ")
|
|
632
|
+ err = utx.Exec(thisSQL, insertData...).Error
|
|
633
|
+ if err != nil {
|
|
634
|
+ utx.Rollback()
|
|
635
|
+ return
|
|
636
|
+ }
|
|
637
|
+ }
|
|
638
|
+ utx.Commit()
|
|
639
|
+ }
|
|
640
|
+ return
|
|
641
|
+
|
|
642
|
+}
|
|
643
|
+
|
399
|
644
|
func FindAllSalesReturnTotal(org_id int64) (total int64, err error) {
|
400
|
645
|
err = readDb.Model(&models.SalesReturn{}).Where("org_id = ?", org_id).Count(&total).Error
|
401
|
646
|
return total, err
|
|
@@ -408,6 +653,12 @@ func FindAllCancelStockTotal(org_id int64) (total int64, err error) {
|
408
|
653
|
|
409
|
654
|
}
|
410
|
655
|
|
|
656
|
+func FindAllDrugCancelStockTotal(org_id int64) (total int64, err error) {
|
|
657
|
+ err = readDb.Model(&models.DrugCancelStock{}).Where("org_id = ?", org_id).Count(&total).Error
|
|
658
|
+ return total, err
|
|
659
|
+
|
|
660
|
+}
|
|
661
|
+
|
411
|
662
|
func FindAllReturnList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.SalesReturn, total int64, err error) {
|
412
|
663
|
db := readDb.Model(&models.SalesReturn{})
|
413
|
664
|
db = db.Where("xt_sales_return.org_id = ? AND xt_sales_return.status = 1 AND xt_sales_return.type = ?", orgId, types)
|
|
@@ -431,6 +682,29 @@ func FindAllReturnList(orgId int64, page int64, limit int64, startTime int64, en
|
431
|
682
|
return
|
432
|
683
|
}
|
433
|
684
|
|
|
685
|
+func FindAllDrugReturnList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.SalesReturn, total int64, err error) {
|
|
686
|
+ db := readDb.Model(&models.SalesReturn{})
|
|
687
|
+ db = db.Where("xt_drug_sales_return.org_id = ? AND xt_drug_sales_return.status = 1 ", orgId)
|
|
688
|
+
|
|
689
|
+ if len(keywords) > 0 {
|
|
690
|
+ likeKey := "%" + keywords + "%"
|
|
691
|
+ db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_sales_return.creater")
|
|
692
|
+ db = db.Joins("join xt_manufacturer on xt_manufacturer.id = xt_drug_sales_return.manufacturer")
|
|
693
|
+ db = db.Where("xt_manufacturer.manufacturer_name LIKE ? OR sgj_user_admin_role.user_name LIKE ? OR xt_drug_sales_return.order_number LIKE ?", likeKey, likeKey, likeKey).Group("xt_drug_sales_return.id")
|
|
694
|
+ }
|
|
695
|
+
|
|
696
|
+ if startTime > 0 {
|
|
697
|
+ db = db.Where("xt_drug_sales_return.opera_time >=?", startTime)
|
|
698
|
+ }
|
|
699
|
+ if endTime > 0 {
|
|
700
|
+ db = db.Where("xt_drug_sales_return.opera_time<= ?", endTime)
|
|
701
|
+ }
|
|
702
|
+ db = db.Count(&total)
|
|
703
|
+ offset := (page - 1) * limit
|
|
704
|
+ err = db.Offset(offset).Limit(limit).Order("xt_drug_sales_return.ctime desc").Find(&list).Error
|
|
705
|
+ return
|
|
706
|
+}
|
|
707
|
+
|
434
|
708
|
func FindReturnInfoById(id int64) (list []*models.SalesReturnInfo, err error) {
|
435
|
709
|
err = readDb.Model(&models.SalesReturnInfo{}).Where("sales_return_id = ? AND status = 1", id).Find(&list).Error
|
436
|
710
|
return list, err
|
|
@@ -441,6 +715,11 @@ func FindCancelStockInfoById(id int64) (list []*models.CancelStockInfo, err erro
|
441
|
715
|
return list, err
|
442
|
716
|
}
|
443
|
717
|
|
|
718
|
+func FindDrugCancelStockInfoById(id int64) (list []*models.DrugCancelStockInfo, err error) {
|
|
719
|
+ err = readDb.Model(&models.DrugCancelStockInfo{}).Where("cancel_stock_id = ? AND status = 1", id).Find(&list).Error
|
|
720
|
+ return list, err
|
|
721
|
+}
|
|
722
|
+
|
444
|
723
|
func FindAllWarehousingInfo(orgId int64, page int64, limit int64, startTime int64, endTime int64) (list []*models.WarehousingInfo, total int64, err error) {
|
445
|
724
|
db := readDb.Model(&models.WarehousingInfo{})
|
446
|
725
|
db = db.Where("org_id = ? AND status = 1", orgId)
|
|
@@ -464,12 +743,24 @@ func FindAllWarehouseOut(org_id int64) (total int64, err error) {
|
464
|
743
|
|
465
|
744
|
}
|
466
|
745
|
|
|
746
|
+func FindAllDrugWarehouseOut(org_id int64) (total int64, err error) {
|
|
747
|
+ err = readDb.Model(&models.DrugWarehouseOut{}).Where("org_id = ?", org_id).Count(&total).Error
|
|
748
|
+ return total, err
|
|
749
|
+
|
|
750
|
+}
|
|
751
|
+
|
467
|
752
|
func AddSigleWarehouseOut(warehouseOut *models.WarehouseOut) error {
|
468
|
753
|
err := writeDb.Create(&warehouseOut).Error
|
469
|
754
|
return err
|
470
|
755
|
|
471
|
756
|
}
|
472
|
757
|
|
|
758
|
+func AddSigleDrugWarehouseOut(warehouseOut *models.DrugWarehouseOut) error {
|
|
759
|
+ err := writeDb.Create(&warehouseOut).Error
|
|
760
|
+ return err
|
|
761
|
+
|
|
762
|
+}
|
|
763
|
+
|
473
|
764
|
func CreateWarehousingOutInfo(warehouseOutInfo []*models.WarehouseOutInfo) (err error) {
|
474
|
765
|
if len(warehouseOutInfo) > 0 {
|
475
|
766
|
utx := writeDb.Begin()
|
|
@@ -510,6 +801,47 @@ func CreateWarehousingOutInfo(warehouseOutInfo []*models.WarehouseOutInfo) (err
|
510
|
801
|
|
511
|
802
|
}
|
512
|
803
|
|
|
804
|
+func CreateDrugWarehousingOutInfo(warehouseOutInfo []*models.DrugWarehouseOutInfo) (err error) {
|
|
805
|
+ if len(warehouseOutInfo) > 0 {
|
|
806
|
+ utx := writeDb.Begin()
|
|
807
|
+ if len(warehouseOutInfo) > 0 {
|
|
808
|
+ thisSQL := "INSERT INTO xt_drug_warehouse_out_info (warehouse_out_id, drug_id, product_date,expiry_date,count,price,total_price,remark,ctime,status,org_id,warehouse_out_order_number,type,dealer,manufacturer,retail_price,retail_total_price) VALUES "
|
|
809
|
+ insertParams := make([]string, 0)
|
|
810
|
+ insertData := make([]interface{}, 0)
|
|
811
|
+ for _, info := range warehouseOutInfo {
|
|
812
|
+ insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
|
813
|
+ insertData = append(insertData, info.WarehouseOutId)
|
|
814
|
+ insertData = append(insertData, info.DrugId)
|
|
815
|
+ insertData = append(insertData, info.ProductDate)
|
|
816
|
+ insertData = append(insertData, info.ExpiryDate)
|
|
817
|
+ insertData = append(insertData, info.Count)
|
|
818
|
+ insertData = append(insertData, info.Price)
|
|
819
|
+ insertData = append(insertData, info.TotalPrice)
|
|
820
|
+ insertData = append(insertData, info.Remark)
|
|
821
|
+ insertData = append(insertData, info.Ctime)
|
|
822
|
+ insertData = append(insertData, info.Status)
|
|
823
|
+ insertData = append(insertData, info.OrgId)
|
|
824
|
+ insertData = append(insertData, info.WarehouseOutOrderNumber)
|
|
825
|
+ insertData = append(insertData, info.Type)
|
|
826
|
+ insertData = append(insertData, info.Dealer)
|
|
827
|
+ insertData = append(insertData, info.Manufacturer)
|
|
828
|
+ insertData = append(insertData, info.RetailPrice)
|
|
829
|
+ insertData = append(insertData, info.RetailTotalPrice)
|
|
830
|
+
|
|
831
|
+ }
|
|
832
|
+ thisSQL += strings.Join(insertParams, ", ")
|
|
833
|
+ err = utx.Exec(thisSQL, insertData...).Error
|
|
834
|
+ if err != nil {
|
|
835
|
+ utx.Rollback()
|
|
836
|
+ return
|
|
837
|
+ }
|
|
838
|
+ }
|
|
839
|
+ utx.Commit()
|
|
840
|
+ }
|
|
841
|
+ return
|
|
842
|
+
|
|
843
|
+}
|
|
844
|
+
|
513
|
845
|
func FindLastWarehousingOutInfo(order string) (info models.WarehouseOutInfo, err error) {
|
514
|
846
|
err = readDb.Model(&models.WarehouseOutInfo{}).Where("warehouse_out_order_number = ? AND status = 1", order).Last(&info).Error
|
515
|
847
|
|
|
@@ -517,6 +849,13 @@ func FindLastWarehousingOutInfo(order string) (info models.WarehouseOutInfo, err
|
517
|
849
|
|
518
|
850
|
}
|
519
|
851
|
|
|
852
|
+func FindLastDrugWarehousingOutInfo(order string) (info models.DrugWarehouseOutInfo, err error) {
|
|
853
|
+ err = readDb.Model(&models.DrugWarehouseOutInfo{}).Where("warehouse_out_order_number = ? AND status = 1", order).Last(&info).Error
|
|
854
|
+
|
|
855
|
+ return info, err
|
|
856
|
+
|
|
857
|
+}
|
|
858
|
+
|
520
|
859
|
func FindAllWarehouseOutList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.WarehouseOut, total int64, err error) {
|
521
|
860
|
db := readDb.Model(&models.WarehouseOut{})
|
522
|
861
|
db = db.Where("xt_warehouse_out.org_id = ? AND xt_warehouse_out.status = 1 AND xt_warehouse_out.type = ?", orgId, types)
|
|
@@ -542,11 +881,41 @@ func FindAllWarehouseOutList(orgId int64, page int64, limit int64, startTime int
|
542
|
881
|
return
|
543
|
882
|
}
|
544
|
883
|
|
|
884
|
+func FindAllDrugWarehouseOutList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.DrugWarehouseOut, total int64, err error) {
|
|
885
|
+ db := readDb.Model(&models.DrugWarehouseOut{})
|
|
886
|
+ db = db.Where("xt_drug_warehouse_out.org_id = ? AND xt_drug_warehouse_out.status = 1 ", orgId)
|
|
887
|
+
|
|
888
|
+ if len(keywords) > 0 {
|
|
889
|
+ likeKey := "%" + keywords + "%"
|
|
890
|
+ db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_warehouse_out.creater")
|
|
891
|
+ db = db.Joins("join xt_manufacturer on xt_manufacturer.id = xt_drug_warehouse_out.manufacturer")
|
|
892
|
+ db = db.Where("xt_manufacturer.manufacturer_name LIKE ? OR sgj_user_admin_role.user_name LIKE ? OR xt_drug_warehouse_out.warehouse_out_order_number LIKE ?", likeKey, likeKey, likeKey).Group("xt_drug_warehouse_out.id")
|
|
893
|
+ }
|
|
894
|
+
|
|
895
|
+ if startTime > 0 {
|
|
896
|
+ db = db.Where("xt_drug_warehouse_out.ctime >=?", startTime)
|
|
897
|
+ }
|
|
898
|
+ if endTime > 0 {
|
|
899
|
+ db = db.Where("xt_drug_warehouse_out.ctime<= ?", endTime)
|
|
900
|
+ }
|
|
901
|
+ db = db.Count(&total)
|
|
902
|
+ offset := (page - 1) * limit
|
|
903
|
+ err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse_out.ctime desc").Find(&list).Error
|
|
904
|
+ return list, total, err
|
|
905
|
+
|
|
906
|
+ return
|
|
907
|
+}
|
|
908
|
+
|
545
|
909
|
func FindWarehouseOutInfoById(id int64) (list []*models.WarehouseOutInfo, err error) {
|
546
|
910
|
err = readDb.Model(&models.WarehouseOutInfo{}).Where("warehouse_out_id = ? AND status = 1 AND count <> 0 AND good_id <> 0", id).Order("good_type_id desc").Find(&list).Error
|
547
|
911
|
return list, err
|
548
|
912
|
}
|
549
|
913
|
|
|
914
|
+func FindDrugWarehouseOutInfoById(id int64) (list []*models.DrugWarehouseOutInfo, err error) {
|
|
915
|
+ err = readDb.Model(&models.DrugWarehouseOutInfo{}).Where("warehouse_out_id = ? AND status = 1 AND count <> 0 AND good_id <> 0", id).Order("good_type_id desc").Find(&list).Error
|
|
916
|
+ return list, err
|
|
917
|
+}
|
|
918
|
+
|
550
|
919
|
func FindWarehouseInfoByGoodId(good_id int64) (int64, *models.WarehousingInfo) {
|
551
|
920
|
info := &models.WarehousingInfo{}
|
552
|
921
|
type WarehouseInfoCountAmount struct {
|
|
@@ -600,6 +969,12 @@ func AddSigleCancelStock(cancelStock *models.CancelStock) error {
|
600
|
969
|
|
601
|
970
|
}
|
602
|
971
|
|
|
972
|
+func AddSigleDrugCancelStock(cancelStock *models.DrugCancelStock) error {
|
|
973
|
+ err := writeDb.Create(&cancelStock).Error
|
|
974
|
+ return err
|
|
975
|
+
|
|
976
|
+}
|
|
977
|
+
|
603
|
978
|
func CreateCancelStockInfo(cancelStockInfo []*models.CancelStockInfo) (err error) {
|
604
|
979
|
if len(cancelStockInfo) > 0 {
|
605
|
980
|
utx := writeDb.Begin()
|
|
@@ -636,6 +1011,44 @@ func CreateCancelStockInfo(cancelStockInfo []*models.CancelStockInfo) (err error
|
636
|
1011
|
|
637
|
1012
|
}
|
638
|
1013
|
|
|
1014
|
+func CreateDrugCancelStockInfo(cancelStockInfo []*models.DrugCancelStockInfo) (err error) {
|
|
1015
|
+ if len(cancelStockInfo) > 0 {
|
|
1016
|
+ utx := writeDb.Begin()
|
|
1017
|
+ if len(cancelStockInfo) > 0 {
|
|
1018
|
+ thisSQL := "INSERT INTO xt_drug_cancel_stock_info (drug_id,cancel_stock_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer,retail_price,retail_total_price) VALUES "
|
|
1019
|
+ insertParams := make([]string, 0)
|
|
1020
|
+ insertData := make([]interface{}, 0)
|
|
1021
|
+ for _, info := range cancelStockInfo {
|
|
1022
|
+ insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
|
1023
|
+ insertData = append(insertData, info.DrugId)
|
|
1024
|
+ insertData = append(insertData, info.CancelStockId)
|
|
1025
|
+ insertData = append(insertData, info.Count)
|
|
1026
|
+ insertData = append(insertData, info.Price)
|
|
1027
|
+ insertData = append(insertData, info.Total)
|
|
1028
|
+ insertData = append(insertData, info.Ctime)
|
|
1029
|
+ insertData = append(insertData, info.Status)
|
|
1030
|
+ insertData = append(insertData, info.OrgId)
|
|
1031
|
+ insertData = append(insertData, info.OrderNumber)
|
|
1032
|
+ insertData = append(insertData, info.Type)
|
|
1033
|
+ insertData = append(insertData, info.Dealer)
|
|
1034
|
+ insertData = append(insertData, info.Manufacturer)
|
|
1035
|
+ insertData = append(insertData, info.RetailPrice)
|
|
1036
|
+ insertData = append(insertData, info.RetailTotalPrice)
|
|
1037
|
+
|
|
1038
|
+ }
|
|
1039
|
+ thisSQL += strings.Join(insertParams, ", ")
|
|
1040
|
+ err = utx.Exec(thisSQL, insertData...).Error
|
|
1041
|
+ if err != nil {
|
|
1042
|
+ utx.Rollback()
|
|
1043
|
+ return
|
|
1044
|
+ }
|
|
1045
|
+ }
|
|
1046
|
+ utx.Commit()
|
|
1047
|
+ }
|
|
1048
|
+ return
|
|
1049
|
+
|
|
1050
|
+}
|
|
1051
|
+
|
639
|
1052
|
func FindAllCancelStockList(orgId int64) (list []*models.CancelStock, err error) {
|
640
|
1053
|
db := readDb.Model(&models.CancelStock{})
|
641
|
1054
|
db = db.Where("org_id = ? AND status = 1", orgId)
|
|
@@ -727,6 +1140,11 @@ func UpDateWarehouseStatus(id int64) (err error) {
|
727
|
1140
|
return
|
728
|
1141
|
}
|
729
|
1142
|
|
|
1143
|
+func UpDateDrugWarehouseStatus(id int64) (err error) {
|
|
1144
|
+ err = readDb.Model(&models.DrugWarehouseInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
1145
|
+ return
|
|
1146
|
+}
|
|
1147
|
+
|
730
|
1148
|
func DeleteWarehouse(ids []string) (err error) {
|
731
|
1149
|
ut := writeDb.Begin()
|
732
|
1150
|
err = ut.Model(&models.Warehousing{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
@@ -743,6 +1161,22 @@ func DeleteWarehouse(ids []string) (err error) {
|
743
|
1161
|
return
|
744
|
1162
|
}
|
745
|
1163
|
|
|
1164
|
+func DeleteDrugWarehouse(ids []string) (err error) {
|
|
1165
|
+ ut := writeDb.Begin()
|
|
1166
|
+ err = ut.Model(&models.DrugWarehouse{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
1167
|
+ if err != nil {
|
|
1168
|
+ ut.Rollback()
|
|
1169
|
+ return
|
|
1170
|
+ }
|
|
1171
|
+ err = ut.Model(&models.DrugWarehouseInfo{}).Where("warehousing_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
1172
|
+ if err != nil {
|
|
1173
|
+ ut.Rollback()
|
|
1174
|
+ return
|
|
1175
|
+ }
|
|
1176
|
+ ut.Commit()
|
|
1177
|
+ return
|
|
1178
|
+}
|
|
1179
|
+
|
746
|
1180
|
func FindWareHouseById(orderNumber string) (*models.Warehousing, error) {
|
747
|
1181
|
warehouse := &models.Warehousing{}
|
748
|
1182
|
err := readDb.Model(&models.Warehousing{}).Where("warehousing_order = ? AND status = 1", orderNumber).First(&warehouse).Error
|
|
@@ -754,6 +1188,12 @@ func FindWareHouseOutById(id int64) (*models.WarehouseOut, error) {
|
754
|
1188
|
return warehouseOut, err
|
755
|
1189
|
}
|
756
|
1190
|
|
|
1191
|
+func FindDrugWareHouseOutById(id int64) (*models.DrugWarehouseOut, error) {
|
|
1192
|
+ warehouseOut := &models.DrugWarehouseOut{}
|
|
1193
|
+ err := readDb.Model(&models.DrugWarehouseOut{}).Where("id = ? AND status = 1", id).First(&warehouseOut).Error
|
|
1194
|
+ return warehouseOut, err
|
|
1195
|
+}
|
|
1196
|
+
|
757
|
1197
|
func FindWarehouseInfoByOrderNumber(orderNumber string) (info []*models.WarehousingInfo, err error) {
|
758
|
1198
|
err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_order = ? AND status = 1", orderNumber).Find(&info).Error
|
759
|
1199
|
return
|
|
@@ -805,11 +1245,20 @@ func UpDateWarehousingInfo(info *models.WarehousingInfo) (err error) {
|
805
|
1245
|
return err
|
806
|
1246
|
}
|
807
|
1247
|
|
|
1248
|
+func UpDateDrugWarehousingInfo(info *models.DrugWarehouseInfo) (err error) {
|
|
1249
|
+ err = writeDb.Save(&info).Error
|
|
1250
|
+ return err
|
|
1251
|
+}
|
|
1252
|
+
|
808
|
1253
|
func EditWarehousing(warehouse models.Warehousing) {
|
809
|
1254
|
err = readDb.Model(&models.Warehousing{}).Where("warehousing_order = ? AND status = 1", warehouse.WarehousingOrder).Update(map[string]interface{}{"mtime": time.Now().Unix(), "warehousing_time": warehouse.WarehousingTime, "modifier": warehouse.Modifier, "dealer": warehouse.Dealer, "manufacturer": warehouse.Manufacturer}).Error
|
810
|
1255
|
|
811
|
1256
|
}
|
812
|
1257
|
|
|
1258
|
+func EditDrugWarehousing(warehouse models.DrugWarehouse) {
|
|
1259
|
+ err = readDb.Model(&models.DrugWarehouse{}).Where("warehousing_order = ? AND status = 1", warehouse.WarehousingOrder).Update(map[string]interface{}{"mtime": time.Now().Unix(), "warehousing_time": warehouse.WarehousingTime, "modifier": warehouse.Modifier, "dealer": warehouse.Dealer, "manufacturer": warehouse.Manufacturer}).Error
|
|
1260
|
+
|
|
1261
|
+}
|
813
|
1262
|
func FindAllWarehouse(org_id int64, types int64) (list []*models.Warehousing, err error) {
|
814
|
1263
|
err = readDb.Model(&models.Warehousing{}).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ? ", org_id).Where("org_id = ? AND status = 1 AND type = ?", org_id, types).Find(&list).Error
|
815
|
1264
|
return list, err
|
|
@@ -838,35 +1287,83 @@ func DeleteSalesReturn(ids []string) (err error) {
|
838
|
1287
|
return
|
839
|
1288
|
}
|
840
|
1289
|
|
|
1290
|
+func DeleteDrugSalesReturn(ids []string) (err error) {
|
|
1291
|
+ ut := writeDb.Begin()
|
|
1292
|
+ err = ut.Model(&models.DrugSalesReturn{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
1293
|
+ if err != nil {
|
|
1294
|
+ ut.Rollback()
|
|
1295
|
+ return
|
|
1296
|
+ }
|
|
1297
|
+ err = ut.Model(&models.DrugSalesReturnInfo{}).Where("sales_return_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
1298
|
+ if err != nil {
|
|
1299
|
+ ut.Rollback()
|
|
1300
|
+ return
|
|
1301
|
+ }
|
|
1302
|
+ ut.Commit()
|
|
1303
|
+ return
|
|
1304
|
+}
|
|
1305
|
+
|
841
|
1306
|
func FindAllSalesReturnInfoById(id int64) (list []*models.SalesReturnInfo, err error) {
|
842
|
1307
|
err = readDb.Model(&models.SalesReturnInfo{}).Where("sales_return_id = ? AND status = 1", id).Find(&list).Error
|
843
|
1308
|
return
|
844
|
1309
|
}
|
845
|
1310
|
|
|
1311
|
+func FindAllDrugSalesReturnInfoById(id int64) (list []*models.DrugSalesReturnInfo, err error) {
|
|
1312
|
+ err = readDb.Model(&models.DrugSalesReturnInfo{}).Where("sales_return_id = ? AND status = 1", id).Find(&list).Error
|
|
1313
|
+ return
|
|
1314
|
+}
|
|
1315
|
+
|
846
|
1316
|
func FindAllSalesReturnById(id int64) (salesReturn models.SalesReturn, err error) {
|
847
|
|
- err = readDb.Model(&models.SalesReturnInfo{}).Where("id = ? AND status = 1", id).First(&salesReturn).Error
|
|
1317
|
+ err = readDb.Model(&models.SalesReturn{}).Where("id = ? AND status = 1", id).First(&salesReturn).Error
|
|
1318
|
+ return
|
|
1319
|
+}
|
|
1320
|
+
|
|
1321
|
+func FindAllDrugSalesReturnById(id int64) (salesReturn models.DrugSalesReturn, err error) {
|
|
1322
|
+ err = readDb.Model(&models.DrugSalesReturn{}).Where("id = ? AND status = 1", id).First(&salesReturn).Error
|
848
|
1323
|
return
|
849
|
1324
|
}
|
|
1325
|
+
|
850
|
1326
|
func UpDateSaleReturnStatus(id int64) (err error) {
|
851
|
1327
|
err = readDb.Model(&models.SalesReturnInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
852
|
1328
|
return
|
853
|
1329
|
}
|
854
|
1330
|
|
|
1331
|
+func UpDateDrugSaleReturnStatus(id int64) (err error) {
|
|
1332
|
+ err = readDb.Model(&models.DrugSalesReturnInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
1333
|
+ return
|
|
1334
|
+}
|
|
1335
|
+
|
855
|
1336
|
func FindSalesReturnById(id int64) (salesReturn models.SalesReturn, err error) {
|
856
|
1337
|
err = readDb.Model(&models.SalesReturn{}).Where("id = ? AND status = 1", id).First(&salesReturn).Error
|
857
|
1338
|
return salesReturn, err
|
858
|
1339
|
|
859
|
1340
|
}
|
860
|
1341
|
|
|
1342
|
+func FindDrugSalesReturnById(id int64) (salesReturn models.DrugSalesReturn, err error) {
|
|
1343
|
+ err = readDb.Model(&models.DrugSalesReturn{}).Where("id = ? AND status = 1", id).First(&salesReturn).Error
|
|
1344
|
+ return salesReturn, err
|
|
1345
|
+
|
|
1346
|
+}
|
|
1347
|
+
|
861
|
1348
|
func EditSaleReturn(sales models.SalesReturn) {
|
862
|
1349
|
err = readDb.Model(&models.SalesReturn{}).Where("id = ? AND status = 1", sales.ID).Update(map[string]interface{}{"mtime": time.Now().Unix(), "return_time": sales.ReturnTime, "dealer": sales.Dealer, "manufacturer": sales.Manufacturer}).Error
|
863
|
1350
|
|
|
1351
|
+}
|
|
1352
|
+
|
|
1353
|
+func EditDrugSaleReturn(sales models.DrugSalesReturn) {
|
|
1354
|
+ err = readDb.Model(&models.DrugSalesReturn{}).Where("id = ? AND status = 1", sales.ID).Update(map[string]interface{}{"mtime": time.Now().Unix(), "return_time": sales.ReturnTime, "dealer": sales.Dealer, "manufacturer": sales.Manufacturer}).Error
|
|
1355
|
+
|
864
|
1356
|
}
|
865
|
1357
|
func UpDateSalesReturnInfo(info *models.SalesReturnInfo) (err error) {
|
866
|
1358
|
err = writeDb.Save(&info).Error
|
867
|
1359
|
return err
|
868
|
1360
|
}
|
869
|
1361
|
|
|
1362
|
+func UpDateDrugSalesReturnInfo(info *models.DrugSalesReturnInfo) (err error) {
|
|
1363
|
+ err = writeDb.Save(&info).Error
|
|
1364
|
+ return err
|
|
1365
|
+}
|
|
1366
|
+
|
870
|
1367
|
func DeleteWarehouseOut(ids []string) (err error) {
|
871
|
1368
|
ut := writeDb.Begin()
|
872
|
1369
|
err = ut.Model(&models.WarehouseOut{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
@@ -882,20 +1379,51 @@ func DeleteWarehouseOut(ids []string) (err error) {
|
882
|
1379
|
ut.Commit()
|
883
|
1380
|
return
|
884
|
1381
|
}
|
|
1382
|
+
|
|
1383
|
+func DeleteDrugWarehouseOut(ids []string) (err error) {
|
|
1384
|
+ ut := writeDb.Begin()
|
|
1385
|
+ err = ut.Model(&models.DrugWarehouseOut{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
1386
|
+ if err != nil {
|
|
1387
|
+ ut.Rollback()
|
|
1388
|
+ return
|
|
1389
|
+ }
|
|
1390
|
+ err = ut.Model(&models.DrugWarehouseOutInfo{}).Where("warehouse_out_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
1391
|
+ if err != nil {
|
|
1392
|
+ ut.Rollback()
|
|
1393
|
+ return
|
|
1394
|
+ }
|
|
1395
|
+ ut.Commit()
|
|
1396
|
+ return
|
|
1397
|
+}
|
|
1398
|
+
|
885
|
1399
|
func UpDateWarehouseOutStatus(id int64) (err error) {
|
886
|
1400
|
err = readDb.Model(&models.WarehouseOutInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
887
|
1401
|
return
|
888
|
1402
|
}
|
889
|
1403
|
|
|
1404
|
+func UpDateDrugWarehouseOutStatus(id int64) (err error) {
|
|
1405
|
+ err = readDb.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
1406
|
+ return
|
|
1407
|
+}
|
|
1408
|
+
|
890
|
1409
|
func EditWarehouseOut(warehouseOut models.WarehouseOut) {
|
891
|
1410
|
err = readDb.Model(&models.WarehouseOut{}).Where("id = ? AND status = 1", warehouseOut.ID).Update(map[string]interface{}{"mtime": time.Now().Unix(), "warehouse_out_time": warehouseOut.WarehouseOutTime, "dealer": warehouseOut.Dealer, "manufacturer": warehouseOut.Manufacturer}).Error
|
892
|
1411
|
}
|
893
|
1412
|
|
|
1413
|
+func EditDrugWarehouseOut(warehouseOut models.DrugWarehouseOut) {
|
|
1414
|
+ err = readDb.Model(&models.DrugWarehouseOut{}).Where("id = ? AND status = 1", warehouseOut.ID).Update(map[string]interface{}{"mtime": time.Now().Unix(), "warehouse_out_time": warehouseOut.WarehouseOutTime, "dealer": warehouseOut.Dealer, "manufacturer": warehouseOut.Manufacturer}).Error
|
|
1415
|
+}
|
|
1416
|
+
|
894
|
1417
|
func UpDateWarehouseOutInfo(info *models.WarehouseOutInfo) (err error) {
|
895
|
1418
|
err = writeDb.Save(&info).Error
|
896
|
1419
|
return err
|
897
|
1420
|
}
|
898
|
1421
|
|
|
1422
|
+func UpDateDrugWarehouseOutInfo(info *models.DrugWarehouseOutInfo) (err error) {
|
|
1423
|
+ err = writeDb.Save(&info).Error
|
|
1424
|
+ return err
|
|
1425
|
+}
|
|
1426
|
+
|
899
|
1427
|
func FindAllCancelList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.CancelStock, total int64, err error) {
|
900
|
1428
|
db := readDb.Model(&models.CancelStock{})
|
901
|
1429
|
db = db.Where("xt_cancel_stock.org_id = ? AND xt_cancel_stock.status = 1 AND xt_cancel_stock.type = ?", orgId, types)
|
|
@@ -918,6 +1446,28 @@ func FindAllCancelList(orgId int64, page int64, limit int64, startTime int64, en
|
918
|
1446
|
return
|
919
|
1447
|
}
|
920
|
1448
|
|
|
1449
|
+func FindAllDrugCancelList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.DrugCancelStock, total int64, err error) {
|
|
1450
|
+ db := readDb.Model(&models.DrugCancelStock{})
|
|
1451
|
+ db = db.Where("xt_drug_cancel_stock.org_id = ? AND xt_drug_cancel_stock.status = 1", orgId)
|
|
1452
|
+ if len(keywords) > 0 {
|
|
1453
|
+ likeKey := "%" + keywords + "%"
|
|
1454
|
+ db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_cancel_stock.creater")
|
|
1455
|
+ db = db.Joins("join xt_manufacturer on xt_manufacturer.id = xt_drug_cancel_stock.manufacturer")
|
|
1456
|
+ db = db.Where("xt_manufacturer.manufacturer_name LIKE ? OR sgj_user_admin_role.user_name LIKE ? OR xt_drug_cancel_stock.order_number LIKE ?", likeKey, likeKey, likeKey).Group("xt_drug_cancel_stock.id")
|
|
1457
|
+ }
|
|
1458
|
+
|
|
1459
|
+ if startTime > 0 {
|
|
1460
|
+ db = db.Where("xt_drug_cancel_stock.opera_time >=?", startTime)
|
|
1461
|
+ }
|
|
1462
|
+ if endTime > 0 {
|
|
1463
|
+ db = db.Where("xt_drug_cancel_stock.opera_time<= ?", endTime)
|
|
1464
|
+ }
|
|
1465
|
+ db = db.Count(&total)
|
|
1466
|
+ offset := (page - 1) * limit
|
|
1467
|
+ err = db.Offset(offset).Limit(limit).Order("xt_drug_cancel_stock.ctime desc").Find(&list).Error
|
|
1468
|
+ return
|
|
1469
|
+}
|
|
1470
|
+
|
921
|
1471
|
func DeleteCancelStock(ids []string) (err error) {
|
922
|
1472
|
ut := writeDb.Begin()
|
923
|
1473
|
err = ut.Model(&models.CancelStock{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
@@ -934,27 +1484,64 @@ func DeleteCancelStock(ids []string) (err error) {
|
934
|
1484
|
return
|
935
|
1485
|
}
|
936
|
1486
|
|
|
1487
|
+func DeleteDrugCancelStock(ids []string) (err error) {
|
|
1488
|
+ ut := writeDb.Begin()
|
|
1489
|
+ err = ut.Model(&models.DrugCancelStock{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
1490
|
+ if err != nil {
|
|
1491
|
+ ut.Rollback()
|
|
1492
|
+ return
|
|
1493
|
+ }
|
|
1494
|
+ err = ut.Model(&models.DrugCancelStockInfo{}).Where("cancel_stock_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
1495
|
+ if err != nil {
|
|
1496
|
+ ut.Rollback()
|
|
1497
|
+ return
|
|
1498
|
+ }
|
|
1499
|
+ ut.Commit()
|
|
1500
|
+ return
|
|
1501
|
+}
|
|
1502
|
+
|
937
|
1503
|
func UpDateCancleStockStatus(id int64) (err error) {
|
938
|
1504
|
err = readDb.Model(&models.CancelStockInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
939
|
1505
|
return
|
940
|
1506
|
}
|
941
|
1507
|
|
|
1508
|
+func UpDateDrugCancleStockStatus(id int64) (err error) {
|
|
1509
|
+ err = readDb.Model(&models.DrugCancelStockInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
1510
|
+ return
|
|
1511
|
+}
|
|
1512
|
+
|
942
|
1513
|
func EditCancelStock(sales models.CancelStock) {
|
943
|
1514
|
err = readDb.Model(&models.CancelStock{}).Where("id = ? AND status = 1", sales.ID).Update(map[string]interface{}{"mtime": time.Now().Unix(), "return_time": sales.ReturnTime, "dealer": sales.Dealer, "manufacturer": sales.Manufacturer}).Error
|
944
|
1515
|
|
945
|
1516
|
}
|
946
|
1517
|
|
|
1518
|
+func EditDrugCancelStock(sales models.DrugCancelStock) {
|
|
1519
|
+ err = readDb.Model(&models.DrugCancelStock{}).Where("id = ? AND status = 1", sales.ID).Update(map[string]interface{}{"mtime": time.Now().Unix(), "return_time": sales.ReturnTime, "dealer": sales.Dealer, "manufacturer": sales.Manufacturer}).Error
|
|
1520
|
+
|
|
1521
|
+}
|
|
1522
|
+
|
947
|
1523
|
func FindCancelStockById(id int64) (cancelStock models.CancelStock, err error) {
|
948
|
1524
|
err = readDb.Model(&models.CancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
|
949
|
1525
|
return cancelStock, err
|
950
|
1526
|
|
951
|
1527
|
}
|
952
|
1528
|
|
|
1529
|
+func FindDrugCancelStockById(id int64) (cancelStock models.DrugCancelStock, err error) {
|
|
1530
|
+ err = readDb.Model(&models.DrugCancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
|
|
1531
|
+ return cancelStock, err
|
|
1532
|
+
|
|
1533
|
+}
|
|
1534
|
+
|
953
|
1535
|
func UpDateCancelStockInfo(info *models.CancelStockInfo) (err error) {
|
954
|
1536
|
err = writeDb.Save(&info).Error
|
955
|
1537
|
return err
|
956
|
1538
|
}
|
957
|
1539
|
|
|
1540
|
+func UpDateDrugCancelStockInfo(info *models.DrugCancelStockInfo) (err error) {
|
|
1541
|
+ err = writeDb.Save(&info).Error
|
|
1542
|
+ return err
|
|
1543
|
+}
|
|
1544
|
+
|
958
|
1545
|
func FindWarehouseOutList(org_id int64, types int64) (list []*models.WarehouseOut, err error) {
|
959
|
1546
|
err = readDb.Model(&models.WarehouseOut{}).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ? ", org_id).Where("org_id = ? AND status = 1 AND type = ?", org_id, types).Find(&list).Error
|
960
|
1547
|
return list, err
|