supply_order_api_contorller.go 128KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735
  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 SupplyOrderApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func SupplyOrderApiRegistRouters() {
  20. //获取供应商列表
  21. beego.Router("/api/supply/getsupplylist", &SupplyOrderApiController{}, "get:GetSupplyList")
  22. //保存供应商及联系人(用于更改)
  23. beego.Router("/api/supply/updatesupply", &SupplyOrderApiController{}, "post:UpdateSupply")
  24. //删除单条联系人
  25. beego.Router("/api/supply/delcontactone", &SupplyOrderApiController{}, "get:DelContactOne")
  26. //获取单条供应商和涉及到的联系人记录
  27. beego.Router("/api/supply/getsupplyandcontactone", &SupplyOrderApiController{}, "get:GetSupplyAndContactOne")
  28. //获取供应商类别
  29. beego.Router("/api/supply/getsupplytype", &SupplyOrderApiController{}, "get:GetSupplyType")
  30. //删除供应商及联系人
  31. beego.Router("/api/supply/delsupply", &SupplyOrderApiController{}, "post:DelSupply")
  32. //获取供应商编码
  33. beego.Router("/api/supply/getsupplycode", &SupplyOrderApiController{}, "get:GetSupplyCode")
  34. //保存供应商及联系人(用于新增)
  35. beego.Router("/api/supply/savesupply", &SupplyOrderApiController{}, "post:SaveSupply")
  36. beego.Router("/api/supply/getinitorder", &SupplyOrderApiController{}, "get:GetInitOrder")
  37. //保存购货订单
  38. beego.Router("/api/supply/savepurchaseorder", &SupplyOrderApiController{}, "post:SavePurchaseOrder")
  39. //获取所有供应商
  40. beego.Router("/api/supply/getallsupply", &SupplyOrderApiController{}, "get:GetAllSupply")
  41. //获取供应商订单列表
  42. beego.Router("/api/supply/getallpurchaseorderlist", &SupplyOrderApiController{}, "get:GetAllPurchaseOrderList")
  43. //修改购货订单
  44. beego.Router("/api/supply/updatepurchaseorder", &SupplyOrderApiController{}, "Post:UpdatePurchaseOrder")
  45. //审核购货订单
  46. beego.Router("/api/supply/checkpurchaseorder", &SupplyOrderApiController{}, "get:UpdateSupplyWaresing")
  47. //获取购货订单详情
  48. beego.Router("/api/supply/getpurchaseorderdetail", &SupplyOrderApiController{}, "get:GetPurchaseOrderDetail")
  49. //新增购货单
  50. beego.Router("/api/supply/addgoodorder", &SupplyOrderApiController{}, "post:AddGoodOrder")
  51. //获取购货单列表
  52. beego.Router("/api/supply/getallgoodorderlist", &SupplyOrderApiController{}, "Get:GetAllGoodOderList")
  53. //修改购货订单详情
  54. beego.Router("/api/supply/getgoodorderdetail", &SupplyOrderApiController{}, "Get:GetGoodOrderDetail")
  55. //修改购货订单
  56. beego.Router("/api/supply/updategoodorder", &SupplyOrderApiController{}, "Post:UpdateGoodOrder")
  57. //删除购货订单
  58. beego.Router("/api/supply/deletepurchorder", &SupplyOrderApiController{}, "Get:DeletePurchOrder")
  59. //生成购货单的判断
  60. beego.Router("/api/supply/getallordercountlist", &SupplyOrderApiController{}, "Get:GetAllOrderCountList")
  61. // 生成购货单
  62. beego.Router("/api/supply/getpurchaseorderinfo", &SupplyOrderApiController{}, "Get:GetPurchOrderInfo")
  63. //反审核 获取关联的购货单数据
  64. beego.Router("/api/supply/getgoodorderlist", &SupplyOrderApiController{}, "Get:GetGoodOrderList")
  65. //反审核购货订单
  66. beego.Router("/api/supply/getreturnorder", &SupplyOrderApiController{}, "Get:GetReturnOrder")
  67. //判断是否全部入库
  68. beego.Router("/api/supply/getgoodordercountlist", &SupplyOrderApiController{}, "Get:GetGoodOrderCountList")
  69. //修改购货订单入库状态
  70. beego.Router("/api/supply/modefysupplywarehousing", &SupplyOrderApiController{}, "Get:ModefySupplyWarehousing")
  71. //保存退货单
  72. beego.Router("/api/supply/savegoodreturnOrder", &SupplyOrderApiController{}, "Post:SaveGoodReturnOrder")
  73. //获取退货单列表
  74. beego.Router("/api/supply/getallgoodreturnorderlist", &SupplyOrderApiController{}, "Get:GetAllGoodReturnOrderList")
  75. //获取退库详情
  76. beego.Router("/api/supply/getgoodreturndetail", &SupplyOrderApiController{}, "Get:GetGoodReturnDetail")
  77. //修改退库
  78. beego.Router("/api/supply/updategoodreturn", &SupplyOrderApiController{}, "Post:UpdateGoodReturn")
  79. //反审核采购单
  80. beego.Router("/api/supply/mofygoodorder", &SupplyOrderApiController{}, "Get:ModefyGoodOrder")
  81. //更改入库状态
  82. beego.Router("/api/supply/updatesupplywarehousing", &SupplyOrderApiController{}, "Get:UpdateSupplyWarehousing")
  83. //删除购货单
  84. beego.Router("/api/supply/deletegoodorder", &SupplyOrderApiController{}, "Get:DeleteGoodOrder")
  85. //生成采购退货单数据
  86. beego.Router("/api/supply/getsupplywarehouseoutbyid", &SupplyOrderApiController{}, "Get:GetSupplyWarehouseById")
  87. //审核采购单
  88. beego.Router("/api/supply/checkgoodorderbyid", &SupplyOrderApiController{}, "Get:CheckGoodOrderById")
  89. //审核退货单
  90. beego.Router("/api/supply/checkreturnorder", &SupplyOrderApiController{}, "Get:CheckReturnOrder")
  91. //删除采购订单
  92. beego.Router("api/supply/deletepurchaseorder", &SupplyOrderApiController{}, "Get:DeletePurchaseOrder")
  93. //删除采购单
  94. beego.Router("/api/supply/deletegoodorderbyid", &SupplyOrderApiController{}, "Get:DeleteGoodOrderById")
  95. //删除退货单
  96. beego.Router("/api/supply/deletereturnorder", &SupplyOrderApiController{}, "Get:DeleteReturnOrder")
  97. //删除
  98. beego.Router("/api/supply/deletereturnorderbyid", &SupplyOrderApiController{}, "Get:DeleteReturnOrderById")
  99. //反审核退货单
  100. beego.Router("/api/supply/modefyreturnorder", &SupplyOrderApiController{}, "Get:ModefyReturnOrder")
  101. //获取采购数据
  102. beego.Router("/api/supply/getgoodorderdetaillist", &SupplyOrderApiController{}, "Get:GetGoodOrderDetailList")
  103. }
  104. //判断前端参数是否为空
  105. func CheckParams(this *SupplyOrderApiController, m *map[string][]string) (map[string]string, error) {
  106. tmp := make(map[string]string)
  107. for k, v := range *m {
  108. t := this.GetString(k)
  109. if v[0] == "must" && t == "" {
  110. return nil, fmt.Errorf(v[2] + "不能为空")
  111. }
  112. tmp[k] = t
  113. }
  114. return tmp, nil
  115. }
  116. //获取供应商列表GetSupplyList
  117. func (this *SupplyOrderApiController) GetSupplyList() {
  118. ctype, _ := this.GetInt64("ctype") //供应商类别
  119. page, _ := this.GetInt64("page") //页码
  120. limit, _ := this.GetInt64("limit") //每一页查出来的条数
  121. check := map[string][]string{
  122. "page": {"must", "string", "page"},
  123. "limit": {"must", "string", "limit"},
  124. }
  125. _, err := CheckParams(this, &check)
  126. if err != nil {
  127. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  128. }
  129. keyword := this.GetString("keyword") //供应商编号\供应商名称\联系人名字
  130. orgId := this.GetAdminUserInfo().CurrentOrgId
  131. //获取分页的数据
  132. list, total, err := service.GetSupplyList(ctype, page, limit, keyword, orgId)
  133. //获取供应商类别
  134. costClassify := "供应商类别"
  135. drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
  136. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  137. tmpmap := make(map[int64]string) //储存供应商类别
  138. namemap := make(map[string]string) //储存首要联系人
  139. phonemap := make(map[string]string) //手机号
  140. for i := 0; i < len(drugTypeList); i++ {
  141. k := int64(drugTypeList[i].Value)
  142. v := drugTypeList[i].Name
  143. tmpmap[k] = v
  144. }
  145. if err == nil {
  146. for i := 0; i < len(list); i++ {
  147. code := list[i].SupplierCode
  148. fistname, errs := service.FindName(code, orgId)
  149. if errs != nil && errs.Error() != "record not found" {
  150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  151. return
  152. }
  153. namemap[code] = fistname.Name
  154. phonemap[code] = fistname.Phone
  155. }
  156. type SpSupplierNameList struct { //基于SpSupplierName结构体修改的,为了方便前端取数据整合了一下,删除了几个用不到的字段,添加了联系人名字和供应商类别两个字段
  157. ID int64
  158. SupplierCode string
  159. SupplierName string
  160. SupplierType int64
  161. VatRate float64
  162. Number string
  163. Bank string
  164. BankAccount string
  165. UserOrgId int64
  166. Status int64
  167. ContactsId int64
  168. ConName string //供应商主要联系人名字
  169. TypeName string //供应商类别
  170. Phone string //电话
  171. }
  172. //初始化该结构体
  173. tmplist := []*SpSupplierNameList{}
  174. for i := 0; i < len(list); i++ {
  175. var typename string //类别名称
  176. if list[i].SupplierType == 0 {
  177. typename = ""
  178. } else {
  179. typename = tmpmap[list[i].SupplierType]
  180. }
  181. tlist := &SpSupplierNameList{
  182. list[i].ID,
  183. list[i].SupplierCode,
  184. list[i].SupplierName,
  185. list[i].SupplierType,
  186. list[i].VatRate,
  187. list[i].Number,
  188. list[i].Bank,
  189. list[i].BankAccount,
  190. list[i].UserOrgId,
  191. list[i].Status,
  192. list[i].ContactsId,
  193. namemap[list[i].SupplierCode],
  194. typename,
  195. phonemap[list[i].SupplierCode],
  196. }
  197. tmplist = append(tmplist, tlist)
  198. }
  199. this.ServeSuccessJSON(map[string]interface{}{
  200. "list": tmplist,
  201. "total": total,
  202. })
  203. } else {
  204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  205. }
  206. }
  207. //保存供应商及联系人(用于更改)
  208. func (this *SupplyOrderApiController) UpdateSupply() {
  209. orgId := this.GetAdminUserInfo().CurrentOrgId
  210. dataBody := make(map[string]interface{}, 0)
  211. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  212. if err != nil {
  213. utils.ErrorLog(err.Error())
  214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  215. return
  216. }
  217. supplierName := dataBody["suppliername"].(string)
  218. if supplierName == "" {
  219. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称不能为空")
  220. return
  221. }
  222. supplierCode := dataBody["suppliercode"].(string)
  223. if supplierCode == "" {
  224. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
  225. return
  226. }
  227. supplierid := int64(dataBody["id"].(float64))
  228. if supplierid == 0 {
  229. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
  230. return
  231. }
  232. //查询供应商的信息
  233. supply, err := service.GetSupplyOne(supplierid)
  234. if err != nil {
  235. utils.ErrorLog(err.Error())
  236. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  237. return
  238. }
  239. if supplierName != supply.SupplierName {
  240. //判断供应商名称是否有重复的
  241. sbool, _ := service.FindSupplierName(supplierName, orgId)
  242. if sbool { //有重复的
  243. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
  244. return
  245. }
  246. }
  247. if supplierCode != supply.SupplierCode {
  248. //判断供应商编号是否有重复的
  249. codebool, _ := service.FindSupplierCode(supplierCode, supplierid, orgId)
  250. if codebool {
  251. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
  252. return
  253. }
  254. }
  255. if dataBody["suppliertype"] == "" || dataBody["suppliertype"] == 0 {
  256. var tmp float64 = 0
  257. dataBody["suppliertype"] = tmp
  258. }
  259. if dataBody["vatrate"] == "" {
  260. dataBody["vatrate"] = 0
  261. }
  262. supplierType := int64(dataBody["suppliertype"].(float64)) //供应商类别
  263. var tmpvarrate float64
  264. datavarrate := dataBody["vatrate"]
  265. switch datavarrate.(type) {
  266. case float64:
  267. tmpvarrate = datavarrate.(float64)
  268. case string:
  269. tmpvarrate, _ = strconv.ParseFloat(dataBody["vatrate"].(string), 64)
  270. }
  271. vatRate := tmpvarrate //增值税税率
  272. number := dataBody["number"].(string) //纳税人识别号
  273. bank := dataBody["bank"].(string) //开户银行
  274. bankAccount := dataBody["bankaccount"].(string) //银行账号
  275. tmodify := this.GetAdminUserInfo().AdminUser.Id //修改者
  276. //保存联系人
  277. if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
  278. thisStockIn, _ := dataBody["contacts"].([]interface{})
  279. if len(thisStockIn) > 0 {
  280. for _, v := range thisStockIn { //这个循环是用来检测当填了手机号时联系人不能为空
  281. vtem := v.(map[string]interface{})
  282. if vtem["phone"].(string) != "" && vtem["name"].(string) == "" {
  283. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
  284. return
  285. }
  286. }
  287. if len(thisStockIn) == 1 { //当只有一条联系人时强制设为首要联系人
  288. for _, item := range thisStockIn {
  289. items := item.(map[string]interface{})
  290. items["is_first"] = 1
  291. //如果电话和联系人都为空,不保存联系人
  292. if items["phone"] == "" && items["name"] == nil {
  293. upsupply := models.SpSupplierName{
  294. ID: supplierid,
  295. SupplierCode: supplierCode,
  296. SupplierName: supplierName,
  297. SupplierType: supplierType,
  298. VatRate: vatRate,
  299. Number: number,
  300. Bank: bank,
  301. BankAccount: bankAccount,
  302. UserOrgId: orgId,
  303. Status: 1,
  304. Mtime: time.Now().Unix(),
  305. Modify: tmodify,
  306. }
  307. err = service.UpdateSupplyName(upsupply)
  308. if err != nil {
  309. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  310. return
  311. }
  312. this.ServeSuccessJSON(map[string]interface{}{
  313. "list": "保存成功",
  314. })
  315. return
  316. }
  317. }
  318. }
  319. err = service.UpdateSupplyAndContact(thisStockIn, supplierid, orgId, supplierType, tmodify, supplierCode, supplierName, number, bank, bankAccount, vatRate)
  320. if err != nil {
  321. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  322. return
  323. }
  324. } else {
  325. //如果联系人是空的,直接保存供应商
  326. //更新供应商
  327. upsupply := models.SpSupplierName{
  328. ID: supplierid,
  329. SupplierCode: supplierCode,
  330. SupplierName: supplierName,
  331. SupplierType: supplierType,
  332. VatRate: vatRate,
  333. Number: number,
  334. Bank: bank,
  335. BankAccount: bankAccount,
  336. Status: 1,
  337. Mtime: time.Now().Unix(),
  338. Modify: tmodify,
  339. }
  340. err = service.UpdateSupplyName(upsupply)
  341. if err != nil {
  342. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  343. return
  344. }
  345. }
  346. }
  347. this.ServeSuccessJSON(map[string]interface{}{
  348. "list": "保存成功",
  349. })
  350. return
  351. }
  352. //获取单条供应商和涉及到的联系人记录
  353. func (this *SupplyOrderApiController) GetSupplyAndContactOne() {
  354. orgId := this.GetAdminUserInfo().CurrentOrgId
  355. id, _ := this.GetInt64("id")
  356. check := map[string][]string{
  357. "id": {"must", "string", "id"},
  358. }
  359. _, err := CheckParams(this, &check)
  360. if err != nil {
  361. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  362. }
  363. supply, contact, err := service.GetSupplyAndContactOne(id, orgId)
  364. //获取供应商类别
  365. costClassify := "供应商类别"
  366. drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
  367. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  368. tmpmap := make(map[int64]string) //储存供应商类别
  369. for i := 0; i < len(drugTypeList); i++ {
  370. k := int64(drugTypeList[i].Value)
  371. v := drugTypeList[i].Name
  372. tmpmap[k] = v
  373. }
  374. type SpSupplierNameList struct { //基于SpSupplierName结构体修改的,为了方便前端取数据整合了一下,删除了几个用不到的字段,添加了联系人名字和供应商类别两个字段
  375. Id int64 `json:"id"`
  376. Suppliercode string `json:"suppliercode"`
  377. Suppliername string `json:"suppliername"`
  378. Suppliertype int64 `json:"suppliertype"`
  379. Vatrate float64 `json:"vatrate"`
  380. Number string `json:"number"`
  381. Bank string `json:"bank"`
  382. Bankaccount string `json:"bankaccount"`
  383. Userorgid int64 `json:"userorgid"`
  384. Status int64 `json:"status"`
  385. Contactsid int64 `json:"contactsid"`
  386. Typename string `json:"typename"` //供应商类别
  387. }
  388. var typename string //类别名称
  389. if supply.SupplierType == 0 {
  390. typename = ""
  391. } else {
  392. typename = tmpmap[supply.SupplierType]
  393. }
  394. tlist := &SpSupplierNameList{
  395. supply.ID,
  396. supply.SupplierCode,
  397. supply.SupplierName,
  398. supply.SupplierType,
  399. supply.VatRate,
  400. supply.Number,
  401. supply.Bank,
  402. supply.BankAccount,
  403. supply.UserOrgId,
  404. supply.Status,
  405. supply.ContactsId,
  406. typename,
  407. }
  408. if err != nil {
  409. utils.ErrorLog(err.Error())
  410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  411. return
  412. }
  413. fmt.Println(tlist)
  414. this.ServeSuccessJSON(map[string]interface{}{
  415. "supply": tlist,
  416. "contact": contact,
  417. })
  418. return
  419. }
  420. //获取供应商类别
  421. func (this *SupplyOrderApiController) GetSupplyType() {
  422. orgId := this.GetAdminUserInfo().CurrentOrgId
  423. costClassify := "供应商类别"
  424. drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
  425. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  426. this.ServeSuccessJSON(map[string]interface{}{
  427. "list": drugTypeList,
  428. })
  429. return
  430. }
  431. //删除供应商及联系人
  432. func (this *SupplyOrderApiController) DelSupply() {
  433. orgId := this.GetAdminUserInfo().CurrentOrgId
  434. //拿到供应商的id
  435. suid, _ := this.GetInt64("id")
  436. if suid == 0 {
  437. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
  438. return
  439. }
  440. supply := models.SpSupplierName{
  441. ID: suid,
  442. }
  443. err := service.DelSupply(supply, orgId)
  444. if err != nil {
  445. utils.ErrorLog(err.Error())
  446. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  447. return
  448. }
  449. this.ServeSuccessJSON(map[string]interface{}{
  450. "list": "删除成功",
  451. })
  452. return
  453. }
  454. //删除单条联系人记录
  455. func (this *SupplyOrderApiController) DelContactOne() {
  456. id, _ := this.GetInt64("id")
  457. if id == 0 {
  458. this.ServeSuccessJSON(map[string]interface{}{
  459. "list": "删除成功,没有走数据库",
  460. })
  461. return
  462. }
  463. err := service.DelContactOne(id)
  464. if err != nil {
  465. utils.ErrorLog(err.Error())
  466. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  467. return
  468. }
  469. this.ServeSuccessJSON(map[string]interface{}{
  470. "list": "删除成功",
  471. })
  472. return
  473. }
  474. //获取供应商编码
  475. func (this *SupplyOrderApiController) GetSupplyCode() {
  476. orgId := this.GetAdminUserInfo().CurrentOrgId
  477. supply, err := service.GetSuppliyCode(orgId)
  478. if err != nil {
  479. return
  480. }
  481. if len(supply) == 0 { //如果数据库中没有gys类型的编码则设置默认值
  482. supply = []*models.SpSupplierName{
  483. {
  484. SupplierCode: "gys001",
  485. },
  486. }
  487. } else { //获取数据库中最大的编码值,并加一
  488. tmp := supply[0].SupplierCode
  489. tmp = tmp[3:]
  490. var code int
  491. code, err = strconv.Atoi(tmp)
  492. code++
  493. tmp = strconv.Itoa(code)
  494. for len(tmp) < 3 {
  495. tmp = "0" + tmp
  496. }
  497. tmp = "gys" + tmp
  498. supply[0].SupplierCode = tmp
  499. }
  500. this.ServeSuccessJSON(map[string]interface{}{
  501. "supplycode": supply,
  502. })
  503. return
  504. }
  505. //保存供应商(用于新增)
  506. func (this *SupplyOrderApiController) SaveSupply() {
  507. orgId := this.GetAdminUserInfo().CurrentOrgId
  508. dataBody := make(map[string]interface{}, 0)
  509. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  510. if err != nil {
  511. utils.ErrorLog(err.Error())
  512. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  513. return
  514. }
  515. supplierName := dataBody["suppliername"].(string)
  516. if supplierName == "" {
  517. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称不能为空")
  518. return
  519. }
  520. //判断供应商名称是否有重复的
  521. sbool, _ := service.FindSupplierName(supplierName, orgId)
  522. if sbool { //有重复的
  523. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
  524. return
  525. }
  526. supplierCode := dataBody["suppliercode"].(string) //供应商编码
  527. if supplierCode == "" {
  528. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
  529. return
  530. }
  531. //判断供应商编号是否有重复的
  532. codebool, _ := service.FindSupplierCodes(supplierCode, orgId)
  533. if codebool {
  534. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
  535. return
  536. }
  537. if dataBody["suppliertype"] == "" {
  538. var tmp int64 = 0
  539. dataBody["suppliertype"] = tmp
  540. }
  541. if dataBody["vatrate"] == "" {
  542. dataBody["vatrate"] = "0"
  543. }
  544. if dataBody["suppliertype"] == "" || dataBody["suppliertype"] == 0 {
  545. var tmp float64 = 0
  546. dataBody["suppliertype"] = tmp
  547. }
  548. supplierType := int64(dataBody["suppliertype"].(float64)) //供应商类别
  549. var tmpvarrate float64
  550. datavarrate := dataBody["vatrate"]
  551. switch datavarrate.(type) {
  552. case float64:
  553. tmpvarrate = datavarrate.(float64)
  554. case string:
  555. tmpvarrate, _ = strconv.ParseFloat(dataBody["vatrate"].(string), 64)
  556. }
  557. vatRate := tmpvarrate //增值税税率
  558. number, _ := dataBody["number"].(string)
  559. bank := dataBody["bank"].(string)
  560. bankAccount := dataBody["bankaccount"].(string)
  561. tcreater := this.GetAdminUserInfo().AdminUser.Id
  562. //保存联系人
  563. if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
  564. thisStockIn, _ := dataBody["contacts"].([]interface{})
  565. if len(thisStockIn) > 0 {
  566. for _, v := range thisStockIn { //这个循环是用来检测当填了手机号时联系人不能为空
  567. vtem := v.(map[string]interface{})
  568. if vtem["phone"] != "" && vtem["name"] == nil {
  569. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
  570. return
  571. }
  572. }
  573. if len(thisStockIn) == 1 { //当只有一条联系人时强制设为首要联系人,
  574. for _, item := range thisStockIn {
  575. items := item.(map[string]interface{})
  576. items["is_first"] = 1
  577. //如果电话和联系人都为空,不保存联系人
  578. if items["phone"] == "" && items["name"] == nil {
  579. supply := models.SpSupplierName{
  580. SupplierCode: supplierCode,
  581. SupplierName: supplierName,
  582. SupplierType: supplierType,
  583. VatRate: vatRate,
  584. Number: number,
  585. Bank: bank,
  586. BankAccount: bankAccount,
  587. UserOrgId: orgId,
  588. Status: 1,
  589. Ctime: time.Now().Unix(),
  590. Mtime: 0,
  591. Creater: tcreater,
  592. Modify: tcreater,
  593. }
  594. err = service.SaveSupply(supply)
  595. if err != nil {
  596. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  597. return
  598. }
  599. this.ServeSuccessJSON(map[string]interface{}{
  600. "list": "保存成功",
  601. })
  602. return
  603. }
  604. }
  605. }
  606. err = service.SaveSupplyAndContact(thisStockIn, orgId, supplierType, tcreater, supplierCode, supplierName, number, bank, bankAccount, vatRate)
  607. if err != nil {
  608. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  609. return
  610. }
  611. } else {
  612. //如果联系人是空的,这里直接保存供应商
  613. supply := models.SpSupplierName{
  614. SupplierCode: supplierCode,
  615. SupplierName: supplierName,
  616. SupplierType: supplierType,
  617. VatRate: vatRate,
  618. Number: number,
  619. Bank: bank,
  620. BankAccount: bankAccount,
  621. UserOrgId: orgId,
  622. Status: 1,
  623. Ctime: time.Now().Unix(),
  624. Mtime: 0,
  625. Creater: tcreater,
  626. Modify: tcreater,
  627. }
  628. err = service.SaveSupply(supply)
  629. if err != nil {
  630. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  631. return
  632. }
  633. }
  634. }
  635. this.ServeSuccessJSON(map[string]interface{}{
  636. "list": "保存成功",
  637. })
  638. return
  639. }
  640. func (this *SupplyOrderApiController) GetInitOrder() {
  641. orgId := this.GetAdminUserInfo().CurrentOrgId
  642. //获取药品库数据
  643. baseList, _ := service.GetSupplyDrugList(orgId)
  644. goodList, _ := service.GetSupplyGoodList(orgId)
  645. manufactuerList, _ := service.GetAllManufacturerList(orgId)
  646. goodTypeList, _ := service.GetAllGoodType(orgId)
  647. supplyList, _ := service.GetSupplierList(orgId)
  648. var drugType = "药品类型"
  649. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  650. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  651. this.ServeSuccessJSON(map[string]interface{}{
  652. "drugList": baseList,
  653. "goodList": goodList,
  654. "manufactuerList": manufactuerList,
  655. "goodTypeList": goodTypeList,
  656. "drugTypeList": drugTypeList,
  657. "supplyList": supplyList,
  658. })
  659. return
  660. }
  661. func (this *SupplyOrderApiController) SavePurchaseOrder() {
  662. supplier_id, _ := this.GetInt64("supplier_name")
  663. start_time := this.GetString("start_time")
  664. end_time := this.GetString("end_time")
  665. timeLayout := "2006-01-02"
  666. loc, _ := time.LoadLocation("Local")
  667. var startTime int64
  668. if len(start_time) > 0 {
  669. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  670. if err != nil {
  671. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  672. return
  673. }
  674. startTime = theTime.Unix()
  675. }
  676. var endTime int64
  677. if len(end_time) > 0 {
  678. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  679. if err != nil {
  680. utils.ErrorLog(err.Error())
  681. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  682. return
  683. }
  684. endTime = theTime.Unix()
  685. }
  686. rate_of_concession := this.GetString("rate_of_concession")
  687. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  688. discount_amount := this.GetString("discount_amount")
  689. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  690. dataBody := make(map[string]interface{}, 0)
  691. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  692. if err != nil {
  693. utils.ErrorLog(err.Error())
  694. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  695. return
  696. }
  697. //生成购货订单
  698. timeStr := time.Now().Format("2006-01-02")
  699. timeArr := strings.Split(timeStr, "-")
  700. orgId := this.GetAdminUserInfo().CurrentOrgId
  701. total, _ := service.FindAllSupplyOrder(orgId)
  702. total = total + 1
  703. warehousing_order := "CGDD" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  704. recordDateStr := time.Now().Format("2006-01-02")
  705. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  706. fmt.Scan("parseDateErr", parseDateErr)
  707. record_date := recordDate.Unix()
  708. return_remake := dataBody["return_remake"].(string)
  709. info := models.SupplierWarehouseInfo{
  710. Number: warehousing_order,
  711. UserOrgId: orgId,
  712. Creater: this.GetAdminUserInfo().AdminUser.Id,
  713. Ctime: time.Now().Unix(),
  714. Mtime: 0,
  715. Status: 1,
  716. RecordDate: record_date,
  717. IsCheck: 2,
  718. RateOfConcession: rate_of_concession_float,
  719. DiscountAmount: discount_amount_float,
  720. DocumentDate: startTime,
  721. DeliveryDate: endTime,
  722. SupplierId: supplier_id,
  723. IsWarehouse: 2,
  724. ReturnRemake: return_remake,
  725. }
  726. err = service.CreateSupplyWarehouse(info)
  727. warehouseInfo, _ := service.FindLastSupplyWarehouseInfo(orgId)
  728. var warehousingInfo []*models.SupplierWarehousingInfoOrder
  729. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  730. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  731. if len(thisStockIn) > 0 {
  732. for _, item := range thisStockIn {
  733. items := item.(map[string]interface{})
  734. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  735. utils.ErrorLog("project_id")
  736. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  737. return
  738. }
  739. project_id := int64(items["project_id"].(float64))
  740. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  741. utils.ErrorLog("supply_count")
  742. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  743. return
  744. }
  745. supply_count := int64(items["supply_count"].(float64))
  746. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  747. utils.ErrorLog("supply_license_number")
  748. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  749. return
  750. }
  751. supply_license_number := items["supply_license_number"].(string)
  752. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  753. utils.ErrorLog("supply_price")
  754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  755. return
  756. }
  757. supply_price := items["supply_price"].(string)
  758. supply_price_float, _ := strconv.ParseFloat(supply_price, 64)
  759. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  760. utils.ErrorLog("supply_remake")
  761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  762. return
  763. }
  764. supply_remake := items["supply_remake"].(string)
  765. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  766. utils.ErrorLog("supply_total_price")
  767. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  768. return
  769. }
  770. supply_total_price := items["supply_total_price"].(string)
  771. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  772. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  773. utils.ErrorLog("type")
  774. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  775. return
  776. }
  777. is_source := int64(items["type"].(float64))
  778. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  779. utils.ErrorLog("supply_type")
  780. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  781. return
  782. }
  783. supply_type := items["supply_type"].(string)
  784. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  785. utils.ErrorLog("supply_specification_name")
  786. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  787. return
  788. }
  789. supply_specification_name := items["supply_specification_name"].(string)
  790. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  791. utils.ErrorLog("supply_total")
  792. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  793. return
  794. }
  795. supply_total := items["supply_total"].(string)
  796. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  797. utils.ErrorLog("supply_manufacturer")
  798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  799. return
  800. }
  801. supply_manufacturer := items["supply_manufacturer"].(string)
  802. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  803. utils.ErrorLog("name")
  804. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  805. return
  806. }
  807. name := items["name"].(string)
  808. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  809. utils.ErrorLog("supply_unit")
  810. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  811. return
  812. }
  813. supply_unit := items["supply_unit"].(string)
  814. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  815. utils.ErrorLog("manufacturer_id")
  816. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  817. return
  818. }
  819. manufacturer_id := int64(items["manufacturer_id"].(float64))
  820. order := models.SupplierWarehousingInfoOrder{
  821. OrderNumber: warehousing_order,
  822. IsSource: is_source,
  823. Count: supply_count,
  824. Price: supply_price_float,
  825. Amount: supply_total_price_float,
  826. Remark: supply_remake,
  827. UserOrgId: orgId,
  828. Ctime: time.Now().Unix(),
  829. Status: 1,
  830. Mtime: 0,
  831. WarehousingId: warehouseInfo.ID,
  832. ProjectId: project_id,
  833. SupplyLicenseNumber: supply_license_number,
  834. SupplyType: supply_type,
  835. SupplySpecificationName: supply_specification_name,
  836. SupplyTotal: supply_total,
  837. SupplyManufacturer: supply_manufacturer,
  838. Name: name,
  839. SupplyUnit: supply_unit,
  840. ManufacturerId: manufacturer_id,
  841. }
  842. warehousingInfo = append(warehousingInfo, &order)
  843. }
  844. }
  845. }
  846. for _, item := range warehousingInfo {
  847. err = service.CreateSupplyWarehousingOrder(item)
  848. }
  849. //查询
  850. orderInfo, err := service.GetSupplyWarehousingOrderInfo(warehouseInfo.ID)
  851. if err == nil {
  852. this.ServeSuccessJSON(map[string]interface{}{
  853. "order": warehousingInfo,
  854. "warehouseInfo": warehouseInfo,
  855. "orderInfo": orderInfo,
  856. })
  857. } else {
  858. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  859. }
  860. }
  861. func (this *SupplyOrderApiController) GetAllSupply() {
  862. orgId := this.GetAdminUserInfo().CurrentOrgId
  863. appId := this.GetAdminUserInfo().CurrentAppId
  864. supplyList, err := service.GetSupplierList(orgId)
  865. doctorList, err := service.GetAllDoctorSix(orgId, appId)
  866. if err == nil {
  867. this.ServeSuccessJSON(map[string]interface{}{
  868. "supplyList": supplyList,
  869. "doctorList": doctorList,
  870. })
  871. } else {
  872. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  873. }
  874. }
  875. func (this *SupplyOrderApiController) GetAllPurchaseOrderList() {
  876. check_id, _ := this.GetInt64("check_id")
  877. start_time := this.GetString("start_time")
  878. end_time := this.GetString("end_time")
  879. timeLayout := "2006-01-02"
  880. loc, _ := time.LoadLocation("Local")
  881. var startTime int64
  882. if len(start_time) > 0 {
  883. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  884. if err != nil {
  885. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  886. return
  887. }
  888. startTime = theTime.Unix()
  889. }
  890. var endTime int64
  891. if len(end_time) > 0 {
  892. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  893. if err != nil {
  894. utils.ErrorLog(err.Error())
  895. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  896. return
  897. }
  898. endTime = theTime.Unix()
  899. }
  900. keyword := this.GetString("keyword")
  901. page, _ := this.GetInt64("page")
  902. limit, _ := this.GetInt64("limit")
  903. orgId := this.GetAdminUserInfo().CurrentOrgId
  904. list, total, err := service.GetAllPurchaseOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
  905. if err == nil {
  906. this.ServeSuccessJSON(map[string]interface{}{
  907. "list": list,
  908. "total": total,
  909. })
  910. } else {
  911. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  912. }
  913. }
  914. func (this *SupplyOrderApiController) UpdatePurchaseOrder() {
  915. dataBody := make(map[string]interface{}, 0)
  916. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  917. if err != nil {
  918. utils.ErrorLog(err.Error())
  919. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  920. return
  921. }
  922. supplier_id, _ := this.GetInt64("supplier_name")
  923. start_time := this.GetString("start_time")
  924. end_time := this.GetString("end_time")
  925. timeLayout := "2006-01-02"
  926. loc, _ := time.LoadLocation("Local")
  927. var startTime int64
  928. if len(start_time) > 0 {
  929. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  930. if err != nil {
  931. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  932. return
  933. }
  934. startTime = theTime.Unix()
  935. }
  936. var endTime int64
  937. if len(end_time) > 0 {
  938. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  939. if err != nil {
  940. utils.ErrorLog(err.Error())
  941. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  942. return
  943. }
  944. endTime = theTime.Unix()
  945. }
  946. rate_of_concession := this.GetString("rate_of_concession")
  947. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  948. discount_amount := this.GetString("discount_amount")
  949. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  950. warehousing_id, _ := this.GetInt64("id")
  951. number := this.GetString("number")
  952. return_remake := dataBody["return_remake"].(string)
  953. orgId := this.GetAdminUserInfo().CurrentOrgId
  954. info := models.SupplierWarehouseInfo{
  955. RateOfConcession: rate_of_concession_float,
  956. DiscountAmount: discount_amount_float,
  957. DocumentDate: startTime,
  958. DeliveryDate: endTime,
  959. SupplierId: supplier_id,
  960. Mtime: time.Now().Unix(),
  961. ReturnRemake: return_remake,
  962. }
  963. service.ModefySupplyWarehouseInfo(warehousing_id, info)
  964. var warehousingInfo []*models.SupplierWarehousingInfoOrder
  965. var updateWarehousingInfo []*models.SupplierWarehousingInfoOrder
  966. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  967. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  968. if len(thisStockIn) > 0 {
  969. for _, item := range thisStockIn {
  970. items := item.(map[string]interface{})
  971. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  972. utils.ErrorLog("id")
  973. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  974. return
  975. }
  976. id := int64(items["id"].(float64))
  977. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  978. utils.ErrorLog("project_id")
  979. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  980. return
  981. }
  982. project_id := int64(items["project_id"].(float64))
  983. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  984. utils.ErrorLog("supply_count")
  985. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  986. return
  987. }
  988. supply_count := int64(items["supply_count"].(float64))
  989. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  990. utils.ErrorLog("supply_license_number")
  991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  992. return
  993. }
  994. supply_license_number := items["supply_license_number"].(string)
  995. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  996. utils.ErrorLog("supply_price")
  997. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  998. return
  999. }
  1000. supply_price := items["supply_price"].(string)
  1001. supply_price_float, _ := strconv.ParseFloat(supply_price, 64)
  1002. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  1003. utils.ErrorLog("supply_remake")
  1004. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1005. return
  1006. }
  1007. supply_remake := items["supply_remake"].(string)
  1008. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  1009. utils.ErrorLog("supply_total_price")
  1010. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1011. return
  1012. }
  1013. supply_total_price := items["supply_total_price"].(string)
  1014. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  1015. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1016. utils.ErrorLog("type")
  1017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1018. return
  1019. }
  1020. is_source := int64(items["type"].(float64))
  1021. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  1022. utils.ErrorLog("supply_type")
  1023. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1024. return
  1025. }
  1026. supply_type := items["supply_type"].(string)
  1027. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  1028. utils.ErrorLog("supply_specification_name")
  1029. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1030. return
  1031. }
  1032. supply_specification_name := items["supply_specification_name"].(string)
  1033. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  1034. utils.ErrorLog("supply_total")
  1035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1036. return
  1037. }
  1038. supply_total := items["supply_total"].(string)
  1039. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  1040. utils.ErrorLog("supply_manufacturer")
  1041. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1042. return
  1043. }
  1044. supply_manufacturer := items["supply_manufacturer"].(string)
  1045. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1046. utils.ErrorLog("name")
  1047. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1048. return
  1049. }
  1050. name := items["name"].(string)
  1051. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  1052. utils.ErrorLog("supply_unit")
  1053. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1054. return
  1055. }
  1056. supply_unit := items["supply_unit"].(string)
  1057. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  1058. utils.ErrorLog("manufacturer_id")
  1059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1060. return
  1061. }
  1062. manufacturer_id := int64(items["manufacturer_id"].(float64))
  1063. if id > 0 {
  1064. order := models.SupplierWarehousingInfoOrder{
  1065. ID: id,
  1066. IsSource: is_source,
  1067. Count: supply_count,
  1068. Price: supply_price_float,
  1069. Amount: supply_total_price_float,
  1070. Remark: supply_remake,
  1071. Ctime: time.Now().Unix(),
  1072. Status: 1,
  1073. Mtime: 0,
  1074. ProjectId: project_id,
  1075. SupplyLicenseNumber: supply_license_number,
  1076. SupplyType: supply_type,
  1077. SupplySpecificationName: supply_specification_name,
  1078. SupplyTotal: supply_total,
  1079. SupplyManufacturer: supply_manufacturer,
  1080. Name: name,
  1081. SupplyUnit: supply_unit,
  1082. ManufacturerId: manufacturer_id,
  1083. }
  1084. updateWarehousingInfo = append(updateWarehousingInfo, &order)
  1085. }
  1086. if id == 0 {
  1087. order := models.SupplierWarehousingInfoOrder{
  1088. OrderNumber: number,
  1089. IsSource: is_source,
  1090. Count: supply_count,
  1091. Price: supply_price_float,
  1092. Amount: supply_total_price_float,
  1093. Remark: supply_remake,
  1094. UserOrgId: orgId,
  1095. Ctime: time.Now().Unix(),
  1096. Status: 1,
  1097. Mtime: 0,
  1098. WarehousingId: warehousing_id,
  1099. ProjectId: project_id,
  1100. SupplyLicenseNumber: supply_license_number,
  1101. SupplyType: supply_type,
  1102. SupplySpecificationName: supply_specification_name,
  1103. SupplyTotal: supply_total,
  1104. SupplyManufacturer: supply_manufacturer,
  1105. Name: name,
  1106. SupplyUnit: supply_unit,
  1107. ManufacturerId: manufacturer_id,
  1108. }
  1109. warehousingInfo = append(warehousingInfo, &order)
  1110. }
  1111. }
  1112. }
  1113. if len(warehousingInfo) > 0 {
  1114. for _, item := range warehousingInfo {
  1115. service.CreateSupplyWarehousingOrder(item)
  1116. }
  1117. }
  1118. if len(updateWarehousingInfo) > 0 {
  1119. for _, item := range updateWarehousingInfo {
  1120. service.ModifySupplyWarehouseOrder(item)
  1121. }
  1122. }
  1123. this.ServeSuccessJSON(map[string]interface{}{
  1124. "warehousingInfo": warehousingInfo,
  1125. })
  1126. }
  1127. }
  1128. func (this *SupplyOrderApiController) UpdateSupplyWaresing() {
  1129. id, _ := this.GetInt64("id")
  1130. recordDateStr := time.Now().Format("2006-01-02")
  1131. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1132. record_date := recordDate.Unix()
  1133. checker := this.GetAdminUserInfo().AdminUser.Id
  1134. info := models.SupplierWarehouseInfo{
  1135. Mtime: time.Now().Unix(),
  1136. Status: 1,
  1137. IsCheck: 1,
  1138. Checker: checker,
  1139. CheckTime: record_date,
  1140. }
  1141. parseDateErr := service.UpdateSupplyWaresing(id, info)
  1142. if parseDateErr == nil {
  1143. this.ServeSuccessJSON(map[string]interface{}{
  1144. "info": info,
  1145. })
  1146. } else {
  1147. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1148. }
  1149. }
  1150. func (this *SupplyOrderApiController) GetPurchaseOrderDetail() {
  1151. id, _ := this.GetInt64("id")
  1152. info, _ := service.GetPurchaseOrderDetail(id)
  1153. //查询
  1154. orderInfo, err := service.GetSupplyWarehousingOrderInfo(id)
  1155. orgId := this.GetAdminUserInfo().CurrentOrgId
  1156. supplyList, _ := service.GetSupplierList(orgId)
  1157. //获取药品库数据
  1158. baseList, _ := service.GetSupplyDrugList(orgId)
  1159. goodList, _ := service.GetSupplyGoodList(orgId)
  1160. if err == nil {
  1161. this.ServeSuccessJSON(map[string]interface{}{
  1162. "info": info,
  1163. "orderInfo": orderInfo,
  1164. "supplyList": supplyList,
  1165. "baseList": baseList,
  1166. "goodList": goodList,
  1167. })
  1168. } else {
  1169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1170. }
  1171. }
  1172. func (this *SupplyOrderApiController) AddGoodOrder() {
  1173. dataBody := make(map[string]interface{}, 0)
  1174. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1175. if err != nil {
  1176. utils.ErrorLog(err.Error())
  1177. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1178. return
  1179. }
  1180. supplier_id, _ := this.GetInt64("supplier_id")
  1181. start_time := this.GetString("start")
  1182. timeLayout := "2006-01-02"
  1183. loc, _ := time.LoadLocation("Local")
  1184. var startTime int64
  1185. if len(start_time) > 0 {
  1186. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1187. if err != nil {
  1188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1189. return
  1190. }
  1191. startTime = theTime.Unix()
  1192. }
  1193. arrerage := this.GetString("arrerage")
  1194. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  1195. payment := this.GetString("payment")
  1196. payment_float, _ := strconv.ParseFloat(payment, 64)
  1197. warehousing_id, _ := this.GetInt64("warehousing_id")
  1198. number := this.GetString("number")
  1199. rate_of_concession := this.GetString("rate_of_concession")
  1200. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  1201. discount_amount := this.GetString("discount_amount")
  1202. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  1203. return_remake := dataBody["return_remake"].(string)
  1204. orgId := this.GetAdminUserInfo().CurrentOrgId
  1205. creater := this.GetAdminUserInfo().AdminUser.Id
  1206. //生成购货单
  1207. timeStr := time.Now().Format("2006-01-02")
  1208. timeArr := strings.Split(timeStr, "-")
  1209. total, _ := service.FindAllSupplyWarehouseOutOrder(orgId)
  1210. total = total + 1
  1211. warehousing_order := "CG" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  1212. recordDateStr := time.Now().Format("2006-01-02")
  1213. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1214. warehouse_out := models.SpSupplierWarehouseOut{
  1215. Number: number,
  1216. UserOrgId: orgId,
  1217. Creater: creater,
  1218. Ctime: time.Now().Unix(),
  1219. Mtime: 0,
  1220. Status: 1,
  1221. RecordDate: recordDate.Unix(),
  1222. IsCheck: 2,
  1223. WarehousingId: warehousing_id,
  1224. GoodNumber: warehousing_order,
  1225. Arrearage: arrerage_float,
  1226. Payment: payment_float,
  1227. RateOfConcession: rate_of_concession_float,
  1228. DiscountAmount: discount_amount_float,
  1229. DocumentDate: startTime,
  1230. SupplierId: supplier_id,
  1231. Checker: 0,
  1232. CheckTime: 0,
  1233. ReturnRemake: return_remake,
  1234. }
  1235. service.CreateSupplyWarehouseOut(warehouse_out)
  1236. //获取最后一条
  1237. warehouseOut, _ := service.FindSupplyWarehouseOutById(orgId)
  1238. var warehousingOut []*models.SpSupplierWarehousingOutOrder
  1239. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  1240. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  1241. if len(thisStockIn) > 0 {
  1242. for _, item := range thisStockIn {
  1243. items := item.(map[string]interface{})
  1244. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  1245. utils.ErrorLog("supply_count")
  1246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1247. return
  1248. }
  1249. supply_count := int64(items["supply_count"].(float64))
  1250. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1251. utils.ErrorLog("id")
  1252. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1253. return
  1254. }
  1255. id := int64(items["id"].(float64))
  1256. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  1257. utils.ErrorLog("manufacturer_id")
  1258. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1259. return
  1260. }
  1261. manufacturer_id := int64(items["manufacturer_id"].(float64))
  1262. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1263. utils.ErrorLog("name")
  1264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1265. return
  1266. }
  1267. name := items["name"].(string)
  1268. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  1269. utils.ErrorLog("order_number")
  1270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1271. return
  1272. }
  1273. order_number := items["order_number"].(string)
  1274. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  1275. utils.ErrorLog("supply_price")
  1276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1277. return
  1278. }
  1279. supply_price := items["supply_price"].(string)
  1280. price_float, _ := strconv.ParseFloat(supply_price, 64)
  1281. if items["min_price"] == nil || reflect.TypeOf(items["min_price"]).String() != "string" {
  1282. utils.ErrorLog("min_price")
  1283. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1284. return
  1285. }
  1286. min_price := items["min_price"].(string)
  1287. min_price_float, _ := strconv.ParseFloat(min_price, 64)
  1288. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  1289. utils.ErrorLog("supply_total_price")
  1290. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1291. return
  1292. }
  1293. supply_total_price := items["supply_total_price"].(string)
  1294. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  1295. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  1296. utils.ErrorLog("project_id")
  1297. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1298. return
  1299. }
  1300. project_id := int64(items["project_id"].(float64))
  1301. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  1302. utils.ErrorLog("supply_remake")
  1303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1304. return
  1305. }
  1306. supply_remake := items["supply_remake"].(string)
  1307. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  1308. utils.ErrorLog("supply_batch_number")
  1309. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1310. return
  1311. }
  1312. supply_batch_number := items["supply_batch_number"].(string)
  1313. var supply_expiry_date_time int64
  1314. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "string" {
  1315. utils.ErrorLog("supply_expiry_date")
  1316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1317. return
  1318. }
  1319. supply_expiry_date := items["supply_expiry_date"].(string)
  1320. if len(supply_expiry_date) > 0 {
  1321. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_expiry_date+" 00:00:00", loc)
  1322. if err != nil {
  1323. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1324. return
  1325. }
  1326. supply_expiry_date_time = theTime.Unix()
  1327. }
  1328. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  1329. utils.ErrorLog("supply_license_number")
  1330. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1331. return
  1332. }
  1333. supply_license_number := items["supply_license_number"].(string)
  1334. var supply_product_date_time int64
  1335. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "string" {
  1336. utils.ErrorLog("supply_product_date")
  1337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1338. return
  1339. }
  1340. supply_product_date := items["supply_product_date"].(string)
  1341. if len(supply_product_date) > 0 {
  1342. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_product_date+" 00:00:00", loc)
  1343. if err != nil {
  1344. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1345. return
  1346. }
  1347. supply_product_date_time = theTime.Unix()
  1348. }
  1349. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  1350. utils.ErrorLog("supply_specification_name")
  1351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1352. return
  1353. }
  1354. supply_specification_name := items["supply_specification_name"].(string)
  1355. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  1356. utils.ErrorLog("supply_total")
  1357. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1358. return
  1359. }
  1360. supply_total := items["supply_total"].(string)
  1361. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  1362. utils.ErrorLog("supply_type")
  1363. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1364. return
  1365. }
  1366. supply_type := items["supply_type"].(string)
  1367. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  1368. utils.ErrorLog("supply_unit")
  1369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1370. return
  1371. }
  1372. supply_unit := items["supply_unit"].(string)
  1373. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1374. utils.ErrorLog("type")
  1375. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1376. return
  1377. }
  1378. is_source := int64(items["type"].(float64))
  1379. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  1380. utils.ErrorLog("supply_manufacturer")
  1381. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1382. return
  1383. }
  1384. supply_manufacturer := items["supply_manufacturer"].(string)
  1385. order := models.SpSupplierWarehousingOutOrder{
  1386. OrderNumber: order_number,
  1387. ProjectId: project_id,
  1388. IsSource: is_source,
  1389. Count: supply_count,
  1390. Amount: supply_total_price_float,
  1391. Price: price_float,
  1392. Remark: supply_remake,
  1393. IsCheck: 2,
  1394. UserOrgId: orgId,
  1395. Status: 1,
  1396. Ctime: time.Now().Unix(),
  1397. Mtime: 0,
  1398. WarehouseOutId: warehouseOut.ID,
  1399. Type: 1,
  1400. SupplyBatchNumber: supply_batch_number,
  1401. SupplyProductDate: supply_product_date_time,
  1402. SupplyExpiryDate: supply_expiry_date_time,
  1403. WarehousingId: warehousing_id,
  1404. WarehouseInfoId: id,
  1405. SupplyType: supply_type,
  1406. SupplyUnit: supply_unit,
  1407. SupplyTotal: supply_total,
  1408. SupplySpecificationName: supply_specification_name,
  1409. SupplyLicenseNumber: supply_license_number,
  1410. Name: name,
  1411. ManufacturerId: manufacturer_id,
  1412. GoodNumber: warehouseOut.GoodNumber,
  1413. SupplyManufacturer: supply_manufacturer,
  1414. MinPrice: min_price_float,
  1415. IsWarehosue: 2,
  1416. }
  1417. warehousingOut = append(warehousingOut, &order)
  1418. }
  1419. }
  1420. }
  1421. for _, item := range warehousingOut {
  1422. //如果是手动新增的,type 等于2
  1423. if item.WarehouseInfoId == 0 {
  1424. item.Type = 2
  1425. service.CreateSupplyWarehousOutOrder(item)
  1426. }
  1427. if item.WarehouseInfoId > 0 {
  1428. //查询该商品是否来源于采购订单,如果存在则关联, 如果不存在则取消关联
  1429. _, errcode := service.GetGoodIsSource(warehousing_id, item.ProjectId, orgId)
  1430. if errcode == gorm.ErrRecordNotFound {
  1431. item.WarehousingId = 0
  1432. item.WarehouseInfoId = 0
  1433. item.OrderNumber = ""
  1434. item.Type = 2
  1435. err = service.CreateSupplyWarehousOutOrder(item)
  1436. //更新采购单
  1437. service.ModfySupplyWarehouseOut(warehousing_id, orgId)
  1438. }
  1439. if errcode == nil {
  1440. err = service.CreateSupplyWarehousOutOrder(item)
  1441. }
  1442. }
  1443. }
  1444. list, parseDateErr := service.GetSupplyWarehouseOutById(warehouseOut.ID, orgId)
  1445. if parseDateErr == nil {
  1446. this.ServeSuccessJSON(map[string]interface{}{
  1447. "list": list,
  1448. "warehouseOut": warehouseOut,
  1449. })
  1450. } else {
  1451. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1452. }
  1453. }
  1454. func (this *SupplyOrderApiController) GetAllGoodOderList() {
  1455. check_id, _ := this.GetInt64("check_id")
  1456. start_time := this.GetString("start_time")
  1457. end_time := this.GetString("end_time")
  1458. keyword := this.GetString("keyword")
  1459. page, _ := this.GetInt64("page")
  1460. limit, _ := this.GetInt64("limit")
  1461. timeLayout := "2006-01-02"
  1462. loc, _ := time.LoadLocation("Local")
  1463. var startTime int64
  1464. if len(start_time) > 0 {
  1465. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1466. if err != nil {
  1467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1468. return
  1469. }
  1470. startTime = theTime.Unix()
  1471. }
  1472. var endTime int64
  1473. if len(end_time) > 0 {
  1474. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1475. if err != nil {
  1476. utils.ErrorLog(err.Error())
  1477. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1478. return
  1479. }
  1480. endTime = theTime.Unix()
  1481. }
  1482. orgId := this.GetAdminUserInfo().CurrentOrgId
  1483. list, total, err := service.GetAllGoodOderList(check_id, keyword, page, limit, startTime, endTime, orgId)
  1484. if err == nil {
  1485. this.ServeSuccessJSON(map[string]interface{}{
  1486. "list": list,
  1487. "total": total,
  1488. })
  1489. } else {
  1490. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1491. }
  1492. }
  1493. func (this *SupplyOrderApiController) GetGoodOrderDetail() {
  1494. id, _ := this.GetInt64("id")
  1495. ids := this.GetString("ids")
  1496. orgId := this.GetAdminUserInfo().CurrentOrgId
  1497. if len(ids) == 0 {
  1498. out, err := service.GetGoodOrderDetail(id, orgId)
  1499. list, _ := service.GetSupplyWarehouseOutById(id, orgId)
  1500. for _, item := range list {
  1501. if item.IsSource == 1 {
  1502. waresingList, _ := service.GetAllDrugWaresingList(item.ProjectId, orgId)
  1503. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1504. item.DrugWarehouseInfo = waresingList
  1505. item.SpBaseDrug = medical
  1506. }
  1507. if item.IsSource == 2 {
  1508. waresingList, _ := service.GetAllGoodWaresingList(item.ProjectId, orgId)
  1509. item.GoodWarehouseInfo = waresingList
  1510. }
  1511. }
  1512. drugList, _ := service.GetSupplyDrugList(orgId)
  1513. goodList, _ := service.GetSupplyGoodList(orgId)
  1514. supplyList, _ := service.GetSupplierList(orgId)
  1515. if err == nil {
  1516. this.ServeSuccessJSON(map[string]interface{}{
  1517. "out": out,
  1518. "list": list,
  1519. "goodList": goodList,
  1520. "drugList": drugList,
  1521. "supplyList": supplyList,
  1522. })
  1523. } else {
  1524. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1525. }
  1526. }
  1527. if len(ids) > 0 {
  1528. idArray := strings.Split(ids, ",")
  1529. out, err := service.GetGoodOrderDetail(id, orgId)
  1530. list, _ := service.GetSupplyWarehouseOutByIdOne(id, orgId, idArray)
  1531. for _, item := range list {
  1532. if item.IsSource == 1 {
  1533. waresingList, _ := service.GetAllDrugWaresingList(item.ProjectId, orgId)
  1534. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1535. item.DrugWarehouseInfo = waresingList
  1536. item.SpBaseDrug = medical
  1537. }
  1538. if item.IsSource == 2 {
  1539. waresingList, _ := service.GetAllGoodWaresingList(item.ProjectId, orgId)
  1540. item.GoodWarehouseInfo = waresingList
  1541. }
  1542. }
  1543. drugList, _ := service.GetSupplyDrugList(orgId)
  1544. goodList, _ := service.GetSupplyGoodList(orgId)
  1545. supplyList, _ := service.GetSupplierList(orgId)
  1546. if err == nil {
  1547. this.ServeSuccessJSON(map[string]interface{}{
  1548. "out": out,
  1549. "list": list,
  1550. "goodList": goodList,
  1551. "drugList": drugList,
  1552. "supplyList": supplyList,
  1553. })
  1554. } else {
  1555. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1556. }
  1557. }
  1558. }
  1559. func (this *SupplyOrderApiController) UpdateGoodOrder() {
  1560. supplier_id, _ := this.GetInt64("supplier_id")
  1561. start_time := this.GetString("start")
  1562. timeLayout := "2006-01-02"
  1563. loc, _ := time.LoadLocation("Local")
  1564. var startTime int64
  1565. if len(start_time) > 0 {
  1566. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1567. if err != nil {
  1568. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1569. return
  1570. }
  1571. startTime = theTime.Unix()
  1572. }
  1573. arrerage := this.GetString("arrerage")
  1574. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  1575. payment := this.GetString("payment")
  1576. payment_float, _ := strconv.ParseFloat(payment, 64)
  1577. warehose_out_id, _ := this.GetInt64("warehose_out_id")
  1578. number := this.GetString("number")
  1579. rate_of_concession := this.GetString("rate_of_concession")
  1580. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  1581. discount_amount := this.GetString("discount_amount")
  1582. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  1583. good_number := this.GetString("good_number")
  1584. fmt.Println(supplier_id, startTime, arrerage, payment, warehose_out_id, number, rate_of_concession, discount_amount)
  1585. orgId := this.GetAdminUserInfo().CurrentOrgId
  1586. dataBody := make(map[string]interface{}, 0)
  1587. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1588. if err != nil {
  1589. utils.ErrorLog(err.Error())
  1590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1591. return
  1592. }
  1593. var warehousingOut []*models.SpSupplierWarehousingOutOrder
  1594. var updateWarehout []*models.SpSupplierWarehousingOutOrder
  1595. return_remake := dataBody["return_remake"].(string)
  1596. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  1597. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  1598. if len(thisStockIn) > 0 {
  1599. for _, item := range thisStockIn {
  1600. items := item.(map[string]interface{})
  1601. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1602. utils.ErrorLog("id")
  1603. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1604. return
  1605. }
  1606. id := int64(items["id"].(float64))
  1607. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  1608. utils.ErrorLog("supply_count")
  1609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1610. return
  1611. }
  1612. supply_count := int64(items["supply_count"].(float64))
  1613. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  1614. utils.ErrorLog("manufacturer_id")
  1615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1616. return
  1617. }
  1618. manufacturer_id := int64(items["manufacturer_id"].(float64))
  1619. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1620. utils.ErrorLog("name")
  1621. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1622. return
  1623. }
  1624. name := items["name"].(string)
  1625. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  1626. utils.ErrorLog("order_number")
  1627. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1628. return
  1629. }
  1630. order_number := items["order_number"].(string)
  1631. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  1632. utils.ErrorLog("supply_price")
  1633. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1634. return
  1635. }
  1636. supply_price := items["supply_price"].(string)
  1637. price_float, _ := strconv.ParseFloat(supply_price, 64)
  1638. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  1639. utils.ErrorLog("supply_total_price")
  1640. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1641. return
  1642. }
  1643. supply_total_price := items["supply_total_price"].(string)
  1644. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  1645. if items["min_price"] == nil || reflect.TypeOf(items["min_price"]).String() != "string" {
  1646. utils.ErrorLog("min_price")
  1647. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1648. return
  1649. }
  1650. min_price := items["min_price"].(string)
  1651. min_price_float, _ := strconv.ParseFloat(min_price, 64)
  1652. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  1653. utils.ErrorLog("project_id")
  1654. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1655. return
  1656. }
  1657. project_id := int64(items["project_id"].(float64))
  1658. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  1659. utils.ErrorLog("supply_remake")
  1660. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1661. return
  1662. }
  1663. supply_remake := items["supply_remake"].(string)
  1664. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  1665. utils.ErrorLog("supply_batch_number")
  1666. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1667. return
  1668. }
  1669. supply_batch_number := items["supply_batch_number"].(string)
  1670. var supply_expiry_date_time int64
  1671. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "string" {
  1672. utils.ErrorLog("supply_expiry_date")
  1673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1674. return
  1675. }
  1676. supply_expiry_date := items["supply_expiry_date"].(string)
  1677. if len(supply_expiry_date) > 0 {
  1678. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_expiry_date+" 00:00:00", loc)
  1679. if err != nil {
  1680. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1681. return
  1682. }
  1683. supply_expiry_date_time = theTime.Unix()
  1684. }
  1685. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  1686. utils.ErrorLog("supply_license_number")
  1687. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1688. return
  1689. }
  1690. supply_license_number := items["supply_license_number"].(string)
  1691. var supply_product_date_time int64
  1692. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "string" {
  1693. utils.ErrorLog("supply_product_date")
  1694. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1695. return
  1696. }
  1697. supply_product_date := items["supply_product_date"].(string)
  1698. if len(supply_product_date) > 0 {
  1699. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_product_date+" 00:00:00", loc)
  1700. if err != nil {
  1701. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1702. return
  1703. }
  1704. supply_product_date_time = theTime.Unix()
  1705. }
  1706. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  1707. utils.ErrorLog("supply_specification_name")
  1708. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1709. return
  1710. }
  1711. supply_specification_name := items["supply_specification_name"].(string)
  1712. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  1713. utils.ErrorLog("supply_total")
  1714. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1715. return
  1716. }
  1717. supply_total := items["supply_total"].(string)
  1718. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  1719. utils.ErrorLog("supply_type")
  1720. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1721. return
  1722. }
  1723. supply_type := items["supply_type"].(string)
  1724. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  1725. utils.ErrorLog("supply_unit")
  1726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1727. return
  1728. }
  1729. supply_unit := items["supply_unit"].(string)
  1730. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1731. utils.ErrorLog("type")
  1732. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1733. return
  1734. }
  1735. is_source := int64(items["type"].(float64))
  1736. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  1737. utils.ErrorLog("supply_manufacturer")
  1738. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1739. return
  1740. }
  1741. supply_manufacturer := items["supply_manufacturer"].(string)
  1742. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  1743. utils.ErrorLog("warehouse_info_id")
  1744. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1745. return
  1746. }
  1747. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1748. if items["warehousing_id"] == nil || reflect.TypeOf(items["warehousing_id"]).String() != "float64" {
  1749. utils.ErrorLog("warehousing_id")
  1750. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1751. return
  1752. }
  1753. warehousing_id := int64(items["warehousing_id"].(float64))
  1754. if id > 0 {
  1755. order := models.SpSupplierWarehousingOutOrder{
  1756. ID: id,
  1757. OrderNumber: order_number,
  1758. ProjectId: project_id,
  1759. IsSource: is_source,
  1760. Count: supply_count,
  1761. Amount: supply_total_price_float,
  1762. Price: price_float,
  1763. Remark: supply_remake,
  1764. IsCheck: 2,
  1765. UserOrgId: orgId,
  1766. Status: 1,
  1767. Ctime: time.Now().Unix(),
  1768. Mtime: 0,
  1769. WarehouseOutId: warehose_out_id,
  1770. Type: 1,
  1771. SupplyBatchNumber: supply_batch_number,
  1772. SupplyProductDate: supply_product_date_time,
  1773. SupplyExpiryDate: supply_expiry_date_time,
  1774. SupplyType: supply_type,
  1775. SupplyUnit: supply_unit,
  1776. SupplyTotal: supply_total,
  1777. SupplySpecificationName: supply_specification_name,
  1778. SupplyLicenseNumber: supply_license_number,
  1779. Name: name,
  1780. ManufacturerId: manufacturer_id,
  1781. GoodNumber: good_number,
  1782. SupplyManufacturer: supply_manufacturer,
  1783. WarehouseInfoId: warehouse_info_id,
  1784. WarehousingId: warehousing_id,
  1785. MinPrice: min_price_float,
  1786. }
  1787. updateWarehout = append(updateWarehout, &order)
  1788. }
  1789. if id == 0 {
  1790. order := models.SpSupplierWarehousingOutOrder{
  1791. OrderNumber: order_number,
  1792. ProjectId: project_id,
  1793. IsSource: is_source,
  1794. Count: supply_count,
  1795. Amount: supply_total_price_float,
  1796. Price: price_float,
  1797. Remark: supply_remake,
  1798. IsCheck: 2,
  1799. UserOrgId: orgId,
  1800. Status: 1,
  1801. Ctime: time.Now().Unix(),
  1802. Mtime: 0,
  1803. WarehouseOutId: warehose_out_id,
  1804. Type: 1,
  1805. SupplyBatchNumber: supply_batch_number,
  1806. SupplyProductDate: supply_product_date_time,
  1807. SupplyExpiryDate: supply_expiry_date_time,
  1808. WarehouseInfoId: id,
  1809. SupplyType: supply_type,
  1810. SupplyUnit: supply_unit,
  1811. SupplyTotal: supply_total,
  1812. SupplySpecificationName: supply_specification_name,
  1813. SupplyLicenseNumber: supply_license_number,
  1814. Name: name,
  1815. ManufacturerId: manufacturer_id,
  1816. GoodNumber: good_number,
  1817. SupplyManufacturer: supply_manufacturer,
  1818. MinPrice: min_price_float,
  1819. IsWarehosue: 2,
  1820. }
  1821. warehousingOut = append(warehousingOut, &order)
  1822. }
  1823. }
  1824. }
  1825. }
  1826. out := models.SpSupplierWarehouseOut{
  1827. Arrearage: arrerage_float,
  1828. Payment: payment_float,
  1829. RateOfConcession: rate_of_concession_float,
  1830. DiscountAmount: discount_amount_float,
  1831. SupplierId: supplier_id,
  1832. DocumentDate: startTime,
  1833. ReturnRemake: return_remake,
  1834. }
  1835. //更改购货单据
  1836. service.UpdateGoodWarehouseOut(warehose_out_id, out)
  1837. for _, item := range warehousingOut {
  1838. //如果是手动新增的,type 等于2
  1839. if item.WarehouseInfoId == 0 {
  1840. item.Type = 2
  1841. }
  1842. err = service.CreateSupplyWarehousOutOrder(item)
  1843. }
  1844. for _, item := range updateWarehout {
  1845. service.UpdateGoodWarehouseOutOrder(item)
  1846. }
  1847. //for _, item := range updateWarehout {
  1848. // service.UpdateGoodWarehouseOutOrder(item)
  1849. // //查询该商品是否来源于采购订单,如果存在则关联, 如果不存在则取消关联
  1850. // _, errcode := service.GetGoodIsSource(item.WarehousingId, item.ProjectId, orgId)
  1851. // if errcode == gorm.ErrRecordNotFound {
  1852. // item.WarehousingId = 0
  1853. // item.WarehouseInfoId = 0
  1854. // item.Type = 2
  1855. // item.OrderNumber = ""
  1856. //
  1857. // //更新采购单
  1858. // service.ModfySupplyWarehouseOut(item.WarehousingId, orgId)
  1859. // }
  1860. //}
  1861. if err == nil {
  1862. this.ServeSuccessJSON(map[string]interface{}{
  1863. "out": out,
  1864. })
  1865. } else {
  1866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1867. }
  1868. }
  1869. func (this *SupplyOrderApiController) DeletePurchOrder() {
  1870. id, _ := this.GetInt64("id")
  1871. orgId := this.GetAdminUserInfo().CurrentOrgId
  1872. err := service.DeletePurchOrder(id, orgId)
  1873. if err == nil {
  1874. returnData := make(map[string]interface{}, 0)
  1875. returnData["msg"] = "ok"
  1876. this.ServeSuccessJSON(returnData)
  1877. return
  1878. } else {
  1879. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1880. }
  1881. }
  1882. func (this *SupplyOrderApiController) GetAllOrderCountList() {
  1883. id, _ := this.GetInt64("id")
  1884. orgId := this.GetAdminUserInfo().CurrentOrgId
  1885. //获取购货订单的数据
  1886. purcaseOrder, _ := service.GetAllPurcaseOrderById(id, orgId)
  1887. //获取购货单的数据
  1888. goodOrder, err := service.GetAllGoodOrderByIdSix(id, orgId)
  1889. drugList, err := service.GetSupplyDrugList(orgId)
  1890. if err == nil {
  1891. this.ServeSuccessJSON(map[string]interface{}{
  1892. "purcaseOrder": purcaseOrder,
  1893. "goodOrder": goodOrder,
  1894. "drugList": drugList,
  1895. })
  1896. } else {
  1897. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1898. }
  1899. }
  1900. func (this *SupplyOrderApiController) GetPurchOrderInfo() {
  1901. id, _ := this.GetInt64("id")
  1902. ids := this.GetString("ids")
  1903. if len(ids) == 0 {
  1904. info, _ := service.GetPurchaseOrderDetail(id)
  1905. //查询
  1906. orderInfo, err := service.GetSupplyWarehousingOrderInfo(id)
  1907. orgId := this.GetAdminUserInfo().CurrentOrgId
  1908. supplyList, _ := service.GetSupplierList(orgId)
  1909. //获取药品库数据
  1910. baseList, _ := service.GetSupplyDrugList(orgId)
  1911. goodList, _ := service.GetSupplyGoodList(orgId)
  1912. if err == nil {
  1913. this.ServeSuccessJSON(map[string]interface{}{
  1914. "info": info,
  1915. "orderInfo": orderInfo,
  1916. "supplyList": supplyList,
  1917. "baseList": baseList,
  1918. "goodList": goodList,
  1919. })
  1920. } else {
  1921. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1922. }
  1923. }
  1924. if len(ids) > 0 {
  1925. idArray := strings.Split(ids, ",")
  1926. info, _ := service.GetPurchaseOrderDetail(id)
  1927. //查询
  1928. orderInfo, err := service.GetSupplyWarehousingOrderInfoTwo(id, idArray)
  1929. orgId := this.GetAdminUserInfo().CurrentOrgId
  1930. supplyList, _ := service.GetSupplierList(orgId)
  1931. //获取药品库数据
  1932. baseList, _ := service.GetSupplyDrugList(orgId)
  1933. goodList, _ := service.GetSupplyGoodList(orgId)
  1934. if err == nil {
  1935. this.ServeSuccessJSON(map[string]interface{}{
  1936. "info": info,
  1937. "orderInfo": orderInfo,
  1938. "supplyList": supplyList,
  1939. "baseList": baseList,
  1940. "goodList": goodList,
  1941. })
  1942. } else {
  1943. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1944. }
  1945. }
  1946. }
  1947. func (this *SupplyOrderApiController) GetGoodOrderList() {
  1948. id, _ := this.GetInt64("id")
  1949. orgId := this.GetAdminUserInfo().CurrentOrgId
  1950. list, err := service.GetGoodOrderList(id, orgId)
  1951. if err == nil {
  1952. this.ServeSuccessJSON(map[string]interface{}{
  1953. "list": list,
  1954. })
  1955. } else {
  1956. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1957. }
  1958. }
  1959. func (this *SupplyOrderApiController) GetReturnOrder() {
  1960. id, _ := this.GetInt64("id")
  1961. orgId := this.GetAdminUserInfo().CurrentOrgId
  1962. err := service.GetReturnOrder(id, orgId)
  1963. if err == nil {
  1964. returnData := make(map[string]interface{}, 0)
  1965. returnData["msg"] = "ok"
  1966. this.ServeSuccessJSON(returnData)
  1967. return
  1968. } else {
  1969. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1970. }
  1971. }
  1972. func (this *SupplyOrderApiController) GetGoodOrderCountList() {
  1973. id, _ := this.GetInt64("id")
  1974. warehousing_id, _ := this.GetInt64("warehousing_id")
  1975. orgId := this.GetAdminUserInfo().CurrentOrgId
  1976. checker := this.GetAdminUserInfo().AdminUser.Id
  1977. recordDateStr := time.Now().Format("2006-01-02")
  1978. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1979. record_date := recordDate.Unix()
  1980. out := models.SpSupplierWarehouseOut{
  1981. IsCheck: 1,
  1982. Checker: checker,
  1983. CheckTime: record_date,
  1984. }
  1985. err := service.CheckGoodOrder(id, orgId, out)
  1986. fmt.Println(err)
  1987. //获取购货订单的数据
  1988. purcaseOrder, _ := service.GetAllPurcaseOrderById(warehousing_id, orgId)
  1989. //获取购货单的数据
  1990. goodOrder, _ := service.GetAllGoodOrderByIdTwo(id, orgId)
  1991. //查询该购货单是否审核成功
  1992. detail, _ := service.GetGoodOrderDetail(id, orgId)
  1993. var warehousingInfo []*models.WarehousingInfo
  1994. var warehouseInfoDetail []*models.DrugWarehouseInfo
  1995. var drugFlow []*models.DrugFlow
  1996. //如果审核成功
  1997. if detail.IsCheck == 1 {
  1998. //入库
  1999. if len(goodOrder) > 0 {
  2000. for _, item := range goodOrder {
  2001. //药品
  2002. if item.IsSource == 1 {
  2003. //获取药品类型
  2004. medical, _ := service.GetBaseDrugMedical(item.ID)
  2005. timeStr := time.Now().Format("2006-01-02")
  2006. timeArr := strings.Split(timeStr, "-")
  2007. total, _ := service.FindAllWarehouseTotalOne(orgId)
  2008. total = total + 1
  2009. warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2010. operation_time := time.Now().Unix()
  2011. warehousing := models.DrugWarehouse{
  2012. WarehousingOrder: warehousing_order,
  2013. OperationTime: operation_time,
  2014. OrgId: orgId,
  2015. Creater: checker,
  2016. Ctime: time.Now().Unix(),
  2017. Status: 1,
  2018. WarehousingTime: record_date,
  2019. Type: 1,
  2020. SupplyWarehouseId: id,
  2021. }
  2022. //查询今日是否存在入库单号
  2023. _, errcode := service.GetSingleDrugWarehouseOrder(record_date, orgId)
  2024. if errcode == gorm.ErrRecordNotFound {
  2025. service.AddSigleDrugWarehouse(&warehousing)
  2026. }
  2027. drugWarehouseInfo, _ := service.GetLastDrugWarehouse(orgId)
  2028. warehouseInfoDetailOne := &models.DrugWarehouseInfo{
  2029. WarehousingOrder: drugWarehouseInfo.WarehousingOrder,
  2030. WarehousingId: drugWarehouseInfo.ID,
  2031. DrugId: item.ProjectId,
  2032. Number: item.SupplyLicenseNumber,
  2033. ProductDate: item.SupplyProductDate,
  2034. ExpiryDate: item.SupplyExpiryDate,
  2035. WarehousingCount: item.Count,
  2036. Price: item.Price,
  2037. TotalPrice: 0,
  2038. Status: 1,
  2039. Ctime: time.Now().Unix(),
  2040. Remark: item.Remark,
  2041. OrgId: orgId,
  2042. Type: 1,
  2043. Manufacturer: item.ManufacturerId,
  2044. Dealer: 0,
  2045. StockMaxNumber: item.Count,
  2046. RetailTotalPrice: 0,
  2047. BatchNumber: item.SupplyBatchNumber,
  2048. MaxUnit: item.SupplyUnit,
  2049. MinUnit: item.SupplyUnit,
  2050. RetailPrice: item.MinPrice,
  2051. SupplyWarehouseId: id,
  2052. SupplyWarehouseDetailInfo: item.ID,
  2053. }
  2054. if medical.MaxUnit == medical.MinUnit {
  2055. warehouseInfoDetailOne.StockMaxNumber = item.Count
  2056. warehouseInfoDetailOne.StockMinNumber = 0
  2057. warehouseInfoDetailOne.MaxUnit = item.SupplyUnit
  2058. }
  2059. if item.SupplyUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2060. warehouseInfoDetailOne.StockMaxNumber = 0
  2061. warehouseInfoDetailOne.StockMinNumber = item.Count
  2062. warehouseInfoDetailOne.MaxUnit = item.SupplyUnit
  2063. }
  2064. warehouseInfoDetail = append(warehouseInfoDetail, warehouseInfoDetailOne)
  2065. drugflow := &models.DrugFlow{
  2066. WarehousingOrder: drugWarehouseInfo.WarehousingOrder,
  2067. WarehousingId: drugWarehouseInfo.ID,
  2068. DrugId: item.ProjectId,
  2069. Number: item.SupplyBatchNumber,
  2070. ProductDate: item.SupplyProductDate,
  2071. ExpireDate: item.SupplyExpiryDate,
  2072. Count: item.Count,
  2073. Price: item.Price,
  2074. Status: 1,
  2075. Ctime: time.Now().Unix(),
  2076. UserOrgId: orgId,
  2077. Manufacturer: item.ManufacturerId,
  2078. Dealer: 0,
  2079. BatchNumber: item.SupplyBatchNumber,
  2080. MaxUnit: item.SupplyUnit,
  2081. MinUnit: item.SupplyUnit,
  2082. ConsumableType: 1,
  2083. IsEdit: 1,
  2084. Creator: checker,
  2085. IsSys: 0,
  2086. SupplyWarehouseId: id,
  2087. SupplyWarehouseDetailInfo: item.ID,
  2088. }
  2089. if medical.MaxUnit == medical.MinUnit {
  2090. drugflow.MaxUnit = item.SupplyUnit
  2091. }
  2092. if item.SupplyUnit == medical.MinUnit {
  2093. warehouseInfoDetailOne.MaxUnit = warehouseInfoDetailOne.MinUnit
  2094. }
  2095. drugFlow = append(drugFlow, drugflow)
  2096. }
  2097. //耗材
  2098. if item.IsSource == 2 {
  2099. //获取耗材类型
  2100. good, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  2101. timeStr := time.Now().Format("2006-01-02")
  2102. timeArr := strings.Split(timeStr, "-")
  2103. total, _ := service.FindAllWarehouseTotal(orgId)
  2104. total = total + 1
  2105. warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2106. operation_time := time.Now().Unix()
  2107. creater := this.GetAdminUserInfo().AdminUser.Id
  2108. warehousing := models.Warehousing{
  2109. WarehousingOrder: warehousing_order,
  2110. OperationTime: operation_time,
  2111. OrgId: orgId,
  2112. Creater: creater,
  2113. Ctime: time.Now().Unix(),
  2114. Status: 1,
  2115. WarehousingTime: record_date,
  2116. Type: 1,
  2117. SupplyWarehouseId: id,
  2118. }
  2119. //查询是否存在入库单
  2120. _, errcose := service.GetSindleWarehouse(record_date, orgId)
  2121. if errcose == gorm.ErrRecordNotFound {
  2122. service.AddSigleWarehouse(&warehousing)
  2123. }
  2124. info, _ := service.GetLastWarehouseInfoByInfo(orgId)
  2125. //入库单表格
  2126. warehouseInfo := &models.WarehousingInfo{
  2127. WarehousingOrder: info.WarehousingOrder,
  2128. WarehousingId: info.ID,
  2129. GoodId: item.ProjectId,
  2130. Number: item.SupplyBatchNumber,
  2131. GoodTypeId: good.GoodTypeId,
  2132. ProductDate: item.SupplyProductDate,
  2133. ExpiryDate: item.SupplyExpiryDate,
  2134. WarehousingCount: item.Count,
  2135. Price: item.Price,
  2136. TotalPrice: 0,
  2137. Status: 1,
  2138. Ctime: time.Now().Unix(),
  2139. Remark: item.Remark,
  2140. OrgId: orgId,
  2141. Type: 1,
  2142. Manufacturer: item.ManufacturerId,
  2143. StockCount: item.Count,
  2144. Dealer: good.Dealer,
  2145. LicenseNumber: item.SupplyLicenseNumber,
  2146. PackingPrice: item.MinPrice,
  2147. SupplyWarehouseId: id,
  2148. SupplyWarehouseDetailInfo: item.ID,
  2149. }
  2150. warehousingInfo = append(warehousingInfo, warehouseInfo)
  2151. }
  2152. }
  2153. }
  2154. }
  2155. for _, item := range warehousingInfo {
  2156. service.CreatedWarehouseingDetail(item)
  2157. warehousinginfo, _ := service.GetLastWarehousingInfo(item.GoodId)
  2158. flow := models.VmStockFlow{
  2159. WarehousingOrder: item.WarehousingOrder,
  2160. WarehousingId: item.ID,
  2161. GoodId: item.GoodId,
  2162. Number: item.Number,
  2163. ProductDate: item.ProductDate,
  2164. ExpireDate: item.ExpiryDate,
  2165. Count: item.WarehousingCount,
  2166. Price: item.Price,
  2167. Status: 1,
  2168. Ctime: time.Now().Unix(),
  2169. UserOrgId: orgId,
  2170. Manufacturer: item.Manufacturer,
  2171. Dealer: item.Dealer,
  2172. LicenseNumber: item.LicenseNumber,
  2173. IsEdit: 1,
  2174. Creator: checker,
  2175. SystemTime: record_date,
  2176. ConsumableType: 1,
  2177. WarehousingDetailId: warehousinginfo.ID,
  2178. SupplyWarehouseId: id,
  2179. SupplyWarehouseDetailInfo: item.ID,
  2180. }
  2181. service.CreateStockFlowOne(flow)
  2182. }
  2183. //创建入库单
  2184. errs := service.CreateDrugWarehousingInfoSix(warehouseInfoDetail)
  2185. //改变入库状态
  2186. fmt.Println(errs)
  2187. for _, items := range drugFlow {
  2188. drugWarehouseInfo, _ := service.GetLastDrugWarehouseInfo(items.DrugId)
  2189. items.WarehousingDetailId = drugWarehouseInfo.ID
  2190. }
  2191. //创建流水单
  2192. service.CreateDrugFlowSix(drugFlow)
  2193. drugList, _ := service.GetSupplyDrugList(orgId)
  2194. for _, items := range goodOrder {
  2195. service.UpdateWarehouseingById(items.ID)
  2196. }
  2197. if err == nil {
  2198. this.ServeSuccessJSON(map[string]interface{}{
  2199. "purcaseOrder": purcaseOrder,
  2200. "goodOrder": goodOrder,
  2201. "drugList": drugList,
  2202. })
  2203. } else {
  2204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2205. }
  2206. }
  2207. func (this *SupplyOrderApiController) ModefySupplyWarehousing() {
  2208. is_warehouse, _ := this.GetInt64("is_warehouse")
  2209. warehousing_id, _ := this.GetInt64("warehousing_id")
  2210. orgId := this.GetAdminUserInfo().CurrentOrgId
  2211. err := service.ModefySupplyWarehousing(is_warehouse, warehousing_id, orgId)
  2212. if err == nil {
  2213. returnData := make(map[string]interface{}, 0)
  2214. returnData["msg"] = "ok"
  2215. this.ServeSuccessJSON(returnData)
  2216. return
  2217. } else {
  2218. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2219. }
  2220. }
  2221. func (this *SupplyOrderApiController) SaveGoodReturnOrder() {
  2222. dataBody := make(map[string]interface{}, 0)
  2223. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2224. if err != nil {
  2225. utils.ErrorLog(err.Error())
  2226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2227. return
  2228. }
  2229. return_remark := dataBody["return_marke"].(string)
  2230. supplier_id, _ := this.GetInt64("supplier_id")
  2231. start_time := this.GetString("start_time")
  2232. timeLayout := "2006-01-02"
  2233. loc, _ := time.LoadLocation("Local")
  2234. var startTime int64
  2235. if len(start_time) > 0 {
  2236. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2237. if err != nil {
  2238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2239. return
  2240. }
  2241. startTime = theTime.Unix()
  2242. }
  2243. warehouse_out_id, _ := this.GetInt64("warehouse_out_id")
  2244. arrerage := this.GetString("arrerage")
  2245. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  2246. payment := this.GetString("payment")
  2247. payment_float, _ := strconv.ParseFloat(payment, 64)
  2248. rate_of_concession := this.GetString("rate_of_concession")
  2249. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  2250. discount_amount := this.GetString("discount_amount")
  2251. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  2252. orgId := this.GetAdminUserInfo().CurrentOrgId
  2253. total, _ := service.GetSupplyCancelOrder(orgId)
  2254. creater := this.GetAdminUserInfo().AdminUser.Id
  2255. //生成购货单
  2256. timeStr := time.Now().Format("2006-01-02")
  2257. timeArr := strings.Split(timeStr, "-")
  2258. total = total + 1
  2259. warehousing_order := "CGT" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  2260. recordDateStr := time.Now().Format("2006-01-02")
  2261. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2262. cancel := models.SpSupplierWarehouseCancel{
  2263. Number: warehousing_order,
  2264. UserOrgId: orgId,
  2265. Creater: creater,
  2266. Ctime: time.Now().Unix(),
  2267. Mtime: 0,
  2268. Status: 1,
  2269. RecordDate: recordDate.Unix(),
  2270. IsCheck: 2,
  2271. WarehouseOutId: warehouse_out_id,
  2272. RateOfConcession: rate_of_concession_float,
  2273. DiscountAmount: discount_amount_float,
  2274. DocumentDate: startTime,
  2275. SupplierId: supplier_id,
  2276. Checker: 0,
  2277. CheckTime: 0,
  2278. Arrearage: arrerage_float,
  2279. Payment: payment_float,
  2280. ReturnRemark: return_remark,
  2281. }
  2282. err = service.CreateReturnCacelOrder(cancel)
  2283. order, _ := service.GetLastReturnCancelOrder(orgId)
  2284. var warehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2285. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  2286. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  2287. if len(thisStockIn) > 0 {
  2288. for _, item := range thisStockIn {
  2289. items := item.(map[string]interface{})
  2290. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  2291. utils.ErrorLog("supply_count")
  2292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2293. return
  2294. }
  2295. supply_count := int64(items["supply_count"].(float64))
  2296. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2297. utils.ErrorLog("count")
  2298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2299. return
  2300. }
  2301. count := items["count"].(string)
  2302. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  2303. utils.ErrorLog("manufacturer_id")
  2304. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2305. return
  2306. }
  2307. manufacturer_id := int64(items["manufacturer_id"].(float64))
  2308. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  2309. utils.ErrorLog("name")
  2310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2311. return
  2312. }
  2313. name := items["name"].(string)
  2314. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  2315. utils.ErrorLog("order_number")
  2316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2317. return
  2318. }
  2319. order_number := items["order_number"].(string)
  2320. if items["good_number"] == nil || reflect.TypeOf(items["good_number"]).String() != "string" {
  2321. utils.ErrorLog("good_number")
  2322. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2323. return
  2324. }
  2325. good_number := items["good_number"].(string)
  2326. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  2327. utils.ErrorLog("supply_price")
  2328. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2329. return
  2330. }
  2331. supply_price := items["supply_price"].(string)
  2332. price_float, _ := strconv.ParseFloat(supply_price, 64)
  2333. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  2334. utils.ErrorLog("project_id")
  2335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2336. return
  2337. }
  2338. project_id := int64(items["project_id"].(float64))
  2339. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  2340. utils.ErrorLog("supply_remake")
  2341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2342. return
  2343. }
  2344. supply_remake := items["supply_remake"].(string)
  2345. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  2346. utils.ErrorLog("supply_license_number")
  2347. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2348. return
  2349. }
  2350. supply_license_number := items["supply_license_number"].(string)
  2351. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  2352. utils.ErrorLog("supply_specification_name")
  2353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2354. return
  2355. }
  2356. supply_specification_name := items["supply_specification_name"].(string)
  2357. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  2358. utils.ErrorLog("supply_total")
  2359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2360. return
  2361. }
  2362. supply_total := items["supply_total"].(string)
  2363. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  2364. utils.ErrorLog("supply_type")
  2365. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2366. return
  2367. }
  2368. supply_type := items["supply_type"].(string)
  2369. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  2370. utils.ErrorLog("supply_unit")
  2371. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2372. return
  2373. }
  2374. supply_unit := items["supply_unit"].(string)
  2375. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2376. utils.ErrorLog("type")
  2377. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2378. return
  2379. }
  2380. is_source := int64(items["type"].(float64))
  2381. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  2382. utils.ErrorLog("supply_manufacturer")
  2383. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2384. return
  2385. }
  2386. supply_manufacturer := items["supply_manufacturer"].(string)
  2387. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  2388. utils.ErrorLog("supply_batch_number")
  2389. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2390. return
  2391. }
  2392. supply_batch_number := items["supply_batch_number"].(string)
  2393. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "float64" {
  2394. utils.ErrorLog("supply_product_date")
  2395. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2396. return
  2397. }
  2398. supply_product_date := int64(items["supply_product_date"].(float64))
  2399. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "float64" {
  2400. utils.ErrorLog("supply_expiry_date")
  2401. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2402. return
  2403. }
  2404. supply_expiry_date := int64(items["supply_expiry_date"].(float64))
  2405. if items["warehousing_id"] == nil || reflect.TypeOf(items["warehousing_id"]).String() != "float64" {
  2406. utils.ErrorLog("warehousing_id")
  2407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2408. return
  2409. }
  2410. warehousing_id := int64(items["warehousing_id"].(float64))
  2411. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  2412. utils.ErrorLog("warehouse_info_id")
  2413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2414. return
  2415. }
  2416. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  2417. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2418. utils.ErrorLog("id")
  2419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2420. return
  2421. }
  2422. id := int64(items["id"].(float64))
  2423. deposit_rate := items["deposit_rate"].(string)
  2424. deposit_rate_float, _ := strconv.ParseFloat(deposit_rate, 64)
  2425. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2426. ManufacturerId: manufacturer_id,
  2427. OrderNumber: order_number,
  2428. ProjectId: project_id,
  2429. GoodNumber: good_number,
  2430. IsSource: is_source,
  2431. Count: count,
  2432. Price: price_float,
  2433. Remark: supply_remake,
  2434. RateOfConcession: rate_of_concession_float,
  2435. DiscountAmount: discount_amount_float,
  2436. UserOrgId: orgId,
  2437. Ctime: time.Now().Unix(),
  2438. Status: 1,
  2439. Mtime: 0,
  2440. WarehouseCancelId: order.ID,
  2441. Type: 1,
  2442. ReturnNumber: order.Number,
  2443. WarehouseOutId: warehouse_out_id,
  2444. SupplySpecificationName: supply_specification_name,
  2445. SupplyType: supply_type,
  2446. SupplyTotal: supply_total,
  2447. SupplyManufacturer: supply_manufacturer,
  2448. Name: name,
  2449. SupplyUnit: supply_unit,
  2450. SupplyLicenseNumber: supply_license_number,
  2451. SupplyBatchNumber: supply_batch_number,
  2452. SupplyExpiryDate: supply_expiry_date,
  2453. SupplyProductDate: supply_product_date,
  2454. WarehouseInfoId: warehouse_info_id,
  2455. WarehousingId: warehousing_id,
  2456. SourceCount: count,
  2457. SupplyWarehouseDetailInfo: id,
  2458. SupplyCount: supply_count,
  2459. DepositRate: deposit_rate_float,
  2460. }
  2461. warehouseCancel = append(warehouseCancel, cancelOrder)
  2462. }
  2463. }
  2464. }
  2465. for _, item := range warehouseCancel {
  2466. service.CreateCancelReturnOrder(item)
  2467. //查询该商品在退库单中是否存在
  2468. _, errcodes := service.GetSupplyWarehouseOutIsExsit(item.WarehouseOutId, item.ProjectId, orgId)
  2469. //如果不存在则情况退库单的关联信息
  2470. if errcodes == gorm.ErrRecordNotFound {
  2471. service.ModfySupplyCancel(item.WarehouseCancelId, orgId)
  2472. }
  2473. }
  2474. cancelOrder, err := service.GetReturnCancelOrder(order.ID, orgId)
  2475. list, err := service.GetReturnCancelOrderList(order.ID, orgId)
  2476. if err == nil {
  2477. this.ServeSuccessJSON(map[string]interface{}{
  2478. "warehouseCancel": warehouseCancel,
  2479. "cancelOrder": cancelOrder,
  2480. "list": list,
  2481. })
  2482. } else {
  2483. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2484. }
  2485. }
  2486. func (this *SupplyOrderApiController) GetAllGoodReturnOrderList() {
  2487. check_id, _ := this.GetInt64("check_id")
  2488. start_time := this.GetString("start_time")
  2489. end_time := this.GetString("end_time")
  2490. keyword := this.GetString("keyword")
  2491. page, _ := this.GetInt64("page")
  2492. limit, _ := this.GetInt64("limit")
  2493. timeLayout := "2006-01-02"
  2494. loc, _ := time.LoadLocation("Local")
  2495. var startTime int64
  2496. if len(start_time) > 0 {
  2497. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2498. if err != nil {
  2499. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2500. return
  2501. }
  2502. startTime = theTime.Unix()
  2503. }
  2504. var endTime int64
  2505. if len(end_time) > 0 {
  2506. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2507. if err != nil {
  2508. utils.ErrorLog(err.Error())
  2509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2510. return
  2511. }
  2512. endTime = theTime.Unix()
  2513. }
  2514. orgId := this.GetAdminUserInfo().CurrentOrgId
  2515. list, total, err := service.GetAllGoodReturnOrderList(check_id, keyword, page, limit, startTime, endTime, orgId)
  2516. if err == nil {
  2517. this.ServeSuccessJSON(map[string]interface{}{
  2518. "total": total,
  2519. "list": list,
  2520. })
  2521. } else {
  2522. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2523. }
  2524. }
  2525. func (this *SupplyOrderApiController) GetGoodReturnDetail() {
  2526. id, _ := this.GetInt64("id")
  2527. orgId := this.GetAdminUserInfo().CurrentOrgId
  2528. detail, err := service.GetGoodReturnDetail(id, orgId)
  2529. orderDetail, err := service.GetGoodReturnOrderDetail(id, orgId)
  2530. //获取药品库数据
  2531. baseList, _ := service.GetSupplyDrugList(orgId)
  2532. goodList, _ := service.GetSupplyGoodList(orgId)
  2533. supplyList, _ := service.GetSupplierList(orgId)
  2534. if err == nil {
  2535. this.ServeSuccessJSON(map[string]interface{}{
  2536. "cancelDetail": detail,
  2537. "orderCancelDetail": orderDetail,
  2538. "drugList": baseList,
  2539. "goodList": goodList,
  2540. "supplyList": supplyList,
  2541. })
  2542. } else {
  2543. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2544. }
  2545. }
  2546. func (this *SupplyOrderApiController) UpdateGoodReturn() {
  2547. dataBody := make(map[string]interface{}, 0)
  2548. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2549. if err != nil {
  2550. utils.ErrorLog(err.Error())
  2551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2552. return
  2553. }
  2554. return_remark := dataBody["return_marke"].(string)
  2555. supplier_id, _ := this.GetInt64("supplier_id")
  2556. start_time := this.GetString("start")
  2557. timeLayout := "2006-01-02"
  2558. loc, _ := time.LoadLocation("Local")
  2559. var startTime int64
  2560. if len(start_time) > 0 {
  2561. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2562. if err != nil {
  2563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2564. return
  2565. }
  2566. startTime = theTime.Unix()
  2567. }
  2568. warehouse_out_id, _ := this.GetInt64("warehouse_out_id")
  2569. arrerage := this.GetString("arrerage")
  2570. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  2571. payment := this.GetString("payment")
  2572. payment_float, _ := strconv.ParseFloat(payment, 64)
  2573. rate_of_concession := this.GetString("rate_of_concession")
  2574. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  2575. discount_amount := this.GetString("discount_amount")
  2576. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  2577. return_number := this.GetString("return_number")
  2578. orgId := this.GetAdminUserInfo().CurrentOrgId
  2579. cancel := models.SpSupplierWarehouseCancel{
  2580. ID: 0,
  2581. Number: return_number,
  2582. RateOfConcession: rate_of_concession_float,
  2583. DiscountAmount: discount_amount_float,
  2584. DocumentDate: startTime,
  2585. SupplierId: supplier_id,
  2586. Arrearage: arrerage_float,
  2587. Payment: payment_float,
  2588. ReturnRemark: return_remark,
  2589. }
  2590. service.UpdateWarehouseCancel(warehouse_out_id, cancel)
  2591. var warehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2592. var updateWarehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2593. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  2594. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  2595. if len(thisStockIn) > 0 {
  2596. for _, item := range thisStockIn {
  2597. items := item.(map[string]interface{})
  2598. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2599. utils.ErrorLog("id")
  2600. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2601. return
  2602. }
  2603. id := int64(items["id"].(float64))
  2604. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  2605. utils.ErrorLog("supply_count")
  2606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2607. return
  2608. }
  2609. supply_count := int64(items["supply_count"].(float64))
  2610. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  2611. utils.ErrorLog("manufacturer_id")
  2612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2613. return
  2614. }
  2615. manufacturer_id := int64(items["manufacturer_id"].(float64))
  2616. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  2617. utils.ErrorLog("name")
  2618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2619. return
  2620. }
  2621. name := items["name"].(string)
  2622. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  2623. utils.ErrorLog("order_number")
  2624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2625. return
  2626. }
  2627. order_number := items["order_number"].(string)
  2628. if items["good_number"] == nil || reflect.TypeOf(items["good_number"]).String() != "string" {
  2629. utils.ErrorLog("good_number")
  2630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2631. return
  2632. }
  2633. good_number := items["good_number"].(string)
  2634. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  2635. utils.ErrorLog("supply_price")
  2636. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2637. return
  2638. }
  2639. supply_price := items["supply_price"].(string)
  2640. price_float, _ := strconv.ParseFloat(supply_price, 64)
  2641. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  2642. utils.ErrorLog("project_id")
  2643. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2644. return
  2645. }
  2646. project_id := int64(items["project_id"].(float64))
  2647. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  2648. utils.ErrorLog("supply_remake")
  2649. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2650. return
  2651. }
  2652. supply_remake := items["supply_remake"].(string)
  2653. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  2654. utils.ErrorLog("supply_license_number")
  2655. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2656. return
  2657. }
  2658. supply_license_number := items["supply_license_number"].(string)
  2659. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  2660. utils.ErrorLog("supply_specification_name")
  2661. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2662. return
  2663. }
  2664. supply_specification_name := items["supply_specification_name"].(string)
  2665. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  2666. utils.ErrorLog("supply_total")
  2667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2668. return
  2669. }
  2670. supply_total := items["supply_total"].(string)
  2671. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  2672. utils.ErrorLog("supply_type")
  2673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2674. return
  2675. }
  2676. supply_type := items["supply_type"].(string)
  2677. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  2678. utils.ErrorLog("supply_unit")
  2679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2680. return
  2681. }
  2682. supply_unit := items["supply_unit"].(string)
  2683. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2684. utils.ErrorLog("type")
  2685. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2686. return
  2687. }
  2688. is_source := int64(items["type"].(float64))
  2689. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  2690. utils.ErrorLog("supply_manufacturer")
  2691. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2692. return
  2693. }
  2694. supply_manufacturer := items["supply_manufacturer"].(string)
  2695. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2696. utils.ErrorLog("count")
  2697. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2698. return
  2699. }
  2700. count := items["count"].(string)
  2701. if items["deposit_rate"] == nil || reflect.TypeOf(items["deposit_rate"]).String() != "string" {
  2702. utils.ErrorLog("deposit_rate")
  2703. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2704. return
  2705. }
  2706. deposit_rate := items["deposit_rate"].(string)
  2707. deposit_rate_float, _ := strconv.ParseFloat(deposit_rate, 64)
  2708. if id > 0 {
  2709. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2710. ID: id,
  2711. ManufacturerId: manufacturer_id,
  2712. OrderNumber: order_number,
  2713. ProjectId: project_id,
  2714. GoodNumber: good_number,
  2715. IsSource: is_source,
  2716. Count: count,
  2717. Price: price_float,
  2718. Remark: supply_remake,
  2719. RateOfConcession: rate_of_concession_float,
  2720. DiscountAmount: discount_amount_float,
  2721. UserOrgId: orgId,
  2722. Ctime: time.Now().Unix(),
  2723. Status: 1,
  2724. Mtime: 0,
  2725. WarehouseCancelId: warehouse_out_id,
  2726. Type: 1,
  2727. ReturnNumber: return_number,
  2728. WarehouseOutId: warehouse_out_id,
  2729. SupplySpecificationName: supply_specification_name,
  2730. SupplyType: supply_type,
  2731. SupplyTotal: supply_total,
  2732. SupplyManufacturer: supply_manufacturer,
  2733. Name: name,
  2734. SupplyUnit: supply_unit,
  2735. SupplyLicenseNumber: supply_license_number,
  2736. SupplyCount: supply_count,
  2737. DepositRate: deposit_rate_float,
  2738. }
  2739. updateWarehouseCancel = append(updateWarehouseCancel, cancelOrder)
  2740. }
  2741. if id == 0 {
  2742. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2743. ManufacturerId: manufacturer_id,
  2744. OrderNumber: order_number,
  2745. ProjectId: project_id,
  2746. GoodNumber: good_number,
  2747. IsSource: is_source,
  2748. Count: count,
  2749. Price: price_float,
  2750. Remark: supply_remake,
  2751. RateOfConcession: rate_of_concession_float,
  2752. DiscountAmount: discount_amount_float,
  2753. UserOrgId: orgId,
  2754. Ctime: time.Now().Unix(),
  2755. Status: 1,
  2756. Mtime: 0,
  2757. WarehouseCancelId: warehouse_out_id,
  2758. Type: 1,
  2759. ReturnNumber: return_number,
  2760. WarehouseOutId: warehouse_out_id,
  2761. SupplySpecificationName: supply_specification_name,
  2762. SupplyType: supply_type,
  2763. SupplyTotal: supply_total,
  2764. SupplyManufacturer: supply_manufacturer,
  2765. Name: name,
  2766. SupplyUnit: supply_unit,
  2767. SupplyLicenseNumber: supply_license_number,
  2768. SupplyCount: supply_count,
  2769. DepositRate: deposit_rate_float,
  2770. }
  2771. warehouseCancel = append(warehouseCancel, cancelOrder)
  2772. }
  2773. }
  2774. }
  2775. if len(updateWarehouseCancel) > 0 {
  2776. for _, item := range updateWarehouseCancel {
  2777. service.UpdateWarehouseCancelOrder(item)
  2778. }
  2779. }
  2780. if len(warehouseCancel) > 0 {
  2781. for _, item := range warehouseCancel {
  2782. service.CreateCancelReturnOrder(item)
  2783. }
  2784. }
  2785. if err == nil {
  2786. returnData := make(map[string]interface{}, 0)
  2787. returnData["msg"] = "ok"
  2788. this.ServeSuccessJSON(returnData)
  2789. return
  2790. } else {
  2791. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2792. }
  2793. }
  2794. }
  2795. func (this *SupplyOrderApiController) ModefyGoodOrder() {
  2796. id, _ := this.GetInt64("id")
  2797. warehousing_id, _ := this.GetInt64("warehousing_id")
  2798. orgId := this.GetAdminUserInfo().CurrentOrgId
  2799. //获取购货单的数据
  2800. goodOrder, _ := service.GetAllGoodOrderById(id, orgId)
  2801. //判断该订单是否有出库记录
  2802. for _, it := range goodOrder {
  2803. if it.IsSource == 1 {
  2804. out, _ := service.GetDrugWarehosueInfoByWarehousingId(it.ProjectId, id, orgId)
  2805. if out.ID > 0 {
  2806. this.ServeSuccessJSON(map[string]interface{}{
  2807. "cancelList": "",
  2808. "purcaseOrder": "",
  2809. "goodOrder": "",
  2810. "drugList": "",
  2811. "msg": 3,
  2812. })
  2813. return
  2814. }
  2815. }
  2816. if it.IsSource == 2 {
  2817. fmt.Println("hh23323233232232332232323232332", it.WarehouseOutId)
  2818. out, _ := service.GetGoodWarehouseInfoByWarehousingId(it.ProjectId, id, orgId)
  2819. if out.ID > 0 {
  2820. this.ServeSuccessJSON(map[string]interface{}{
  2821. "cancelList": "",
  2822. "purcaseOrder": "",
  2823. "goodOrder": "",
  2824. "drugList": "",
  2825. "msg": 3,
  2826. })
  2827. return
  2828. }
  2829. }
  2830. }
  2831. //获取购货订单的数据
  2832. purcaseOrder, _ := service.GetAllPurcaseOrderById(warehousing_id, orgId)
  2833. drugList, _ := service.GetSupplyDrugList(orgId)
  2834. //获取已有关联的退货单
  2835. cancelList, _ := service.GetSupplyCancelWarehouse(id, orgId)
  2836. //查询是否存在退货单
  2837. _, errcode := service.GetSupplyCancelOrderById(id, orgId)
  2838. //无退库单
  2839. if errcode == gorm.ErrRecordNotFound {
  2840. //反审核成功
  2841. out := models.SpSupplierWarehouseOut{
  2842. IsCheck: 2,
  2843. Checker: 0,
  2844. CheckTime: 0,
  2845. }
  2846. err := service.UpdateSupplyGoodOrder(id, out)
  2847. for _, its := range goodOrder {
  2848. //改变采购单状态
  2849. service.UpdateSupplyOrderListById(its.ID)
  2850. }
  2851. //查询该订单不是采购入库的数据
  2852. list, _ := service.GetDrugSupplyWarehousingById(id, orgId)
  2853. if len(list) == 0 {
  2854. service.UpdateSupplyWarehousing(id, orgId)
  2855. }
  2856. goodList, _ := service.GetGoodSupplyWarehousingById(id, orgId)
  2857. if len(goodList) == 0 {
  2858. service.UpdateGoodWarehousing(id, orgId)
  2859. }
  2860. //删除药品入库单
  2861. service.UpdateDrugSupplyWarehousingInfo(id, orgId)
  2862. //删除入库流水
  2863. service.UpdateDrugSupplyFlow(id, orgId)
  2864. //删除耗材入库单
  2865. service.UpdateGoodSupplyWarehousingInfo(id, orgId)
  2866. //删除耗材入库流水
  2867. service.UpdateGoodSupplyFlow(id, orgId)
  2868. if err == nil {
  2869. this.ServeSuccessJSON(map[string]interface{}{
  2870. "cancelList": cancelList,
  2871. "purcaseOrder": purcaseOrder,
  2872. "goodOrder": goodOrder,
  2873. "drugList": drugList,
  2874. "msg": 1,
  2875. })
  2876. return
  2877. } else {
  2878. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2879. }
  2880. } else if errcode == nil {
  2881. this.ServeSuccessJSON(map[string]interface{}{
  2882. "cancelList": cancelList,
  2883. "purcaseOrder": purcaseOrder,
  2884. "goodOrder": goodOrder,
  2885. "drugList": drugList,
  2886. "msg": 2,
  2887. })
  2888. return
  2889. }
  2890. }
  2891. func (this *SupplyOrderApiController) UpdateSupplyWarehousing() {
  2892. warehousing_id, _ := this.GetInt64("warehousing_id")
  2893. orgId := this.GetAdminUserInfo().CurrentOrgId
  2894. err := service.UpdateSupplyWarehousingById(warehousing_id, orgId)
  2895. if err == nil {
  2896. returnData := make(map[string]interface{}, 0)
  2897. returnData["msg"] = "ok"
  2898. this.ServeSuccessJSON(returnData)
  2899. return
  2900. } else {
  2901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2902. }
  2903. }
  2904. func (this *SupplyOrderApiController) DeleteGoodOrder() {
  2905. id, _ := this.GetInt64("id")
  2906. orgId := this.GetAdminUserInfo().CurrentOrgId
  2907. err := service.DeleteGoodOrder(id, orgId)
  2908. if err == nil {
  2909. returnData := make(map[string]interface{}, 0)
  2910. returnData["msg"] = "ok"
  2911. this.ServeSuccessJSON(returnData)
  2912. return
  2913. } else {
  2914. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2915. }
  2916. }
  2917. func (this *SupplyOrderApiController) GetSupplyWarehouseById() {
  2918. id, _ := this.GetInt64("id")
  2919. orgId := this.GetAdminUserInfo().CurrentOrgId
  2920. //获取已有关联的退货单
  2921. cancelList, err := service.GetSupplyCancelWarehouse(id, orgId)
  2922. //获取采购单数据
  2923. outList, _ := service.GetGoodOrderListById(id, orgId)
  2924. //获取退货单数据
  2925. cancelOrderList, _ := service.GetGoodCanceListById(id, orgId)
  2926. //获取药品库数据
  2927. baseList, _ := service.GetSupplyDrugList(orgId)
  2928. if err == nil {
  2929. this.ServeSuccessJSON(map[string]interface{}{
  2930. "cancelList": cancelList,
  2931. "outList": outList,
  2932. "drugList": baseList,
  2933. "cancelOrderList": cancelOrderList,
  2934. })
  2935. } else {
  2936. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2937. }
  2938. }
  2939. func (this *SupplyOrderApiController) CheckGoodOrderById() {
  2940. id, _ := this.GetInt64("id")
  2941. recordDateStr := time.Now().Format("2006-01-02")
  2942. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2943. record_date := recordDate.Unix()
  2944. checker := this.GetAdminUserInfo().AdminUser.Id
  2945. out := models.SpSupplierWarehouseOut{
  2946. IsCheck: 1,
  2947. Checker: checker,
  2948. CheckTime: record_date,
  2949. }
  2950. err := service.UpdateSupplyGoodOrder(id, out)
  2951. if err == nil {
  2952. this.ServeSuccessJSON(map[string]interface{}{
  2953. "out": out,
  2954. })
  2955. } else {
  2956. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2957. }
  2958. }
  2959. func (this *SupplyOrderApiController) CheckReturnOrder() {
  2960. id, _ := this.GetInt64("id")
  2961. warehouse_out_id, _ := this.GetInt64("warehouse_out_id")
  2962. recordDateStr := time.Now().Format("2006-01-02")
  2963. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2964. orgId := this.GetAdminUserInfo().CurrentOrgId
  2965. record_date := recordDate.Unix()
  2966. checker := this.GetAdminUserInfo().AdminUser.Id
  2967. //获取退库单详情
  2968. list, _ := service.GetSupplyCancelOrderDetail(id, orgId)
  2969. for _, item := range list {
  2970. var total_count int64
  2971. var prescribing_number_total int64
  2972. //药品
  2973. if item.IsSource == 1 {
  2974. //获取药品库存
  2975. info, _ := service.GetDrugTotalCountTwenTy(item.ProjectId, item.SupplyWarehouseDetailInfo)
  2976. for _, it := range info {
  2977. if it.MaxUnit == it.CountUnit {
  2978. it.StockMaxNumber = it.StockMaxNumber * it.MinNumber
  2979. }
  2980. total_count += (it.StockMaxNumber + it.StockMinNumber)
  2981. }
  2982. //查询改药品信息
  2983. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  2984. //判断单位是否相等
  2985. if medical.MaxUnit == item.SupplyUnit {
  2986. //转化为最小单位
  2987. prescribing_number_total = item.SupplyCount * medical.MinNumber
  2988. }
  2989. if medical.MinUnit == item.SupplyUnit {
  2990. prescribing_number_total = item.SupplyCount
  2991. }
  2992. fmt.Println("hhhhhadf dafsdfsdfddddfdf", prescribing_number_total)
  2993. //判断单位
  2994. if total_count == 0 {
  2995. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  2996. this.ServeSuccessJSON(map[string]interface{}{
  2997. "msg": "3",
  2998. "drug_name": goodObj.DrugName,
  2999. "dose": goodObj.Dose,
  3000. "dose_unit": goodObj.DoseUnit,
  3001. "min_number": goodObj.MinNumber,
  3002. "min_unit": goodObj.MinUnit,
  3003. "max_unit": goodObj.MaxUnit,
  3004. })
  3005. return
  3006. }
  3007. if prescribing_number_total > total_count {
  3008. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  3009. this.ServeSuccessJSON(map[string]interface{}{
  3010. "msg": "3",
  3011. "drug_name": goodObj.DrugName,
  3012. "dose": goodObj.Dose,
  3013. "dose_unit": goodObj.DoseUnit,
  3014. "min_number": goodObj.MinNumber,
  3015. "min_unit": goodObj.MinUnit,
  3016. "max_unit": goodObj.MaxUnit,
  3017. })
  3018. return
  3019. }
  3020. ctime := time.Now().Unix()
  3021. timeStr := time.Now().Format("2006-01-02")
  3022. timeArr := strings.Split(timeStr, "-")
  3023. total, _ := service.FindAllDrugWarehouseOut(orgId)
  3024. total = total + 1
  3025. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3026. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3027. number = number + total
  3028. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  3029. //operation_time := time.Now().Unix()
  3030. creater := this.GetAdminUserInfo().AdminUser.Id
  3031. recordDateStr := time.Now().Format("2006-01-02")
  3032. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3033. orgId := this.GetAdminUserInfo().CurrentOrgId
  3034. record_date := recordDate.Unix()
  3035. warehouseOut := models.DrugWarehouseOut{
  3036. WarehouseOutOrderNumber: warehousing_out_order,
  3037. OperationTime: record_date,
  3038. OrgId: orgId,
  3039. Creater: creater,
  3040. Ctime: ctime,
  3041. Status: 1,
  3042. WarehouseOutTime: record_date,
  3043. Type: 1,
  3044. SupplyCancelOutId: id,
  3045. SupplyWarehouseId: warehouse_out_id,
  3046. }
  3047. // 查询今日是否存在出库单
  3048. _, errcodes := service.GetDrugWarehouseOutById(orgId, record_date)
  3049. if errcodes == gorm.ErrRecordNotFound {
  3050. service.AddSigleDrugWarehouseOut(&warehouseOut)
  3051. }
  3052. lastDrug, _ := service.GetLastDrugWarehouseById(orgId, record_date)
  3053. //获取
  3054. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  3055. WarehouseOutOrderNumber: lastDrug.WarehouseOutOrderNumber,
  3056. WarehouseOutId: lastDrug.ID,
  3057. DrugId: item.ProjectId,
  3058. Count: item.SupplyCount,
  3059. Price: item.Price,
  3060. Status: 1,
  3061. Ctime: ctime,
  3062. Remark: "",
  3063. OrgId: orgId,
  3064. Type: 1,
  3065. Manufacturer: item.ManufacturerId,
  3066. Dealer: 0,
  3067. CountUnit: item.SupplyUnit,
  3068. ExpiryDate: item.SupplyExpiryDate,
  3069. ProductDate: item.SupplyProductDate,
  3070. Number: item.SupplyLicenseNumber,
  3071. BatchNumber: item.SupplyBatchNumber,
  3072. IsSys: 0,
  3073. WarehouseInfoId: 0,
  3074. SupplyCancelOutId: id,
  3075. SupplyWarehouseId: warehouse_out_id,
  3076. SysRecordTime: record_date,
  3077. }
  3078. drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
  3079. if drup.ID > 0 {
  3080. prescribingNumber := item.SupplyCount
  3081. service.AutoDrugDeliverInfoNight(orgId, prescribingNumber, &warehouseOut, &drup, warehouseOutInfo)
  3082. }
  3083. //修改原数据
  3084. /* orderInfo := models.SpSupplierWarehousingCancelOrder{
  3085. SourceCount: item.SupplyCount - item.SourceCount,
  3086. }
  3087. service.UpdateSupplyCancelById(item.ID, orderInfo)*/
  3088. }
  3089. //耗材
  3090. if item.IsSource == 2 {
  3091. // 查询该耗材是否有库存
  3092. warehouseOne, _ := service.FindWarehousingInfoTwenTy(item.ProjectId, item.SupplyWarehouseDetailInfo)
  3093. // 如果出库数量大于该批次剩余库存数量
  3094. if item.SupplyCount > warehouseOne.StockCount {
  3095. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  3096. this.ServeSuccessJSON(map[string]interface{}{
  3097. "msg": "2",
  3098. "good_name": goodObj.GoodName,
  3099. "specification_name": goodObj.SpecificationName,
  3100. })
  3101. return
  3102. }
  3103. ctime := time.Now().Unix()
  3104. timeStr := time.Now().Format("2006-01-02")
  3105. timeArr := strings.Split(timeStr, "-")
  3106. total, _ := service.FindAllWarehouseOut(orgId)
  3107. total = total + 1
  3108. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3109. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3110. number = number + total
  3111. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3112. operation_time := time.Now().Unix()
  3113. creater := this.GetAdminUserInfo().AdminUser.Id
  3114. recordDateStr := time.Now().Format("2006-01-02")
  3115. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3116. record_date := recordDate.Unix()
  3117. warehouseOut := models.WarehouseOut{
  3118. WarehouseOutOrderNumber: warehousing_out_order,
  3119. OperationTime: record_date,
  3120. OrgId: orgId,
  3121. Creater: creater,
  3122. Ctime: ctime,
  3123. Status: 1,
  3124. WarehouseOutTime: record_date,
  3125. Type: 1,
  3126. SupplyCancelOutId: id,
  3127. SupplyWarehouseId: warehouse_out_id,
  3128. IsSys: 0,
  3129. }
  3130. //查询是否生成出库单
  3131. _, errcodes := service.FindStockOutByIsSys(orgId, 0, operation_time)
  3132. if errcodes == gorm.ErrRecordNotFound {
  3133. service.AddSigleWarehouseOut(&warehouseOut)
  3134. }
  3135. outWarehouse, _ := service.GetlastWarehouseOutById(orgId, record_date)
  3136. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  3137. info := &models.WarehouseOutInfo{
  3138. WarehouseOutOrderNumber: outWarehouse.WarehouseOutOrderNumber,
  3139. WarehouseOutId: outWarehouse.ID,
  3140. WarehouseInfotId: 0,
  3141. GoodId: item.ProjectId,
  3142. GoodTypeId: goodObj.GoodTypeId,
  3143. Count: item.SupplyCount,
  3144. Price: item.Price,
  3145. TotalPrice: 0,
  3146. ProductDate: item.SupplyProductDate,
  3147. ExpiryDate: item.SupplyExpiryDate,
  3148. Type: 0,
  3149. Dealer: 0,
  3150. Manufacturer: item.ManufacturerId,
  3151. IsSys: 0,
  3152. SysRecordTime: record_date,
  3153. Number: item.SupplyBatchNumber,
  3154. LicenseNumber: item.SupplyLicenseNumber,
  3155. ConsumableType: 0,
  3156. SupplyCancelOutId: id,
  3157. OrgId: orgId,
  3158. SupplyWarehouseId: warehouse_out_id,
  3159. }
  3160. //出库逻辑
  3161. parseDateErr := service.ConsumablesDeliveryNight(orgId, record_date, info, &warehouseOut, item.SupplyCount, creater, warehouse_out_id, id)
  3162. if parseDateErr != nil {
  3163. utils.ErrorLog(parseDateErr.Error())
  3164. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  3165. return
  3166. }
  3167. //更改原退库数据
  3168. //order := models.SpSupplierWarehousingCancelOrder{
  3169. // SourceCount: item.SourceCount - item.SupplyCount,
  3170. //}
  3171. //service.UpdateSupplyCancelById(item.ID, order)
  3172. }
  3173. }
  3174. cancel := models.SpSupplierWarehouseCancel{
  3175. IsCheck: 1,
  3176. Checker: checker,
  3177. CheckTime: record_date,
  3178. }
  3179. err := service.CheckReturnOrder(id, orgId, cancel)
  3180. if err == nil {
  3181. this.ServeSuccessJSON(map[string]interface{}{
  3182. "msg": "1",
  3183. "drug_name": "",
  3184. "dose": "",
  3185. "dose_unit": "",
  3186. "min_number": "",
  3187. "min_unit": "",
  3188. "max_unit": "",
  3189. })
  3190. return
  3191. }
  3192. }
  3193. func (this *SupplyOrderApiController) DeletePurchaseOrder() {
  3194. id, _ := this.GetInt64("id")
  3195. err := service.DeletePurchaseOrder(id)
  3196. if err == nil {
  3197. returnData := make(map[string]interface{}, 0)
  3198. returnData["msg"] = "ok"
  3199. this.ServeSuccessJSON(returnData)
  3200. return
  3201. } else {
  3202. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3203. }
  3204. }
  3205. func (this *SupplyOrderApiController) DeleteGoodOrderById() {
  3206. id, _ := this.GetInt64("id")
  3207. err := service.DeleteGoodOrderById(id)
  3208. if err == nil {
  3209. returnData := make(map[string]interface{}, 0)
  3210. returnData["msg"] = "ok"
  3211. this.ServeSuccessJSON(returnData)
  3212. return
  3213. } else {
  3214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3215. }
  3216. }
  3217. func (this *SupplyOrderApiController) DeleteReturnOrder() {
  3218. id, _ := this.GetInt64("id")
  3219. err := service.DeleteReturnOrder(id)
  3220. if err == nil {
  3221. returnData := make(map[string]interface{}, 0)
  3222. returnData["msg"] = "ok"
  3223. this.ServeSuccessJSON(returnData)
  3224. return
  3225. } else {
  3226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3227. }
  3228. }
  3229. func (this *SupplyOrderApiController) DeleteReturnOrderById() {
  3230. id, _ := this.GetInt64("id")
  3231. err := service.DeleteReturnOrderById(id)
  3232. if err == nil {
  3233. returnData := make(map[string]interface{}, 0)
  3234. returnData["msg"] = "ok"
  3235. this.ServeSuccessJSON(returnData)
  3236. return
  3237. } else {
  3238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3239. }
  3240. }
  3241. func (this *SupplyOrderApiController) ModefyReturnOrder() {
  3242. id, _ := this.GetInt64("id")
  3243. err := service.ModefyReturnOrder(id)
  3244. //获取退库单据日期
  3245. cancel, _ := service.GetReturnOrderById(id)
  3246. orgId := this.GetAdminUserInfo().CurrentOrgId
  3247. if err == nil {
  3248. //获取退库单详情
  3249. list, _ := service.GetSupplyCancelOrderDetail(id, orgId)
  3250. for _, item := range list {
  3251. //药品
  3252. if item.IsSource == 1 {
  3253. base, _ := service.GetDrugDetailByDrugId(item.ProjectId)
  3254. //更改库存
  3255. if item.SupplyUnit == base.MaxUnit {
  3256. //退库
  3257. drugInfo := models.DrugWarehouseInfo{
  3258. StockMaxNumber: item.SupplyCount,
  3259. }
  3260. service.UpdateDrugWasehousring(item.ProjectId, item.SupplyWarehouseDetailInfo, drugInfo)
  3261. }
  3262. if item.SupplyType == base.MinUnit && base.MaxUnit != base.MinUnit {
  3263. drugInfo := models.DrugWarehouseInfo{
  3264. StockMinNumber: item.SupplyCount,
  3265. }
  3266. service.UpdateDrugWasehousringOne(item.ProjectId, item.SupplyWarehouseDetailInfo, drugInfo)
  3267. }
  3268. //删除流水
  3269. service.DeleteDrugWarehouseOutNight(item.ProjectId, item.WarehouseCancelId)
  3270. //查询出库订单
  3271. drugOut, _ := service.GetDrugWarehouseByDate(cancel.RecordDate, orgId)
  3272. drugOutList, _ := service.GetDrugWarehouseByIdList(drugOut.ID, orgId)
  3273. if len(drugOutList) == 0 {
  3274. service.UpdateDrugWarehouseById(drugOut.ID)
  3275. }
  3276. }
  3277. //耗材
  3278. if item.IsSource == 2 {
  3279. fmt.Println("item2332322323232332", item.SupplyCount)
  3280. //退库
  3281. info := models.WarehousingInfo{
  3282. StockCount: item.SupplyCount,
  3283. }
  3284. //更改库存
  3285. err := service.UpdateWarehousingInfoById(item.ProjectId, item.SupplyWarehouseDetailInfo, info)
  3286. fmt.Println(err)
  3287. //删除出库记录
  3288. service.DeleteGoodWarehouseOut(item.ProjectId, item.WarehouseCancelId, orgId)
  3289. //查询今日的出库单是
  3290. out, _ := service.GetWarehouseOutByDate(cancel.RecordDate, orgId)
  3291. warehouseOutList, _ := service.GetWarehouseOutById(out.ID, orgId)
  3292. if len(warehouseOutList) == 0 {
  3293. //删除出库单
  3294. service.DeleteWarehouseOutById(out.ID)
  3295. }
  3296. }
  3297. }
  3298. } else {
  3299. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3300. }
  3301. if err == nil {
  3302. returnData := make(map[string]interface{}, 0)
  3303. returnData["msg"] = "ok"
  3304. this.ServeSuccessJSON(returnData)
  3305. return
  3306. } else {
  3307. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3308. }
  3309. }
  3310. func (this *SupplyOrderApiController) GetGoodOrderDetailList() {
  3311. id, _ := this.GetInt64("id")
  3312. ids := this.GetString("ids")
  3313. orgId := this.GetAdminUserInfo().CurrentOrgId
  3314. if len(ids) == 0 {
  3315. out, err := service.GetGoodOrderDetail(id, orgId)
  3316. list, _ := service.GetSupplyWarehouseOutById(id, orgId)
  3317. for _, item := range list {
  3318. if item.IsSource == 1 {
  3319. waresingList, _ := service.GetAllDrugWaresingList(item.ProjectId, orgId)
  3320. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  3321. item.DrugWarehouseInfo = waresingList
  3322. item.SpBaseDrug = medical
  3323. }
  3324. if item.IsSource == 2 {
  3325. waresingList, _ := service.GetAllGoodWaresingList(item.ProjectId, orgId)
  3326. item.GoodWarehouseInfo = waresingList
  3327. }
  3328. }
  3329. drugList, _ := service.GetSupplyDrugList(orgId)
  3330. goodList, _ := service.GetSupplyGoodList(orgId)
  3331. supplyList, _ := service.GetSupplierList(orgId)
  3332. if err == nil {
  3333. this.ServeSuccessJSON(map[string]interface{}{
  3334. "out": out,
  3335. "list": list,
  3336. "goodList": goodList,
  3337. "drugList": drugList,
  3338. "supplyList": supplyList,
  3339. })
  3340. } else {
  3341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3342. }
  3343. }
  3344. if len(ids) > 0 {
  3345. idArray := strings.Split(ids, ",")
  3346. out, err := service.GetGoodOrderDetail(id, orgId)
  3347. list, _ := service.GetSupplyWarehouseOutByIdOne(id, orgId, idArray)
  3348. for _, item := range list {
  3349. if item.IsSource == 1 {
  3350. waresingList, _ := service.GetAllDrugWaresingList(item.ProjectId, orgId)
  3351. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  3352. item.DrugWarehouseInfo = waresingList
  3353. item.SpBaseDrug = medical
  3354. }
  3355. if item.IsSource == 2 {
  3356. waresingList, _ := service.GetAllGoodWaresingList(item.ProjectId, orgId)
  3357. item.GoodWarehouseInfo = waresingList
  3358. }
  3359. }
  3360. drugList, _ := service.GetSupplyDrugList(orgId)
  3361. goodList, _ := service.GetSupplyGoodList(orgId)
  3362. supplyList, _ := service.GetSupplierList(orgId)
  3363. if err == nil {
  3364. this.ServeSuccessJSON(map[string]interface{}{
  3365. "out": out,
  3366. "list": list,
  3367. "goodList": goodList,
  3368. "drugList": drugList,
  3369. "supplyList": supplyList,
  3370. })
  3371. } else {
  3372. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3373. }
  3374. }
  3375. }