stock_in_api_controller.go 148KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655
  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. "github.com/jinzhu/gorm"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type StockManagerApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func StockManagerApiRegistRouters() {
  20. //入库管理和其他入库管理相关接口
  21. beego.Router("/api/warehouse/create", &StockManagerApiController{}, "post:CreateWarehouse")
  22. beego.Router("/api/warehouse/list", &StockManagerApiController{}, "get:GetWarehouseList")
  23. beego.Router("/api/warehouse/delete", &StockManagerApiController{}, "post:DeleteWarehouse")
  24. beego.Router("/api/warehouseinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseInfo")
  25. beego.Router("/api/warehouseinfo/list", &StockManagerApiController{}, "get:GetWarehouseInfoList")
  26. beego.Router("/api/warehouse/edit", &StockManagerApiController{}, "post:EditWarehouse")
  27. //退货管理和其他退货管理相关接口
  28. beego.Router("/api/salesreturn/create", &StockManagerApiController{}, "post:CreateSalesReturn")
  29. beego.Router("/api/salesreturn/delete", &StockManagerApiController{}, "post:DeleteSalesReturn")
  30. beego.Router("/api/salesreturninfo/delete", &StockManagerApiController{}, "post:DeleteSalesReturnInfo")
  31. beego.Router("/api/salesreturninfo/list", &StockManagerApiController{}, "get:GetSalesReturnInfoList")
  32. beego.Router("/api/salesreturn/list", &StockManagerApiController{}, "get:GetSalesReturnList")
  33. beego.Router("/api/salesreturn/edit", &StockManagerApiController{}, "post:EditReturnInfo")
  34. //出库管理和其他出库管理相关接口
  35. beego.Router("/api/warehouseout/create", &StockManagerApiController{}, "post:CreateWarehouseOut")
  36. beego.Router("/api/warehouseout/delete", &StockManagerApiController{}, "post:DeleteWarehouseOut")
  37. beego.Router("/api/warehouseoutinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseOutInfo")
  38. beego.Router("/api/warehouseout/list", &StockManagerApiController{}, "get:GetWarehouseOutList")
  39. beego.Router("/api/warehouseout/edit", &StockManagerApiController{}, "post:EditWarehouseOut")
  40. beego.Router("/api/warehouseout/info", &StockManagerApiController{}, "get:GetWarehouseOutInfoList")
  41. //出库退库管理和其他出库退库管理相关接口
  42. beego.Router("/api/cancelstock/create", &StockManagerApiController{}, "post:CreateCancelStock")
  43. beego.Router("/api/cancelstock/list", &StockManagerApiController{}, "get:GetCancelStockList")
  44. beego.Router("/api/cancelstock/info", &StockManagerApiController{}, "get:GetCancelStockInfoList")
  45. beego.Router("/api/cancelstock/delete", &StockManagerApiController{}, "post:DeleteCancelStock")
  46. beego.Router("/api/cancelstockinfo/delete", &StockManagerApiController{}, "post:DeleteCancelStockInfo")
  47. beego.Router("/api/cancelstockinfo/edit", &StockManagerApiController{}, "post:EditCancelStock")
  48. beego.Router("/api/cancelstockinfo/config", &StockManagerApiController{}, "get:GetCancelStockConfig")
  49. //库存相关全局配置
  50. beego.Router("/api/stock/config", &StockManagerApiController{}, "get:GetAllConfig")
  51. beego.Router("/api/return/config", &StockManagerApiController{}, "get:GetAllSalesReturnConfig")
  52. //库存查询
  53. beego.Router("/api/stock/query", &StockManagerApiController{}, "get:GetQueryInfo")
  54. beego.Router("/api/stock/detail", &StockManagerApiController{}, "get:GetDetailInfo")
  55. beego.Router("/api/warehouseout/user", &StockManagerApiController{}, "get:GetUserDetailInfo")
  56. beego.Router("/api/warehouseout/postsearchstock", &StockManagerApiController{}, "Get:PostSearchStock")
  57. beego.Router("/api/warehouseout/getoutstocktotalcount", &StockManagerApiController{}, "Get:GetOutStockTotalCount")
  58. beego.Router("/api/good/postgoodinformation", &StockManagerApiController{}, "Post:AddGoodInformation")
  59. beego.Router("/api/good/postdruginformation", &StockManagerApiController{}, "Post:AddDrugInformation")
  60. beego.Router("/api/good/initializtion", &StockManagerApiController{}, "Get:GetInitializtion")
  61. beego.Router("/api/good/getwarehouseorderinfolist", &StockManagerApiController{}, "Get:GetWarehouseOrderInfolist")
  62. beego.Router("/api/good/postsearchgoodlist", &StockManagerApiController{}, "Get:PostSearchGoodList")
  63. beego.Router("/api/good/getallstocklist", &StockManagerApiController{}, "Get:GetAllStockList")
  64. beego.Router("/api/stock/getstocklistbyid", &StockManagerApiController{}, "Get:GetStockListById")
  65. beego.Router("/api/stock/getstockoutlist", &StockManagerApiController{}, "Get:GetStockOutList")
  66. beego.Router("/api/good/getstockdrugcount", &StockManagerApiController{}, "Get:GetStockDrugCount")
  67. beego.Router("/api/good/getorderdetialbyorderid", &StockManagerApiController{}, "Get:GetOrderDetialByOrderId")
  68. beego.Router("/api/good/getorderdetaibyid", &StockManagerApiController{}, "Get:GetOrderDetailById")
  69. beego.Router("/api/good/getsingleoutorderdetail", &StockManagerApiController{}, "Get:GetSingleOutOrderDetail")
  70. beego.Router("/api/stock/getexportstocklist", &StockManagerApiController{}, "Get:GetExprotStockList")
  71. beego.Router("/api/stock/getoutexprotlist", &StockManagerApiController{}, "Get:GetOutExprotList")
  72. beego.Router("/api/stock/getsinglecancelorder", &StockManagerApiController{}, "Get:GetSingleCancelOrder")
  73. beego.Router("/api/stock/getcancelstockorderprint", &StockManagerApiController{}, "Get:GetCancelStockOrderPrint")
  74. beego.Router("/api/stock/getstockbatchnumber", &StockManagerApiController{}, "Get:GetStockBatchNumber")
  75. beego.Router("/api/stock/getstockflow", &StockManagerApiController{}, "Get:GetStockFlow")
  76. beego.Router("/api/cancel/getcancelexportlist", &StockManagerApiController{}, "Get:GetCancelExportList")
  77. }
  78. func (c *StockManagerApiController) CreateWarehouse() {
  79. warehousing_time := c.GetString("warehousing_time")
  80. types, _ := c.GetInt64("type", 0)
  81. ctime := time.Now().Unix()
  82. adminUserInfo := c.GetAdminUserInfo()
  83. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  84. if parseDateErr != nil {
  85. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  86. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  87. return
  88. }
  89. timeStr := time.Now().Format("2006-01-02")
  90. timeArr := strings.Split(timeStr, "-")
  91. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  92. total = total + 1
  93. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  94. operation_time := time.Now().Unix()
  95. creater := adminUserInfo.AdminUser.Id
  96. warehousing := models.Warehousing{
  97. WarehousingOrder: warehousing_order,
  98. OperationTime: operation_time,
  99. OrgId: adminUserInfo.CurrentOrgId,
  100. Creater: creater,
  101. Ctime: ctime,
  102. Status: 1,
  103. WarehousingTime: warehousingDate.Unix(),
  104. Type: types,
  105. }
  106. service.AddSigleWarehouse(&warehousing)
  107. dataBody := make(map[string]interface{}, 0)
  108. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  109. if err != nil {
  110. utils.ErrorLog(err.Error())
  111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  112. return
  113. }
  114. var warehousingInfo []*models.WarehousingInfo
  115. var stockFlow []*models.VmStockFlow
  116. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  117. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  118. if len(thisStockIn) > 0 {
  119. for _, item := range thisStockIn {
  120. items := item.(map[string]interface{})
  121. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  122. utils.ErrorLog("good_id")
  123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  124. return
  125. }
  126. good_id := int64(items["good_id"].(float64))
  127. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  128. utils.ErrorLog("good_type_id")
  129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  130. return
  131. }
  132. good_type_id := int64(items["good_type_id"].(float64))
  133. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  134. utils.ErrorLog("warehousing_count")
  135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  136. return
  137. }
  138. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  139. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  140. utils.ErrorLog("price")
  141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  142. return
  143. }
  144. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  145. total := float64(warehousing_count) * price
  146. var productDates int64
  147. var expiryDates int64
  148. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  149. expiryDates = 0
  150. } else {
  151. if len(items["expiry_date"].(string)) == 0 {
  152. expiryDates = 0
  153. } else {
  154. expiryDate, _ := items["expiry_date"].(string)
  155. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  156. expiryDates = expiry_date.Unix()
  157. }
  158. }
  159. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  160. productDates = 0
  161. } else {
  162. if len(items["product_date"].(string)) == 0 {
  163. productDates = 0
  164. } else {
  165. productDate, _ := items["product_date"].(string)
  166. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  167. productDates = product_date.Unix()
  168. }
  169. }
  170. number, _ := items["number"].(string)
  171. remark, _ := items["remark"].(string)
  172. manufacturer := int64(items["manufacturer"].(float64))
  173. dealer := int64(items["dealer"].(float64))
  174. license_number, _ := items["license_number"].(string)
  175. //入库单表格
  176. warehouseInfo := &models.WarehousingInfo{
  177. WarehousingOrder: warehousing.WarehousingOrder,
  178. WarehousingId: warehousing.ID,
  179. GoodId: good_id,
  180. Number: number,
  181. GoodTypeId: good_type_id,
  182. ProductDate: productDates,
  183. ExpiryDate: expiryDates,
  184. WarehousingCount: warehousing_count,
  185. Price: price,
  186. TotalPrice: total,
  187. Status: 1,
  188. Ctime: ctime,
  189. Remark: remark,
  190. OrgId: adminUserInfo.CurrentOrgId,
  191. Type: types,
  192. Manufacturer: manufacturer,
  193. StockCount: warehousing_count,
  194. Dealer: dealer,
  195. LicenseNumber: license_number,
  196. }
  197. warehousingInfo = append(warehousingInfo, warehouseInfo)
  198. flow := &models.VmStockFlow{
  199. WarehousingOrder: warehousing.WarehousingOrder,
  200. WarehousingId: warehousing.ID,
  201. GoodId: good_id,
  202. Number: number,
  203. ProductDate: productDates,
  204. ExpireDate: expiryDates,
  205. Count: warehousing_count,
  206. Price: price,
  207. Status: 1,
  208. Ctime: ctime,
  209. UserOrgId: adminUserInfo.CurrentOrgId,
  210. Manufacturer: manufacturer,
  211. Dealer: dealer,
  212. LicenseNumber: license_number,
  213. IsEdit: 1,
  214. Creator: adminUserInfo.AdminUser.Id,
  215. SystemTime: operation_time,
  216. ConsumableType: 1,
  217. WarehousingDetailId: warehouseInfo.ID,
  218. }
  219. stockFlow = append(stockFlow, flow)
  220. }
  221. }
  222. }
  223. //入库单创建成功
  224. errs := service.CreateWarehousingInfo(warehousingInfo)
  225. //创建入库单流水
  226. service.CreateStockFlow(stockFlow)
  227. info, _ := service.FindLastWarehousingInfo(warehousing.WarehousingOrder)
  228. if errs != nil {
  229. utils.ErrorLog(errs.Error())
  230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  231. return
  232. }
  233. c.ServeSuccessJSON(map[string]interface{}{
  234. "msg": "入库成功",
  235. "warehousing_order": warehousing_order,
  236. "info": info,
  237. })
  238. }
  239. func (c *StockManagerApiController) GetWarehouseList() {
  240. page, _ := c.GetInt64("page", -1)
  241. limit, _ := c.GetInt64("limit", -1)
  242. start_time := c.GetString("start_time")
  243. end_time := c.GetString("end_time")
  244. types, _ := c.GetInt64("type", 0)
  245. keywords := c.GetString("keywords")
  246. timeLayout := "2006-01-02"
  247. loc, _ := time.LoadLocation("Local")
  248. var startTime int64
  249. if len(start_time) > 0 {
  250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  251. if err != nil {
  252. fmt.Println(err)
  253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  254. return
  255. }
  256. startTime = theTime.Unix()
  257. }
  258. var endTime int64
  259. if len(end_time) > 0 {
  260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  261. if err != nil {
  262. utils.ErrorLog(err.Error())
  263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  264. return
  265. }
  266. endTime = theTime.Unix()
  267. }
  268. adminUserInfo := c.GetAdminUserInfo()
  269. var ids []int64
  270. var goodids []int64
  271. //查询商品名称
  272. if len(keywords) > 0 {
  273. //查询商品名称
  274. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  275. for _, item := range list {
  276. goodids = append(goodids, item.ID)
  277. //入库详情但里面查询
  278. }
  279. if len(goodids) > 0 {
  280. info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  281. for _, it := range info {
  282. ids = append(ids, it.WarehousingId)
  283. }
  284. }
  285. }
  286. warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  287. if err == nil {
  288. c.ServeSuccessJSON(map[string]interface{}{
  289. "list": warehouseList,
  290. "total": total,
  291. })
  292. } else {
  293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  294. }
  295. }
  296. func (c *StockManagerApiController) GetWarehouseInfoList() {
  297. id := c.GetString("id")
  298. idArray := strings.Split(id, ",")
  299. warehousing, err := service.FindWarehousingByIdOne(idArray)
  300. if err != nil {
  301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  302. return
  303. }
  304. var ids []int64
  305. for _, item := range warehousing {
  306. ids = append(ids, item.ID)
  307. }
  308. warehousingInfo, err := service.FindWarehousingInfoByIdOne(ids)
  309. if err == nil {
  310. c.ServeSuccessJSON(map[string]interface{}{
  311. "info": warehousingInfo,
  312. "warehousing": warehousing,
  313. })
  314. } else {
  315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  316. }
  317. }
  318. func (c *StockManagerApiController) EditWarehouse() {
  319. warehousing_time := c.GetString("warehousing_time")
  320. id, _ := c.GetInt64("id", 0)
  321. types, _ := c.GetInt64("type", 0)
  322. if id == 0 {
  323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  324. return
  325. }
  326. ctime := time.Now().Unix()
  327. mtime := time.Now().Unix()
  328. adminUserInfo := c.GetAdminUserInfo()
  329. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  330. if parseDateErr != nil {
  331. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  333. return
  334. }
  335. warehouse, _ := service.FindWarehousingById(id)
  336. warehousing := models.Warehousing{
  337. WarehousingOrder: warehouse.WarehousingOrder,
  338. OrgId: adminUserInfo.CurrentOrgId,
  339. Modifier: adminUserInfo.AdminUser.Id,
  340. Mtime: mtime,
  341. Status: 1,
  342. WarehousingTime: warehousingDate.Unix(),
  343. Type: warehouse.Type,
  344. }
  345. service.EditWarehousing(warehousing)
  346. dataBody := make(map[string]interface{}, 0)
  347. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  348. if err != nil {
  349. utils.ErrorLog(err.Error())
  350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  351. return
  352. }
  353. var warehousingInfo []*models.WarehousingInfo
  354. var upDateWarehousingInfo []*models.WarehousingInfo
  355. var stockFlow []*models.VmStockFlow
  356. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  357. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  358. if len(thisStockIn) > 0 {
  359. for _, item := range thisStockIn {
  360. items := item.(map[string]interface{})
  361. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  362. utils.ErrorLog("good_id")
  363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  364. return
  365. }
  366. good_id := int64(items["good_id"].(float64))
  367. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  368. utils.ErrorLog("good_type_id")
  369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  370. return
  371. }
  372. good_type_id := int64(items["good_type_id"].(float64))
  373. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  374. utils.ErrorLog("warehousing_count")
  375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  376. return
  377. }
  378. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  379. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  380. utils.ErrorLog("price")
  381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  382. return
  383. }
  384. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  385. total := float64(warehousing_count) * price
  386. var productDates int64
  387. var expiryDates int64
  388. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  389. expiryDates = 0
  390. } else {
  391. if len(items["expiry_date"].(string)) == 0 {
  392. expiryDates = 0
  393. } else {
  394. expiryDate, _ := items["expiry_date"].(string)
  395. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  396. expiryDates = expiry_date.Unix()
  397. }
  398. }
  399. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  400. productDates = 0
  401. } else {
  402. if len(items["product_date"].(string)) == 0 {
  403. productDates = 0
  404. } else {
  405. productDate, _ := items["product_date"].(string)
  406. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  407. productDates = product_date.Unix()
  408. }
  409. }
  410. number, _ := items["number"].(string)
  411. remark, _ := items["remark"].(string)
  412. manufacturer := int64(items["manufacturer"].(float64))
  413. dealer := int64(items["dealer"].(float64))
  414. license_number, _ := items["license_number"].(string)
  415. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  416. utils.ErrorLog("id")
  417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  418. return
  419. }
  420. id := int64(items["id"].(float64))
  421. if id == 0 {
  422. warehouseInfo := &models.WarehousingInfo{
  423. WarehousingOrder: warehouse.WarehousingOrder,
  424. WarehousingId: warehouse.ID,
  425. GoodId: good_id,
  426. Number: number,
  427. GoodTypeId: good_type_id,
  428. ProductDate: productDates,
  429. ExpiryDate: expiryDates,
  430. WarehousingCount: warehousing_count,
  431. Price: price,
  432. TotalPrice: total,
  433. Status: 1,
  434. Ctime: ctime,
  435. Remark: remark,
  436. OrgId: adminUserInfo.CurrentOrgId,
  437. Type: types,
  438. Manufacturer: manufacturer,
  439. Dealer: dealer,
  440. StockCount: warehousing_count,
  441. LicenseNumber: license_number,
  442. }
  443. warehousingInfo = append(warehousingInfo, warehouseInfo)
  444. flow := &models.VmStockFlow{
  445. WarehousingOrder: warehousing.WarehousingOrder,
  446. WarehousingId: warehousing.ID,
  447. GoodId: good_id,
  448. Number: number,
  449. ProductDate: productDates,
  450. ExpireDate: expiryDates,
  451. Count: warehousing_count,
  452. Price: price,
  453. Status: 1,
  454. Ctime: ctime,
  455. UserOrgId: adminUserInfo.CurrentOrgId,
  456. Manufacturer: manufacturer,
  457. Dealer: dealer,
  458. LicenseNumber: license_number,
  459. IsEdit: 1,
  460. Creator: adminUserInfo.AdminUser.Id,
  461. SystemTime: ctime,
  462. ConsumableType: 1,
  463. WarehousingDetailId: warehouseInfo.ID,
  464. }
  465. stockFlow = append(stockFlow, flow)
  466. } else {
  467. warehouseInfo := &models.WarehousingInfo{
  468. ID: id,
  469. WarehousingOrder: warehouse.WarehousingOrder,
  470. WarehousingId: warehouse.ID,
  471. GoodId: good_id,
  472. Number: number,
  473. GoodTypeId: good_type_id,
  474. ProductDate: productDates,
  475. ExpiryDate: expiryDates,
  476. WarehousingCount: warehousing_count,
  477. Price: price,
  478. TotalPrice: total,
  479. Status: 1,
  480. Ctime: ctime,
  481. Remark: remark,
  482. OrgId: adminUserInfo.CurrentOrgId,
  483. Type: types,
  484. Manufacturer: manufacturer,
  485. Dealer: dealer,
  486. StockCount: warehousing_count,
  487. LicenseNumber: license_number,
  488. }
  489. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  490. flow := &models.VmStockFlow{
  491. WarehousingOrder: warehousing.WarehousingOrder,
  492. WarehousingId: warehousing.ID,
  493. GoodId: good_id,
  494. Number: number,
  495. ProductDate: productDates,
  496. ExpireDate: expiryDates,
  497. Count: warehousing_count,
  498. Price: price,
  499. Status: 1,
  500. Ctime: ctime,
  501. UserOrgId: adminUserInfo.CurrentOrgId,
  502. Manufacturer: manufacturer,
  503. Dealer: dealer,
  504. LicenseNumber: license_number,
  505. IsEdit: 2,
  506. Creator: adminUserInfo.AdminUser.Id,
  507. SystemTime: ctime,
  508. ConsumableType: 1,
  509. WarehousingDetailId: warehouseInfo.ID,
  510. }
  511. stockFlow = append(stockFlow, flow)
  512. }
  513. }
  514. }
  515. }
  516. var errs error
  517. if len(warehousingInfo) > 0 {
  518. errs = service.CreateWarehousingInfo(warehousingInfo)
  519. service.CreateStockFlow(stockFlow)
  520. }
  521. if len(upDateWarehousingInfo) > 0 {
  522. for _, item := range upDateWarehousingInfo {
  523. var total int64
  524. var all_total int64
  525. //获取该批次该型号的库存
  526. info, _ := service.GetLastWarehousingById(item.WarehousingId, item.GoodId)
  527. //判断 该批次的入库数量
  528. total = item.WarehousingCount - info.WarehousingCount
  529. all_total = info.StockCount + total
  530. item.StockCount = all_total
  531. errs = service.UpDateWarehousingInfo(item)
  532. service.CreateStockFlow(stockFlow)
  533. }
  534. }
  535. if errs != nil {
  536. utils.ErrorLog(errs.Error())
  537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  538. return
  539. }
  540. c.ServeSuccessJSON(map[string]interface{}{
  541. "msg": "编辑成功",
  542. })
  543. }
  544. func (c *StockManagerApiController) DeleteWarehouse() {
  545. ids := c.GetString("ids")
  546. if len(ids) == 0 {
  547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  548. return
  549. }
  550. idArray := strings.Split(ids, ",")
  551. err := service.DeleteWarehouse(idArray)
  552. if err != nil {
  553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  554. } else {
  555. c.ServeSuccessJSON(map[string]interface{}{
  556. "msg": "删除成功",
  557. })
  558. }
  559. }
  560. func (c *StockManagerApiController) DeleteWarehouseInfo() {
  561. id, _ := c.GetInt64("id", 0)
  562. if id == 0 {
  563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  564. return
  565. }
  566. err := service.UpDateWarehouseStatus(id)
  567. if err != nil {
  568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  569. } else {
  570. c.ServeSuccessJSON(map[string]interface{}{
  571. "msg": "删除成功",
  572. })
  573. }
  574. }
  575. func (c *StockManagerApiController) CreateSalesReturn() {
  576. dealer_id, _ := c.GetInt64("dealer_id", 0)
  577. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  578. sales_return_time := c.GetString("time")
  579. types, _ := c.GetInt64("type", 0)
  580. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  581. if parseDateErr != nil {
  582. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  584. return
  585. }
  586. adminUserInfo := c.GetAdminUserInfo()
  587. operation_time := time.Now().Unix()
  588. creater := adminUserInfo.AdminUser.Id
  589. ctime := time.Now().Unix()
  590. timeStr := time.Now().Format("2006-01-02")
  591. timeArr := strings.Split(timeStr, "-")
  592. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  593. total = total + 1
  594. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  595. salesReturn := models.SalesReturn{
  596. OrderNumber: orderNumber,
  597. OperaTime: operation_time,
  598. OrgId: adminUserInfo.CurrentOrgId,
  599. Creater: creater,
  600. Ctime: ctime,
  601. Status: 1,
  602. ReturnTime: salesReturnDate.Unix(),
  603. Dealer: dealer_id,
  604. Manufacturer: manufacturer_id,
  605. Type: types,
  606. }
  607. service.AddSigleSalesReturn(&salesReturn)
  608. dataBody := make(map[string]interface{}, 0)
  609. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  610. if err != nil {
  611. utils.ErrorLog(err.Error())
  612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  613. return
  614. }
  615. var salesReturnInfos []*models.SalesReturnInfo
  616. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  617. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  618. if len(thisStockIn) > 0 {
  619. for _, item := range thisStockIn {
  620. items := item.(map[string]interface{})
  621. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  622. utils.ErrorLog("good_id")
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  624. return
  625. }
  626. good_id := int64(items["good_id"].(float64))
  627. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  628. utils.ErrorLog("good_type_id")
  629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  630. return
  631. }
  632. good_type_id := int64(items["good_type_id"].(float64))
  633. return_count, _ := items["return_count"].(string)
  634. if len(return_count) == 0 {
  635. utils.ErrorLog("len(return_count) == 0")
  636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  637. return
  638. }
  639. count, _ := strconv.ParseInt(return_count, 10, 64)
  640. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  641. total := float64(count) * price
  642. salesReturnInfo := &models.SalesReturnInfo{
  643. OrderNumber: salesReturn.OrderNumber,
  644. SalesReturnId: salesReturn.ID,
  645. GoodId: good_id,
  646. GoodTypeId: good_type_id,
  647. Count: count,
  648. Price: price,
  649. Total: total,
  650. Status: 1,
  651. Ctime: ctime,
  652. OrgId: adminUserInfo.CurrentOrgId,
  653. Type: types,
  654. Manufacturer: manufacturer_id,
  655. Dealer: dealer_id,
  656. }
  657. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  658. }
  659. }
  660. }
  661. errs := service.CreateSalesReturnInfo(salesReturnInfos)
  662. if errs != nil {
  663. utils.ErrorLog(errs.Error())
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  665. return
  666. }
  667. c.ServeSuccessJSON(map[string]interface{}{
  668. "msg": "退货成功",
  669. })
  670. }
  671. func (c *StockManagerApiController) GetSalesReturnList() {
  672. page, _ := c.GetInt64("page", -1)
  673. limit, _ := c.GetInt64("limit", -1)
  674. start_time := c.GetString("start_time")
  675. end_time := c.GetString("end_time")
  676. types, _ := c.GetInt64("type", 0)
  677. keywords := c.GetString("keywords")
  678. timeLayout := "2006-01-02"
  679. loc, _ := time.LoadLocation("Local")
  680. var startTime int64
  681. if len(start_time) > 0 {
  682. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  683. if err != nil {
  684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  685. return
  686. }
  687. startTime = theTime.Unix()
  688. }
  689. var endTime int64
  690. if len(end_time) > 0 {
  691. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  692. if err != nil {
  693. utils.ErrorLog(err.Error())
  694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  695. return
  696. }
  697. endTime = theTime.Unix()
  698. }
  699. adminUserInfo := c.GetAdminUserInfo()
  700. returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  701. if err == nil {
  702. c.ServeSuccessJSON(map[string]interface{}{
  703. "list": returnList,
  704. "total": total,
  705. })
  706. } else {
  707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  708. }
  709. }
  710. func (this *StockManagerApiController) DeleteSalesReturn() {
  711. ids := this.GetString("ids")
  712. if len(ids) == 0 {
  713. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  714. return
  715. }
  716. idArray := strings.Split(ids, ",")
  717. err := service.DeleteSalesReturn(idArray)
  718. if err != nil {
  719. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  720. } else {
  721. this.ServeSuccessJSON(map[string]interface{}{
  722. "msg": "删除成功",
  723. })
  724. }
  725. }
  726. func (this *StockManagerApiController) DeleteSalesReturnInfo() {
  727. id, _ := this.GetInt64("id", 0)
  728. fmt.Println(id)
  729. if id == 0 {
  730. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  731. return
  732. }
  733. err := service.UpDateSaleReturnStatus(id)
  734. if err != nil {
  735. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  736. } else {
  737. this.ServeSuccessJSON(map[string]interface{}{
  738. "msg": "删除成功",
  739. })
  740. }
  741. }
  742. func (this *StockManagerApiController) GetSalesReturnInfoList() {
  743. id, _ := this.GetInt64("id", 0)
  744. list, _ := service.FindAllSalesReturnInfoById(id)
  745. salesReturn, _ := service.FindAllSalesReturnById(id)
  746. this.ServeSuccessJSON(map[string]interface{}{
  747. "list": list,
  748. "salesReturn": salesReturn,
  749. })
  750. }
  751. func (c *StockManagerApiController) EditReturnInfo() {
  752. return_time := c.GetString("return_time")
  753. id, _ := c.GetInt64("id", 0)
  754. types, _ := c.GetInt64("type", 0)
  755. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  756. dealer_id, _ := c.GetInt64("dealer_id", 0)
  757. if id == 0 {
  758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  759. return
  760. }
  761. ctime := time.Now().Unix()
  762. mtime := time.Now().Unix()
  763. adminUserInfo := c.GetAdminUserInfo()
  764. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  765. if parseDateErr != nil {
  766. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  768. return
  769. }
  770. salesReturns, _ := service.FindSalesReturnById(id)
  771. sales := models.SalesReturn{
  772. ID: salesReturns.ID,
  773. Mtime: mtime,
  774. ReturnTime: returnDate.Unix(),
  775. Manufacturer: manufacturer_id,
  776. Dealer: dealer_id,
  777. }
  778. service.EditSaleReturn(sales)
  779. dataBody := make(map[string]interface{}, 0)
  780. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  781. if err != nil {
  782. utils.ErrorLog(err.Error())
  783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  784. return
  785. }
  786. var returnInfos []*models.SalesReturnInfo
  787. var upDateReturnInfos []*models.SalesReturnInfo
  788. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  789. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  790. if len(thisStockIn) > 0 {
  791. for _, item := range thisStockIn {
  792. items := item.(map[string]interface{})
  793. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  794. utils.ErrorLog("good_id")
  795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  796. return
  797. }
  798. good_id := int64(items["good_id"].(float64))
  799. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  800. utils.ErrorLog("good_type_id")
  801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  802. return
  803. }
  804. good_type_id := int64(items["good_type_id"].(float64))
  805. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  806. utils.ErrorLog("count")
  807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  808. return
  809. }
  810. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  811. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  812. utils.ErrorLog("id")
  813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  814. return
  815. }
  816. id := int64(items["id"].(float64))
  817. if id == 0 {
  818. returnInfo := &models.SalesReturnInfo{
  819. GoodId: good_id,
  820. GoodTypeId: good_type_id,
  821. Count: count,
  822. Status: 1,
  823. Ctime: ctime,
  824. OrgId: adminUserInfo.CurrentOrgId,
  825. OrderNumber: sales.OrderNumber,
  826. SalesReturnId: sales.ID,
  827. Mtime: time.Now().Unix(),
  828. Type: types,
  829. Manufacturer: manufacturer_id,
  830. Dealer: dealer_id,
  831. }
  832. returnInfos = append(returnInfos, returnInfo)
  833. } else {
  834. returnInfo := &models.SalesReturnInfo{
  835. ID: id,
  836. GoodId: good_id,
  837. GoodTypeId: good_type_id,
  838. Count: count,
  839. Status: 1,
  840. Ctime: ctime,
  841. OrgId: adminUserInfo.CurrentOrgId,
  842. OrderNumber: sales.OrderNumber,
  843. SalesReturnId: sales.ID,
  844. Mtime: time.Now().Unix(),
  845. Type: types,
  846. Manufacturer: manufacturer_id,
  847. Dealer: dealer_id,
  848. }
  849. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  850. }
  851. }
  852. }
  853. }
  854. var errs error
  855. if len(returnInfos) > 0 {
  856. errs = service.CreateSalesReturnInfo(returnInfos)
  857. }
  858. if len(upDateReturnInfos) > 0 {
  859. for _, item := range upDateReturnInfos {
  860. errs = service.UpDateSalesReturnInfo(item)
  861. }
  862. }
  863. if errs != nil {
  864. utils.ErrorLog(errs.Error())
  865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  866. return
  867. }
  868. c.ServeSuccessJSON(map[string]interface{}{
  869. "msg": "编辑成功",
  870. })
  871. }
  872. func (c *StockManagerApiController) CreateWarehouseOut() {
  873. types, _ := c.GetInt64("type", 0)
  874. ctime := time.Now().Unix()
  875. adminUserInfo := c.GetAdminUserInfo()
  876. warehousing_out_time := c.GetString("warehousing_out_time")
  877. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  878. if parseDateErr != nil {
  879. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  881. return
  882. }
  883. timeStr := time.Now().Format("2006-01-02")
  884. timeArr := strings.Split(timeStr, "-")
  885. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  886. total = total + 1
  887. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  888. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  889. number = number + total
  890. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  891. operation_time := time.Now().Unix()
  892. creater := adminUserInfo.AdminUser.Id
  893. warehouseOut := models.WarehouseOut{
  894. WarehouseOutOrderNumber: warehousing_out_order,
  895. OperationTime: operation_time,
  896. OrgId: adminUserInfo.CurrentOrgId,
  897. Creater: creater,
  898. Ctime: ctime,
  899. Status: 1,
  900. WarehouseOutTime: warehousingOutDate.Unix(),
  901. Type: types,
  902. }
  903. dataBody := make(map[string]interface{}, 0)
  904. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  905. if err != nil {
  906. utils.ErrorLog(err.Error())
  907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  908. return
  909. }
  910. var warehousingOutInfo []*models.WarehouseOutInfo
  911. var beforePrepares []*models.DialysisBeforePrepareGoods
  912. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  913. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  914. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  915. if len(thisStockIn) > 0 {
  916. for _, item := range thisStockIn {
  917. items := item.(map[string]interface{})
  918. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  919. utils.ErrorLog("good_id")
  920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  921. return
  922. }
  923. good_id := int64(items["good_id"].(float64))
  924. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  925. utils.ErrorLog("good_type_id")
  926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  927. return
  928. }
  929. good_type_id := int64(items["good_type_id"].(float64))
  930. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  931. utils.ErrorLog("count")
  932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  933. return
  934. }
  935. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  936. utils.ErrorLog("price")
  937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  938. return
  939. }
  940. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  941. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  942. total := float64(count) * price
  943. remark := items["remark"].(string)
  944. manufacturer := int64(items["manufacturer"].(float64))
  945. dealer := int64(items["dealer"].(float64))
  946. number := items["number"].(string)
  947. expiry_date := items["expiry_date"].(string)
  948. timeLayout := "2006-01-02"
  949. loc, _ := time.LoadLocation("Local")
  950. var expiryDate int64
  951. if len(expiry_date) > 0 {
  952. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  953. if err != nil {
  954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  955. return
  956. }
  957. expiryDate = theTime.Unix()
  958. }
  959. product_date := items["product_date"].(string)
  960. var productDate int64
  961. if len(product_date) > 0 {
  962. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  963. if err != nil {
  964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  965. return
  966. }
  967. productDate = theTime.Unix()
  968. }
  969. license_number := items["license_number"].(string)
  970. warehouseOutInfo := &models.WarehouseOutInfo{
  971. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  972. WarehouseOutId: warehouseOut.ID,
  973. GoodId: good_id,
  974. GoodTypeId: good_type_id,
  975. Count: count,
  976. Price: price,
  977. TotalPrice: total,
  978. Status: 1,
  979. Ctime: ctime,
  980. Remark: remark,
  981. OrgId: adminUserInfo.CurrentOrgId,
  982. Type: types,
  983. Manufacturer: manufacturer,
  984. Number: number,
  985. ExpiryDate: expiryDate,
  986. ProductDate: productDate,
  987. Dealer: dealer,
  988. LicenseNumber: license_number,
  989. }
  990. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  991. prepareGoods := &models.DialysisBeforePrepareGoods{
  992. GoodTypeId: good_type_id,
  993. GoodId: good_id,
  994. Count: count,
  995. }
  996. beforePrepares = append(beforePrepares, prepareGoods)
  997. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  998. GoodTypeId: good_type_id,
  999. GoodId: good_id,
  1000. Count: count,
  1001. }
  1002. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  1003. }
  1004. }
  1005. }
  1006. //出库逻辑
  1007. for _, item := range warehousingOutInfo {
  1008. //查询库存
  1009. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
  1010. fmt.Println("库存数量组吗", warehouse.Count)
  1011. if item.Count > warehouse.Count {
  1012. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  1013. c.ServeSuccessJSON(map[string]interface{}{
  1014. "msg": "1",
  1015. "good_name": goodObj.GoodName,
  1016. "specification_name": goodObj.SpecificationName,
  1017. })
  1018. return
  1019. } else {
  1020. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  1021. if errcodes == gorm.ErrRecordNotFound {
  1022. service.AddSigleWarehouseOut(&warehouseOut)
  1023. }
  1024. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
  1025. if parseDateErr != nil {
  1026. utils.ErrorLog(parseDateErr.Error())
  1027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1028. return
  1029. }
  1030. c.ServeSuccessJSON(map[string]interface{}{
  1031. "msg": "2",
  1032. "good_name": "",
  1033. "specification_name": "",
  1034. })
  1035. }
  1036. }
  1037. //errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
  1038. //info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
  1039. }
  1040. func (c *StockManagerApiController) GetWarehouseOutList() {
  1041. page, _ := c.GetInt64("page", -1)
  1042. limit, _ := c.GetInt64("limit", -1)
  1043. start_time := c.GetString("start_time")
  1044. end_time := c.GetString("end_time")
  1045. types, _ := c.GetInt64("type", 0)
  1046. keywords := c.GetString("keywords")
  1047. timeLayout := "2006-01-02"
  1048. loc, _ := time.LoadLocation("Local")
  1049. var startTime int64
  1050. if len(start_time) > 0 {
  1051. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1052. if err != nil {
  1053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1054. return
  1055. }
  1056. startTime = theTime.Unix()
  1057. }
  1058. var endTime int64
  1059. if len(end_time) > 0 {
  1060. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1061. if err != nil {
  1062. utils.ErrorLog(err.Error())
  1063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1064. return
  1065. }
  1066. endTime = theTime.Unix()
  1067. }
  1068. adminUserInfo := c.GetAdminUserInfo()
  1069. var ids []int64
  1070. var goodids []int64
  1071. if len(keywords) > 0 {
  1072. //查询商品名称
  1073. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  1074. for _, item := range list {
  1075. goodids = append(goodids, item.ID)
  1076. }
  1077. if len(goodids) > 0 {
  1078. //出库详情但里面查询
  1079. info, _ := service.GetWarehoureOrderOutByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  1080. for _, it := range info {
  1081. ids = append(ids, it.WarehouseOutId)
  1082. }
  1083. }
  1084. }
  1085. warehouseOutList, total, err := service.FindAllWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  1086. fmt.Println(err)
  1087. if err == nil {
  1088. c.ServeSuccessJSON(map[string]interface{}{
  1089. "list": warehouseOutList,
  1090. "total": total,
  1091. })
  1092. } else {
  1093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1094. }
  1095. }
  1096. func (c *StockManagerApiController) DeleteWarehouseOut() {
  1097. ids := c.GetString("ids")
  1098. if len(ids) == 0 {
  1099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1100. return
  1101. }
  1102. idArray := strings.Split(ids, ",")
  1103. err := service.DeleteWarehouseOut(idArray)
  1104. if err != nil {
  1105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1106. } else {
  1107. c.ServeSuccessJSON(map[string]interface{}{
  1108. "msg": "删除成功",
  1109. })
  1110. }
  1111. }
  1112. func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
  1113. id, _ := this.GetInt64("id", 0)
  1114. fmt.Println(id)
  1115. if id == 0 {
  1116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1117. return
  1118. }
  1119. err := service.UpDateWarehouseOutStatus(id)
  1120. if err != nil {
  1121. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1122. } else {
  1123. this.ServeSuccessJSON(map[string]interface{}{
  1124. "msg": "删除成功",
  1125. })
  1126. }
  1127. }
  1128. func (c *StockManagerApiController) GetWarehouseOutInfoList() {
  1129. id, _ := c.GetInt64("id", 0)
  1130. warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
  1131. warehouseOut, _ := service.FindWareHouseOutById(id)
  1132. adminUserInfo := c.GetAdminUserInfo()
  1133. orgId := adminUserInfo.CurrentOrgId
  1134. wareoutList, _ := service.GetWareOutInfoById(id, orgId)
  1135. c.ServeSuccessJSON(map[string]interface{}{
  1136. "list": warehouseOutInfo,
  1137. "info": warehouseOut,
  1138. "wareoutList": wareoutList,
  1139. })
  1140. }
  1141. func (c *StockManagerApiController) EditWarehouseOut() {
  1142. warehouse_out_time := c.GetString("warehouse_out_time")
  1143. id, _ := c.GetInt64("id", 0)
  1144. types, _ := c.GetInt64("type", 0)
  1145. if id == 0 {
  1146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1147. return
  1148. }
  1149. ctime := time.Now().Unix()
  1150. mtime := time.Now().Unix()
  1151. adminUserInfo := c.GetAdminUserInfo()
  1152. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1153. if parseDateErr != nil {
  1154. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1156. return
  1157. }
  1158. warehouseOut, _ := service.FindWareHouseOutById(id)
  1159. tempWarehouseOut := models.WarehouseOut{
  1160. ID: warehouseOut.ID,
  1161. Mtime: mtime,
  1162. WarehouseOutTime: warehouseOutDate.Unix(),
  1163. }
  1164. service.EditWarehouseOut(tempWarehouseOut)
  1165. dataBody := make(map[string]interface{}, 0)
  1166. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1167. if err != nil {
  1168. utils.ErrorLog(err.Error())
  1169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1170. return
  1171. }
  1172. var warehousingOutInfo []*models.WarehouseOutInfo
  1173. var upDateWarehouseOutInfos []*models.WarehouseOutInfo
  1174. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1175. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1176. if len(thisStockOut) > 0 {
  1177. for _, item := range thisStockOut {
  1178. items := item.(map[string]interface{})
  1179. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1180. utils.ErrorLog("good_id")
  1181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1182. return
  1183. }
  1184. good_id := int64(items["good_id"].(float64))
  1185. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1186. utils.ErrorLog("good_type_id")
  1187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1188. return
  1189. }
  1190. good_type_id := int64(items["good_type_id"].(float64))
  1191. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1192. utils.ErrorLog("count")
  1193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1194. return
  1195. }
  1196. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1197. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1198. utils.ErrorLog("price")
  1199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1200. return
  1201. }
  1202. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1203. total := float64(count) * price
  1204. remark := items["remark"].(string)
  1205. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1206. utils.ErrorLog("id")
  1207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1208. return
  1209. }
  1210. id := int64(items["id"].(float64))
  1211. manufacturer := int64(items["manufacturer"].(float64))
  1212. dealer := int64(items["dealer"].(float64))
  1213. number := items["number"].(string)
  1214. license_number := items["license_number"].(string)
  1215. timeLayout := "2006-01-02"
  1216. loc, _ := time.LoadLocation("Local")
  1217. expiry_date := items["expiry_date"].(string)
  1218. var expiryDate int64
  1219. if len(expiry_date) > 0 {
  1220. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1221. if err != nil {
  1222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1223. return
  1224. }
  1225. expiryDate = theTime.Unix()
  1226. }
  1227. product_date := items["product_date"].(string)
  1228. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1229. var productDate int64
  1230. if len(product_date) > 0 {
  1231. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1232. if err != nil {
  1233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1234. return
  1235. }
  1236. productDate = theTime.Unix()
  1237. }
  1238. if id == 0 {
  1239. warehouseOutInfo := &models.WarehouseOutInfo{
  1240. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1241. WarehouseOutId: warehouseOut.ID,
  1242. GoodId: good_id,
  1243. GoodTypeId: good_type_id,
  1244. Count: count,
  1245. Price: price,
  1246. TotalPrice: total,
  1247. Status: 1,
  1248. Ctime: ctime,
  1249. Remark: remark,
  1250. OrgId: adminUserInfo.CurrentOrgId,
  1251. Type: types,
  1252. IsSys: 0,
  1253. SysRecordTime: 0,
  1254. Number: number,
  1255. ExpiryDate: expiryDate,
  1256. ProductDate: productDate,
  1257. Dealer: dealer,
  1258. Manufacturer: manufacturer,
  1259. LicenseNumber: license_number,
  1260. ConsumableType: 1,
  1261. WarehouseInfotId: warehouse_info_id,
  1262. }
  1263. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1264. } else {
  1265. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1266. utils.ErrorLog("is_sys")
  1267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1268. return
  1269. }
  1270. is_sys := int64(items["is_sys"].(float64))
  1271. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1272. utils.ErrorLog("sys_record_time")
  1273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1274. return
  1275. }
  1276. sys_record_time := int64(items["sys_record_time"].(float64))
  1277. warehouseOutInfo := &models.WarehouseOutInfo{
  1278. ID: id,
  1279. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1280. WarehouseOutId: warehouseOut.ID,
  1281. GoodId: good_id,
  1282. GoodTypeId: good_type_id,
  1283. Count: count,
  1284. Price: price,
  1285. TotalPrice: total,
  1286. Status: 1,
  1287. Ctime: ctime,
  1288. Remark: remark,
  1289. OrgId: adminUserInfo.CurrentOrgId,
  1290. Mtime: time.Now().Unix(),
  1291. Type: types,
  1292. Manufacturer: manufacturer,
  1293. IsSys: is_sys,
  1294. SysRecordTime: sys_record_time,
  1295. Number: number,
  1296. ExpiryDate: expiryDate,
  1297. ProductDate: productDate,
  1298. Dealer: dealer,
  1299. LicenseNumber: license_number,
  1300. ConsumableType: 2,
  1301. WarehouseInfotId: warehouse_info_id,
  1302. }
  1303. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1304. }
  1305. }
  1306. }
  1307. }
  1308. var errs error
  1309. if len(warehousingOutInfo) > 0 {
  1310. errs = service.CreateWarehousingOutInfo(warehousingOutInfo)
  1311. }
  1312. if len(upDateWarehouseOutInfos) > 0 {
  1313. for _, item := range upDateWarehouseOutInfos {
  1314. //1.查询该耗材该批次的最后一次出库记录
  1315. lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, adminUserInfo.CurrentOrgId)
  1316. fmt.Println("lastGood", lastGood.Count)
  1317. fmt.Println("item2323232", item.Count)
  1318. // 退库的库存和该耗材该批次最后一次出库数量进行比较
  1319. //如果退库数量大于 最后一次批次的数量(要么要进行出库)
  1320. if item.Count > lastGood.Count {
  1321. //查询该耗材是否还有库存
  1322. warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId)
  1323. fmt.Println("hhhhhh23h2323232", warehouseinfo.StockCount)
  1324. //无库存
  1325. if warehouseinfo.StockCount <= 0 {
  1326. c.ServeSuccessJSON(map[string]interface{}{
  1327. "msg": "5",
  1328. })
  1329. return
  1330. }
  1331. //有库存,进行出库,调用出库接口
  1332. if warehouseinfo.StockCount > 0 {
  1333. var total int64
  1334. var stock_cout int64
  1335. var total_count int64
  1336. //计算和最后一次出库数据的差
  1337. total = item.Count - lastGood.Count
  1338. fmt.Println("total22323232", total)
  1339. //获取该耗材该批次的剩余库存量
  1340. info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1341. fmt.Println("info2232323232323", info)
  1342. //判断该批次的剩余库存 和出库的库存进行比较
  1343. //如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
  1344. if item.Count > info.StockCount {
  1345. //计算出库和该批次相差的库存
  1346. total_count = item.Count - info.StockCount
  1347. //清空本批次次库存
  1348. service.DeleteWarehouseInfo(item.WarehouseInfotId)
  1349. //调用出库逻辑
  1350. service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
  1351. }
  1352. //如果出库的库存小于或等于于该批次的剩余库存,那么需要该批次出库
  1353. if item.Count <= info.StockCount {
  1354. stock_cout = lastGood.Count + total
  1355. fmt.Println("232323223232323232323232", stock_cout)
  1356. //扣减库存
  1357. warehouse := models.WarehousingInfo{
  1358. StockCount: info.StockCount - total,
  1359. }
  1360. errs := service.UpdateWarehousingInfo(warehouse, info.ID)
  1361. warehouseOutInfo := &models.WarehouseOutInfo{
  1362. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1363. WarehouseOutId: id,
  1364. WarehouseInfotId: item.WarehouseInfotId,
  1365. Status: 1,
  1366. Ctime: time.Now().Unix(),
  1367. Remark: item.Remark,
  1368. OrgId: item.OrgId,
  1369. Type: 1,
  1370. Manufacturer: item.Manufacturer,
  1371. Dealer: item.Dealer,
  1372. IsSys: 0,
  1373. SysRecordTime: item.SysRecordTime,
  1374. GoodTypeId: item.GoodTypeId,
  1375. GoodId: item.GoodId,
  1376. ExpiryDate: item.ExpiryDate,
  1377. ProductDate: item.ProductDate,
  1378. Number: item.Number,
  1379. Price: item.Price,
  1380. LicenseNumber: item.LicenseNumber,
  1381. Count: item.Count,
  1382. ConsumableType: 2,
  1383. }
  1384. //查询是否存在
  1385. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1386. if errcode == gorm.ErrRecordNotFound {
  1387. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1388. if errOne != nil {
  1389. utils.ErrorLog(errs.Error())
  1390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1391. return
  1392. }
  1393. c.ServeSuccessJSON(map[string]interface{}{
  1394. "msg": "1",
  1395. })
  1396. } else if errcode == nil {
  1397. service.UpDateWarehouseOutInfo(item)
  1398. }
  1399. }
  1400. }
  1401. }
  1402. var last_count int64
  1403. var all_total int64
  1404. var stock_total int64
  1405. //如果退库数量小于最后一次批次的数量(要么要进行退库)
  1406. if item.Count < lastGood.Count {
  1407. fmt.Println("hh232323h2h3hh23hh23hh2h3h23")
  1408. //退库数量和最后一次出库数据进行计算
  1409. last_count = lastGood.Count - item.Count
  1410. fmt.Println("last_count", last_count)
  1411. //获取该耗材该批次的剩余库存量
  1412. infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1413. //退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
  1414. all_total = last_count + infoInfo.StockCount
  1415. fmt.Println("all_total", all_total)
  1416. //如果库存大于总数量,则退回到这个批次
  1417. fmt.Println("inf232323", infoInfo.WarehousingCount)
  1418. if infoInfo.WarehousingCount > all_total {
  1419. stock_total = last_count + infoInfo.StockCount
  1420. fmt.Println("经历323232323232232", last_count, stock_total)
  1421. //退回该批次,计算数量
  1422. warehousingInfoOne := models.WarehousingInfo{
  1423. StockCount: stock_total,
  1424. ID: item.WarehouseInfotId,
  1425. OrgId: item.OrgId,
  1426. }
  1427. fmt.Println("********************", warehousingInfoOne, item.WarehouseInfotId)
  1428. parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
  1429. fmt.Println("parseDateErr2323232322323", parseDateErr)
  1430. //插入一条新纪录
  1431. warehouseOutInfoThree := &models.WarehouseOutInfo{
  1432. WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
  1433. WarehouseOutId: id,
  1434. WarehouseInfotId: item.WarehouseInfotId,
  1435. Status: 1,
  1436. Ctime: time.Now().Unix(),
  1437. Remark: item.Remark,
  1438. OrgId: item.OrgId,
  1439. Type: 1,
  1440. Manufacturer: item.Manufacturer,
  1441. Dealer: item.Dealer,
  1442. IsSys: 0,
  1443. GoodTypeId: item.GoodTypeId,
  1444. GoodId: item.GoodId,
  1445. ExpiryDate: item.ExpiryDate,
  1446. ProductDate: item.ProductDate,
  1447. Number: item.Number,
  1448. Price: item.Price,
  1449. LicenseNumber: item.LicenseNumber,
  1450. ConsumableType: 2,
  1451. Count: item.Count,
  1452. }
  1453. //查询是否存在
  1454. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1455. if errcode == gorm.ErrRecordNotFound {
  1456. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfoThree)
  1457. if errOne != nil {
  1458. utils.ErrorLog(errs.Error())
  1459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1460. return
  1461. }
  1462. c.ServeSuccessJSON(map[string]interface{}{
  1463. "msg": "1",
  1464. })
  1465. } else if errcode == nil {
  1466. service.UpDateWarehouseOutInfo(item)
  1467. }
  1468. }
  1469. //如果库存小于总数量,则报错提醒,该批次的退库数据大于入库数据了无法退库,则需要退库到另一个批次
  1470. if infoInfo.WarehousingCount < all_total {
  1471. c.ServeSuccessJSON(map[string]interface{}{
  1472. "msg": "6",
  1473. })
  1474. return
  1475. }
  1476. }
  1477. if item.Count == lastGood.Count {
  1478. errs = service.UpDateWarehouseOutInfo(item)
  1479. if errs != nil {
  1480. utils.ErrorLog(errs.Error())
  1481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1482. return
  1483. }
  1484. c.ServeSuccessJSON(map[string]interface{}{
  1485. "msg": "1",
  1486. })
  1487. }
  1488. }
  1489. }
  1490. if errs != nil {
  1491. utils.ErrorLog(errs.Error())
  1492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1493. return
  1494. }
  1495. c.ServeSuccessJSON(map[string]interface{}{
  1496. "msg": "1",
  1497. })
  1498. }
  1499. func (c *StockManagerApiController) CreateCancelStock() {
  1500. cancel_stock_time := c.GetString("time")
  1501. types, _ := c.GetInt64("type", 0)
  1502. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1503. if parseDateErr != nil {
  1504. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1506. return
  1507. }
  1508. adminUserInfo := c.GetAdminUserInfo()
  1509. operation_time := time.Now().Unix()
  1510. creater := adminUserInfo.AdminUser.Id
  1511. ctime := time.Now().Unix()
  1512. timeStr := time.Now().Format("2006-01-02")
  1513. timeArr := strings.Split(timeStr, "-")
  1514. total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
  1515. total = total + 1
  1516. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1517. cancelStock := models.CancelStock{
  1518. OrderNumber: orderNumber,
  1519. OperaTime: operation_time,
  1520. OrgId: adminUserInfo.CurrentOrgId,
  1521. Creater: creater,
  1522. Ctime: ctime,
  1523. Status: 1,
  1524. ReturnTime: cancelStockDate.Unix(),
  1525. Type: types,
  1526. }
  1527. service.AddSigleCancelStock(&cancelStock)
  1528. dataBody := make(map[string]interface{}, 0)
  1529. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1530. if err != nil {
  1531. utils.ErrorLog(err.Error())
  1532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1533. return
  1534. }
  1535. var cancelStockInfos []*models.CancelStockInfo
  1536. var stockFLow []*models.VmStockFlow
  1537. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1538. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1539. if len(thisStockIn) > 0 {
  1540. for _, item := range thisStockIn {
  1541. items := item.(map[string]interface{})
  1542. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1543. utils.ErrorLog("good_id")
  1544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1545. return
  1546. }
  1547. good_id := int64(items["good_id"].(float64))
  1548. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1549. utils.ErrorLog("good_type_id")
  1550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1551. return
  1552. }
  1553. good_type_id := int64(items["good_type_id"].(float64))
  1554. return_count, _ := items["return_count"].(string)
  1555. if len(return_count) == 0 {
  1556. utils.ErrorLog("len(return_count) == 0")
  1557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1558. return
  1559. }
  1560. count, _ := strconv.ParseInt(return_count, 10, 64)
  1561. number := items["number"].(string)
  1562. register_account := items["register_account"].(string)
  1563. manufacturer, _ := items["manufacturer"].(string)
  1564. dealer, _ := items["dealer"].(string)
  1565. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1566. var expiryDates int64
  1567. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1568. expiryDates = 0
  1569. } else {
  1570. if len(items["expiry_date"].(string)) == 0 {
  1571. expiryDates = 0
  1572. } else {
  1573. expiryDate, _ := items["expiry_date"].(string)
  1574. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1575. expiryDates = expiry_date.Unix()
  1576. }
  1577. }
  1578. var productDates int64
  1579. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1580. productDates = 0
  1581. } else {
  1582. if len(items["product_date"].(string)) == 0 {
  1583. productDates = 0
  1584. } else {
  1585. productDate, _ := items["product_date"].(string)
  1586. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1587. productDates = product_date.Unix()
  1588. }
  1589. }
  1590. remark := items["remark"].(string)
  1591. retail_prices := items["price"].(string)
  1592. price, _ := strconv.ParseFloat(retail_prices, 64)
  1593. cancelStockInfo := &models.CancelStockInfo{
  1594. OrderNumber: cancelStock.OrderNumber,
  1595. CancelStockId: cancelStock.ID,
  1596. GoodId: good_id,
  1597. GoodTypeId: good_type_id,
  1598. Count: count,
  1599. Status: 1,
  1600. Ctime: ctime,
  1601. OrgId: adminUserInfo.CurrentOrgId,
  1602. Type: types,
  1603. Manufacturer: manufacturer,
  1604. Dealer: dealer,
  1605. Number: number,
  1606. ProductDate: productDates,
  1607. ExpiryDate: expiryDates,
  1608. RegisterAccount: register_account,
  1609. Remark: remark,
  1610. Price: price,
  1611. WarehouseInfoId: warehouse_info_id,
  1612. }
  1613. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1614. flow := &models.VmStockFlow{
  1615. WarehousingId: 0,
  1616. GoodId: good_id,
  1617. Number: number,
  1618. LicenseNumber: "",
  1619. Count: count,
  1620. UserOrgId: adminUserInfo.CurrentOrgId,
  1621. PatientId: 0,
  1622. SystemTime: time.Now().Unix(),
  1623. ConsumableType: 4,
  1624. IsSys: 0,
  1625. WarehousingOrder: "",
  1626. WarehouseOutId: 0,
  1627. WarehouseOutOrderNumber: "",
  1628. IsEdit: 0,
  1629. CancelStockId: cancelStock.ID,
  1630. CancelOrderNumber: cancelStock.OrderNumber,
  1631. Manufacturer: 0,
  1632. Dealer: 0,
  1633. Creator: adminUserInfo.AdminUser.Id,
  1634. UpdateCreator: 0,
  1635. Status: 1,
  1636. Ctime: time.Now().Unix(),
  1637. Mtime: 0,
  1638. Price: price,
  1639. WarehousingDetailId: 0,
  1640. WarehouseOutDetailId: 0,
  1641. CancelOutDetailId: 0,
  1642. ProductDate: productDates,
  1643. ExpireDate: expiryDates,
  1644. }
  1645. stockFLow = append(stockFLow, flow)
  1646. }
  1647. }
  1648. }
  1649. for _, item := range cancelStockInfos {
  1650. ////查找该耗材是否有出库记录
  1651. //_, errcode := service.GetWarehoureOutOrderInfo(item.GoodId, item.OrgId)
  1652. //if errcode == gorm.ErrRecordNotFound {
  1653. // c.ServeSuccessJSON(map[string]interface{}{
  1654. // "msg": "1",
  1655. // })
  1656. // return
  1657. //}
  1658. //统计该耗材的出库数量
  1659. info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
  1660. if item.Count > info.Count {
  1661. c.ServeSuccessJSON(map[string]interface{}{
  1662. "msg": "2",
  1663. })
  1664. return
  1665. }
  1666. //查询该批次入库的值
  1667. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  1668. if item.Count > infolist.WarehousingCount {
  1669. c.ServeSuccessJSON(map[string]interface{}{
  1670. "msg": "4",
  1671. })
  1672. return
  1673. }
  1674. if item.Count <= infolist.WarehousingCount {
  1675. errs := service.CreateCancelStockInfo(cancelStockInfos)
  1676. if len(stockFLow) > 0 {
  1677. service.CreateStockFlow(stockFLow)
  1678. }
  1679. if errs != nil {
  1680. utils.ErrorLog(errs.Error())
  1681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1682. return
  1683. }
  1684. //更改入库数量
  1685. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  1686. //查询该耗材的入库记录
  1687. //list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
  1688. ////调用退库的方法
  1689. //parseDateErr := service.UpdateCancelOut(list, item.Count)
  1690. //fmt.Println("999999999999", parseDateErr)
  1691. break
  1692. }
  1693. }
  1694. c.ServeSuccessJSON(map[string]interface{}{
  1695. "msg": "3",
  1696. })
  1697. return
  1698. }
  1699. func (c *StockManagerApiController) GetCancelStockInfoList() {
  1700. id, _ := c.GetInt64("id", 0)
  1701. cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
  1702. info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1703. manufacturerList, _ := service.GetAllManufacturerList(c.GetAdminUserInfo().CurrentOrgId)
  1704. dealerList, _ := service.GetAllDealerList(c.GetAdminUserInfo().CurrentOrgId)
  1705. c.ServeSuccessJSON(map[string]interface{}{
  1706. "list": cancelStockInfoList,
  1707. "info": info,
  1708. "manufacturerList": manufacturerList,
  1709. "dealerList": dealerList,
  1710. })
  1711. }
  1712. func (c *StockManagerApiController) GetCancelStockList() {
  1713. page, _ := c.GetInt64("page", -1)
  1714. limit, _ := c.GetInt64("limit", -1)
  1715. start_time := c.GetString("start_time")
  1716. end_time := c.GetString("end_time")
  1717. types, _ := c.GetInt64("type", 0)
  1718. keywords := c.GetString("keywords")
  1719. timeLayout := "2006-01-02"
  1720. loc, _ := time.LoadLocation("Local")
  1721. var startTime int64
  1722. if len(start_time) > 0 {
  1723. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1724. if err != nil {
  1725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1726. return
  1727. }
  1728. startTime = theTime.Unix()
  1729. }
  1730. var endTime int64
  1731. if len(end_time) > 0 {
  1732. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1733. if err != nil {
  1734. utils.ErrorLog(err.Error())
  1735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1736. return
  1737. }
  1738. endTime = theTime.Unix()
  1739. }
  1740. adminUserInfo := c.GetAdminUserInfo()
  1741. returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1742. if err == nil {
  1743. c.ServeSuccessJSON(map[string]interface{}{
  1744. "list": returnList,
  1745. "total": total,
  1746. })
  1747. } else {
  1748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1749. }
  1750. }
  1751. func (this *StockManagerApiController) DeleteCancelStock() {
  1752. ids := this.GetString("ids")
  1753. if len(ids) == 0 {
  1754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1755. return
  1756. }
  1757. idArray := strings.Split(ids, ",")
  1758. err := service.DeleteCancelStock(idArray)
  1759. if err != nil {
  1760. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1761. } else {
  1762. this.ServeSuccessJSON(map[string]interface{}{
  1763. "msg": "删除成功",
  1764. })
  1765. }
  1766. }
  1767. func (this *StockManagerApiController) DeleteCancelStockInfo() {
  1768. id, _ := this.GetInt64("id", 0)
  1769. fmt.Println(id)
  1770. if id == 0 {
  1771. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1772. return
  1773. }
  1774. err := service.UpDateCancleStockStatus(id)
  1775. if err != nil {
  1776. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1777. } else {
  1778. this.ServeSuccessJSON(map[string]interface{}{
  1779. "msg": "删除成功",
  1780. })
  1781. }
  1782. }
  1783. func (c *StockManagerApiController) EditCancelStock() {
  1784. cancel_time := c.GetString("cancel_time")
  1785. id, _ := c.GetInt64("id", 0)
  1786. if id == 0 {
  1787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1788. return
  1789. }
  1790. ctime := time.Now().Unix()
  1791. mtime := time.Now().Unix()
  1792. adminUserInfo := c.GetAdminUserInfo()
  1793. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  1794. if parseDateErr != nil {
  1795. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  1796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1797. return
  1798. }
  1799. cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1800. tempCancelStock := models.CancelStock{
  1801. ID: cancelStock.ID,
  1802. Mtime: mtime,
  1803. ReturnTime: cancelDate.Unix(),
  1804. }
  1805. service.EditCancelStock(tempCancelStock)
  1806. dataBody := make(map[string]interface{}, 0)
  1807. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1808. if err != nil {
  1809. utils.ErrorLog(err.Error())
  1810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1811. return
  1812. }
  1813. var cancelStockInfos []*models.CancelStockInfo
  1814. var upDateCancelStockInfos []*models.CancelStockInfo
  1815. var stockFlow []*models.VmStockFlow
  1816. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1817. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  1818. if len(thisCancelStock) > 0 {
  1819. for _, item := range thisCancelStock {
  1820. items := item.(map[string]interface{})
  1821. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1822. utils.ErrorLog("good_id")
  1823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1824. return
  1825. }
  1826. good_id := int64(items["good_id"].(float64))
  1827. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1828. utils.ErrorLog("good_type_id")
  1829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1830. return
  1831. }
  1832. good_type_id := int64(items["good_type_id"].(float64))
  1833. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1834. utils.ErrorLog("count")
  1835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1836. return
  1837. }
  1838. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1839. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1840. utils.ErrorLog("id")
  1841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1842. return
  1843. }
  1844. id := int64(items["id"].(float64))
  1845. number := items["number"].(string)
  1846. register_account := items["register_account"].(string)
  1847. manufacturer, _ := items["manufacturer"].(string)
  1848. dealer, _ := items["dealer"].(string)
  1849. remark := items["remark"].(string)
  1850. var productDates int64
  1851. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1852. productDates = 0
  1853. } else {
  1854. if len(items["product_date"].(string)) == 0 {
  1855. productDates = 0
  1856. } else {
  1857. productDate, _ := items["product_date"].(string)
  1858. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1859. productDates = product_date.Unix()
  1860. }
  1861. }
  1862. var expiryDates int64
  1863. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1864. expiryDates = 0
  1865. } else {
  1866. if len(items["expiry_date"].(string)) == 0 {
  1867. expiryDates = 0
  1868. } else {
  1869. expiryDate, _ := items["expiry_date"].(string)
  1870. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1871. expiryDates = expiry_date.Unix()
  1872. }
  1873. }
  1874. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1875. utils.ErrorLog("price")
  1876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1877. return
  1878. }
  1879. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1880. if id == 0 {
  1881. cancelStockInfo := &models.CancelStockInfo{
  1882. GoodId: good_id,
  1883. GoodTypeId: good_type_id,
  1884. Count: count,
  1885. Status: 1,
  1886. Ctime: ctime,
  1887. OrgId: adminUserInfo.CurrentOrgId,
  1888. OrderNumber: cancelStock.OrderNumber,
  1889. CancelStockId: cancelStock.ID,
  1890. Mtime: time.Now().Unix(),
  1891. Number: number,
  1892. RegisterAccount: register_account,
  1893. Manufacturer: manufacturer,
  1894. Dealer: dealer,
  1895. ProductDate: productDates,
  1896. ExpiryDate: expiryDates,
  1897. Remark: remark,
  1898. Price: price,
  1899. }
  1900. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1901. flow := &models.VmStockFlow{
  1902. WarehousingId: 0,
  1903. GoodId: good_id,
  1904. Number: number,
  1905. LicenseNumber: "",
  1906. Count: count,
  1907. UserOrgId: adminUserInfo.CurrentOrgId,
  1908. PatientId: 0,
  1909. SystemTime: time.Now().Unix(),
  1910. ConsumableType: 4,
  1911. IsSys: 0,
  1912. WarehousingOrder: "",
  1913. WarehouseOutId: 0,
  1914. WarehouseOutOrderNumber: "",
  1915. IsEdit: 2,
  1916. CancelStockId: cancelStock.ID,
  1917. CancelOrderNumber: cancelStock.OrderNumber,
  1918. Manufacturer: 0,
  1919. Dealer: 0,
  1920. Creator: adminUserInfo.AdminUser.Id,
  1921. UpdateCreator: 0,
  1922. Status: 1,
  1923. Ctime: time.Now().Unix(),
  1924. Mtime: 0,
  1925. Price: price,
  1926. WarehousingDetailId: 0,
  1927. WarehouseOutDetailId: 0,
  1928. CancelOutDetailId: 0,
  1929. ProductDate: productDates,
  1930. ExpireDate: expiryDates,
  1931. }
  1932. stockFlow = append(stockFlow, flow)
  1933. } else {
  1934. cancelStockInfo := &models.CancelStockInfo{
  1935. ID: id,
  1936. GoodId: good_id,
  1937. GoodTypeId: good_type_id,
  1938. Count: count,
  1939. Status: 1,
  1940. Ctime: ctime,
  1941. OrgId: adminUserInfo.CurrentOrgId,
  1942. OrderNumber: cancelStock.OrderNumber,
  1943. CancelStockId: cancelStock.ID,
  1944. Mtime: time.Now().Unix(),
  1945. Number: number,
  1946. RegisterAccount: register_account,
  1947. Manufacturer: manufacturer,
  1948. Dealer: dealer,
  1949. ProductDate: productDates,
  1950. ExpiryDate: expiryDates,
  1951. Remark: remark,
  1952. Price: price,
  1953. }
  1954. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  1955. flow := &models.VmStockFlow{
  1956. WarehousingId: 0,
  1957. GoodId: good_id,
  1958. Number: number,
  1959. LicenseNumber: "",
  1960. Count: count,
  1961. UserOrgId: adminUserInfo.CurrentOrgId,
  1962. PatientId: 0,
  1963. SystemTime: time.Now().Unix(),
  1964. ConsumableType: 4,
  1965. IsSys: 0,
  1966. WarehousingOrder: "",
  1967. WarehouseOutId: 0,
  1968. WarehouseOutOrderNumber: "",
  1969. IsEdit: 2,
  1970. CancelStockId: cancelStock.ID,
  1971. CancelOrderNumber: cancelStock.OrderNumber,
  1972. Manufacturer: 0,
  1973. Dealer: 0,
  1974. Creator: adminUserInfo.AdminUser.Id,
  1975. UpdateCreator: 0,
  1976. Status: 1,
  1977. Ctime: time.Now().Unix(),
  1978. Mtime: 0,
  1979. Price: price,
  1980. WarehousingDetailId: 0,
  1981. WarehouseOutDetailId: 0,
  1982. CancelOutDetailId: 0,
  1983. ProductDate: productDates,
  1984. ExpireDate: expiryDates,
  1985. }
  1986. stockFlow = append(stockFlow, flow)
  1987. }
  1988. }
  1989. }
  1990. }
  1991. var errs error
  1992. fmt.Println("出库22322333223", cancelStockInfos)
  1993. fmt.Println("更新23232323232323233", upDateCancelStockInfos)
  1994. if len(cancelStockInfos) > 0 {
  1995. for _, item := range cancelStockInfos {
  1996. //统计该耗材的出库数量
  1997. info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
  1998. if item.Count > info.Count {
  1999. c.ServeSuccessJSON(map[string]interface{}{
  2000. "msg": "2",
  2001. })
  2002. return
  2003. }
  2004. //查询该批次入库的值
  2005. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2006. if item.Count > infolist.WarehousingCount {
  2007. c.ServeSuccessJSON(map[string]interface{}{
  2008. "msg": "4",
  2009. })
  2010. return
  2011. }
  2012. if item.Count <= infolist.WarehousingCount {
  2013. errs := service.CreateCancelStockInfo(cancelStockInfos)
  2014. if len(stockFlow) > 0 {
  2015. service.CreateStockFlow(stockFlow)
  2016. }
  2017. if errs != nil {
  2018. utils.ErrorLog(errs.Error())
  2019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2020. return
  2021. }
  2022. //更改入库数量
  2023. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  2024. break
  2025. }
  2026. }
  2027. }
  2028. if len(upDateCancelStockInfos) > 0 {
  2029. for _, item := range upDateCancelStockInfos {
  2030. //获取该批次最后一套出库记录
  2031. info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
  2032. fmt.Println("info232332322332233223", info.Count, item.Count)
  2033. //比较出库数量和最后一次出库数据大小
  2034. //退库(加)
  2035. if item.Count < info.Count {
  2036. var total = info.Count - item.Count
  2037. errs = service.UpDateCancelStockInfo(item)
  2038. service.CreateStockFlow(stockFlow)
  2039. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
  2040. if parseDateErr != nil {
  2041. utils.ErrorLog(errs.Error())
  2042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2043. break
  2044. }
  2045. }
  2046. //(减)
  2047. if item.Count > info.Count {
  2048. errs = service.UpDateCancelStockInfo(item)
  2049. service.CreateStockFlow(stockFlow)
  2050. //查询该批次入库的值
  2051. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2052. if item.Count > infolist.WarehousingCount {
  2053. c.ServeSuccessJSON(map[string]interface{}{
  2054. "msg": "4",
  2055. })
  2056. return
  2057. }
  2058. if item.Count <= infolist.WarehousingCount {
  2059. var total_count = info.Count - item.Count
  2060. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total_count)
  2061. if parseDateErr != nil {
  2062. utils.ErrorLog(errs.Error())
  2063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2064. return
  2065. }
  2066. }
  2067. }
  2068. }
  2069. if errs != nil {
  2070. utils.ErrorLog(errs.Error())
  2071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2072. return
  2073. }
  2074. c.ServeSuccessJSON(map[string]interface{}{
  2075. "msg": "3",
  2076. })
  2077. }
  2078. if errs != nil {
  2079. utils.ErrorLog(errs.Error())
  2080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2081. return
  2082. }
  2083. c.ServeSuccessJSON(map[string]interface{}{
  2084. "msg": "3",
  2085. })
  2086. }
  2087. func (this *StockManagerApiController) GetCancelStockConfig() {
  2088. types, _ := this.GetInt64("type", 0)
  2089. adminUserInfo := this.GetAdminUserInfo()
  2090. warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
  2091. this.ServeSuccessJSON(map[string]interface{}{
  2092. "warehouseOutInfoList": warehouseOutInfoList,
  2093. })
  2094. }
  2095. func (c *StockManagerApiController) GetQueryInfo() {
  2096. page, _ := c.GetInt64("page", -1)
  2097. limit, _ := c.GetInt64("limit", -1)
  2098. keyword := c.GetString("keyword")
  2099. start_time := c.GetString("start_time")
  2100. end_time := c.GetString("end_time")
  2101. type_name, _ := c.GetInt64("type_name")
  2102. timeLayout := "2006-01-02"
  2103. loc, _ := time.LoadLocation("Local")
  2104. var startTime int64
  2105. if len(start_time) > 0 {
  2106. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2107. if err != nil {
  2108. fmt.Println(err)
  2109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2110. return
  2111. }
  2112. startTime = theTime.Unix()
  2113. }
  2114. var endTime int64
  2115. if len(end_time) > 0 {
  2116. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2117. if err != nil {
  2118. utils.ErrorLog(err.Error())
  2119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2120. return
  2121. }
  2122. endTime = theTime.Unix()
  2123. }
  2124. adminUserInfo := c.GetAdminUserInfo()
  2125. list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
  2126. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  2127. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId, "")
  2128. if err == nil {
  2129. c.ServeSuccessJSON(map[string]interface{}{
  2130. "list": list,
  2131. "total": total,
  2132. "info": info,
  2133. "infomationList": infomationList,
  2134. "orgid": adminUserInfo.CurrentOrgId,
  2135. })
  2136. } else {
  2137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2138. }
  2139. }
  2140. func (c *StockManagerApiController) SearchWarehouse() {
  2141. keywords := c.GetString("keywords")
  2142. adminUserInfo := c.GetAdminUserInfo()
  2143. warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
  2144. if err == nil {
  2145. c.ServeSuccessJSON(map[string]interface{}{
  2146. "list": warehouseList,
  2147. "total": total,
  2148. })
  2149. } else {
  2150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2151. }
  2152. }
  2153. func (c *StockManagerApiController) GetAllConfig() {
  2154. adminUserInfo := c.GetAdminUserInfo()
  2155. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  2156. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  2157. goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  2158. goodInfo, _ := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  2159. c.ServeSuccessJSON(map[string]interface{}{
  2160. "manufacturer": manufacturer,
  2161. "dealer": dealer,
  2162. "goodType": goodType,
  2163. "goodInfo": goodInfo,
  2164. })
  2165. }
  2166. func (this *StockManagerApiController) GetAllSalesReturnConfig() {
  2167. types, _ := this.GetInt64("type", 0)
  2168. adminUserInfo := this.GetAdminUserInfo()
  2169. warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
  2170. this.ServeSuccessJSON(map[string]interface{}{
  2171. "warehouseInfoList": warehouseInfoList,
  2172. })
  2173. }
  2174. func (this *StockManagerApiController) GetDetailInfo() {
  2175. page, _ := this.GetInt64("page", 0)
  2176. limit, _ := this.GetInt64("limit", 0)
  2177. start_time := this.GetString("start_time")
  2178. end_time := this.GetString("end_time")
  2179. types, _ := this.GetInt64("type", 0)
  2180. keywords := this.GetString("keywords")
  2181. manufacturer, _ := this.GetInt64("manufacturer", 0)
  2182. order_type, _ := this.GetInt64("order_type", 0)
  2183. dealer, _ := this.GetInt64("dealer", 0)
  2184. timeLayout := "2006-01-02"
  2185. loc, _ := time.LoadLocation("Local")
  2186. var startTime int64
  2187. if len(start_time) > 0 {
  2188. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2189. if err != nil {
  2190. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2191. return
  2192. }
  2193. startTime = theTime.Unix()
  2194. }
  2195. var endTime int64
  2196. if len(end_time) > 0 {
  2197. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2198. if err != nil {
  2199. utils.ErrorLog(err.Error())
  2200. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2201. return
  2202. }
  2203. endTime = theTime.Unix()
  2204. }
  2205. adminUserInfo := this.GetAdminUserInfo()
  2206. var list []*models.WarehousingInfo
  2207. var list1 []*models.WarehouseOutInfo
  2208. var list2 []*models.SalesReturnInfo
  2209. var list3 []*models.CancelStockInfo
  2210. var total int64
  2211. var err error
  2212. var total_price float64
  2213. if types == 1 {
  2214. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2215. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2216. if err == nil {
  2217. this.ServeSuccessJSON(map[string]interface{}{
  2218. "list": list,
  2219. "total": total,
  2220. "total_price": total_price,
  2221. })
  2222. } else {
  2223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2224. }
  2225. } else if types == 2 {
  2226. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2227. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2228. if err == nil {
  2229. this.ServeSuccessJSON(map[string]interface{}{
  2230. "list": list1,
  2231. "total": total,
  2232. "total_price": total_price,
  2233. })
  2234. } else {
  2235. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2236. }
  2237. } else if types == 3 {
  2238. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2239. if err == nil {
  2240. this.ServeSuccessJSON(map[string]interface{}{
  2241. "list": list2,
  2242. "total": total,
  2243. })
  2244. } else {
  2245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2246. }
  2247. } else if types == 4 {
  2248. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2249. if err == nil {
  2250. this.ServeSuccessJSON(map[string]interface{}{
  2251. "list": list3,
  2252. "total": total,
  2253. })
  2254. } else {
  2255. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2256. }
  2257. }
  2258. }
  2259. func (this *StockManagerApiController) GetUserDetailInfo() {
  2260. order_id, _ := this.GetInt64("id")
  2261. if order_id <= 0 {
  2262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2263. return
  2264. }
  2265. adminUserInfo := this.GetAdminUserInfo()
  2266. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  2267. if err == nil {
  2268. this.ServeSuccessJSON(map[string]interface{}{
  2269. "list": userDetails,
  2270. "total": total,
  2271. })
  2272. } else {
  2273. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2274. return
  2275. }
  2276. }
  2277. func (this *StockManagerApiController) PostSearchStock() {
  2278. keyword := this.GetString("keyword")
  2279. adminUserInfo := this.GetAdminUserInfo()
  2280. orgId := adminUserInfo.CurrentOrgId
  2281. stock, err := service.PostSearchStock(keyword, orgId)
  2282. if err != nil {
  2283. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2284. }
  2285. this.ServeSuccessJSON(map[string]interface{}{
  2286. "stock": stock,
  2287. })
  2288. }
  2289. func (this *StockManagerApiController) GetOutStockTotalCount() {
  2290. warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
  2291. adminUserInfo := this.GetAdminUserInfo()
  2292. stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
  2293. if err != nil {
  2294. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2295. }
  2296. this.ServeSuccessJSON(map[string]interface{}{
  2297. "stockCount": stockCount,
  2298. })
  2299. }
  2300. func (this *StockManagerApiController) AddGoodInformation() {
  2301. adminUserInfo := this.GetAdminUserInfo()
  2302. orgId := adminUserInfo.CurrentOrgId
  2303. dataBody := make(map[string]interface{}, 0)
  2304. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2305. if err != nil {
  2306. utils.ErrorLog(err.Error())
  2307. return
  2308. }
  2309. utils.ErrorLog("%v", dataBody)
  2310. var goods []*models.GoodInfo
  2311. var total_goods []interface{}
  2312. tempGoods := dataBody["goods"].([]interface{})
  2313. total_goods = tempGoods
  2314. for index, goodMap := range tempGoods {
  2315. goodNameM := goodMap.(map[string]interface{})
  2316. var good models.GoodInfo
  2317. if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
  2318. utils.ErrorLog("good_name")
  2319. return
  2320. }
  2321. good_name, _ := goodNameM["good_name"].(string)
  2322. if len(good_name) == 0 { //名字为空则生成一条导入错误日志
  2323. err_log := models.ExportErrLog{
  2324. LogType: 5,
  2325. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2326. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
  2327. Status: 1,
  2328. CreateTime: time.Now().Unix(),
  2329. UpdateTime: time.Now().Unix(),
  2330. ExportTime: time.Now().Unix(),
  2331. }
  2332. service.CreateExportErrLog(&err_log)
  2333. continue
  2334. }
  2335. good.GoodName = good_name
  2336. // 获取数据字典数据
  2337. var good_kind_id int64
  2338. var name = "耗材种类"
  2339. config, _ := service.GetDrugDataConfig(0, name)
  2340. good_kind := goodNameM["good_kind"].(string)
  2341. if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
  2342. err_log := models.ExportErrLog{
  2343. LogType: 5,
  2344. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2345. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
  2346. Status: 1,
  2347. CreateTime: time.Now().Unix(),
  2348. UpdateTime: time.Now().Unix(),
  2349. ExportTime: time.Now().Unix(),
  2350. }
  2351. service.CreateExportErrLog(&err_log)
  2352. continue
  2353. }
  2354. if len(good_kind) != 0 {
  2355. _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
  2356. lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
  2357. dataconfig := models.DictDataconfig{
  2358. ParentId: config.ID,
  2359. Module: "system",
  2360. OrgId: orgId,
  2361. Name: good_kind,
  2362. FieldName: "",
  2363. Value: lastConfig.Value + 1,
  2364. CreatedTime: "",
  2365. UpdatedTime: "",
  2366. CreateUserId: adminUserInfo.AdminUser.Id,
  2367. Status: 1,
  2368. Remark: "",
  2369. DeleteIdSystem: 0,
  2370. Title: "",
  2371. Content: "",
  2372. Order: 0,
  2373. Code: "",
  2374. }
  2375. if errcodegoodkind == gorm.ErrRecordNotFound {
  2376. service.CreatedDicConfig(&dataconfig)
  2377. }
  2378. }
  2379. dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
  2380. for _, it := range dataConfig {
  2381. if good_kind == it.Name {
  2382. fmt.Println(it.Name)
  2383. good_kind_id = int64(it.Value)
  2384. }
  2385. }
  2386. good.GoodKind = good_kind_id
  2387. good_type := goodNameM["type_name"].(string)
  2388. if len(good_type) == 0 {
  2389. err_log := models.ExportErrLog{
  2390. LogType: 5,
  2391. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2392. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
  2393. Status: 1,
  2394. CreateTime: time.Now().Unix(),
  2395. UpdateTime: time.Now().Unix(),
  2396. ExportTime: time.Now().Unix(),
  2397. }
  2398. service.CreateExportErrLog(&err_log)
  2399. continue
  2400. }
  2401. if len(good_type) != 0 {
  2402. _, errcodegoodtype := service.GetGoodType(good_type, orgId)
  2403. if errcodegoodtype == gorm.ErrRecordNotFound {
  2404. goodsType := models.GoodsType{
  2405. TypeName: good_type,
  2406. Remark: "",
  2407. Ctime: time.Now().Unix(),
  2408. Mtime: 0,
  2409. Creater: adminUserInfo.AdminUser.Id,
  2410. Modifier: 0,
  2411. OrgId: adminUserInfo.CurrentOrgId,
  2412. Status: 1,
  2413. Type: 0,
  2414. Number: 0,
  2415. OutStock: 0,
  2416. StockAttribute: 1,
  2417. }
  2418. service.CreatedGoodType(&goodsType)
  2419. }
  2420. }
  2421. goodType, _ := service.GetAllGoodType(orgId)
  2422. var good_type_id int64
  2423. for _, it := range goodType {
  2424. if good_type == it.TypeName {
  2425. good_type_id = it.ID
  2426. }
  2427. }
  2428. good.GoodTypeId = good_type_id
  2429. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  2430. if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
  2431. err_log := models.ExportErrLog{
  2432. LogType: 5,
  2433. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2434. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  2435. Status: 1,
  2436. CreateTime: time.Now().Unix(),
  2437. UpdateTime: time.Now().Unix(),
  2438. ExportTime: time.Now().Unix(),
  2439. }
  2440. service.CreateExportErrLog(&err_log)
  2441. continue
  2442. }
  2443. var medical_insurance_id int64
  2444. var medicalInsurance = "医保等级"
  2445. medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
  2446. if len(medical_insurance_level) != 0 {
  2447. _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
  2448. if errcodemedicalInsurance == gorm.ErrRecordNotFound {
  2449. mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
  2450. dataconfig := models.DictDataconfig{
  2451. ParentId: medicalInsuranceDataConfig.ID,
  2452. Module: "system",
  2453. OrgId: orgId,
  2454. Name: medical_insurance_level,
  2455. FieldName: "",
  2456. Value: mediConfigOne.Value + 1,
  2457. CreatedTime: "",
  2458. UpdatedTime: "",
  2459. CreateUserId: adminUserInfo.AdminUser.Id,
  2460. Status: 1,
  2461. Remark: "",
  2462. DeleteIdSystem: 0,
  2463. Title: "",
  2464. Content: "",
  2465. Order: 0,
  2466. Code: "",
  2467. }
  2468. service.CreatedDicConfig(&dataconfig)
  2469. }
  2470. }
  2471. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
  2472. for _, it := range medicalInsuranceList {
  2473. if medical_insurance_level == it.Name {
  2474. medical_insurance_id = int64(it.Value)
  2475. }
  2476. }
  2477. good.MedicalInsuranceLevel = medical_insurance_id
  2478. if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
  2479. utils.ErrorLog("specification_name")
  2480. return
  2481. }
  2482. specification_name := goodNameM["specification_name"].(string)
  2483. if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
  2484. err_log := models.ExportErrLog{
  2485. LogType: 5,
  2486. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2487. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
  2488. Status: 1,
  2489. CreateTime: time.Now().Unix(),
  2490. UpdateTime: time.Now().Unix(),
  2491. ExportTime: time.Now().Unix(),
  2492. }
  2493. service.CreateExportErrLog(&err_log)
  2494. continue
  2495. }
  2496. good.SpecificationName = specification_name
  2497. var manufacturer_id int64
  2498. manufacturer := goodNameM["manufacturer"].(string)
  2499. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  2500. err_log := models.ExportErrLog{
  2501. LogType: 5,
  2502. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2503. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
  2504. Status: 1,
  2505. CreateTime: time.Now().Unix(),
  2506. UpdateTime: time.Now().Unix(),
  2507. ExportTime: time.Now().Unix(),
  2508. }
  2509. service.CreateExportErrLog(&err_log)
  2510. continue
  2511. }
  2512. if len(manufacturer) != 0 {
  2513. _, errcodes := service.GetManufacturerName(orgId, manufacturer)
  2514. manu := models.Manufacturer{
  2515. ManufacturerName: manufacturer,
  2516. Status: 1,
  2517. OrgId: orgId,
  2518. Creater: adminUserInfo.AdminUser.Id,
  2519. }
  2520. if errcodes == gorm.ErrRecordNotFound {
  2521. service.CreateManufacturer(&manu)
  2522. }
  2523. }
  2524. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2525. for _, it := range manufacturerList {
  2526. if manufacturer == it.ManufacturerName {
  2527. manufacturer_id = it.ID
  2528. }
  2529. }
  2530. good.Manufacturer = manufacturer_id
  2531. if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
  2532. utils.ErrorLog("unit_id")
  2533. return
  2534. }
  2535. unit_id := int64(goodNameM["unit_id"].(float64))
  2536. if unit_id <= 0 { //名字为空则生成一条导入错误日志
  2537. err_log := models.ExportErrLog{
  2538. LogType: 5,
  2539. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2540. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
  2541. Status: 1,
  2542. CreateTime: time.Now().Unix(),
  2543. UpdateTime: time.Now().Unix(),
  2544. ExportTime: time.Now().Unix(),
  2545. }
  2546. service.CreateExportErrLog(&err_log)
  2547. continue
  2548. }
  2549. good.GoodUnit = unit_id
  2550. retail_prices := goodNameM["retail_price"].(string)
  2551. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  2552. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  2553. err_log := models.ExportErrLog{
  2554. LogType: 5,
  2555. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2556. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
  2557. Status: 1,
  2558. CreateTime: time.Now().Unix(),
  2559. UpdateTime: time.Now().Unix(),
  2560. ExportTime: time.Now().Unix(),
  2561. }
  2562. service.CreateExportErrLog(&err_log)
  2563. continue
  2564. }
  2565. good.RetailPrice = retail_price
  2566. if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
  2567. utils.ErrorLog("stock_warn_count")
  2568. return
  2569. }
  2570. stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
  2571. if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
  2572. err_log := models.ExportErrLog{
  2573. LogType: 5,
  2574. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2575. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
  2576. Status: 1,
  2577. CreateTime: time.Now().Unix(),
  2578. UpdateTime: time.Now().Unix(),
  2579. ExportTime: time.Now().Unix(),
  2580. }
  2581. service.CreateExportErrLog(&err_log)
  2582. continue
  2583. }
  2584. good.StockWarnCount = stock_warn_count
  2585. var dealer_id int64
  2586. dealerName := goodNameM["dealer"].(string)
  2587. fmt.Println("经销商", dealerName)
  2588. dealer := models.Dealer{
  2589. OrgId: orgId,
  2590. Status: 1,
  2591. DealerName: dealerName,
  2592. Creater: adminUserInfo.AdminUser.Id,
  2593. Ctime: time.Now().Unix(),
  2594. }
  2595. if len(dealerName) != 0 {
  2596. _, errcodedealer := service.GetDealerByName(orgId, dealerName)
  2597. if errcodedealer == gorm.ErrRecordNotFound {
  2598. service.CreateDealer(&dealer)
  2599. }
  2600. }
  2601. dealerList, _ := service.GetAllDealerList(orgId)
  2602. for _, it := range dealerList {
  2603. if dealerName == it.DealerName {
  2604. dealer_id = it.ID
  2605. }
  2606. }
  2607. good.Dealer = dealer_id
  2608. if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
  2609. utils.ErrorLog("pinyin")
  2610. return
  2611. }
  2612. pinyin := goodNameM["pinyin"].(string)
  2613. good.Pinyin = pinyin
  2614. if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
  2615. utils.ErrorLog("wubi")
  2616. return
  2617. }
  2618. wubi := goodNameM["wubi"].(string)
  2619. good.Wubi = wubi
  2620. buy_prices := goodNameM["buy_price"].(string)
  2621. buy_price, _ := strconv.ParseFloat(buy_prices, 64)
  2622. good.BuyPrice = buy_price
  2623. if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
  2624. utils.ErrorLog("social_security_directory_code")
  2625. return
  2626. }
  2627. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  2628. good.SocialSecurityDirectoryCode = social_security_directory_code
  2629. if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
  2630. utils.ErrorLog("is_special_diseases")
  2631. return
  2632. }
  2633. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  2634. good.IsSpecialDiseases = is_special_diseases
  2635. if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
  2636. utils.ErrorLog("is_record")
  2637. return
  2638. }
  2639. is_record := int64(goodNameM["is_record"].(float64))
  2640. good.IsRecord = is_record
  2641. if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
  2642. utils.ErrorLog("good_status")
  2643. return
  2644. }
  2645. good_status := goodNameM["good_status"].(string)
  2646. good.GoodStatus = good_status
  2647. if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
  2648. utils.ErrorLog("medical_insurance_number")
  2649. return
  2650. }
  2651. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  2652. good.MedicalInsuranceNumber = medical_insurance_number
  2653. if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
  2654. utils.ErrorLog("production_type")
  2655. return
  2656. }
  2657. production_type := goodNameM["production_type"].(string)
  2658. good.ProductionType = production_type
  2659. if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
  2660. utils.ErrorLog("remark")
  2661. return
  2662. }
  2663. remark := goodNameM["remark"].(string)
  2664. good.Remark = remark
  2665. statistics_category := goodNameM["statistics_category"].(string)
  2666. var categoryName = "统计分类"
  2667. var statistic_id int64
  2668. drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
  2669. if len(statistics_category) != 0 {
  2670. _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
  2671. if errcodecagegory == gorm.ErrRecordNotFound {
  2672. dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
  2673. dataconfig := models.DictDataconfig{
  2674. ParentId: drugDataConfig.ID,
  2675. Module: "system",
  2676. OrgId: orgId,
  2677. Name: statistics_category,
  2678. FieldName: "",
  2679. Value: dicConfigThree.Value + 1,
  2680. CreatedTime: "",
  2681. UpdatedTime: "",
  2682. CreateUserId: adminUserInfo.AdminUser.Id,
  2683. Status: 1,
  2684. Remark: "",
  2685. DeleteIdSystem: 0,
  2686. Title: "",
  2687. Content: "",
  2688. Order: 0,
  2689. Code: "",
  2690. }
  2691. service.CreatedDicConfig(&dataconfig)
  2692. }
  2693. }
  2694. parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
  2695. for _, it := range parentDataConfig {
  2696. if statistics_category == it.Name {
  2697. statistic_id = int64(it.Value)
  2698. }
  2699. }
  2700. good.StatisticsCategory = statistic_id
  2701. special_medical := goodNameM["special_medical"].(string)
  2702. good.SpecialMedical = special_medical
  2703. goods = append(goods, &good)
  2704. }
  2705. export_time := time.Now().Unix()
  2706. errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2707. if len(goods) > 0 {
  2708. for _, item := range goods {
  2709. goodInfo := models.GoodInfo{
  2710. GoodName: item.GoodName,
  2711. SpecificationName: item.SpecificationName,
  2712. GoodKind: item.GoodKind,
  2713. GoodTypeId: item.GoodTypeId,
  2714. Dealer: item.Dealer,
  2715. GoodUnit: item.GoodUnit,
  2716. IsRecord: item.IsRecord,
  2717. IsSpecialDiseases: item.IsSpecialDiseases,
  2718. Manufacturer: item.Manufacturer,
  2719. Pinyin: item.Pinyin,
  2720. GoodStatus: item.GoodStatus,
  2721. ProductionType: item.ProductionType,
  2722. Remark: item.Remark,
  2723. RetailPrice: item.RetailPrice,
  2724. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  2725. SpecialMedical: item.SpecialMedical,
  2726. Wubi: item.Wubi,
  2727. StockWarnCount: item.StockWarnCount,
  2728. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  2729. OrgId: orgId,
  2730. Status: 1,
  2731. Ctime: time.Now().Unix(),
  2732. StatisticsCategory: item.StatisticsCategory,
  2733. GoodCode: item.GoodCode,
  2734. BuyPrice: item.BuyPrice,
  2735. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  2736. }
  2737. //查询同种耗材名称同种类型同种规格的耗材是否存在
  2738. _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2739. if errcodegood == gorm.ErrRecordNotFound {
  2740. service.CreateGoodsInfomation(&goodInfo)
  2741. } else if errcodegood == nil {
  2742. service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2743. }
  2744. log := models.ExportLog{
  2745. LogType: 5,
  2746. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2747. TotalNum: int64(len(total_goods)),
  2748. FailNum: int64(len(errLogs)),
  2749. SuccessNum: int64(len(goods)),
  2750. CreateTime: time.Now().Unix(),
  2751. UpdateTime: time.Now().Unix(),
  2752. ExportTime: export_time,
  2753. Status: 1,
  2754. }
  2755. service.CreateExportLog(&log)
  2756. this.ServeSuccessJSON(map[string]interface{}{
  2757. "msg": "导入成功",
  2758. "total_num": len(total_goods),
  2759. "success_num": len(goods),
  2760. "fail_num": int64(len(errLogs)),
  2761. })
  2762. }
  2763. } else {
  2764. log := models.ExportLog{
  2765. LogType: 5,
  2766. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2767. TotalNum: int64(len(total_goods)),
  2768. FailNum: int64(len(errLogs)),
  2769. SuccessNum: int64(len(goods)),
  2770. CreateTime: time.Now().Unix(),
  2771. UpdateTime: time.Now().Unix(),
  2772. ExportTime: export_time,
  2773. Status: 1,
  2774. }
  2775. service.CreateExportLog(&log)
  2776. this.ServeSuccessJSON(map[string]interface{}{
  2777. "msg": "导入成功",
  2778. "total_num": len(total_goods),
  2779. "success_num": len(goods),
  2780. "fail_num": int64(len(errLogs)),
  2781. })
  2782. }
  2783. }
  2784. func (this *StockManagerApiController) AddDrugInformation() {
  2785. adminUser := this.GetAdminUserInfo()
  2786. orgId := adminUser.CurrentOrgId
  2787. dataBody := make(map[string]interface{}, 0)
  2788. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2789. if err != nil {
  2790. utils.ErrorLog(err.Error())
  2791. return
  2792. }
  2793. utils.ErrorLog("%v", dataBody)
  2794. var drugList []*models.BaseDrugLib
  2795. var total_goods []interface{}
  2796. tempDrugs := dataBody["drugs"].([]interface{})
  2797. total_goods = tempDrugs
  2798. for index, drugMap := range tempDrugs {
  2799. goodNameM := drugMap.(map[string]interface{})
  2800. var drug models.BaseDrugLib
  2801. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  2802. utils.ErrorLog("drug_name")
  2803. return
  2804. }
  2805. drug_name, _ := goodNameM["drug_name"].(string)
  2806. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2807. err_log := models.ExportErrLog{
  2808. LogType: 4,
  2809. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2810. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  2811. Status: 1,
  2812. CreateTime: time.Now().Unix(),
  2813. UpdateTime: time.Now().Unix(),
  2814. ExportTime: time.Now().Unix(),
  2815. }
  2816. service.CreateExportErrLog(&err_log)
  2817. continue
  2818. }
  2819. drug.DrugName = drug_name
  2820. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  2821. utils.ErrorLog("min_number")
  2822. return
  2823. }
  2824. min_number, _ := goodNameM["min_number"].(string)
  2825. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  2826. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2827. err_log := models.ExportErrLog{
  2828. LogType: 4,
  2829. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2830. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  2831. Status: 1,
  2832. CreateTime: time.Now().Unix(),
  2833. UpdateTime: time.Now().Unix(),
  2834. ExportTime: time.Now().Unix(),
  2835. }
  2836. service.CreateExportErrLog(&err_log)
  2837. continue
  2838. }
  2839. drug.MinNumber = minNumber
  2840. min_unit := goodNameM["min_unit"].(string)
  2841. if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
  2842. err_log := models.ExportErrLog{
  2843. LogType: 4,
  2844. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2845. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
  2846. Status: 1,
  2847. CreateTime: time.Now().Unix(),
  2848. UpdateTime: time.Now().Unix(),
  2849. ExportTime: time.Now().Unix(),
  2850. }
  2851. service.CreateExportErrLog(&err_log)
  2852. continue
  2853. }
  2854. drug.MinUnit = min_unit
  2855. dose := goodNameM["dose"].(float64)
  2856. if dose < 0 { //名字为空则生成一条导入错误日志
  2857. err_log := models.ExportErrLog{
  2858. LogType: 4,
  2859. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2860. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  2861. Status: 1,
  2862. CreateTime: time.Now().Unix(),
  2863. UpdateTime: time.Now().Unix(),
  2864. ExportTime: time.Now().Unix(),
  2865. }
  2866. service.CreateExportErrLog(&err_log)
  2867. continue
  2868. }
  2869. drug.Dose = dose
  2870. max_unit_id := goodNameM["max_unit"].(string)
  2871. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  2872. err_log := models.ExportErrLog{
  2873. LogType: 4,
  2874. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2875. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  2876. Status: 1,
  2877. CreateTime: time.Now().Unix(),
  2878. UpdateTime: time.Now().Unix(),
  2879. ExportTime: time.Now().Unix(),
  2880. }
  2881. service.CreateExportErrLog(&err_log)
  2882. continue
  2883. }
  2884. drug.MaxUnit = max_unit_id
  2885. max_unit := goodNameM["max_unit"].(string)
  2886. if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
  2887. err_log := models.ExportErrLog{
  2888. LogType: 4,
  2889. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2890. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
  2891. Status: 1,
  2892. CreateTime: time.Now().Unix(),
  2893. UpdateTime: time.Now().Unix(),
  2894. ExportTime: time.Now().Unix(),
  2895. }
  2896. service.CreateExportErrLog(&err_log)
  2897. continue
  2898. }
  2899. drug.MaxUnit = max_unit
  2900. delivery_way := goodNameM["delivery_way"].(string)
  2901. if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
  2902. err_log := models.ExportErrLog{
  2903. LogType: 4,
  2904. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2905. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
  2906. Status: 1,
  2907. CreateTime: time.Now().Unix(),
  2908. UpdateTime: time.Now().Unix(),
  2909. ExportTime: time.Now().Unix(),
  2910. }
  2911. service.CreateExportErrLog(&err_log)
  2912. continue
  2913. }
  2914. drug.DeliveryWay = delivery_way
  2915. execution_frequency := goodNameM["execution_frequency"].(string)
  2916. if len(execution_frequency) == 0 { //名字为空则生成一条导入错误日志
  2917. err_log := models.ExportErrLog{
  2918. LogType: 4,
  2919. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2920. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  2921. Status: 1,
  2922. CreateTime: time.Now().Unix(),
  2923. UpdateTime: time.Now().Unix(),
  2924. ExportTime: time.Now().Unix(),
  2925. }
  2926. service.CreateExportErrLog(&err_log)
  2927. continue
  2928. }
  2929. drug.ExecutionFrequency = execution_frequency
  2930. drug_day := goodNameM["drug_day"].(string)
  2931. if len(drug_day) == 0 { //名字为空则生成一条导入错误日志
  2932. err_log := models.ExportErrLog{
  2933. LogType: 4,
  2934. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2935. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  2936. Status: 1,
  2937. CreateTime: time.Now().Unix(),
  2938. UpdateTime: time.Now().Unix(),
  2939. ExportTime: time.Now().Unix(),
  2940. }
  2941. service.CreateExportErrLog(&err_log)
  2942. continue
  2943. }
  2944. drug.DrugDay = drug_day
  2945. drug_type := goodNameM["drug_type"].(string)
  2946. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  2947. err_log := models.ExportErrLog{
  2948. LogType: 4,
  2949. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2950. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
  2951. Status: 1,
  2952. CreateTime: time.Now().Unix(),
  2953. UpdateTime: time.Now().Unix(),
  2954. ExportTime: time.Now().Unix(),
  2955. }
  2956. service.CreateExportErrLog(&err_log)
  2957. continue
  2958. }
  2959. var drug_type_id int64
  2960. var drugType = "药品类型"
  2961. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  2962. if len(drug_type) != 0 {
  2963. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  2964. if errcodes == gorm.ErrRecordNotFound {
  2965. //获取该型号最后一条数据型号
  2966. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  2967. dataconfig := models.DictDataconfig{
  2968. ParentId: drugconfig.ID,
  2969. Module: "system",
  2970. OrgId: orgId,
  2971. Name: drug_type,
  2972. FieldName: "",
  2973. Value: config.Value + 1,
  2974. CreatedTime: "",
  2975. UpdatedTime: "",
  2976. CreateUserId: adminUser.AdminUser.Id,
  2977. Status: 1,
  2978. Remark: "",
  2979. DeleteIdSystem: 0,
  2980. Title: "",
  2981. Content: "",
  2982. Order: 0,
  2983. Code: "",
  2984. }
  2985. service.CreatedDicConfig(&dataconfig)
  2986. }
  2987. }
  2988. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  2989. for _, it := range drugTypeList {
  2990. if drug_type == it.Name {
  2991. drug_type_id = int64(it.Value)
  2992. }
  2993. }
  2994. drug.DrugType = drug_type_id
  2995. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  2996. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  2997. err_log := models.ExportErrLog{
  2998. LogType: 4,
  2999. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3000. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  3001. Status: 1,
  3002. CreateTime: time.Now().Unix(),
  3003. UpdateTime: time.Now().Unix(),
  3004. ExportTime: time.Now().Unix(),
  3005. }
  3006. service.CreateExportErrLog(&err_log)
  3007. continue
  3008. }
  3009. drug.DrugStockLimit = drug_stock_limit
  3010. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  3011. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  3012. err_log := models.ExportErrLog{
  3013. LogType: 4,
  3014. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3015. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  3016. Status: 1,
  3017. CreateTime: time.Now().Unix(),
  3018. UpdateTime: time.Now().Unix(),
  3019. ExportTime: time.Now().Unix(),
  3020. }
  3021. service.CreateExportErrLog(&err_log)
  3022. continue
  3023. }
  3024. drug.DrugOriginPlace = drug_origin_place
  3025. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  3026. if len(drug_dosage_form) == 0 {
  3027. err_log := models.ExportErrLog{
  3028. LogType: 4,
  3029. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3030. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  3031. Status: 1,
  3032. CreateTime: time.Now().Unix(),
  3033. UpdateTime: time.Now().Unix(),
  3034. ExportTime: time.Now().Unix(),
  3035. }
  3036. service.CreateExportErrLog(&err_log)
  3037. continue
  3038. }
  3039. var drug_dosage = "药品剂型"
  3040. var drug_dosage_form_id int64
  3041. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  3042. if len(drug_dosage_form) != 0 {
  3043. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  3044. if errcodess == gorm.ErrRecordNotFound {
  3045. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  3046. dataconfig := models.DictDataconfig{
  3047. ParentId: drugDosageconfig.ID,
  3048. Module: "system",
  3049. OrgId: orgId,
  3050. Name: drug_dosage_form,
  3051. FieldName: "",
  3052. Value: configOne.Value + 1,
  3053. CreatedTime: "",
  3054. UpdatedTime: "",
  3055. CreateUserId: adminUser.AdminUser.Id,
  3056. Status: 1,
  3057. Remark: "",
  3058. DeleteIdSystem: 0,
  3059. Title: "",
  3060. Content: "",
  3061. Order: 0,
  3062. Code: "",
  3063. }
  3064. service.CreatedDicConfig(&dataconfig)
  3065. }
  3066. }
  3067. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  3068. for _, it := range drugDosageList {
  3069. if drug_dosage_form == it.Name {
  3070. drug_dosage_form_id = int64(it.Value)
  3071. }
  3072. }
  3073. drug.DrugDosageForm = drug_dosage_form_id
  3074. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  3075. var medical_insurance_level_id int64
  3076. if len(medical_insurance_level) == 0 { //名字为空则生成一条导入错误日志
  3077. err_log := models.ExportErrLog{
  3078. LogType: 4,
  3079. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3080. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  3081. Status: 1,
  3082. CreateTime: time.Now().Unix(),
  3083. UpdateTime: time.Now().Unix(),
  3084. ExportTime: time.Now().Unix(),
  3085. }
  3086. service.CreateExportErrLog(&err_log)
  3087. continue
  3088. }
  3089. var medicalInsuranceName = "医保等级"
  3090. medicalInsuranceConfig, _ := service.GetDrugDataConfig(0, medicalInsuranceName)
  3091. if len(medical_insurance_level) != 0 {
  3092. _, errcodemedical := service.IsExistDicConfig(medicalInsuranceConfig.ID, medical_insurance_level, orgId)
  3093. if errcodemedical == gorm.ErrRecordNotFound {
  3094. medConfig, _ := service.GetLastDicConfig(medicalInsuranceConfig.ID, orgId)
  3095. dataconfig := models.DictDataconfig{
  3096. ParentId: medicalInsuranceConfig.ID,
  3097. Module: "system",
  3098. OrgId: orgId,
  3099. Name: medical_insurance_level,
  3100. FieldName: "",
  3101. Value: medConfig.Value + 1,
  3102. CreatedTime: "",
  3103. UpdatedTime: "",
  3104. CreateUserId: adminUser.AdminUser.Id,
  3105. Status: 1,
  3106. Remark: "",
  3107. DeleteIdSystem: 0,
  3108. Title: "",
  3109. Content: "",
  3110. Order: 0,
  3111. Code: "",
  3112. }
  3113. service.CreatedDicConfig(&dataconfig)
  3114. }
  3115. }
  3116. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceConfig.ID, orgId)
  3117. for _, it := range medicalInsuranceList {
  3118. if medical_insurance_level == it.Name {
  3119. medical_insurance_level_id = int64(it.Value)
  3120. }
  3121. }
  3122. drug.MedicalInsuranceLevel = medical_insurance_level_id
  3123. unit_matrixing := goodNameM["unit_matrixing"].(string)
  3124. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3125. err_log := models.ExportErrLog{
  3126. LogType: 4,
  3127. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3128. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位换算不能为空",
  3129. Status: 1,
  3130. CreateTime: time.Now().Unix(),
  3131. UpdateTime: time.Now().Unix(),
  3132. ExportTime: time.Now().Unix(),
  3133. }
  3134. service.CreateExportErrLog(&err_log)
  3135. continue
  3136. }
  3137. drug.UnitMatrixing = unit_matrixing
  3138. retail_prices := goodNameM["retail_price"].(string)
  3139. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3140. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3141. err_log := models.ExportErrLog{
  3142. LogType: 4,
  3143. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3144. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  3145. Status: 1,
  3146. CreateTime: time.Now().Unix(),
  3147. UpdateTime: time.Now().Unix(),
  3148. ExportTime: time.Now().Unix(),
  3149. }
  3150. service.CreateExportErrLog(&err_log)
  3151. continue
  3152. }
  3153. drug.RetailPrice = retail_price
  3154. packing_prices := goodNameM["packing_price"].(string)
  3155. packing_price, _ := strconv.ParseFloat(packing_prices, 64)
  3156. if packing_price <= 0 { //名字为空则生成一条导入错误日志
  3157. err_log := models.ExportErrLog{
  3158. LogType: 4,
  3159. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3160. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装零售价不能为空",
  3161. Status: 1,
  3162. CreateTime: time.Now().Unix(),
  3163. UpdateTime: time.Now().Unix(),
  3164. ExportTime: time.Now().Unix(),
  3165. }
  3166. service.CreateExportErrLog(&err_log)
  3167. continue
  3168. }
  3169. drug.RetailPrice = retail_price
  3170. last_prices := goodNameM["last_price"].(string)
  3171. last_price, _ := strconv.ParseFloat(last_prices, 64)
  3172. if last_price <= 0 { //名字为空则生成一条导入错误日志
  3173. err_log := models.ExportErrLog{
  3174. LogType: 4,
  3175. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3176. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  3177. Status: 1,
  3178. CreateTime: time.Now().Unix(),
  3179. UpdateTime: time.Now().Unix(),
  3180. ExportTime: time.Now().Unix(),
  3181. }
  3182. service.CreateExportErrLog(&err_log)
  3183. continue
  3184. }
  3185. drug.LastPrice = last_price
  3186. drug_classify := goodNameM["drug_classify"].(string)
  3187. if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
  3188. err_log := models.ExportErrLog{
  3189. LogType: 4,
  3190. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3191. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
  3192. Status: 1,
  3193. CreateTime: time.Now().Unix(),
  3194. UpdateTime: time.Now().Unix(),
  3195. ExportTime: time.Now().Unix(),
  3196. }
  3197. service.CreateExportErrLog(&err_log)
  3198. continue
  3199. }
  3200. var drugClassify = "药物分类"
  3201. var drug_classify_id int64
  3202. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  3203. if len(drug_classify) != 0 {
  3204. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  3205. if errcodesClass == gorm.ErrRecordNotFound {
  3206. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  3207. dataconfig := models.DictDataconfig{
  3208. ParentId: drugClassifyConfig.ID,
  3209. Module: "system",
  3210. OrgId: orgId,
  3211. Name: drug_classify,
  3212. FieldName: "",
  3213. Value: drugClassConfig.Value + 1,
  3214. CreatedTime: "",
  3215. UpdatedTime: "",
  3216. CreateUserId: adminUser.AdminUser.Id,
  3217. Status: 1,
  3218. Remark: "",
  3219. DeleteIdSystem: 0,
  3220. Title: "",
  3221. Content: "",
  3222. Order: 0,
  3223. Code: "",
  3224. }
  3225. service.CreatedDicConfig(&dataconfig)
  3226. }
  3227. }
  3228. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  3229. for _, it := range drugClassList {
  3230. if drug_classify == it.Name {
  3231. drug_classify_id = int64(it.Value)
  3232. }
  3233. }
  3234. drug_dose := goodNameM["drug_dose"].(string)
  3235. if len(drug_dose) == 0 {
  3236. err_log := models.ExportErrLog{
  3237. LogType: 4,
  3238. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3239. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
  3240. Status: 1,
  3241. CreateTime: time.Now().Unix(),
  3242. UpdateTime: time.Now().Unix(),
  3243. ExportTime: time.Now().Unix(),
  3244. }
  3245. service.CreateExportErrLog(&err_log)
  3246. continue
  3247. }
  3248. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  3249. drug.DrugDose = drugDoses
  3250. var units = "单位"
  3251. var unit_id int64
  3252. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  3253. if len(drugDoseUnit) == 0 {
  3254. err_log := models.ExportErrLog{
  3255. LogType: 4,
  3256. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3257. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  3258. Status: 1,
  3259. CreateTime: time.Now().Unix(),
  3260. UpdateTime: time.Now().Unix(),
  3261. ExportTime: time.Now().Unix(),
  3262. }
  3263. service.CreateExportErrLog(&err_log)
  3264. continue
  3265. }
  3266. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  3267. if len(drugDoseUnit) != 0 {
  3268. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  3269. if errcodedataconfig == gorm.ErrRecordNotFound {
  3270. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  3271. dataconfig := models.Dataconfig{
  3272. ParentId: dataConfig.ID,
  3273. Module: "hemodialysis",
  3274. OrgId: orgId,
  3275. Name: drugDoseUnit,
  3276. FieldName: "",
  3277. Value: childConfig.Value + 1,
  3278. CreatedTime: "",
  3279. UpdatedTime: "",
  3280. CreateUserId: adminUser.AdminUser.Id,
  3281. Status: 1,
  3282. Remark: "",
  3283. DeleteIdSystem: 0,
  3284. Title: "",
  3285. Content: "",
  3286. Order: 0,
  3287. Code: "",
  3288. FieldType: 0,
  3289. }
  3290. service.CreateDataConfig(&dataconfig)
  3291. }
  3292. }
  3293. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  3294. for _, it := range list {
  3295. if drugDoseUnit == it.Name {
  3296. unit_id = int64(it.Value)
  3297. }
  3298. }
  3299. drug.DrugDoseUnit = unit_id
  3300. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  3301. manufacturer := goodNameM["manufacturer"].(string)
  3302. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3303. err_log := models.ExportErrLog{
  3304. LogType: 4,
  3305. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3306. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  3307. Status: 1,
  3308. CreateTime: time.Now().Unix(),
  3309. UpdateTime: time.Now().Unix(),
  3310. ExportTime: time.Now().Unix(),
  3311. }
  3312. service.CreateExportErrLog(&err_log)
  3313. continue
  3314. }
  3315. if len(manufacturer) != 0 {
  3316. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  3317. if errcodema == gorm.ErrRecordNotFound {
  3318. manufactur := models.Manufacturer{
  3319. OrgId: orgId,
  3320. Status: 1,
  3321. ManufacturerName: manufacturer,
  3322. Ctime: time.Now().Unix(),
  3323. Creater: adminUser.AdminUser.Id,
  3324. }
  3325. service.CreateManufacturer(&manufactur)
  3326. }
  3327. }
  3328. var manufacturer_id int64
  3329. manufacturList, _ := service.GetAllManufacturerList(orgId)
  3330. for _, it := range manufacturList {
  3331. if manufacturer == it.ManufacturerName {
  3332. manufacturer_id = it.ID
  3333. }
  3334. }
  3335. drug.Manufacturer = manufacturer_id
  3336. dealer := goodNameM["dealer"].(string)
  3337. if len(dealer) != 0 {
  3338. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  3339. if errcodesdealer == gorm.ErrRecordNotFound {
  3340. dealerconfig := models.Dealer{
  3341. DealerName: dealer,
  3342. Status: 1,
  3343. OrgId: orgId,
  3344. Ctime: time.Now().Unix(),
  3345. Creater: adminUser.AdminUser.Id,
  3346. }
  3347. service.CreateDealer(&dealerconfig)
  3348. }
  3349. }
  3350. var dealer_id int64
  3351. dealerList, _ := service.GetAllDealerList(orgId)
  3352. for _, it := range dealerList {
  3353. if dealer == it.DealerName {
  3354. dealer_id = it.ID
  3355. }
  3356. }
  3357. drug.Dealer = dealer_id
  3358. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  3359. drug.LmtUsedFlag = lmt_used_flags
  3360. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  3361. utils.ErrorLog("drug_alias")
  3362. return
  3363. }
  3364. drug_alias, _ := goodNameM["drug_alias"].(string)
  3365. drug.DrugAlias = drug_alias
  3366. drug_category := goodNameM["drug_category"].(string)
  3367. var drugCategory = "药品类别"
  3368. var drug_category_id int64
  3369. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  3370. if len(drug_category) != 0 {
  3371. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  3372. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  3373. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  3374. dataconfig := models.DictDataconfig{
  3375. ParentId: drugCategoryConfig.ID,
  3376. Module: "system",
  3377. OrgId: orgId,
  3378. Name: drug_category,
  3379. FieldName: "",
  3380. Value: drugCategoryConfigSix.Value + 1,
  3381. CreatedTime: "",
  3382. UpdatedTime: "",
  3383. CreateUserId: adminUser.AdminUser.Id,
  3384. Status: 1,
  3385. Remark: "",
  3386. DeleteIdSystem: 0,
  3387. Title: "",
  3388. Content: "",
  3389. Order: 0,
  3390. Code: "",
  3391. }
  3392. service.CreatedDicConfig(&dataconfig)
  3393. }
  3394. }
  3395. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  3396. fmt.Println("drugCategoryList", drugCategoryList)
  3397. for _, it := range drugCategoryList {
  3398. if drug_category == it.Name {
  3399. drug_category_id = int64(it.Value)
  3400. }
  3401. }
  3402. drug.DrugCategory = drug_category_id
  3403. statistics_category := goodNameM["statistics_category"].(string)
  3404. var statisticsCategory = "统计分类"
  3405. var statistics_category_id int64
  3406. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3407. if len(statistics_category) != 0 {
  3408. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  3409. if errcodestatistc == gorm.ErrRecordNotFound {
  3410. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  3411. dataconfig := models.DictDataconfig{
  3412. ParentId: statistcConfig.ID,
  3413. Module: "system",
  3414. OrgId: orgId,
  3415. Name: statistics_category,
  3416. FieldName: "",
  3417. Value: staConfig.Value + 1,
  3418. CreatedTime: "",
  3419. UpdatedTime: "",
  3420. CreateUserId: adminUser.AdminUser.Id,
  3421. Status: 1,
  3422. Remark: "",
  3423. DeleteIdSystem: 0,
  3424. Title: "",
  3425. Content: "",
  3426. Order: 0,
  3427. Code: "",
  3428. }
  3429. service.CreatedDicConfig(&dataconfig)
  3430. }
  3431. }
  3432. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  3433. for _, it := range statisticsCategoryList {
  3434. if statistics_category == it.Name {
  3435. statistics_category_id = int64(it.Value)
  3436. }
  3437. }
  3438. drug.StatisticsCategory = statistics_category_id
  3439. number := goodNameM["number"].(string)
  3440. drug.Number = number
  3441. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  3442. drug.HospApprFlag = hosp_appr_flag
  3443. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3444. drug.MedicalInsuranceNumber = medical_insurance_number
  3445. pharmacology_category := goodNameM["pharmacology_category"].(string)
  3446. var pharmacology = "药理分类"
  3447. var pharmacology_category_id int64
  3448. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  3449. if len(pharmacology_category) != 0 {
  3450. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  3451. if errcodespharmacology == gorm.ErrRecordNotFound {
  3452. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  3453. dataconfig := models.DictDataconfig{
  3454. ParentId: pharmacologyConfig.ID,
  3455. Module: "system",
  3456. OrgId: orgId,
  3457. Name: pharmacology_category,
  3458. FieldName: "",
  3459. Value: dicConfig.Value + 1,
  3460. CreatedTime: "",
  3461. UpdatedTime: "",
  3462. CreateUserId: adminUser.AdminUser.Id,
  3463. Status: 1,
  3464. Remark: "",
  3465. DeleteIdSystem: 0,
  3466. Title: "",
  3467. Content: "",
  3468. Order: 0,
  3469. Code: "",
  3470. }
  3471. service.CreatedDicConfig(&dataconfig)
  3472. }
  3473. }
  3474. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  3475. for _, it := range pharmacologyList {
  3476. if pharmacology_category == it.Name {
  3477. pharmacology_category_id = int64(it.Value)
  3478. }
  3479. }
  3480. drug.PharmacologyCategory = pharmacology_category_id
  3481. code := goodNameM["code"].(string)
  3482. drug.Code = code
  3483. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3484. drug.IsSpecialDiseases = is_special_diseases
  3485. is_record := int64(goodNameM["is_record"].(float64))
  3486. drug.IsRecord = is_record
  3487. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  3488. drug.PrescriptionMark = prescription_mark
  3489. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3490. drug.SocialSecurityDirectoryCode = social_security_directory_code
  3491. record_date := goodNameM["record_date"].(string)
  3492. timeLayout := "2006-01-02"
  3493. loc, _ := time.LoadLocation("Local")
  3494. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3495. drug.RecordDate = theTime.Unix()
  3496. drug_remark := goodNameM["drug_remark"].(string)
  3497. drug.DrugRemark = drug_remark
  3498. drug_status := goodNameM["drug_status"].(string)
  3499. drug.DrugStatus = drug_status
  3500. limit_remark := goodNameM["limit_remark"].(string)
  3501. drug.LimitRemark = limit_remark
  3502. drug_control := goodNameM["drug_control"].(string)
  3503. var drugControl = "开药控制"
  3504. var drug_control_id int64
  3505. drugContorlConfig, _ := service.GetDrugDataConfig(0, drugControl)
  3506. if len(drug_control) != 0 {
  3507. _, errcodesdrugcontrol := service.IsExistDicConfig(drugContorlConfig.ID, drug_control, orgId)
  3508. if errcodesdrugcontrol == gorm.ErrRecordNotFound {
  3509. drugContorlConfigOne, _ := service.GetLastDicConfig(drugContorlConfig.ID, orgId)
  3510. dataconfig := models.DictDataconfig{
  3511. ParentId: drugContorlConfig.ID,
  3512. Module: "system",
  3513. OrgId: orgId,
  3514. Name: drug_control,
  3515. FieldName: "",
  3516. Value: drugContorlConfigOne.Value + 1,
  3517. CreatedTime: "",
  3518. UpdatedTime: "",
  3519. CreateUserId: adminUser.AdminUser.Id,
  3520. Status: 1,
  3521. Remark: "",
  3522. DeleteIdSystem: 0,
  3523. Title: "",
  3524. Content: "",
  3525. Order: 0,
  3526. Code: "",
  3527. }
  3528. service.CreatedDicConfig(&dataconfig)
  3529. }
  3530. }
  3531. drugContorlList, _ := service.GetParentDataConfig(drugContorlConfig.ID, orgId)
  3532. for _, it := range drugContorlList {
  3533. if drug_control == it.Name {
  3534. drug_control_id = int64(it.Value)
  3535. }
  3536. }
  3537. drug.DrugControl = drug_control_id
  3538. drugList = append(drugList, &drug)
  3539. }
  3540. export_time := time.Now().Unix()
  3541. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3542. if len(drugList) > 0 {
  3543. for _, item := range drugList {
  3544. goodInfo := models.BaseDrugLib{
  3545. DrugName: item.DrugName,
  3546. DrugAlias: item.DrugAlias,
  3547. DrugSpec: item.DrugSpec,
  3548. DrugType: item.DrugType,
  3549. DrugStockLimit: item.DrugStockLimit,
  3550. DrugOriginPlace: item.DrugOriginPlace,
  3551. DrugDosageForm: item.DrugDosageForm,
  3552. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3553. MaxUnit: item.MaxUnit,
  3554. MinUnit: item.MinUnit,
  3555. UnitMatrixing: item.UnitMatrixing,
  3556. RetailPrice: item.RetailPrice,
  3557. LastPrice: item.LastPrice,
  3558. DrugClassify: item.DrugClassify,
  3559. Manufacturer: item.Manufacturer,
  3560. Dealer: item.Dealer,
  3561. OrgId: orgId,
  3562. Status: 1,
  3563. Ctime: time.Now().Unix(),
  3564. Pinyin: item.Pinyin,
  3565. Wubi: item.Wubi,
  3566. DrugAliasPinyin: item.DrugAliasPinyin,
  3567. DrugAliasWubi: item.DrugAliasWubi,
  3568. DrugControl: item.DrugControl,
  3569. Number: item.Number,
  3570. HospApprFlag: item.HospApprFlag,
  3571. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3572. PharmacologyCategory: item.PharmacologyCategory,
  3573. StatisticsCategory: item.StatisticsCategory,
  3574. Code: item.Code,
  3575. IsSpecialDiseases: item.IsSpecialDiseases,
  3576. IsRecord: item.IsRecord,
  3577. PrescriptionMark: item.PrescriptionMark,
  3578. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3579. RecordDate: item.RecordDate,
  3580. DrugRemark: item.DrugRemark,
  3581. DrugStatus: item.DrugStatus,
  3582. LimitRemark: item.LimitRemark,
  3583. DrugCategory: item.DrugCategory,
  3584. DrugDose: item.DrugDose,
  3585. DrugDoseUnit: item.DrugDoseUnit,
  3586. LmtUsedFlag: item.LmtUsedFlag,
  3587. DrugDay: item.DrugDay,
  3588. DeliveryWay: item.DeliveryWay,
  3589. ExecutionFrequency: item.ExecutionFrequency,
  3590. DoseUnit: item.DoseUnit,
  3591. }
  3592. //查询同种药品同种规格是否存在
  3593. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.MaxUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  3594. if drugerror == gorm.ErrRecordNotFound {
  3595. service.CreateDrugsInfomation(&goodInfo)
  3596. } else if drugerror == nil {
  3597. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  3598. }
  3599. log := models.ExportLog{
  3600. LogType: 4,
  3601. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3602. TotalNum: int64(len(total_goods)),
  3603. FailNum: int64(len(errLogs)),
  3604. SuccessNum: int64(len(drugList)),
  3605. CreateTime: time.Now().Unix(),
  3606. UpdateTime: time.Now().Unix(),
  3607. ExportTime: export_time,
  3608. Status: 1,
  3609. }
  3610. service.CreateExportLog(&log)
  3611. this.ServeSuccessJSON(map[string]interface{}{
  3612. "msg": "导入成功",
  3613. "total_num": len(total_goods),
  3614. "success_num": len(drugList),
  3615. "fail_num": int64(len(errLogs)),
  3616. })
  3617. }
  3618. } else {
  3619. log := models.ExportLog{
  3620. LogType: 4,
  3621. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3622. TotalNum: int64(len(total_goods)),
  3623. FailNum: int64(len(errLogs)),
  3624. SuccessNum: int64(len(drugList)),
  3625. CreateTime: time.Now().Unix(),
  3626. UpdateTime: time.Now().Unix(),
  3627. ExportTime: export_time,
  3628. Status: 1,
  3629. }
  3630. service.CreateExportLog(&log)
  3631. this.ServeSuccessJSON(map[string]interface{}{
  3632. "msg": "导入成功",
  3633. "total_num": len(total_goods),
  3634. "success_num": len(drugList),
  3635. "fail_num": int64(len(errLogs)),
  3636. })
  3637. }
  3638. }
  3639. func (this *StockManagerApiController) GetInitializtion() {
  3640. orgId := this.GetAdminUserInfo().CurrentOrgId
  3641. var drugCategory = "药品类别"
  3642. var drugType = "药品类型"
  3643. var drugDosageForm = "药品剂型"
  3644. var medicalInsuranceLevel = "医保等级"
  3645. var drugControl = "开药控制"
  3646. var drugClassify = "药物分类"
  3647. var statisticsCategory = "统计分类"
  3648. var pharmacologyCategory = "药理分类"
  3649. var goodKind = "耗材种类"
  3650. var tubeColor = "试管颜色"
  3651. var costClassify = "费用类别"
  3652. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3653. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3654. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  3655. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  3656. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  3657. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  3658. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  3659. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  3660. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  3661. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  3662. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  3663. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  3664. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3665. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  3666. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  3667. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  3668. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  3669. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  3670. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  3671. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  3672. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  3673. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  3674. this.ServeSuccessJSON(map[string]interface{}{
  3675. "drugCategoryList": drugCategoryList,
  3676. "drugTypeList": drugTypeList,
  3677. "drugDosageFormList": drugDosageFormList,
  3678. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  3679. "drugControlList": drugControlList,
  3680. "drugClassifyList": drugClassifyList,
  3681. "statisticsCategoryList": statisticsCategoryList,
  3682. "pharmacologyCategoryList": pharmacologyCategoryList,
  3683. "goodKindList": goodKindList,
  3684. "tubeColorList": tubeColorList,
  3685. "costClassifyList": costClassifyList,
  3686. })
  3687. }
  3688. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  3689. adminUserInfo := this.GetAdminUserInfo()
  3690. orgId := adminUserInfo.CurrentOrgId
  3691. list, _ := service.GetWarehouseOrderInfoList(orgId)
  3692. this.ServeSuccessJSON(map[string]interface{}{
  3693. "list": list,
  3694. })
  3695. }
  3696. func (this *StockManagerApiController) PostSearchGoodList() {
  3697. keyword := this.GetString("keyword")
  3698. adminUserInfo := this.GetAdminUserInfo()
  3699. orgId := adminUserInfo.CurrentOrgId
  3700. list, _ := service.GetSearchGoodList(keyword, orgId)
  3701. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3702. dealerList, _ := service.GetAllDealerList(orgId)
  3703. this.ServeSuccessJSON(map[string]interface{}{
  3704. "list": list,
  3705. "manufacturerList": manufacturerList,
  3706. "dealerList": dealerList,
  3707. })
  3708. }
  3709. func (this *StockManagerApiController) GetAllStockList() {
  3710. page, _ := this.GetInt64("page", -1)
  3711. limit, _ := this.GetInt64("limit", -1)
  3712. start_time := this.GetString("start_time")
  3713. end_time := this.GetString("end_time")
  3714. types, _ := this.GetInt64("type", 0)
  3715. keywords := this.GetString("keywords")
  3716. timeLayout := "2006-01-02"
  3717. loc, _ := time.LoadLocation("Local")
  3718. var startTime int64
  3719. if len(start_time) > 0 {
  3720. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3721. if err != nil {
  3722. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3723. return
  3724. }
  3725. startTime = theTime.Unix()
  3726. }
  3727. var endTime int64
  3728. if len(end_time) > 0 {
  3729. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3730. if err != nil {
  3731. utils.ErrorLog(err.Error())
  3732. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3733. return
  3734. }
  3735. endTime = theTime.Unix()
  3736. }
  3737. adminUserInfo := this.GetAdminUserInfo()
  3738. orgId := adminUserInfo.CurrentOrgId
  3739. list, total, _ := service.GetAllStockList(page, limit, startTime, endTime, types, keywords, orgId)
  3740. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3741. this.ServeSuccessJSON(map[string]interface{}{
  3742. "list": list,
  3743. "total": total,
  3744. "manufacturerList": manufacturerList,
  3745. })
  3746. }
  3747. func (this *StockManagerApiController) GetStockListById() {
  3748. id, _ := this.GetInt64("id")
  3749. adminUserInfo := this.GetAdminUserInfo()
  3750. orgId := adminUserInfo.CurrentOrgId
  3751. limit, _ := this.GetInt64("limit")
  3752. page, _ := this.GetInt64("page")
  3753. timeLayout := "2006-01-02"
  3754. loc, _ := time.LoadLocation("Local")
  3755. start_time := this.GetString("start_time")
  3756. end_time := this.GetString("end_time")
  3757. var startTime int64
  3758. if len(start_time) > 0 {
  3759. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3760. if err != nil {
  3761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3762. return
  3763. }
  3764. startTime = theTime.Unix()
  3765. }
  3766. var endTime int64
  3767. if len(end_time) > 0 {
  3768. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3769. if err != nil {
  3770. utils.ErrorLog(err.Error())
  3771. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3772. return
  3773. }
  3774. endTime = theTime.Unix()
  3775. }
  3776. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3777. list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime)
  3778. this.ServeSuccessJSON(map[string]interface{}{
  3779. "list": list,
  3780. "total": total,
  3781. "manufacturerList": manufacturerList,
  3782. })
  3783. }
  3784. func (this *StockManagerApiController) GetStockOutList() {
  3785. id, _ := this.GetInt64("id")
  3786. adminUserInfo := this.GetAdminUserInfo()
  3787. orgId := adminUserInfo.CurrentOrgId
  3788. limit, _ := this.GetInt64("limit")
  3789. page, _ := this.GetInt64("page")
  3790. timeLayout := "2006-01-02"
  3791. loc, _ := time.LoadLocation("Local")
  3792. start_time := this.GetString("start_time")
  3793. end_time := this.GetString("end_time")
  3794. is_sys, _ := this.GetInt64("is_sys")
  3795. var startTime int64
  3796. if len(start_time) > 0 {
  3797. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3798. if err != nil {
  3799. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3800. return
  3801. }
  3802. startTime = theTime.Unix()
  3803. }
  3804. var endTime int64
  3805. if len(end_time) > 0 {
  3806. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3807. if err != nil {
  3808. utils.ErrorLog(err.Error())
  3809. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3810. return
  3811. }
  3812. endTime = theTime.Unix()
  3813. }
  3814. outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
  3815. this.ServeSuccessJSON(map[string]interface{}{
  3816. "outList": outList,
  3817. "total": total,
  3818. })
  3819. }
  3820. func (this *StockManagerApiController) GetStockDrugCount() {
  3821. adminUserInfo := this.GetAdminUserInfo()
  3822. orgId := adminUserInfo.CurrentOrgId
  3823. fmt.Println(orgId)
  3824. timeLayout := "2006-01-02"
  3825. loc, _ := time.LoadLocation("Local")
  3826. start_time := this.GetString("start_time")
  3827. end_time := this.GetString("end_time")
  3828. var startTime int64
  3829. if len(start_time) > 0 {
  3830. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3831. if err != nil {
  3832. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3833. return
  3834. }
  3835. startTime = theTime.Unix()
  3836. }
  3837. var endTime int64
  3838. if len(end_time) > 0 {
  3839. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3840. if err != nil {
  3841. utils.ErrorLog(err.Error())
  3842. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3843. return
  3844. }
  3845. endTime = theTime.Unix()
  3846. }
  3847. count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
  3848. outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
  3849. autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
  3850. totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
  3851. this.ServeSuccessJSON(map[string]interface{}{
  3852. "count": count,
  3853. "outList": outList,
  3854. "autoCount": autoCount,
  3855. "totalCount": totalCount,
  3856. })
  3857. }
  3858. func (this *StockManagerApiController) GetOrderDetialByOrderId() {
  3859. ids := this.GetString("id")
  3860. idsArray := strings.Split(ids, ",")
  3861. orgId := this.GetAdminUserInfo().CurrentOrgId
  3862. order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
  3863. list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
  3864. //获取该耗材的最后一条数据
  3865. info, _ := service.GetLastWarehouseOutInfo(idsArray, orgId)
  3866. fmt.Println("info323e2342342342432342342432", info)
  3867. this.ServeSuccessJSON(map[string]interface{}{
  3868. "order": order,
  3869. "list": list,
  3870. "info": info,
  3871. })
  3872. }
  3873. func (this *StockManagerApiController) GetOrderDetailById() {
  3874. id, _ := this.GetInt64("id")
  3875. good_id, _ := this.GetInt64("good_id")
  3876. record_time, _ := this.GetInt64("record_time")
  3877. orgId := this.GetAdminUserInfo().CurrentOrgId
  3878. //自动出库
  3879. userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
  3880. //手动出库
  3881. info, _ := service.GetWarehouseOutInfoById(id, good_id)
  3882. stockFlowList, err := service.GetStockFlowBatchNumber(id, good_id)
  3883. if err == nil {
  3884. this.ServeSuccessJSON(map[string]interface{}{
  3885. "list": userDetails,
  3886. "total": total,
  3887. "info": info,
  3888. "stockFlowList": stockFlowList,
  3889. })
  3890. } else {
  3891. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3892. return
  3893. }
  3894. }
  3895. func (this *StockManagerApiController) GetSingleOutOrderDetail() {
  3896. id, _ := this.GetInt64("id", 0)
  3897. orgId := this.GetAdminUserInfo().CurrentOrgId
  3898. warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
  3899. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3900. dealerList, _ := service.GetAllDealerList(orgId)
  3901. goodType, _ := service.GetAllGoodType(orgId)
  3902. this.ServeSuccessJSON(map[string]interface{}{
  3903. "list": warehouseOutInfo,
  3904. "dealerList": dealerList,
  3905. "manufacturerList": manufacturerList,
  3906. "goodType": goodType,
  3907. })
  3908. }
  3909. func (this *StockManagerApiController) GetExprotStockList() {
  3910. adminUserInfo := this.GetAdminUserInfo()
  3911. orgId := adminUserInfo.CurrentOrgId
  3912. timeLayout := "2006-01-02"
  3913. loc, _ := time.LoadLocation("Local")
  3914. start_time := this.GetString("start_time")
  3915. end_time := this.GetString("end_time")
  3916. idArray := this.GetString("id")
  3917. ids := strings.Split(idArray, ",")
  3918. var startTime int64
  3919. if len(start_time) > 0 {
  3920. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3921. if err != nil {
  3922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3923. return
  3924. }
  3925. startTime = theTime.Unix()
  3926. }
  3927. var endTime int64
  3928. if len(end_time) > 0 {
  3929. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3930. if err != nil {
  3931. utils.ErrorLog(err.Error())
  3932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3933. return
  3934. }
  3935. endTime = theTime.Unix()
  3936. }
  3937. fmt.Println("ids2222222222222222", ids)
  3938. list, _ := service.GetExprotStockList(orgId, ids, startTime, endTime)
  3939. this.ServeSuccessJSON(map[string]interface{}{
  3940. "list": list,
  3941. })
  3942. }
  3943. func (this *StockManagerApiController) GetOutExprotList() {
  3944. adminUserInfo := this.GetAdminUserInfo()
  3945. orgId := adminUserInfo.CurrentOrgId
  3946. timeLayout := "2006-01-02"
  3947. loc, _ := time.LoadLocation("Local")
  3948. start_time := this.GetString("start_time")
  3949. end_time := this.GetString("end_time")
  3950. idArray := this.GetString("id")
  3951. ids := strings.Split(idArray, ",")
  3952. fmt.Println("ids2222222222", ids)
  3953. var startTime int64
  3954. if len(start_time) > 0 {
  3955. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3956. if err != nil {
  3957. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3958. return
  3959. }
  3960. startTime = theTime.Unix()
  3961. }
  3962. var endTime int64
  3963. if len(end_time) > 0 {
  3964. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3965. if err != nil {
  3966. utils.ErrorLog(err.Error())
  3967. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3968. return
  3969. }
  3970. endTime = theTime.Unix()
  3971. }
  3972. list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
  3973. outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
  3974. this.ServeSuccessJSON(map[string]interface{}{
  3975. "list": list,
  3976. "count": outCount,
  3977. })
  3978. }
  3979. func (this *StockManagerApiController) GetSingleCancelOrder() {
  3980. id, _ := this.GetInt64("id")
  3981. adminUserInfo := this.GetAdminUserInfo()
  3982. orgId := adminUserInfo.CurrentOrgId
  3983. order, _ := service.GetSingleCancelOrder(id, orgId)
  3984. this.ServeSuccessJSON(map[string]interface{}{
  3985. "list": order,
  3986. })
  3987. }
  3988. func (this *StockManagerApiController) GetCancelStockOrderPrint() {
  3989. id := this.GetString("id")
  3990. idStr := strings.Split(id, ",")
  3991. orgId := this.GetAdminUserInfo().CurrentOrgId
  3992. list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
  3993. this.ServeSuccessJSON(map[string]interface{}{
  3994. "list": list,
  3995. })
  3996. }
  3997. func (this *StockManagerApiController) GetStockBatchNumber() {
  3998. id, _ := this.GetInt64("id")
  3999. orgId := this.GetAdminUserInfo().CurrentOrgId
  4000. list, _ := service.GetStockBatchNumber(id, orgId)
  4001. this.ServeSuccessJSON(map[string]interface{}{
  4002. "list": list,
  4003. })
  4004. }
  4005. func (this *StockManagerApiController) GetStockFlow() {
  4006. limit, _ := this.GetInt64("limit")
  4007. page, _ := this.GetInt64("page")
  4008. good_id, _ := this.GetInt64("good_id")
  4009. consumable_type, _ := this.GetInt64("is_sys")
  4010. adminUserInfo := this.GetAdminUserInfo()
  4011. orgId := adminUserInfo.CurrentOrgId
  4012. timeLayout := "2006-01-02"
  4013. loc, _ := time.LoadLocation("Local")
  4014. start_time := this.GetString("start_time")
  4015. end_time := this.GetString("end_time")
  4016. var startTime int64
  4017. if len(start_time) > 0 {
  4018. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4019. if err != nil {
  4020. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4021. return
  4022. }
  4023. startTime = theTime.Unix()
  4024. }
  4025. var endTime int64
  4026. if len(end_time) > 0 {
  4027. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4028. if err != nil {
  4029. utils.ErrorLog(err.Error())
  4030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4031. return
  4032. }
  4033. endTime = theTime.Unix()
  4034. }
  4035. list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
  4036. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4037. this.ServeSuccessJSON(map[string]interface{}{
  4038. "list": list,
  4039. "total": total,
  4040. "manufacturerList": manufacturerList,
  4041. })
  4042. }
  4043. func (this *StockManagerApiController) GetCancelExportList() {
  4044. adminUserInfo := this.GetAdminUserInfo()
  4045. orgId := adminUserInfo.CurrentOrgId
  4046. timeLayout := "2006-01-02"
  4047. loc, _ := time.LoadLocation("Local")
  4048. start_time := this.GetString("start_time")
  4049. end_time := this.GetString("end_time")
  4050. idArray := this.GetString("order_id")
  4051. fmt.Println("232323232323232232", idArray)
  4052. ids := strings.Split(idArray, ",")
  4053. var startTime int64
  4054. if len(start_time) > 0 {
  4055. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4056. if err != nil {
  4057. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4058. return
  4059. }
  4060. startTime = theTime.Unix()
  4061. }
  4062. var endTime int64
  4063. if len(end_time) > 0 {
  4064. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4065. if err != nil {
  4066. utils.ErrorLog(err.Error())
  4067. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4068. return
  4069. }
  4070. endTime = theTime.Unix()
  4071. }
  4072. list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
  4073. this.ServeSuccessJSON(map[string]interface{}{
  4074. "list": list,
  4075. })
  4076. }