stock_in_api_controller.go 167KB

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