stock_in_api_controller.go 149KB

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