stock_in_api_controller.go 158KB

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