drug_stock_api_contorller.go 88KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. type StockDrugApiController struct {
  16. BaseAuthAPIController
  17. }
  18. func DrugStockManagerApiRegistRouters() {
  19. //入库管理和其他入库管理相关接口
  20. beego.Router("/api/drugwarehouse/create", &StockDrugApiController{}, "post:CreateDrugWarehouse")
  21. beego.Router("/api/drugwarehouse/list", &StockDrugApiController{}, "get:GetDrugWarehouseList")
  22. beego.Router("/api/drugwarehouse/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouse")
  23. beego.Router("/api/drugwarehouseinfo/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouseInfo")
  24. beego.Router("/api/drugwarehouseinfo/list", &StockDrugApiController{}, "get:GetDrugWarehouseInfoList")
  25. beego.Router("/api/drugwarehouse/edit", &StockDrugApiController{}, "post:EditDrugWarehouse")
  26. //退货管理和其他退货管理相关接口
  27. beego.Router("/api/drugsalesreturn/create", &StockDrugApiController{}, "post:CreateDrugSalesReturn")
  28. beego.Router("/api/drugsalesreturn/delete", &StockDrugApiController{}, "post:DeleteDrugSalesReturn")
  29. beego.Router("/api/drugsalesreturninfo/delete", &StockDrugApiController{}, "post:DeleteDrugSalesReturnInfo")
  30. beego.Router("/api/drugsalesreturninfo/list", &StockDrugApiController{}, "get:GetDrugSalesReturnInfoList")
  31. beego.Router("/api/drugsalesreturn/list", &StockDrugApiController{}, "get:GetDrugSalesReturnList")
  32. beego.Router("/api/drugsalesreturn/edit", &StockDrugApiController{}, "post:EditDrugReturnInfo")
  33. //出库管理和其他出库管理相关接口
  34. beego.Router("/api/drugwarehouseout/create", &StockDrugApiController{}, "post:CreateDrugWarehouseOut")
  35. beego.Router("/api/drugwarehouseout/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouseOut")
  36. beego.Router("/api/drugwarehouseoutinfo/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouseOutInfo")
  37. beego.Router("/api/drugwarehouseout/list", &StockDrugApiController{}, "get:GetDrugWarehouseOutList")
  38. beego.Router("/api/drugwarehouseout/edit", &StockDrugApiController{}, "post:EditDrugWarehouseOut")
  39. beego.Router("/api/drugwarehouseout/info", &StockDrugApiController{}, "get:GetDrugWarehouseOutInfoList")
  40. //出库退库管理和其他出库退库管理相关接口
  41. beego.Router("/api/drugcancelstock/create", &StockDrugApiController{}, "post:CreateDrugCancelStock")
  42. beego.Router("/api/drugcancelstock/list", &StockDrugApiController{}, "get:GetDrugCancelStockList")
  43. beego.Router("/api/drugcancelstock/info", &StockDrugApiController{}, "get:GetDrugCancelStockInfoList")
  44. beego.Router("/api/drugcancelstock/delete", &StockDrugApiController{}, "post:DeleteDrugCancelStock")
  45. beego.Router("/api/drugcancelstockinfo/delete", &StockDrugApiController{}, "post:DeleteDrugCancelStockInfo")
  46. beego.Router("/api/drugcancelstockinfo/edit", &StockDrugApiController{}, "post:EditDrugCancelStock")
  47. //beego.Router("/api/drugcancelstockinfo/config", &StockDrugApiController{}, "get:GetDrugCancelStockConfig")
  48. ////库存相关全局配置
  49. beego.Router("/api/drugstock/config", &StockDrugApiController{}, "get:GetAllConfig")
  50. //beego.Router("/api/drugreturn/config", &StockDrugApiController{}, "get:GetAllSalesReturnConfig")
  51. //
  52. ////库存查询
  53. beego.Router("/api/drugstock/query", &StockDrugApiController{}, "get:GetDrugQueryInfo")
  54. //
  55. //beego.Router("/api/drugstock/detail", &StockDrugApiController{}, "get:GetDetailInfo")
  56. //
  57. beego.Router("/api/drugwarehouseout/user", &StockDrugApiController{}, "get:GetUserDetailInfo")
  58. beego.Router("/api/drugstock/get", &StockDrugApiController{}, "get:GetAllDrugStock")
  59. beego.Router("/api/drug/getcanceldrugorderprint", &StockDrugApiController{}, "get:GetCancelDrugOrderPrint")
  60. beego.Router("/api/drug/drugcancelexportlist", &StockDrugApiController{}, "get:GetDrugCancelExportList")
  61. }
  62. func (c *StockDrugApiController) CreateDrugWarehouse() {
  63. warehousing_time := c.GetString("warehousing_time")
  64. types, _ := c.GetInt64("type", 0)
  65. ctime := time.Now().Unix()
  66. adminUserInfo := c.GetAdminUserInfo()
  67. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  68. if parseDateErr != nil {
  69. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  70. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  71. return
  72. }
  73. timeStr := time.Now().Format("2006-01-02")
  74. timeArr := strings.Split(timeStr, "-")
  75. total, _ := service.FindAllWarehouseTotalOne(adminUserInfo.CurrentOrgId)
  76. total = total + 1
  77. fmt.Println("total2323232323232", total)
  78. warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  79. fmt.Println("r入库单据好 2323232322223", warehousing_order)
  80. operation_time := time.Now().Unix()
  81. creater := adminUserInfo.AdminUser.Id
  82. warehousing := models.DrugWarehouse{
  83. WarehousingOrder: warehousing_order,
  84. OperationTime: operation_time,
  85. OrgId: adminUserInfo.CurrentOrgId,
  86. Creater: creater,
  87. Ctime: ctime,
  88. Status: 1,
  89. WarehousingTime: warehousingDate.Unix(),
  90. Type: types,
  91. }
  92. service.AddSigleDrugWarehouse(&warehousing)
  93. dataBody := make(map[string]interface{}, 0)
  94. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  95. if err != nil {
  96. utils.ErrorLog(err.Error())
  97. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  98. return
  99. }
  100. var warehousingInfo []*models.DrugWarehouseInfo
  101. var drugFlow []*models.DrugFlow
  102. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  103. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  104. if len(thisStockIn) > 0 {
  105. for _, item := range thisStockIn {
  106. items := item.(map[string]interface{})
  107. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  108. utils.ErrorLog("drug_id")
  109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  110. return
  111. }
  112. drug_id := int64(items["drug_id"].(float64))
  113. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  114. utils.ErrorLog("warehousing_count")
  115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  116. return
  117. }
  118. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  119. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  120. utils.ErrorLog("last_price")
  121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  122. return
  123. }
  124. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  125. total := float64(warehousing_count) * last_price
  126. retail_price_total := float64(warehousing_count) * last_price
  127. var productDates int64
  128. var expiryDates int64
  129. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  130. expiryDates = 0
  131. } else {
  132. if len(items["expiry_date"].(string)) == 0 {
  133. expiryDates = 0
  134. } else {
  135. expiryDate, _ := items["expiry_date"].(string)
  136. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  137. expiryDates = expiry_date.Unix()
  138. }
  139. }
  140. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  141. productDates = 0
  142. } else {
  143. if len(items["product_date"].(string)) == 0 {
  144. productDates = 0
  145. } else {
  146. productDate, _ := items["product_date"].(string)
  147. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  148. productDates = product_date.Unix()
  149. }
  150. }
  151. number, _ := items["number"].(string)
  152. batch_number, _ := items["batch_number"].(string)
  153. if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
  154. utils.ErrorLog("max_unit")
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  156. return
  157. }
  158. max_unit, _ := items["max_unit"].(string)
  159. if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
  160. utils.ErrorLog("min_unit")
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  162. return
  163. }
  164. min_unit, _ := items["min_unit"].(string)
  165. var remark string
  166. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  167. remark = ""
  168. } else {
  169. remark = items["remark"].(string)
  170. }
  171. manufacturer := int64(items["manufacturer"].(float64))
  172. dealer := int64(items["dealer"].(float64))
  173. warehouseInfo := &models.DrugWarehouseInfo{
  174. WarehousingOrder: warehousing.WarehousingOrder,
  175. WarehousingId: warehousing.ID,
  176. DrugId: drug_id,
  177. Number: number,
  178. ProductDate: productDates,
  179. ExpiryDate: expiryDates,
  180. WarehousingCount: warehousing_count,
  181. Price: last_price,
  182. TotalPrice: total,
  183. Status: 1,
  184. Ctime: ctime,
  185. Remark: remark,
  186. OrgId: adminUserInfo.CurrentOrgId,
  187. Type: types,
  188. Manufacturer: manufacturer,
  189. Dealer: dealer,
  190. StockMaxNumber: warehousing_count,
  191. RetailTotalPrice: retail_price_total,
  192. BatchNumber: batch_number,
  193. MaxUnit: max_unit,
  194. MinUnit: min_unit,
  195. }
  196. warehousingInfo = append(warehousingInfo, warehouseInfo)
  197. drugflow := &models.DrugFlow{
  198. WarehousingOrder: warehousing.WarehousingOrder,
  199. WarehousingId: warehousing.ID,
  200. DrugId: drug_id,
  201. Number: number,
  202. ProductDate: productDates,
  203. ExpireDate: expiryDates,
  204. Count: warehousing_count,
  205. Price: last_price,
  206. Status: 1,
  207. Ctime: ctime,
  208. UserOrgId: adminUserInfo.CurrentOrgId,
  209. Manufacturer: manufacturer,
  210. Dealer: dealer,
  211. BatchNumber: batch_number,
  212. MaxUnit: max_unit,
  213. MinUnit: min_unit,
  214. ConsumableType: 1,
  215. IsEdit: 1,
  216. Creator: adminUserInfo.AdminUser.Id,
  217. IsSys: 0,
  218. }
  219. drugFlow = append(drugFlow, drugflow)
  220. }
  221. }
  222. }
  223. //创建入库单
  224. errs := service.CreateDrugWarehousingInfo(warehousingInfo)
  225. if errs == nil {
  226. //更改库存
  227. service.UpdateDrugInfo(warehousingInfo)
  228. }
  229. //创建流水单
  230. service.CreateDrugFlow(drugFlow)
  231. info, _ := service.FindLastDrugWarehousingInfo(warehousing.WarehousingOrder)
  232. if errs != nil {
  233. utils.ErrorLog(errs.Error())
  234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  235. return
  236. }
  237. c.ServeSuccessJSON(map[string]interface{}{
  238. "msg": "入库成功",
  239. "warehousing_order": warehousing_order,
  240. "info": info,
  241. })
  242. }
  243. func (c *StockDrugApiController) GetDrugWarehouseList() {
  244. page, _ := c.GetInt64("page", -1)
  245. limit, _ := c.GetInt64("limit", -1)
  246. start_time := c.GetString("start_time")
  247. end_time := c.GetString("end_time")
  248. types, _ := c.GetInt64("type", 0)
  249. keywords := c.GetString("keywords")
  250. timeLayout := "2006-01-02"
  251. loc, _ := time.LoadLocation("Local")
  252. var startTime int64
  253. if len(start_time) > 0 {
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  255. if err != nil {
  256. fmt.Println(err)
  257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  258. return
  259. }
  260. startTime = theTime.Unix()
  261. }
  262. var endTime int64
  263. if len(end_time) > 0 {
  264. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  265. if err != nil {
  266. utils.ErrorLog(err.Error())
  267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  268. return
  269. }
  270. endTime = theTime.Unix()
  271. }
  272. adminUserInfo := c.GetAdminUserInfo()
  273. fmt.Println("hhh2h3h23h2h32h3h2h32h32h3h2h3", keywords)
  274. //按药品名称搜索
  275. var ids []int64
  276. var idArray []int64
  277. list, _ := service.GetDrugNameByKeyword(keywords, adminUserInfo.CurrentOrgId)
  278. for _, item := range list {
  279. ids = append(ids, item.ID)
  280. }
  281. //查找入库单详情
  282. if len(ids) > 0 {
  283. info, _ := service.GetDrugWarehouseOrderDetailTwo(ids, adminUserInfo.CurrentOrgId, startTime, endTime)
  284. for _, it := range info {
  285. idArray = append(idArray, it.WarehousingId)
  286. }
  287. }
  288. warehouseList, total, err := service.FindAllDrugWarehousingListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, idArray)
  289. if err == nil {
  290. c.ServeSuccessJSON(map[string]interface{}{
  291. "list": warehouseList,
  292. "total": total,
  293. })
  294. } else {
  295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  296. }
  297. }
  298. func (c *StockDrugApiController) GetDrugWarehouseInfoList() {
  299. id, _ := c.GetInt64("id", 0)
  300. if id <= 0 {
  301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  302. return
  303. }
  304. admin := c.GetAdminUserInfo()
  305. warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId)
  306. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  307. dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId)
  308. if err != nil {
  309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  310. return
  311. }
  312. if warehousing.ID <= 0 {
  313. return
  314. }
  315. warehousingInfo, err := service.FindDrugWarehousingInfoById(id, admin.CurrentOrgId)
  316. fmt.Println("warehousinginfo000000000000000", warehousingInfo)
  317. if err == nil {
  318. c.ServeSuccessJSON(map[string]interface{}{
  319. "info": warehousingInfo,
  320. "warehousing": warehousing,
  321. "manufacturerList": manufacturerList,
  322. "dealerList": dealerList,
  323. })
  324. } else {
  325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  326. }
  327. }
  328. func (c *StockDrugApiController) EditDrugWarehouse() {
  329. warehousing_time := c.GetString("warehousing_time")
  330. id, _ := c.GetInt64("id", 0)
  331. types, _ := c.GetInt64("type", 0)
  332. if id == 0 {
  333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  334. return
  335. }
  336. ctime := time.Now().Unix()
  337. mtime := time.Now().Unix()
  338. adminUserInfo := c.GetAdminUserInfo()
  339. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  340. if parseDateErr != nil {
  341. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  343. return
  344. }
  345. warehouse, _ := service.FindDrugWarehousingById(id, adminUserInfo.CurrentOrgId)
  346. warehousing := models.DrugWarehouse{
  347. WarehousingOrder: warehouse.WarehousingOrder,
  348. OrgId: adminUserInfo.CurrentOrgId,
  349. Modifier: adminUserInfo.AdminUser.Id,
  350. Mtime: mtime,
  351. Status: 1,
  352. WarehousingTime: warehousingDate.Unix(),
  353. Type: warehouse.Type,
  354. }
  355. service.EditDrugWarehousingOne(warehousing, id)
  356. dataBody := make(map[string]interface{}, 0)
  357. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  358. if err != nil {
  359. utils.ErrorLog(err.Error())
  360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  361. return
  362. }
  363. var warehousingInfo []*models.DrugWarehouseInfo
  364. var upDateWarehousingInfo []*models.DrugWarehouseInfo
  365. var drugFlow []*models.DrugFlow
  366. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  367. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  368. if len(thisStockIn) > 0 {
  369. for _, item := range thisStockIn {
  370. items := item.(map[string]interface{})
  371. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  372. utils.ErrorLog("drug_id")
  373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  374. return
  375. }
  376. drug_id := int64(items["drug_id"].(float64))
  377. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  378. utils.ErrorLog("warehousing_count")
  379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  380. return
  381. }
  382. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  383. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  384. utils.ErrorLog("price")
  385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  386. return
  387. }
  388. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  389. total := float64(warehousing_count) * price
  390. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  391. utils.ErrorLog("last_price")
  392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  393. return
  394. }
  395. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  396. retail_price_total := float64(warehousing_count) * last_price
  397. var productDates int64
  398. var expiryDates int64
  399. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  400. expiryDates = 0
  401. } else {
  402. if len(items["expiry_date"].(string)) == 0 {
  403. expiryDates = 0
  404. } else {
  405. expiryDate, _ := items["expiry_date"].(string)
  406. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  407. expiryDates = expiry_date.Unix()
  408. }
  409. }
  410. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  411. productDates = 0
  412. } else {
  413. if len(items["product_date"].(string)) == 0 {
  414. productDates = 0
  415. } else {
  416. productDate, _ := items["product_date"].(string)
  417. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  418. productDates = product_date.Unix()
  419. }
  420. }
  421. number, _ := items["number"].(string)
  422. batch_number, _ := items["batch_number"].(string)
  423. max_unit, _ := items["max_unit"].(string)
  424. min_unit, _ := items["min_unit"].(string)
  425. var remark string
  426. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  427. remark = ""
  428. } else {
  429. remark = items["remark"].(string)
  430. }
  431. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  432. utils.ErrorLog("id")
  433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  434. return
  435. }
  436. id := int64(items["id"].(float64))
  437. manufacturer := int64(items["manufacturer"].(float64))
  438. dealer := int64(items["dealer"].(float64))
  439. if id == 0 {
  440. warehouseInfo := &models.DrugWarehouseInfo{
  441. WarehousingOrder: warehouse.WarehousingOrder,
  442. WarehousingId: warehouse.ID,
  443. DrugId: drug_id,
  444. Number: number,
  445. ProductDate: productDates,
  446. ExpiryDate: expiryDates,
  447. WarehousingCount: warehousing_count,
  448. Price: price,
  449. TotalPrice: total,
  450. Status: 1,
  451. Ctime: ctime,
  452. Remark: remark,
  453. OrgId: adminUserInfo.CurrentOrgId,
  454. Type: types,
  455. Manufacturer: manufacturer,
  456. Dealer: dealer,
  457. RetailPrice: last_price,
  458. RetailTotalPrice: retail_price_total,
  459. BatchNumber: batch_number,
  460. MaxUnit: max_unit,
  461. MinUnit: min_unit,
  462. }
  463. warehousingInfo = append(warehousingInfo, warehouseInfo)
  464. } else {
  465. warehouseInfo := &models.DrugWarehouseInfo{
  466. ID: id,
  467. WarehousingOrder: warehouse.WarehousingOrder,
  468. WarehousingId: warehouse.ID,
  469. DrugId: drug_id,
  470. Number: number,
  471. ProductDate: productDates,
  472. ExpiryDate: expiryDates,
  473. WarehousingCount: warehousing_count,
  474. Price: price,
  475. TotalPrice: total,
  476. Status: 1,
  477. Ctime: ctime,
  478. Remark: remark,
  479. OrgId: adminUserInfo.CurrentOrgId,
  480. Type: types,
  481. Manufacturer: manufacturer,
  482. Dealer: dealer,
  483. RetailPrice: last_price,
  484. RetailTotalPrice: retail_price_total,
  485. StockMaxNumber: warehousing_count,
  486. MaxUnit: max_unit,
  487. MinUnit: min_unit,
  488. BatchNumber: batch_number,
  489. }
  490. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  491. drugflow := &models.DrugFlow{
  492. WarehousingOrder: warehousing.WarehousingOrder,
  493. WarehousingId: warehousing.ID,
  494. DrugId: drug_id,
  495. Number: number,
  496. ProductDate: productDates,
  497. ExpireDate: expiryDates,
  498. Count: warehousing_count,
  499. Price: last_price,
  500. Status: 1,
  501. Ctime: ctime,
  502. UserOrgId: adminUserInfo.CurrentOrgId,
  503. Manufacturer: manufacturer,
  504. Dealer: dealer,
  505. BatchNumber: batch_number,
  506. MaxUnit: max_unit,
  507. MinUnit: min_unit,
  508. ConsumableType: 1,
  509. IsEdit: 1,
  510. Creator: adminUserInfo.AdminUser.Id,
  511. IsSys: 0,
  512. }
  513. drugFlow = append(drugFlow, drugflow)
  514. }
  515. }
  516. }
  517. }
  518. var errs error
  519. if len(warehousingInfo) > 0 {
  520. errs = service.CreateDrugWarehousingInfo(warehousingInfo)
  521. if errs == nil {
  522. service.CreateDrugFlow(drugFlow)
  523. //更改库存
  524. service.UpdateDrugInfo(warehousingInfo)
  525. }
  526. }
  527. if len(upDateWarehousingInfo) > 0 {
  528. var total int64
  529. var minNumber float64
  530. var allTotal int64
  531. for _, item := range upDateWarehousingInfo {
  532. //查询修改的记录
  533. orderInfo, _ := service.GetDrugWarehouseOrderOne(id, item.DrugId)
  534. info, _ := service.FindeDrugInfo(item.DrugId)
  535. total = orderInfo.StockMaxNumber * info.MinNumber
  536. allTotal = item.WarehousingCount*info.MinNumber - total
  537. str := strconv.FormatInt(allTotal, 10)
  538. minFloat, _ := strconv.ParseFloat(str, 64)
  539. minNumber = info.Total + minFloat
  540. lib := models.BaseDrugLib{
  541. Total: minNumber,
  542. }
  543. service.UpdateBaseDrug(&lib, item.DrugId)
  544. errs = service.UpDateDrugWarehousingInfo(item)
  545. service.CreateDrugFlow(drugFlow)
  546. }
  547. }
  548. if errs != nil {
  549. utils.ErrorLog(errs.Error())
  550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  551. return
  552. }
  553. c.ServeSuccessJSON(map[string]interface{}{
  554. "msg": "编辑成功",
  555. })
  556. }
  557. func (c *StockDrugApiController) DeleteDrugWarehouse() {
  558. ids := c.GetString("ids")
  559. if len(ids) == 0 {
  560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  561. return
  562. }
  563. idArray := strings.Split(ids, ",")
  564. err := service.DeleteDrugWarehouse(idArray)
  565. if err != nil {
  566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  567. } else {
  568. c.ServeSuccessJSON(map[string]interface{}{
  569. "msg": "删除成功",
  570. })
  571. }
  572. }
  573. func (c *StockDrugApiController) DeleteDrugWarehouseInfo() {
  574. id, _ := c.GetInt64("id", 0)
  575. if id == 0 {
  576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  577. return
  578. }
  579. err := service.UpDateDrugWarehouseStatus(id)
  580. if err != nil {
  581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  582. } else {
  583. c.ServeSuccessJSON(map[string]interface{}{
  584. "msg": "删除成功",
  585. })
  586. }
  587. }
  588. func (c *StockDrugApiController) CreateDrugSalesReturn() {
  589. dealer_id, _ := c.GetInt64("dealer_id", 0)
  590. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  591. sales_return_time := c.GetString("time")
  592. types, _ := c.GetInt64("type", 0)
  593. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  594. if parseDateErr != nil {
  595. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  597. return
  598. }
  599. adminUserInfo := c.GetAdminUserInfo()
  600. operation_time := time.Now().Unix()
  601. creater := adminUserInfo.AdminUser.Id
  602. ctime := time.Now().Unix()
  603. timeStr := time.Now().Format("2006-01-02")
  604. timeArr := strings.Split(timeStr, "-")
  605. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  606. total = total + 1
  607. orderNumber := "YPTHD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  608. salesReturn := models.DrugSalesReturn{
  609. OrderNumber: orderNumber,
  610. OperaTime: operation_time,
  611. OrgId: adminUserInfo.CurrentOrgId,
  612. Creater: creater,
  613. Ctime: ctime,
  614. Status: 1,
  615. ReturnTime: salesReturnDate.Unix(),
  616. Dealer: dealer_id,
  617. Manufacturer: manufacturer_id,
  618. Type: types,
  619. }
  620. service.AddSigleDrugSalesReturn(&salesReturn)
  621. dataBody := make(map[string]interface{}, 0)
  622. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  623. if err != nil {
  624. utils.ErrorLog(err.Error())
  625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  626. return
  627. }
  628. var salesReturnInfos []*models.DrugSalesReturnInfo
  629. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  630. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  631. if len(thisStockIn) > 0 {
  632. for _, item := range thisStockIn {
  633. items := item.(map[string]interface{})
  634. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  635. utils.ErrorLog("drug_id")
  636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  637. return
  638. }
  639. drug_id := int64(items["drug_id"].(float64))
  640. return_count, _ := items["return_count"].(string)
  641. if len(return_count) == 0 {
  642. utils.ErrorLog("len(return_count) == 0")
  643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  644. return
  645. }
  646. count, _ := strconv.ParseInt(return_count, 10, 64)
  647. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  648. utils.ErrorLog("price")
  649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  650. return
  651. }
  652. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  653. total := float64(count) * price
  654. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  655. utils.ErrorLog("retail_price")
  656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  657. return
  658. }
  659. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  660. retail_price_total := float64(count) * retail_price
  661. salesReturnInfo := &models.DrugSalesReturnInfo{
  662. OrderNumber: salesReturn.OrderNumber,
  663. SalesReturnId: salesReturn.ID,
  664. DrugId: drug_id,
  665. Count: count,
  666. Price: price,
  667. Total: total,
  668. Status: 1,
  669. Ctime: ctime,
  670. OrgId: adminUserInfo.CurrentOrgId,
  671. Type: types,
  672. Manufacturer: manufacturer_id,
  673. Dealer: dealer_id,
  674. RetailPrice: retail_price,
  675. RetailTotalPrice: retail_price_total,
  676. }
  677. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  678. }
  679. }
  680. }
  681. errs := service.CreateDrugSalesReturnInfo(salesReturnInfos)
  682. if errs != nil {
  683. utils.ErrorLog(errs.Error())
  684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateReturnFail)
  685. return
  686. }
  687. c.ServeSuccessJSON(map[string]interface{}{
  688. "msg": "退货成功",
  689. })
  690. }
  691. func (c *StockDrugApiController) GetDrugSalesReturnList() {
  692. page, _ := c.GetInt64("page", -1)
  693. limit, _ := c.GetInt64("limit", -1)
  694. start_time := c.GetString("start_time")
  695. end_time := c.GetString("end_time")
  696. types, _ := c.GetInt64("type", 0)
  697. keywords := c.GetString("keywords")
  698. timeLayout := "2006-01-02"
  699. loc, _ := time.LoadLocation("Local")
  700. var startTime int64
  701. if len(start_time) > 0 {
  702. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  703. if err != nil {
  704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  705. return
  706. }
  707. startTime = theTime.Unix()
  708. }
  709. var endTime int64
  710. if len(end_time) > 0 {
  711. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  712. if err != nil {
  713. utils.ErrorLog(err.Error())
  714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  715. return
  716. }
  717. endTime = theTime.Unix()
  718. }
  719. adminUserInfo := c.GetAdminUserInfo()
  720. returnList, total, err := service.FindAllDrugReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  721. if err == nil {
  722. c.ServeSuccessJSON(map[string]interface{}{
  723. "list": returnList,
  724. "total": total,
  725. })
  726. } else {
  727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  728. }
  729. }
  730. func (this *StockDrugApiController) DeleteDrugSalesReturn() {
  731. ids := this.GetString("ids")
  732. if len(ids) == 0 {
  733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  734. return
  735. }
  736. idArray := strings.Split(ids, ",")
  737. err := service.DeleteDrugSalesReturn(idArray)
  738. if err != nil {
  739. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  740. } else {
  741. this.ServeSuccessJSON(map[string]interface{}{
  742. "msg": "删除成功",
  743. })
  744. }
  745. }
  746. func (this *StockDrugApiController) DeleteDrugSalesReturnInfo() {
  747. id, _ := this.GetInt64("id", 0)
  748. fmt.Println(id)
  749. if id == 0 {
  750. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  751. return
  752. }
  753. err := service.UpDateDrugSaleReturnStatus(id)
  754. if err != nil {
  755. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  756. } else {
  757. this.ServeSuccessJSON(map[string]interface{}{
  758. "msg": "删除成功",
  759. })
  760. }
  761. }
  762. func (this *StockDrugApiController) GetDrugSalesReturnInfoList() {
  763. id, _ := this.GetInt64("id", 0)
  764. adminUserInfo := this.GetAdminUserInfo()
  765. list, _ := service.FindAllDrugSalesReturnInfoById(id, adminUserInfo.CurrentOrgId)
  766. salesReturn, _ := service.FindAllDrugSalesReturnById(id, adminUserInfo.CurrentOrgId)
  767. this.ServeSuccessJSON(map[string]interface{}{
  768. "list": list,
  769. "salesReturn": salesReturn,
  770. })
  771. }
  772. func (c *StockDrugApiController) EditDrugReturnInfo() {
  773. return_time := c.GetString("return_time")
  774. id, _ := c.GetInt64("id", 0)
  775. types, _ := c.GetInt64("type", 0)
  776. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  777. dealer_id, _ := c.GetInt64("dealer_id", 0)
  778. if id == 0 {
  779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  780. return
  781. }
  782. ctime := time.Now().Unix()
  783. mtime := time.Now().Unix()
  784. adminUserInfo := c.GetAdminUserInfo()
  785. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  786. if parseDateErr != nil {
  787. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  789. return
  790. }
  791. salesReturns, _ := service.FindDrugSalesReturnById(id)
  792. sales := models.DrugSalesReturn{
  793. ID: salesReturns.ID,
  794. Mtime: mtime,
  795. ReturnTime: returnDate.Unix(),
  796. Manufacturer: manufacturer_id,
  797. Dealer: dealer_id,
  798. }
  799. service.EditDrugSaleReturn(sales)
  800. dataBody := make(map[string]interface{}, 0)
  801. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  802. if err != nil {
  803. utils.ErrorLog(err.Error())
  804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  805. return
  806. }
  807. var returnInfos []*models.DrugSalesReturnInfo
  808. var upDateReturnInfos []*models.DrugSalesReturnInfo
  809. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  810. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  811. if len(thisStockIn) > 0 {
  812. for _, item := range thisStockIn {
  813. items := item.(map[string]interface{})
  814. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  815. utils.ErrorLog("drug_id")
  816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  817. return
  818. }
  819. drug_id := int64(items["drug_id"].(float64))
  820. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  821. utils.ErrorLog("count")
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  826. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  827. utils.ErrorLog("id")
  828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  829. return
  830. }
  831. id := int64(items["id"].(float64))
  832. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  833. utils.ErrorLog("price")
  834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  835. return
  836. }
  837. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  838. total := float64(count) * price
  839. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  840. utils.ErrorLog("retail_price")
  841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  842. return
  843. }
  844. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  845. retail_price_total := float64(count) * retail_price
  846. if id == 0 {
  847. returnInfo := &models.DrugSalesReturnInfo{
  848. DrugId: drug_id,
  849. Count: count,
  850. Status: 1,
  851. Ctime: ctime,
  852. OrgId: adminUserInfo.CurrentOrgId,
  853. OrderNumber: sales.OrderNumber,
  854. SalesReturnId: sales.ID,
  855. Mtime: time.Now().Unix(),
  856. Type: types,
  857. Manufacturer: manufacturer_id,
  858. Dealer: dealer_id,
  859. RetailPrice: retail_price,
  860. RetailTotalPrice: retail_price_total,
  861. Total: total,
  862. Price: price,
  863. }
  864. returnInfos = append(returnInfos, returnInfo)
  865. } else {
  866. returnInfo := &models.DrugSalesReturnInfo{
  867. ID: id,
  868. DrugId: drug_id,
  869. Count: count,
  870. Status: 1,
  871. Ctime: ctime,
  872. OrgId: adminUserInfo.CurrentOrgId,
  873. OrderNumber: sales.OrderNumber,
  874. SalesReturnId: sales.ID,
  875. Mtime: time.Now().Unix(),
  876. Type: types,
  877. Manufacturer: manufacturer_id,
  878. Dealer: dealer_id,
  879. RetailPrice: retail_price,
  880. RetailTotalPrice: retail_price_total,
  881. Total: total,
  882. Price: price,
  883. }
  884. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  885. }
  886. }
  887. }
  888. }
  889. var errs error
  890. if len(returnInfos) > 0 {
  891. errs = service.CreateDrugSalesReturnInfo(returnInfos)
  892. }
  893. if len(upDateReturnInfos) > 0 {
  894. for _, item := range upDateReturnInfos {
  895. errs = service.UpDateDrugSalesReturnInfo(item)
  896. }
  897. }
  898. if errs != nil {
  899. utils.ErrorLog(errs.Error())
  900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateReturnFail)
  901. return
  902. }
  903. c.ServeSuccessJSON(map[string]interface{}{
  904. "msg": "编辑成功",
  905. })
  906. }
  907. func (c *StockDrugApiController) CreateDrugWarehouseOut() {
  908. types, _ := c.GetInt64("type", 0)
  909. ctime := time.Now().Unix()
  910. adminUserInfo := c.GetAdminUserInfo()
  911. warehousing_out_time := c.GetString("warehousing_out_time")
  912. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  913. if parseDateErr != nil {
  914. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  916. return
  917. }
  918. timeStr := time.Now().Format("2006-01-02")
  919. timeArr := strings.Split(timeStr, "-")
  920. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  921. total = total + 1
  922. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  923. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  924. number = number + total
  925. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  926. operation_time := time.Now().Unix()
  927. creater := adminUserInfo.AdminUser.Id
  928. warehouseOut := models.DrugWarehouseOut{
  929. WarehouseOutOrderNumber: warehousing_out_order,
  930. OperationTime: operation_time,
  931. OrgId: adminUserInfo.CurrentOrgId,
  932. Creater: creater,
  933. Ctime: ctime,
  934. Status: 1,
  935. WarehouseOutTime: warehousingOutDate.Unix(),
  936. Type: types,
  937. }
  938. dataBody := make(map[string]interface{}, 0)
  939. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  940. if err != nil {
  941. utils.ErrorLog(err.Error())
  942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  943. return
  944. }
  945. var warehousingOutInfo []*models.DrugWarehouseOutInfo
  946. var drugFlow []*models.DrugFlow
  947. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  948. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  949. if len(thisStockIn) > 0 {
  950. for _, item := range thisStockIn {
  951. items := item.(map[string]interface{})
  952. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  953. utils.ErrorLog("drug_id")
  954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  955. return
  956. }
  957. drug_id := int64(items["drug_id"].(float64))
  958. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  959. utils.ErrorLog("count")
  960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  961. return
  962. }
  963. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  964. utils.ErrorLog("price")
  965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  966. return
  967. }
  968. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  969. //if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  970. // utils.ErrorLog("last_price")
  971. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  972. // return
  973. //}
  974. //last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  975. //fmt.Println(last_price)
  976. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  977. total := float64(count) * price
  978. retail_price_total := float64(count) * price
  979. remark := items["remark"].(string)
  980. max_unit := items["max_unit"].(string)
  981. dealer := int64(items["dealer"].(float64))
  982. fmt.Println("dealer2222222222222222222", dealer)
  983. manufacturer := int64(items["manufacturer"].(float64))
  984. fmt.Println("manufacturer22222222222222", manufacturer)
  985. number := items["number"].(string)
  986. batch_number := items["batch_number"].(string)
  987. var productDates int64
  988. var expiryDates int64
  989. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  990. expiryDates = 0
  991. } else {
  992. if len(items["expiry_date"].(string)) == 0 {
  993. expiryDates = 0
  994. } else {
  995. expiryDate, _ := items["expiry_date"].(string)
  996. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  997. expiryDates = expiry_date.Unix()
  998. }
  999. }
  1000. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1001. productDates = 0
  1002. } else {
  1003. if len(items["product_date"].(string)) == 0 {
  1004. productDates = 0
  1005. } else {
  1006. productDate, _ := items["product_date"].(string)
  1007. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1008. productDates = product_date.Unix()
  1009. }
  1010. }
  1011. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1012. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1013. WarehouseOutId: warehouseOut.ID,
  1014. DrugId: drug_id,
  1015. Count: count,
  1016. Price: price,
  1017. TotalPrice: total,
  1018. Status: 1,
  1019. Ctime: ctime,
  1020. Remark: remark,
  1021. OrgId: adminUserInfo.CurrentOrgId,
  1022. Type: types,
  1023. Manufacturer: manufacturer,
  1024. Dealer: dealer,
  1025. RetailPrice: price,
  1026. RetailTotalPrice: retail_price_total,
  1027. CountUnit: max_unit,
  1028. ExpiryDate: expiryDates,
  1029. ProductDate: productDates,
  1030. Number: number,
  1031. BatchNumber: batch_number,
  1032. IsSys: 0,
  1033. }
  1034. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1035. drugflow := &models.DrugFlow{
  1036. WarehouseOutId: warehouseOut.ID,
  1037. WarehouseOutOrderNumber: warehousing_out_order,
  1038. DrugId: drug_id,
  1039. Number: number,
  1040. ProductDate: productDates,
  1041. ExpireDate: expiryDates,
  1042. Count: count,
  1043. Price: price,
  1044. Status: 1,
  1045. Ctime: ctime,
  1046. UserOrgId: adminUserInfo.CurrentOrgId,
  1047. Manufacturer: manufacturer,
  1048. Dealer: dealer,
  1049. BatchNumber: batch_number,
  1050. MaxUnit: max_unit,
  1051. ConsumableType: 2,
  1052. IsEdit: 1,
  1053. Creator: adminUserInfo.AdminUser.Id,
  1054. IsSys: 0,
  1055. }
  1056. drugFlow = append(drugFlow, drugflow)
  1057. }
  1058. }
  1059. }
  1060. var total_count int64
  1061. var prescribing_number_total int64
  1062. //调用出库逻辑
  1063. for _, item := range warehousingOutInfo {
  1064. //获取药品库存
  1065. info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId)
  1066. //查询改药品信息
  1067. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1068. //判断单位是否相等
  1069. if medical.MaxUnit == item.CountUnit {
  1070. //转化为最小单位
  1071. total_count = info.Count * medical.MinNumber
  1072. prescribing_number_total = item.Count * medical.MinNumber
  1073. }
  1074. if medical.MinUnit == item.CountUnit {
  1075. total_count = info.Count
  1076. prescribing_number_total = item.Count
  1077. }
  1078. fmt.Println("数量一", prescribing_number_total)
  1079. fmt.Println("数量二", total_count)
  1080. //判断单位
  1081. if total_count == 0 {
  1082. goodObj, _ := service.GetDrugByGoodId(item.DrugId)
  1083. c.ServeSuccessJSON(map[string]interface{}{
  1084. "msg": "1",
  1085. "drug_name": goodObj.DrugName,
  1086. "dose": goodObj.Dose,
  1087. "dose_unit": goodObj.DoseUnit,
  1088. "min_number": goodObj.MinNumber,
  1089. "min_unit": goodObj.MinUnit,
  1090. "max_unit": goodObj.MaxUnit,
  1091. })
  1092. return
  1093. }
  1094. if prescribing_number_total > total_count {
  1095. goodObj, _ := service.GetDrugByGoodId(item.DrugId)
  1096. c.ServeSuccessJSON(map[string]interface{}{
  1097. "msg": "1",
  1098. "drug_name": goodObj.DrugName,
  1099. "dose": goodObj.Dose,
  1100. "dose_unit": goodObj.DoseUnit,
  1101. "min_number": goodObj.MinNumber,
  1102. "min_unit": goodObj.MinUnit,
  1103. "max_unit": goodObj.MaxUnit,
  1104. })
  1105. return
  1106. } else {
  1107. service.AddSigleDrugWarehouseOut(&warehouseOut)
  1108. service.CreateDrugFlow(drugFlow)
  1109. // 出库流程
  1110. // 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
  1111. drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
  1112. if drup.ID > 0 {
  1113. prescribingNumber := item.Count
  1114. service.AutoDrugDeliverInfo(item.OrgId, prescribingNumber, &warehouseOut, &drup, item)
  1115. }
  1116. }
  1117. }
  1118. c.ServeSuccessJSON(map[string]interface{}{
  1119. "msg": "2",
  1120. "drug_name": "",
  1121. "dose": "",
  1122. "dose_unit": "",
  1123. "min_number": "",
  1124. "min_unit": "",
  1125. "max_unit": "",
  1126. })
  1127. }
  1128. func (c *StockDrugApiController) GetDrugWarehouseOutList() {
  1129. page, _ := c.GetInt64("page", -1)
  1130. limit, _ := c.GetInt64("limit", -1)
  1131. start_time := c.GetString("start_time")
  1132. end_time := c.GetString("end_time")
  1133. types, _ := c.GetInt64("type", 0)
  1134. keywords := c.GetString("keywords")
  1135. timeLayout := "2006-01-02"
  1136. loc, _ := time.LoadLocation("Local")
  1137. var startTime int64
  1138. if len(start_time) > 0 {
  1139. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1140. if err != nil {
  1141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1142. return
  1143. }
  1144. startTime = theTime.Unix()
  1145. }
  1146. var endTime int64
  1147. if len(end_time) > 0 {
  1148. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1149. if err != nil {
  1150. utils.ErrorLog(err.Error())
  1151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1152. return
  1153. }
  1154. endTime = theTime.Unix()
  1155. }
  1156. adminUserInfo := c.GetAdminUserInfo()
  1157. var ids []int64
  1158. var goodids []int64
  1159. if len(keywords) > 0 {
  1160. //查询商品名称
  1161. list, _ := service.GetDrugNameByKeyword(keywords, adminUserInfo.CurrentOrgId)
  1162. for _, item := range list {
  1163. goodids = append(goodids, item.ID)
  1164. }
  1165. if len(goodids) > 0 {
  1166. //出库详情但里面查询
  1167. info, _ := service.GetDrugWarehouseOrderDetail(goodids, adminUserInfo.CurrentOrgId, startTime, endTime)
  1168. for _, it := range info {
  1169. ids = append(ids, it.WarehouseOutId)
  1170. }
  1171. }
  1172. }
  1173. warehouseOutList, total, err := service.FindAllDrugWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  1174. fmt.Println(err)
  1175. if err == nil {
  1176. c.ServeSuccessJSON(map[string]interface{}{
  1177. "list": warehouseOutList,
  1178. "total": total,
  1179. })
  1180. } else {
  1181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1182. }
  1183. }
  1184. func (c *StockDrugApiController) DeleteDrugWarehouseOut() {
  1185. ids := c.GetString("ids")
  1186. if len(ids) == 0 {
  1187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1188. return
  1189. }
  1190. idArray := strings.Split(ids, ",")
  1191. err := service.DeleteDrugWarehouseOut(idArray)
  1192. if err != nil {
  1193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1194. } else {
  1195. c.ServeSuccessJSON(map[string]interface{}{
  1196. "msg": "删除成功",
  1197. })
  1198. }
  1199. }
  1200. func (this *StockDrugApiController) DeleteDrugWarehouseOutInfo() {
  1201. id, _ := this.GetInt64("id", 0)
  1202. fmt.Println(id)
  1203. if id == 0 {
  1204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. err := service.UpDateDrugWarehouseOutStatus(id)
  1208. if err != nil {
  1209. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1210. } else {
  1211. this.ServeSuccessJSON(map[string]interface{}{
  1212. "msg": "删除成功",
  1213. })
  1214. }
  1215. }
  1216. func (c *StockDrugApiController) GetDrugWarehouseOutInfoList() {
  1217. id, _ := c.GetInt64("id", 0)
  1218. adminInfo := c.GetAdminUserInfo()
  1219. warehouseOutInfo, _ := service.FindDrugWarehouseOutInfoById(id, adminInfo.CurrentOrgId)
  1220. warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminInfo.CurrentOrgId)
  1221. manulist, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1222. dealerList, _ := service.GetAllDealerList(adminInfo.CurrentOrgId)
  1223. c.ServeSuccessJSON(map[string]interface{}{
  1224. "list": warehouseOutInfo,
  1225. "info": warehouseOut,
  1226. "manulist": manulist,
  1227. "dealerList": dealerList,
  1228. })
  1229. }
  1230. func (c *StockDrugApiController) EditDrugWarehouseOut() {
  1231. warehouse_out_time := c.GetString("warehouse_out_time")
  1232. id, _ := c.GetInt64("id", 0)
  1233. types, _ := c.GetInt64("type", 0)
  1234. if id == 0 {
  1235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1236. return
  1237. }
  1238. ctime := time.Now().Unix()
  1239. mtime := time.Now().Unix()
  1240. adminUserInfo := c.GetAdminUserInfo()
  1241. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1242. if parseDateErr != nil {
  1243. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1245. return
  1246. }
  1247. warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminUserInfo.CurrentOrgId)
  1248. tempWarehouseOut := models.DrugWarehouseOut{
  1249. ID: warehouseOut.ID,
  1250. Mtime: mtime,
  1251. WarehouseOutTime: warehouseOutDate.Unix(),
  1252. }
  1253. service.EditDrugWarehouseOut(tempWarehouseOut)
  1254. dataBody := make(map[string]interface{}, 0)
  1255. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1256. if err != nil {
  1257. utils.ErrorLog(err.Error())
  1258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1259. return
  1260. }
  1261. var warehousingOutInfo []*models.DrugWarehouseOutInfo
  1262. var upDateWarehouseOutInfos []*models.DrugWarehouseOutInfo
  1263. var drugFlow []*models.DrugFlow
  1264. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1265. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1266. if len(thisStockOut) > 0 {
  1267. for _, item := range thisStockOut {
  1268. items := item.(map[string]interface{})
  1269. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1270. utils.ErrorLog("drug_id")
  1271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1272. return
  1273. }
  1274. drug_id := int64(items["drug_id"].(float64))
  1275. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1276. utils.ErrorLog("count")
  1277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1278. return
  1279. }
  1280. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1281. count_unit, _ := items["count_unit"].(string)
  1282. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1283. utils.ErrorLog("price")
  1284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1285. return
  1286. }
  1287. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1288. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1289. utils.ErrorLog("retail_price")
  1290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1291. return
  1292. }
  1293. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1294. total := float64(count) * price
  1295. retail_price_total := float64(count) * retail_price
  1296. remark := items["remark"].(string)
  1297. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1298. utils.ErrorLog("id")
  1299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1300. return
  1301. }
  1302. id := int64(items["id"].(float64))
  1303. dealer := int64(items["dealer"].(float64))
  1304. manufacturer := int64(items["manufacturer"].(float64))
  1305. batch_number := items["batch_number"].(string)
  1306. number := items["number"].(string)
  1307. max_unit := items["count_unit"].(string)
  1308. var productDates int64
  1309. var expiryDates int64
  1310. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1311. expiryDates = 0
  1312. } else {
  1313. if len(items["expiry_date"].(string)) == 0 {
  1314. expiryDates = 0
  1315. } else {
  1316. expiryDate, _ := items["expiry_date"].(string)
  1317. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1318. expiryDates = expiry_date.Unix()
  1319. }
  1320. }
  1321. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1322. productDates = 0
  1323. } else {
  1324. if len(items["product_date"].(string)) == 0 {
  1325. productDates = 0
  1326. } else {
  1327. productDate, _ := items["product_date"].(string)
  1328. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1329. productDates = product_date.Unix()
  1330. }
  1331. }
  1332. fmt.Println("生产日期22222222222222222222222222", expiryDates)
  1333. fmt.Println("生产日期22222222222222222222222222", productDates)
  1334. if id == 0 {
  1335. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1336. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1337. WarehouseOutId: warehouseOut.ID,
  1338. DrugId: drug_id,
  1339. Count: count,
  1340. Price: price,
  1341. TotalPrice: total,
  1342. Status: 1,
  1343. Ctime: ctime,
  1344. Remark: remark,
  1345. OrgId: adminUserInfo.CurrentOrgId,
  1346. Type: types,
  1347. Manufacturer: manufacturer,
  1348. Dealer: dealer,
  1349. IsSys: 0,
  1350. SysRecordTime: 0,
  1351. RetailPrice: retail_price,
  1352. RetailTotalPrice: retail_price_total,
  1353. BatchNumber: batch_number,
  1354. Number: number,
  1355. ProductDate: productDates,
  1356. ExpiryDate: expiryDates,
  1357. CountUnit: count_unit,
  1358. }
  1359. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1360. drugflow := &models.DrugFlow{
  1361. WarehousingOrder: "",
  1362. WarehousingId: 0,
  1363. DrugId: drug_id,
  1364. Number: number,
  1365. ProductDate: productDates,
  1366. ExpireDate: expiryDates,
  1367. Count: count,
  1368. Price: price,
  1369. Status: 1,
  1370. Ctime: ctime,
  1371. UserOrgId: adminUserInfo.CurrentOrgId,
  1372. Manufacturer: manufacturer,
  1373. Dealer: dealer,
  1374. BatchNumber: batch_number,
  1375. MaxUnit: max_unit,
  1376. ConsumableType: 1,
  1377. IsEdit: 1,
  1378. Creator: adminUserInfo.AdminUser.Id,
  1379. IsSys: 0,
  1380. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1381. WarehouseOutId: warehouseOut.ID,
  1382. }
  1383. drugFlow = append(drugFlow, drugflow)
  1384. } else {
  1385. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1386. utils.ErrorLog("is_sys")
  1387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1388. return
  1389. }
  1390. is_sys := int64(items["is_sys"].(float64))
  1391. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1392. utils.ErrorLog("sys_record_time")
  1393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1394. return
  1395. }
  1396. sys_record_time := int64(items["sys_record_time"].(float64))
  1397. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1398. ID: id,
  1399. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1400. WarehouseOutId: warehouseOut.ID,
  1401. DrugId: drug_id,
  1402. Count: count,
  1403. Price: price,
  1404. TotalPrice: total,
  1405. Status: 1,
  1406. Ctime: ctime,
  1407. Remark: remark,
  1408. OrgId: adminUserInfo.CurrentOrgId,
  1409. Mtime: time.Now().Unix(),
  1410. Type: types,
  1411. Manufacturer: manufacturer,
  1412. Dealer: dealer,
  1413. IsSys: is_sys,
  1414. SysRecordTime: sys_record_time,
  1415. RetailPrice: retail_price,
  1416. RetailTotalPrice: retail_price_total,
  1417. BatchNumber: batch_number,
  1418. Number: number,
  1419. ProductDate: productDates,
  1420. ExpiryDate: expiryDates,
  1421. CountUnit: count_unit,
  1422. }
  1423. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1424. drugflow := &models.DrugFlow{
  1425. WarehousingOrder: "",
  1426. WarehousingId: 0,
  1427. DrugId: drug_id,
  1428. Number: number,
  1429. ProductDate: productDates,
  1430. ExpireDate: expiryDates,
  1431. Count: count,
  1432. Price: price,
  1433. Status: 1,
  1434. Ctime: ctime,
  1435. UserOrgId: adminUserInfo.CurrentOrgId,
  1436. Manufacturer: manufacturer,
  1437. Dealer: dealer,
  1438. BatchNumber: batch_number,
  1439. MaxUnit: max_unit,
  1440. ConsumableType: 1,
  1441. IsEdit: 1,
  1442. Creator: adminUserInfo.AdminUser.Id,
  1443. IsSys: 0,
  1444. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1445. WarehouseOutId: warehouseOut.ID,
  1446. }
  1447. drugFlow = append(drugFlow, drugflow)
  1448. }
  1449. }
  1450. }
  1451. }
  1452. var errs error
  1453. if len(warehousingOutInfo) > 0 {
  1454. var total_count int64
  1455. var prescribing_number_total int64
  1456. //调用出库逻辑
  1457. for _, item := range warehousingOutInfo {
  1458. //获取药品库存
  1459. info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId)
  1460. //查询改药品信息
  1461. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1462. //判断单位是否相等
  1463. if medical.MaxUnit == item.CountUnit {
  1464. //转化为最小单位
  1465. total_count = info.Count * medical.MinNumber
  1466. prescribing_number_total = item.Count * medical.MinNumber
  1467. }
  1468. if medical.MinUnit == item.CountUnit {
  1469. total_count = info.Count
  1470. prescribing_number_total = item.Count
  1471. }
  1472. fmt.Println("数量一", prescribing_number_total)
  1473. fmt.Println("数量二", total_count)
  1474. //判断单位
  1475. if total_count == 0 {
  1476. goodObj, _ := service.GetDrugByGoodId(item.DrugId)
  1477. c.ServeSuccessJSON(map[string]interface{}{
  1478. "msg": "1",
  1479. "drug_name": goodObj.DrugName,
  1480. "dose": goodObj.Dose,
  1481. "dose_unit": goodObj.DoseUnit,
  1482. "min_number": goodObj.MinNumber,
  1483. "min_unit": goodObj.MinUnit,
  1484. "max_unit": goodObj.MaxUnit,
  1485. })
  1486. return
  1487. }
  1488. if prescribing_number_total > total_count {
  1489. goodObj, _ := service.GetDrugByGoodId(item.DrugId)
  1490. c.ServeSuccessJSON(map[string]interface{}{
  1491. "msg": "1",
  1492. "drug_name": goodObj.DrugName,
  1493. "dose": goodObj.Dose,
  1494. "dose_unit": goodObj.DoseUnit,
  1495. "min_number": goodObj.MinNumber,
  1496. "min_unit": goodObj.MinUnit,
  1497. "max_unit": goodObj.MaxUnit,
  1498. })
  1499. return
  1500. } else {
  1501. errs = service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
  1502. service.CreateDrugFlow(drugFlow)
  1503. // 出库流程
  1504. // 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
  1505. drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
  1506. if drup.ID > 0 {
  1507. prescribingNumber := item.Count
  1508. service.AutoDrugDeliverInfo(item.OrgId, prescribingNumber, &tempWarehouseOut, &drup, item)
  1509. }
  1510. }
  1511. }
  1512. }
  1513. if len(upDateWarehouseOutInfos) > 0 {
  1514. for _, item := range upDateWarehouseOutInfos {
  1515. //获取药品库存
  1516. info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId)
  1517. //查询改药品信息
  1518. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1519. //查询最后一次出库记录
  1520. outInfo, _ := service.GetLastDrugWarehouseOutInfo(item.DrugId, item.WarehouseOutId, item.OrgId)
  1521. var min_number int64 //最后一次库存
  1522. var max_number int64 //当前库存
  1523. var all_number int64 //总库存
  1524. var cha_number int64 //库存差
  1525. var maxNumber int64
  1526. var minNumber int64
  1527. if medical.MaxUnit == outInfo.CountUnit {
  1528. //转为最小单位
  1529. min_number = outInfo.Count * medical.MinNumber
  1530. }
  1531. if medical.MinUnit == outInfo.CountUnit {
  1532. min_number = outInfo.Count
  1533. }
  1534. fmt.Println("单位1", medical.MaxUnit)
  1535. fmt.Println("单位2", item.CountUnit)
  1536. if medical.MaxUnit == item.CountUnit {
  1537. max_number = item.Count * medical.MinNumber
  1538. }
  1539. if medical.MinUnit == item.CountUnit {
  1540. max_number = item.Count
  1541. }
  1542. all_number = info.Count*medical.MinNumber + info.StockMinNumber
  1543. fmt.Println("总库存223232", all_number)
  1544. fmt.Println("当前库存00000000000000000000000000000000000000000", max_number)
  1545. ////比较当前出库数量 和 最后一次出库数量,正常出库
  1546. if max_number <= min_number {
  1547. errs = service.UpDateDrugWarehouseOutInfo(item)
  1548. cha_number = min_number - max_number
  1549. fmt.Println("差库存", cha_number)
  1550. fmt.Println("最后一次库存0000000000000000000000000000000000000000", min_number)
  1551. if item.CountUnit == medical.MaxUnit {
  1552. maxNumber = cha_number / medical.MinNumber
  1553. parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
  1554. if parseDateErr != nil {
  1555. utils.ErrorLog(errs.Error())
  1556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1557. return
  1558. }
  1559. c.ServeSuccessJSON(map[string]interface{}{
  1560. "msg": "2",
  1561. "drug_name": "",
  1562. "dose": "",
  1563. "dose_unit": "",
  1564. "min_number": "",
  1565. "min_unit": "",
  1566. "max_unit": "",
  1567. })
  1568. minNumber = cha_number % medical.MinNumber
  1569. parseDateErr = service.UpdateWarehouseInfoOne(minNumber, item.DrugId, item.OrgId)
  1570. if parseDateErr != nil {
  1571. utils.ErrorLog(errs.Error())
  1572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1573. return
  1574. }
  1575. c.ServeSuccessJSON(map[string]interface{}{
  1576. "msg": "2",
  1577. "drug_name": "",
  1578. "dose": "",
  1579. "dose_unit": "",
  1580. "min_number": "",
  1581. "min_unit": "",
  1582. "max_unit": "",
  1583. })
  1584. }
  1585. if item.CountUnit == medical.MinUnit {
  1586. parseDateErr := service.UpdateWarehouseInfoOne(cha_number, item.DrugId, item.OrgId)
  1587. if parseDateErr != nil {
  1588. utils.ErrorLog(errs.Error())
  1589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1590. return
  1591. }
  1592. c.ServeSuccessJSON(map[string]interface{}{
  1593. "msg": "2",
  1594. "drug_name": "",
  1595. "dose": "",
  1596. "dose_unit": "",
  1597. "min_number": "",
  1598. "min_unit": "",
  1599. "max_unit": "",
  1600. })
  1601. }
  1602. }
  1603. fmt.Println("当前出库", max_number)
  1604. fmt.Println("最后一次232233", min_number)
  1605. //退库操作
  1606. if max_number > min_number {
  1607. cha_number = min_number - max_number
  1608. //如果总库存大于差,正常出库
  1609. if all_number >= cha_number {
  1610. errs = service.UpDateDrugWarehouseOutInfo(item)
  1611. fmt.Println("232322332233232", item.CountUnit, medical.MaxUnit)
  1612. if item.CountUnit == medical.MaxUnit {
  1613. maxNumber = cha_number / medical.MinNumber
  1614. fmt.Println("maxNumber232323232323232232", maxNumber)
  1615. parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
  1616. fmt.Println("parseDateErr9999999999999999999999", parseDateErr)
  1617. if parseDateErr != nil {
  1618. utils.ErrorLog(errs.Error())
  1619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1620. return
  1621. }
  1622. c.ServeSuccessJSON(map[string]interface{}{
  1623. "msg": "2",
  1624. "drug_name": "",
  1625. "dose": "",
  1626. "dose_unit": "",
  1627. "min_number": "",
  1628. "min_unit": "",
  1629. "max_unit": "",
  1630. })
  1631. minNumber = cha_number % medical.MinNumber
  1632. parseDateErr = service.UpdateWarehouseInfoOne(minNumber, item.DrugId, item.OrgId)
  1633. if parseDateErr != nil {
  1634. utils.ErrorLog(errs.Error())
  1635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1636. return
  1637. }
  1638. c.ServeSuccessJSON(map[string]interface{}{
  1639. "msg": "2",
  1640. "drug_name": "",
  1641. "dose": "",
  1642. "dose_unit": "",
  1643. "min_number": "",
  1644. "min_unit": "",
  1645. "max_unit": "",
  1646. })
  1647. }
  1648. if item.CountUnit == medical.MinUnit {
  1649. parseDateErr := service.UpdateWarehouseInfoOne(cha_number, item.DrugId, item.OrgId)
  1650. if parseDateErr != nil {
  1651. utils.ErrorLog(errs.Error())
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1653. return
  1654. }
  1655. c.ServeSuccessJSON(map[string]interface{}{
  1656. "msg": "2",
  1657. "drug_name": "",
  1658. "dose": "",
  1659. "dose_unit": "",
  1660. "min_number": "",
  1661. "min_unit": "",
  1662. "max_unit": "",
  1663. })
  1664. }
  1665. }
  1666. if all_number < cha_number {
  1667. goodObj, _ := service.GetDrugByGoodId(item.DrugId)
  1668. c.ServeSuccessJSON(map[string]interface{}{
  1669. "msg": "1",
  1670. "drug_name": goodObj.DrugName,
  1671. "dose": goodObj.Dose,
  1672. "dose_unit": goodObj.DoseUnit,
  1673. "min_number": goodObj.MinNumber,
  1674. "min_unit": goodObj.MinUnit,
  1675. "max_unit": goodObj.MaxUnit,
  1676. })
  1677. return
  1678. }
  1679. }
  1680. }
  1681. }
  1682. if errs != nil {
  1683. utils.ErrorLog(errs.Error())
  1684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1685. return
  1686. }
  1687. c.ServeSuccessJSON(map[string]interface{}{
  1688. "msg": "2",
  1689. "drug_name": "",
  1690. "dose": "",
  1691. "dose_unit": "",
  1692. "min_number": "",
  1693. "min_unit": "",
  1694. "max_unit": "",
  1695. })
  1696. }
  1697. func (c *StockDrugApiController) CreateDrugCancelStock() {
  1698. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1699. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1700. cancel_stock_time := c.GetString("time")
  1701. types, _ := c.GetInt64("type", 0)
  1702. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1703. if parseDateErr != nil {
  1704. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1706. return
  1707. }
  1708. fmt.Println("cancelStockDate232323223233223", cancelStockDate.Unix())
  1709. adminUserInfo := c.GetAdminUserInfo()
  1710. operation_time := time.Now().Unix()
  1711. creater := adminUserInfo.AdminUser.Id
  1712. ctime := time.Now().Unix()
  1713. timeStr := time.Now().Format("2006-01-02")
  1714. timeArr := strings.Split(timeStr, "-")
  1715. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1716. total = total + 1
  1717. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1718. cancelStock := models.DrugCancelStock{
  1719. OrderNumber: orderNumber,
  1720. OperaTime: operation_time,
  1721. OrgId: adminUserInfo.CurrentOrgId,
  1722. Creater: creater,
  1723. Ctime: ctime,
  1724. Status: 1,
  1725. ReturnTime: cancelStockDate.Unix(),
  1726. Dealer: dealer_id,
  1727. Manufacturer: manufacturer_id,
  1728. Type: types,
  1729. }
  1730. service.AddSigleDrugCancelStock(&cancelStock)
  1731. fmt.Println("hh232323232323232323232323232322332", parseDateErr)
  1732. dataBody := make(map[string]interface{}, 0)
  1733. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1734. if err != nil {
  1735. utils.ErrorLog(err.Error())
  1736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1737. return
  1738. }
  1739. var cancelStockInfos []*models.DrugCancelStockInfo
  1740. var drugFlow []*models.DrugFlow
  1741. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1742. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1743. if len(thisStockIn) > 0 {
  1744. for _, item := range thisStockIn {
  1745. items := item.(map[string]interface{})
  1746. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1747. utils.ErrorLog("drug_id")
  1748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1749. return
  1750. }
  1751. drug_id := int64(items["drug_id"].(float64))
  1752. return_count, _ := items["return_count"].(string)
  1753. if len(return_count) == 0 {
  1754. utils.ErrorLog("len(return_count) == 0")
  1755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1756. return
  1757. }
  1758. count, _ := strconv.ParseInt(return_count, 10, 64)
  1759. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1760. utils.ErrorLog("price")
  1761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1762. return
  1763. }
  1764. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1765. total := float64(count) * price
  1766. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1767. utils.ErrorLog("retail_price")
  1768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1769. return
  1770. }
  1771. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1772. retail_price_total := float64(count) * retail_price
  1773. register_account, _ := items["register_account"].(string)
  1774. remark, _ := items["remark"].(string)
  1775. var productDates int64
  1776. var expiryDates int64
  1777. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1778. expiryDates = 0
  1779. } else {
  1780. if len(items["expiry_date"].(string)) == 0 {
  1781. expiryDates = 0
  1782. } else {
  1783. expiryDate, _ := items["expiry_date"].(string)
  1784. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1785. expiryDates = expiry_date.Unix()
  1786. }
  1787. }
  1788. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1789. productDates = 0
  1790. } else {
  1791. if len(items["product_date"].(string)) == 0 {
  1792. productDates = 0
  1793. } else {
  1794. productDate, _ := items["product_date"].(string)
  1795. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1796. productDates = product_date.Unix()
  1797. }
  1798. }
  1799. manufacturer, _ := items["manufacturer"].(string)
  1800. dealer, _ := items["dealer"].(string)
  1801. batch_number := items["batch_number"].(string)
  1802. max_unit := items["max_unit"].(string)
  1803. batch_number_id := int64(items["batch_number_id"].(float64))
  1804. fmt.Println("99999999999999999999", batch_number_id)
  1805. cancelStockInfo := &models.DrugCancelStockInfo{
  1806. OrderNumber: cancelStock.OrderNumber,
  1807. CancelStockId: cancelStock.ID,
  1808. DrugId: drug_id,
  1809. Count: count,
  1810. Status: 1,
  1811. Ctime: ctime,
  1812. OrgId: adminUserInfo.CurrentOrgId,
  1813. Type: types,
  1814. Manufacturer: manufacturer,
  1815. Dealer: dealer,
  1816. Total: total,
  1817. RetailPrice: retail_price,
  1818. RetailTotalPrice: retail_price_total,
  1819. Price: price,
  1820. RegisterAccount: register_account,
  1821. Remark: remark,
  1822. BatchNumber: batch_number,
  1823. MaxUnit: max_unit,
  1824. ProductDate: productDates,
  1825. ExpiryDate: expiryDates,
  1826. BatchNumberId: batch_number_id,
  1827. }
  1828. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1829. flow := &models.DrugFlow{
  1830. WarehousingId: 0,
  1831. DrugId: drug_id,
  1832. Number: "",
  1833. BatchNumber: batch_number,
  1834. Count: count,
  1835. UserOrgId: adminUserInfo.CurrentOrgId,
  1836. PatientId: 0,
  1837. SystemTime: ctime,
  1838. ConsumableType: 4,
  1839. IsSys: 0,
  1840. WarehousingOrder: "",
  1841. WarehouseOutId: 0,
  1842. WarehouseOutOrderNumber: "",
  1843. IsEdit: 0,
  1844. CancelStockId: cancelStock.ID,
  1845. CancelOrderNumber: cancelStock.OrderNumber,
  1846. Manufacturer: 0,
  1847. Dealer: 0,
  1848. Creator: adminUserInfo.AdminUser.Id,
  1849. UpdateCreator: 0,
  1850. Status: 1,
  1851. Ctime: time.Now().Unix(),
  1852. Mtime: 0,
  1853. Price: price,
  1854. WarehousingDetailId: 0,
  1855. WarehouseOutDetailId: 0,
  1856. CancelOutDetailId: 0,
  1857. ExpireDate: expiryDates,
  1858. ProductDate: productDates,
  1859. MaxUnit: max_unit,
  1860. MinUnit: "",
  1861. }
  1862. drugFlow = append(drugFlow, flow)
  1863. }
  1864. }
  1865. }
  1866. //扣减库存逻辑
  1867. for _, item := range cancelStockInfos {
  1868. var total_number int64
  1869. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1870. //将当前退库数转为最小单位
  1871. if item.MaxUnit == medical.MaxUnit {
  1872. total_number = item.Count * medical.MinNumber
  1873. }
  1874. if item.MaxUnit == medical.MinUnit {
  1875. total_number = item.Count
  1876. }
  1877. fmt.Println("当前库存", total_number)
  1878. //查询当前药品退库的批次号的总入库数
  1879. infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
  1880. fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit, infoWareInfo.StockMaxNumber, infoWareInfo.StockMinNumber)
  1881. var total_count int64
  1882. total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
  1883. fmt.Println("当前批次总库存", total_count)
  1884. //判断退库数量是否大于总入库数量
  1885. if total_number > total_count {
  1886. c.ServeSuccessJSON(map[string]interface{}{
  1887. "msg": "2",
  1888. })
  1889. return
  1890. }
  1891. //正常退库
  1892. if total_number <= total_count {
  1893. //创建退库详情
  1894. errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
  1895. //创建库存明细
  1896. errs = service.CreateDrugFlow(drugFlow)
  1897. var total int64
  1898. ////退库到当前批次,获取当前退库批次的库存
  1899. //info, _ := service.GetDrugWarehouseInfoById(item.BatchNumberId)
  1900. if medical.MaxUnit == item.MaxUnit {
  1901. total = item.Count
  1902. warehouseInfo := models.XtDrugWarehouseInfo{
  1903. StockMaxNumber: total,
  1904. }
  1905. errs = service.UpdateDrugWarehouseInfo(&warehouseInfo, item.BatchNumberId)
  1906. if errs != nil {
  1907. utils.ErrorLog(errs.Error())
  1908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1909. return
  1910. }
  1911. c.ServeSuccessJSON(map[string]interface{}{
  1912. "msg": "1",
  1913. })
  1914. }
  1915. if medical.MinUnit == item.MaxUnit {
  1916. fmt.Println("hhhhhh2323323232322332232332999999999进来", item.Count)
  1917. total = item.Count
  1918. warehouseInfo := models.XtDrugWarehouseInfo{
  1919. StockMinNumber: total,
  1920. }
  1921. errs = service.UpdateDrugWarehouseInfoOne(&warehouseInfo, item.BatchNumberId)
  1922. if errs != nil {
  1923. utils.ErrorLog(errs.Error())
  1924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1925. return
  1926. }
  1927. c.ServeSuccessJSON(map[string]interface{}{
  1928. "msg": "1",
  1929. })
  1930. }
  1931. if errs != nil {
  1932. utils.ErrorLog(errs.Error())
  1933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1934. return
  1935. }
  1936. c.ServeSuccessJSON(map[string]interface{}{
  1937. "msg": "1",
  1938. })
  1939. }
  1940. }
  1941. }
  1942. func (c *StockDrugApiController) GetDrugCancelStockInfoList() {
  1943. id, _ := c.GetInt64("id", 0)
  1944. adminUserInfo := c.GetAdminUserInfo()
  1945. cancelStockInfoList, _ := service.FindDrugCancelStockInfoById(id, adminUserInfo.CurrentOrgId)
  1946. info, _ := service.FindCancelDrugById(id, adminUserInfo.CurrentOrgId)
  1947. c.ServeSuccessJSON(map[string]interface{}{
  1948. "list": cancelStockInfoList,
  1949. "info": info,
  1950. })
  1951. }
  1952. func (c *StockDrugApiController) GetDrugCancelStockList() {
  1953. page, _ := c.GetInt64("page", -1)
  1954. limit, _ := c.GetInt64("limit", -1)
  1955. start_time := c.GetString("start_time")
  1956. end_time := c.GetString("end_time")
  1957. types, _ := c.GetInt64("type", 0)
  1958. keywords := c.GetString("keywords")
  1959. timeLayout := "2006-01-02"
  1960. loc, _ := time.LoadLocation("Local")
  1961. var startTime int64
  1962. if len(start_time) > 0 {
  1963. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1964. if err != nil {
  1965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1966. return
  1967. }
  1968. startTime = theTime.Unix()
  1969. }
  1970. var endTime int64
  1971. if len(end_time) > 0 {
  1972. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1973. if err != nil {
  1974. utils.ErrorLog(err.Error())
  1975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1976. return
  1977. }
  1978. endTime = theTime.Unix()
  1979. }
  1980. adminUserInfo := c.GetAdminUserInfo()
  1981. returnList, total, err := service.FindAllDrugCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1982. if err == nil {
  1983. c.ServeSuccessJSON(map[string]interface{}{
  1984. "list": returnList,
  1985. "total": total,
  1986. })
  1987. } else {
  1988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1989. }
  1990. }
  1991. func (this *StockDrugApiController) DeleteDrugCancelStock() {
  1992. ids := this.GetString("ids")
  1993. if len(ids) == 0 {
  1994. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1995. return
  1996. }
  1997. idArray := strings.Split(ids, ",")
  1998. err := service.DeleteDrugCancelStock(idArray)
  1999. if err != nil {
  2000. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2001. } else {
  2002. this.ServeSuccessJSON(map[string]interface{}{
  2003. "msg": "删除成功",
  2004. })
  2005. }
  2006. }
  2007. func (this *StockDrugApiController) DeleteDrugCancelStockInfo() {
  2008. id, _ := this.GetInt64("id", 0)
  2009. fmt.Println(id)
  2010. if id == 0 {
  2011. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2012. return
  2013. }
  2014. err := service.UpDateDrugCancleStockStatus(id)
  2015. if err != nil {
  2016. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2017. } else {
  2018. this.ServeSuccessJSON(map[string]interface{}{
  2019. "msg": "删除成功",
  2020. })
  2021. }
  2022. }
  2023. func (c *StockDrugApiController) EditDrugCancelStock() {
  2024. cancel_time := c.GetString("cancel_time")
  2025. id, _ := c.GetInt64("id", 0)
  2026. types, _ := c.GetInt64("type", 0)
  2027. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  2028. dealer_id, _ := c.GetInt64("dealer_id", 0)
  2029. if id == 0 {
  2030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2031. return
  2032. }
  2033. ctime := time.Now().Unix()
  2034. mtime := time.Now().Unix()
  2035. adminUserInfo := c.GetAdminUserInfo()
  2036. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  2037. if parseDateErr != nil {
  2038. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  2039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2040. return
  2041. }
  2042. cancelStock, _ := service.FindDrugCancelStockById(id)
  2043. tempCancelStock := models.DrugCancelStock{
  2044. ID: cancelStock.ID,
  2045. Mtime: mtime,
  2046. ReturnTime: cancelDate.Unix(),
  2047. Manufacturer: manufacturer_id,
  2048. Dealer: dealer_id,
  2049. }
  2050. service.EditDrugCancelStock(tempCancelStock)
  2051. dataBody := make(map[string]interface{}, 0)
  2052. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2053. if err != nil {
  2054. utils.ErrorLog(err.Error())
  2055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2056. return
  2057. }
  2058. var cancelStockInfos []*models.DrugCancelStockInfo
  2059. var upDateCancelStockInfos []*models.DrugCancelStockInfo
  2060. var drugFlow []*models.DrugFlow
  2061. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  2062. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  2063. if len(thisCancelStock) > 0 {
  2064. for _, item := range thisCancelStock {
  2065. items := item.(map[string]interface{})
  2066. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  2067. utils.ErrorLog("drug_id")
  2068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2069. return
  2070. }
  2071. drug_id := int64(items["drug_id"].(float64))
  2072. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2073. utils.ErrorLog("count")
  2074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2075. return
  2076. }
  2077. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2078. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2079. utils.ErrorLog("price")
  2080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2081. return
  2082. }
  2083. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2084. total := float64(count) * price
  2085. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  2086. utils.ErrorLog("retail_price")
  2087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2088. return
  2089. }
  2090. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  2091. retail_price_total := float64(count) * retail_price
  2092. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2093. utils.ErrorLog("id")
  2094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2095. return
  2096. }
  2097. id := int64(items["id"].(float64))
  2098. max_unit := items["max_unit"].(string)
  2099. batch_number := items["batch_number"].(string)
  2100. register_account := items["register_account"].(string)
  2101. remark := items["remark"].(string)
  2102. manufacturer := items["manufacturer"].(string)
  2103. dealer := items["dealer"].(string)
  2104. var productDates int64
  2105. var expiryDates int64
  2106. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  2107. expiryDates = 0
  2108. } else {
  2109. if len(items["expiry_date"].(string)) == 0 {
  2110. expiryDates = 0
  2111. } else {
  2112. expiryDate, _ := items["expiry_date"].(string)
  2113. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  2114. expiryDates = expiry_date.Unix()
  2115. }
  2116. }
  2117. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  2118. productDates = 0
  2119. } else {
  2120. if len(items["product_date"].(string)) == 0 {
  2121. productDates = 0
  2122. } else {
  2123. productDate, _ := items["product_date"].(string)
  2124. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  2125. productDates = product_date.Unix()
  2126. }
  2127. }
  2128. batch_number_id := int64(items["batch_number_id"].(float64))
  2129. if id == 0 {
  2130. cancelStockInfo := &models.DrugCancelStockInfo{
  2131. DrugId: drug_id,
  2132. Count: count,
  2133. Status: 1,
  2134. Ctime: ctime,
  2135. OrgId: adminUserInfo.CurrentOrgId,
  2136. OrderNumber: cancelStock.OrderNumber,
  2137. CancelStockId: cancelStock.ID,
  2138. Mtime: time.Now().Unix(),
  2139. Type: types,
  2140. RetailPrice: retail_price,
  2141. RetailTotalPrice: retail_price_total,
  2142. Price: price,
  2143. Total: total,
  2144. Manufacturer: manufacturer,
  2145. Dealer: dealer,
  2146. RegisterAccount: register_account,
  2147. MaxUnit: max_unit,
  2148. BatchNumber: batch_number,
  2149. Remark: remark,
  2150. ProductDate: productDates,
  2151. ExpiryDate: expiryDates,
  2152. BatchNumberId: batch_number_id,
  2153. }
  2154. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  2155. } else {
  2156. cancelStockInfo := &models.DrugCancelStockInfo{
  2157. ID: id,
  2158. DrugId: drug_id,
  2159. Count: count,
  2160. Status: 1,
  2161. Ctime: ctime,
  2162. OrgId: adminUserInfo.CurrentOrgId,
  2163. OrderNumber: cancelStock.OrderNumber,
  2164. CancelStockId: cancelStock.ID,
  2165. Mtime: time.Now().Unix(),
  2166. Type: types,
  2167. RetailPrice: retail_price,
  2168. RetailTotalPrice: retail_price_total,
  2169. Price: price,
  2170. Total: total,
  2171. Manufacturer: manufacturer,
  2172. Dealer: dealer,
  2173. RegisterAccount: register_account,
  2174. MaxUnit: max_unit,
  2175. BatchNumber: batch_number,
  2176. Remark: remark,
  2177. ProductDate: productDates,
  2178. ExpiryDate: expiryDates,
  2179. BatchNumberId: batch_number_id,
  2180. }
  2181. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  2182. }
  2183. flow := &models.DrugFlow{
  2184. WarehousingId: 0,
  2185. DrugId: drug_id,
  2186. Number: "",
  2187. BatchNumber: batch_number,
  2188. Count: count,
  2189. UserOrgId: adminUserInfo.CurrentOrgId,
  2190. PatientId: 0,
  2191. SystemTime: time.Now().Unix(),
  2192. ConsumableType: 4,
  2193. IsSys: 0,
  2194. WarehousingOrder: "",
  2195. WarehouseOutId: 0,
  2196. WarehouseOutOrderNumber: "",
  2197. IsEdit: 0,
  2198. CancelStockId: cancelStock.ID,
  2199. CancelOrderNumber: cancelStock.OrderNumber,
  2200. Manufacturer: 0,
  2201. Dealer: 0,
  2202. Creator: adminUserInfo.AdminUser.Id,
  2203. UpdateCreator: adminUserInfo.AdminUser.Id,
  2204. Status: 1,
  2205. Ctime: time.Now().Unix(),
  2206. Mtime: 0,
  2207. Price: price,
  2208. WarehousingDetailId: 0,
  2209. WarehouseOutDetailId: 0,
  2210. CancelOutDetailId: 0,
  2211. ExpireDate: expiryDates,
  2212. ProductDate: productDates,
  2213. MaxUnit: max_unit,
  2214. MinUnit: "",
  2215. }
  2216. drugFlow = append(drugFlow, flow)
  2217. }
  2218. }
  2219. }
  2220. fmt.Println("cancelStockInfos232323223323223322323223", cancelStockInfos)
  2221. fmt.Println("cancelStockInfos232323223323223322323223", upDateCancelStockInfos)
  2222. var errs error
  2223. if len(cancelStockInfos) > 0 {
  2224. //扣减库存逻辑
  2225. for _, item := range cancelStockInfos {
  2226. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  2227. //查询当前药品退库的批次号的总入库数
  2228. infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
  2229. fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit)
  2230. var total_count int64
  2231. total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
  2232. //转化为最小单位
  2233. var total_number int64
  2234. if item.MaxUnit == medical.MaxUnit {
  2235. total_number = item.Count * medical.MinNumber
  2236. }
  2237. if item.MaxUnit == medical.MinUnit {
  2238. total_number = item.Count
  2239. }
  2240. //if item.MaxUnit == medical.MaxUnit {
  2241. // total_count = infoWareInfo.WarehousingCount
  2242. //}
  2243. ////转化为最小库存
  2244. //if item.MaxUnit == medical.MinUnit {
  2245. // total_count = infoWareInfo.WarehousingCount * medical.MinNumber
  2246. //}
  2247. //判断退库数量是否大于总入库数量
  2248. if total_number > total_count {
  2249. c.ServeSuccessJSON(map[string]interface{}{
  2250. "msg": "2",
  2251. })
  2252. return
  2253. }
  2254. //正常退库
  2255. if total_number <= total_count {
  2256. //创建退库详情
  2257. errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
  2258. //创建库存明细
  2259. errs = service.CreateDrugFlow(drugFlow)
  2260. //获取该批次最后一条退库详情
  2261. lastCancel, _ := service.GetLastCancelStockInfo(id)
  2262. var cancel_number int64
  2263. if lastCancel.MaxUnit == medical.MaxUnit {
  2264. cancel_number = lastCancel.Count * medical.MinNumber
  2265. }
  2266. if lastCancel.MaxUnit == medical.MinUnit {
  2267. cancel_number = lastCancel.Count
  2268. }
  2269. fmt.Println("999999232323232232232323232323", lastCancel)
  2270. var total int64
  2271. if medical.MaxUnit == item.MaxUnit {
  2272. total = item.Count - cancel_number
  2273. warehouseInfo := models.XtDrugWarehouseInfo{
  2274. StockMaxNumber: total,
  2275. }
  2276. errs = service.UpdateDrugWarehouseInfo(&warehouseInfo, item.BatchNumberId)
  2277. if errs != nil {
  2278. utils.ErrorLog(errs.Error())
  2279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2280. return
  2281. }
  2282. c.ServeSuccessJSON(map[string]interface{}{
  2283. "msg": "1",
  2284. })
  2285. }
  2286. if medical.MinUnit == item.MaxUnit {
  2287. total = item.Count - cancel_number
  2288. warehouseInfo := models.XtDrugWarehouseInfo{
  2289. StockMinNumber: total,
  2290. }
  2291. errs = service.UpdateDrugWarehouseInfoOne(&warehouseInfo, item.BatchNumberId)
  2292. if errs != nil {
  2293. utils.ErrorLog(errs.Error())
  2294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2295. return
  2296. }
  2297. c.ServeSuccessJSON(map[string]interface{}{
  2298. "msg": "1",
  2299. })
  2300. }
  2301. if errs != nil {
  2302. utils.ErrorLog(errs.Error())
  2303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2304. return
  2305. }
  2306. c.ServeSuccessJSON(map[string]interface{}{
  2307. "msg": "1",
  2308. })
  2309. }
  2310. }
  2311. }
  2312. if len(drugFlow) > 0 {
  2313. parseDateErr := service.CreateDrugFlow(drugFlow)
  2314. fmt.Println(parseDateErr)
  2315. }
  2316. if len(upDateCancelStockInfos) > 0 {
  2317. var total int64
  2318. for _, item := range upDateCancelStockInfos {
  2319. errs = service.UpDateDrugCancelStockInfo(item)
  2320. //查询该批次最后一条退库记录
  2321. info, _ := service.GetLastCancelStockInfo(id)
  2322. //查询该药品的信息
  2323. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  2324. if item.MaxUnit == medical.MaxUnit {
  2325. item.Count = item.Count * medical.MinNumber
  2326. //更新库存
  2327. total = item.Count - info.Count
  2328. fmt.Println("total232323232323232232323", total)
  2329. service.UpdatedDrugInfo(item.BatchNumberId, total)
  2330. break
  2331. }
  2332. if item.MaxUnit == medical.MinUnit {
  2333. item.Count = item.Count
  2334. total = item.Count - info.Count
  2335. service.UpdatedDrugInfoOne(item.BatchNumberId, total)
  2336. break
  2337. }
  2338. }
  2339. }
  2340. if errs != nil {
  2341. utils.ErrorLog(errs.Error())
  2342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateCancelStockFail)
  2343. return
  2344. }
  2345. c.ServeSuccessJSON(map[string]interface{}{
  2346. "msg": "1",
  2347. })
  2348. }
  2349. func (c *StockDrugApiController) GetAllConfig() {
  2350. adminUserInfo := c.GetAdminUserInfo()
  2351. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  2352. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  2353. stockIns, _ := service.FindStockInNumber(adminUserInfo.CurrentOrgId)
  2354. drugs, _ := service.GetDrugs(adminUserInfo.CurrentOrgId)
  2355. c.ServeSuccessJSON(map[string]interface{}{
  2356. "manufacturer": manufacturer,
  2357. "dealer": dealer,
  2358. "drugs": drugs,
  2359. "numbers": stockIns,
  2360. })
  2361. }
  2362. func (c *StockDrugApiController) GetAllDrugStock() {
  2363. adminUserInfo := c.GetAdminUserInfo()
  2364. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  2365. dealer_id, _ := c.GetInt64("dealer_id", 0)
  2366. drugs, err := service.FindAllDrugByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  2367. if err == nil {
  2368. c.ServeSuccessJSON(map[string]interface{}{
  2369. "drugs": drugs,
  2370. })
  2371. } else {
  2372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2373. }
  2374. }
  2375. func (c *StockDrugApiController) GetDrugQueryInfo() {
  2376. page, _ := c.GetInt64("page", -1)
  2377. limit, _ := c.GetInt64("limit", -1)
  2378. keyword := c.GetString("keyword")
  2379. drug_category, _ := c.GetInt64("drug_category")
  2380. start_time := c.GetString("start_time")
  2381. end_time := c.GetString("end_time")
  2382. timeLayout := "2006-01-02"
  2383. loc, _ := time.LoadLocation("Local")
  2384. var startTime int64
  2385. if len(start_time) > 0 {
  2386. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2387. if err != nil {
  2388. fmt.Println(err)
  2389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2390. return
  2391. }
  2392. startTime = theTime.Unix()
  2393. }
  2394. var endTime int64
  2395. if len(end_time) > 0 {
  2396. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2397. if err != nil {
  2398. utils.ErrorLog(err.Error())
  2399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2400. return
  2401. }
  2402. endTime = theTime.Unix()
  2403. }
  2404. adminUserInfo := c.GetAdminUserInfo()
  2405. list, total, err := service.FindAllDrugStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, drug_category, startTime, endTime)
  2406. if err == nil {
  2407. c.ServeSuccessJSON(map[string]interface{}{
  2408. "list": list,
  2409. "total": total,
  2410. })
  2411. } else {
  2412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2413. }
  2414. }
  2415. func (this *StockDrugApiController) GetUserDetailInfo() {
  2416. order_id, _ := this.GetInt64("id")
  2417. if order_id <= 0 {
  2418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2419. return
  2420. }
  2421. adminUserInfo := this.GetAdminUserInfo()
  2422. userDetails, err, total := service.FindDrugStockUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  2423. if err == nil {
  2424. this.ServeSuccessJSON(map[string]interface{}{
  2425. "list": userDetails,
  2426. "total": total,
  2427. })
  2428. } else {
  2429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2430. return
  2431. }
  2432. }
  2433. func (this *StockDrugApiController) GetCancelDrugOrderPrint() {
  2434. orderId := this.GetString("order_id")
  2435. ids := strings.Split(orderId, ",")
  2436. orgId := this.GetAdminUserInfo().CurrentOrgId
  2437. list, _ := service.GetCancelDrugOrderPrint(ids, orgId)
  2438. this.ServeSuccessJSON(map[string]interface{}{
  2439. "list": list,
  2440. })
  2441. }
  2442. func (this *StockDrugApiController) GetDrugCancelExportList() {
  2443. orderId := this.GetString("order_id")
  2444. fmt.Println("order_id2323232323223", orderId)
  2445. ids := strings.Split(orderId, ",")
  2446. orgId := this.GetAdminUserInfo().CurrentOrgId
  2447. list, _ := service.GetDrugCancelExportList(ids, orgId)
  2448. this.ServeSuccessJSON(map[string]interface{}{
  2449. "list": list,
  2450. })
  2451. }