supply_order_api_contorller.go 128KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749
  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. //查询
  1124. orderInfo, _ := service.GetSupplyWarehousingOrderInfo(warehousing_id)
  1125. this.ServeSuccessJSON(map[string]interface{}{
  1126. "warehousingInfo": warehousingInfo,
  1127. "orderInfo": orderInfo,
  1128. })
  1129. }
  1130. }
  1131. func (this *SupplyOrderApiController) UpdateSupplyWaresing() {
  1132. id, _ := this.GetInt64("id")
  1133. recordDateStr := time.Now().Format("2006-01-02")
  1134. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1135. record_date := recordDate.Unix()
  1136. checker := this.GetAdminUserInfo().AdminUser.Id
  1137. info := models.SupplierWarehouseInfo{
  1138. Mtime: time.Now().Unix(),
  1139. Status: 1,
  1140. IsCheck: 1,
  1141. Checker: checker,
  1142. CheckTime: record_date,
  1143. }
  1144. parseDateErr := service.UpdateSupplyWaresing(id, info)
  1145. if parseDateErr == nil {
  1146. this.ServeSuccessJSON(map[string]interface{}{
  1147. "info": info,
  1148. })
  1149. } else {
  1150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1151. }
  1152. }
  1153. func (this *SupplyOrderApiController) GetPurchaseOrderDetail() {
  1154. id, _ := this.GetInt64("id")
  1155. info, _ := service.GetPurchaseOrderDetail(id)
  1156. //查询
  1157. orderInfo, err := service.GetSupplyWarehousingOrderInfo(id)
  1158. orgId := this.GetAdminUserInfo().CurrentOrgId
  1159. supplyList, _ := service.GetSupplierList(orgId)
  1160. //获取药品库数据
  1161. baseList, _ := service.GetSupplyDrugList(orgId)
  1162. goodList, _ := service.GetSupplyGoodList(orgId)
  1163. if err == nil {
  1164. this.ServeSuccessJSON(map[string]interface{}{
  1165. "info": info,
  1166. "orderInfo": orderInfo,
  1167. "supplyList": supplyList,
  1168. "baseList": baseList,
  1169. "goodList": goodList,
  1170. })
  1171. } else {
  1172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1173. }
  1174. }
  1175. func (this *SupplyOrderApiController) AddGoodOrder() {
  1176. dataBody := make(map[string]interface{}, 0)
  1177. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1178. if err != nil {
  1179. utils.ErrorLog(err.Error())
  1180. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1181. return
  1182. }
  1183. supplier_id, _ := this.GetInt64("supplier_id")
  1184. start_time := this.GetString("start")
  1185. timeLayout := "2006-01-02"
  1186. loc, _ := time.LoadLocation("Local")
  1187. var startTime int64
  1188. if len(start_time) > 0 {
  1189. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1190. if err != nil {
  1191. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1192. return
  1193. }
  1194. startTime = theTime.Unix()
  1195. }
  1196. arrerage := this.GetString("arrerage")
  1197. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  1198. payment := this.GetString("payment")
  1199. payment_float, _ := strconv.ParseFloat(payment, 64)
  1200. warehousing_id, _ := this.GetInt64("warehousing_id")
  1201. number := this.GetString("number")
  1202. rate_of_concession := this.GetString("rate_of_concession")
  1203. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  1204. discount_amount := this.GetString("discount_amount")
  1205. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  1206. return_remake := dataBody["return_remake"].(string)
  1207. orgId := this.GetAdminUserInfo().CurrentOrgId
  1208. creater := this.GetAdminUserInfo().AdminUser.Id
  1209. //生成购货单
  1210. timeStr := time.Now().Format("2006-01-02")
  1211. timeArr := strings.Split(timeStr, "-")
  1212. total, _ := service.FindAllSupplyWarehouseOutOrder(orgId)
  1213. total = total + 1
  1214. warehousing_order := "CG" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  1215. recordDateStr := time.Now().Format("2006-01-02")
  1216. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1217. warehouse_out := models.SpSupplierWarehouseOut{
  1218. Number: number,
  1219. UserOrgId: orgId,
  1220. Creater: creater,
  1221. Ctime: time.Now().Unix(),
  1222. Mtime: 0,
  1223. Status: 1,
  1224. RecordDate: recordDate.Unix(),
  1225. IsCheck: 2,
  1226. WarehousingId: warehousing_id,
  1227. GoodNumber: warehousing_order,
  1228. Arrearage: arrerage_float,
  1229. Payment: payment_float,
  1230. RateOfConcession: rate_of_concession_float,
  1231. DiscountAmount: discount_amount_float,
  1232. DocumentDate: startTime,
  1233. SupplierId: supplier_id,
  1234. Checker: 0,
  1235. CheckTime: 0,
  1236. ReturnRemake: return_remake,
  1237. }
  1238. service.CreateSupplyWarehouseOut(warehouse_out)
  1239. //获取最后一条
  1240. warehouseOut, _ := service.FindSupplyWarehouseOutById(orgId)
  1241. var warehousingOut []*models.SpSupplierWarehousingOutOrder
  1242. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  1243. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  1244. if len(thisStockIn) > 0 {
  1245. for _, item := range thisStockIn {
  1246. items := item.(map[string]interface{})
  1247. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  1248. utils.ErrorLog("supply_count")
  1249. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1250. return
  1251. }
  1252. supply_count := int64(items["supply_count"].(float64))
  1253. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1254. utils.ErrorLog("id")
  1255. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. id := int64(items["id"].(float64))
  1259. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  1260. utils.ErrorLog("manufacturer_id")
  1261. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1262. return
  1263. }
  1264. manufacturer_id := int64(items["manufacturer_id"].(float64))
  1265. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1266. utils.ErrorLog("name")
  1267. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1268. return
  1269. }
  1270. name := items["name"].(string)
  1271. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  1272. utils.ErrorLog("order_number")
  1273. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1274. return
  1275. }
  1276. order_number := items["order_number"].(string)
  1277. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  1278. utils.ErrorLog("supply_price")
  1279. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1280. return
  1281. }
  1282. supply_price := items["supply_price"].(string)
  1283. price_float, _ := strconv.ParseFloat(supply_price, 64)
  1284. if items["min_price"] == nil || reflect.TypeOf(items["min_price"]).String() != "string" {
  1285. utils.ErrorLog("min_price")
  1286. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1287. return
  1288. }
  1289. min_price := items["min_price"].(string)
  1290. min_price_float, _ := strconv.ParseFloat(min_price, 64)
  1291. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  1292. utils.ErrorLog("supply_total_price")
  1293. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1294. return
  1295. }
  1296. supply_total_price := items["supply_total_price"].(string)
  1297. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  1298. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  1299. utils.ErrorLog("project_id")
  1300. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1301. return
  1302. }
  1303. project_id := int64(items["project_id"].(float64))
  1304. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  1305. utils.ErrorLog("supply_remake")
  1306. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1307. return
  1308. }
  1309. supply_remake := items["supply_remake"].(string)
  1310. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  1311. utils.ErrorLog("supply_batch_number")
  1312. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1313. return
  1314. }
  1315. supply_batch_number := items["supply_batch_number"].(string)
  1316. var supply_expiry_date_time int64
  1317. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "string" {
  1318. utils.ErrorLog("supply_expiry_date")
  1319. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1320. return
  1321. }
  1322. supply_expiry_date := items["supply_expiry_date"].(string)
  1323. if len(supply_expiry_date) > 0 {
  1324. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_expiry_date+" 00:00:00", loc)
  1325. if err != nil {
  1326. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1327. return
  1328. }
  1329. supply_expiry_date_time = theTime.Unix()
  1330. }
  1331. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  1332. utils.ErrorLog("supply_license_number")
  1333. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1334. return
  1335. }
  1336. supply_license_number := items["supply_license_number"].(string)
  1337. var supply_product_date_time int64
  1338. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "string" {
  1339. utils.ErrorLog("supply_product_date")
  1340. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1341. return
  1342. }
  1343. supply_product_date := items["supply_product_date"].(string)
  1344. if len(supply_product_date) > 0 {
  1345. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_product_date+" 00:00:00", loc)
  1346. if err != nil {
  1347. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1348. return
  1349. }
  1350. supply_product_date_time = theTime.Unix()
  1351. }
  1352. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  1353. utils.ErrorLog("supply_specification_name")
  1354. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1355. return
  1356. }
  1357. supply_specification_name := items["supply_specification_name"].(string)
  1358. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  1359. utils.ErrorLog("supply_total")
  1360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1361. return
  1362. }
  1363. supply_total := items["supply_total"].(string)
  1364. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  1365. utils.ErrorLog("supply_type")
  1366. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1367. return
  1368. }
  1369. supply_type := items["supply_type"].(string)
  1370. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  1371. utils.ErrorLog("supply_unit")
  1372. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1373. return
  1374. }
  1375. supply_unit := items["supply_unit"].(string)
  1376. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1377. utils.ErrorLog("type")
  1378. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1379. return
  1380. }
  1381. is_source := int64(items["type"].(float64))
  1382. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  1383. utils.ErrorLog("supply_manufacturer")
  1384. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1385. return
  1386. }
  1387. supply_manufacturer := items["supply_manufacturer"].(string)
  1388. order := models.SpSupplierWarehousingOutOrder{
  1389. OrderNumber: order_number,
  1390. ProjectId: project_id,
  1391. IsSource: is_source,
  1392. Count: supply_count,
  1393. Amount: supply_total_price_float,
  1394. Price: price_float,
  1395. Remark: supply_remake,
  1396. IsCheck: 2,
  1397. UserOrgId: orgId,
  1398. Status: 1,
  1399. Ctime: time.Now().Unix(),
  1400. Mtime: 0,
  1401. WarehouseOutId: warehouseOut.ID,
  1402. Type: 1,
  1403. SupplyBatchNumber: supply_batch_number,
  1404. SupplyProductDate: supply_product_date_time,
  1405. SupplyExpiryDate: supply_expiry_date_time,
  1406. WarehousingId: warehousing_id,
  1407. WarehouseInfoId: id,
  1408. SupplyType: supply_type,
  1409. SupplyUnit: supply_unit,
  1410. SupplyTotal: supply_total,
  1411. SupplySpecificationName: supply_specification_name,
  1412. SupplyLicenseNumber: supply_license_number,
  1413. Name: name,
  1414. ManufacturerId: manufacturer_id,
  1415. GoodNumber: warehouseOut.GoodNumber,
  1416. SupplyManufacturer: supply_manufacturer,
  1417. MinPrice: min_price_float,
  1418. IsWarehosue: 2,
  1419. }
  1420. warehousingOut = append(warehousingOut, &order)
  1421. }
  1422. }
  1423. }
  1424. for _, item := range warehousingOut {
  1425. //如果是手动新增的,type 等于2
  1426. if item.WarehouseInfoId == 0 {
  1427. item.Type = 2
  1428. service.CreateSupplyWarehousOutOrder(item)
  1429. }
  1430. if item.WarehouseInfoId > 0 {
  1431. //查询该商品是否来源于采购订单,如果存在则关联, 如果不存在则取消关联
  1432. _, errcode := service.GetGoodIsSource(warehousing_id, item.ProjectId, orgId)
  1433. if errcode == gorm.ErrRecordNotFound {
  1434. item.WarehousingId = 0
  1435. item.WarehouseInfoId = 0
  1436. item.OrderNumber = ""
  1437. item.Type = 2
  1438. err = service.CreateSupplyWarehousOutOrder(item)
  1439. //更新采购单
  1440. service.ModfySupplyWarehouseOut(warehousing_id, orgId)
  1441. }
  1442. if errcode == nil {
  1443. err = service.CreateSupplyWarehousOutOrder(item)
  1444. }
  1445. }
  1446. }
  1447. list, parseDateErr := service.GetSupplyWarehouseOutById(warehouseOut.ID, orgId)
  1448. if parseDateErr == nil {
  1449. this.ServeSuccessJSON(map[string]interface{}{
  1450. "list": list,
  1451. "warehouseOut": warehouseOut,
  1452. })
  1453. } else {
  1454. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1455. }
  1456. }
  1457. func (this *SupplyOrderApiController) GetAllGoodOderList() {
  1458. check_id, _ := this.GetInt64("check_id")
  1459. start_time := this.GetString("start_time")
  1460. end_time := this.GetString("end_time")
  1461. keyword := this.GetString("keyword")
  1462. page, _ := this.GetInt64("page")
  1463. limit, _ := this.GetInt64("limit")
  1464. timeLayout := "2006-01-02"
  1465. loc, _ := time.LoadLocation("Local")
  1466. var startTime int64
  1467. if len(start_time) > 0 {
  1468. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1469. if err != nil {
  1470. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1471. return
  1472. }
  1473. startTime = theTime.Unix()
  1474. }
  1475. var endTime int64
  1476. if len(end_time) > 0 {
  1477. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1478. if err != nil {
  1479. utils.ErrorLog(err.Error())
  1480. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1481. return
  1482. }
  1483. endTime = theTime.Unix()
  1484. }
  1485. orgId := this.GetAdminUserInfo().CurrentOrgId
  1486. list, total, err := service.GetAllGoodOderList(check_id, keyword, page, limit, startTime, endTime, orgId)
  1487. if err == nil {
  1488. this.ServeSuccessJSON(map[string]interface{}{
  1489. "list": list,
  1490. "total": total,
  1491. })
  1492. } else {
  1493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1494. }
  1495. }
  1496. func (this *SupplyOrderApiController) GetGoodOrderDetail() {
  1497. id, _ := this.GetInt64("id")
  1498. ids := this.GetString("ids")
  1499. orgId := this.GetAdminUserInfo().CurrentOrgId
  1500. if len(ids) == 0 {
  1501. out, err := service.GetGoodOrderDetail(id, orgId)
  1502. list, _ := service.GetSupplyWarehouseOutById(id, orgId)
  1503. for _, item := range list {
  1504. if item.IsSource == 1 {
  1505. waresingList, _ := service.GetAllDrugWaresingList(item.ProjectId, orgId)
  1506. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1507. item.DrugWarehouseInfo = waresingList
  1508. item.SpBaseDrug = medical
  1509. }
  1510. if item.IsSource == 2 {
  1511. waresingList, _ := service.GetAllGoodWaresingList(item.ProjectId, orgId)
  1512. item.GoodWarehouseInfo = waresingList
  1513. }
  1514. }
  1515. drugList, _ := service.GetSupplyDrugList(orgId)
  1516. goodList, _ := service.GetSupplyGoodList(orgId)
  1517. supplyList, _ := service.GetSupplierList(orgId)
  1518. if err == nil {
  1519. this.ServeSuccessJSON(map[string]interface{}{
  1520. "out": out,
  1521. "list": list,
  1522. "goodList": goodList,
  1523. "drugList": drugList,
  1524. "supplyList": supplyList,
  1525. })
  1526. } else {
  1527. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1528. }
  1529. }
  1530. if len(ids) > 0 {
  1531. idArray := strings.Split(ids, ",")
  1532. out, err := service.GetGoodOrderDetail(id, orgId)
  1533. list, _ := service.GetSupplyWarehouseOutByIdOne(id, orgId, idArray)
  1534. for _, item := range list {
  1535. if item.IsSource == 1 {
  1536. waresingList, _ := service.GetAllDrugWaresingList(item.ProjectId, orgId)
  1537. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1538. item.DrugWarehouseInfo = waresingList
  1539. item.SpBaseDrug = medical
  1540. }
  1541. if item.IsSource == 2 {
  1542. waresingList, _ := service.GetAllGoodWaresingList(item.ProjectId, orgId)
  1543. item.GoodWarehouseInfo = waresingList
  1544. }
  1545. }
  1546. drugList, _ := service.GetSupplyDrugList(orgId)
  1547. goodList, _ := service.GetSupplyGoodList(orgId)
  1548. supplyList, _ := service.GetSupplierList(orgId)
  1549. if err == nil {
  1550. this.ServeSuccessJSON(map[string]interface{}{
  1551. "out": out,
  1552. "list": list,
  1553. "goodList": goodList,
  1554. "drugList": drugList,
  1555. "supplyList": supplyList,
  1556. })
  1557. } else {
  1558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1559. }
  1560. }
  1561. }
  1562. func (this *SupplyOrderApiController) UpdateGoodOrder() {
  1563. supplier_id, _ := this.GetInt64("supplier_id")
  1564. start_time := this.GetString("start")
  1565. timeLayout := "2006-01-02"
  1566. loc, _ := time.LoadLocation("Local")
  1567. var startTime int64
  1568. if len(start_time) > 0 {
  1569. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1570. if err != nil {
  1571. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1572. return
  1573. }
  1574. startTime = theTime.Unix()
  1575. }
  1576. arrerage := this.GetString("arrerage")
  1577. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  1578. payment := this.GetString("payment")
  1579. payment_float, _ := strconv.ParseFloat(payment, 64)
  1580. warehose_out_id, _ := this.GetInt64("warehose_out_id")
  1581. number := this.GetString("number")
  1582. rate_of_concession := this.GetString("rate_of_concession")
  1583. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  1584. discount_amount := this.GetString("discount_amount")
  1585. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  1586. good_number := this.GetString("good_number")
  1587. fmt.Println(supplier_id, startTime, arrerage, payment, warehose_out_id, number, rate_of_concession, discount_amount)
  1588. orgId := this.GetAdminUserInfo().CurrentOrgId
  1589. dataBody := make(map[string]interface{}, 0)
  1590. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1591. if err != nil {
  1592. utils.ErrorLog(err.Error())
  1593. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1594. return
  1595. }
  1596. var warehousingOut []*models.SpSupplierWarehousingOutOrder
  1597. var updateWarehout []*models.SpSupplierWarehousingOutOrder
  1598. return_remake := dataBody["return_remake"].(string)
  1599. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  1600. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  1601. if len(thisStockIn) > 0 {
  1602. for _, item := range thisStockIn {
  1603. items := item.(map[string]interface{})
  1604. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1605. utils.ErrorLog("id")
  1606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1607. return
  1608. }
  1609. id := int64(items["id"].(float64))
  1610. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  1611. utils.ErrorLog("supply_count")
  1612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1613. return
  1614. }
  1615. supply_count := int64(items["supply_count"].(float64))
  1616. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  1617. utils.ErrorLog("manufacturer_id")
  1618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1619. return
  1620. }
  1621. manufacturer_id := int64(items["manufacturer_id"].(float64))
  1622. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1623. utils.ErrorLog("name")
  1624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1625. return
  1626. }
  1627. name := items["name"].(string)
  1628. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  1629. utils.ErrorLog("order_number")
  1630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1631. return
  1632. }
  1633. order_number := items["order_number"].(string)
  1634. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  1635. utils.ErrorLog("supply_price")
  1636. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1637. return
  1638. }
  1639. supply_price := items["supply_price"].(string)
  1640. price_float, _ := strconv.ParseFloat(supply_price, 64)
  1641. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  1642. utils.ErrorLog("supply_total_price")
  1643. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1644. return
  1645. }
  1646. supply_total_price := items["supply_total_price"].(string)
  1647. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  1648. if items["min_price"] == nil || reflect.TypeOf(items["min_price"]).String() != "string" {
  1649. utils.ErrorLog("min_price")
  1650. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1651. return
  1652. }
  1653. min_price := items["min_price"].(string)
  1654. min_price_float, _ := strconv.ParseFloat(min_price, 64)
  1655. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  1656. utils.ErrorLog("project_id")
  1657. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1658. return
  1659. }
  1660. project_id := int64(items["project_id"].(float64))
  1661. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  1662. utils.ErrorLog("supply_remake")
  1663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1664. return
  1665. }
  1666. supply_remake := items["supply_remake"].(string)
  1667. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  1668. utils.ErrorLog("supply_batch_number")
  1669. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1670. return
  1671. }
  1672. supply_batch_number := items["supply_batch_number"].(string)
  1673. var supply_expiry_date_time int64
  1674. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "string" {
  1675. utils.ErrorLog("supply_expiry_date")
  1676. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1677. return
  1678. }
  1679. supply_expiry_date := items["supply_expiry_date"].(string)
  1680. if len(supply_expiry_date) > 0 {
  1681. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_expiry_date+" 00:00:00", loc)
  1682. if err != nil {
  1683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1684. return
  1685. }
  1686. supply_expiry_date_time = theTime.Unix()
  1687. }
  1688. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  1689. utils.ErrorLog("supply_license_number")
  1690. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1691. return
  1692. }
  1693. supply_license_number := items["supply_license_number"].(string)
  1694. var supply_product_date_time int64
  1695. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "string" {
  1696. utils.ErrorLog("supply_product_date")
  1697. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1698. return
  1699. }
  1700. supply_product_date := items["supply_product_date"].(string)
  1701. if len(supply_product_date) > 0 {
  1702. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_product_date+" 00:00:00", loc)
  1703. if err != nil {
  1704. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1705. return
  1706. }
  1707. supply_product_date_time = theTime.Unix()
  1708. }
  1709. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  1710. utils.ErrorLog("supply_specification_name")
  1711. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1712. return
  1713. }
  1714. supply_specification_name := items["supply_specification_name"].(string)
  1715. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  1716. utils.ErrorLog("supply_total")
  1717. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1718. return
  1719. }
  1720. supply_total := items["supply_total"].(string)
  1721. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  1722. utils.ErrorLog("supply_type")
  1723. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1724. return
  1725. }
  1726. supply_type := items["supply_type"].(string)
  1727. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  1728. utils.ErrorLog("supply_unit")
  1729. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1730. return
  1731. }
  1732. supply_unit := items["supply_unit"].(string)
  1733. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1734. utils.ErrorLog("type")
  1735. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1736. return
  1737. }
  1738. is_source := int64(items["type"].(float64))
  1739. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  1740. utils.ErrorLog("supply_manufacturer")
  1741. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1742. return
  1743. }
  1744. supply_manufacturer := items["supply_manufacturer"].(string)
  1745. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  1746. utils.ErrorLog("warehouse_info_id")
  1747. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1748. return
  1749. }
  1750. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1751. if items["warehousing_id"] == nil || reflect.TypeOf(items["warehousing_id"]).String() != "float64" {
  1752. utils.ErrorLog("warehousing_id")
  1753. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1754. return
  1755. }
  1756. warehousing_id := int64(items["warehousing_id"].(float64))
  1757. if id > 0 {
  1758. order := models.SpSupplierWarehousingOutOrder{
  1759. ID: id,
  1760. OrderNumber: order_number,
  1761. ProjectId: project_id,
  1762. IsSource: is_source,
  1763. Count: supply_count,
  1764. Amount: supply_total_price_float,
  1765. Price: price_float,
  1766. Remark: supply_remake,
  1767. IsCheck: 2,
  1768. UserOrgId: orgId,
  1769. Status: 1,
  1770. Ctime: time.Now().Unix(),
  1771. Mtime: 0,
  1772. WarehouseOutId: warehose_out_id,
  1773. Type: 1,
  1774. SupplyBatchNumber: supply_batch_number,
  1775. SupplyProductDate: supply_product_date_time,
  1776. SupplyExpiryDate: supply_expiry_date_time,
  1777. SupplyType: supply_type,
  1778. SupplyUnit: supply_unit,
  1779. SupplyTotal: supply_total,
  1780. SupplySpecificationName: supply_specification_name,
  1781. SupplyLicenseNumber: supply_license_number,
  1782. Name: name,
  1783. ManufacturerId: manufacturer_id,
  1784. GoodNumber: good_number,
  1785. SupplyManufacturer: supply_manufacturer,
  1786. WarehouseInfoId: warehouse_info_id,
  1787. WarehousingId: warehousing_id,
  1788. MinPrice: min_price_float,
  1789. }
  1790. updateWarehout = append(updateWarehout, &order)
  1791. }
  1792. if id == 0 {
  1793. order := models.SpSupplierWarehousingOutOrder{
  1794. OrderNumber: order_number,
  1795. ProjectId: project_id,
  1796. IsSource: is_source,
  1797. Count: supply_count,
  1798. Amount: supply_total_price_float,
  1799. Price: price_float,
  1800. Remark: supply_remake,
  1801. IsCheck: 2,
  1802. UserOrgId: orgId,
  1803. Status: 1,
  1804. Ctime: time.Now().Unix(),
  1805. Mtime: 0,
  1806. WarehouseOutId: warehose_out_id,
  1807. Type: 1,
  1808. SupplyBatchNumber: supply_batch_number,
  1809. SupplyProductDate: supply_product_date_time,
  1810. SupplyExpiryDate: supply_expiry_date_time,
  1811. WarehouseInfoId: id,
  1812. SupplyType: supply_type,
  1813. SupplyUnit: supply_unit,
  1814. SupplyTotal: supply_total,
  1815. SupplySpecificationName: supply_specification_name,
  1816. SupplyLicenseNumber: supply_license_number,
  1817. Name: name,
  1818. ManufacturerId: manufacturer_id,
  1819. GoodNumber: good_number,
  1820. SupplyManufacturer: supply_manufacturer,
  1821. MinPrice: min_price_float,
  1822. IsWarehosue: 2,
  1823. }
  1824. warehousingOut = append(warehousingOut, &order)
  1825. }
  1826. }
  1827. }
  1828. }
  1829. out := models.SpSupplierWarehouseOut{
  1830. Arrearage: arrerage_float,
  1831. Payment: payment_float,
  1832. RateOfConcession: rate_of_concession_float,
  1833. DiscountAmount: discount_amount_float,
  1834. SupplierId: supplier_id,
  1835. DocumentDate: startTime,
  1836. ReturnRemake: return_remake,
  1837. }
  1838. //更改购货单据
  1839. service.UpdateGoodWarehouseOut(warehose_out_id, out)
  1840. for _, item := range warehousingOut {
  1841. //如果是手动新增的,type 等于2
  1842. if item.WarehouseInfoId == 0 {
  1843. item.Type = 2
  1844. }
  1845. err = service.CreateSupplyWarehousOutOrder(item)
  1846. }
  1847. for _, item := range updateWarehout {
  1848. service.UpdateGoodWarehouseOutOrder(item)
  1849. }
  1850. //for _, item := range updateWarehout {
  1851. // service.UpdateGoodWarehouseOutOrder(item)
  1852. // //查询该商品是否来源于采购订单,如果存在则关联, 如果不存在则取消关联
  1853. // _, errcode := service.GetGoodIsSource(item.WarehousingId, item.ProjectId, orgId)
  1854. // if errcode == gorm.ErrRecordNotFound {
  1855. // item.WarehousingId = 0
  1856. // item.WarehouseInfoId = 0
  1857. // item.Type = 2
  1858. // item.OrderNumber = ""
  1859. //
  1860. // //更新采购单
  1861. // service.ModfySupplyWarehouseOut(item.WarehousingId, orgId)
  1862. // }
  1863. //}
  1864. list, _ := service.GetSupplyWarehouseOutById(warehose_out_id, orgId)
  1865. if err == nil {
  1866. this.ServeSuccessJSON(map[string]interface{}{
  1867. "out": out,
  1868. "list": list,
  1869. })
  1870. } else {
  1871. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1872. }
  1873. }
  1874. func (this *SupplyOrderApiController) DeletePurchOrder() {
  1875. id, _ := this.GetInt64("id")
  1876. orgId := this.GetAdminUserInfo().CurrentOrgId
  1877. err := service.DeletePurchOrder(id, orgId)
  1878. if err == nil {
  1879. returnData := make(map[string]interface{}, 0)
  1880. returnData["msg"] = "ok"
  1881. this.ServeSuccessJSON(returnData)
  1882. return
  1883. } else {
  1884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1885. }
  1886. }
  1887. func (this *SupplyOrderApiController) GetAllOrderCountList() {
  1888. id, _ := this.GetInt64("id")
  1889. orgId := this.GetAdminUserInfo().CurrentOrgId
  1890. //获取购货订单的数据
  1891. purcaseOrder, _ := service.GetAllPurcaseOrderById(id, orgId)
  1892. //获取购货单的数据
  1893. goodOrder, err := service.GetAllGoodOrderByIdSix(id, orgId)
  1894. fmt.Println("2323232332232323232332", goodOrder)
  1895. drugList, err := service.GetSupplyDrugList(orgId)
  1896. if err == nil {
  1897. this.ServeSuccessJSON(map[string]interface{}{
  1898. "purcaseOrder": purcaseOrder,
  1899. "goodOrder": goodOrder,
  1900. "drugList": drugList,
  1901. })
  1902. } else {
  1903. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1904. }
  1905. }
  1906. func (this *SupplyOrderApiController) GetPurchOrderInfo() {
  1907. id, _ := this.GetInt64("id")
  1908. ids := this.GetString("ids")
  1909. if len(ids) == 0 {
  1910. info, _ := service.GetPurchaseOrderDetail(id)
  1911. //查询
  1912. orderInfo, err := service.GetSupplyWarehousingOrderInfo(id)
  1913. orgId := this.GetAdminUserInfo().CurrentOrgId
  1914. supplyList, _ := service.GetSupplierList(orgId)
  1915. //获取药品库数据
  1916. baseList, _ := service.GetSupplyDrugList(orgId)
  1917. goodList, _ := service.GetSupplyGoodList(orgId)
  1918. if err == nil {
  1919. this.ServeSuccessJSON(map[string]interface{}{
  1920. "info": info,
  1921. "orderInfo": orderInfo,
  1922. "supplyList": supplyList,
  1923. "baseList": baseList,
  1924. "goodList": goodList,
  1925. })
  1926. } else {
  1927. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1928. }
  1929. }
  1930. if len(ids) > 0 {
  1931. idArray := strings.Split(ids, ",")
  1932. info, _ := service.GetPurchaseOrderDetail(id)
  1933. //查询
  1934. orderInfo, err := service.GetSupplyWarehousingOrderInfoTwo(id, idArray)
  1935. orgId := this.GetAdminUserInfo().CurrentOrgId
  1936. supplyList, _ := service.GetSupplierList(orgId)
  1937. //获取药品库数据
  1938. baseList, _ := service.GetSupplyDrugList(orgId)
  1939. goodList, _ := service.GetSupplyGoodList(orgId)
  1940. if err == nil {
  1941. this.ServeSuccessJSON(map[string]interface{}{
  1942. "info": info,
  1943. "orderInfo": orderInfo,
  1944. "supplyList": supplyList,
  1945. "baseList": baseList,
  1946. "goodList": goodList,
  1947. })
  1948. } else {
  1949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1950. }
  1951. }
  1952. }
  1953. func (this *SupplyOrderApiController) GetGoodOrderList() {
  1954. id, _ := this.GetInt64("id")
  1955. orgId := this.GetAdminUserInfo().CurrentOrgId
  1956. list, err := service.GetGoodOrderList(id, orgId)
  1957. if err == nil {
  1958. this.ServeSuccessJSON(map[string]interface{}{
  1959. "list": list,
  1960. })
  1961. } else {
  1962. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1963. }
  1964. }
  1965. func (this *SupplyOrderApiController) GetReturnOrder() {
  1966. id, _ := this.GetInt64("id")
  1967. orgId := this.GetAdminUserInfo().CurrentOrgId
  1968. err := service.GetReturnOrder(id, orgId)
  1969. if err == nil {
  1970. returnData := make(map[string]interface{}, 0)
  1971. returnData["msg"] = "ok"
  1972. this.ServeSuccessJSON(returnData)
  1973. return
  1974. } else {
  1975. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1976. }
  1977. }
  1978. func (this *SupplyOrderApiController) GetGoodOrderCountList() {
  1979. id, _ := this.GetInt64("id")
  1980. warehousing_id, _ := this.GetInt64("warehousing_id")
  1981. orgId := this.GetAdminUserInfo().CurrentOrgId
  1982. checker := this.GetAdminUserInfo().AdminUser.Id
  1983. recordDateStr := time.Now().Format("2006-01-02")
  1984. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1985. record_date := recordDate.Unix()
  1986. out := models.SpSupplierWarehouseOut{
  1987. IsCheck: 1,
  1988. Checker: checker,
  1989. CheckTime: record_date,
  1990. }
  1991. err := service.CheckGoodOrder(id, orgId, out)
  1992. fmt.Println(err)
  1993. //获取购货订单的数据
  1994. purcaseOrder, _ := service.GetAllPurcaseOrderById(warehousing_id, orgId)
  1995. //获取购货单的数据
  1996. goodOrder, _ := service.GetAllGoodOrderByIdTwo(id, orgId)
  1997. //查询该购货单是否审核成功
  1998. detail, _ := service.GetGoodOrderDetail(id, orgId)
  1999. var warehousingInfo []*models.WarehousingInfo
  2000. var warehouseInfoDetail []*models.DrugWarehouseInfo
  2001. var drugFlow []*models.DrugFlow
  2002. //如果审核成功
  2003. if detail.IsCheck == 1 {
  2004. //入库
  2005. if len(goodOrder) > 0 {
  2006. for _, item := range goodOrder {
  2007. //药品
  2008. if item.IsSource == 1 {
  2009. //获取药品类型
  2010. medical, _ := service.GetBaseDrugMedical(item.ID)
  2011. timeStr := time.Now().Format("2006-01-02")
  2012. timeArr := strings.Split(timeStr, "-")
  2013. total, _ := service.FindAllWarehouseTotalOne(orgId)
  2014. total = total + 1
  2015. warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2016. operation_time := time.Now().Unix()
  2017. warehousing := models.DrugWarehouse{
  2018. WarehousingOrder: warehousing_order,
  2019. OperationTime: operation_time,
  2020. OrgId: orgId,
  2021. Creater: checker,
  2022. Ctime: time.Now().Unix(),
  2023. Status: 1,
  2024. WarehousingTime: record_date,
  2025. Type: 1,
  2026. SupplyWarehouseId: id,
  2027. }
  2028. //查询今日是否存在入库单号
  2029. _, errcode := service.GetSingleDrugWarehouseOrder(record_date, orgId)
  2030. if errcode == gorm.ErrRecordNotFound {
  2031. service.AddSigleDrugWarehouse(&warehousing)
  2032. }
  2033. drugWarehouseInfo, _ := service.GetLastDrugWarehouse(orgId)
  2034. warehouseInfoDetailOne := &models.DrugWarehouseInfo{
  2035. WarehousingOrder: drugWarehouseInfo.WarehousingOrder,
  2036. WarehousingId: drugWarehouseInfo.ID,
  2037. DrugId: item.ProjectId,
  2038. Number: item.SupplyLicenseNumber,
  2039. ProductDate: item.SupplyProductDate,
  2040. ExpiryDate: item.SupplyExpiryDate,
  2041. WarehousingCount: item.Count,
  2042. Price: item.Price,
  2043. TotalPrice: 0,
  2044. Status: 1,
  2045. Ctime: time.Now().Unix(),
  2046. Remark: item.Remark,
  2047. OrgId: orgId,
  2048. Type: 1,
  2049. Manufacturer: item.ManufacturerId,
  2050. Dealer: 0,
  2051. StockMaxNumber: item.Count,
  2052. RetailTotalPrice: 0,
  2053. BatchNumber: item.SupplyBatchNumber,
  2054. MaxUnit: item.SupplyUnit,
  2055. MinUnit: item.SupplyUnit,
  2056. RetailPrice: item.MinPrice,
  2057. SupplyWarehouseId: id,
  2058. SupplyWarehouseDetailInfo: item.ID,
  2059. }
  2060. if medical.MaxUnit == medical.MinUnit {
  2061. warehouseInfoDetailOne.StockMaxNumber = item.Count
  2062. warehouseInfoDetailOne.StockMinNumber = 0
  2063. warehouseInfoDetailOne.MaxUnit = item.SupplyUnit
  2064. }
  2065. if item.SupplyUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2066. warehouseInfoDetailOne.StockMaxNumber = 0
  2067. warehouseInfoDetailOne.StockMinNumber = item.Count
  2068. warehouseInfoDetailOne.MaxUnit = item.SupplyUnit
  2069. }
  2070. warehouseInfoDetail = append(warehouseInfoDetail, warehouseInfoDetailOne)
  2071. drugflow := &models.DrugFlow{
  2072. WarehousingOrder: drugWarehouseInfo.WarehousingOrder,
  2073. WarehousingId: drugWarehouseInfo.ID,
  2074. DrugId: item.ProjectId,
  2075. Number: item.SupplyBatchNumber,
  2076. ProductDate: item.SupplyProductDate,
  2077. ExpireDate: item.SupplyExpiryDate,
  2078. Count: item.Count,
  2079. Price: item.Price,
  2080. Status: 1,
  2081. Ctime: time.Now().Unix(),
  2082. UserOrgId: orgId,
  2083. Manufacturer: item.ManufacturerId,
  2084. Dealer: 0,
  2085. BatchNumber: item.SupplyBatchNumber,
  2086. MaxUnit: item.SupplyUnit,
  2087. MinUnit: item.SupplyUnit,
  2088. ConsumableType: 1,
  2089. IsEdit: 1,
  2090. Creator: checker,
  2091. IsSys: 0,
  2092. SupplyWarehouseId: id,
  2093. SupplyWarehouseDetailInfo: item.ID,
  2094. }
  2095. if medical.MaxUnit == medical.MinUnit {
  2096. drugflow.MaxUnit = item.SupplyUnit
  2097. }
  2098. if item.SupplyUnit == medical.MinUnit {
  2099. warehouseInfoDetailOne.MaxUnit = warehouseInfoDetailOne.MinUnit
  2100. }
  2101. drugFlow = append(drugFlow, drugflow)
  2102. }
  2103. //耗材
  2104. if item.IsSource == 2 {
  2105. //获取耗材类型
  2106. good, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  2107. timeStr := time.Now().Format("2006-01-02")
  2108. timeArr := strings.Split(timeStr, "-")
  2109. total, _ := service.FindAllWarehouseTotal(orgId)
  2110. total = total + 1
  2111. warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2112. operation_time := time.Now().Unix()
  2113. creater := this.GetAdminUserInfo().AdminUser.Id
  2114. warehousing := models.Warehousing{
  2115. WarehousingOrder: warehousing_order,
  2116. OperationTime: operation_time,
  2117. OrgId: orgId,
  2118. Creater: creater,
  2119. Ctime: time.Now().Unix(),
  2120. Status: 1,
  2121. WarehousingTime: record_date,
  2122. Type: 1,
  2123. SupplyWarehouseId: id,
  2124. }
  2125. //查询是否存在入库单
  2126. _, errcose := service.GetSindleWarehouse(record_date, orgId)
  2127. if errcose == gorm.ErrRecordNotFound {
  2128. service.AddSigleWarehouse(&warehousing)
  2129. }
  2130. info, _ := service.GetLastWarehouseInfoByInfo(orgId)
  2131. //入库单表格
  2132. warehouseInfo := &models.WarehousingInfo{
  2133. WarehousingOrder: info.WarehousingOrder,
  2134. WarehousingId: info.ID,
  2135. GoodId: item.ProjectId,
  2136. Number: item.SupplyBatchNumber,
  2137. GoodTypeId: good.GoodTypeId,
  2138. ProductDate: item.SupplyProductDate,
  2139. ExpiryDate: item.SupplyExpiryDate,
  2140. WarehousingCount: item.Count,
  2141. Price: item.Price,
  2142. TotalPrice: 0,
  2143. Status: 1,
  2144. Ctime: time.Now().Unix(),
  2145. Remark: item.Remark,
  2146. OrgId: orgId,
  2147. Type: 1,
  2148. Manufacturer: item.ManufacturerId,
  2149. StockCount: item.Count,
  2150. Dealer: good.Dealer,
  2151. LicenseNumber: item.SupplyLicenseNumber,
  2152. PackingPrice: item.MinPrice,
  2153. SupplyWarehouseId: id,
  2154. SupplyWarehouseDetailInfo: item.ID,
  2155. }
  2156. warehousingInfo = append(warehousingInfo, warehouseInfo)
  2157. }
  2158. }
  2159. }
  2160. }
  2161. for _, item := range warehousingInfo {
  2162. service.CreatedWarehouseingDetail(item)
  2163. warehousinginfo, _ := service.GetLastWarehousingInfo(item.GoodId)
  2164. flow := models.VmStockFlow{
  2165. WarehousingOrder: item.WarehousingOrder,
  2166. WarehousingId: item.ID,
  2167. GoodId: item.GoodId,
  2168. Number: item.Number,
  2169. ProductDate: item.ProductDate,
  2170. ExpireDate: item.ExpiryDate,
  2171. Count: item.WarehousingCount,
  2172. Price: item.Price,
  2173. Status: 1,
  2174. Ctime: time.Now().Unix(),
  2175. UserOrgId: orgId,
  2176. Manufacturer: item.Manufacturer,
  2177. Dealer: item.Dealer,
  2178. LicenseNumber: item.LicenseNumber,
  2179. IsEdit: 1,
  2180. Creator: checker,
  2181. SystemTime: record_date,
  2182. ConsumableType: 1,
  2183. WarehousingDetailId: warehousinginfo.ID,
  2184. SupplyWarehouseId: id,
  2185. SupplyWarehouseDetailInfo: item.ID,
  2186. }
  2187. service.CreateStockFlowOne(flow)
  2188. }
  2189. //创建入库单
  2190. errs := service.CreateDrugWarehousingInfoSix(warehouseInfoDetail)
  2191. //改变入库状态
  2192. fmt.Println(errs)
  2193. for _, items := range drugFlow {
  2194. drugWarehouseInfo, _ := service.GetLastDrugWarehouseInfo(items.DrugId)
  2195. items.WarehousingDetailId = drugWarehouseInfo.ID
  2196. }
  2197. //创建流水单
  2198. service.CreateDrugFlowSix(drugFlow)
  2199. drugList, _ := service.GetSupplyDrugList(orgId)
  2200. for _, items := range goodOrder {
  2201. service.UpdateWarehouseingById(items.ID)
  2202. }
  2203. if err == nil {
  2204. this.ServeSuccessJSON(map[string]interface{}{
  2205. "purcaseOrder": purcaseOrder,
  2206. "goodOrder": goodOrder,
  2207. "drugList": drugList,
  2208. })
  2209. } else {
  2210. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2211. }
  2212. }
  2213. func (this *SupplyOrderApiController) ModefySupplyWarehousing() {
  2214. is_warehouse, _ := this.GetInt64("is_warehouse")
  2215. warehousing_id, _ := this.GetInt64("warehousing_id")
  2216. orgId := this.GetAdminUserInfo().CurrentOrgId
  2217. err := service.ModefySupplyWarehousing(is_warehouse, warehousing_id, orgId)
  2218. if err == nil {
  2219. returnData := make(map[string]interface{}, 0)
  2220. returnData["msg"] = "ok"
  2221. this.ServeSuccessJSON(returnData)
  2222. return
  2223. } else {
  2224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2225. }
  2226. }
  2227. func (this *SupplyOrderApiController) SaveGoodReturnOrder() {
  2228. dataBody := make(map[string]interface{}, 0)
  2229. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2230. if err != nil {
  2231. utils.ErrorLog(err.Error())
  2232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2233. return
  2234. }
  2235. return_remark := dataBody["return_marke"].(string)
  2236. supplier_id, _ := this.GetInt64("supplier_id")
  2237. start_time := this.GetString("start_time")
  2238. timeLayout := "2006-01-02"
  2239. loc, _ := time.LoadLocation("Local")
  2240. var startTime int64
  2241. if len(start_time) > 0 {
  2242. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2243. if err != nil {
  2244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2245. return
  2246. }
  2247. startTime = theTime.Unix()
  2248. }
  2249. warehouse_out_id, _ := this.GetInt64("warehouse_out_id")
  2250. arrerage := this.GetString("arrerage")
  2251. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  2252. payment := this.GetString("payment")
  2253. payment_float, _ := strconv.ParseFloat(payment, 64)
  2254. rate_of_concession := this.GetString("rate_of_concession")
  2255. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  2256. discount_amount := this.GetString("discount_amount")
  2257. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  2258. orgId := this.GetAdminUserInfo().CurrentOrgId
  2259. total, _ := service.GetSupplyCancelOrder(orgId)
  2260. creater := this.GetAdminUserInfo().AdminUser.Id
  2261. //生成购货单
  2262. timeStr := time.Now().Format("2006-01-02")
  2263. timeArr := strings.Split(timeStr, "-")
  2264. total = total + 1
  2265. warehousing_order := "CGT" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  2266. recordDateStr := time.Now().Format("2006-01-02")
  2267. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2268. cancel := models.SpSupplierWarehouseCancel{
  2269. Number: warehousing_order,
  2270. UserOrgId: orgId,
  2271. Creater: creater,
  2272. Ctime: time.Now().Unix(),
  2273. Mtime: 0,
  2274. Status: 1,
  2275. RecordDate: recordDate.Unix(),
  2276. IsCheck: 2,
  2277. WarehouseOutId: warehouse_out_id,
  2278. RateOfConcession: rate_of_concession_float,
  2279. DiscountAmount: discount_amount_float,
  2280. DocumentDate: startTime,
  2281. SupplierId: supplier_id,
  2282. Checker: 0,
  2283. CheckTime: 0,
  2284. Arrearage: arrerage_float,
  2285. Payment: payment_float,
  2286. ReturnRemark: return_remark,
  2287. }
  2288. err = service.CreateReturnCacelOrder(cancel)
  2289. order, _ := service.GetLastReturnCancelOrder(orgId)
  2290. var warehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2291. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  2292. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  2293. if len(thisStockIn) > 0 {
  2294. for _, item := range thisStockIn {
  2295. items := item.(map[string]interface{})
  2296. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  2297. utils.ErrorLog("supply_count")
  2298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2299. return
  2300. }
  2301. supply_count := int64(items["supply_count"].(float64))
  2302. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2303. utils.ErrorLog("count")
  2304. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2305. return
  2306. }
  2307. count := items["count"].(string)
  2308. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  2309. utils.ErrorLog("manufacturer_id")
  2310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2311. return
  2312. }
  2313. manufacturer_id := int64(items["manufacturer_id"].(float64))
  2314. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  2315. utils.ErrorLog("name")
  2316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2317. return
  2318. }
  2319. name := items["name"].(string)
  2320. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  2321. utils.ErrorLog("order_number")
  2322. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2323. return
  2324. }
  2325. order_number := items["order_number"].(string)
  2326. if items["good_number"] == nil || reflect.TypeOf(items["good_number"]).String() != "string" {
  2327. utils.ErrorLog("good_number")
  2328. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2329. return
  2330. }
  2331. good_number := items["good_number"].(string)
  2332. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  2333. utils.ErrorLog("supply_price")
  2334. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2335. return
  2336. }
  2337. supply_price := items["supply_price"].(string)
  2338. price_float, _ := strconv.ParseFloat(supply_price, 64)
  2339. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  2340. utils.ErrorLog("project_id")
  2341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2342. return
  2343. }
  2344. project_id := int64(items["project_id"].(float64))
  2345. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  2346. utils.ErrorLog("supply_remake")
  2347. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2348. return
  2349. }
  2350. supply_remake := items["supply_remake"].(string)
  2351. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  2352. utils.ErrorLog("supply_license_number")
  2353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2354. return
  2355. }
  2356. supply_license_number := items["supply_license_number"].(string)
  2357. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  2358. utils.ErrorLog("supply_specification_name")
  2359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2360. return
  2361. }
  2362. supply_specification_name := items["supply_specification_name"].(string)
  2363. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  2364. utils.ErrorLog("supply_total")
  2365. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2366. return
  2367. }
  2368. supply_total := items["supply_total"].(string)
  2369. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  2370. utils.ErrorLog("supply_type")
  2371. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2372. return
  2373. }
  2374. supply_type := items["supply_type"].(string)
  2375. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  2376. utils.ErrorLog("supply_unit")
  2377. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2378. return
  2379. }
  2380. supply_unit := items["supply_unit"].(string)
  2381. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2382. utils.ErrorLog("type")
  2383. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2384. return
  2385. }
  2386. is_source := int64(items["type"].(float64))
  2387. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  2388. utils.ErrorLog("supply_manufacturer")
  2389. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2390. return
  2391. }
  2392. supply_manufacturer := items["supply_manufacturer"].(string)
  2393. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  2394. utils.ErrorLog("supply_batch_number")
  2395. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2396. return
  2397. }
  2398. supply_batch_number := items["supply_batch_number"].(string)
  2399. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "float64" {
  2400. utils.ErrorLog("supply_product_date")
  2401. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2402. return
  2403. }
  2404. supply_product_date := int64(items["supply_product_date"].(float64))
  2405. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "float64" {
  2406. utils.ErrorLog("supply_expiry_date")
  2407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2408. return
  2409. }
  2410. supply_expiry_date := int64(items["supply_expiry_date"].(float64))
  2411. if items["warehousing_id"] == nil || reflect.TypeOf(items["warehousing_id"]).String() != "float64" {
  2412. utils.ErrorLog("warehousing_id")
  2413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2414. return
  2415. }
  2416. warehousing_id := int64(items["warehousing_id"].(float64))
  2417. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  2418. utils.ErrorLog("warehouse_info_id")
  2419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2420. return
  2421. }
  2422. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  2423. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2424. utils.ErrorLog("id")
  2425. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2426. return
  2427. }
  2428. id := int64(items["id"].(float64))
  2429. deposit_rate := items["deposit_rate"].(string)
  2430. deposit_rate_float, _ := strconv.ParseFloat(deposit_rate, 64)
  2431. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2432. ManufacturerId: manufacturer_id,
  2433. OrderNumber: order_number,
  2434. ProjectId: project_id,
  2435. GoodNumber: good_number,
  2436. IsSource: is_source,
  2437. Count: count,
  2438. Price: price_float,
  2439. Remark: supply_remake,
  2440. RateOfConcession: rate_of_concession_float,
  2441. DiscountAmount: discount_amount_float,
  2442. UserOrgId: orgId,
  2443. Ctime: time.Now().Unix(),
  2444. Status: 1,
  2445. Mtime: 0,
  2446. WarehouseCancelId: order.ID,
  2447. Type: 1,
  2448. ReturnNumber: order.Number,
  2449. WarehouseOutId: warehouse_out_id,
  2450. SupplySpecificationName: supply_specification_name,
  2451. SupplyType: supply_type,
  2452. SupplyTotal: supply_total,
  2453. SupplyManufacturer: supply_manufacturer,
  2454. Name: name,
  2455. SupplyUnit: supply_unit,
  2456. SupplyLicenseNumber: supply_license_number,
  2457. SupplyBatchNumber: supply_batch_number,
  2458. SupplyExpiryDate: supply_expiry_date,
  2459. SupplyProductDate: supply_product_date,
  2460. WarehouseInfoId: warehouse_info_id,
  2461. WarehousingId: warehousing_id,
  2462. SourceCount: count,
  2463. SupplyWarehouseDetailInfo: id,
  2464. SupplyCount: supply_count,
  2465. DepositRate: deposit_rate_float,
  2466. }
  2467. warehouseCancel = append(warehouseCancel, cancelOrder)
  2468. }
  2469. }
  2470. }
  2471. for _, item := range warehouseCancel {
  2472. if item.SupplyWarehouseDetailInfo > 0 {
  2473. item.Type = 1
  2474. } else {
  2475. item.Type = 2
  2476. }
  2477. service.CreateCancelReturnOrder(item)
  2478. //查询该商品在退库单中是否存在
  2479. _, errcodes := service.GetSupplyWarehouseOutIsExsit(item.WarehouseOutId, item.ProjectId, orgId)
  2480. //如果不存在则情况退库单的关联信息
  2481. if errcodes == gorm.ErrRecordNotFound {
  2482. service.ModfySupplyCancel(item.WarehouseCancelId, orgId, item.ProjectId)
  2483. }
  2484. }
  2485. cancelOrder, err := service.GetReturnCancelOrder(order.ID, orgId)
  2486. list, err := service.GetReturnCancelOrderList(order.ID, orgId)
  2487. if err == nil {
  2488. this.ServeSuccessJSON(map[string]interface{}{
  2489. "warehouseCancel": warehouseCancel,
  2490. "cancelOrder": cancelOrder,
  2491. "list": list,
  2492. })
  2493. } else {
  2494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2495. }
  2496. }
  2497. func (this *SupplyOrderApiController) GetAllGoodReturnOrderList() {
  2498. check_id, _ := this.GetInt64("check_id")
  2499. start_time := this.GetString("start_time")
  2500. end_time := this.GetString("end_time")
  2501. keyword := this.GetString("keyword")
  2502. page, _ := this.GetInt64("page")
  2503. limit, _ := this.GetInt64("limit")
  2504. timeLayout := "2006-01-02"
  2505. loc, _ := time.LoadLocation("Local")
  2506. var startTime int64
  2507. if len(start_time) > 0 {
  2508. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2509. if err != nil {
  2510. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2511. return
  2512. }
  2513. startTime = theTime.Unix()
  2514. }
  2515. var endTime int64
  2516. if len(end_time) > 0 {
  2517. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2518. if err != nil {
  2519. utils.ErrorLog(err.Error())
  2520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2521. return
  2522. }
  2523. endTime = theTime.Unix()
  2524. }
  2525. orgId := this.GetAdminUserInfo().CurrentOrgId
  2526. list, total, err := service.GetAllGoodReturnOrderList(check_id, keyword, page, limit, startTime, endTime, orgId)
  2527. if err == nil {
  2528. this.ServeSuccessJSON(map[string]interface{}{
  2529. "total": total,
  2530. "list": list,
  2531. })
  2532. } else {
  2533. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2534. }
  2535. }
  2536. func (this *SupplyOrderApiController) GetGoodReturnDetail() {
  2537. id, _ := this.GetInt64("id")
  2538. orgId := this.GetAdminUserInfo().CurrentOrgId
  2539. detail, err := service.GetGoodReturnDetail(id, orgId)
  2540. orderDetail, err := service.GetGoodReturnOrderDetail(id, orgId)
  2541. //获取药品库数据
  2542. baseList, _ := service.GetSupplyDrugList(orgId)
  2543. goodList, _ := service.GetSupplyGoodList(orgId)
  2544. supplyList, _ := service.GetSupplierList(orgId)
  2545. if err == nil {
  2546. this.ServeSuccessJSON(map[string]interface{}{
  2547. "cancelDetail": detail,
  2548. "orderCancelDetail": orderDetail,
  2549. "drugList": baseList,
  2550. "goodList": goodList,
  2551. "supplyList": supplyList,
  2552. })
  2553. } else {
  2554. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2555. }
  2556. }
  2557. func (this *SupplyOrderApiController) UpdateGoodReturn() {
  2558. dataBody := make(map[string]interface{}, 0)
  2559. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2560. if err != nil {
  2561. utils.ErrorLog(err.Error())
  2562. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2563. return
  2564. }
  2565. return_remark := dataBody["return_marke"].(string)
  2566. supplier_id, _ := this.GetInt64("supplier_id")
  2567. start_time := this.GetString("start")
  2568. timeLayout := "2006-01-02"
  2569. loc, _ := time.LoadLocation("Local")
  2570. var startTime int64
  2571. if len(start_time) > 0 {
  2572. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2573. if err != nil {
  2574. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2575. return
  2576. }
  2577. startTime = theTime.Unix()
  2578. }
  2579. warehouse_out_id, _ := this.GetInt64("warehouse_out_id")
  2580. arrerage := this.GetString("arrerage")
  2581. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  2582. payment := this.GetString("payment")
  2583. payment_float, _ := strconv.ParseFloat(payment, 64)
  2584. rate_of_concession := this.GetString("rate_of_concession")
  2585. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  2586. discount_amount := this.GetString("discount_amount")
  2587. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  2588. return_number := this.GetString("return_number")
  2589. orgId := this.GetAdminUserInfo().CurrentOrgId
  2590. cancel := models.SpSupplierWarehouseCancel{
  2591. ID: 0,
  2592. Number: return_number,
  2593. RateOfConcession: rate_of_concession_float,
  2594. DiscountAmount: discount_amount_float,
  2595. DocumentDate: startTime,
  2596. SupplierId: supplier_id,
  2597. Arrearage: arrerage_float,
  2598. Payment: payment_float,
  2599. ReturnRemark: return_remark,
  2600. }
  2601. service.UpdateWarehouseCancel(warehouse_out_id, cancel)
  2602. var warehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2603. var updateWarehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2604. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  2605. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  2606. if len(thisStockIn) > 0 {
  2607. for _, item := range thisStockIn {
  2608. items := item.(map[string]interface{})
  2609. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2610. utils.ErrorLog("id")
  2611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2612. return
  2613. }
  2614. id := int64(items["id"].(float64))
  2615. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  2616. utils.ErrorLog("supply_count")
  2617. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2618. return
  2619. }
  2620. supply_count := int64(items["supply_count"].(float64))
  2621. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  2622. utils.ErrorLog("manufacturer_id")
  2623. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2624. return
  2625. }
  2626. manufacturer_id := int64(items["manufacturer_id"].(float64))
  2627. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  2628. utils.ErrorLog("name")
  2629. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2630. return
  2631. }
  2632. name := items["name"].(string)
  2633. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  2634. utils.ErrorLog("order_number")
  2635. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2636. return
  2637. }
  2638. order_number := items["order_number"].(string)
  2639. if items["good_number"] == nil || reflect.TypeOf(items["good_number"]).String() != "string" {
  2640. utils.ErrorLog("good_number")
  2641. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2642. return
  2643. }
  2644. good_number := items["good_number"].(string)
  2645. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  2646. utils.ErrorLog("supply_price")
  2647. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2648. return
  2649. }
  2650. supply_price := items["supply_price"].(string)
  2651. price_float, _ := strconv.ParseFloat(supply_price, 64)
  2652. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  2653. utils.ErrorLog("project_id")
  2654. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2655. return
  2656. }
  2657. project_id := int64(items["project_id"].(float64))
  2658. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  2659. utils.ErrorLog("supply_remake")
  2660. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2661. return
  2662. }
  2663. supply_remake := items["supply_remake"].(string)
  2664. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  2665. utils.ErrorLog("supply_license_number")
  2666. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2667. return
  2668. }
  2669. supply_license_number := items["supply_license_number"].(string)
  2670. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  2671. utils.ErrorLog("supply_specification_name")
  2672. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2673. return
  2674. }
  2675. supply_specification_name := items["supply_specification_name"].(string)
  2676. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  2677. utils.ErrorLog("supply_total")
  2678. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2679. return
  2680. }
  2681. supply_total := items["supply_total"].(string)
  2682. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  2683. utils.ErrorLog("supply_type")
  2684. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2685. return
  2686. }
  2687. supply_type := items["supply_type"].(string)
  2688. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  2689. utils.ErrorLog("supply_unit")
  2690. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2691. return
  2692. }
  2693. supply_unit := items["supply_unit"].(string)
  2694. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2695. utils.ErrorLog("type")
  2696. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2697. return
  2698. }
  2699. is_source := int64(items["type"].(float64))
  2700. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  2701. utils.ErrorLog("supply_manufacturer")
  2702. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2703. return
  2704. }
  2705. supply_manufacturer := items["supply_manufacturer"].(string)
  2706. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2707. utils.ErrorLog("count")
  2708. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2709. return
  2710. }
  2711. count := items["count"].(string)
  2712. if items["deposit_rate"] == nil || reflect.TypeOf(items["deposit_rate"]).String() != "string" {
  2713. utils.ErrorLog("deposit_rate")
  2714. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2715. return
  2716. }
  2717. deposit_rate := items["deposit_rate"].(string)
  2718. deposit_rate_float, _ := strconv.ParseFloat(deposit_rate, 64)
  2719. if id > 0 {
  2720. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2721. ID: id,
  2722. ManufacturerId: manufacturer_id,
  2723. OrderNumber: order_number,
  2724. ProjectId: project_id,
  2725. GoodNumber: good_number,
  2726. IsSource: is_source,
  2727. Count: count,
  2728. Price: price_float,
  2729. Remark: supply_remake,
  2730. RateOfConcession: rate_of_concession_float,
  2731. DiscountAmount: discount_amount_float,
  2732. UserOrgId: orgId,
  2733. Ctime: time.Now().Unix(),
  2734. Status: 1,
  2735. Mtime: 0,
  2736. WarehouseCancelId: warehouse_out_id,
  2737. Type: 1,
  2738. ReturnNumber: return_number,
  2739. WarehouseOutId: warehouse_out_id,
  2740. SupplySpecificationName: supply_specification_name,
  2741. SupplyType: supply_type,
  2742. SupplyTotal: supply_total,
  2743. SupplyManufacturer: supply_manufacturer,
  2744. Name: name,
  2745. SupplyUnit: supply_unit,
  2746. SupplyLicenseNumber: supply_license_number,
  2747. SupplyCount: supply_count,
  2748. DepositRate: deposit_rate_float,
  2749. }
  2750. updateWarehouseCancel = append(updateWarehouseCancel, cancelOrder)
  2751. }
  2752. if id == 0 {
  2753. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2754. ManufacturerId: manufacturer_id,
  2755. OrderNumber: order_number,
  2756. ProjectId: project_id,
  2757. GoodNumber: good_number,
  2758. IsSource: is_source,
  2759. Count: count,
  2760. Price: price_float,
  2761. Remark: supply_remake,
  2762. RateOfConcession: rate_of_concession_float,
  2763. DiscountAmount: discount_amount_float,
  2764. UserOrgId: orgId,
  2765. Ctime: time.Now().Unix(),
  2766. Status: 1,
  2767. Mtime: 0,
  2768. WarehouseCancelId: warehouse_out_id,
  2769. Type: 2,
  2770. ReturnNumber: return_number,
  2771. WarehouseOutId: warehouse_out_id,
  2772. SupplySpecificationName: supply_specification_name,
  2773. SupplyType: supply_type,
  2774. SupplyTotal: supply_total,
  2775. SupplyManufacturer: supply_manufacturer,
  2776. Name: name,
  2777. SupplyUnit: supply_unit,
  2778. SupplyLicenseNumber: supply_license_number,
  2779. SupplyCount: supply_count,
  2780. DepositRate: deposit_rate_float,
  2781. }
  2782. warehouseCancel = append(warehouseCancel, cancelOrder)
  2783. }
  2784. }
  2785. }
  2786. if len(updateWarehouseCancel) > 0 {
  2787. for _, item := range updateWarehouseCancel {
  2788. service.UpdateWarehouseCancelOrder(item)
  2789. }
  2790. }
  2791. if len(warehouseCancel) > 0 {
  2792. for _, item := range warehouseCancel {
  2793. service.CreateCancelReturnOrder(item)
  2794. }
  2795. }
  2796. list, err := service.GetReturnCancelOrderList(warehouse_out_id, orgId)
  2797. if err == nil {
  2798. this.ServeSuccessJSON(map[string]interface{}{
  2799. "list": list,
  2800. "msg": "msg",
  2801. })
  2802. return
  2803. } else {
  2804. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2805. }
  2806. }
  2807. }
  2808. func (this *SupplyOrderApiController) ModefyGoodOrder() {
  2809. id, _ := this.GetInt64("id")
  2810. warehousing_id, _ := this.GetInt64("warehousing_id")
  2811. orgId := this.GetAdminUserInfo().CurrentOrgId
  2812. //获取购货单的数据
  2813. goodOrder, _ := service.GetAllGoodOrderById(id, orgId)
  2814. //判断该订单是否有出库记录
  2815. for _, it := range goodOrder {
  2816. if it.IsSource == 1 {
  2817. out, _ := service.GetDrugWarehosueInfoByWarehousingId(it.ProjectId, id, orgId)
  2818. if out.ID > 0 {
  2819. this.ServeSuccessJSON(map[string]interface{}{
  2820. "cancelList": "",
  2821. "purcaseOrder": "",
  2822. "goodOrder": "",
  2823. "drugList": "",
  2824. "msg": 3,
  2825. })
  2826. return
  2827. }
  2828. }
  2829. if it.IsSource == 2 {
  2830. fmt.Println("hh23323233232232332232323232332", it.WarehouseOutId)
  2831. out, _ := service.GetGoodWarehouseInfoByWarehousingId(it.ProjectId, id, orgId)
  2832. if out.ID > 0 {
  2833. this.ServeSuccessJSON(map[string]interface{}{
  2834. "cancelList": "",
  2835. "purcaseOrder": "",
  2836. "goodOrder": "",
  2837. "drugList": "",
  2838. "msg": 3,
  2839. })
  2840. return
  2841. }
  2842. }
  2843. }
  2844. //获取购货订单的数据
  2845. purcaseOrder, _ := service.GetAllPurcaseOrderById(warehousing_id, orgId)
  2846. drugList, _ := service.GetSupplyDrugList(orgId)
  2847. //获取已有关联的退货单
  2848. cancelList, _ := service.GetSupplyCancelWarehouse(id, orgId)
  2849. //查询是否存在退货单
  2850. _, errcode := service.GetSupplyCancelOrderById(id, orgId)
  2851. //无退库单
  2852. if errcode == gorm.ErrRecordNotFound {
  2853. //反审核成功
  2854. out := models.SpSupplierWarehouseOut{
  2855. IsCheck: 2,
  2856. Checker: 0,
  2857. CheckTime: 0,
  2858. }
  2859. err := service.UpdateSupplyGoodOrder(id, out)
  2860. for _, its := range goodOrder {
  2861. //改变采购单状态
  2862. service.UpdateSupplyOrderListById(its.ID)
  2863. }
  2864. //查询该订单不是采购入库的数据
  2865. list, _ := service.GetDrugSupplyWarehousingById(id, orgId)
  2866. if len(list) == 0 {
  2867. service.UpdateSupplyWarehousing(id, orgId)
  2868. }
  2869. goodList, _ := service.GetGoodSupplyWarehousingById(id, orgId)
  2870. if len(goodList) == 0 {
  2871. service.UpdateGoodWarehousing(id, orgId)
  2872. }
  2873. //删除药品入库单
  2874. service.UpdateDrugSupplyWarehousingInfo(id, orgId)
  2875. //删除入库流水
  2876. service.UpdateDrugSupplyFlow(id, orgId)
  2877. //删除耗材入库单
  2878. service.UpdateGoodSupplyWarehousingInfo(id, orgId)
  2879. //删除耗材入库流水
  2880. service.UpdateGoodSupplyFlow(id, orgId)
  2881. if err == nil {
  2882. this.ServeSuccessJSON(map[string]interface{}{
  2883. "cancelList": cancelList,
  2884. "purcaseOrder": purcaseOrder,
  2885. "goodOrder": goodOrder,
  2886. "drugList": drugList,
  2887. "msg": 1,
  2888. })
  2889. return
  2890. } else {
  2891. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2892. }
  2893. } else if errcode == nil {
  2894. this.ServeSuccessJSON(map[string]interface{}{
  2895. "cancelList": cancelList,
  2896. "purcaseOrder": purcaseOrder,
  2897. "goodOrder": goodOrder,
  2898. "drugList": drugList,
  2899. "msg": 2,
  2900. })
  2901. return
  2902. }
  2903. }
  2904. func (this *SupplyOrderApiController) UpdateSupplyWarehousing() {
  2905. warehousing_id, _ := this.GetInt64("warehousing_id")
  2906. orgId := this.GetAdminUserInfo().CurrentOrgId
  2907. err := service.UpdateSupplyWarehousingById(warehousing_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) DeleteGoodOrder() {
  2918. id, _ := this.GetInt64("id")
  2919. orgId := this.GetAdminUserInfo().CurrentOrgId
  2920. err := service.DeleteGoodOrder(id, orgId)
  2921. if err == nil {
  2922. returnData := make(map[string]interface{}, 0)
  2923. returnData["msg"] = "ok"
  2924. this.ServeSuccessJSON(returnData)
  2925. return
  2926. } else {
  2927. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2928. }
  2929. }
  2930. func (this *SupplyOrderApiController) GetSupplyWarehouseById() {
  2931. id, _ := this.GetInt64("id")
  2932. orgId := this.GetAdminUserInfo().CurrentOrgId
  2933. //获取已有关联的退货单
  2934. cancelList, err := service.GetSupplyCancelWarehouse(id, orgId)
  2935. //获取采购单数据
  2936. outList, _ := service.GetGoodOrderListById(id, orgId)
  2937. //获取退货单数据
  2938. cancelOrderList, _ := service.GetGoodCanceListById(id, orgId)
  2939. //获取药品库数据
  2940. baseList, _ := service.GetSupplyDrugList(orgId)
  2941. if err == nil {
  2942. this.ServeSuccessJSON(map[string]interface{}{
  2943. "cancelList": cancelList,
  2944. "outList": outList,
  2945. "drugList": baseList,
  2946. "cancelOrderList": cancelOrderList,
  2947. })
  2948. } else {
  2949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2950. }
  2951. }
  2952. func (this *SupplyOrderApiController) CheckGoodOrderById() {
  2953. id, _ := this.GetInt64("id")
  2954. recordDateStr := time.Now().Format("2006-01-02")
  2955. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2956. record_date := recordDate.Unix()
  2957. checker := this.GetAdminUserInfo().AdminUser.Id
  2958. out := models.SpSupplierWarehouseOut{
  2959. IsCheck: 1,
  2960. Checker: checker,
  2961. CheckTime: record_date,
  2962. }
  2963. err := service.UpdateSupplyGoodOrder(id, out)
  2964. if err == nil {
  2965. this.ServeSuccessJSON(map[string]interface{}{
  2966. "out": out,
  2967. })
  2968. } else {
  2969. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2970. }
  2971. }
  2972. func (this *SupplyOrderApiController) CheckReturnOrder() {
  2973. id, _ := this.GetInt64("id")
  2974. warehouse_out_id, _ := this.GetInt64("warehouse_out_id")
  2975. recordDateStr := time.Now().Format("2006-01-02")
  2976. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2977. orgId := this.GetAdminUserInfo().CurrentOrgId
  2978. record_date := recordDate.Unix()
  2979. checker := this.GetAdminUserInfo().AdminUser.Id
  2980. //获取退库单详情
  2981. list, _ := service.GetSupplyCancelOrderDetail(id, orgId)
  2982. for _, item := range list {
  2983. fmt.Println("itme.233232323232323232323232323232232332", item.Type)
  2984. var total_count int64
  2985. var prescribing_number_total int64
  2986. //药品
  2987. if item.IsSource == 1 {
  2988. //获取药品库存
  2989. info, _ := service.GetDrugTotalCountTwenTy(item.ProjectId, item.SupplyWarehouseDetailInfo, item.Type)
  2990. for _, it := range info {
  2991. if it.MaxUnit == it.CountUnit {
  2992. it.StockMaxNumber = it.StockMaxNumber * it.MinNumber
  2993. }
  2994. total_count += (it.StockMaxNumber + it.StockMinNumber)
  2995. }
  2996. //查询改药品信息
  2997. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  2998. //判断单位是否相等
  2999. if medical.MaxUnit == item.SupplyUnit {
  3000. //转化为最小单位
  3001. prescribing_number_total = item.SupplyCount * medical.MinNumber
  3002. }
  3003. if medical.MinUnit == item.SupplyUnit {
  3004. prescribing_number_total = item.SupplyCount
  3005. }
  3006. fmt.Println("hhhhhadf dafsdfsdfddddfdf", prescribing_number_total)
  3007. //判断单位
  3008. if total_count == 0 {
  3009. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  3010. this.ServeSuccessJSON(map[string]interface{}{
  3011. "msg": "3",
  3012. "drug_name": goodObj.DrugName,
  3013. "dose": goodObj.Dose,
  3014. "dose_unit": goodObj.DoseUnit,
  3015. "min_number": goodObj.MinNumber,
  3016. "min_unit": goodObj.MinUnit,
  3017. "max_unit": goodObj.MaxUnit,
  3018. })
  3019. return
  3020. }
  3021. if prescribing_number_total > total_count {
  3022. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  3023. this.ServeSuccessJSON(map[string]interface{}{
  3024. "msg": "3",
  3025. "drug_name": goodObj.DrugName,
  3026. "dose": goodObj.Dose,
  3027. "dose_unit": goodObj.DoseUnit,
  3028. "min_number": goodObj.MinNumber,
  3029. "min_unit": goodObj.MinUnit,
  3030. "max_unit": goodObj.MaxUnit,
  3031. })
  3032. return
  3033. }
  3034. ctime := time.Now().Unix()
  3035. timeStr := time.Now().Format("2006-01-02")
  3036. timeArr := strings.Split(timeStr, "-")
  3037. total, _ := service.FindAllDrugWarehouseOut(orgId)
  3038. total = total + 1
  3039. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3040. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3041. number = number + total
  3042. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  3043. //operation_time := time.Now().Unix()
  3044. creater := this.GetAdminUserInfo().AdminUser.Id
  3045. recordDateStr := time.Now().Format("2006-01-02")
  3046. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3047. orgId := this.GetAdminUserInfo().CurrentOrgId
  3048. record_date := recordDate.Unix()
  3049. warehouseOut := models.DrugWarehouseOut{
  3050. WarehouseOutOrderNumber: warehousing_out_order,
  3051. OperationTime: record_date,
  3052. OrgId: orgId,
  3053. Creater: creater,
  3054. Ctime: ctime,
  3055. Status: 1,
  3056. WarehouseOutTime: record_date,
  3057. Type: 1,
  3058. SupplyCancelOutId: id,
  3059. SupplyWarehouseId: warehouse_out_id,
  3060. }
  3061. // 查询今日是否存在出库单
  3062. _, errcodes := service.GetDrugWarehouseOutById(orgId, record_date)
  3063. if errcodes == gorm.ErrRecordNotFound {
  3064. service.AddSigleDrugWarehouseOut(&warehouseOut)
  3065. }
  3066. lastDrug, _ := service.GetLastDrugWarehouseById(orgId, record_date)
  3067. //获取
  3068. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  3069. WarehouseOutOrderNumber: lastDrug.WarehouseOutOrderNumber,
  3070. WarehouseOutId: lastDrug.ID,
  3071. DrugId: item.ProjectId,
  3072. Count: item.SupplyCount,
  3073. Price: item.Price,
  3074. Status: 1,
  3075. Ctime: ctime,
  3076. Remark: "",
  3077. OrgId: orgId,
  3078. Type: 1,
  3079. Manufacturer: item.ManufacturerId,
  3080. Dealer: 0,
  3081. CountUnit: item.SupplyUnit,
  3082. ExpiryDate: item.SupplyExpiryDate,
  3083. ProductDate: item.SupplyProductDate,
  3084. Number: item.SupplyLicenseNumber,
  3085. BatchNumber: item.SupplyBatchNumber,
  3086. IsSys: 0,
  3087. WarehouseInfoId: 0,
  3088. SupplyCancelOutId: id,
  3089. SupplyWarehouseId: warehouse_out_id,
  3090. SysRecordTime: record_date,
  3091. IsSource: item.Type,
  3092. }
  3093. drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
  3094. if drup.ID > 0 {
  3095. prescribingNumber := item.SupplyCount
  3096. service.AutoDrugDeliverInfoNight(orgId, prescribingNumber, &warehouseOut, &drup, warehouseOutInfo, warehouse_out_id, id)
  3097. }
  3098. //修改原数据
  3099. /* orderInfo := models.SpSupplierWarehousingCancelOrder{
  3100. SourceCount: item.SupplyCount - item.SourceCount,
  3101. }
  3102. service.UpdateSupplyCancelById(item.ID, orderInfo)*/
  3103. }
  3104. //耗材
  3105. if item.IsSource == 2 {
  3106. // 查询该耗材是否有库存
  3107. warehouseOne, _ := service.FindWarehousingInfoTwenTy(item.ProjectId, item.SupplyWarehouseDetailInfo, item.Type)
  3108. // 如果出库数量大于该批次剩余库存数量
  3109. if item.SupplyCount > warehouseOne.StockCount {
  3110. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  3111. this.ServeSuccessJSON(map[string]interface{}{
  3112. "msg": "2",
  3113. "good_name": goodObj.GoodName,
  3114. "specification_name": goodObj.SpecificationName,
  3115. })
  3116. return
  3117. }
  3118. ctime := time.Now().Unix()
  3119. timeStr := time.Now().Format("2006-01-02")
  3120. timeArr := strings.Split(timeStr, "-")
  3121. total, _ := service.FindAllWarehouseOut(orgId)
  3122. total = total + 1
  3123. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3124. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3125. number = number + total
  3126. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3127. //operation_time := time.Now().Unix()
  3128. creater := this.GetAdminUserInfo().AdminUser.Id
  3129. recordDateStr := time.Now().Format("2006-01-02")
  3130. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3131. record_date := recordDate.Unix()
  3132. warehouseOut := models.WarehouseOut{
  3133. WarehouseOutOrderNumber: warehousing_out_order,
  3134. OperationTime: record_date,
  3135. OrgId: orgId,
  3136. Creater: creater,
  3137. Ctime: ctime,
  3138. Status: 1,
  3139. WarehouseOutTime: record_date,
  3140. Type: 1,
  3141. SupplyCancelOutId: id,
  3142. SupplyWarehouseId: warehouse_out_id,
  3143. IsSys: 0,
  3144. }
  3145. //查询是否生成出库单
  3146. _, errcodes := service.FindStockOutByIsSys(orgId, 0, record_date)
  3147. if errcodes == gorm.ErrRecordNotFound {
  3148. service.AddSigleWarehouseOut(&warehouseOut)
  3149. }
  3150. outWarehouse, _ := service.GetlastWarehouseOutById(orgId, record_date)
  3151. fmt.Println("232332322332232323", outWarehouse)
  3152. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  3153. info := &models.WarehouseOutInfo{
  3154. WarehouseOutOrderNumber: outWarehouse.WarehouseOutOrderNumber,
  3155. WarehouseOutId: outWarehouse.ID,
  3156. WarehouseInfotId: 0,
  3157. GoodId: item.ProjectId,
  3158. GoodTypeId: goodObj.GoodTypeId,
  3159. Count: item.SupplyCount,
  3160. Price: item.Price,
  3161. TotalPrice: 0,
  3162. ProductDate: item.SupplyProductDate,
  3163. ExpiryDate: item.SupplyExpiryDate,
  3164. Type: 0,
  3165. Dealer: 0,
  3166. Manufacturer: item.ManufacturerId,
  3167. IsSys: 0,
  3168. SysRecordTime: record_date,
  3169. Number: item.SupplyBatchNumber,
  3170. LicenseNumber: item.SupplyLicenseNumber,
  3171. ConsumableType: 0,
  3172. SupplyCancelOutId: id,
  3173. OrgId: orgId,
  3174. SupplyWarehouseId: warehouse_out_id,
  3175. IsSource: item.Type,
  3176. }
  3177. //出库逻辑
  3178. parseDateErr := service.ConsumablesDeliveryNight(orgId, record_date, info, &warehouseOut, item.SupplyCount, creater, warehouse_out_id, id)
  3179. if parseDateErr != nil {
  3180. utils.ErrorLog(parseDateErr.Error())
  3181. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  3182. return
  3183. }
  3184. }
  3185. }
  3186. cancel := models.SpSupplierWarehouseCancel{
  3187. IsCheck: 1,
  3188. Checker: checker,
  3189. CheckTime: record_date,
  3190. }
  3191. err := service.CheckReturnOrder(id, orgId, cancel)
  3192. fmt.Println("3232233232322332232323232323322332232323232323")
  3193. if err == nil {
  3194. this.ServeSuccessJSON(map[string]interface{}{
  3195. "msg": "1",
  3196. "drug_name": "",
  3197. "dose": "",
  3198. "dose_unit": "",
  3199. "min_number": "",
  3200. "min_unit": "",
  3201. "max_unit": "",
  3202. })
  3203. return
  3204. }
  3205. }
  3206. func (this *SupplyOrderApiController) DeletePurchaseOrder() {
  3207. id, _ := this.GetInt64("id")
  3208. err := service.DeletePurchaseOrder(id)
  3209. if err == nil {
  3210. returnData := make(map[string]interface{}, 0)
  3211. returnData["msg"] = "ok"
  3212. this.ServeSuccessJSON(returnData)
  3213. return
  3214. } else {
  3215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3216. }
  3217. }
  3218. func (this *SupplyOrderApiController) DeleteGoodOrderById() {
  3219. id, _ := this.GetInt64("id")
  3220. err := service.DeleteGoodOrderById(id)
  3221. if err == nil {
  3222. returnData := make(map[string]interface{}, 0)
  3223. returnData["msg"] = "ok"
  3224. this.ServeSuccessJSON(returnData)
  3225. return
  3226. } else {
  3227. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3228. }
  3229. }
  3230. func (this *SupplyOrderApiController) DeleteReturnOrder() {
  3231. id, _ := this.GetInt64("id")
  3232. err := service.DeleteReturnOrder(id)
  3233. if err == nil {
  3234. returnData := make(map[string]interface{}, 0)
  3235. returnData["msg"] = "ok"
  3236. this.ServeSuccessJSON(returnData)
  3237. return
  3238. } else {
  3239. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3240. }
  3241. }
  3242. func (this *SupplyOrderApiController) DeleteReturnOrderById() {
  3243. id, _ := this.GetInt64("id")
  3244. err := service.DeleteReturnOrderById(id)
  3245. if err == nil {
  3246. returnData := make(map[string]interface{}, 0)
  3247. returnData["msg"] = "ok"
  3248. this.ServeSuccessJSON(returnData)
  3249. return
  3250. } else {
  3251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3252. }
  3253. }
  3254. func (this *SupplyOrderApiController) ModefyReturnOrder() {
  3255. id, _ := this.GetInt64("id")
  3256. err := service.ModefyReturnOrder(id)
  3257. //获取退库单据日期
  3258. cancel, _ := service.GetReturnOrderById(id)
  3259. orgId := this.GetAdminUserInfo().CurrentOrgId
  3260. if err == nil {
  3261. //获取退库单详情
  3262. list, _ := service.GetSupplyCancelOrderDetail(id, orgId)
  3263. for _, item := range list {
  3264. //药品
  3265. if item.IsSource == 1 {
  3266. base, _ := service.GetDrugDetailByDrugId(item.ProjectId)
  3267. //更改库存
  3268. if item.SupplyUnit == base.MaxUnit {
  3269. //退库
  3270. drugInfo := models.DrugWarehouseInfo{
  3271. StockMaxNumber: item.SupplyCount,
  3272. }
  3273. service.UpdateDrugWasehousring(item.ProjectId, item.SupplyWarehouseDetailInfo, drugInfo)
  3274. }
  3275. if item.SupplyType == base.MinUnit && base.MaxUnit != base.MinUnit {
  3276. drugInfo := models.DrugWarehouseInfo{
  3277. StockMinNumber: item.SupplyCount,
  3278. }
  3279. service.UpdateDrugWasehousringOne(item.ProjectId, item.SupplyWarehouseDetailInfo, drugInfo)
  3280. }
  3281. //删除流水
  3282. service.DeleteDrugWarehouseOutNight(item.ProjectId, item.WarehouseCancelId)
  3283. //查询出库订单
  3284. drugOut, _ := service.GetDrugWarehouseByDate(cancel.RecordDate, orgId)
  3285. drugOutList, _ := service.GetDrugWarehouseByIdList(drugOut.ID, orgId)
  3286. if len(drugOutList) == 0 {
  3287. service.UpdateDrugWarehouseById(drugOut.ID)
  3288. }
  3289. }
  3290. //耗材
  3291. if item.IsSource == 2 {
  3292. fmt.Println("item2332322323232332", item.SupplyCount)
  3293. //退库
  3294. info := models.WarehousingInfo{
  3295. StockCount: item.SupplyCount,
  3296. }
  3297. //更改库存
  3298. err := service.UpdateWarehousingInfoById(item.ProjectId, item.SupplyWarehouseDetailInfo, info)
  3299. fmt.Println(err)
  3300. //删除出库记录
  3301. service.DeleteGoodWarehouseOut(item.ProjectId, item.WarehouseCancelId, orgId)
  3302. //查询今日的出库单是
  3303. out, _ := service.GetWarehouseOutByDate(cancel.RecordDate, orgId)
  3304. warehouseOutList, _ := service.GetWarehouseOutById(out.ID, orgId)
  3305. if len(warehouseOutList) == 0 {
  3306. //删除出库单
  3307. service.DeleteWarehouseOutById(out.ID)
  3308. }
  3309. }
  3310. }
  3311. } else {
  3312. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3313. }
  3314. if err == nil {
  3315. returnData := make(map[string]interface{}, 0)
  3316. returnData["msg"] = "ok"
  3317. this.ServeSuccessJSON(returnData)
  3318. return
  3319. } else {
  3320. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3321. }
  3322. }
  3323. func (this *SupplyOrderApiController) GetGoodOrderDetailList() {
  3324. id, _ := this.GetInt64("id")
  3325. ids := this.GetString("ids")
  3326. orgId := this.GetAdminUserInfo().CurrentOrgId
  3327. if len(ids) == 0 {
  3328. out, err := service.GetGoodOrderDetail(id, orgId)
  3329. list, _ := service.GetSupplyWarehouseOutById(id, orgId)
  3330. for _, item := range list {
  3331. if item.IsSource == 1 {
  3332. waresingList, _ := service.GetAllDrugWaresingList(item.ProjectId, orgId)
  3333. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  3334. item.DrugWarehouseInfo = waresingList
  3335. item.SpBaseDrug = medical
  3336. }
  3337. if item.IsSource == 2 {
  3338. waresingList, _ := service.GetAllGoodWaresingList(item.ProjectId, orgId)
  3339. item.GoodWarehouseInfo = waresingList
  3340. }
  3341. }
  3342. drugList, _ := service.GetSupplyDrugList(orgId)
  3343. goodList, _ := service.GetSupplyGoodList(orgId)
  3344. supplyList, _ := service.GetSupplierList(orgId)
  3345. if err == nil {
  3346. this.ServeSuccessJSON(map[string]interface{}{
  3347. "out": out,
  3348. "list": list,
  3349. "goodList": goodList,
  3350. "drugList": drugList,
  3351. "supplyList": supplyList,
  3352. })
  3353. } else {
  3354. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3355. }
  3356. }
  3357. if len(ids) > 0 {
  3358. idArray := strings.Split(ids, ",")
  3359. out, err := service.GetGoodOrderDetail(id, orgId)
  3360. list, _ := service.GetSupplyWarehouseOutByIdOne(id, orgId, idArray)
  3361. for _, item := range list {
  3362. if item.IsSource == 1 {
  3363. waresingList, _ := service.GetAllDrugWaresingList(item.ProjectId, orgId)
  3364. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  3365. item.DrugWarehouseInfo = waresingList
  3366. item.SpBaseDrug = medical
  3367. }
  3368. if item.IsSource == 2 {
  3369. waresingList, _ := service.GetAllGoodWaresingList(item.ProjectId, orgId)
  3370. item.GoodWarehouseInfo = waresingList
  3371. }
  3372. }
  3373. drugList, _ := service.GetSupplyDrugList(orgId)
  3374. goodList, _ := service.GetSupplyGoodList(orgId)
  3375. supplyList, _ := service.GetSupplierList(orgId)
  3376. if err == nil {
  3377. this.ServeSuccessJSON(map[string]interface{}{
  3378. "out": out,
  3379. "list": list,
  3380. "goodList": goodList,
  3381. "drugList": drugList,
  3382. "supplyList": supplyList,
  3383. })
  3384. } else {
  3385. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3386. }
  3387. }
  3388. }