stock_in_api_controller.go 119KB

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