stock_in_api_controller.go 115KB

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