supply_service.go 39KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. "strings"
  6. "time"
  7. )
  8. //根据供应商编号获取首要联系人
  9. func FindName(code string, orgid int64) (fistname models.SpSupplierContacts, err error) {
  10. err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1 and is_first = 1 and user_org_id = ?", code, orgid).First(&fistname).Error
  11. return fistname, err
  12. }
  13. //供应商分页
  14. func GetSupplyList(ctype int64, page int64, limit int64, keyword string, orgid int64) (supplylist []*models.SpSupplierName, total int64, err error) {
  15. db := XTReadDB().Model(&supplylist).Where("xt_supplier_name.status = 1 and xt_supplier_name.user_org_id = ?", orgid)
  16. offset := (page - 1) * limit
  17. if len(keyword) > 0 {
  18. keyword = "%" + keyword + "%" //联系人
  19. db = db.Joins("join xt_supplier_contacts on xt_supplier_contacts.supplier_code = xt_supplier_name.supplier_code")
  20. db = db.Where("xt_supplier_contacts.name like ? or xt_supplier_name.supplier_code like ? or xt_supplier_name.supplier_name like ? ", keyword, keyword, keyword).Group("xt_supplier_name.id")
  21. }
  22. if ctype > 0 {
  23. db = db.Where("xt_supplier_name.supplier_type = ?", ctype)
  24. }
  25. err = db.Count(&total).Offset(offset).Order("xt_supplier_name.id desc").Limit(limit).Find(&supplylist).Error
  26. return supplylist, total, err
  27. }
  28. //修改供应商和联系人
  29. func UpdateSupplyAndContact(thisStockIn []interface{}, suid, orgId, supplierType, tcreater int64, supplierCode, supplierName, number, bank, bankAccount string, vatRate float64) error {
  30. tx := XTWriteDB().Begin()
  31. defer func() {
  32. if err != nil {
  33. tx.Rollback()
  34. } else {
  35. tx.Commit()
  36. }
  37. }()
  38. for _, item := range thisStockIn {
  39. items := item.(map[string]interface{})
  40. //查询是否
  41. if items["id"] == "" || items["id"] == 0 {
  42. var tmp float64 = 0
  43. items["id"] = tmp
  44. }
  45. //id, _ := strconv.ParseInt(items["id"].(string), 10, 64)
  46. id := int64(items["id"].(float64))
  47. name := items["name"].(string)
  48. phone := items["phone"].(string)
  49. address := items["address"].(string)
  50. var tmpfirst int64
  51. //tmptype := reflect.TypeOf(items["is_first"])
  52. switch items["is_first"].(type) {
  53. case int:
  54. var aint int = items["is_first"].(int)
  55. tmpfirst = int64(aint)
  56. case float64:
  57. tmpfirst = int64(items["is_first"].(float64))
  58. }
  59. isfirst := tmpfirst
  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, orgId)
  96. if err != nil {
  97. return err
  98. }
  99. tmpid = spconid[0].ID
  100. } else {
  101. tmpid = id
  102. }
  103. //更新供应商
  104. upsupply := models.SpSupplierName{
  105. ID: suid,
  106. SupplierCode: supplierCode,
  107. SupplierName: supplierName,
  108. SupplierType: supplierType,
  109. VatRate: vatRate,
  110. Number: number,
  111. Bank: bank,
  112. BankAccount: bankAccount,
  113. UserOrgId: orgId,
  114. Status: 1,
  115. ContactsId: tmpid,
  116. Mtime: time.Now().Unix(),
  117. Modify: tcreater,
  118. }
  119. err = UpdateSupplyName(upsupply, tx)
  120. if err != nil {
  121. return err
  122. }
  123. }
  124. }
  125. return err
  126. }
  127. //更新一条供应商的信息
  128. func UpdateSupplyName(upsupply models.SpSupplierName, tx *gorm.DB) error {
  129. 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
  130. return err
  131. }
  132. //更新一条联系人的信息
  133. func UpdateContact(updatecontacts models.SpSupplierContacts, tx *gorm.DB) error {
  134. 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
  135. return err
  136. }
  137. //查询供应商单条记录
  138. func GetSupplyOne(id int64) (supply models.SpSupplierName, err error) {
  139. err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1", id).First(&supply).Error
  140. return supply, err
  141. }
  142. //删除单条联系人记录
  143. func DelContactOne(id int64) error {
  144. err := XTWriteDB().Model(&models.SpSupplierContacts{}).Where("id = ?", id).Update("status", 0).Error
  145. return err
  146. }
  147. //获取单条供应商和涉及到的联系人记录
  148. func GetSupplyAndContactOne(id, orgId int64) (supply models.SpSupplierName, contact []*models.SpSupplierContacts, err error) {
  149. err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgId).First(&supply).Error
  150. code := supply.SupplierCode
  151. err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1 and user_org_id = ?", code, orgId).Find(&contact).Error
  152. return supply, contact, err
  153. }
  154. //删除供应商及联系人
  155. func DelSupply(supply models.SpSupplierName) error {
  156. err := XTWriteDB().Model(&supply).Update("status", 0).Error
  157. return err
  158. }
  159. //保存供应商和联系人
  160. func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreater int64, supplierCode, supplierName, number, bank, bankAccount string, vatRate float64) error {
  161. tx := XTWriteDB().Begin()
  162. defer func() {
  163. if err != nil {
  164. tx.Rollback()
  165. } else {
  166. tx.Commit()
  167. }
  168. }()
  169. for _, item := range thisStockIn {
  170. items := item.(map[string]interface{})
  171. name := items["name"].(string)
  172. phone := items["phone"].(string)
  173. address := items["address"].(string)
  174. //isfirst := int64(items["is_first"].(float64))
  175. var tmpfirst int64
  176. //tmptype := reflect.TypeOf(items["is_first"])
  177. switch items["is_first"].(type) {
  178. case int:
  179. var aint int = items["is_first"].(int)
  180. tmpfirst = int64(aint)
  181. case float64:
  182. tmpfirst = int64(items["is_first"].(float64))
  183. }
  184. isfirst := tmpfirst
  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, orgId)
  200. if err != nil {
  201. return err
  202. }
  203. tmpid := spconid[0].ID
  204. //保存供应商
  205. supply := models.SpSupplierName{
  206. SupplierCode: supplierCode,
  207. SupplierName: supplierName,
  208. SupplierType: supplierType,
  209. VatRate: vatRate,
  210. Number: number,
  211. Bank: bank,
  212. BankAccount: bankAccount,
  213. UserOrgId: orgId,
  214. Status: 1,
  215. ContactsId: tmpid,
  216. Ctime: time.Now().Unix(),
  217. Mtime: 0,
  218. Creater: tcreater,
  219. Modify: tcreater,
  220. }
  221. err = SaveSupply(supply, tx)
  222. if err != nil {
  223. return err
  224. }
  225. }
  226. if err != nil {
  227. return err
  228. }
  229. }
  230. return err
  231. }
  232. //获取供应商编码
  233. func GetSuppliyCode(orgId int64) (spcode []*models.SpSupplierName, err error) {
  234. err = XTReadDB().Model(&models.SpSupplierName{}).Select("supplier_code").Where("supplier_code like 'gys%' and status = 1 and user_org_id = ? ", orgId).Order("supplier_code desc").First(&spcode).Error
  235. return spcode, err
  236. }
  237. //查询供应商的名字是否有重复
  238. func FindSupplierName(supplierName string, orgId int64) (sbool bool, err error) {
  239. var total int
  240. err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierName).Count(&total).Error
  241. if total != 0 {
  242. sbool = true
  243. } else {
  244. sbool = false
  245. }
  246. return sbool, err
  247. }
  248. //查询供应商的编号是否有重复(用于修改)
  249. func FindSupplierCode(supplierCode string, supplierid, orgid int64) (codebool bool, err error) {
  250. var total int
  251. err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_code = ? and id != ? and user_org_id = ? and status = 1", supplierCode, supplierid, orgid).Count(&total).Error
  252. if total > 0 {
  253. codebool = true
  254. } else {
  255. codebool = false
  256. }
  257. return codebool, err
  258. }
  259. //查询供应商的编号是否有重复(用于新增)
  260. func FindSupplierCodes(supplierCode string, orgid int64) (codebool bool, err error) {
  261. var total int
  262. err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_code = ? and status = 1 and user_org_id = ?", supplierCode, orgid).Count(&total).Error
  263. if total > 0 {
  264. codebool = true
  265. } else {
  266. codebool = false
  267. }
  268. return codebool, err
  269. }
  270. //保存一条供应商数据
  271. func SaveSupply(supply models.SpSupplierName, tx *gorm.DB) error {
  272. err := tx.Create(&supply).Error
  273. return err
  274. }
  275. //获取联系人的id
  276. func SaveContactsId(tx *gorm.DB, orgid int64) (spconid []*models.SpSupplierContacts, err error) {
  277. err = tx.Model(&models.SpSupplierContacts{}).Select("id").Where("status = 1 and user_org_id = ?", orgid).Order("id desc").First(&spconid).Error
  278. return
  279. }
  280. //保存一条联系人数据
  281. func SaveContacts(spcontacts models.SpSupplierContacts, tx *gorm.DB) error {
  282. err := tx.Create(&spcontacts).Error
  283. return err
  284. }
  285. func GetSupplyDrugList(orgid int64) (drug []*models.SpBaseDrug, err error) {
  286. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1 AND find_in_set('停用',drug_status) = 0")
  287. if orgid > 0 {
  288. db = db.Where("x.org_id = ?", orgid)
  289. }
  290. err = db.Preload("DrugWarehouseInfo", "status = 1 and org_id = ? and (stock_max_number >0 or stock_min_number>0)", orgid).Find(&drug).Error
  291. return drug, err
  292. }
  293. func GetSupplyGoodList(orgid int64) (good []*models.SpGoodInformation, err error) {
  294. db := XTReadDB().Table("xt_good_information as x").Where("x.status = 1 AND find_in_set('停用',good_status) = 0")
  295. if orgid > 0 {
  296. db = db.Where("x.org_id = ?", orgid)
  297. }
  298. err = db.Preload("GoodWarehouseInfo", "status = 1 and org_id = ?", orgid).Find(&good).Error
  299. return good, err
  300. }
  301. func GetSupplierList(orgid int64) (suppler []*models.SpSupplierName, err error) {
  302. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&suppler).Error
  303. return suppler, err
  304. }
  305. func FindAllSupplyOrder(orgid int64) (total int64, err error) {
  306. err = XTReadDB().Model(&models.SupplierWarehouseInfo{}).Where("user_org_id = ?", orgid).Count(&total).Error
  307. return total, err
  308. }
  309. func CreateSupplyWarehouse(info models.SupplierWarehouseInfo) error {
  310. err := XTWriteDB().Create(&info).Error
  311. return err
  312. }
  313. func FindLastSupplyWarehouseInfo(orgid int64) (models.SupplierWarehouseInfo, error) {
  314. info := models.SupplierWarehouseInfo{}
  315. err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Last(&info).Error
  316. return info, err
  317. }
  318. func CreateSupplyWarehousingOrder(order *models.SupplierWarehousingInfoOrder) error {
  319. err := XTWriteDB().Create(&order).Error
  320. return err
  321. }
  322. func GetAllPurchaseOrderList(check_id int64, startime int64, endtime int64, keyword string, page int64, limit int64, orgid int64) (info []*models.VmSupplierWarehouseInfo, total int64, err error) {
  323. db := XTReadDB().Model(&info).Where("sgj_xt.xt_supplier_warehouse_info.status = 1")
  324. likeKey := "%" + keyword + "%"
  325. offset := (page - 1) * limit
  326. if check_id > 0 {
  327. db = db.Where("sgj_xt.xt_supplier_warehouse_info.is_check = ?", check_id)
  328. }
  329. if startime > 0 {
  330. db = db.Where("sgj_xt.xt_supplier_warehouse_info.record_date >= ?", startime)
  331. }
  332. if endtime > 0 {
  333. db = db.Where("sgj_xt.xt_supplier_warehouse_info.record_date<=?", endtime)
  334. }
  335. if len(keyword) > 0 {
  336. db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_info.supplier_id")
  337. 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")
  338. }
  339. if orgid > 0 {
  340. db = db.Where("sgj_xt.xt_supplier_warehouse_info.user_org_id = ?", orgid)
  341. }
  342. 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).Order("ctime desc").Find(&info).Error
  343. return info, total, err
  344. }
  345. func GetSupplyWarehousingOrderInfo(id int64) (order []*models.SupplierWarehousingInfoOrder, err error) {
  346. err = XTReadDB().Where("warehousing_id = ? and status = 1", id).Find(&order).Error
  347. return order, err
  348. }
  349. func GetSupplyWarehousingOrderInfoTwo(id int64, ids []string) (order []*models.SupplierWarehousingInfoOrder, err error) {
  350. err = XTReadDB().Where("warehousing_id = ? and status = 1 and project_id in(?)", id, ids).Find(&order).Error
  351. return order, err
  352. }
  353. func ModefySupplyWarehouseInfo(id int64, info models.SupplierWarehouseInfo) error {
  354. 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
  355. return err
  356. }
  357. func ModifySupplyWarehouseOrder(order *models.SupplierWarehousingInfoOrder) error {
  358. 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
  359. return err
  360. }
  361. func UpdateSupplyWaresing(id int64, info models.SupplierWarehouseInfo) error {
  362. 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
  363. return err
  364. }
  365. func GetPurchaseOrderDetail(id int64) (models.SupplierWarehouseInfo, error) {
  366. info := models.SupplierWarehouseInfo{}
  367. err := XTReadDB().Model(&info).Where("id =? and status =1", id).Find(&info).Error
  368. return info, err
  369. }
  370. func FindAllSupplyWarehouseOutOrder(orgid int64) (total int64, err error) {
  371. err = XTReadDB().Model(&models.SpSupplierWarehouseOut{}).Where("user_org_id = ?", orgid).Count(&total).Error
  372. return total, err
  373. }
  374. func FindSupplyWarehouseOutById(orgid int64) (models.SpSupplierWarehouseOut, error) {
  375. out := models.SpSupplierWarehouseOut{}
  376. err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Last(&out).Error
  377. return out, err
  378. }
  379. func CreateSupplyWarehouseOut(out models.SpSupplierWarehouseOut) error {
  380. err := XTWriteDB().Create(&out).Error
  381. return err
  382. }
  383. func CreateSupplyWarehousOutOrder(order *models.SpSupplierWarehousingOutOrder) error {
  384. err := XTWriteDB().Create(&order).Error
  385. return err
  386. }
  387. func GetSupplyWarehouseOutById(id int64, user_org_id int64) (order []*models.SpSupplierWarehousingOutOrder, err error) {
  388. err = XTReadDB().Where("warehouse_out_id = ? and status = 1 and user_org_id = ?", id, user_org_id).Find(&order).Error
  389. return order, err
  390. }
  391. func GetSupplyWarehouseOutByIdOne(id int64, user_org_id int64, ids []string) (order []*models.SpSupplierWarehousingOutOrder, err error) {
  392. 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
  393. return order, err
  394. }
  395. func GetAllGoodOderList(check_id int64, keyword string, page int64, limit int64, startime int64, endtime int64, orgid int64) (out []*models.VmSupplierWarehouseOut, total int64, err error) {
  396. db := XTReadDB().Model(&out).Where("sgj_xt.xt_supplier_warehouse_out.status = 1")
  397. likeKey := "%" + keyword + "%"
  398. offset := (page - 1) * limit
  399. if check_id > 0 {
  400. db = db.Where("sgj_xt.xt_supplier_warehouse_out.is_check = ?", check_id)
  401. }
  402. if startime > 0 {
  403. db = db.Where("sgj_xt.xt_supplier_warehouse_out.record_date >= ?", startime)
  404. }
  405. if endtime > 0 {
  406. db = db.Where("sgj_xt.xt_supplier_warehouse_out.record_date<=?", endtime)
  407. }
  408. if len(keyword) > 0 {
  409. db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_out.supplier_id")
  410. 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")
  411. }
  412. if orgid > 0 {
  413. db = db.Where("sgj_xt.xt_supplier_warehouse_out.user_org_id = ?", orgid)
  414. }
  415. 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).Order("ctime desc").Find(&out).Error
  416. return out, total, err
  417. }
  418. func GetGoodOrderDetail(id int64, orgid int64) (models.SpSupplierWarehouseOut, error) {
  419. out := models.SpSupplierWarehouseOut{}
  420. err := XTReadDB().Where("id = ? and user_org_id = ? and status = 1", id, orgid).Find(&out).Error
  421. return out, err
  422. }
  423. func UpdateGoodWarehouseOut(id int64, out models.SpSupplierWarehouseOut) error {
  424. 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
  425. return err
  426. }
  427. func UpdateGoodWarehouseOutOrder(order *models.SpSupplierWarehousingOutOrder) error {
  428. 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
  429. return err
  430. }
  431. func DeletePurchOrder(id int64, orgid int64) error {
  432. err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  433. 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
  434. return err
  435. }
  436. func GetAllPurcaseOrderById(id int64, orgid int64) (order []*models.VSupplierWarehousingInfoOrder, err error) {
  437. err = XTReadDB().Model(&order).Where("warehousing_id = ? and user_org_id = ? and status =1", id, orgid).Find(&order).Error
  438. return order, err
  439. }
  440. func GetAllGoodOrderById(id int64, orgid int64) (order []*models.VSpSupplierWarehousingOutOrder, err error) {
  441. db := XTReadDB().Table("xt_supplier_warehousing_out_order as o").Where("o.status = 1")
  442. if id > 0 {
  443. db = db.Where("o.warehousing_id = ?", id)
  444. }
  445. if orgid > 0 {
  446. db = db.Where("o.user_org_id =?", orgid)
  447. }
  448. err = db.Select("o.id,o.order_number,o.project_id,o.count as count,o.supply_unit,o.is_source").Find(&order).Error
  449. return order, err
  450. }
  451. func GetAllGoodOrderByIdTwo(id int64, orgid int64) (order []*models.SpSupplierWarehousingOutOrder, err error) {
  452. err = XTReadDB().Where("warehousing_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&order).Error
  453. return order, err
  454. }
  455. func GetGoodOrderList(id int64, orgid int64) (info []*models.SpSupplierWarehouseOut, err error) {
  456. err = XTReadDB().Where("warehousing_id = ? and status = 1 and user_org_id = ?", id, orgid).Find(&info).Error
  457. return info, err
  458. }
  459. func GetReturnOrder(id int64, orgid int64) error {
  460. 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
  461. return err
  462. }
  463. func CheckGoodOrder(id int64, orgid int64, out models.SpSupplierWarehouseOut) error {
  464. 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
  465. return err
  466. }
  467. func ModefySupplyWarehousing(is_warehose int64, warehousing_id int64, orgid int64) error {
  468. 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
  469. return err
  470. }
  471. func GetAllDoctorSix(orgid int64, appid int64) (appRole []*models.App_Role, err error) {
  472. err = UserReadDB().Where("org_id = ? AND app_id = ? AND status = 1", orgid, appid).Find(&appRole).Error
  473. return appRole, err
  474. }
  475. func GetSingleDrugWarehouseOrder(record_date int64, orgid int64) (*models.DrugWarehouse, error) {
  476. warehouse := models.DrugWarehouse{}
  477. var err error
  478. err = XTReadDB().Model(&warehouse).Where("warehousing_time = ? and org_id = ? and status = 1", record_date, orgid).Find(&warehouse).Error
  479. if err == gorm.ErrRecordNotFound {
  480. return nil, err
  481. }
  482. if err != nil {
  483. return nil, err
  484. }
  485. return &warehouse, nil
  486. }
  487. func GetSindleWarehouse(record_date int64, orgid int64) (*models.Warehousing, error) {
  488. warehousing := models.Warehousing{}
  489. var err error
  490. err = XTReadDB().Model(&warehousing).Where("warehousing_time = ? and org_id = ? and status = 1", record_date, orgid).Find(&warehousing).Error
  491. if err == gorm.ErrRecordNotFound {
  492. return nil, err
  493. }
  494. if err != nil {
  495. return nil, err
  496. }
  497. return &warehousing, nil
  498. }
  499. func GetLastWarehouseInfoByInfo(orgid int64) (models.Warehousing, error) {
  500. warehousing := models.Warehousing{}
  501. err := XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&warehousing).Error
  502. return warehousing, err
  503. }
  504. func GetSupplyCancelOrder(orgid int64) (total int64, err error) {
  505. err = XTReadDB().Model(&models.SpSupplierWarehouseCancel{}).Where("user_org_id = ?", orgid).Count(&total).Error
  506. return total, err
  507. }
  508. func CreateReturnCacelOrder(cancel models.SpSupplierWarehouseCancel) error {
  509. err := XTWriteDB().Create(&cancel).Error
  510. return err
  511. }
  512. func GetLastReturnCancelOrder(orgid int64) (models.SpSupplierWarehouseCancel, error) {
  513. cancel := models.SpSupplierWarehouseCancel{}
  514. err := XTReadDB().Where("user_org_id =? and status = 1", orgid).Find(&cancel).Error
  515. return cancel, err
  516. }
  517. func CreateCancelReturnOrder(order *models.SpSupplierWarehousingCancelOrder) error {
  518. err := XTWriteDB().Create(&order).Error
  519. return err
  520. }
  521. func GetReturnCancelOrder(id int64, orgid int64) (models.SpSupplierWarehouseCancel, error) {
  522. cancel := models.SpSupplierWarehouseCancel{}
  523. err := XTReadDB().Where("id = ? and status= 1 and user_org_id =?", id, orgid).Find(&cancel).Error
  524. return cancel, err
  525. }
  526. func GetReturnCancelOrderList(id int64, orgid int64) (order models.SpSupplierWarehousingCancelOrder, err error) {
  527. err = XTReadDB().Where("warehouse_cancel_id = ? and user_org_id =? and status = 1", id, orgid).Find(&order).Error
  528. return order, err
  529. }
  530. func GetAllGoodReturnOrderList(checkid int64, keyword string, page int64, limit int64, startime int64, endtime int64, orgid int64) (order []*models.VmSpSupplierWarehouseCancel, total int64, err error) {
  531. db := XTReadDB().Table("sgj_xt.xt_supplier_warehouse_cancel").Where("sgj_xt.xt_supplier_warehouse_cancel.status = 1")
  532. likeKey := "%" + keyword + "%"
  533. offset := (page - 1) * limit
  534. if checkid > 0 {
  535. db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.is_check = ?", checkid)
  536. }
  537. if len(keyword) > 0 {
  538. db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_cancel.supplier_id")
  539. 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")
  540. }
  541. if startime > 0 {
  542. db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.record_date >= ?", startime)
  543. }
  544. if endtime > 0 {
  545. db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.record_date <= ?", endtime)
  546. }
  547. if orgid > 0 {
  548. db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.user_org_id = ?", orgid)
  549. }
  550. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SpSupplierWarehousingCancelOrder", "status= 1 and user_org_id = ?", orgid).Order("ctime desc").Find(&order).Error
  551. return order, total, err
  552. }
  553. func GetGoodReturnDetail(id int64, orgid int64) (models.VmSpSupplierWarehouseCancel, error) {
  554. cancel := models.VmSpSupplierWarehouseCancel{}
  555. db := XTReadDB().Model(&cancel).Where("status = 1")
  556. if id > 0 {
  557. db = db.Where("id = ?", id)
  558. }
  559. if orgid > 0 {
  560. db = db.Where("user_org_id = ?", orgid)
  561. }
  562. err := db.Find(&cancel).Error
  563. return cancel, err
  564. }
  565. func GetGoodReturnOrderDetail(id int64, orgid int64) (order []*models.SpSupplierWarehousingCancelOrder, err error) {
  566. db := XTReadDB().Model(&order).Where("status =1")
  567. if id > 0 {
  568. db = db.Where("warehouse_cancel_id = ?", id)
  569. }
  570. if orgid > 0 {
  571. db = db.Where("user_org_id = ?", orgid)
  572. }
  573. err = db.Find(&order).Error
  574. return order, err
  575. }
  576. func UpdateWarehouseCancelOrder(order *models.SpSupplierWarehousingCancelOrder) error {
  577. err = XTWriteDB().Model(&order).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
  578. return err
  579. }
  580. func UpdateWarehouseCancel(id int64, cancel models.SpSupplierWarehouseCancel) error {
  581. 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
  582. return err
  583. }
  584. func GetSupplyCancelOrderById(warehouse_out_id int64, orgid int64) (*models.SpSupplierWarehouseCancel, error) {
  585. cancel := models.SpSupplierWarehouseCancel{}
  586. var err error
  587. err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", warehouse_out_id, orgid).Find(&cancel).Error
  588. if err == gorm.ErrRecordNotFound {
  589. return nil, err
  590. }
  591. if err != nil {
  592. return nil, err
  593. }
  594. return &cancel, nil
  595. }
  596. func UpdateSupplyGoodOrder(id int64, out models.SpSupplierWarehouseOut) error {
  597. 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
  598. return err
  599. }
  600. func UpdateDrugSupplyWarehousingInfo(id int64, orgid int64) error {
  601. err := XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  602. return err
  603. }
  604. func UpdateDrugSupplyFlow(id int64, orgid int64) error {
  605. 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
  606. return err
  607. }
  608. func UpdateGoodSupplyWarehousingInfo(id int64, orgid int64) error {
  609. err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  610. return err
  611. }
  612. func UpdateGoodSupplyFlow(id int64, orgid int64) error {
  613. 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
  614. return err
  615. }
  616. func GetDrugSupplyWarehousingById(id int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
  617. err = XTReadDB().Where("supply_warehouse_id <> ? and org_id = ? and status = 1", id, orgid).Find(&info).Error
  618. return info, err
  619. }
  620. func UpdateSupplyWarehousing(id int64, orgid int64) error {
  621. err := XTWriteDB().Model(&models.DrugWarehouse{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  622. return err
  623. }
  624. func GetGoodSupplyWarehousingById(id int64, orgid int64) (info []*models.WarehousingInfo, err error) {
  625. err = XTReadDB().Where("supply_warehouse_id <> ? and org_id = ? and status = 1", id, orgid).Find(&info).Error
  626. return info, err
  627. }
  628. func UpdateGoodWarehousing(id int64, orgid int64) error {
  629. err := XTWriteDB().Model(&models.Warehousing{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  630. return err
  631. }
  632. func UpdateSupplyWarehousingById(id int64, orgid int64) error {
  633. err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and user_org_id =? and status = 1", id, orgid).Updates(map[string]interface{}{"is_warehouse": 1}).Error
  634. return err
  635. }
  636. func DeleteGoodOrder(id int64, orgid int64) error {
  637. err := XTWriteDB().Model(&models.SpSupplierWarehouseOut{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  638. 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
  639. return err
  640. }
  641. func GetSupplyCancelWarehouse(id int64, orgid int64) (cancel []*models.SpSupplierWarehouseCancel, err error) {
  642. err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&cancel).Error
  643. return cancel, err
  644. }
  645. func GetGoodOrderListById(id int64, orgid int64) (out []*models.VmSpSupplierWarehousingOutOrder, err error) {
  646. err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&out).Error
  647. return out, err
  648. }
  649. func GetGoodCanceListById(id int64, orgid int64) (cancel []*models.VmSpSupplierWarehousingCancelOrder, err error) {
  650. err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&cancel).Error
  651. return cancel, err
  652. }
  653. func CreateDrugFlowSix(drugflow []*models.DrugFlow) (err error) {
  654. if len(drugflow) > 0 {
  655. utx := writeDb.Begin()
  656. if len(drugflow) > 0 {
  657. thisSQL := "INSERT INTO xt_drug_flow (warehousing_id, drug_id, number,batch_number,count,user_org_id,patient_id,system_time,consumable_type,is_sys,warehousing_order,warehouse_out_id,warehouse_out_order_number,is_edit,cancel_stock_id,cancel_order_number,manufacturer,dealer,creator,update_creator,status,ctime,mtime,price,warehousing_detail_id,warehouse_out_detail_id,cancel_out_detail_id,expire_date,product_date,max_unit,min_unit,supply_warehouse_id,supply_warehouse_detail_info) VALUES "
  658. insertParams := make([]string, 0)
  659. insertData := make([]interface{}, 0)
  660. for _, info := range drugflow {
  661. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  662. insertData = append(insertData, info.WarehousingId)
  663. insertData = append(insertData, info.DrugId)
  664. insertData = append(insertData, info.Number)
  665. insertData = append(insertData, info.BatchNumber)
  666. insertData = append(insertData, info.Count)
  667. insertData = append(insertData, info.UserOrgId)
  668. insertData = append(insertData, info.PatientId)
  669. insertData = append(insertData, info.SystemTime)
  670. insertData = append(insertData, info.ConsumableType)
  671. insertData = append(insertData, info.IsSys)
  672. insertData = append(insertData, info.WarehousingOrder)
  673. insertData = append(insertData, info.WarehouseOutId)
  674. insertData = append(insertData, info.WarehouseOutOrderNumber)
  675. insertData = append(insertData, info.IsEdit)
  676. insertData = append(insertData, info.CancelStockId)
  677. insertData = append(insertData, info.CancelOrderNumber)
  678. insertData = append(insertData, info.Manufacturer)
  679. insertData = append(insertData, info.Dealer)
  680. insertData = append(insertData, info.Creator)
  681. insertData = append(insertData, info.UpdateCreator)
  682. insertData = append(insertData, info.Status)
  683. insertData = append(insertData, info.Ctime)
  684. insertData = append(insertData, info.Mtime)
  685. insertData = append(insertData, info.Price)
  686. insertData = append(insertData, info.WarehousingDetailId)
  687. insertData = append(insertData, info.WarehouseOutDetailId)
  688. insertData = append(insertData, info.CancelOutDetailId)
  689. insertData = append(insertData, info.ExpireDate)
  690. insertData = append(insertData, info.ProductDate)
  691. insertData = append(insertData, info.MaxUnit)
  692. insertData = append(insertData, info.MinUnit)
  693. insertData = append(insertData, info.SupplyWarehouseId)
  694. insertData = append(insertData, info.SupplyWarehouseDetailInfo)
  695. }
  696. thisSQL += strings.Join(insertParams, ", ")
  697. err = utx.Exec(thisSQL, insertData...).Error
  698. if err != nil {
  699. utx.Rollback()
  700. return
  701. }
  702. }
  703. utx.Commit()
  704. }
  705. return
  706. }
  707. func CheckReturnOrder(id int64, orgid int64, cancel models.SpSupplierWarehouseCancel) error {
  708. err := XTWriteDB().Model(&cancel).Where("id = ? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"is_check": cancel.IsCheck, "checker": cancel.Checker, "check_time": cancel.CheckTime}).Error
  709. return err
  710. }
  711. func GetSupplyCancelOrderDetail(id int64, orgid int64) (cancel []*models.SpSupplierWarehousingCancelOrder, err error) {
  712. err = XTReadDB().Where("warehouse_cancel_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&cancel).Error
  713. return cancel, err
  714. }
  715. func DeletePurchaseOrder(id int64) error {
  716. err := XTWriteDB().Model(&models.SupplierWarehousingInfoOrder{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  717. return err
  718. }
  719. func DeleteGoodOrderById(id int64) error {
  720. err := XTWriteDB().Model(&models.SpSupplierWarehousingOutOrder{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  721. return err
  722. }
  723. func GetlastWarehouseOutById(user_org_id int64, record_date int64) (models.WarehouseOut, error) {
  724. out := models.WarehouseOut{}
  725. err := XTReadDB().Where("org_id = ? and warehouse_out_time = ? and status = 1", user_org_id, record_date).Find(&out).Error
  726. return out, err
  727. }
  728. func GetDrugWarehouseOutById(orgid int64, record_date int64) (*models.DrugWarehouseOut, error) {
  729. out := models.DrugWarehouseOut{}
  730. var err error
  731. err = XTReadDB().Where("org_id = ? and warehouse_out_time = ?", orgid, record_date).Find(&out).Error
  732. if err == gorm.ErrRecordNotFound {
  733. return nil, err
  734. }
  735. if err != nil {
  736. return nil, err
  737. }
  738. return &out, nil
  739. }
  740. func GetLastDrugWarehouseById(orgid int64, record_date int64) (models.DrugWarehouseOut, error) {
  741. out := models.DrugWarehouseOut{}
  742. err := XTReadDB().Where("org_id = ? and warehouse_out_time =? and status = 1", orgid, record_date).Find(&out).Error
  743. return out, err
  744. }
  745. func UpdateSupplyCancelById(id int64, order models.SpSupplierWarehousingCancelOrder) error {
  746. err := XTReadDB().Model(&order).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"source_count": order.SourceCount}).Error
  747. return err
  748. }
  749. func DeleteReturnOrder(id int64) error {
  750. err := XTWriteDB().Model(&models.SpSupplierWarehouseCancel{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  751. err = XTWriteDB().Model(&models.SpSupplierWarehousingCancelOrder{}).Where("warehouse_cancel_id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  752. return err
  753. }
  754. func DeleteReturnOrderById(id int64) error {
  755. err = XTWriteDB().Model(&models.SpSupplierWarehousingCancelOrder{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  756. return err
  757. }
  758. func ModefyReturnOrder(id int64) error {
  759. cancel := models.SpSupplierWarehouseCancel{}
  760. err := XTWriteDB().Model(&cancel).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"is_check": 2, "checker": 0, "check_time": 0}).Error
  761. return err
  762. }
  763. func UpdateWarehousingInfoById(goodid int64, supply_warehouse_id int64, info models.WarehousingInfo) error {
  764. err := XTWriteDB().Model(&info).Where("good_id = ? and supply_warehouse_detail_info = ? and status = 1", goodid, supply_warehouse_id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", info.StockCount)).Error
  765. return err
  766. }
  767. func DeleteGoodWarehouseOut(goodid int64, supply_warehouse_id int64) error {
  768. err := XTWriteDB().Model(&models.WarehouseOutInfo{}).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).Updates(map[string]interface{}{"status": 0}).Error
  769. err = XTWriteDB().Model(&models.VmStockFlow{}).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).Updates(map[string]interface{}{"status": 0}).Error
  770. return err
  771. }
  772. func UpdateDrugWasehousring(goodid int64, supply_warehouse_id int64, info models.DrugWarehouseInfo) error {
  773. err := XTWriteDB().Model(&info).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", info.StockMaxNumber)).Error
  774. return err
  775. }
  776. func UpdateDrugWasehousringOne(goodid int64, supply_warehouse_id int64, info models.DrugWarehouseInfo) error {
  777. err := XTWriteDB().Model(&info).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number - ?", info.StockMinNumber)).Error
  778. return err
  779. }
  780. func DeleteDrugWarehouseOutNight(goodid int64, supply_warehouse_id int64) error {
  781. err := XTWriteDB().Model(&models.DrugWarehouseOutInfo{}).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).Updates(map[string]interface{}{"status": 0}).Error
  782. err = XTWriteDB().Model(&models.DrugFlow{}).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).Updates(map[string]interface{}{"status": 0}).Error
  783. return err
  784. }