package service import ( "XT_New/models" "github.com/jinzhu/gorm" "strconv" "time" ) //根据供应商编号获取首要联系人 func FindName(code string) (fistname models.SpSupplierContacts, err error) { err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1", code).First(&fistname).Error return fistname, err } //供应商分页 func GetSupplyList(ctype int64, page int64, limit int64, code string, sname string, cname string) (supplylist []*models.SpSupplierName, total int64, err error) { db := XTReadDB().Model(&supplylist).Where("sgj_xt.xt_supplier_name.status = 1 ") offset := (page - 1) * limit if cname != "" { cname = "%" + cname + "%" //联系人 db = db.Joins("join sgj_xt.xt_supplier_contacts on sgj_xt.xt_supplier_contacts.supplier_code = sgj_xt.xt_supplier_name.supplier_code") 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") } if ctype > 0 { db = db.Where("sgj_xt.xt_supplier_name.supplier_type = ?", ctype) } if code != "" { code = "%" + code + "%" //供应商编码 db = db.Where("sgj_xt.xt_supplier_name.supplier_code = ?", code) } if sname != "" { sname = "%" + sname + "%" //供应商名称 db = db.Where("sgj_xt.xt_supplier_name.supplier_name = ?", sname) } err = db.Count(&total).Offset(offset).Limit(limit).Find(&supplylist).Error return supplylist, total, err } //修改供应商和联系人 func UpdateSupplyAndContact(thisStockIn []interface{}, suid, orgId, supplierType, tcreater int64, supplierCode, supplierName, number, bank, bankAccount string, vatRate float64) error { tx := XTWriteDB().Begin() defer func() { if err != nil { tx.Rollback() } else { tx.Commit() } }() for _, item := range thisStockIn { items := item.(map[string]interface{}) //查询是否 id, _ := strconv.ParseInt(items["id"].(string), 10, 64) name := items["name"].(string) phone := items["phone"].(string) address := items["address"].(string) isfirst, _ := strconv.ParseInt(items["isfirst"].(string), 10, 64) updatecontacts := models.SpSupplierContacts{ ID: id, Name: name, Phone: phone, Address: address, IsFirst: isfirst, SupplierCode: supplierCode, UserOrgId: orgId, Status: 1, Ctime: 0, Mtime: time.Now().Unix(), } if id == 0 { spcontacts := models.SpSupplierContacts{ Name: name, Phone: phone, Address: address, IsFirst: isfirst, SupplierCode: supplierCode, UserOrgId: orgId, Status: 1, Ctime: time.Now().Unix(), Mtime: 0, } err = SaveContacts(spcontacts, tx) if err != nil { return err } } else { err = UpdateContact(updatecontacts, tx) } var tmpid int64 if isfirst == 1 { if id == 0 { var spconid []*models.SpSupplierContacts spconid, err = SaveContactsId(tx) if err != nil { return err } tmpid = spconid[0].ID } else { tmpid = id } //更新供应商 upsupply := models.SpSupplierName{ ID: suid, SupplierCode: supplierCode, SupplierName: supplierName, SupplierType: supplierType, VatRate: vatRate, Number: number, Bank: bank, BankAccount: bankAccount, UserOrgId: orgId, Status: 1, ContactsId: tmpid, Mtime: time.Now().Unix(), Modify: tcreater, } err = UpdateSupplyName(upsupply, tx) if err != nil { return err } } } return err } //更新一条供应商的信息 func UpdateSupplyName(upsupply models.SpSupplierName, tx *gorm.DB) error { 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 return err } //更新一条联系人的信息 func UpdateContact(updatecontacts models.SpSupplierContacts, tx *gorm.DB) error { 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 return err } //查询供应商单条记录 func GetSupplyOne(id int64) (supply models.SpSupplierName, err error) { err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1", id).First(&supply).Error return supply, err } //删除单条联系人记录 func DelContactOne(id int64) error { err := XTWriteDB().Model(&models.SpSupplierContacts{}).Where("id = ?", id).Update("status", 0).Error return err } //获取单条供应商和涉及到的联系人记录 func GetSupplyAndContactOne(id int64) (supply models.SpSupplierName, contact []*models.SpSupplierContacts, err error) { err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1", id).First(&supply).Error code := supply.SupplierCode err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1", code).Find(&contact).Error return supply, contact, err } //删除供应商及联系人 func DelSupply(supply models.SpSupplierName) error { err := XTWriteDB().Model(&supply).Update("status", 0).Error return err } //保存供应商和联系人 func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreater int64, supplierCode, supplierName, number, bank, bankAccount string, vatRate float64) error { tx := XTWriteDB().Begin() defer func() { if err != nil { tx.Rollback() } else { tx.Commit() } }() for _, item := range thisStockIn { items := item.(map[string]interface{}) name := items["name"].(string) phone := items["phone"].(string) address := items["address"].(string) isfirst, _ := strconv.ParseInt(items["isfirst"].(string), 10, 64) spcontacts := models.SpSupplierContacts{ Name: name, Phone: phone, Address: address, IsFirst: isfirst, SupplierCode: supplierCode, UserOrgId: orgId, Status: 1, Ctime: time.Now().Unix(), Mtime: 0, } err = SaveContacts(spcontacts, tx) if isfirst == 1 { var spconid []*models.SpSupplierContacts spconid, err = SaveContactsId(tx) if err != nil { return err } tmpid := spconid[0].ID //保存供应商 supply := models.SpSupplierName{ SupplierCode: supplierCode, SupplierName: supplierName, SupplierType: supplierType, VatRate: vatRate, Number: number, Bank: bank, BankAccount: bankAccount, UserOrgId: orgId, Status: 1, ContactsId: tmpid, Ctime: time.Now().Unix(), Mtime: 0, Creater: tcreater, Modify: tcreater, } err = SaveSupply(supply, tx) if err != nil { return err } } if err != nil { return err } } return err } //获取供应商编码 func GetSuppliyCode() (spcode []*models.SpSupplierName, err error) { err = XTReadDB().Model(&models.SpSupplierName{}).Select("supplier_code").Where("supplier_code like 'gys%' and status = 1 ").Order("supplier_code desc").First(&spcode).Error return spcode, err } //查询供应商的名字是否有重复 func FindSupplierName(supplierName string) (sbool bool, err error) { var total int err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierName).Count(&total).Error if total != 0 { sbool = true } else { sbool = false } return sbool, err } //查询供应商的编号是否有重复 func FindSupplierCode(supplierCode string) (codebool bool, err error) { var total int err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierCode).Count(&total).Error if total != 0 { codebool = true } else { codebool = false } return codebool, err } //保存一条供应商数据 func SaveSupply(supply models.SpSupplierName, tx *gorm.DB) error { err := tx.Create(&supply).Error return err } //获取联系人的id func SaveContactsId(tx *gorm.DB) (spconid []*models.SpSupplierContacts, err error) { err = tx.Model(&models.SpSupplierContacts{}).Select("id").Where("and status = 1").Order("id desc").First(&spconid).Error return } //保存一条联系人数据 func SaveContacts(spcontacts models.SpSupplierContacts, tx *gorm.DB) error { err := tx.Create(&spcontacts).Error return err } func GetSupplyDrugList(orgid int64) (drug []*models.SpBaseDrug, err error) { db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1") if orgid > 0 { db = db.Where("x.org_id = ?", orgid) } err = db.Preload("DrugWarehouseInfo", "status = 1 and org_id = ? and (stock_max_number >0 or stock_min_number>0)", orgid).Find(&drug).Error return drug, err } func GetSupplyGoodList(orgid int64) (good []*models.SpGoodInformation, err error) { db := XTReadDB().Table("xt_good_information as x").Where("x.status = 1") if orgid > 0 { db = db.Where("x.org_id = ?", orgid) } err = db.Preload("GoodWarehouseInfo", "status = 1 and org_id = ?", orgid).Find(&good).Error return good, err } func GetSupplierList(orgid int64) (suppler []*models.SpSupplierName, err error) { err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&suppler).Error return suppler, err } func FindAllSupplyOrder(orgid int64) (total int64, err error) { err = XTReadDB().Model(&models.SupplierWarehouseInfo{}).Where("user_org_id = ?", orgid).Count(&total).Error return total, err } func CreateSupplyWarehouse(info models.SupplierWarehouseInfo) error { err := XTWriteDB().Create(&info).Error return err } func FindLastSupplyWarehouseInfo(orgid int64) (models.SupplierWarehouseInfo, error) { info := models.SupplierWarehouseInfo{} err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Last(&info).Error return info, err } func CreateSupplyWarehousingOrder(order *models.SupplierWarehousingInfoOrder) error { err := XTWriteDB().Create(&order).Error return err } func GetAllPurchaseOrderList(check_id int64, startime int64, endtime int64, keyword string, page int64, limit int64, orgid int64) (info []*models.VmSupplierWarehouseInfo, total int64, err error) { db := XTReadDB().Model(&info).Where("sgj_xt.xt_supplier_warehouse_info.status = 1") likeKey := "%" + keyword + "%" offset := (page - 1) * limit if check_id > 0 { db = db.Where("sgj_xt.xt_supplier_warehouse_info.is_check = ?", check_id) } if startime > 0 { db = db.Where("sgj_xt.xt_supplier_warehouse_info.record_date >= ?", startime) } if endtime > 0 { db = db.Where("sgj_xt.xt_supplier_warehouse_info.record_date<=?", endtime) } if len(keyword) > 0 { db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_info.supplier_id") 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") } if orgid > 0 { db = db.Where("sgj_xt.xt_supplier_warehouse_info.user_org_id = ?", orgid) } 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 return info, total, err } func GetSupplyWarehousingOrderInfo(id int64) (order []*models.SupplierWarehousingInfoOrder, err error) { err = XTReadDB().Where("warehousing_id = ? and status = 1", id).Find(&order).Error return order, err } func GetSupplyWarehousingOrderInfoTwo(id int64, ids []string) (order []*models.SupplierWarehousingInfoOrder, err error) { err = XTReadDB().Where("warehousing_id = ? and status = 1 and project_id in(?)", id, ids).Find(&order).Error return order, err } func ModefySupplyWarehouseInfo(id int64, info models.SupplierWarehouseInfo) error { 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, "return_remake": info.ReturnRemake}).Error return err } func ModifySupplyWarehouseOrder(order *models.SupplierWarehousingInfoOrder) error { 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 return err } func UpdateSupplyWaresing(id int64, info models.SupplierWarehouseInfo) error { err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"is_check": info.IsCheck, "checker": info.Checker, "check_time": info.CheckTime, "mtime": time.Now().Unix()}).Error return err } func GetPurchaseOrderDetail(id int64) (models.SupplierWarehouseInfo, error) { info := models.SupplierWarehouseInfo{} err := XTReadDB().Model(&info).Where("id =? and status =1", id).Find(&info).Error return info, err } func FindAllSupplyWarehouseOutOrder(orgid int64) (total int64, err error) { err = XTReadDB().Model(&models.SpSupplierWarehouseOut{}).Where("user_org_id = ?", orgid).Count(&total).Error return total, err } func FindSupplyWarehouseOutById(orgid int64) (models.SpSupplierWarehouseOut, error) { out := models.SpSupplierWarehouseOut{} err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Last(&out).Error return out, err } func CreateSupplyWarehouseOut(out models.SpSupplierWarehouseOut) error { err := XTWriteDB().Create(&out).Error return err } func CreateSupplyWarehousOutOrder(order *models.SpSupplierWarehousingOutOrder) error { err := XTWriteDB().Create(&order).Error return err } func GetSupplyWarehouseOutById(id int64, user_org_id int64) (order []*models.SpSupplierWarehousingOutOrder, err error) { err = XTReadDB().Where("warehouse_out_id = ? and status = 1 and user_org_id = ?", id, user_org_id).Find(&order).Error return order, err } func GetSupplyWarehouseOutByIdOne(id int64, user_org_id int64, ids []string) (order []*models.SpSupplierWarehousingOutOrder, err error) { err = XTReadDB().Where("warehouse_out_id = ? and status = 1 and user_org_id = ? and project_id in(?)", id, user_org_id, ids).Find(&order).Error return order, err } func GetAllGoodOderList(check_id int64, keyword string, page int64, limit int64, startime int64, endtime int64, orgid int64) (out []*models.VmSupplierWarehouseOut, total int64, err error) { db := XTReadDB().Model(&out).Where("sgj_xt.xt_supplier_warehouse_out.status = 1") likeKey := "%" + keyword + "%" offset := (page - 1) * limit if check_id > 0 { db = db.Where("sgj_xt.xt_supplier_warehouse_out.is_check = ?", check_id) } if startime > 0 { db = db.Where("sgj_xt.xt_supplier_warehouse_out.record_date >= ?", startime) } if endtime > 0 { db = db.Where("sgj_xt.xt_supplier_warehouse_out.record_date<=?", endtime) } if len(keyword) > 0 { db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_out.supplier_id") db = db.Where("sgj_xt.xt_supplier_warehouse_out.good_number like ? or sgj_xt.xt_supplier_name.supplier_name like ? ", likeKey, likeKey).Group("xt_supplier_warehouse_out.id") } if orgid > 0 { db = db.Where("sgj_xt.xt_supplier_warehouse_out.user_org_id = ?", orgid) } err = db.Count(&total).Offset(offset).Limit(limit).Preload("SpSupplierWarehousingOutOrder", "status= 1 and user_org_id = ?", orgid).Preload("SpSupplierWarehousingCancelOrder", "status= 1 and user_org_id = ?", orgid).Find(&out).Error return out, total, err } func GetGoodOrderDetail(id int64, orgid int64) (models.SpSupplierWarehouseOut, error) { out := models.SpSupplierWarehouseOut{} err := XTReadDB().Where("id = ? and user_org_id = ? and status = 1", id, orgid).Find(&out).Error return out, err } func UpdateGoodWarehouseOut(id int64, out models.SpSupplierWarehouseOut) error { 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, "return_remake": out.ReturnRemake}).Error return err } func UpdateGoodWarehouseOutOrder(order *models.SpSupplierWarehousingOutOrder) error { 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, "remark": order.Remark, "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, "warehousing_id": order.WarehousingId, "warehouse_info_id": order.WarehouseInfoId}).Error return err } func DeletePurchOrder(id int64, orgid int64) error { err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error 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 return err } func GetAllPurcaseOrderById(id int64, orgid int64) (order []*models.VSupplierWarehousingInfoOrder, err error) { err = XTReadDB().Model(&order).Where("warehousing_id = ? and user_org_id = ? and status =1", id, orgid).Find(&order).Error return order, err } func GetAllGoodOrderById(id int64, orgid int64) (order []*models.VSpSupplierWarehousingOutOrder, err error) { db := XTReadDB().Table("xt_supplier_warehousing_out_order as o").Where("o.status = 1") if id > 0 { db = db.Where("o.warehousing_id = ?", id) } if orgid > 0 { db = db.Where("o.user_org_id =?", orgid) } err = db.Select("o.id,o.order_number,o.project_id,o.count as count,o.supply_unit,o.is_source").Find(&order).Error return order, err } func GetAllGoodOrderByIdTwo(id int64, orgid int64) (order []*models.SpSupplierWarehousingOutOrder, err error) { err = XTReadDB().Where("warehousing_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&order).Error return order, err } func GetGoodOrderList(id int64, orgid int64) (info []*models.SpSupplierWarehouseOut, err error) { err = XTReadDB().Where("warehousing_id = ? and status = 1 and user_org_id = ?", id, orgid).Find(&info).Error return info, err } func GetReturnOrder(id int64, orgid int64) error { 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 return err } func CheckGoodOrder(id int64, orgid int64, out models.SpSupplierWarehouseOut) error { 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 return err } func ModefySupplyWarehousing(is_warehose int64, warehousing_id int64, orgid int64) error { err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status = 1 and user_org_id =?", warehousing_id, orgid).Updates(map[string]interface{}{"is_warehouse": is_warehose, "mtime": time.Now().Unix()}).Error return err } func GetAllDoctorSix(orgid int64, appid int64) (appRole []*models.App_Role, err error) { err = UserReadDB().Where("org_id = ? AND app_id = ? AND status = 1", orgid, appid).Find(&appRole).Error return appRole, err } func GetSingleDrugWarehouseOrder(record_date int64, orgid int64) (*models.DrugWarehouse, error) { warehouse := models.DrugWarehouse{} var err error err = XTReadDB().Model(&warehouse).Where("warehousing_time = ? and org_id = ? and status = 1", record_date, orgid).Find(&warehouse).Error if err == gorm.ErrRecordNotFound { return nil, err } if err != nil { return nil, err } return &warehouse, nil } func GetSindleWarehouse(record_date int64, orgid int64) (*models.Warehousing, error) { warehousing := models.Warehousing{} var err error err = XTReadDB().Model(&warehousing).Where("warehousing_time = ? and org_id = ? and status = 1", record_date, orgid).Find(&warehousing).Error if err == gorm.ErrRecordNotFound { return nil, err } if err != nil { return nil, err } return &warehousing, nil } func GetLastWarehouseInfoByInfo(orgid int64) (models.Warehousing, error) { warehousing := models.Warehousing{} err := XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&warehousing).Error return warehousing, err } func GetSupplyCancelOrder(orgid int64) (total int64, err error) { err = XTReadDB().Model(&models.SpSupplierWarehouseCancel{}).Where("user_org_id = ?", orgid).Count(&total).Error return total, err } func CreateReturnCacelOrder(cancel models.SpSupplierWarehouseCancel) error { err := XTWriteDB().Create(&cancel).Error return err } func GetLastReturnCancelOrder(orgid int64) (models.SpSupplierWarehouseCancel, error) { cancel := models.SpSupplierWarehouseCancel{} err := XTReadDB().Where("user_org_id =? and status = 1", orgid).Find(&cancel).Error return cancel, err } func CreateCancelReturnOrder(order *models.SpSupplierWarehousingCancelOrder) error { err := XTWriteDB().Create(&order).Error return err } func GetReturnCancelOrder(id int64, orgid int64) (models.SpSupplierWarehouseCancel, error) { cancel := models.SpSupplierWarehouseCancel{} err := XTReadDB().Where("id = ? and status= 1 and user_org_id =?", id, orgid).Find(&cancel).Error return cancel, err } func GetReturnCancelOrderList(id int64, orgid int64) (order models.SpSupplierWarehousingCancelOrder, err error) { err = XTReadDB().Where("warehouse_cancel_id = ? and user_org_id =? and status = 1", id, orgid).Find(&order).Error return order, err } func GetAllGoodReturnOrderList(checkid int64, keyword string, page int64, limit int64, startime int64, endtime int64, orgid int64) (order []*models.VmSpSupplierWarehouseCancel, total int64, err error) { db := XTReadDB().Table("sgj_xt.xt_supplier_warehouse_cancel").Where("sgj_xt.xt_supplier_warehouse_cancel.status = 1") likeKey := "%" + keyword + "%" offset := (page - 1) * limit if checkid > 0 { db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.is_check = ?", checkid) } if len(keyword) > 0 { db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_out.supplier_id") db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.number like ? or sgj_xt.xt_supplier_name.supplier_name like ? ", likeKey, likeKey).Group("xt_supplier_warehouse_cancel.id") } if startime > 0 { db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.record_date >= ?", startime) } if endtime > 0 { db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.record_date <= ?", endtime) } if orgid > 0 { db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.user_org_id = ?", orgid) } err = db.Count(&total).Offset(offset).Limit(limit).Preload("SpSupplierWarehousingCancelOrder", "status= 1 and user_org_id = ?", orgid).Find(&order).Error return order, total, err } func GetGoodReturnDetail(id int64, orgid int64) (models.VmSpSupplierWarehouseCancel, error) { cancel := models.VmSpSupplierWarehouseCancel{} db := XTReadDB().Model(&cancel).Where("status = 1") if id > 0 { db = db.Where("id = ?", id) } if orgid > 0 { db = db.Where("user_org_id = ?", orgid) } err := db.Find(&cancel).Error return cancel, err } func GetGoodReturnOrderDetail(id int64, orgid int64) (order []*models.SpSupplierWarehousingCancelOrder, err error) { db := XTReadDB().Model(&order).Where("status =1") if id > 0 { db = db.Where("warehouse_cancel_id = ?", id) } if orgid > 0 { db = db.Where("user_org_id = ?", orgid) } err = db.Find(&order).Error return order, err } func UpdateWarehouseCancelOrder(order *models.SpSupplierWarehousingCancelOrder) error { err = XTWriteDB().Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{"manufacturer_id": order.ManufacturerId, "order_number": order.OrderNumber, "project_id": order.ProjectId, "is_source": order.IsSource, "count": order.Count, "price": order.Price, "remark": order.Remark, "rate_of_concession": order.RateOfConcession, "discount_amount": order.DiscountAmount, "type": order.Type, "supply_specification_name": order.SupplySpecificationName, "supply_type": order.SupplyType, "supply_total": order.SupplyTotal, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit, "supply_license_number": order.SupplyLicenseNumber}).Error return err } func UpdateWarehouseCancel(id int64, cancel models.SpSupplierWarehouseCancel) error { err := XTWriteDB().Model(&cancel).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"rate_of_concession": cancel.RateOfConcession, "discount_amount": cancel.DiscountAmount, "document_date": cancel.DocumentDate, "supplier_id": cancel.SupplierId, "arrearage": cancel.Arrearage, "payment": cancel.Payment, "return_remark": cancel.ReturnRemark}).Error return err } func GetSupplyCancelOrderById(warehouse_out_id int64, orgid int64) (*models.SpSupplierWarehouseCancel, error) { cancel := models.SpSupplierWarehouseCancel{} var err error err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", warehouse_out_id, orgid).Find(&cancel).Error if err == gorm.ErrRecordNotFound { return nil, err } if err != nil { return nil, err } return &cancel, nil } func UpdateSupplyGoodOrder(id int64, out models.SpSupplierWarehouseOut) error { err := XTWriteDB().Model(&models.SpSupplierWarehouseOut{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"is_check": out.IsCheck, "checker": out.Checker, "check_time": out.CheckTime}).Error return err } func UpdateDrugSupplyWarehousingInfo(id int64, orgid int64) error { err := XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error return err } func UpdateDrugSupplyFlow(id int64, orgid int64) error { err := XTWriteDB().Model(&models.DrugFlow{}).Where("supply_warehouse_id = ? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error return err } func UpdateGoodSupplyWarehousingInfo(id int64, orgid int64) error { err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error return err } func UpdateGoodSupplyFlow(id int64, orgid int64) error { err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("supply_warehouse_id = ? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error return err } func GetDrugSupplyWarehousingById(id int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) { err = XTReadDB().Where("supply_warehouse_id <> ? and org_id = ? and status = 1", id, orgid).Find(&info).Error return info, err } func UpdateSupplyWarehousing(id int64, orgid int64) error { err := XTWriteDB().Model(&models.DrugWarehouse{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error return err } func GetGoodSupplyWarehousingById(id int64, orgid int64) (info []*models.WarehousingInfo, err error) { err = XTReadDB().Where("supply_warehouse_id <> ? and org_id = ? and status = 1", id, orgid).Find(&info).Error return info, err } func UpdateGoodWarehousing(id int64, orgid int64) error { err := XTWriteDB().Model(&models.Warehousing{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error return err } func UpdateSupplyWarehousingById(id int64, orgid int64) error { err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and user_org_id =? and status = 1", id, orgid).Updates(map[string]interface{}{"is_warehouse": 1}).Error return err } func DeleteGoodOrder(id int64, orgid int64) error { err := XTWriteDB().Model(&models.SpSupplierWarehouseOut{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgid).Updates(map[string]interface{}{"status": 0}).Error err = XTWriteDB().Model(&models.SpSupplierWarehousingOutOrder{}).Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error return err } func GetSupplyCancelWarehouse(id int64, orgid int64) (cancel []*models.SpSupplierWarehouseCancel, err error) { err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&cancel).Error return cancel, err } func GetGoodOrderListById(id int64, orgid int64) (out []*models.VmSpSupplierWarehousingOutOrder, err error) { err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&out).Error return out, err } func GetGoodCanceListById(id int64, orgid int64) (cancel []*models.VmSpSupplierWarehousingCancelOrder, err error) { err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&cancel).Error return cancel, err }