stock_in_api_controller.go 131KB

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