new_stock_service.go 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. )
  6. func GetGoodStockCount(user_org_id int64, storehouse_id int64, good_id int64) (*models.XtGoodStockCount, error) {
  7. goodStock := models.XtGoodStockCount{}
  8. var err error
  9. err = XTReadDB().Where("user_org_id = ? and storehouse_id = ? and good_id = ?", user_org_id, storehouse_id, good_id).Find(&goodStock).Error
  10. if err == gorm.ErrRecordNotFound {
  11. return nil, err
  12. }
  13. if err != nil {
  14. return nil, err
  15. }
  16. return &goodStock, nil
  17. }
  18. func CreateGoodCount(good models.XtGoodStockCount) error {
  19. db := writeDb.Begin()
  20. err := db.Create(&good).Error
  21. if err != nil {
  22. db.Rollback()
  23. return err
  24. }
  25. db.Commit()
  26. return err
  27. }
  28. func UpdateGoodStockCount(user_org_id int64, storehouse_id int64, good_id int64, count int64, flush_count int64) error {
  29. db := writeDb.Begin()
  30. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count + ?", count)).Error
  31. if err != nil {
  32. db.Rollback()
  33. return err
  34. }
  35. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
  36. if err != nil {
  37. db.Rollback()
  38. return err
  39. }
  40. db.Commit()
  41. return err
  42. }
  43. func UpdateGoodInCount(count int64, user_org_id int64, good_id int64, storehouse_id int64, flush_count int64) error {
  44. db := writeDb.Begin()
  45. err := db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and good_id = ? and storehouse_id = ? and status = 1", user_org_id, good_id, storehouse_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count - ?", count)).Error
  46. if err != nil {
  47. db.Rollback()
  48. return err
  49. }
  50. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and good_id = ? and storehouse_id = ? and status = 1", user_org_id, good_id, storehouse_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
  51. if err != nil {
  52. db.Rollback()
  53. return err
  54. }
  55. db.Commit()
  56. return err
  57. }
  58. func CreateGoodErrcode(errcode models.XtGoodErrcode) error {
  59. db := writeDb.Begin()
  60. err := db.Create(&errcode).Error
  61. if err != nil {
  62. db.Rollback()
  63. return err
  64. }
  65. db.Commit()
  66. return err
  67. }
  68. func GetGoodStockList(orgId int64, storehouse_id int64, good_type int64, keyword string, page int64, limit int64, ids []int64) (good []*models.GoodInformation, total int64, err error) {
  69. offset := (page - 1) * limit
  70. likeKey := "%" + keyword + "%"
  71. db := XTReadDB().Table("xt_good_information as x").Where("x.status = 1 and x.org_id =? and find_in_set('停用',x.good_status) = 0", orgId)
  72. if good_type == 2 {
  73. db = db.Where(" x.total_count<=x.stock_warn_count")
  74. }
  75. if good_type == 3 {
  76. db = db.Where("x.sum_count = 0")
  77. }
  78. if good_type == 4 {
  79. db = db.Where("x.sum_count > 0")
  80. }
  81. if len(keyword) > 0 {
  82. db = db.Where("good_name like ? or manufacturer in(?)", likeKey, ids)
  83. }
  84. db = db.Preload("XtGoodStockCount", func(db *gorm.DB) *gorm.DB {
  85. if storehouse_id > 0 {
  86. db = db.Where("storehouse_id = ?", storehouse_id)
  87. }
  88. return db.Where("status = 1 and user_org_id = ?", orgId)
  89. })
  90. db = db.Preload("GoodStockCount", func(db *gorm.DB) *gorm.DB {
  91. if storehouse_id > 0 {
  92. db = db.Where("storehouse_id = ?", storehouse_id)
  93. }
  94. return db.Where("status = 1 and user_org_id = ?", orgId).Group("good_id,storehouse_id")
  95. })
  96. db = db.Preload("WarehousingInfo", func(db *gorm.DB) *gorm.DB {
  97. if storehouse_id > 0 {
  98. db = db.Where("storehouse_id = ?", storehouse_id)
  99. }
  100. return db.Where("status = 1 and org_id = ? and is_check = 1", orgId)
  101. })
  102. if orgId == 10489 {
  103. err = db.Count(&total).Offset(offset).Limit(limit).Order("x.sum_count desc").Find(&good).Error
  104. } else {
  105. err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Find(&good).Error
  106. }
  107. return good, total, err
  108. }
  109. func GetSumGoodList(orgid int64, storehouse_id int64, good_id int64) (info []*models.WarehousingInfo, err error) {
  110. err = XTReadDB().Where("org_id = ? and storehouse_id = ? and good_id = ? and status =1 and is_check = 1", orgid, storehouse_id, good_id).Find(&info).Error
  111. return info, err
  112. }
  113. func UpdateSumGood(orgid int64, storehouse_id int64, good_id int64, flush_count int64) error {
  114. db := writeDb.Begin()
  115. err := db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", orgid, storehouse_id, good_id).Updates(map[string]interface{}{"flush_count": flush_count}).Error
  116. if err != nil {
  117. db.Rollback()
  118. return err
  119. }
  120. db.Commit()
  121. return err
  122. }
  123. func UpdateSumCount(user_org_id int64, storehouse_id int64, good_id int64, count int64) error {
  124. ut := XTWriteDB().Begin()
  125. err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count - ?", count)).Error
  126. if err != nil {
  127. ut.Rollback()
  128. return err
  129. }
  130. ut.Commit()
  131. return err
  132. }
  133. func UpdateActSumCount(user_org_id int64, storehouse_id int64, good_id int64, count int64) error {
  134. ut := XTWriteDB().Begin()
  135. err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_act_out_count", gorm.Expr("stock_act_out_count - ?", count)).Error
  136. if err != nil {
  137. ut.Rollback()
  138. return err
  139. }
  140. ut.Commit()
  141. return err
  142. }
  143. func GetHisPrescriptionList(orgid int64) (project []*models.HisPrescriptionProject, err error) {
  144. err = XTReadDB().Where("user_org_id = ? and status= 1 and record_date =1690819200", orgid).Find(&project).Error
  145. return project, err
  146. }
  147. func UpdateGoodFlow(project_id int64, price float64) error {
  148. flow := models.VmStockFlow{}
  149. err := XTWriteDB().Model(&flow).Where("warehousing_id = ? and user_org_id =10265", project_id).Updates(map[string]interface{}{"price": price}).Error
  150. err = XTWriteDB().Model(models.WarehouseOutInfo{}).Where("warehouse_info_id = ? and org_id =10265", project_id).Updates(map[string]interface{}{"price": price}).Error
  151. return err
  152. }
  153. func GetSendGoodInformation(org_id int64) (info []*models.WarehousingInfo, err error) {
  154. err = XTReadDB().Where("org_id = ? and is_check = 1 and status = 1", org_id).Find(&info).Error
  155. return info, err
  156. }
  157. func GetStockFlush(storehouse_id int64, good_id int64, orgid int64) (*models.XtGoodStockCount, error) {
  158. stockCount := models.XtGoodStockCount{}
  159. var err error
  160. err = XTReadDB().Where("storehouse_id =? and good_id = ? and user_org_id = ?", storehouse_id, good_id, orgid).Find(&stockCount).Error
  161. if err == gorm.ErrRecordNotFound {
  162. return nil, err
  163. }
  164. if err != nil {
  165. return nil, err
  166. }
  167. return &stockCount, nil
  168. }
  169. func CreateGoodCountSix(good models.XtGoodStockCount) error {
  170. err := XTWriteDB().Create(&good).Error
  171. return err
  172. }
  173. func UpdateGoodCount(warehousingCount int64, stock_count int64, out_count int64, storehouse_id int64, good_id int64, orgid int64, cancel_count int64, act_count int64) error {
  174. err := XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count+?", warehousingCount)).Error
  175. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_out_count": out_count}).Error
  176. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).UpdateColumn("flush_count", gorm.Expr("flush_count + ?", stock_count)).Error
  177. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_cancel_count": cancel_count}).Error
  178. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_act_out_count": act_count}).Error
  179. return err
  180. }
  181. func UpdateGoodCountSend(warehousingCount int64, stock_count int64, out_count int64, storehouse_id int64, good_id int64, orgid int64, cancel_count int64, act_count int64) error {
  182. err := XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Updates(map[string]interface{}{"stock_in_count": warehousingCount}).Error
  183. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_out_count": out_count}).Error
  184. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"flush_count": stock_count}).Error
  185. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_cancel_count": cancel_count}).Error
  186. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_act_out_count": act_count}).Error
  187. return err
  188. }
  189. func GetAllCancelCount(storehouse_id int64, good_id int64, org_id int64) (flow []*models.VmStockFlow, err error) {
  190. err = XTReadDB().Where("storehouse_id = ? and good_id = ? and user_org_id = ? and (consumable_type = 4 or consumable_type= 7) and status = 1", storehouse_id, good_id, org_id).Find(&flow).Error
  191. return flow, err
  192. }
  193. func GetAllStockOutCount(storehouse_id int64, good_id int64, org_id int64) (flow []*models.VmStockFlow, err error) {
  194. err = XTReadDB().Where("storehouse_id = ? and good_id = ? and user_org_id = ? and (consumable_type = 2 or consumable_type= 3)", storehouse_id, good_id, org_id).Find(&flow).Error
  195. return flow, err
  196. }
  197. func GetActStockOutCount(storehouse_id int64, good_id int64, org_id int64) (flow []*models.VmStockFlow, err error) {
  198. err = XTReadDB().Where("storehouse_id = ? and good_id = ? and user_org_id = ? and (consumable_type = 2 or consumable_type= 3) and status = 1", storehouse_id, good_id, org_id).Find(&flow).Error
  199. return flow, err
  200. }
  201. func GetDrugStockCount(storehouse_id int64, drug_id int64, org_id int64) (*models.XtDrugStockCount, error) {
  202. drugStockCount := models.XtDrugStockCount{}
  203. var err error
  204. err = XTReadDB().Where("storehouse_id = ? and drug_id = ? and user_org_id = ? and status = 1", storehouse_id, drug_id, org_id).Find(&drugStockCount).Error
  205. if err == gorm.ErrRecordNotFound {
  206. return nil, err
  207. }
  208. if err != nil {
  209. return nil, err
  210. }
  211. return &drugStockCount, nil
  212. }
  213. func GetDrugStockCountSix(storehouse_id int64, drug_id int64, org_id int64) (models.XtDrugStockCount, error) {
  214. drugStockCount := models.XtDrugStockCount{}
  215. err = XTReadDB().Where("storehouse_id = ? and drug_id = ? and user_org_id = ? and status = 1", storehouse_id, drug_id, org_id).Find(&drugStockCount).Error
  216. return drugStockCount, err
  217. }
  218. func CreateDrugStockSum(drug models.XtDrugStockCount) error {
  219. ut := XTWriteDB().Begin()
  220. err := ut.Create(&drug).Error
  221. if err != nil {
  222. ut.Rollback()
  223. return err
  224. }
  225. ut.Commit()
  226. return err
  227. }
  228. func AddDrugStockSum(storehouse_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64) error {
  229. db := writeDb.Begin()
  230. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count + ?", waresing_count)).Error
  231. if err != nil {
  232. db.Rollback()
  233. return err
  234. }
  235. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
  236. if err != nil {
  237. db.Rollback()
  238. return err
  239. }
  240. db.Commit()
  241. return err
  242. }
  243. func UpdateDrugStockSum(storehouse_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64) error {
  244. db := writeDb.Begin()
  245. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"sum_in_count": waresing_count}).Error
  246. if err != nil {
  247. db.Rollback()
  248. return err
  249. }
  250. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
  251. if err != nil {
  252. db.Rollback()
  253. return err
  254. }
  255. db.Commit()
  256. return err
  257. }
  258. func ReduceDrugStockCount(storehouse_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64) error {
  259. db := writeDb.Begin()
  260. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count - ?", waresing_count)).Error
  261. if err != nil {
  262. db.Rollback()
  263. return err
  264. }
  265. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
  266. if err != nil {
  267. db.Rollback()
  268. return err
  269. }
  270. db.Commit()
  271. return err
  272. }
  273. func AddCancelSumCount(storehouse_id int64, drug_id int64, user_org_id int64, cancel_count int64, over_count int64) error {
  274. db := writeDb.Begin()
  275. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_cancel_count", gorm.Expr("sum_cancel_count + ?", cancel_count)).Error
  276. if err != nil {
  277. db.Rollback()
  278. return err
  279. }
  280. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
  281. if err != nil {
  282. db.Rollback()
  283. return err
  284. }
  285. db.Commit()
  286. return err
  287. }
  288. func AddCancelSumCountOne(storehouse_id int64, drug_id int64, user_org_id int64, cancel_count int64) error {
  289. db := writeDb.Begin()
  290. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_cancel_count", gorm.Expr("sum_cancel_count + ?", cancel_count)).Error
  291. if err != nil {
  292. db.Rollback()
  293. return err
  294. }
  295. db.Commit()
  296. return err
  297. }
  298. func ReduceCancelSumCount(storehouse_id int64, drug_id int64, user_org_id int64, cancel_count int64, over_count int64) error {
  299. db := writeDb.Begin()
  300. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_cancel_count", gorm.Expr("sum_cancel_count - ?", cancel_count)).Error
  301. if err != nil {
  302. db.Rollback()
  303. return err
  304. }
  305. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
  306. if err != nil {
  307. db.Rollback()
  308. return err
  309. }
  310. db.Commit()
  311. return err
  312. }
  313. func UpdateSumDrug(orgid int64, storehouse_id int64, drug_id int64, flush_count int64) error {
  314. db := writeDb.Begin()
  315. err := db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", orgid, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
  316. if err != nil {
  317. db.Rollback()
  318. return err
  319. }
  320. db.Commit()
  321. return err
  322. }
  323. func UpdateSumOutDrug(orgid int64, storehouse_id int64, drug_id int64, sum_out_count int64) error {
  324. db := writeDb.Begin()
  325. err := db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", orgid, storehouse_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count - ?", sum_out_count)).Error
  326. if err != nil {
  327. db.Rollback()
  328. return err
  329. }
  330. db.Commit()
  331. return err
  332. }
  333. func GetAutoGoodLastCount(goodid int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  334. detail := models.AutomaticReduceDetail{}
  335. err := XTReadDB().Where("good_id = ? and count = ? and record_time = ? and patient_id = ?", goodid, count, record_time, patient_id).Last(&detail).Error
  336. return detail, err
  337. }
  338. func UpdateLastAutoCount(id int64, count int64) error {
  339. detail := models.AutomaticReduceDetail{}
  340. err := XTWriteDB().Model(&detail).Where("id = ?", id).Update(map[string]interface{}{"count": count, "status": 1}).Error
  341. return err
  342. }
  343. func GetWareOutInfo(good_id int64, record_date int64, user_org_id int64, patient_id int64, order_id int64) (outinfo []*models.WarehouseOutInfo, err error) {
  344. err = XTReadDB().Where("good_id = ? and sys_record_time = ? and org_id = ? and status = 1 and patient_id = ? and order_id = ?", good_id, record_date, user_org_id, patient_id, order_id).Find(&outinfo).Error
  345. return outinfo, err
  346. }
  347. func AddGoodStockCount(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
  348. db := writeDb.Begin()
  349. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count + ?", count)).Error
  350. if err != nil {
  351. db.Rollback()
  352. return err
  353. }
  354. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("flush_count", gorm.Expr("flush_count + ?", count)).Error
  355. if err != nil {
  356. db.Rollback()
  357. return err
  358. }
  359. db.Commit()
  360. return err
  361. }
  362. func AddDrugStockCount(storehouse_id int64, drug_id int64, user_org_id int64, count int64) error {
  363. db := writeDb.Begin()
  364. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count + ?", count)).Error
  365. if err != nil {
  366. db.Rollback()
  367. return err
  368. }
  369. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("flush_count", gorm.Expr("flush_count + ?", count)).Error
  370. if err != nil {
  371. db.Rollback()
  372. return err
  373. }
  374. db.Commit()
  375. return err
  376. }
  377. func ReduceStockCount(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
  378. db := writeDb.Begin()
  379. //err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count - ?", count)).Error
  380. //if err != nil {
  381. // db.Rollback()
  382. // return err
  383. //}
  384. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count + ?", count)).Error
  385. if err != nil {
  386. db.Rollback()
  387. return err
  388. }
  389. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_act_out_count", gorm.Expr("stock_act_out_count + ?", count)).Error
  390. if err != nil {
  391. db.Rollback()
  392. return err
  393. }
  394. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("flush_count", gorm.Expr("flush_count - ?", count)).Error
  395. if err != nil {
  396. db.Rollback()
  397. return err
  398. }
  399. db.Commit()
  400. return err
  401. }
  402. func ReduceStockCountTwo(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
  403. db := writeDb.Begin()
  404. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count + ?", count)).Error
  405. if err != nil {
  406. db.Rollback()
  407. return err
  408. }
  409. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_act_out_count", gorm.Expr("stock_act_out_count + ?", count)).Error
  410. if err != nil {
  411. db.Rollback()
  412. return err
  413. }
  414. err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("flush_count", gorm.Expr("flush_count - ?", count)).Error
  415. if err != nil {
  416. db.Rollback()
  417. return err
  418. }
  419. db.Commit()
  420. return err
  421. }
  422. func ReduceDrugStockCountSix(storehouse_id int64, drug_id int64, user_org_id int64, count int64) error {
  423. db := writeDb.Begin()
  424. //err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count - ?", count)).Error
  425. //if err != nil {
  426. // db.Rollback()
  427. // return err
  428. //}
  429. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count + ?", count)).Error
  430. if err != nil {
  431. db.Rollback()
  432. return err
  433. }
  434. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count + ?", count)).Error
  435. if err != nil {
  436. db.Rollback()
  437. return err
  438. }
  439. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("flush_count", gorm.Expr("flush_count - ?", count)).Error
  440. if err != nil {
  441. db.Rollback()
  442. return err
  443. }
  444. db.Commit()
  445. return err
  446. }
  447. func ReduceDrugStockCountSeven(storehouse_id int64, drug_id int64, user_org_id int64, count int64) error {
  448. db := writeDb.Begin()
  449. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count + ?", count)).Error
  450. if err != nil {
  451. db.Rollback()
  452. return err
  453. }
  454. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count + ?", count)).Error
  455. if err != nil {
  456. db.Rollback()
  457. return err
  458. }
  459. err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("flush_count", gorm.Expr("flush_count - ?", count)).Error
  460. if err != nil {
  461. db.Rollback()
  462. return err
  463. }
  464. db.Commit()
  465. return err
  466. }
  467. func GetWarehouseOutInfoByProjectIdList(project_id int64, org_id int64, storehouse_id int64, good_id int64, patient_id int64, sys_record_time int64) (info []*models.WarehouseOutInfoNight, err error) {
  468. err = XTReadDB().Where("project_id = ? and org_id = ? and storehouse_id = ? and good_id = ? and patient_id = ? and sys_record_time = ? and status = 1", project_id, org_id, storehouse_id, good_id, patient_id, sys_record_time).Find(&info).Error
  469. return info, err
  470. }
  471. func GetWarehouseStockFlow(warehouse_info_id int64, good_id int64, user_org_id int64, patient_id int64, system_time int64) (models.VmStockFlow, error) {
  472. stockFlow := models.VmStockFlow{}
  473. err := XTReadDB().Where("warehousing_detail_id = ? and good_id = ? and user_org_id = ? and patient_id = ? AND consumable_type = 7 and system_time = ?", warehouse_info_id, good_id, user_org_id, patient_id, system_time).Find(&stockFlow).Error
  474. return stockFlow, err
  475. }
  476. func AddCountFlowOne(warehouse_info_id int64, good_id int64, user_org_id int64, patient_id int64, count int64, system_time int64, over_count int64) error {
  477. stockFlow := models.VmStockFlow{}
  478. err := XTWriteDB().Model(&stockFlow).Where("warehousing_detail_id = ? and good_id = ? and user_org_id = ? and patient_id = ? AND consumable_type = 7 and system_time = ?", warehouse_info_id, good_id, user_org_id, patient_id, system_time).UpdateColumn("count", gorm.Expr("count + ?", count)).Error
  479. err = XTWriteDB().Model(&stockFlow).Where("warehousing_detail_id = ? and good_id = ? and user_org_id = ? and patient_id = ? AND consumable_type = 7 and system_time = ?").Update(map[string]interface{}{"over_count": over_count}).Error
  480. return err
  481. }
  482. func GetWarehouseOutInfo(user_org_id int64) (info []*models.WarehouseOut, err error) {
  483. err = XTReadDB().Where("org_id = ? and status =1", 10485).Find(&info).Error
  484. return info, err
  485. }
  486. func UpdateWarehosueOutInfo(id int64, sys_record_time int64) (models.WarehouseOutInfo, error) {
  487. info := models.WarehouseOutInfo{}
  488. err := XTWriteDB().Model(&info).Where("warehouse_out_id = ? and org_id = ? ", id, 10485).Updates(map[string]interface{}{"sys_record_time": sys_record_time, "ctime": sys_record_time}).Error
  489. return info, err
  490. }