stock_in_api_controller.go 142KB

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