supply_order_api_contorller.go 128KB

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