stock_in_api_controller.go 115KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630
  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. var beforePrepares []*models.DialysisBeforePrepareGoods
  960. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  961. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  962. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  963. if len(thisStockIn) > 0 {
  964. for _, item := range thisStockIn {
  965. items := item.(map[string]interface{})
  966. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  967. utils.ErrorLog("good_id")
  968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  969. return
  970. }
  971. good_id := int64(items["good_id"].(float64))
  972. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  973. utils.ErrorLog("good_type_id")
  974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  975. return
  976. }
  977. good_type_id := int64(items["good_type_id"].(float64))
  978. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  979. utils.ErrorLog("count")
  980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  981. return
  982. }
  983. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  984. utils.ErrorLog("price")
  985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  986. return
  987. }
  988. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  989. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  990. total := float64(count) * price
  991. remark := items["remark"].(string)
  992. warehouseOutInfo := &models.WarehouseOutInfo{
  993. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  994. WarehouseOutId: warehouseOut.ID,
  995. GoodId: good_id,
  996. GoodTypeId: good_type_id,
  997. Count: count,
  998. Price: price,
  999. TotalPrice: total,
  1000. Status: 1,
  1001. Ctime: ctime,
  1002. Remark: remark,
  1003. OrgId: adminUserInfo.CurrentOrgId,
  1004. Type: types,
  1005. Manufacturer: manufacturer_id,
  1006. Dealer: dealer_id,
  1007. }
  1008. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1009. prepareGoods := &models.DialysisBeforePrepareGoods{
  1010. GoodTypeId: good_type_id,
  1011. GoodId: good_id,
  1012. Count: count,
  1013. }
  1014. beforePrepares = append(beforePrepares, prepareGoods)
  1015. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  1016. GoodTypeId: good_type_id,
  1017. GoodId: good_id,
  1018. Count: count,
  1019. }
  1020. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  1021. }
  1022. }
  1023. }
  1024. //查询库存
  1025. for _, item := range warehousingOutInfo {
  1026. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count)
  1027. fmt.Println(parseDateErr)
  1028. }
  1029. //errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
  1030. //info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
  1031. //if errs != nil {
  1032. // utils.ErrorLog(errs.Error())
  1033. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1034. // return
  1035. //}
  1036. c.ServeSuccessJSON(map[string]interface{}{
  1037. "msg": "出库成功",
  1038. "warehousing_out_order": warehousing_out_order,
  1039. })
  1040. }
  1041. func (c *StockManagerApiController) GetWarehouseOutList() {
  1042. page, _ := c.GetInt64("page", -1)
  1043. limit, _ := c.GetInt64("limit", -1)
  1044. start_time := c.GetString("start_time")
  1045. end_time := c.GetString("end_time")
  1046. types, _ := c.GetInt64("type", 0)
  1047. keywords := c.GetString("keywords")
  1048. timeLayout := "2006-01-02"
  1049. loc, _ := time.LoadLocation("Local")
  1050. var startTime int64
  1051. if len(start_time) > 0 {
  1052. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1053. if err != nil {
  1054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1055. return
  1056. }
  1057. startTime = theTime.Unix()
  1058. }
  1059. var endTime int64
  1060. if len(end_time) > 0 {
  1061. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1062. if err != nil {
  1063. utils.ErrorLog(err.Error())
  1064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1065. return
  1066. }
  1067. endTime = theTime.Unix()
  1068. }
  1069. adminUserInfo := c.GetAdminUserInfo()
  1070. warehouseOutList, total, err := service.FindAllWarehouseOutList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1071. fmt.Println(err)
  1072. if err == nil {
  1073. c.ServeSuccessJSON(map[string]interface{}{
  1074. "list": warehouseOutList,
  1075. "total": total,
  1076. })
  1077. } else {
  1078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1079. }
  1080. }
  1081. func (c *StockManagerApiController) DeleteWarehouseOut() {
  1082. ids := c.GetString("ids")
  1083. if len(ids) == 0 {
  1084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1085. return
  1086. }
  1087. idArray := strings.Split(ids, ",")
  1088. err := service.DeleteWarehouseOut(idArray)
  1089. if err != nil {
  1090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1091. } else {
  1092. c.ServeSuccessJSON(map[string]interface{}{
  1093. "msg": "删除成功",
  1094. })
  1095. }
  1096. }
  1097. func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
  1098. id, _ := this.GetInt64("id", 0)
  1099. fmt.Println(id)
  1100. if id == 0 {
  1101. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1102. return
  1103. }
  1104. err := service.UpDateWarehouseOutStatus(id)
  1105. if err != nil {
  1106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1107. } else {
  1108. this.ServeSuccessJSON(map[string]interface{}{
  1109. "msg": "删除成功",
  1110. })
  1111. }
  1112. }
  1113. func (c *StockManagerApiController) GetWarehouseOutInfoList() {
  1114. id, _ := c.GetInt64("id", 0)
  1115. warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
  1116. warehouseOut, _ := service.FindWareHouseOutById(id)
  1117. adminUserInfo := c.GetAdminUserInfo()
  1118. orgId := adminUserInfo.CurrentOrgId
  1119. wareoutList, _ := service.GetWareOutInfoById(id, orgId)
  1120. c.ServeSuccessJSON(map[string]interface{}{
  1121. "list": warehouseOutInfo,
  1122. "info": warehouseOut,
  1123. "wareoutList": wareoutList,
  1124. })
  1125. }
  1126. func (c *StockManagerApiController) EditWarehouseOut() {
  1127. warehouse_out_time := c.GetString("warehouse_out_time")
  1128. id, _ := c.GetInt64("id", 0)
  1129. types, _ := c.GetInt64("type", 0)
  1130. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1131. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1132. if id == 0 {
  1133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1134. return
  1135. }
  1136. ctime := time.Now().Unix()
  1137. mtime := time.Now().Unix()
  1138. adminUserInfo := c.GetAdminUserInfo()
  1139. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1140. if parseDateErr != nil {
  1141. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1143. return
  1144. }
  1145. warehouseOut, _ := service.FindWareHouseOutById(id)
  1146. tempWarehouseOut := models.WarehouseOut{
  1147. ID: warehouseOut.ID,
  1148. Mtime: mtime,
  1149. WarehouseOutTime: warehouseOutDate.Unix(),
  1150. Manufacturer: manufacturer_id,
  1151. Dealer: dealer_id,
  1152. }
  1153. service.EditWarehouseOut(tempWarehouseOut)
  1154. dataBody := make(map[string]interface{}, 0)
  1155. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1156. if err != nil {
  1157. utils.ErrorLog(err.Error())
  1158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1159. return
  1160. }
  1161. var warehousingOutInfo []*models.WarehouseOutInfo
  1162. var upDateWarehouseOutInfos []*models.WarehouseOutInfo
  1163. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1164. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1165. if len(thisStockOut) > 0 {
  1166. for _, item := range thisStockOut {
  1167. items := item.(map[string]interface{})
  1168. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1169. utils.ErrorLog("good_id")
  1170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1171. return
  1172. }
  1173. good_id := int64(items["good_id"].(float64))
  1174. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1175. utils.ErrorLog("good_type_id")
  1176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1177. return
  1178. }
  1179. good_type_id := int64(items["good_type_id"].(float64))
  1180. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1181. utils.ErrorLog("count")
  1182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1183. return
  1184. }
  1185. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1186. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1187. utils.ErrorLog("price")
  1188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1189. return
  1190. }
  1191. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1192. total := float64(count) * price
  1193. remark := items["remark"].(string)
  1194. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1195. utils.ErrorLog("id")
  1196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1197. return
  1198. }
  1199. id := int64(items["id"].(float64))
  1200. if id == 0 {
  1201. warehouseOutInfo := &models.WarehouseOutInfo{
  1202. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1203. WarehouseOutId: warehouseOut.ID,
  1204. GoodId: good_id,
  1205. GoodTypeId: good_type_id,
  1206. Count: count,
  1207. Price: price,
  1208. TotalPrice: total,
  1209. Status: 1,
  1210. Ctime: ctime,
  1211. Remark: remark,
  1212. OrgId: adminUserInfo.CurrentOrgId,
  1213. Type: types,
  1214. Manufacturer: manufacturer_id,
  1215. Dealer: dealer_id,
  1216. IsSys: 0,
  1217. SysRecordTime: 0,
  1218. }
  1219. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1220. } else {
  1221. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1222. utils.ErrorLog("is_sys")
  1223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1224. return
  1225. }
  1226. is_sys := int64(items["is_sys"].(float64))
  1227. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1228. utils.ErrorLog("sys_record_time")
  1229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1230. return
  1231. }
  1232. sys_record_time := int64(items["sys_record_time"].(float64))
  1233. warehouseOutInfo := &models.WarehouseOutInfo{
  1234. ID: id,
  1235. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1236. WarehouseOutId: warehouseOut.ID,
  1237. GoodId: good_id,
  1238. GoodTypeId: good_type_id,
  1239. Count: count,
  1240. Price: price,
  1241. TotalPrice: total,
  1242. Status: 1,
  1243. Ctime: ctime,
  1244. Remark: remark,
  1245. OrgId: adminUserInfo.CurrentOrgId,
  1246. Mtime: time.Now().Unix(),
  1247. Type: types,
  1248. Manufacturer: manufacturer_id,
  1249. Dealer: dealer_id,
  1250. IsSys: is_sys,
  1251. SysRecordTime: sys_record_time,
  1252. }
  1253. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1254. }
  1255. }
  1256. }
  1257. }
  1258. var errs error
  1259. if len(warehousingOutInfo) > 0 {
  1260. errs = service.CreateWarehousingOutInfo(warehousingOutInfo)
  1261. }
  1262. if len(upDateWarehouseOutInfos) > 0 {
  1263. for _, item := range upDateWarehouseOutInfos {
  1264. errs = service.UpDateWarehouseOutInfo(item)
  1265. }
  1266. }
  1267. if errs != nil {
  1268. utils.ErrorLog(errs.Error())
  1269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1270. return
  1271. }
  1272. c.ServeSuccessJSON(map[string]interface{}{
  1273. "msg": "编辑成功",
  1274. })
  1275. }
  1276. func (c *StockManagerApiController) CreateCancelStock() {
  1277. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1278. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1279. cancel_stock_time := c.GetString("time")
  1280. types, _ := c.GetInt64("type", 0)
  1281. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1282. if parseDateErr != nil {
  1283. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1285. return
  1286. }
  1287. adminUserInfo := c.GetAdminUserInfo()
  1288. operation_time := time.Now().Unix()
  1289. creater := adminUserInfo.AdminUser.Id
  1290. ctime := time.Now().Unix()
  1291. timeStr := time.Now().Format("2006-01-02")
  1292. timeArr := strings.Split(timeStr, "-")
  1293. total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
  1294. total = total + 1
  1295. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1296. cancelStock := models.CancelStock{
  1297. OrderNumber: orderNumber,
  1298. OperaTime: operation_time,
  1299. OrgId: adminUserInfo.CurrentOrgId,
  1300. Creater: creater,
  1301. Ctime: ctime,
  1302. Status: 1,
  1303. ReturnTime: cancelStockDate.Unix(),
  1304. Dealer: dealer_id,
  1305. Manufacturer: manufacturer_id,
  1306. Type: types,
  1307. }
  1308. service.AddSigleCancelStock(&cancelStock)
  1309. dataBody := make(map[string]interface{}, 0)
  1310. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1311. if err != nil {
  1312. utils.ErrorLog(err.Error())
  1313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1314. return
  1315. }
  1316. var cancelStockInfos []*models.CancelStockInfo
  1317. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1318. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1319. if len(thisStockIn) > 0 {
  1320. for _, item := range thisStockIn {
  1321. items := item.(map[string]interface{})
  1322. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1323. utils.ErrorLog("good_id")
  1324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1325. return
  1326. }
  1327. good_id := int64(items["good_id"].(float64))
  1328. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1329. utils.ErrorLog("good_type_id")
  1330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1331. return
  1332. }
  1333. good_type_id := int64(items["good_type_id"].(float64))
  1334. return_count, _ := items["return_count"].(string)
  1335. if len(return_count) == 0 {
  1336. utils.ErrorLog("len(return_count) == 0")
  1337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1338. return
  1339. }
  1340. count, _ := strconv.ParseInt(return_count, 10, 64)
  1341. cancelStockInfo := &models.CancelStockInfo{
  1342. OrderNumber: cancelStock.OrderNumber,
  1343. CancelStockId: cancelStock.ID,
  1344. GoodId: good_id,
  1345. GoodTypeId: good_type_id,
  1346. Count: count,
  1347. Status: 1,
  1348. Ctime: ctime,
  1349. OrgId: adminUserInfo.CurrentOrgId,
  1350. Type: types,
  1351. Manufacturer: manufacturer_id,
  1352. Dealer: dealer_id,
  1353. }
  1354. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1355. }
  1356. }
  1357. }
  1358. errs := service.CreateCancelStockInfo(cancelStockInfos)
  1359. if errs != nil {
  1360. utils.ErrorLog(errs.Error())
  1361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1362. return
  1363. }
  1364. c.ServeSuccessJSON(map[string]interface{}{
  1365. "msg": "退库成功",
  1366. })
  1367. }
  1368. func (c *StockManagerApiController) GetCancelStockInfoList() {
  1369. id, _ := c.GetInt64("id", 0)
  1370. cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
  1371. info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1372. c.ServeSuccessJSON(map[string]interface{}{
  1373. "list": cancelStockInfoList,
  1374. "info": info,
  1375. })
  1376. }
  1377. func (c *StockManagerApiController) GetCancelStockList() {
  1378. page, _ := c.GetInt64("page", -1)
  1379. limit, _ := c.GetInt64("limit", -1)
  1380. start_time := c.GetString("start_time")
  1381. end_time := c.GetString("end_time")
  1382. types, _ := c.GetInt64("type", 0)
  1383. keywords := c.GetString("keywords")
  1384. timeLayout := "2006-01-02"
  1385. loc, _ := time.LoadLocation("Local")
  1386. var startTime int64
  1387. if len(start_time) > 0 {
  1388. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1389. if err != nil {
  1390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1391. return
  1392. }
  1393. startTime = theTime.Unix()
  1394. }
  1395. var endTime int64
  1396. if len(end_time) > 0 {
  1397. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1398. if err != nil {
  1399. utils.ErrorLog(err.Error())
  1400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1401. return
  1402. }
  1403. endTime = theTime.Unix()
  1404. }
  1405. adminUserInfo := c.GetAdminUserInfo()
  1406. returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1407. if err == nil {
  1408. c.ServeSuccessJSON(map[string]interface{}{
  1409. "list": returnList,
  1410. "total": total,
  1411. })
  1412. } else {
  1413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1414. }
  1415. }
  1416. func (this *StockManagerApiController) DeleteCancelStock() {
  1417. ids := this.GetString("ids")
  1418. if len(ids) == 0 {
  1419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1420. return
  1421. }
  1422. idArray := strings.Split(ids, ",")
  1423. err := service.DeleteCancelStock(idArray)
  1424. if err != nil {
  1425. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1426. } else {
  1427. this.ServeSuccessJSON(map[string]interface{}{
  1428. "msg": "删除成功",
  1429. })
  1430. }
  1431. }
  1432. func (this *StockManagerApiController) DeleteCancelStockInfo() {
  1433. id, _ := this.GetInt64("id", 0)
  1434. fmt.Println(id)
  1435. if id == 0 {
  1436. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1437. return
  1438. }
  1439. err := service.UpDateCancleStockStatus(id)
  1440. if err != nil {
  1441. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1442. } else {
  1443. this.ServeSuccessJSON(map[string]interface{}{
  1444. "msg": "删除成功",
  1445. })
  1446. }
  1447. }
  1448. func (c *StockManagerApiController) EditCancelStock() {
  1449. cancel_time := c.GetString("cancel_time")
  1450. id, _ := c.GetInt64("id", 0)
  1451. types, _ := c.GetInt64("type", 0)
  1452. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1453. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1454. if id == 0 {
  1455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1456. return
  1457. }
  1458. ctime := time.Now().Unix()
  1459. mtime := time.Now().Unix()
  1460. adminUserInfo := c.GetAdminUserInfo()
  1461. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  1462. if parseDateErr != nil {
  1463. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  1464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1465. return
  1466. }
  1467. cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1468. tempCancelStock := models.CancelStock{
  1469. ID: cancelStock.ID,
  1470. Mtime: mtime,
  1471. ReturnTime: cancelDate.Unix(),
  1472. Manufacturer: manufacturer_id,
  1473. Dealer: dealer_id,
  1474. }
  1475. service.EditCancelStock(tempCancelStock)
  1476. dataBody := make(map[string]interface{}, 0)
  1477. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1478. if err != nil {
  1479. utils.ErrorLog(err.Error())
  1480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1481. return
  1482. }
  1483. var cancelStockInfos []*models.CancelStockInfo
  1484. var upDateCancelStockInfos []*models.CancelStockInfo
  1485. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1486. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  1487. if len(thisCancelStock) > 0 {
  1488. for _, item := range thisCancelStock {
  1489. items := item.(map[string]interface{})
  1490. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1491. utils.ErrorLog("good_id")
  1492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1493. return
  1494. }
  1495. good_id := int64(items["good_id"].(float64))
  1496. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1497. utils.ErrorLog("good_type_id")
  1498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1499. return
  1500. }
  1501. good_type_id := int64(items["good_type_id"].(float64))
  1502. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1503. utils.ErrorLog("count")
  1504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1505. return
  1506. }
  1507. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1508. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1509. utils.ErrorLog("id")
  1510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1511. return
  1512. }
  1513. id := int64(items["id"].(float64))
  1514. if id == 0 {
  1515. cancelStockInfo := &models.CancelStockInfo{
  1516. GoodId: good_id,
  1517. GoodTypeId: good_type_id,
  1518. Count: count,
  1519. Status: 1,
  1520. Ctime: ctime,
  1521. OrgId: adminUserInfo.CurrentOrgId,
  1522. OrderNumber: cancelStock.OrderNumber,
  1523. CancelStockId: cancelStock.ID,
  1524. Mtime: time.Now().Unix(),
  1525. Type: types,
  1526. Manufacturer: manufacturer_id,
  1527. Dealer: dealer_id,
  1528. }
  1529. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1530. } else {
  1531. cancelStockInfo := &models.CancelStockInfo{
  1532. ID: id,
  1533. GoodId: good_id,
  1534. GoodTypeId: good_type_id,
  1535. Count: count,
  1536. Status: 1,
  1537. Ctime: ctime,
  1538. OrgId: adminUserInfo.CurrentOrgId,
  1539. OrderNumber: cancelStock.OrderNumber,
  1540. CancelStockId: cancelStock.ID,
  1541. Mtime: time.Now().Unix(),
  1542. Type: types,
  1543. Manufacturer: manufacturer_id,
  1544. Dealer: dealer_id,
  1545. }
  1546. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  1547. }
  1548. }
  1549. }
  1550. }
  1551. var errs error
  1552. if len(cancelStockInfos) > 0 {
  1553. errs = service.CreateCancelStockInfo(cancelStockInfos)
  1554. }
  1555. if len(upDateCancelStockInfos) > 0 {
  1556. for _, item := range upDateCancelStockInfos {
  1557. errs = service.UpDateCancelStockInfo(item)
  1558. }
  1559. }
  1560. if errs != nil {
  1561. utils.ErrorLog(errs.Error())
  1562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1563. return
  1564. }
  1565. c.ServeSuccessJSON(map[string]interface{}{
  1566. "msg": "编辑成功",
  1567. })
  1568. }
  1569. func (this *StockManagerApiController) GetCancelStockConfig() {
  1570. types, _ := this.GetInt64("type", 0)
  1571. adminUserInfo := this.GetAdminUserInfo()
  1572. warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
  1573. this.ServeSuccessJSON(map[string]interface{}{
  1574. "warehouseOutInfoList": warehouseOutInfoList,
  1575. })
  1576. }
  1577. func (c *StockManagerApiController) GetQueryInfo() {
  1578. page, _ := c.GetInt64("page", -1)
  1579. limit, _ := c.GetInt64("limit", -1)
  1580. keyword := c.GetString("keyword")
  1581. start_time := c.GetString("start_time")
  1582. end_time := c.GetString("end_time")
  1583. type_name, _ := c.GetInt64("type_name")
  1584. timeLayout := "2006-01-02"
  1585. loc, _ := time.LoadLocation("Local")
  1586. var startTime int64
  1587. if len(start_time) > 0 {
  1588. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1589. if err != nil {
  1590. fmt.Println(err)
  1591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1592. return
  1593. }
  1594. startTime = theTime.Unix()
  1595. }
  1596. var endTime int64
  1597. if len(end_time) > 0 {
  1598. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1599. if err != nil {
  1600. utils.ErrorLog(err.Error())
  1601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1602. return
  1603. }
  1604. endTime = theTime.Unix()
  1605. }
  1606. adminUserInfo := c.GetAdminUserInfo()
  1607. list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
  1608. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  1609. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId, "")
  1610. if err == nil {
  1611. c.ServeSuccessJSON(map[string]interface{}{
  1612. "list": list,
  1613. "total": total,
  1614. "info": info,
  1615. "infomationList": infomationList,
  1616. "orgid": adminUserInfo.CurrentOrgId,
  1617. })
  1618. } else {
  1619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1620. }
  1621. }
  1622. func (c *StockManagerApiController) SearchWarehouse() {
  1623. keywords := c.GetString("keywords")
  1624. adminUserInfo := c.GetAdminUserInfo()
  1625. warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
  1626. if err == nil {
  1627. c.ServeSuccessJSON(map[string]interface{}{
  1628. "list": warehouseList,
  1629. "total": total,
  1630. })
  1631. } else {
  1632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1633. }
  1634. }
  1635. func (c *StockManagerApiController) GetAllConfig() {
  1636. adminUserInfo := c.GetAdminUserInfo()
  1637. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  1638. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  1639. goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  1640. goodInfo, _ := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  1641. c.ServeSuccessJSON(map[string]interface{}{
  1642. "manufacturer": manufacturer,
  1643. "dealer": dealer,
  1644. "goodType": goodType,
  1645. "goodInfo": goodInfo,
  1646. })
  1647. }
  1648. func (this *StockManagerApiController) GetAllSalesReturnConfig() {
  1649. types, _ := this.GetInt64("type", 0)
  1650. adminUserInfo := this.GetAdminUserInfo()
  1651. warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
  1652. this.ServeSuccessJSON(map[string]interface{}{
  1653. "warehouseInfoList": warehouseInfoList,
  1654. })
  1655. }
  1656. func (this *StockManagerApiController) GetDetailInfo() {
  1657. page, _ := this.GetInt64("page", 0)
  1658. limit, _ := this.GetInt64("limit", 0)
  1659. start_time := this.GetString("start_time")
  1660. end_time := this.GetString("end_time")
  1661. types, _ := this.GetInt64("type", 0)
  1662. keywords := this.GetString("keywords")
  1663. manufacturer, _ := this.GetInt64("manufacturer", 0)
  1664. order_type, _ := this.GetInt64("order_type", 0)
  1665. dealer, _ := this.GetInt64("dealer", 0)
  1666. timeLayout := "2006-01-02"
  1667. loc, _ := time.LoadLocation("Local")
  1668. var startTime int64
  1669. if len(start_time) > 0 {
  1670. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1671. if err != nil {
  1672. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1673. return
  1674. }
  1675. startTime = theTime.Unix()
  1676. }
  1677. var endTime int64
  1678. if len(end_time) > 0 {
  1679. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1680. if err != nil {
  1681. utils.ErrorLog(err.Error())
  1682. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1683. return
  1684. }
  1685. endTime = theTime.Unix()
  1686. }
  1687. adminUserInfo := this.GetAdminUserInfo()
  1688. var list []*models.WarehousingInfo
  1689. var list1 []*models.WarehouseOutInfo
  1690. var list2 []*models.SalesReturnInfo
  1691. var list3 []*models.CancelStockInfo
  1692. var total int64
  1693. var err error
  1694. var total_price float64
  1695. if types == 1 {
  1696. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1697. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1698. if err == nil {
  1699. this.ServeSuccessJSON(map[string]interface{}{
  1700. "list": list,
  1701. "total": total,
  1702. "total_price": total_price,
  1703. })
  1704. } else {
  1705. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1706. }
  1707. } else if types == 2 {
  1708. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1709. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1710. if err == nil {
  1711. this.ServeSuccessJSON(map[string]interface{}{
  1712. "list": list1,
  1713. "total": total,
  1714. "total_price": total_price,
  1715. })
  1716. } else {
  1717. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1718. }
  1719. } else if types == 3 {
  1720. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1721. if err == nil {
  1722. this.ServeSuccessJSON(map[string]interface{}{
  1723. "list": list2,
  1724. "total": total,
  1725. })
  1726. } else {
  1727. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1728. }
  1729. } else if types == 4 {
  1730. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1731. if err == nil {
  1732. this.ServeSuccessJSON(map[string]interface{}{
  1733. "list": list3,
  1734. "total": total,
  1735. })
  1736. } else {
  1737. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1738. }
  1739. }
  1740. }
  1741. func (this *StockManagerApiController) GetUserDetailInfo() {
  1742. order_id, _ := this.GetInt64("id")
  1743. if order_id <= 0 {
  1744. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1745. return
  1746. }
  1747. adminUserInfo := this.GetAdminUserInfo()
  1748. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  1749. if err == nil {
  1750. this.ServeSuccessJSON(map[string]interface{}{
  1751. "list": userDetails,
  1752. "total": total,
  1753. })
  1754. } else {
  1755. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1756. return
  1757. }
  1758. }
  1759. func (this *StockManagerApiController) PostSearchStock() {
  1760. keyword := this.GetString("keyword")
  1761. adminUserInfo := this.GetAdminUserInfo()
  1762. orgId := adminUserInfo.CurrentOrgId
  1763. stock, err := service.PostSearchStock(keyword, orgId)
  1764. if err != nil {
  1765. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1766. }
  1767. this.ServeSuccessJSON(map[string]interface{}{
  1768. "stock": stock,
  1769. })
  1770. }
  1771. func (this *StockManagerApiController) GetOutStockTotalCount() {
  1772. warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
  1773. adminUserInfo := this.GetAdminUserInfo()
  1774. stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
  1775. if err != nil {
  1776. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1777. }
  1778. this.ServeSuccessJSON(map[string]interface{}{
  1779. "stockCount": stockCount,
  1780. })
  1781. }
  1782. func (this *StockManagerApiController) AddGoodInformation() {
  1783. adminUserInfo := this.GetAdminUserInfo()
  1784. orgId := adminUserInfo.CurrentOrgId
  1785. dataBody := make(map[string]interface{}, 0)
  1786. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1787. if err != nil {
  1788. utils.ErrorLog(err.Error())
  1789. return
  1790. }
  1791. utils.ErrorLog("%v", dataBody)
  1792. var goods []*models.GoodInfo
  1793. var total_goods []interface{}
  1794. tempGoods := dataBody["goods"].([]interface{})
  1795. total_goods = tempGoods
  1796. for index, goodMap := range tempGoods {
  1797. goodNameM := goodMap.(map[string]interface{})
  1798. var good models.GoodInfo
  1799. if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
  1800. utils.ErrorLog("good_name")
  1801. return
  1802. }
  1803. good_name, _ := goodNameM["good_name"].(string)
  1804. if len(good_name) == 0 { //名字为空则生成一条导入错误日志
  1805. err_log := models.ExportErrLog{
  1806. LogType: 5,
  1807. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1808. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
  1809. Status: 1,
  1810. CreateTime: time.Now().Unix(),
  1811. UpdateTime: time.Now().Unix(),
  1812. ExportTime: time.Now().Unix(),
  1813. }
  1814. service.CreateExportErrLog(&err_log)
  1815. continue
  1816. }
  1817. good.GoodName = good_name
  1818. // 获取数据字典数据
  1819. var good_kind_id int64
  1820. var name = "耗材种类"
  1821. config, _ := service.GetDrugDataConfig(0, name)
  1822. good_kind := goodNameM["good_kind"].(string)
  1823. if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
  1824. err_log := models.ExportErrLog{
  1825. LogType: 5,
  1826. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1827. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
  1828. Status: 1,
  1829. CreateTime: time.Now().Unix(),
  1830. UpdateTime: time.Now().Unix(),
  1831. ExportTime: time.Now().Unix(),
  1832. }
  1833. service.CreateExportErrLog(&err_log)
  1834. continue
  1835. }
  1836. if len(good_kind) != 0 {
  1837. _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
  1838. lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
  1839. dataconfig := models.DictDataconfig{
  1840. ParentId: config.ID,
  1841. Module: "system",
  1842. OrgId: orgId,
  1843. Name: good_kind,
  1844. FieldName: "",
  1845. Value: lastConfig.Value + 1,
  1846. CreatedTime: "",
  1847. UpdatedTime: "",
  1848. CreateUserId: adminUserInfo.AdminUser.Id,
  1849. Status: 1,
  1850. Remark: "",
  1851. DeleteIdSystem: 0,
  1852. Title: "",
  1853. Content: "",
  1854. Order: 0,
  1855. Code: "",
  1856. }
  1857. if errcodegoodkind == gorm.ErrRecordNotFound {
  1858. service.CreatedDicConfig(&dataconfig)
  1859. }
  1860. }
  1861. dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
  1862. for _, it := range dataConfig {
  1863. if good_kind == it.Name {
  1864. fmt.Println(it.Name)
  1865. good_kind_id = int64(it.Value)
  1866. }
  1867. }
  1868. good.GoodKind = good_kind_id
  1869. good_type := goodNameM["type_name"].(string)
  1870. if len(good_type) == 0 {
  1871. err_log := models.ExportErrLog{
  1872. LogType: 5,
  1873. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1874. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
  1875. Status: 1,
  1876. CreateTime: time.Now().Unix(),
  1877. UpdateTime: time.Now().Unix(),
  1878. ExportTime: time.Now().Unix(),
  1879. }
  1880. service.CreateExportErrLog(&err_log)
  1881. continue
  1882. }
  1883. if len(good_type) != 0 {
  1884. _, errcodegoodtype := service.GetGoodType(good_type, orgId)
  1885. if errcodegoodtype == gorm.ErrRecordNotFound {
  1886. goodsType := models.GoodsType{
  1887. TypeName: good_type,
  1888. Remark: "",
  1889. Ctime: time.Now().Unix(),
  1890. Mtime: 0,
  1891. Creater: adminUserInfo.AdminUser.Id,
  1892. Modifier: 0,
  1893. OrgId: adminUserInfo.CurrentOrgId,
  1894. Status: 1,
  1895. Type: 0,
  1896. Number: 0,
  1897. OutStock: 0,
  1898. StockAttribute: 1,
  1899. }
  1900. service.CreatedGoodType(&goodsType)
  1901. }
  1902. }
  1903. goodType, _ := service.GetAllGoodType(orgId)
  1904. var good_type_id int64
  1905. for _, it := range goodType {
  1906. if good_type == it.TypeName {
  1907. good_type_id = it.ID
  1908. }
  1909. }
  1910. good.GoodTypeId = good_type_id
  1911. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  1912. if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
  1913. err_log := models.ExportErrLog{
  1914. LogType: 5,
  1915. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1916. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  1917. Status: 1,
  1918. CreateTime: time.Now().Unix(),
  1919. UpdateTime: time.Now().Unix(),
  1920. ExportTime: time.Now().Unix(),
  1921. }
  1922. service.CreateExportErrLog(&err_log)
  1923. continue
  1924. }
  1925. var medical_insurance_id int64
  1926. var medicalInsurance = "医保等级"
  1927. medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
  1928. if len(medical_insurance_level) != 0 {
  1929. _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
  1930. if errcodemedicalInsurance == gorm.ErrRecordNotFound {
  1931. mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
  1932. dataconfig := models.DictDataconfig{
  1933. ParentId: medicalInsuranceDataConfig.ID,
  1934. Module: "system",
  1935. OrgId: orgId,
  1936. Name: medical_insurance_level,
  1937. FieldName: "",
  1938. Value: mediConfigOne.Value + 1,
  1939. CreatedTime: "",
  1940. UpdatedTime: "",
  1941. CreateUserId: adminUserInfo.AdminUser.Id,
  1942. Status: 1,
  1943. Remark: "",
  1944. DeleteIdSystem: 0,
  1945. Title: "",
  1946. Content: "",
  1947. Order: 0,
  1948. Code: "",
  1949. }
  1950. service.CreatedDicConfig(&dataconfig)
  1951. }
  1952. }
  1953. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
  1954. for _, it := range medicalInsuranceList {
  1955. if medical_insurance_level == it.Name {
  1956. medical_insurance_id = int64(it.Value)
  1957. }
  1958. }
  1959. good.MedicalInsuranceLevel = medical_insurance_id
  1960. if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
  1961. utils.ErrorLog("specification_name")
  1962. return
  1963. }
  1964. specification_name := goodNameM["specification_name"].(string)
  1965. if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
  1966. err_log := models.ExportErrLog{
  1967. LogType: 5,
  1968. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1969. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
  1970. Status: 1,
  1971. CreateTime: time.Now().Unix(),
  1972. UpdateTime: time.Now().Unix(),
  1973. ExportTime: time.Now().Unix(),
  1974. }
  1975. service.CreateExportErrLog(&err_log)
  1976. continue
  1977. }
  1978. good.SpecificationName = specification_name
  1979. var manufacturer_id int64
  1980. manufacturer := goodNameM["manufacturer"].(string)
  1981. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  1982. err_log := models.ExportErrLog{
  1983. LogType: 5,
  1984. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1985. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
  1986. Status: 1,
  1987. CreateTime: time.Now().Unix(),
  1988. UpdateTime: time.Now().Unix(),
  1989. ExportTime: time.Now().Unix(),
  1990. }
  1991. service.CreateExportErrLog(&err_log)
  1992. continue
  1993. }
  1994. if len(manufacturer) != 0 {
  1995. _, errcodes := service.GetManufacturerName(orgId, manufacturer)
  1996. manu := models.Manufacturer{
  1997. ManufacturerName: manufacturer,
  1998. Status: 1,
  1999. OrgId: orgId,
  2000. Creater: adminUserInfo.AdminUser.Id,
  2001. }
  2002. if errcodes == gorm.ErrRecordNotFound {
  2003. service.CreateManufacturer(&manu)
  2004. }
  2005. }
  2006. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2007. for _, it := range manufacturerList {
  2008. if manufacturer == it.ManufacturerName {
  2009. manufacturer_id = it.ID
  2010. }
  2011. }
  2012. good.Manufacturer = manufacturer_id
  2013. if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
  2014. utils.ErrorLog("unit_id")
  2015. return
  2016. }
  2017. unit_id := int64(goodNameM["unit_id"].(float64))
  2018. if unit_id <= 0 { //名字为空则生成一条导入错误日志
  2019. err_log := models.ExportErrLog{
  2020. LogType: 5,
  2021. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2022. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
  2023. Status: 1,
  2024. CreateTime: time.Now().Unix(),
  2025. UpdateTime: time.Now().Unix(),
  2026. ExportTime: time.Now().Unix(),
  2027. }
  2028. service.CreateExportErrLog(&err_log)
  2029. continue
  2030. }
  2031. good.GoodUnit = unit_id
  2032. retail_prices := goodNameM["retail_price"].(string)
  2033. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  2034. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  2035. err_log := models.ExportErrLog{
  2036. LogType: 5,
  2037. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2038. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
  2039. Status: 1,
  2040. CreateTime: time.Now().Unix(),
  2041. UpdateTime: time.Now().Unix(),
  2042. ExportTime: time.Now().Unix(),
  2043. }
  2044. service.CreateExportErrLog(&err_log)
  2045. continue
  2046. }
  2047. good.RetailPrice = retail_price
  2048. if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
  2049. utils.ErrorLog("stock_warn_count")
  2050. return
  2051. }
  2052. stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
  2053. if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
  2054. err_log := models.ExportErrLog{
  2055. LogType: 5,
  2056. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2057. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
  2058. Status: 1,
  2059. CreateTime: time.Now().Unix(),
  2060. UpdateTime: time.Now().Unix(),
  2061. ExportTime: time.Now().Unix(),
  2062. }
  2063. service.CreateExportErrLog(&err_log)
  2064. continue
  2065. }
  2066. good.StockWarnCount = stock_warn_count
  2067. var dealer_id int64
  2068. dealerName := goodNameM["dealer"].(string)
  2069. fmt.Println("经销商", dealerName)
  2070. dealer := models.Dealer{
  2071. OrgId: orgId,
  2072. Status: 1,
  2073. DealerName: dealerName,
  2074. Creater: adminUserInfo.AdminUser.Id,
  2075. Ctime: time.Now().Unix(),
  2076. }
  2077. if len(dealerName) != 0 {
  2078. _, errcodedealer := service.GetDealerByName(orgId, dealerName)
  2079. if errcodedealer == gorm.ErrRecordNotFound {
  2080. service.CreateDealer(&dealer)
  2081. }
  2082. }
  2083. dealerList, _ := service.GetAllDealerList(orgId)
  2084. for _, it := range dealerList {
  2085. if dealerName == it.DealerName {
  2086. dealer_id = it.ID
  2087. }
  2088. }
  2089. good.Dealer = dealer_id
  2090. if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
  2091. utils.ErrorLog("pinyin")
  2092. return
  2093. }
  2094. pinyin := goodNameM["pinyin"].(string)
  2095. good.Pinyin = pinyin
  2096. if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
  2097. utils.ErrorLog("wubi")
  2098. return
  2099. }
  2100. wubi := goodNameM["wubi"].(string)
  2101. good.Wubi = wubi
  2102. buy_prices := goodNameM["buy_price"].(string)
  2103. buy_price, _ := strconv.ParseFloat(buy_prices, 64)
  2104. good.BuyPrice = buy_price
  2105. if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
  2106. utils.ErrorLog("social_security_directory_code")
  2107. return
  2108. }
  2109. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  2110. good.SocialSecurityDirectoryCode = social_security_directory_code
  2111. if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
  2112. utils.ErrorLog("is_special_diseases")
  2113. return
  2114. }
  2115. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  2116. good.IsSpecialDiseases = is_special_diseases
  2117. if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
  2118. utils.ErrorLog("is_record")
  2119. return
  2120. }
  2121. is_record := int64(goodNameM["is_record"].(float64))
  2122. good.IsRecord = is_record
  2123. if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
  2124. utils.ErrorLog("good_status")
  2125. return
  2126. }
  2127. good_status := goodNameM["good_status"].(string)
  2128. good.GoodStatus = good_status
  2129. if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
  2130. utils.ErrorLog("medical_insurance_number")
  2131. return
  2132. }
  2133. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  2134. good.MedicalInsuranceNumber = medical_insurance_number
  2135. if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
  2136. utils.ErrorLog("production_type")
  2137. return
  2138. }
  2139. production_type := goodNameM["production_type"].(string)
  2140. good.ProductionType = production_type
  2141. if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
  2142. utils.ErrorLog("remark")
  2143. return
  2144. }
  2145. remark := goodNameM["remark"].(string)
  2146. good.Remark = remark
  2147. statistics_category := goodNameM["statistics_category"].(string)
  2148. var categoryName = "统计分类"
  2149. var statistic_id int64
  2150. drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
  2151. if len(statistics_category) != 0 {
  2152. _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
  2153. if errcodecagegory == gorm.ErrRecordNotFound {
  2154. dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
  2155. dataconfig := models.DictDataconfig{
  2156. ParentId: drugDataConfig.ID,
  2157. Module: "system",
  2158. OrgId: orgId,
  2159. Name: statistics_category,
  2160. FieldName: "",
  2161. Value: dicConfigThree.Value + 1,
  2162. CreatedTime: "",
  2163. UpdatedTime: "",
  2164. CreateUserId: adminUserInfo.AdminUser.Id,
  2165. Status: 1,
  2166. Remark: "",
  2167. DeleteIdSystem: 0,
  2168. Title: "",
  2169. Content: "",
  2170. Order: 0,
  2171. Code: "",
  2172. }
  2173. service.CreatedDicConfig(&dataconfig)
  2174. }
  2175. }
  2176. parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
  2177. for _, it := range parentDataConfig {
  2178. if statistics_category == it.Name {
  2179. statistic_id = int64(it.Value)
  2180. }
  2181. }
  2182. good.StatisticsCategory = statistic_id
  2183. special_medical := goodNameM["special_medical"].(string)
  2184. good.SpecialMedical = special_medical
  2185. goods = append(goods, &good)
  2186. }
  2187. export_time := time.Now().Unix()
  2188. errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2189. if len(goods) > 0 {
  2190. for _, item := range goods {
  2191. goodInfo := models.GoodInfo{
  2192. GoodName: item.GoodName,
  2193. SpecificationName: item.SpecificationName,
  2194. GoodKind: item.GoodKind,
  2195. GoodTypeId: item.GoodTypeId,
  2196. Dealer: item.Dealer,
  2197. GoodUnit: item.GoodUnit,
  2198. IsRecord: item.IsRecord,
  2199. IsSpecialDiseases: item.IsSpecialDiseases,
  2200. Manufacturer: item.Manufacturer,
  2201. Pinyin: item.Pinyin,
  2202. GoodStatus: item.GoodStatus,
  2203. ProductionType: item.ProductionType,
  2204. Remark: item.Remark,
  2205. RetailPrice: item.RetailPrice,
  2206. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  2207. SpecialMedical: item.SpecialMedical,
  2208. Wubi: item.Wubi,
  2209. StockWarnCount: item.StockWarnCount,
  2210. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  2211. OrgId: orgId,
  2212. Status: 1,
  2213. Ctime: time.Now().Unix(),
  2214. StatisticsCategory: item.StatisticsCategory,
  2215. GoodCode: item.GoodCode,
  2216. BuyPrice: item.BuyPrice,
  2217. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  2218. }
  2219. //查询同种耗材名称同种类型同种规格的耗材是否存在
  2220. _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2221. if errcodegood == gorm.ErrRecordNotFound {
  2222. service.CreateGoodsInfomation(&goodInfo)
  2223. } else if errcodegood == nil {
  2224. service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2225. }
  2226. log := models.ExportLog{
  2227. LogType: 5,
  2228. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2229. TotalNum: int64(len(total_goods)),
  2230. FailNum: int64(len(errLogs)),
  2231. SuccessNum: int64(len(goods)),
  2232. CreateTime: time.Now().Unix(),
  2233. UpdateTime: time.Now().Unix(),
  2234. ExportTime: export_time,
  2235. Status: 1,
  2236. }
  2237. service.CreateExportLog(&log)
  2238. this.ServeSuccessJSON(map[string]interface{}{
  2239. "msg": "导入成功",
  2240. "total_num": len(total_goods),
  2241. "success_num": len(goods),
  2242. "fail_num": int64(len(errLogs)),
  2243. })
  2244. }
  2245. } else {
  2246. log := models.ExportLog{
  2247. LogType: 5,
  2248. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2249. TotalNum: int64(len(total_goods)),
  2250. FailNum: int64(len(errLogs)),
  2251. SuccessNum: int64(len(goods)),
  2252. CreateTime: time.Now().Unix(),
  2253. UpdateTime: time.Now().Unix(),
  2254. ExportTime: export_time,
  2255. Status: 1,
  2256. }
  2257. service.CreateExportLog(&log)
  2258. this.ServeSuccessJSON(map[string]interface{}{
  2259. "msg": "导入成功",
  2260. "total_num": len(total_goods),
  2261. "success_num": len(goods),
  2262. "fail_num": int64(len(errLogs)),
  2263. })
  2264. }
  2265. }
  2266. func (this *StockManagerApiController) AddDrugInformation() {
  2267. adminUser := this.GetAdminUserInfo()
  2268. orgId := adminUser.CurrentOrgId
  2269. dataBody := make(map[string]interface{}, 0)
  2270. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2271. if err != nil {
  2272. utils.ErrorLog(err.Error())
  2273. return
  2274. }
  2275. utils.ErrorLog("%v", dataBody)
  2276. var drugList []*models.BaseDrugLib
  2277. var total_goods []interface{}
  2278. tempDrugs := dataBody["drugs"].([]interface{})
  2279. total_goods = tempDrugs
  2280. for index, drugMap := range tempDrugs {
  2281. goodNameM := drugMap.(map[string]interface{})
  2282. var drug models.BaseDrugLib
  2283. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  2284. utils.ErrorLog("drug_name")
  2285. return
  2286. }
  2287. drug_name, _ := goodNameM["drug_name"].(string)
  2288. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2289. err_log := models.ExportErrLog{
  2290. LogType: 4,
  2291. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2292. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  2293. Status: 1,
  2294. CreateTime: time.Now().Unix(),
  2295. UpdateTime: time.Now().Unix(),
  2296. ExportTime: time.Now().Unix(),
  2297. }
  2298. service.CreateExportErrLog(&err_log)
  2299. continue
  2300. }
  2301. drug.DrugName = drug_name
  2302. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  2303. utils.ErrorLog("min_number")
  2304. return
  2305. }
  2306. min_number, _ := goodNameM["min_number"].(string)
  2307. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  2308. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2309. err_log := models.ExportErrLog{
  2310. LogType: 4,
  2311. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2312. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  2313. Status: 1,
  2314. CreateTime: time.Now().Unix(),
  2315. UpdateTime: time.Now().Unix(),
  2316. ExportTime: time.Now().Unix(),
  2317. }
  2318. service.CreateExportErrLog(&err_log)
  2319. continue
  2320. }
  2321. drug.MinNumber = minNumber
  2322. min_unit := goodNameM["min_unit"].(string)
  2323. if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
  2324. err_log := models.ExportErrLog{
  2325. LogType: 4,
  2326. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2327. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
  2328. Status: 1,
  2329. CreateTime: time.Now().Unix(),
  2330. UpdateTime: time.Now().Unix(),
  2331. ExportTime: time.Now().Unix(),
  2332. }
  2333. service.CreateExportErrLog(&err_log)
  2334. continue
  2335. }
  2336. drug.MinUnit = min_unit
  2337. dose := goodNameM["dose"].(float64)
  2338. if dose < 0 { //名字为空则生成一条导入错误日志
  2339. err_log := models.ExportErrLog{
  2340. LogType: 4,
  2341. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2342. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  2343. Status: 1,
  2344. CreateTime: time.Now().Unix(),
  2345. UpdateTime: time.Now().Unix(),
  2346. ExportTime: time.Now().Unix(),
  2347. }
  2348. service.CreateExportErrLog(&err_log)
  2349. continue
  2350. }
  2351. drug.Dose = dose
  2352. max_unit_id := goodNameM["max_unit"].(string)
  2353. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  2354. err_log := models.ExportErrLog{
  2355. LogType: 4,
  2356. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2357. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  2358. Status: 1,
  2359. CreateTime: time.Now().Unix(),
  2360. UpdateTime: time.Now().Unix(),
  2361. ExportTime: time.Now().Unix(),
  2362. }
  2363. service.CreateExportErrLog(&err_log)
  2364. continue
  2365. }
  2366. drug.MaxUnit = max_unit_id
  2367. max_unit := goodNameM["max_unit"].(string)
  2368. if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
  2369. err_log := models.ExportErrLog{
  2370. LogType: 4,
  2371. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2372. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
  2373. Status: 1,
  2374. CreateTime: time.Now().Unix(),
  2375. UpdateTime: time.Now().Unix(),
  2376. ExportTime: time.Now().Unix(),
  2377. }
  2378. service.CreateExportErrLog(&err_log)
  2379. continue
  2380. }
  2381. drug.MaxUnit = max_unit
  2382. delivery_way := goodNameM["delivery_way"].(string)
  2383. if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
  2384. err_log := models.ExportErrLog{
  2385. LogType: 4,
  2386. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2387. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
  2388. Status: 1,
  2389. CreateTime: time.Now().Unix(),
  2390. UpdateTime: time.Now().Unix(),
  2391. ExportTime: time.Now().Unix(),
  2392. }
  2393. service.CreateExportErrLog(&err_log)
  2394. continue
  2395. }
  2396. drug.DeliveryWay = delivery_way
  2397. execution_frequency := goodNameM["execution_frequency"].(string)
  2398. if len(execution_frequency) == 0 { //名字为空则生成一条导入错误日志
  2399. err_log := models.ExportErrLog{
  2400. LogType: 4,
  2401. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2402. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  2403. Status: 1,
  2404. CreateTime: time.Now().Unix(),
  2405. UpdateTime: time.Now().Unix(),
  2406. ExportTime: time.Now().Unix(),
  2407. }
  2408. service.CreateExportErrLog(&err_log)
  2409. continue
  2410. }
  2411. drug.ExecutionFrequency = execution_frequency
  2412. drug_day := goodNameM["drug_day"].(string)
  2413. if len(drug_day) == 0 { //名字为空则生成一条导入错误日志
  2414. err_log := models.ExportErrLog{
  2415. LogType: 4,
  2416. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2417. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  2418. Status: 1,
  2419. CreateTime: time.Now().Unix(),
  2420. UpdateTime: time.Now().Unix(),
  2421. ExportTime: time.Now().Unix(),
  2422. }
  2423. service.CreateExportErrLog(&err_log)
  2424. continue
  2425. }
  2426. drug.DrugDay = drug_day
  2427. drug_type := goodNameM["drug_type"].(string)
  2428. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  2429. err_log := models.ExportErrLog{
  2430. LogType: 4,
  2431. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2432. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
  2433. Status: 1,
  2434. CreateTime: time.Now().Unix(),
  2435. UpdateTime: time.Now().Unix(),
  2436. ExportTime: time.Now().Unix(),
  2437. }
  2438. service.CreateExportErrLog(&err_log)
  2439. continue
  2440. }
  2441. var drug_type_id int64
  2442. var drugType = "药品类型"
  2443. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  2444. if len(drug_type) != 0 {
  2445. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  2446. if errcodes == gorm.ErrRecordNotFound {
  2447. //获取该型号最后一条数据型号
  2448. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  2449. dataconfig := models.DictDataconfig{
  2450. ParentId: drugconfig.ID,
  2451. Module: "system",
  2452. OrgId: orgId,
  2453. Name: drug_type,
  2454. FieldName: "",
  2455. Value: config.Value + 1,
  2456. CreatedTime: "",
  2457. UpdatedTime: "",
  2458. CreateUserId: adminUser.AdminUser.Id,
  2459. Status: 1,
  2460. Remark: "",
  2461. DeleteIdSystem: 0,
  2462. Title: "",
  2463. Content: "",
  2464. Order: 0,
  2465. Code: "",
  2466. }
  2467. service.CreatedDicConfig(&dataconfig)
  2468. }
  2469. }
  2470. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  2471. for _, it := range drugTypeList {
  2472. if drug_type == it.Name {
  2473. drug_type_id = int64(it.Value)
  2474. }
  2475. }
  2476. drug.DrugType = drug_type_id
  2477. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  2478. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  2479. err_log := models.ExportErrLog{
  2480. LogType: 4,
  2481. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2482. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  2483. Status: 1,
  2484. CreateTime: time.Now().Unix(),
  2485. UpdateTime: time.Now().Unix(),
  2486. ExportTime: time.Now().Unix(),
  2487. }
  2488. service.CreateExportErrLog(&err_log)
  2489. continue
  2490. }
  2491. drug.DrugStockLimit = drug_stock_limit
  2492. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  2493. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  2494. err_log := models.ExportErrLog{
  2495. LogType: 4,
  2496. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2497. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  2498. Status: 1,
  2499. CreateTime: time.Now().Unix(),
  2500. UpdateTime: time.Now().Unix(),
  2501. ExportTime: time.Now().Unix(),
  2502. }
  2503. service.CreateExportErrLog(&err_log)
  2504. continue
  2505. }
  2506. drug.DrugOriginPlace = drug_origin_place
  2507. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  2508. if len(drug_dosage_form) == 0 {
  2509. err_log := models.ExportErrLog{
  2510. LogType: 4,
  2511. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2512. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  2513. Status: 1,
  2514. CreateTime: time.Now().Unix(),
  2515. UpdateTime: time.Now().Unix(),
  2516. ExportTime: time.Now().Unix(),
  2517. }
  2518. service.CreateExportErrLog(&err_log)
  2519. continue
  2520. }
  2521. var drug_dosage = "药品剂型"
  2522. var drug_dosage_form_id int64
  2523. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  2524. if len(drug_dosage_form) != 0 {
  2525. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  2526. if errcodess == gorm.ErrRecordNotFound {
  2527. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  2528. dataconfig := models.DictDataconfig{
  2529. ParentId: drugDosageconfig.ID,
  2530. Module: "system",
  2531. OrgId: orgId,
  2532. Name: drug_dosage_form,
  2533. FieldName: "",
  2534. Value: configOne.Value + 1,
  2535. CreatedTime: "",
  2536. UpdatedTime: "",
  2537. CreateUserId: adminUser.AdminUser.Id,
  2538. Status: 1,
  2539. Remark: "",
  2540. DeleteIdSystem: 0,
  2541. Title: "",
  2542. Content: "",
  2543. Order: 0,
  2544. Code: "",
  2545. }
  2546. service.CreatedDicConfig(&dataconfig)
  2547. }
  2548. }
  2549. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  2550. for _, it := range drugDosageList {
  2551. if drug_dosage_form == it.Name {
  2552. drug_dosage_form_id = int64(it.Value)
  2553. }
  2554. }
  2555. drug.DrugDosageForm = drug_dosage_form_id
  2556. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  2557. var medical_insurance_level_id int64
  2558. if len(medical_insurance_level) == 0 { //名字为空则生成一条导入错误日志
  2559. err_log := models.ExportErrLog{
  2560. LogType: 4,
  2561. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2562. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  2563. Status: 1,
  2564. CreateTime: time.Now().Unix(),
  2565. UpdateTime: time.Now().Unix(),
  2566. ExportTime: time.Now().Unix(),
  2567. }
  2568. service.CreateExportErrLog(&err_log)
  2569. continue
  2570. }
  2571. var medicalInsuranceName = "医保等级"
  2572. medicalInsuranceConfig, _ := service.GetDrugDataConfig(0, medicalInsuranceName)
  2573. if len(medical_insurance_level) != 0 {
  2574. _, errcodemedical := service.IsExistDicConfig(medicalInsuranceConfig.ID, medical_insurance_level, orgId)
  2575. if errcodemedical == gorm.ErrRecordNotFound {
  2576. medConfig, _ := service.GetLastDicConfig(medicalInsuranceConfig.ID, orgId)
  2577. dataconfig := models.DictDataconfig{
  2578. ParentId: medicalInsuranceConfig.ID,
  2579. Module: "system",
  2580. OrgId: orgId,
  2581. Name: medical_insurance_level,
  2582. FieldName: "",
  2583. Value: medConfig.Value + 1,
  2584. CreatedTime: "",
  2585. UpdatedTime: "",
  2586. CreateUserId: adminUser.AdminUser.Id,
  2587. Status: 1,
  2588. Remark: "",
  2589. DeleteIdSystem: 0,
  2590. Title: "",
  2591. Content: "",
  2592. Order: 0,
  2593. Code: "",
  2594. }
  2595. service.CreatedDicConfig(&dataconfig)
  2596. }
  2597. }
  2598. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceConfig.ID, orgId)
  2599. for _, it := range medicalInsuranceList {
  2600. if medical_insurance_level == it.Name {
  2601. medical_insurance_level_id = int64(it.Value)
  2602. }
  2603. }
  2604. drug.MedicalInsuranceLevel = medical_insurance_level_id
  2605. unit_matrixing := goodNameM["unit_matrixing"].(string)
  2606. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  2607. err_log := models.ExportErrLog{
  2608. LogType: 4,
  2609. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2610. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位换算不能为空",
  2611. Status: 1,
  2612. CreateTime: time.Now().Unix(),
  2613. UpdateTime: time.Now().Unix(),
  2614. ExportTime: time.Now().Unix(),
  2615. }
  2616. service.CreateExportErrLog(&err_log)
  2617. continue
  2618. }
  2619. drug.UnitMatrixing = unit_matrixing
  2620. retail_prices := goodNameM["retail_price"].(string)
  2621. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  2622. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  2623. err_log := models.ExportErrLog{
  2624. LogType: 4,
  2625. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2626. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  2627. Status: 1,
  2628. CreateTime: time.Now().Unix(),
  2629. UpdateTime: time.Now().Unix(),
  2630. ExportTime: time.Now().Unix(),
  2631. }
  2632. service.CreateExportErrLog(&err_log)
  2633. continue
  2634. }
  2635. drug.RetailPrice = retail_price
  2636. packing_prices := goodNameM["packing_price"].(string)
  2637. packing_price, _ := strconv.ParseFloat(packing_prices, 64)
  2638. if packing_price <= 0 { //名字为空则生成一条导入错误日志
  2639. err_log := models.ExportErrLog{
  2640. LogType: 4,
  2641. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2642. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装零售价不能为空",
  2643. Status: 1,
  2644. CreateTime: time.Now().Unix(),
  2645. UpdateTime: time.Now().Unix(),
  2646. ExportTime: time.Now().Unix(),
  2647. }
  2648. service.CreateExportErrLog(&err_log)
  2649. continue
  2650. }
  2651. drug.RetailPrice = retail_price
  2652. last_prices := goodNameM["last_price"].(string)
  2653. last_price, _ := strconv.ParseFloat(last_prices, 64)
  2654. if last_price <= 0 { //名字为空则生成一条导入错误日志
  2655. err_log := models.ExportErrLog{
  2656. LogType: 4,
  2657. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2658. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  2659. Status: 1,
  2660. CreateTime: time.Now().Unix(),
  2661. UpdateTime: time.Now().Unix(),
  2662. ExportTime: time.Now().Unix(),
  2663. }
  2664. service.CreateExportErrLog(&err_log)
  2665. continue
  2666. }
  2667. drug.LastPrice = last_price
  2668. drug_classify := goodNameM["drug_classify"].(string)
  2669. if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
  2670. err_log := models.ExportErrLog{
  2671. LogType: 4,
  2672. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2673. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
  2674. Status: 1,
  2675. CreateTime: time.Now().Unix(),
  2676. UpdateTime: time.Now().Unix(),
  2677. ExportTime: time.Now().Unix(),
  2678. }
  2679. service.CreateExportErrLog(&err_log)
  2680. continue
  2681. }
  2682. var drugClassify = "药物分类"
  2683. var drug_classify_id int64
  2684. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  2685. if len(drug_classify) != 0 {
  2686. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  2687. if errcodesClass == gorm.ErrRecordNotFound {
  2688. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  2689. dataconfig := models.DictDataconfig{
  2690. ParentId: drugClassifyConfig.ID,
  2691. Module: "system",
  2692. OrgId: orgId,
  2693. Name: drug_classify,
  2694. FieldName: "",
  2695. Value: drugClassConfig.Value + 1,
  2696. CreatedTime: "",
  2697. UpdatedTime: "",
  2698. CreateUserId: adminUser.AdminUser.Id,
  2699. Status: 1,
  2700. Remark: "",
  2701. DeleteIdSystem: 0,
  2702. Title: "",
  2703. Content: "",
  2704. Order: 0,
  2705. Code: "",
  2706. }
  2707. service.CreatedDicConfig(&dataconfig)
  2708. }
  2709. }
  2710. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  2711. for _, it := range drugClassList {
  2712. if drug_classify == it.Name {
  2713. drug_classify_id = int64(it.Value)
  2714. }
  2715. }
  2716. drug_dose := goodNameM["drug_dose"].(string)
  2717. if len(drug_dose) == 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. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  2731. drug.DrugDose = drugDoses
  2732. var units = "单位"
  2733. var unit_id int64
  2734. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  2735. if len(drugDoseUnit) == 0 {
  2736. err_log := models.ExportErrLog{
  2737. LogType: 4,
  2738. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2739. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  2740. Status: 1,
  2741. CreateTime: time.Now().Unix(),
  2742. UpdateTime: time.Now().Unix(),
  2743. ExportTime: time.Now().Unix(),
  2744. }
  2745. service.CreateExportErrLog(&err_log)
  2746. continue
  2747. }
  2748. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  2749. if len(drugDoseUnit) != 0 {
  2750. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  2751. if errcodedataconfig == gorm.ErrRecordNotFound {
  2752. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  2753. dataconfig := models.Dataconfig{
  2754. ParentId: dataConfig.ID,
  2755. Module: "hemodialysis",
  2756. OrgId: orgId,
  2757. Name: drugDoseUnit,
  2758. FieldName: "",
  2759. Value: childConfig.Value + 1,
  2760. CreatedTime: "",
  2761. UpdatedTime: "",
  2762. CreateUserId: adminUser.AdminUser.Id,
  2763. Status: 1,
  2764. Remark: "",
  2765. DeleteIdSystem: 0,
  2766. Title: "",
  2767. Content: "",
  2768. Order: 0,
  2769. Code: "",
  2770. FieldType: 0,
  2771. }
  2772. service.CreateDataConfig(&dataconfig)
  2773. }
  2774. }
  2775. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  2776. for _, it := range list {
  2777. if drugDoseUnit == it.Name {
  2778. unit_id = int64(it.Value)
  2779. }
  2780. }
  2781. drug.DrugDoseUnit = unit_id
  2782. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  2783. manufacturer := goodNameM["manufacturer"].(string)
  2784. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  2785. err_log := models.ExportErrLog{
  2786. LogType: 4,
  2787. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2788. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  2789. Status: 1,
  2790. CreateTime: time.Now().Unix(),
  2791. UpdateTime: time.Now().Unix(),
  2792. ExportTime: time.Now().Unix(),
  2793. }
  2794. service.CreateExportErrLog(&err_log)
  2795. continue
  2796. }
  2797. if len(manufacturer) != 0 {
  2798. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  2799. if errcodema == gorm.ErrRecordNotFound {
  2800. manufactur := models.Manufacturer{
  2801. OrgId: orgId,
  2802. Status: 1,
  2803. ManufacturerName: manufacturer,
  2804. Ctime: time.Now().Unix(),
  2805. Creater: adminUser.AdminUser.Id,
  2806. }
  2807. service.CreateManufacturer(&manufactur)
  2808. }
  2809. }
  2810. var manufacturer_id int64
  2811. manufacturList, _ := service.GetAllManufacturerList(orgId)
  2812. for _, it := range manufacturList {
  2813. if manufacturer == it.ManufacturerName {
  2814. manufacturer_id = it.ID
  2815. }
  2816. }
  2817. drug.Manufacturer = manufacturer_id
  2818. dealer := goodNameM["dealer"].(string)
  2819. if len(dealer) != 0 {
  2820. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  2821. if errcodesdealer == gorm.ErrRecordNotFound {
  2822. dealerconfig := models.Dealer{
  2823. DealerName: dealer,
  2824. Status: 1,
  2825. OrgId: orgId,
  2826. Ctime: time.Now().Unix(),
  2827. Creater: adminUser.AdminUser.Id,
  2828. }
  2829. service.CreateDealer(&dealerconfig)
  2830. }
  2831. }
  2832. var dealer_id int64
  2833. dealerList, _ := service.GetAllDealerList(orgId)
  2834. for _, it := range dealerList {
  2835. if dealer == it.DealerName {
  2836. dealer_id = it.ID
  2837. }
  2838. }
  2839. drug.Dealer = dealer_id
  2840. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  2841. drug.LmtUsedFlag = lmt_used_flags
  2842. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  2843. utils.ErrorLog("drug_alias")
  2844. return
  2845. }
  2846. drug_alias, _ := goodNameM["drug_alias"].(string)
  2847. drug.DrugAlias = drug_alias
  2848. drug_category := goodNameM["drug_category"].(string)
  2849. var drugCategory = "药品类别"
  2850. var drug_category_id int64
  2851. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  2852. if len(drug_category) != 0 {
  2853. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  2854. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  2855. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  2856. dataconfig := models.DictDataconfig{
  2857. ParentId: drugCategoryConfig.ID,
  2858. Module: "system",
  2859. OrgId: orgId,
  2860. Name: drug_category,
  2861. FieldName: "",
  2862. Value: drugCategoryConfigSix.Value + 1,
  2863. CreatedTime: "",
  2864. UpdatedTime: "",
  2865. CreateUserId: adminUser.AdminUser.Id,
  2866. Status: 1,
  2867. Remark: "",
  2868. DeleteIdSystem: 0,
  2869. Title: "",
  2870. Content: "",
  2871. Order: 0,
  2872. Code: "",
  2873. }
  2874. service.CreatedDicConfig(&dataconfig)
  2875. }
  2876. }
  2877. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  2878. fmt.Println("drugCategoryList", drugCategoryList)
  2879. for _, it := range drugCategoryList {
  2880. if drug_category == it.Name {
  2881. drug_category_id = int64(it.Value)
  2882. }
  2883. }
  2884. drug.DrugCategory = drug_category_id
  2885. statistics_category := goodNameM["statistics_category"].(string)
  2886. var statisticsCategory = "统计分类"
  2887. var statistics_category_id int64
  2888. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  2889. if len(statistics_category) != 0 {
  2890. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  2891. if errcodestatistc == gorm.ErrRecordNotFound {
  2892. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  2893. dataconfig := models.DictDataconfig{
  2894. ParentId: statistcConfig.ID,
  2895. Module: "system",
  2896. OrgId: orgId,
  2897. Name: statistics_category,
  2898. FieldName: "",
  2899. Value: staConfig.Value + 1,
  2900. CreatedTime: "",
  2901. UpdatedTime: "",
  2902. CreateUserId: adminUser.AdminUser.Id,
  2903. Status: 1,
  2904. Remark: "",
  2905. DeleteIdSystem: 0,
  2906. Title: "",
  2907. Content: "",
  2908. Order: 0,
  2909. Code: "",
  2910. }
  2911. service.CreatedDicConfig(&dataconfig)
  2912. }
  2913. }
  2914. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  2915. for _, it := range statisticsCategoryList {
  2916. if statistics_category == it.Name {
  2917. statistics_category_id = int64(it.Value)
  2918. }
  2919. }
  2920. drug.StatisticsCategory = statistics_category_id
  2921. number := goodNameM["number"].(string)
  2922. drug.Number = number
  2923. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  2924. drug.HospApprFlag = hosp_appr_flag
  2925. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  2926. drug.MedicalInsuranceNumber = medical_insurance_number
  2927. pharmacology_category := goodNameM["pharmacology_category"].(string)
  2928. var pharmacology = "药理分类"
  2929. var pharmacology_category_id int64
  2930. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  2931. if len(pharmacology_category) != 0 {
  2932. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  2933. if errcodespharmacology == gorm.ErrRecordNotFound {
  2934. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  2935. dataconfig := models.DictDataconfig{
  2936. ParentId: pharmacologyConfig.ID,
  2937. Module: "system",
  2938. OrgId: orgId,
  2939. Name: pharmacology_category,
  2940. FieldName: "",
  2941. Value: dicConfig.Value + 1,
  2942. CreatedTime: "",
  2943. UpdatedTime: "",
  2944. CreateUserId: adminUser.AdminUser.Id,
  2945. Status: 1,
  2946. Remark: "",
  2947. DeleteIdSystem: 0,
  2948. Title: "",
  2949. Content: "",
  2950. Order: 0,
  2951. Code: "",
  2952. }
  2953. service.CreatedDicConfig(&dataconfig)
  2954. }
  2955. }
  2956. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  2957. for _, it := range pharmacologyList {
  2958. if pharmacology_category == it.Name {
  2959. pharmacology_category_id = int64(it.Value)
  2960. }
  2961. }
  2962. drug.PharmacologyCategory = pharmacology_category_id
  2963. code := goodNameM["code"].(string)
  2964. drug.Code = code
  2965. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  2966. drug.IsSpecialDiseases = is_special_diseases
  2967. is_record := int64(goodNameM["is_record"].(float64))
  2968. drug.IsRecord = is_record
  2969. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  2970. drug.PrescriptionMark = prescription_mark
  2971. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  2972. drug.SocialSecurityDirectoryCode = social_security_directory_code
  2973. record_date := goodNameM["record_date"].(string)
  2974. timeLayout := "2006-01-02"
  2975. loc, _ := time.LoadLocation("Local")
  2976. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2977. drug.RecordDate = theTime.Unix()
  2978. drug_remark := goodNameM["drug_remark"].(string)
  2979. drug.DrugRemark = drug_remark
  2980. drug_status := goodNameM["drug_status"].(string)
  2981. drug.DrugStatus = drug_status
  2982. limit_remark := goodNameM["limit_remark"].(string)
  2983. drug.LimitRemark = limit_remark
  2984. drug_control := goodNameM["drug_control"].(string)
  2985. var drugControl = "开药控制"
  2986. var drug_control_id int64
  2987. drugContorlConfig, _ := service.GetDrugDataConfig(0, drugControl)
  2988. if len(drug_control) != 0 {
  2989. _, errcodesdrugcontrol := service.IsExistDicConfig(drugContorlConfig.ID, drug_control, orgId)
  2990. if errcodesdrugcontrol == gorm.ErrRecordNotFound {
  2991. drugContorlConfigOne, _ := service.GetLastDicConfig(drugContorlConfig.ID, orgId)
  2992. dataconfig := models.DictDataconfig{
  2993. ParentId: drugContorlConfig.ID,
  2994. Module: "system",
  2995. OrgId: orgId,
  2996. Name: drug_control,
  2997. FieldName: "",
  2998. Value: drugContorlConfigOne.Value + 1,
  2999. CreatedTime: "",
  3000. UpdatedTime: "",
  3001. CreateUserId: adminUser.AdminUser.Id,
  3002. Status: 1,
  3003. Remark: "",
  3004. DeleteIdSystem: 0,
  3005. Title: "",
  3006. Content: "",
  3007. Order: 0,
  3008. Code: "",
  3009. }
  3010. service.CreatedDicConfig(&dataconfig)
  3011. }
  3012. }
  3013. drugContorlList, _ := service.GetParentDataConfig(drugContorlConfig.ID, orgId)
  3014. for _, it := range drugContorlList {
  3015. if drug_control == it.Name {
  3016. drug_control_id = int64(it.Value)
  3017. }
  3018. }
  3019. drug.DrugControl = drug_control_id
  3020. drugList = append(drugList, &drug)
  3021. }
  3022. export_time := time.Now().Unix()
  3023. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3024. if len(drugList) > 0 {
  3025. for _, item := range drugList {
  3026. goodInfo := models.BaseDrugLib{
  3027. DrugName: item.DrugName,
  3028. DrugAlias: item.DrugAlias,
  3029. DrugSpec: item.DrugSpec,
  3030. DrugType: item.DrugType,
  3031. DrugStockLimit: item.DrugStockLimit,
  3032. DrugOriginPlace: item.DrugOriginPlace,
  3033. DrugDosageForm: item.DrugDosageForm,
  3034. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3035. MaxUnit: item.MaxUnit,
  3036. MinUnit: item.MinUnit,
  3037. UnitMatrixing: item.UnitMatrixing,
  3038. RetailPrice: item.RetailPrice,
  3039. LastPrice: item.LastPrice,
  3040. DrugClassify: item.DrugClassify,
  3041. Manufacturer: item.Manufacturer,
  3042. Dealer: item.Dealer,
  3043. OrgId: orgId,
  3044. Status: 1,
  3045. Ctime: time.Now().Unix(),
  3046. Pinyin: item.Pinyin,
  3047. Wubi: item.Wubi,
  3048. DrugAliasPinyin: item.DrugAliasPinyin,
  3049. DrugAliasWubi: item.DrugAliasWubi,
  3050. DrugControl: item.DrugControl,
  3051. Number: item.Number,
  3052. HospApprFlag: item.HospApprFlag,
  3053. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3054. PharmacologyCategory: item.PharmacologyCategory,
  3055. StatisticsCategory: item.StatisticsCategory,
  3056. Code: item.Code,
  3057. IsSpecialDiseases: item.IsSpecialDiseases,
  3058. IsRecord: item.IsRecord,
  3059. PrescriptionMark: item.PrescriptionMark,
  3060. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3061. RecordDate: item.RecordDate,
  3062. DrugRemark: item.DrugRemark,
  3063. DrugStatus: item.DrugStatus,
  3064. LimitRemark: item.LimitRemark,
  3065. DrugCategory: item.DrugCategory,
  3066. DrugDose: item.DrugDose,
  3067. DrugDoseUnit: item.DrugDoseUnit,
  3068. LmtUsedFlag: item.LmtUsedFlag,
  3069. DrugDay: item.DrugDay,
  3070. DeliveryWay: item.DeliveryWay,
  3071. ExecutionFrequency: item.ExecutionFrequency,
  3072. DoseUnit: item.DoseUnit,
  3073. }
  3074. //查询同种药品同种规格是否存在
  3075. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.MaxUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  3076. if drugerror == gorm.ErrRecordNotFound {
  3077. service.CreateDrugsInfomation(&goodInfo)
  3078. } else if drugerror == nil {
  3079. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  3080. }
  3081. log := models.ExportLog{
  3082. LogType: 4,
  3083. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3084. TotalNum: int64(len(total_goods)),
  3085. FailNum: int64(len(errLogs)),
  3086. SuccessNum: int64(len(drugList)),
  3087. CreateTime: time.Now().Unix(),
  3088. UpdateTime: time.Now().Unix(),
  3089. ExportTime: export_time,
  3090. Status: 1,
  3091. }
  3092. service.CreateExportLog(&log)
  3093. this.ServeSuccessJSON(map[string]interface{}{
  3094. "msg": "导入成功",
  3095. "total_num": len(total_goods),
  3096. "success_num": len(drugList),
  3097. "fail_num": int64(len(errLogs)),
  3098. })
  3099. }
  3100. } else {
  3101. log := models.ExportLog{
  3102. LogType: 4,
  3103. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3104. TotalNum: int64(len(total_goods)),
  3105. FailNum: int64(len(errLogs)),
  3106. SuccessNum: int64(len(drugList)),
  3107. CreateTime: time.Now().Unix(),
  3108. UpdateTime: time.Now().Unix(),
  3109. ExportTime: export_time,
  3110. Status: 1,
  3111. }
  3112. service.CreateExportLog(&log)
  3113. this.ServeSuccessJSON(map[string]interface{}{
  3114. "msg": "导入成功",
  3115. "total_num": len(total_goods),
  3116. "success_num": len(drugList),
  3117. "fail_num": int64(len(errLogs)),
  3118. })
  3119. }
  3120. }
  3121. func (this *StockManagerApiController) GetInitializtion() {
  3122. orgId := this.GetAdminUserInfo().CurrentOrgId
  3123. var drugCategory = "药品类别"
  3124. var drugType = "药品类型"
  3125. var drugDosageForm = "药品剂型"
  3126. var medicalInsuranceLevel = "医保等级"
  3127. var drugControl = "开药控制"
  3128. var drugClassify = "药物分类"
  3129. var statisticsCategory = "统计分类"
  3130. var pharmacologyCategory = "药理分类"
  3131. var goodKind = "耗材种类"
  3132. var tubeColor = "试管颜色"
  3133. var costClassify = "费用类别"
  3134. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3135. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3136. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  3137. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  3138. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  3139. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  3140. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  3141. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  3142. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  3143. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  3144. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  3145. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  3146. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3147. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  3148. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  3149. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  3150. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  3151. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  3152. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  3153. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  3154. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  3155. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  3156. this.ServeSuccessJSON(map[string]interface{}{
  3157. "drugCategoryList": drugCategoryList,
  3158. "drugTypeList": drugTypeList,
  3159. "drugDosageFormList": drugDosageFormList,
  3160. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  3161. "drugControlList": drugControlList,
  3162. "drugClassifyList": drugClassifyList,
  3163. "statisticsCategoryList": statisticsCategoryList,
  3164. "pharmacologyCategoryList": pharmacologyCategoryList,
  3165. "goodKindList": goodKindList,
  3166. "tubeColorList": tubeColorList,
  3167. "costClassifyList": costClassifyList,
  3168. })
  3169. }
  3170. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  3171. adminUserInfo := this.GetAdminUserInfo()
  3172. orgId := adminUserInfo.CurrentOrgId
  3173. list, _ := service.GetWarehouseOrderInfoList(orgId)
  3174. this.ServeSuccessJSON(map[string]interface{}{
  3175. "list": list,
  3176. })
  3177. }
  3178. func (this *StockManagerApiController) PostSearchGoodList() {
  3179. keyword := this.GetString("keyword")
  3180. adminUserInfo := this.GetAdminUserInfo()
  3181. orgId := adminUserInfo.CurrentOrgId
  3182. list, _ := service.GetSearchGoodList(keyword, orgId)
  3183. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3184. this.ServeSuccessJSON(map[string]interface{}{
  3185. "list": list,
  3186. "manufacturerList": manufacturerList,
  3187. })
  3188. }