supply_order_api_contorller.go 100KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875
  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. //获取供应商列表GetSupplyList
  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. //获取供应商列表GetSupplyList
  89. func (this *SupplyOrderApiController) GetSupplyList() {
  90. ctype, _ := this.GetInt64("ctype") //供应商类别
  91. page, _ := this.GetInt64("page") //页码
  92. limit, _ := this.GetInt64("limit") //每一页查出来的条数
  93. if page == 0 || limit == 0 {
  94. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "page或limit参数不能为空")
  95. return
  96. }
  97. //code := this.GetString("code") //供应商编号
  98. //sname := this.GetString("sname") //供应商名称
  99. //cname := this.GetString("cname") //联系人名字
  100. keyword := this.GetString("keyword") //供应商编号\供应商名称\联系人名字
  101. orgId := this.GetAdminUserInfo().CurrentOrgId
  102. //获取分页的数据
  103. list, total, err := service.GetSupplyList(ctype, page, limit, keyword)
  104. //获取供应商类别
  105. costClassify := "供应商类别"
  106. drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
  107. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  108. tmpmap := make(map[int64]string) //储存供应商类别
  109. namemap := make(map[string]string) //储存首要联系人
  110. phonemap := make(map[string]string) //手机号
  111. for i := 0; i < len(drugTypeList); i++ {
  112. k := int64(drugTypeList[i].Value)
  113. v := drugTypeList[i].Name
  114. tmpmap[k] = v
  115. }
  116. if err == nil {
  117. for i := 0; i < len(list); i++ {
  118. code := list[i].SupplierCode
  119. fistname, errs := service.FindName(code)
  120. if errs != nil && errs.Error() != "record not found" {
  121. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  122. return
  123. }
  124. namemap[code] = fistname.Name
  125. phonemap[code] = fistname.Phone
  126. }
  127. type SpSupplierNameList struct { //基于SpSupplierName结构体修改的,为了方便前端取数据整合了一下,删除了几个用不到的字段,添加了联系人名字和供应商类别两个字段
  128. ID int64
  129. SupplierCode string
  130. SupplierName string
  131. SupplierType int64
  132. VatRate float64
  133. Number string
  134. Bank string
  135. BankAccount string
  136. UserOrgId int64
  137. Status int64
  138. ContactsId int64
  139. ConName string //供应商主要联系人名字
  140. TypeName string //供应商类别
  141. Phone string //电话
  142. }
  143. //初始化该结构体
  144. tmplist := []*SpSupplierNameList{}
  145. for i := 0; i < len(list); i++ {
  146. var typename string //类别名称
  147. if list[i].SupplierType == 0 {
  148. typename = ""
  149. } else {
  150. typename = tmpmap[list[i].SupplierType]
  151. }
  152. tlist := &SpSupplierNameList{
  153. list[i].ID,
  154. list[i].SupplierCode,
  155. list[i].SupplierName,
  156. list[i].SupplierType,
  157. list[i].VatRate,
  158. list[i].Number,
  159. list[i].Bank,
  160. list[i].BankAccount,
  161. list[i].UserOrgId,
  162. list[i].Status,
  163. list[i].ContactsId,
  164. namemap[list[i].SupplierCode],
  165. typename,
  166. phonemap[list[i].SupplierCode],
  167. }
  168. tmplist = append(tmplist, tlist)
  169. }
  170. this.ServeSuccessJSON(map[string]interface{}{
  171. "list": tmplist,
  172. "total": total,
  173. })
  174. } else {
  175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  176. }
  177. }
  178. //保存供应商及联系人(用于更改)
  179. func (this *SupplyOrderApiController) UpdateSupply() {
  180. dataBody := make(map[string]interface{}, 0)
  181. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  182. if err != nil {
  183. utils.ErrorLog(err.Error())
  184. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  185. return
  186. }
  187. supplierName := dataBody["suppliername"].(string)
  188. if supplierName == "" {
  189. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称不能为空")
  190. return
  191. }
  192. //upplierCode := this.GetString("suppliercode") //供应商编码
  193. supplierCode := dataBody["suppliercode"].(string)
  194. if supplierCode == "" {
  195. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
  196. return
  197. }
  198. //supplierid, _ := this.GetInt64("id") //供应商id
  199. //fmt.Println(dataBody["id"])
  200. //utils.InfoLog("+++++++++++++前++++++++++++++++++", dataBody["id"])
  201. supplierid := int64(dataBody["id"].(float64))
  202. //utils.InfoLog("+++++++++++++后++++++++++++++++++", supplierid)
  203. if supplierid == 0 {
  204. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
  205. return
  206. }
  207. //查询供应商的信息
  208. supply, err := service.GetSupplyOne(supplierid)
  209. if err != nil {
  210. utils.ErrorLog(err.Error())
  211. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  212. return
  213. }
  214. if supplierName != supply.SupplierName {
  215. //判断供应商名称是否有重复的
  216. sbool, _ := service.FindSupplierName(supplierName)
  217. if sbool { //有重复的
  218. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
  219. return
  220. }
  221. }
  222. if supplierCode != supply.SupplierCode {
  223. //判断供应商编号是否有重复的
  224. codebool, _ := service.FindSupplierCode(supplierCode)
  225. if codebool {
  226. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
  227. return
  228. }
  229. }
  230. //supplierType, _ := this.GetInt64("suppliertype") //供应商类别
  231. if dataBody["suppliertype"] == "" || dataBody["suppliertype"] == 0 {
  232. var tmp float64 = 0
  233. dataBody["suppliertype"] = tmp
  234. }
  235. if dataBody["vatrate"] == "" {
  236. dataBody["vatrate"] = 0
  237. }
  238. supplierType := int64(dataBody["suppliertype"].(float64)) //供应商类别
  239. //vatRate, _ := this.GetFloat("vatrate") //增值税税率
  240. vatRate, _ := dataBody["suppliertype"].(float64) //增值税税率
  241. //number := this.GetString("number") //纳税人识别号
  242. number := dataBody["number"].(string) //纳税人识别号
  243. //bank := this.GetString("bank") //开户银行
  244. bank := dataBody["bank"].(string) //纳税人识别号
  245. //bankAccount := this.GetString("bankAccount") //银行账号
  246. bankAccount := dataBody["bankaccount"].(string)
  247. orgId := this.GetAdminUserInfo().CurrentOrgId
  248. //contacts := this.Get("contacts")//联系人
  249. //dataBody := make(map[string]interface{}, 0)
  250. //err = json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  251. //if err != nil {
  252. // utils.ErrorLog(err.Error())
  253. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  254. // return
  255. //}
  256. //保存联系人
  257. if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
  258. thisStockIn, _ := dataBody["contacts"].([]interface{})
  259. if len(thisStockIn) > 0 {
  260. if len(thisStockIn) == 1 {
  261. for _, item := range thisStockIn {
  262. items := item.(map[string]interface{})
  263. items["is_first"] = 1
  264. }
  265. }
  266. tmodify := this.GetAdminUserInfo().AdminUser.Id
  267. err = service.UpdateSupplyAndContact(thisStockIn, supplierid, orgId, supplierType, tmodify, supplierCode, supplierName, number, bank, bankAccount, vatRate)
  268. if err != nil {
  269. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  270. return
  271. }
  272. } else {
  273. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
  274. return
  275. }
  276. }
  277. this.ServeSuccessJSON(map[string]interface{}{
  278. "list": "保存成功",
  279. })
  280. return
  281. }
  282. //获取单条供应商和涉及到的联系人记录
  283. func (this *SupplyOrderApiController) GetSupplyAndContactOne() {
  284. id, _ := this.GetInt64("id")
  285. if id == 0 {
  286. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
  287. return
  288. }
  289. supply, contact, err := service.GetSupplyAndContactOne(id)
  290. //获取供应商类别
  291. orgId := this.GetAdminUserInfo().CurrentOrgId
  292. costClassify := "供应商类别"
  293. drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
  294. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  295. tmpmap := make(map[int64]string) //储存供应商类别
  296. for i := 0; i < len(drugTypeList); i++ {
  297. k := int64(drugTypeList[i].Value)
  298. v := drugTypeList[i].Name
  299. tmpmap[k] = v
  300. }
  301. type SpSupplierNameList struct { //基于SpSupplierName结构体修改的,为了方便前端取数据整合了一下,删除了几个用不到的字段,添加了联系人名字和供应商类别两个字段
  302. Id int64 `json:"id"`
  303. Suppliercode string `json:"suppliercode"`
  304. Suppliername string `json:"suppliername"`
  305. Suppliertype int64 `json:"suppliertype"`
  306. Vatrate float64 `json:"vatrate"`
  307. Number string `json:"number"`
  308. Bank string `json:"bank"`
  309. Bankaccount string `json:"bankaccount"`
  310. Userorgid int64 `json:"userorgid"`
  311. Status int64 `json:"status"`
  312. Contactsid int64 `json:"contactsid"`
  313. Typename string `json:"typename"` //供应商类别
  314. }
  315. var typename string //类别名称
  316. if supply.SupplierType == 0 {
  317. typename = ""
  318. } else {
  319. typename = tmpmap[supply.SupplierType]
  320. }
  321. tlist := &SpSupplierNameList{
  322. supply.ID,
  323. supply.SupplierCode,
  324. supply.SupplierName,
  325. supply.SupplierType,
  326. supply.VatRate,
  327. supply.Number,
  328. supply.Bank,
  329. supply.BankAccount,
  330. supply.UserOrgId,
  331. supply.Status,
  332. supply.ContactsId,
  333. typename,
  334. }
  335. if err != nil {
  336. utils.ErrorLog(err.Error())
  337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  338. return
  339. }
  340. fmt.Println(tlist)
  341. this.ServeSuccessJSON(map[string]interface{}{
  342. "supply": tlist,
  343. "contact": contact,
  344. })
  345. return
  346. }
  347. //获取供应商类别
  348. func (this *SupplyOrderApiController) GetSupplyType() {
  349. orgId := this.GetAdminUserInfo().CurrentOrgId
  350. costClassify := "供应商类别"
  351. drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
  352. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  353. this.ServeSuccessJSON(map[string]interface{}{
  354. "list": drugTypeList,
  355. })
  356. return
  357. }
  358. //删除供应商及联系人
  359. func (this *SupplyOrderApiController) DelSupply() {
  360. //拿到供应商的id
  361. suid, _ := this.GetInt64("id")
  362. if suid == 0 {
  363. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
  364. return
  365. }
  366. supply := models.SpSupplierName{
  367. ID: suid,
  368. }
  369. err := service.DelSupply(supply)
  370. if err != nil {
  371. utils.ErrorLog(err.Error())
  372. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  373. return
  374. }
  375. this.ServeSuccessJSON(map[string]interface{}{
  376. "list": "删除成功",
  377. })
  378. return
  379. }
  380. //删除单条联系人记录
  381. func (this *SupplyOrderApiController) DelContactOne() {
  382. id, _ := this.GetInt64("id")
  383. if id == 0 {
  384. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人id不能为空")
  385. return
  386. }
  387. err := service.DelContactOne(id)
  388. if err != nil {
  389. utils.ErrorLog(err.Error())
  390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  391. return
  392. }
  393. this.ServeSuccessJSON(map[string]interface{}{
  394. "list": "删除成功",
  395. })
  396. return
  397. }
  398. //获取供应商编码
  399. func (this *SupplyOrderApiController) GetSupplyCode() {
  400. supply, err := service.GetSuppliyCode()
  401. if err != nil {
  402. return
  403. }
  404. if len(supply) == 0 { //如果数据库中没有gys类型的编码则设置默认值
  405. //supply[0].SupplierCode ="gys001"
  406. supply = []*models.SpSupplierName{
  407. {
  408. SupplierCode: "gys001",
  409. },
  410. }
  411. } else { //获取数据库中最大的编码值,并加一
  412. tmp := supply[0].SupplierCode
  413. tmp = tmp[3:]
  414. var code int
  415. code, err = strconv.Atoi(tmp)
  416. code++
  417. tmp = strconv.Itoa(code)
  418. for len(tmp) < 3 {
  419. tmp = "0" + tmp
  420. }
  421. tmp = "gys" + tmp
  422. supply[0].SupplierCode = tmp
  423. }
  424. this.ServeSuccessJSON(map[string]interface{}{
  425. "supplycode": supply,
  426. })
  427. return
  428. }
  429. //保存供应商
  430. func (this *SupplyOrderApiController) SaveSupply() {
  431. //supplierName := this.GetString("suppliername") //供应商名称
  432. dataBody := make(map[string]interface{}, 0)
  433. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  434. if err != nil {
  435. utils.ErrorLog(err.Error())
  436. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  437. return
  438. }
  439. supplierName := dataBody["suppliername"].(string)
  440. if supplierName == "" {
  441. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称不能为空")
  442. return
  443. }
  444. //判断供应商名称是否有重复的
  445. sbool, _ := service.FindSupplierName(supplierName)
  446. if sbool { //有重复的
  447. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
  448. return
  449. }
  450. //supplierCode := this.GetString("suppliercode") //供应商编码
  451. supplierCode := dataBody["suppliercode"].(string) //供应商编码
  452. if supplierCode == "" {
  453. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
  454. return
  455. }
  456. //判断供应商编号是否有重复的
  457. codebool, _ := service.FindSupplierCode(supplierCode)
  458. if codebool {
  459. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
  460. return
  461. }
  462. if dataBody["suppliertype"] == "" {
  463. var tmp int64 = 0
  464. dataBody["suppliertype"] = tmp
  465. }
  466. if dataBody["vatrate"] == "" {
  467. dataBody["vatrate"] = 0
  468. }
  469. //supplierType, _ := this.GetInt64("suppliertype")
  470. supplierType := dataBody["suppliertype"].(int64) //供应商类别
  471. //vatRate, _ := this.GetFloat("vatrate")
  472. vatRate, _ := dataBody["suppliertype"].(float64) //增值税税率
  473. //number := this.GetString("number")
  474. number := dataBody["number"].(string)
  475. //bank := this.GetString("bank")
  476. bank := dataBody["bank"].(string)
  477. //bankAccount := this.GetString("bankAccount")
  478. bankAccount := dataBody["bankaccount"].(string)
  479. orgId := this.GetAdminUserInfo().CurrentOrgId
  480. //contacts := this.Get("contacts")//联系人
  481. //err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  482. //if err != nil {
  483. // utils.ErrorLog(err.Error())
  484. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  485. // return
  486. //}
  487. //保存联系人
  488. if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
  489. thisStockIn, _ := dataBody["contacts"].([]interface{})
  490. if len(thisStockIn) > 0 {
  491. if len(thisStockIn) == 1 {
  492. for _, item := range thisStockIn {
  493. items := item.(map[string]interface{})
  494. items["is_first"] = 1
  495. }
  496. }
  497. tcreater := this.GetAdminUserInfo().AdminUser.Id
  498. err = service.SaveSupplyAndContact(thisStockIn, orgId, supplierType, tcreater, supplierCode, supplierName, number, bank, bankAccount, vatRate)
  499. if err != nil {
  500. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  501. return
  502. }
  503. } else {
  504. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
  505. return
  506. }
  507. }
  508. this.ServeSuccessJSON(map[string]interface{}{
  509. "list": "保存成功",
  510. })
  511. return
  512. }
  513. func (this *SupplyOrderApiController) GetInitOrder() {
  514. orgId := this.GetAdminUserInfo().CurrentOrgId
  515. //获取药品库数据
  516. baseList, _ := service.GetSupplyDrugList(orgId)
  517. goodList, _ := service.GetSupplyGoodList(orgId)
  518. manufactuerList, _ := service.GetAllManufacturerList(orgId)
  519. goodTypeList, _ := service.GetAllGoodType(orgId)
  520. supplyList, _ := service.GetSupplierList(orgId)
  521. var drugType = "药品类型"
  522. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  523. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  524. this.ServeSuccessJSON(map[string]interface{}{
  525. "drugList": baseList,
  526. "goodList": goodList,
  527. "manufactuerList": manufactuerList,
  528. "goodTypeList": goodTypeList,
  529. "drugTypeList": drugTypeList,
  530. "supplyList": supplyList,
  531. })
  532. return
  533. }
  534. func (this *SupplyOrderApiController) SavePurchaseOrder() {
  535. supplier_id, _ := this.GetInt64("supplier_name")
  536. start_time := this.GetString("start_time")
  537. end_time := this.GetString("end_time")
  538. timeLayout := "2006-01-02"
  539. loc, _ := time.LoadLocation("Local")
  540. var startTime int64
  541. if len(start_time) > 0 {
  542. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  543. if err != nil {
  544. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  545. return
  546. }
  547. startTime = theTime.Unix()
  548. }
  549. var endTime int64
  550. if len(end_time) > 0 {
  551. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  552. if err != nil {
  553. utils.ErrorLog(err.Error())
  554. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  555. return
  556. }
  557. endTime = theTime.Unix()
  558. }
  559. rate_of_concession := this.GetString("rate_of_concession")
  560. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  561. discount_amount := this.GetString("discount_amount")
  562. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  563. dataBody := make(map[string]interface{}, 0)
  564. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  565. if err != nil {
  566. utils.ErrorLog(err.Error())
  567. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  568. return
  569. }
  570. //生成购货订单
  571. timeStr := time.Now().Format("2006-01-02")
  572. timeArr := strings.Split(timeStr, "-")
  573. orgId := this.GetAdminUserInfo().CurrentOrgId
  574. total, _ := service.FindAllSupplyOrder(orgId)
  575. total = total + 1
  576. warehousing_order := "CGDD" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  577. recordDateStr := time.Now().Format("2006-01-02")
  578. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  579. fmt.Scan("parseDateErr", parseDateErr)
  580. record_date := recordDate.Unix()
  581. return_remake := dataBody["return_remake"].(string)
  582. info := models.SupplierWarehouseInfo{
  583. Number: warehousing_order,
  584. UserOrgId: orgId,
  585. Creater: this.GetAdminUserInfo().AdminUser.Id,
  586. Ctime: time.Now().Unix(),
  587. Mtime: 0,
  588. Status: 1,
  589. RecordDate: record_date,
  590. IsCheck: 2,
  591. RateOfConcession: rate_of_concession_float,
  592. DiscountAmount: discount_amount_float,
  593. DocumentDate: startTime,
  594. DeliveryDate: endTime,
  595. SupplierId: supplier_id,
  596. IsWarehouse: 2,
  597. ReturnRemake: return_remake,
  598. }
  599. err = service.CreateSupplyWarehouse(info)
  600. warehouseInfo, _ := service.FindLastSupplyWarehouseInfo(orgId)
  601. var warehousingInfo []*models.SupplierWarehousingInfoOrder
  602. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  603. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  604. if len(thisStockIn) > 0 {
  605. for _, item := range thisStockIn {
  606. items := item.(map[string]interface{})
  607. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  608. utils.ErrorLog("project_id")
  609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  610. return
  611. }
  612. project_id := int64(items["project_id"].(float64))
  613. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  614. utils.ErrorLog("supply_count")
  615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  616. return
  617. }
  618. supply_count := int64(items["supply_count"].(float64))
  619. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  620. utils.ErrorLog("supply_license_number")
  621. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  622. return
  623. }
  624. supply_license_number := items["supply_license_number"].(string)
  625. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  626. utils.ErrorLog("supply_price")
  627. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  628. return
  629. }
  630. supply_price := items["supply_price"].(string)
  631. supply_price_float, _ := strconv.ParseFloat(supply_price, 64)
  632. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  633. utils.ErrorLog("supply_remake")
  634. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  635. return
  636. }
  637. supply_remake := items["supply_remake"].(string)
  638. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  639. utils.ErrorLog("supply_total_price")
  640. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  641. return
  642. }
  643. supply_total_price := items["supply_total_price"].(string)
  644. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  645. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  646. utils.ErrorLog("type")
  647. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  648. return
  649. }
  650. is_source := int64(items["type"].(float64))
  651. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  652. utils.ErrorLog("supply_type")
  653. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  654. return
  655. }
  656. supply_type := items["supply_type"].(string)
  657. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  658. utils.ErrorLog("supply_specification_name")
  659. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  660. return
  661. }
  662. supply_specification_name := items["supply_specification_name"].(string)
  663. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  664. utils.ErrorLog("supply_total")
  665. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  666. return
  667. }
  668. supply_total := items["supply_total"].(string)
  669. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  670. utils.ErrorLog("supply_manufacturer")
  671. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  672. return
  673. }
  674. supply_manufacturer := items["supply_manufacturer"].(string)
  675. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  676. utils.ErrorLog("name")
  677. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  678. return
  679. }
  680. name := items["name"].(string)
  681. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  682. utils.ErrorLog("supply_unit")
  683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  684. return
  685. }
  686. supply_unit := items["supply_unit"].(string)
  687. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  688. utils.ErrorLog("manufacturer_id")
  689. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  690. return
  691. }
  692. manufacturer_id := int64(items["manufacturer_id"].(float64))
  693. order := models.SupplierWarehousingInfoOrder{
  694. OrderNumber: warehousing_order,
  695. IsSource: is_source,
  696. Count: supply_count,
  697. Price: supply_price_float,
  698. Amount: supply_total_price_float,
  699. Remark: supply_remake,
  700. UserOrgId: orgId,
  701. Ctime: time.Now().Unix(),
  702. Status: 1,
  703. Mtime: 0,
  704. WarehousingId: warehouseInfo.ID,
  705. ProjectId: project_id,
  706. SupplyLicenseNumber: supply_license_number,
  707. SupplyType: supply_type,
  708. SupplySpecificationName: supply_specification_name,
  709. SupplyTotal: supply_total,
  710. SupplyManufacturer: supply_manufacturer,
  711. Name: name,
  712. SupplyUnit: supply_unit,
  713. ManufacturerId: manufacturer_id,
  714. }
  715. warehousingInfo = append(warehousingInfo, &order)
  716. }
  717. }
  718. }
  719. for _, item := range warehousingInfo {
  720. err = service.CreateSupplyWarehousingOrder(item)
  721. }
  722. //查询
  723. orderInfo, err := service.GetSupplyWarehousingOrderInfo(warehouseInfo.ID)
  724. if err == nil {
  725. this.ServeSuccessJSON(map[string]interface{}{
  726. "order": warehousingInfo,
  727. "warehouseInfo": warehouseInfo,
  728. "orderInfo": orderInfo,
  729. })
  730. } else {
  731. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  732. }
  733. }
  734. func (this *SupplyOrderApiController) GetAllSupply() {
  735. orgId := this.GetAdminUserInfo().CurrentOrgId
  736. appId := this.GetAdminUserInfo().CurrentAppId
  737. supplyList, err := service.GetSupplierList(orgId)
  738. doctorList, err := service.GetAllDoctorSix(orgId, appId)
  739. if err == nil {
  740. this.ServeSuccessJSON(map[string]interface{}{
  741. "supplyList": supplyList,
  742. "doctorList": doctorList,
  743. })
  744. } else {
  745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  746. }
  747. }
  748. func (this *SupplyOrderApiController) GetAllPurchaseOrderList() {
  749. check_id, _ := this.GetInt64("check_id")
  750. start_time := this.GetString("start_time")
  751. end_time := this.GetString("end_time")
  752. timeLayout := "2006-01-02"
  753. loc, _ := time.LoadLocation("Local")
  754. var startTime int64
  755. if len(start_time) > 0 {
  756. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  757. if err != nil {
  758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  759. return
  760. }
  761. startTime = theTime.Unix()
  762. }
  763. var endTime int64
  764. if len(end_time) > 0 {
  765. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  766. if err != nil {
  767. utils.ErrorLog(err.Error())
  768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  769. return
  770. }
  771. endTime = theTime.Unix()
  772. }
  773. keyword := this.GetString("keyword")
  774. page, _ := this.GetInt64("page")
  775. limit, _ := this.GetInt64("limit")
  776. orgId := this.GetAdminUserInfo().CurrentOrgId
  777. list, total, err := service.GetAllPurchaseOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
  778. if err == nil {
  779. this.ServeSuccessJSON(map[string]interface{}{
  780. "list": list,
  781. "total": total,
  782. })
  783. } else {
  784. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  785. }
  786. }
  787. func (this *SupplyOrderApiController) UpdatePurchaseOrder() {
  788. dataBody := make(map[string]interface{}, 0)
  789. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  790. if err != nil {
  791. utils.ErrorLog(err.Error())
  792. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  793. return
  794. }
  795. supplier_id, _ := this.GetInt64("supplier_name")
  796. start_time := this.GetString("start_time")
  797. end_time := this.GetString("end_time")
  798. timeLayout := "2006-01-02"
  799. loc, _ := time.LoadLocation("Local")
  800. var startTime int64
  801. if len(start_time) > 0 {
  802. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  803. if err != nil {
  804. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  805. return
  806. }
  807. startTime = theTime.Unix()
  808. }
  809. var endTime int64
  810. if len(end_time) > 0 {
  811. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  812. if err != nil {
  813. utils.ErrorLog(err.Error())
  814. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  815. return
  816. }
  817. endTime = theTime.Unix()
  818. }
  819. rate_of_concession := this.GetString("rate_of_concession")
  820. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  821. discount_amount := this.GetString("discount_amount")
  822. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  823. warehousing_id, _ := this.GetInt64("id")
  824. number := this.GetString("number")
  825. return_remake := dataBody["return_remake"].(string)
  826. orgId := this.GetAdminUserInfo().CurrentOrgId
  827. info := models.SupplierWarehouseInfo{
  828. RateOfConcession: rate_of_concession_float,
  829. DiscountAmount: discount_amount_float,
  830. DocumentDate: startTime,
  831. DeliveryDate: endTime,
  832. SupplierId: supplier_id,
  833. Mtime: time.Now().Unix(),
  834. ReturnRemake: return_remake,
  835. }
  836. service.ModefySupplyWarehouseInfo(warehousing_id, info)
  837. var warehousingInfo []*models.SupplierWarehousingInfoOrder
  838. var updateWarehousingInfo []*models.SupplierWarehousingInfoOrder
  839. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  840. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  841. if len(thisStockIn) > 0 {
  842. for _, item := range thisStockIn {
  843. items := item.(map[string]interface{})
  844. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  845. utils.ErrorLog("id")
  846. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  847. return
  848. }
  849. id := int64(items["id"].(float64))
  850. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  851. utils.ErrorLog("project_id")
  852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  853. return
  854. }
  855. project_id := int64(items["project_id"].(float64))
  856. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  857. utils.ErrorLog("supply_count")
  858. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  859. return
  860. }
  861. supply_count := int64(items["supply_count"].(float64))
  862. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  863. utils.ErrorLog("supply_license_number")
  864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  865. return
  866. }
  867. supply_license_number := items["supply_license_number"].(string)
  868. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  869. utils.ErrorLog("supply_price")
  870. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  871. return
  872. }
  873. supply_price := items["supply_price"].(string)
  874. supply_price_float, _ := strconv.ParseFloat(supply_price, 64)
  875. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  876. utils.ErrorLog("supply_remake")
  877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  878. return
  879. }
  880. supply_remake := items["supply_remake"].(string)
  881. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  882. utils.ErrorLog("supply_total_price")
  883. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  884. return
  885. }
  886. supply_total_price := items["supply_total_price"].(string)
  887. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  888. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  889. utils.ErrorLog("type")
  890. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  891. return
  892. }
  893. is_source := int64(items["type"].(float64))
  894. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  895. utils.ErrorLog("supply_type")
  896. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  897. return
  898. }
  899. supply_type := items["supply_type"].(string)
  900. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  901. utils.ErrorLog("supply_specification_name")
  902. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  903. return
  904. }
  905. supply_specification_name := items["supply_specification_name"].(string)
  906. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  907. utils.ErrorLog("supply_total")
  908. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  909. return
  910. }
  911. supply_total := items["supply_total"].(string)
  912. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  913. utils.ErrorLog("supply_manufacturer")
  914. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  915. return
  916. }
  917. supply_manufacturer := items["supply_manufacturer"].(string)
  918. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  919. utils.ErrorLog("name")
  920. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  921. return
  922. }
  923. name := items["name"].(string)
  924. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  925. utils.ErrorLog("supply_unit")
  926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  927. return
  928. }
  929. supply_unit := items["supply_unit"].(string)
  930. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  931. utils.ErrorLog("manufacturer_id")
  932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  933. return
  934. }
  935. manufacturer_id := int64(items["manufacturer_id"].(float64))
  936. if id > 0 {
  937. order := models.SupplierWarehousingInfoOrder{
  938. ID: id,
  939. IsSource: is_source,
  940. Count: supply_count,
  941. Price: supply_price_float,
  942. Amount: supply_total_price_float,
  943. Remark: supply_remake,
  944. Ctime: time.Now().Unix(),
  945. Status: 1,
  946. Mtime: 0,
  947. ProjectId: project_id,
  948. SupplyLicenseNumber: supply_license_number,
  949. SupplyType: supply_type,
  950. SupplySpecificationName: supply_specification_name,
  951. SupplyTotal: supply_total,
  952. SupplyManufacturer: supply_manufacturer,
  953. Name: name,
  954. SupplyUnit: supply_unit,
  955. ManufacturerId: manufacturer_id,
  956. }
  957. updateWarehousingInfo = append(updateWarehousingInfo, &order)
  958. }
  959. if id == 0 {
  960. order := models.SupplierWarehousingInfoOrder{
  961. OrderNumber: number,
  962. IsSource: is_source,
  963. Count: supply_count,
  964. Price: supply_price_float,
  965. Amount: supply_total_price_float,
  966. Remark: supply_remake,
  967. UserOrgId: orgId,
  968. Ctime: time.Now().Unix(),
  969. Status: 1,
  970. Mtime: 0,
  971. WarehousingId: warehousing_id,
  972. ProjectId: project_id,
  973. SupplyLicenseNumber: supply_license_number,
  974. SupplyType: supply_type,
  975. SupplySpecificationName: supply_specification_name,
  976. SupplyTotal: supply_total,
  977. SupplyManufacturer: supply_manufacturer,
  978. Name: name,
  979. SupplyUnit: supply_unit,
  980. ManufacturerId: manufacturer_id,
  981. }
  982. warehousingInfo = append(warehousingInfo, &order)
  983. }
  984. }
  985. }
  986. if len(warehousingInfo) > 0 {
  987. for _, item := range warehousingInfo {
  988. service.CreateSupplyWarehousingOrder(item)
  989. }
  990. }
  991. if len(updateWarehousingInfo) > 0 {
  992. for _, item := range updateWarehousingInfo {
  993. service.ModifySupplyWarehouseOrder(item)
  994. }
  995. }
  996. this.ServeSuccessJSON(map[string]interface{}{
  997. "warehousingInfo": warehousingInfo,
  998. })
  999. }
  1000. }
  1001. func (this *SupplyOrderApiController) UpdateSupplyWaresing() {
  1002. id, _ := this.GetInt64("id")
  1003. recordDateStr := time.Now().Format("2006-01-02")
  1004. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1005. record_date := recordDate.Unix()
  1006. checker := this.GetAdminUserInfo().AdminUser.Id
  1007. info := models.SupplierWarehouseInfo{
  1008. Mtime: time.Now().Unix(),
  1009. Status: 1,
  1010. IsCheck: 1,
  1011. Checker: checker,
  1012. CheckTime: record_date,
  1013. }
  1014. parseDateErr := service.UpdateSupplyWaresing(id, info)
  1015. if parseDateErr == nil {
  1016. this.ServeSuccessJSON(map[string]interface{}{
  1017. "info": info,
  1018. })
  1019. } else {
  1020. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1021. }
  1022. }
  1023. func (this *SupplyOrderApiController) GetPurchaseOrderDetail() {
  1024. id, _ := this.GetInt64("id")
  1025. info, _ := service.GetPurchaseOrderDetail(id)
  1026. //查询
  1027. orderInfo, err := service.GetSupplyWarehousingOrderInfo(id)
  1028. orgId := this.GetAdminUserInfo().CurrentOrgId
  1029. supplyList, _ := service.GetSupplierList(orgId)
  1030. //获取药品库数据
  1031. baseList, _ := service.GetSupplyDrugList(orgId)
  1032. goodList, _ := service.GetSupplyGoodList(orgId)
  1033. if err == nil {
  1034. this.ServeSuccessJSON(map[string]interface{}{
  1035. "info": info,
  1036. "orderInfo": orderInfo,
  1037. "supplyList": supplyList,
  1038. "baseList": baseList,
  1039. "goodList": goodList,
  1040. })
  1041. } else {
  1042. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1043. }
  1044. }
  1045. func (this *SupplyOrderApiController) AddGoodOrder() {
  1046. dataBody := make(map[string]interface{}, 0)
  1047. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1048. if err != nil {
  1049. utils.ErrorLog(err.Error())
  1050. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1051. return
  1052. }
  1053. supplier_id, _ := this.GetInt64("supplier_id")
  1054. start_time := this.GetString("start")
  1055. timeLayout := "2006-01-02"
  1056. loc, _ := time.LoadLocation("Local")
  1057. var startTime int64
  1058. if len(start_time) > 0 {
  1059. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1060. if err != nil {
  1061. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1062. return
  1063. }
  1064. startTime = theTime.Unix()
  1065. }
  1066. arrerage := this.GetString("arrerage")
  1067. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  1068. payment := this.GetString("payment")
  1069. payment_float, _ := strconv.ParseFloat(payment, 64)
  1070. warehousing_id, _ := this.GetInt64("warehousing_id")
  1071. number := this.GetString("number")
  1072. rate_of_concession := this.GetString("rate_of_concession")
  1073. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  1074. discount_amount := this.GetString("discount_amount")
  1075. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  1076. return_remake := dataBody["return_remake"].(string)
  1077. orgId := this.GetAdminUserInfo().CurrentOrgId
  1078. creater := this.GetAdminUserInfo().AdminUser.Id
  1079. //生成购货单
  1080. timeStr := time.Now().Format("2006-01-02")
  1081. timeArr := strings.Split(timeStr, "-")
  1082. total, _ := service.FindAllSupplyWarehouseOutOrder(orgId)
  1083. total = total + 1
  1084. warehousing_order := "CG" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  1085. recordDateStr := time.Now().Format("2006-01-02")
  1086. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1087. warehouse_out := models.SpSupplierWarehouseOut{
  1088. Number: number,
  1089. UserOrgId: orgId,
  1090. Creater: creater,
  1091. Ctime: time.Now().Unix(),
  1092. Mtime: 0,
  1093. Status: 1,
  1094. RecordDate: recordDate.Unix(),
  1095. IsCheck: 2,
  1096. WarehousingId: warehousing_id,
  1097. GoodNumber: warehousing_order,
  1098. Arrearage: arrerage_float,
  1099. Payment: payment_float,
  1100. RateOfConcession: rate_of_concession_float,
  1101. DiscountAmount: discount_amount_float,
  1102. DocumentDate: startTime,
  1103. SupplierId: supplier_id,
  1104. Checker: 0,
  1105. CheckTime: 0,
  1106. ReturnRemake: return_remake,
  1107. }
  1108. service.CreateSupplyWarehouseOut(warehouse_out)
  1109. //获取最后一条
  1110. warehouseOut, _ := service.FindSupplyWarehouseOutById(orgId)
  1111. var warehousingOut []*models.SpSupplierWarehousingOutOrder
  1112. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  1113. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  1114. if len(thisStockIn) > 0 {
  1115. for _, item := range thisStockIn {
  1116. items := item.(map[string]interface{})
  1117. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  1118. utils.ErrorLog("supply_count")
  1119. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1120. return
  1121. }
  1122. supply_count := int64(items["supply_count"].(float64))
  1123. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1124. utils.ErrorLog("id")
  1125. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1126. return
  1127. }
  1128. id := int64(items["id"].(float64))
  1129. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  1130. utils.ErrorLog("manufacturer_id")
  1131. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1132. return
  1133. }
  1134. manufacturer_id := int64(items["manufacturer_id"].(float64))
  1135. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1136. utils.ErrorLog("name")
  1137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1138. return
  1139. }
  1140. name := items["name"].(string)
  1141. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  1142. utils.ErrorLog("order_number")
  1143. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1144. return
  1145. }
  1146. order_number := items["order_number"].(string)
  1147. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  1148. utils.ErrorLog("supply_price")
  1149. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1150. return
  1151. }
  1152. supply_price := items["supply_price"].(string)
  1153. price_float, _ := strconv.ParseFloat(supply_price, 64)
  1154. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  1155. utils.ErrorLog("supply_total_price")
  1156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1157. return
  1158. }
  1159. supply_total_price := items["supply_total_price"].(string)
  1160. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  1161. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  1162. utils.ErrorLog("project_id")
  1163. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1164. return
  1165. }
  1166. project_id := int64(items["project_id"].(float64))
  1167. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  1168. utils.ErrorLog("supply_remake")
  1169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1170. return
  1171. }
  1172. supply_remake := items["supply_remake"].(string)
  1173. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  1174. utils.ErrorLog("supply_batch_number")
  1175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1176. return
  1177. }
  1178. supply_batch_number := items["supply_batch_number"].(string)
  1179. var supply_expiry_date_time int64
  1180. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "string" {
  1181. utils.ErrorLog("supply_expiry_date")
  1182. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1183. return
  1184. }
  1185. supply_expiry_date := items["supply_expiry_date"].(string)
  1186. if len(supply_expiry_date) > 0 {
  1187. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_expiry_date+" 00:00:00", loc)
  1188. if err != nil {
  1189. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1190. return
  1191. }
  1192. supply_expiry_date_time = theTime.Unix()
  1193. }
  1194. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  1195. utils.ErrorLog("supply_license_number")
  1196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1197. return
  1198. }
  1199. supply_license_number := items["supply_license_number"].(string)
  1200. var supply_product_date_time int64
  1201. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "string" {
  1202. utils.ErrorLog("supply_product_date")
  1203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1204. return
  1205. }
  1206. supply_product_date := items["supply_product_date"].(string)
  1207. if len(supply_product_date) > 0 {
  1208. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_product_date+" 00:00:00", loc)
  1209. if err != nil {
  1210. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1211. return
  1212. }
  1213. supply_product_date_time = theTime.Unix()
  1214. }
  1215. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  1216. utils.ErrorLog("supply_specification_name")
  1217. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1218. return
  1219. }
  1220. supply_specification_name := items["supply_specification_name"].(string)
  1221. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  1222. utils.ErrorLog("supply_total")
  1223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1224. return
  1225. }
  1226. supply_total := items["supply_total"].(string)
  1227. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  1228. utils.ErrorLog("supply_type")
  1229. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1230. return
  1231. }
  1232. supply_type := items["supply_type"].(string)
  1233. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  1234. utils.ErrorLog("supply_unit")
  1235. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1236. return
  1237. }
  1238. supply_unit := items["supply_unit"].(string)
  1239. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1240. utils.ErrorLog("type")
  1241. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1242. return
  1243. }
  1244. is_source := int64(items["type"].(float64))
  1245. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  1246. utils.ErrorLog("supply_manufacturer")
  1247. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1248. return
  1249. }
  1250. supply_manufacturer := items["supply_manufacturer"].(string)
  1251. order := models.SpSupplierWarehousingOutOrder{
  1252. OrderNumber: order_number,
  1253. ProjectId: project_id,
  1254. IsSource: is_source,
  1255. Count: supply_count,
  1256. Amount: supply_total_price_float,
  1257. Price: price_float,
  1258. Remark: supply_remake,
  1259. IsCheck: 2,
  1260. UserOrgId: orgId,
  1261. Status: 1,
  1262. Ctime: time.Now().Unix(),
  1263. Mtime: 0,
  1264. WarehouseOutId: warehouseOut.ID,
  1265. Type: 1,
  1266. SupplyBatchNumber: supply_batch_number,
  1267. SupplyProductDate: supply_product_date_time,
  1268. SupplyExpiryDate: supply_expiry_date_time,
  1269. WarehousingId: warehousing_id,
  1270. WarehouseInfoId: id,
  1271. SupplyType: supply_type,
  1272. SupplyUnit: supply_unit,
  1273. SupplyTotal: supply_total,
  1274. SupplySpecificationName: supply_specification_name,
  1275. SupplyLicenseNumber: supply_license_number,
  1276. Name: name,
  1277. ManufacturerId: manufacturer_id,
  1278. GoodNumber: warehouseOut.GoodNumber,
  1279. SupplyManufacturer: supply_manufacturer,
  1280. }
  1281. warehousingOut = append(warehousingOut, &order)
  1282. }
  1283. }
  1284. }
  1285. for _, item := range warehousingOut {
  1286. //如果是手动新增的,type 等于2
  1287. if item.WarehouseInfoId == 0 {
  1288. item.Type = 2
  1289. }
  1290. err = service.CreateSupplyWarehousOutOrder(item)
  1291. }
  1292. list, parseDateErr := service.GetSupplyWarehouseOutById(warehouseOut.ID, orgId)
  1293. if parseDateErr == nil {
  1294. this.ServeSuccessJSON(map[string]interface{}{
  1295. "list": list,
  1296. "warehouseOut": warehouseOut,
  1297. })
  1298. } else {
  1299. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1300. }
  1301. }
  1302. func (this *SupplyOrderApiController) GetAllGoodOderList() {
  1303. check_id, _ := this.GetInt64("check_id")
  1304. start_time := this.GetString("start_time")
  1305. end_time := this.GetString("end_time")
  1306. keyword := this.GetString("keyword")
  1307. page, _ := this.GetInt64("page")
  1308. limit, _ := this.GetInt64("limit")
  1309. timeLayout := "2006-01-02"
  1310. loc, _ := time.LoadLocation("Local")
  1311. var startTime int64
  1312. if len(start_time) > 0 {
  1313. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1314. if err != nil {
  1315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1316. return
  1317. }
  1318. startTime = theTime.Unix()
  1319. }
  1320. var endTime int64
  1321. if len(end_time) > 0 {
  1322. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1323. if err != nil {
  1324. utils.ErrorLog(err.Error())
  1325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1326. return
  1327. }
  1328. endTime = theTime.Unix()
  1329. }
  1330. orgId := this.GetAdminUserInfo().CurrentOrgId
  1331. list, total, err := service.GetAllGoodOderList(check_id, keyword, page, limit, startTime, endTime, orgId)
  1332. if err == nil {
  1333. this.ServeSuccessJSON(map[string]interface{}{
  1334. "list": list,
  1335. "total": total,
  1336. })
  1337. } else {
  1338. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1339. }
  1340. }
  1341. func (this *SupplyOrderApiController) GetGoodOrderDetail() {
  1342. id, _ := this.GetInt64("id")
  1343. ids := this.GetString("ids")
  1344. orgId := this.GetAdminUserInfo().CurrentOrgId
  1345. if len(ids) == 0 {
  1346. out, err := service.GetGoodOrderDetail(id, orgId)
  1347. list, _ := service.GetSupplyWarehouseOutById(id, orgId)
  1348. drugList, _ := service.GetSupplyDrugList(orgId)
  1349. goodList, _ := service.GetSupplyGoodList(orgId)
  1350. if err == nil {
  1351. this.ServeSuccessJSON(map[string]interface{}{
  1352. "out": out,
  1353. "list": list,
  1354. "goodList": goodList,
  1355. "drugList": drugList,
  1356. })
  1357. } else {
  1358. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1359. }
  1360. }
  1361. if len(ids) > 0 {
  1362. idArray := strings.Split(ids, ",")
  1363. out, err := service.GetGoodOrderDetail(id, orgId)
  1364. list, _ := service.GetSupplyWarehouseOutByIdOne(id, orgId, idArray)
  1365. drugList, _ := service.GetSupplyDrugList(orgId)
  1366. goodList, _ := service.GetSupplyGoodList(orgId)
  1367. if err == nil {
  1368. this.ServeSuccessJSON(map[string]interface{}{
  1369. "out": out,
  1370. "list": list,
  1371. "goodList": goodList,
  1372. "drugList": drugList,
  1373. })
  1374. } else {
  1375. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1376. }
  1377. }
  1378. }
  1379. func (this *SupplyOrderApiController) UpdateGoodOrder() {
  1380. supplier_id, _ := this.GetInt64("supplier_id")
  1381. start_time := this.GetString("start")
  1382. timeLayout := "2006-01-02"
  1383. loc, _ := time.LoadLocation("Local")
  1384. var startTime int64
  1385. if len(start_time) > 0 {
  1386. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1387. if err != nil {
  1388. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1389. return
  1390. }
  1391. startTime = theTime.Unix()
  1392. }
  1393. arrerage := this.GetString("arrerage")
  1394. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  1395. payment := this.GetString("payment")
  1396. payment_float, _ := strconv.ParseFloat(payment, 64)
  1397. warehose_out_id, _ := this.GetInt64("warehose_out_id")
  1398. number := this.GetString("number")
  1399. rate_of_concession := this.GetString("rate_of_concession")
  1400. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  1401. discount_amount := this.GetString("discount_amount")
  1402. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  1403. good_number := this.GetString("good_number")
  1404. fmt.Println(supplier_id, startTime, arrerage, payment, warehose_out_id, number, rate_of_concession, discount_amount)
  1405. orgId := this.GetAdminUserInfo().CurrentOrgId
  1406. dataBody := make(map[string]interface{}, 0)
  1407. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1408. if err != nil {
  1409. utils.ErrorLog(err.Error())
  1410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1411. return
  1412. }
  1413. var warehousingOut []*models.SpSupplierWarehousingOutOrder
  1414. var updateWarehout []*models.SpSupplierWarehousingOutOrder
  1415. return_remake := dataBody["return_remake"].(string)
  1416. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  1417. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  1418. if len(thisStockIn) > 0 {
  1419. for _, item := range thisStockIn {
  1420. items := item.(map[string]interface{})
  1421. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1422. utils.ErrorLog("id")
  1423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1424. return
  1425. }
  1426. id := int64(items["id"].(float64))
  1427. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  1428. utils.ErrorLog("supply_count")
  1429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1430. return
  1431. }
  1432. supply_count := int64(items["supply_count"].(float64))
  1433. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  1434. utils.ErrorLog("manufacturer_id")
  1435. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1436. return
  1437. }
  1438. manufacturer_id := int64(items["manufacturer_id"].(float64))
  1439. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1440. utils.ErrorLog("name")
  1441. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1442. return
  1443. }
  1444. name := items["name"].(string)
  1445. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  1446. utils.ErrorLog("order_number")
  1447. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1448. return
  1449. }
  1450. order_number := items["order_number"].(string)
  1451. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  1452. utils.ErrorLog("supply_price")
  1453. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1454. return
  1455. }
  1456. supply_price := items["supply_price"].(string)
  1457. price_float, _ := strconv.ParseFloat(supply_price, 64)
  1458. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  1459. utils.ErrorLog("supply_total_price")
  1460. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1461. return
  1462. }
  1463. supply_total_price := items["supply_total_price"].(string)
  1464. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  1465. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  1466. utils.ErrorLog("project_id")
  1467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1468. return
  1469. }
  1470. project_id := int64(items["project_id"].(float64))
  1471. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  1472. utils.ErrorLog("supply_remake")
  1473. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1474. return
  1475. }
  1476. supply_remake := items["supply_remake"].(string)
  1477. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  1478. utils.ErrorLog("supply_batch_number")
  1479. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1480. return
  1481. }
  1482. supply_batch_number := items["supply_batch_number"].(string)
  1483. var supply_expiry_date_time int64
  1484. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "string" {
  1485. utils.ErrorLog("supply_expiry_date")
  1486. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1487. return
  1488. }
  1489. supply_expiry_date := items["supply_expiry_date"].(string)
  1490. if len(supply_expiry_date) > 0 {
  1491. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_expiry_date+" 00:00:00", loc)
  1492. if err != nil {
  1493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1494. return
  1495. }
  1496. supply_expiry_date_time = theTime.Unix()
  1497. }
  1498. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  1499. utils.ErrorLog("supply_license_number")
  1500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1501. return
  1502. }
  1503. supply_license_number := items["supply_license_number"].(string)
  1504. var supply_product_date_time int64
  1505. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "string" {
  1506. utils.ErrorLog("supply_product_date")
  1507. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1508. return
  1509. }
  1510. supply_product_date := items["supply_product_date"].(string)
  1511. if len(supply_product_date) > 0 {
  1512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_product_date+" 00:00:00", loc)
  1513. if err != nil {
  1514. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1515. return
  1516. }
  1517. supply_product_date_time = theTime.Unix()
  1518. }
  1519. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  1520. utils.ErrorLog("supply_specification_name")
  1521. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1522. return
  1523. }
  1524. supply_specification_name := items["supply_specification_name"].(string)
  1525. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  1526. utils.ErrorLog("supply_total")
  1527. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1528. return
  1529. }
  1530. supply_total := items["supply_total"].(string)
  1531. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  1532. utils.ErrorLog("supply_type")
  1533. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1534. return
  1535. }
  1536. supply_type := items["supply_type"].(string)
  1537. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  1538. utils.ErrorLog("supply_unit")
  1539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1540. return
  1541. }
  1542. supply_unit := items["supply_unit"].(string)
  1543. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1544. utils.ErrorLog("type")
  1545. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1546. return
  1547. }
  1548. is_source := int64(items["type"].(float64))
  1549. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  1550. utils.ErrorLog("supply_manufacturer")
  1551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1552. return
  1553. }
  1554. supply_manufacturer := items["supply_manufacturer"].(string)
  1555. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  1556. utils.ErrorLog("warehouse_info_id")
  1557. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1558. return
  1559. }
  1560. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1561. if items["warehousing_id"] == nil || reflect.TypeOf(items["warehousing_id"]).String() != "float64" {
  1562. utils.ErrorLog("warehouse_info_id")
  1563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1564. return
  1565. }
  1566. warehousing_id := int64(items["warehousing_id"].(float64))
  1567. if id > 0 {
  1568. order := models.SpSupplierWarehousingOutOrder{
  1569. ID: id,
  1570. OrderNumber: order_number,
  1571. ProjectId: project_id,
  1572. IsSource: is_source,
  1573. Count: supply_count,
  1574. Amount: supply_total_price_float,
  1575. Price: price_float,
  1576. Remark: supply_remake,
  1577. IsCheck: 2,
  1578. UserOrgId: orgId,
  1579. Status: 1,
  1580. Ctime: time.Now().Unix(),
  1581. Mtime: 0,
  1582. WarehouseOutId: warehose_out_id,
  1583. Type: 1,
  1584. SupplyBatchNumber: supply_batch_number,
  1585. SupplyProductDate: supply_product_date_time,
  1586. SupplyExpiryDate: supply_expiry_date_time,
  1587. SupplyType: supply_type,
  1588. SupplyUnit: supply_unit,
  1589. SupplyTotal: supply_total,
  1590. SupplySpecificationName: supply_specification_name,
  1591. SupplyLicenseNumber: supply_license_number,
  1592. Name: name,
  1593. ManufacturerId: manufacturer_id,
  1594. GoodNumber: good_number,
  1595. SupplyManufacturer: supply_manufacturer,
  1596. WarehouseInfoId: warehouse_info_id,
  1597. WarehousingId: warehousing_id,
  1598. }
  1599. updateWarehout = append(updateWarehout, &order)
  1600. }
  1601. if id == 0 {
  1602. order := models.SpSupplierWarehousingOutOrder{
  1603. OrderNumber: order_number,
  1604. ProjectId: project_id,
  1605. IsSource: is_source,
  1606. Count: supply_count,
  1607. Amount: supply_total_price_float,
  1608. Price: price_float,
  1609. Remark: supply_remake,
  1610. IsCheck: 2,
  1611. UserOrgId: orgId,
  1612. Status: 1,
  1613. Ctime: time.Now().Unix(),
  1614. Mtime: 0,
  1615. WarehouseOutId: warehose_out_id,
  1616. Type: 1,
  1617. SupplyBatchNumber: supply_batch_number,
  1618. SupplyProductDate: supply_product_date_time,
  1619. SupplyExpiryDate: supply_expiry_date_time,
  1620. WarehouseInfoId: id,
  1621. SupplyType: supply_type,
  1622. SupplyUnit: supply_unit,
  1623. SupplyTotal: supply_total,
  1624. SupplySpecificationName: supply_specification_name,
  1625. SupplyLicenseNumber: supply_license_number,
  1626. Name: name,
  1627. ManufacturerId: manufacturer_id,
  1628. GoodNumber: good_number,
  1629. SupplyManufacturer: supply_manufacturer,
  1630. }
  1631. warehousingOut = append(warehousingOut, &order)
  1632. }
  1633. }
  1634. }
  1635. }
  1636. out := models.SpSupplierWarehouseOut{
  1637. Arrearage: arrerage_float,
  1638. Payment: payment_float,
  1639. RateOfConcession: rate_of_concession_float,
  1640. DiscountAmount: discount_amount_float,
  1641. SupplierId: supplier_id,
  1642. DocumentDate: startTime,
  1643. ReturnRemake: return_remake,
  1644. }
  1645. //更改购货单据
  1646. service.UpdateGoodWarehouseOut(warehose_out_id, out)
  1647. for _, item := range warehousingOut {
  1648. //如果是手动新增的,type 等于2
  1649. if item.WarehouseInfoId == 0 {
  1650. item.Type = 2
  1651. }
  1652. err = service.CreateSupplyWarehousOutOrder(item)
  1653. }
  1654. for _, item := range updateWarehout {
  1655. service.UpdateGoodWarehouseOutOrder(item)
  1656. }
  1657. if err == nil {
  1658. this.ServeSuccessJSON(map[string]interface{}{
  1659. "out": out,
  1660. })
  1661. } else {
  1662. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1663. }
  1664. }
  1665. func (this *SupplyOrderApiController) DeletePurchOrder() {
  1666. id, _ := this.GetInt64("id")
  1667. orgId := this.GetAdminUserInfo().CurrentOrgId
  1668. err := service.DeletePurchOrder(id, orgId)
  1669. if err == nil {
  1670. returnData := make(map[string]interface{}, 0)
  1671. returnData["msg"] = "ok"
  1672. this.ServeSuccessJSON(returnData)
  1673. return
  1674. } else {
  1675. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1676. }
  1677. }
  1678. func (this *SupplyOrderApiController) GetAllOrderCountList() {
  1679. id, _ := this.GetInt64("id")
  1680. orgId := this.GetAdminUserInfo().CurrentOrgId
  1681. //获取购货订单的数据
  1682. purcaseOrder, _ := service.GetAllPurcaseOrderById(id, orgId)
  1683. //获取购货单的数据
  1684. goodOrder, err := service.GetAllGoodOrderById(id, orgId)
  1685. drugList, err := service.GetSupplyDrugList(orgId)
  1686. if err == nil {
  1687. this.ServeSuccessJSON(map[string]interface{}{
  1688. "purcaseOrder": purcaseOrder,
  1689. "goodOrder": goodOrder,
  1690. "drugList": drugList,
  1691. })
  1692. } else {
  1693. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1694. }
  1695. }
  1696. func (this *SupplyOrderApiController) GetPurchOrderInfo() {
  1697. id, _ := this.GetInt64("id")
  1698. ids := this.GetString("ids")
  1699. if len(ids) == 0 {
  1700. info, _ := service.GetPurchaseOrderDetail(id)
  1701. //查询
  1702. orderInfo, err := service.GetSupplyWarehousingOrderInfo(id)
  1703. orgId := this.GetAdminUserInfo().CurrentOrgId
  1704. supplyList, _ := service.GetSupplierList(orgId)
  1705. //获取药品库数据
  1706. baseList, _ := service.GetSupplyDrugList(orgId)
  1707. goodList, _ := service.GetSupplyGoodList(orgId)
  1708. if err == nil {
  1709. this.ServeSuccessJSON(map[string]interface{}{
  1710. "info": info,
  1711. "orderInfo": orderInfo,
  1712. "supplyList": supplyList,
  1713. "baseList": baseList,
  1714. "goodList": goodList,
  1715. })
  1716. } else {
  1717. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1718. }
  1719. }
  1720. if len(ids) > 0 {
  1721. idArray := strings.Split(ids, ",")
  1722. info, _ := service.GetPurchaseOrderDetail(id)
  1723. //查询
  1724. orderInfo, err := service.GetSupplyWarehousingOrderInfoTwo(id, idArray)
  1725. orgId := this.GetAdminUserInfo().CurrentOrgId
  1726. supplyList, _ := service.GetSupplierList(orgId)
  1727. //获取药品库数据
  1728. baseList, _ := service.GetSupplyDrugList(orgId)
  1729. goodList, _ := service.GetSupplyGoodList(orgId)
  1730. if err == nil {
  1731. this.ServeSuccessJSON(map[string]interface{}{
  1732. "info": info,
  1733. "orderInfo": orderInfo,
  1734. "supplyList": supplyList,
  1735. "baseList": baseList,
  1736. "goodList": goodList,
  1737. })
  1738. } else {
  1739. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1740. }
  1741. }
  1742. }
  1743. func (this *SupplyOrderApiController) GetGoodOrderList() {
  1744. id, _ := this.GetInt64("id")
  1745. orgId := this.GetAdminUserInfo().CurrentOrgId
  1746. list, err := service.GetGoodOrderList(id, orgId)
  1747. if err == nil {
  1748. this.ServeSuccessJSON(map[string]interface{}{
  1749. "list": list,
  1750. })
  1751. } else {
  1752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1753. }
  1754. }
  1755. func (this *SupplyOrderApiController) GetReturnOrder() {
  1756. id, _ := this.GetInt64("id")
  1757. orgId := this.GetAdminUserInfo().CurrentOrgId
  1758. err := service.GetReturnOrder(id, orgId)
  1759. if err == nil {
  1760. returnData := make(map[string]interface{}, 0)
  1761. returnData["msg"] = "ok"
  1762. this.ServeSuccessJSON(returnData)
  1763. return
  1764. } else {
  1765. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1766. }
  1767. }
  1768. func (this *SupplyOrderApiController) GetGoodOrderCountList() {
  1769. id, _ := this.GetInt64("id")
  1770. warehousing_id, _ := this.GetInt64("warehousing_id")
  1771. orgId := this.GetAdminUserInfo().CurrentOrgId
  1772. checker := this.GetAdminUserInfo().AdminUser.Id
  1773. recordDateStr := time.Now().Format("2006-01-02")
  1774. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1775. record_date := recordDate.Unix()
  1776. out := models.SpSupplierWarehouseOut{
  1777. IsCheck: 1,
  1778. Checker: checker,
  1779. CheckTime: record_date,
  1780. }
  1781. err := service.CheckGoodOrder(id, orgId, out)
  1782. fmt.Println(err)
  1783. //获取购货订单的数据
  1784. purcaseOrder, _ := service.GetAllPurcaseOrderById(warehousing_id, orgId)
  1785. //获取购货单的数据
  1786. goodOrder, _ := service.GetAllGoodOrderByIdTwo(warehousing_id, orgId)
  1787. //查询该购货单是否审核成功
  1788. detail, _ := service.GetGoodOrderDetail(id, orgId)
  1789. var warehousingInfo []*models.WarehousingInfo
  1790. var warehouseInfoDetail []*models.DrugWarehouseInfo
  1791. var drugFlow []*models.DrugFlow
  1792. //如果审核成功
  1793. if detail.IsCheck == 1 {
  1794. //入库
  1795. if len(goodOrder) > 0 {
  1796. for _, item := range goodOrder {
  1797. //药品
  1798. if item.IsSource == 1 {
  1799. //获取药品类型
  1800. medical, _ := service.GetBaseDrugMedical(item.ID)
  1801. timeStr := time.Now().Format("2006-01-02")
  1802. timeArr := strings.Split(timeStr, "-")
  1803. total, _ := service.FindAllWarehouseTotalOne(orgId)
  1804. total = total + 1
  1805. warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1806. operation_time := time.Now().Unix()
  1807. warehousing := models.DrugWarehouse{
  1808. WarehousingOrder: warehousing_order,
  1809. OperationTime: operation_time,
  1810. OrgId: orgId,
  1811. Creater: checker,
  1812. Ctime: time.Now().Unix(),
  1813. Status: 1,
  1814. WarehousingTime: record_date,
  1815. Type: 1,
  1816. SupplyWarehouseId: id,
  1817. }
  1818. //查询今日是否存在入库单号
  1819. _, errcode := service.GetSingleDrugWarehouseOrder(record_date, orgId)
  1820. if errcode == gorm.ErrRecordNotFound {
  1821. service.AddSigleDrugWarehouse(&warehousing)
  1822. }
  1823. drugWarehouseInfo, _ := service.GetLastDrugWarehouse(orgId)
  1824. warehouseInfoDetailOne := &models.DrugWarehouseInfo{
  1825. WarehousingOrder: drugWarehouseInfo.WarehousingOrder,
  1826. WarehousingId: drugWarehouseInfo.ID,
  1827. DrugId: item.ProjectId,
  1828. Number: item.SupplyLicenseNumber,
  1829. ProductDate: item.SupplyProductDate,
  1830. ExpiryDate: item.SupplyExpiryDate,
  1831. WarehousingCount: item.Count,
  1832. Price: item.Price,
  1833. TotalPrice: 0,
  1834. Status: 1,
  1835. Ctime: time.Now().Unix(),
  1836. Remark: item.Remark,
  1837. OrgId: orgId,
  1838. Type: 1,
  1839. Manufacturer: item.ManufacturerId,
  1840. Dealer: 0,
  1841. StockMaxNumber: item.Count,
  1842. RetailTotalPrice: 0,
  1843. BatchNumber: item.SupplyBatchNumber,
  1844. MaxUnit: item.SupplyUnit,
  1845. MinUnit: item.SupplyUnit,
  1846. RetailPrice: medical.MinPrice,
  1847. SupplyWarehouseId: id,
  1848. }
  1849. if medical.MaxUnit == medical.MinUnit {
  1850. warehouseInfoDetailOne.StockMaxNumber = item.Count
  1851. warehouseInfoDetailOne.StockMinNumber = 0
  1852. warehouseInfoDetailOne.MaxUnit = item.SupplyUnit
  1853. }
  1854. if item.SupplyUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1855. warehouseInfoDetailOne.StockMaxNumber = 0
  1856. warehouseInfoDetailOne.StockMinNumber = item.Count
  1857. warehouseInfoDetailOne.MaxUnit = item.SupplyUnit
  1858. }
  1859. warehouseInfoDetail = append(warehouseInfoDetail, warehouseInfoDetailOne)
  1860. drugflow := &models.DrugFlow{
  1861. WarehousingOrder: drugWarehouseInfo.WarehousingOrder,
  1862. WarehousingId: drugWarehouseInfo.ID,
  1863. DrugId: item.ProjectId,
  1864. Number: item.SupplyBatchNumber,
  1865. ProductDate: item.SupplyProductDate,
  1866. ExpireDate: item.SupplyExpiryDate,
  1867. Count: item.Count,
  1868. Price: item.Price,
  1869. Status: 1,
  1870. Ctime: time.Now().Unix(),
  1871. UserOrgId: orgId,
  1872. Manufacturer: item.ManufacturerId,
  1873. Dealer: 0,
  1874. BatchNumber: item.SupplyBatchNumber,
  1875. MaxUnit: item.SupplyUnit,
  1876. MinUnit: item.SupplyUnit,
  1877. ConsumableType: 1,
  1878. IsEdit: 1,
  1879. Creator: checker,
  1880. IsSys: 0,
  1881. SupplyWarehouseId: id,
  1882. }
  1883. if medical.MaxUnit == medical.MinUnit {
  1884. drugflow.MaxUnit = item.SupplyUnit
  1885. }
  1886. if item.SupplyUnit == medical.MinUnit {
  1887. warehouseInfoDetailOne.MaxUnit = warehouseInfoDetailOne.MinUnit
  1888. }
  1889. drugFlow = append(drugFlow, drugflow)
  1890. }
  1891. //耗材
  1892. if item.IsSource == 2 {
  1893. //获取耗材类型
  1894. good, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1895. timeStr := time.Now().Format("2006-01-02")
  1896. timeArr := strings.Split(timeStr, "-")
  1897. total, _ := service.FindAllWarehouseTotal(orgId)
  1898. total = total + 1
  1899. warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1900. operation_time := time.Now().Unix()
  1901. creater := this.GetAdminUserInfo().AdminUser.Id
  1902. warehousing := models.Warehousing{
  1903. WarehousingOrder: warehousing_order,
  1904. OperationTime: operation_time,
  1905. OrgId: orgId,
  1906. Creater: creater,
  1907. Ctime: time.Now().Unix(),
  1908. Status: 1,
  1909. WarehousingTime: record_date,
  1910. Type: 1,
  1911. SupplyWarehouseId: id,
  1912. }
  1913. //查询是否存在入库单
  1914. _, errcose := service.GetSindleWarehouse(record_date, orgId)
  1915. if errcose == gorm.ErrRecordNotFound {
  1916. service.AddSigleWarehouse(&warehousing)
  1917. }
  1918. info, _ := service.GetLastWarehouseInfoByInfo(orgId)
  1919. //入库单表格
  1920. warehouseInfo := &models.WarehousingInfo{
  1921. WarehousingOrder: info.WarehousingOrder,
  1922. WarehousingId: info.ID,
  1923. GoodId: item.ProjectId,
  1924. Number: item.SupplyBatchNumber,
  1925. GoodTypeId: good.GoodTypeId,
  1926. ProductDate: item.SupplyProductDate,
  1927. ExpiryDate: item.SupplyExpiryDate,
  1928. WarehousingCount: item.Count,
  1929. Price: item.Price,
  1930. TotalPrice: 0,
  1931. Status: 1,
  1932. Ctime: time.Now().Unix(),
  1933. Remark: item.Remark,
  1934. OrgId: orgId,
  1935. Type: 1,
  1936. Manufacturer: item.ManufacturerId,
  1937. StockCount: item.Count,
  1938. Dealer: good.Dealer,
  1939. LicenseNumber: item.SupplyLicenseNumber,
  1940. PackingPrice: good.PackingPrice,
  1941. SupplyWarehouseId: id,
  1942. }
  1943. warehousingInfo = append(warehousingInfo, warehouseInfo)
  1944. }
  1945. }
  1946. }
  1947. }
  1948. for _, item := range warehousingInfo {
  1949. service.CreatedWarehouseingDetail(item)
  1950. warehousinginfo, _ := service.GetLastWarehousingInfo(item.GoodId)
  1951. flow := models.VmStockFlow{
  1952. WarehousingOrder: item.WarehousingOrder,
  1953. WarehousingId: item.ID,
  1954. GoodId: item.GoodId,
  1955. Number: item.Number,
  1956. ProductDate: item.ProductDate,
  1957. ExpireDate: item.ExpiryDate,
  1958. Count: item.WarehousingCount,
  1959. Price: item.Price,
  1960. Status: 1,
  1961. Ctime: time.Now().Unix(),
  1962. UserOrgId: orgId,
  1963. Manufacturer: item.Manufacturer,
  1964. Dealer: item.Dealer,
  1965. LicenseNumber: item.LicenseNumber,
  1966. IsEdit: 1,
  1967. Creator: checker,
  1968. SystemTime: record_date,
  1969. ConsumableType: 1,
  1970. WarehousingDetailId: warehousinginfo.ID,
  1971. SupplyWarehouseId: id,
  1972. }
  1973. service.CreateStockFlowOne(flow)
  1974. }
  1975. //创建入库单
  1976. errs := service.CreateDrugWarehousingInfo(warehouseInfoDetail)
  1977. fmt.Println(errs)
  1978. for _, items := range drugFlow {
  1979. drugWarehouseInfo, _ := service.GetLastDrugWarehouseInfo(items.DrugId)
  1980. items.WarehousingDetailId = drugWarehouseInfo.ID
  1981. }
  1982. //创建流水单
  1983. service.CreateDrugFlow(drugFlow)
  1984. drugList, _ := service.GetSupplyDrugList(orgId)
  1985. if err == nil {
  1986. this.ServeSuccessJSON(map[string]interface{}{
  1987. "purcaseOrder": purcaseOrder,
  1988. "goodOrder": goodOrder,
  1989. "drugList": drugList,
  1990. })
  1991. } else {
  1992. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1993. }
  1994. }
  1995. func (this *SupplyOrderApiController) ModefySupplyWarehousing() {
  1996. is_warehouse, _ := this.GetInt64("is_warehouse")
  1997. warehousing_id, _ := this.GetInt64("warehousing_id")
  1998. orgId := this.GetAdminUserInfo().CurrentOrgId
  1999. err := service.ModefySupplyWarehousing(is_warehouse, warehousing_id, orgId)
  2000. if err == nil {
  2001. returnData := make(map[string]interface{}, 0)
  2002. returnData["msg"] = "ok"
  2003. this.ServeSuccessJSON(returnData)
  2004. return
  2005. } else {
  2006. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2007. }
  2008. }
  2009. func (this *SupplyOrderApiController) SaveGoodReturnOrder() {
  2010. dataBody := make(map[string]interface{}, 0)
  2011. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2012. if err != nil {
  2013. utils.ErrorLog(err.Error())
  2014. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2015. return
  2016. }
  2017. return_remark := dataBody["return_marke"].(string)
  2018. supplier_id, _ := this.GetInt64("supplier_id")
  2019. start_time := this.GetString("start")
  2020. timeLayout := "2006-01-02"
  2021. loc, _ := time.LoadLocation("Local")
  2022. var startTime int64
  2023. if len(start_time) > 0 {
  2024. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2025. if err != nil {
  2026. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2027. return
  2028. }
  2029. startTime = theTime.Unix()
  2030. }
  2031. warehouse_out_id, _ := this.GetInt64("warehouse_out_id")
  2032. arrerage := this.GetString("arrerage")
  2033. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  2034. payment := this.GetString("payment")
  2035. payment_float, _ := strconv.ParseFloat(payment, 64)
  2036. rate_of_concession := this.GetString("rate_of_concession")
  2037. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  2038. discount_amount := this.GetString("discount_amount")
  2039. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  2040. orgId := this.GetAdminUserInfo().CurrentOrgId
  2041. total, _ := service.GetSupplyCancelOrder(orgId)
  2042. creater := this.GetAdminUserInfo().AdminUser.Id
  2043. //生成购货单
  2044. timeStr := time.Now().Format("2006-01-02")
  2045. timeArr := strings.Split(timeStr, "-")
  2046. total = total + 1
  2047. warehousing_order := "CGT" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  2048. recordDateStr := time.Now().Format("2006-01-02")
  2049. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2050. cancel := models.SpSupplierWarehouseCancel{
  2051. Number: warehousing_order,
  2052. UserOrgId: orgId,
  2053. Creater: creater,
  2054. Ctime: time.Now().Unix(),
  2055. Mtime: 0,
  2056. Status: 1,
  2057. RecordDate: recordDate.Unix(),
  2058. IsCheck: 2,
  2059. WarehouseOutId: warehouse_out_id,
  2060. RateOfConcession: rate_of_concession_float,
  2061. DiscountAmount: discount_amount_float,
  2062. DocumentDate: startTime,
  2063. SupplierId: supplier_id,
  2064. Checker: 0,
  2065. CheckTime: 0,
  2066. Arrearage: arrerage_float,
  2067. Payment: payment_float,
  2068. ReturnRemark: return_remark,
  2069. }
  2070. err = service.CreateReturnCacelOrder(cancel)
  2071. order, _ := service.GetLastReturnCancelOrder(orgId)
  2072. var warehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2073. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  2074. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  2075. if len(thisStockIn) > 0 {
  2076. for _, item := range thisStockIn {
  2077. items := item.(map[string]interface{})
  2078. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  2079. utils.ErrorLog("supply_count")
  2080. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2081. return
  2082. }
  2083. supply_count := int64(items["supply_count"].(float64))
  2084. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  2085. utils.ErrorLog("manufacturer_id")
  2086. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2087. return
  2088. }
  2089. manufacturer_id := int64(items["manufacturer_id"].(float64))
  2090. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  2091. utils.ErrorLog("name")
  2092. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2093. return
  2094. }
  2095. name := items["name"].(string)
  2096. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  2097. utils.ErrorLog("order_number")
  2098. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2099. return
  2100. }
  2101. order_number := items["order_number"].(string)
  2102. if items["good_number"] == nil || reflect.TypeOf(items["good_number"]).String() != "string" {
  2103. utils.ErrorLog("good_number")
  2104. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2105. return
  2106. }
  2107. good_number := items["good_number"].(string)
  2108. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  2109. utils.ErrorLog("supply_price")
  2110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2111. return
  2112. }
  2113. supply_price := items["supply_price"].(string)
  2114. price_float, _ := strconv.ParseFloat(supply_price, 64)
  2115. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  2116. utils.ErrorLog("project_id")
  2117. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2118. return
  2119. }
  2120. project_id := int64(items["project_id"].(float64))
  2121. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  2122. utils.ErrorLog("supply_remake")
  2123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2124. return
  2125. }
  2126. supply_remake := items["supply_remake"].(string)
  2127. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  2128. utils.ErrorLog("supply_license_number")
  2129. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2130. return
  2131. }
  2132. supply_license_number := items["supply_license_number"].(string)
  2133. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  2134. utils.ErrorLog("supply_specification_name")
  2135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2136. return
  2137. }
  2138. supply_specification_name := items["supply_specification_name"].(string)
  2139. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  2140. utils.ErrorLog("supply_total")
  2141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2142. return
  2143. }
  2144. supply_total := items["supply_total"].(string)
  2145. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  2146. utils.ErrorLog("supply_type")
  2147. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2148. return
  2149. }
  2150. supply_type := items["supply_type"].(string)
  2151. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  2152. utils.ErrorLog("supply_unit")
  2153. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2154. return
  2155. }
  2156. supply_unit := items["supply_unit"].(string)
  2157. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2158. utils.ErrorLog("type")
  2159. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2160. return
  2161. }
  2162. is_source := int64(items["type"].(float64))
  2163. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  2164. utils.ErrorLog("supply_manufacturer")
  2165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2166. return
  2167. }
  2168. supply_manufacturer := items["supply_manufacturer"].(string)
  2169. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2170. ManufacturerId: manufacturer_id,
  2171. OrderNumber: order_number,
  2172. ProjectId: project_id,
  2173. GoodNumber: good_number,
  2174. IsSource: is_source,
  2175. Count: supply_count,
  2176. Price: price_float,
  2177. Remark: supply_remake,
  2178. RateOfConcession: rate_of_concession_float,
  2179. DiscountAmount: discount_amount_float,
  2180. UserOrgId: orgId,
  2181. Ctime: time.Now().Unix(),
  2182. Status: 1,
  2183. Mtime: 0,
  2184. WarehouseCancelId: order.ID,
  2185. Type: 1,
  2186. ReturnNumber: order.Number,
  2187. WarehouseOutId: warehouse_out_id,
  2188. SupplySpecificationName: supply_specification_name,
  2189. SupplyType: supply_type,
  2190. SupplyTotal: supply_total,
  2191. SupplyManufacturer: supply_manufacturer,
  2192. Name: name,
  2193. SupplyUnit: supply_unit,
  2194. SupplyLicenseNumber: supply_license_number,
  2195. }
  2196. warehouseCancel = append(warehouseCancel, cancelOrder)
  2197. }
  2198. }
  2199. }
  2200. for _, item := range warehouseCancel {
  2201. service.CreateCancelReturnOrder(item)
  2202. }
  2203. cancelOrder, err := service.GetReturnCancelOrder(order.ID, orgId)
  2204. list, err := service.GetReturnCancelOrderList(order.ID, orgId)
  2205. if err == nil {
  2206. this.ServeSuccessJSON(map[string]interface{}{
  2207. "warehouseCancel": warehouseCancel,
  2208. "cancelOrder": cancelOrder,
  2209. "list": list,
  2210. })
  2211. } else {
  2212. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2213. }
  2214. }
  2215. func (this *SupplyOrderApiController) GetAllGoodReturnOrderList() {
  2216. check_id, _ := this.GetInt64("check_id")
  2217. start_time := this.GetString("start_time")
  2218. end_time := this.GetString("end_time")
  2219. keyword := this.GetString("keyword")
  2220. page, _ := this.GetInt64("page")
  2221. limit, _ := this.GetInt64("limit")
  2222. timeLayout := "2006-01-02"
  2223. loc, _ := time.LoadLocation("Local")
  2224. var startTime int64
  2225. if len(start_time) > 0 {
  2226. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2227. if err != nil {
  2228. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2229. return
  2230. }
  2231. startTime = theTime.Unix()
  2232. }
  2233. var endTime int64
  2234. if len(end_time) > 0 {
  2235. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2236. if err != nil {
  2237. utils.ErrorLog(err.Error())
  2238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2239. return
  2240. }
  2241. endTime = theTime.Unix()
  2242. }
  2243. orgId := this.GetAdminUserInfo().CurrentOrgId
  2244. list, total, err := service.GetAllGoodReturnOrderList(check_id, keyword, page, limit, startTime, endTime, orgId)
  2245. if err == nil {
  2246. this.ServeSuccessJSON(map[string]interface{}{
  2247. "total": total,
  2248. "list": list,
  2249. })
  2250. } else {
  2251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2252. }
  2253. }
  2254. func (this *SupplyOrderApiController) GetGoodReturnDetail() {
  2255. id, _ := this.GetInt64("id")
  2256. orgId := this.GetAdminUserInfo().CurrentOrgId
  2257. detail, err := service.GetGoodReturnDetail(id, orgId)
  2258. orderDetail, err := service.GetGoodReturnOrderDetail(id, orgId)
  2259. //获取药品库数据
  2260. baseList, _ := service.GetSupplyDrugList(orgId)
  2261. goodList, _ := service.GetSupplyGoodList(orgId)
  2262. if err == nil {
  2263. this.ServeSuccessJSON(map[string]interface{}{
  2264. "cancelDetail": detail,
  2265. "orderCancelDetail": orderDetail,
  2266. "drugList": baseList,
  2267. "goodList": goodList,
  2268. })
  2269. } else {
  2270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2271. }
  2272. }
  2273. func (this *SupplyOrderApiController) UpdateGoodReturn() {
  2274. dataBody := make(map[string]interface{}, 0)
  2275. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2276. if err != nil {
  2277. utils.ErrorLog(err.Error())
  2278. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2279. return
  2280. }
  2281. return_remark := dataBody["return_marke"].(string)
  2282. supplier_id, _ := this.GetInt64("supplier_id")
  2283. start_time := this.GetString("start")
  2284. timeLayout := "2006-01-02"
  2285. loc, _ := time.LoadLocation("Local")
  2286. var startTime int64
  2287. if len(start_time) > 0 {
  2288. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2289. if err != nil {
  2290. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2291. return
  2292. }
  2293. startTime = theTime.Unix()
  2294. }
  2295. warehouse_out_id, _ := this.GetInt64("warehouse_out_id")
  2296. arrerage := this.GetString("arrerage")
  2297. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  2298. payment := this.GetString("payment")
  2299. payment_float, _ := strconv.ParseFloat(payment, 64)
  2300. rate_of_concession := this.GetString("rate_of_concession")
  2301. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  2302. discount_amount := this.GetString("discount_amount")
  2303. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  2304. return_number := this.GetString("return_number")
  2305. orgId := this.GetAdminUserInfo().CurrentOrgId
  2306. cancel := models.SpSupplierWarehouseCancel{
  2307. ID: 0,
  2308. Number: return_number,
  2309. RateOfConcession: rate_of_concession_float,
  2310. DiscountAmount: discount_amount_float,
  2311. DocumentDate: startTime,
  2312. SupplierId: supplier_id,
  2313. Arrearage: arrerage_float,
  2314. Payment: payment_float,
  2315. ReturnRemark: return_remark,
  2316. }
  2317. service.UpdateWarehouseCancel(warehouse_out_id, cancel)
  2318. var warehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2319. var updateWarehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2320. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  2321. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  2322. if len(thisStockIn) > 0 {
  2323. for _, item := range thisStockIn {
  2324. items := item.(map[string]interface{})
  2325. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2326. utils.ErrorLog("id")
  2327. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2328. return
  2329. }
  2330. id := int64(items["id"].(float64))
  2331. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  2332. utils.ErrorLog("supply_count")
  2333. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2334. return
  2335. }
  2336. supply_count := int64(items["supply_count"].(float64))
  2337. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  2338. utils.ErrorLog("manufacturer_id")
  2339. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2340. return
  2341. }
  2342. manufacturer_id := int64(items["manufacturer_id"].(float64))
  2343. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  2344. utils.ErrorLog("name")
  2345. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2346. return
  2347. }
  2348. name := items["name"].(string)
  2349. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  2350. utils.ErrorLog("order_number")
  2351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2352. return
  2353. }
  2354. order_number := items["order_number"].(string)
  2355. if items["good_number"] == nil || reflect.TypeOf(items["good_number"]).String() != "string" {
  2356. utils.ErrorLog("good_number")
  2357. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2358. return
  2359. }
  2360. good_number := items["good_number"].(string)
  2361. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  2362. utils.ErrorLog("supply_price")
  2363. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2364. return
  2365. }
  2366. supply_price := items["supply_price"].(string)
  2367. price_float, _ := strconv.ParseFloat(supply_price, 64)
  2368. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  2369. utils.ErrorLog("project_id")
  2370. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2371. return
  2372. }
  2373. project_id := int64(items["project_id"].(float64))
  2374. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  2375. utils.ErrorLog("supply_remake")
  2376. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2377. return
  2378. }
  2379. supply_remake := items["supply_remake"].(string)
  2380. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  2381. utils.ErrorLog("supply_license_number")
  2382. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2383. return
  2384. }
  2385. supply_license_number := items["supply_license_number"].(string)
  2386. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  2387. utils.ErrorLog("supply_specification_name")
  2388. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2389. return
  2390. }
  2391. supply_specification_name := items["supply_specification_name"].(string)
  2392. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  2393. utils.ErrorLog("supply_total")
  2394. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2395. return
  2396. }
  2397. supply_total := items["supply_total"].(string)
  2398. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  2399. utils.ErrorLog("supply_type")
  2400. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2401. return
  2402. }
  2403. supply_type := items["supply_type"].(string)
  2404. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  2405. utils.ErrorLog("supply_unit")
  2406. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2407. return
  2408. }
  2409. supply_unit := items["supply_unit"].(string)
  2410. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2411. utils.ErrorLog("type")
  2412. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2413. return
  2414. }
  2415. is_source := int64(items["type"].(float64))
  2416. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  2417. utils.ErrorLog("supply_manufacturer")
  2418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2419. return
  2420. }
  2421. supply_manufacturer := items["supply_manufacturer"].(string)
  2422. if id > 0 {
  2423. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2424. ManufacturerId: manufacturer_id,
  2425. OrderNumber: order_number,
  2426. ProjectId: project_id,
  2427. GoodNumber: good_number,
  2428. IsSource: is_source,
  2429. Count: supply_count,
  2430. Price: price_float,
  2431. Remark: supply_remake,
  2432. RateOfConcession: rate_of_concession_float,
  2433. DiscountAmount: discount_amount_float,
  2434. UserOrgId: orgId,
  2435. Ctime: time.Now().Unix(),
  2436. Status: 1,
  2437. Mtime: 0,
  2438. WarehouseCancelId: warehouse_out_id,
  2439. Type: 1,
  2440. ReturnNumber: return_number,
  2441. WarehouseOutId: warehouse_out_id,
  2442. SupplySpecificationName: supply_specification_name,
  2443. SupplyType: supply_type,
  2444. SupplyTotal: supply_total,
  2445. SupplyManufacturer: supply_manufacturer,
  2446. Name: name,
  2447. SupplyUnit: supply_unit,
  2448. SupplyLicenseNumber: supply_license_number,
  2449. }
  2450. updateWarehouseCancel = append(updateWarehouseCancel, cancelOrder)
  2451. }
  2452. if id == 0 {
  2453. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2454. ManufacturerId: manufacturer_id,
  2455. OrderNumber: order_number,
  2456. ProjectId: project_id,
  2457. GoodNumber: good_number,
  2458. IsSource: is_source,
  2459. Count: supply_count,
  2460. Price: price_float,
  2461. Remark: supply_remake,
  2462. RateOfConcession: rate_of_concession_float,
  2463. DiscountAmount: discount_amount_float,
  2464. UserOrgId: orgId,
  2465. Ctime: time.Now().Unix(),
  2466. Status: 1,
  2467. Mtime: 0,
  2468. WarehouseCancelId: warehouse_out_id,
  2469. Type: 1,
  2470. ReturnNumber: return_number,
  2471. WarehouseOutId: warehouse_out_id,
  2472. SupplySpecificationName: supply_specification_name,
  2473. SupplyType: supply_type,
  2474. SupplyTotal: supply_total,
  2475. SupplyManufacturer: supply_manufacturer,
  2476. Name: name,
  2477. SupplyUnit: supply_unit,
  2478. SupplyLicenseNumber: supply_license_number,
  2479. }
  2480. warehouseCancel = append(warehouseCancel, cancelOrder)
  2481. }
  2482. }
  2483. }
  2484. if len(updateWarehouseCancel) > 0 {
  2485. for _, item := range warehouseCancel {
  2486. service.UpdateWarehouseCancelOrder(item)
  2487. }
  2488. }
  2489. if len(warehouseCancel) > 0 {
  2490. for _, item := range warehouseCancel {
  2491. service.CreateCancelReturnOrder(item)
  2492. }
  2493. }
  2494. if err == nil {
  2495. returnData := make(map[string]interface{}, 0)
  2496. returnData["msg"] = "ok"
  2497. this.ServeSuccessJSON(returnData)
  2498. return
  2499. } else {
  2500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2501. }
  2502. }
  2503. }
  2504. func (this *SupplyOrderApiController) ModefyGoodOrder() {
  2505. id, _ := this.GetInt64("id")
  2506. orgId := this.GetAdminUserInfo().CurrentOrgId
  2507. //获取购货订单的数据
  2508. purcaseOrder, _ := service.GetAllPurcaseOrderById(id, orgId)
  2509. //获取购货单的数据
  2510. goodOrder, _ := service.GetAllGoodOrderById(id, orgId)
  2511. drugList, _ := service.GetSupplyDrugList(orgId)
  2512. //获取已有关联的退货单
  2513. cancelList, _ := service.GetSupplyCancelWarehouse(id, orgId)
  2514. //查询是否存在退货单
  2515. _, errcode := service.GetSupplyCancelOrderById(id, orgId)
  2516. //无退库单
  2517. if errcode == gorm.ErrRecordNotFound {
  2518. //反审核成功
  2519. out := models.SpSupplierWarehouseOut{
  2520. IsCheck: 2,
  2521. Checker: 0,
  2522. CheckTime: 0,
  2523. }
  2524. err := service.UpdateSupplyGoodOrder(id, out)
  2525. //查询该订单不是采购入库的数据
  2526. list, _ := service.GetDrugSupplyWarehousingById(id, orgId)
  2527. if len(list) == 0 {
  2528. service.UpdateSupplyWarehousing(id, orgId)
  2529. }
  2530. goodList, _ := service.GetGoodSupplyWarehousingById(id, orgId)
  2531. if len(goodList) == 0 {
  2532. service.UpdateGoodWarehousing(id, orgId)
  2533. }
  2534. //删除药品入库单
  2535. service.UpdateDrugSupplyWarehousingInfo(id, orgId)
  2536. //删除入库流水
  2537. service.UpdateDrugSupplyFlow(id, orgId)
  2538. //删除耗材入库单
  2539. service.UpdateGoodSupplyWarehousingInfo(id, orgId)
  2540. //删除耗材入库流水
  2541. service.UpdateGoodSupplyFlow(id, orgId)
  2542. if err == nil {
  2543. this.ServeSuccessJSON(map[string]interface{}{
  2544. "cancelList": cancelList,
  2545. "purcaseOrder": purcaseOrder,
  2546. "goodOrder": goodOrder,
  2547. "drugList": drugList,
  2548. "msg": 1,
  2549. })
  2550. return
  2551. } else {
  2552. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2553. }
  2554. } else if errcode == nil {
  2555. this.ServeSuccessJSON(map[string]interface{}{
  2556. "cancelList": cancelList,
  2557. "purcaseOrder": purcaseOrder,
  2558. "goodOrder": goodOrder,
  2559. "drugList": drugList,
  2560. "msg": 2,
  2561. })
  2562. return
  2563. }
  2564. }
  2565. func (this *SupplyOrderApiController) UpdateSupplyWarehousing() {
  2566. warehousing_id, _ := this.GetInt64("warehousing_id")
  2567. orgId := this.GetAdminUserInfo().CurrentOrgId
  2568. err := service.UpdateSupplyWarehousingById(warehousing_id, orgId)
  2569. if err == nil {
  2570. returnData := make(map[string]interface{}, 0)
  2571. returnData["msg"] = "ok"
  2572. this.ServeSuccessJSON(returnData)
  2573. return
  2574. } else {
  2575. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2576. }
  2577. }
  2578. func (this *SupplyOrderApiController) DeleteGoodOrder() {
  2579. id, _ := this.GetInt64("id")
  2580. orgId := this.GetAdminUserInfo().CurrentOrgId
  2581. err := service.DeleteGoodOrder(id, orgId)
  2582. if err == nil {
  2583. returnData := make(map[string]interface{}, 0)
  2584. returnData["msg"] = "ok"
  2585. this.ServeSuccessJSON(returnData)
  2586. return
  2587. } else {
  2588. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2589. }
  2590. }
  2591. func (this *SupplyOrderApiController) GetSupplyWarehouseById() {
  2592. id, _ := this.GetInt64("id")
  2593. orgId := this.GetAdminUserInfo().CurrentOrgId
  2594. //获取已有关联的退货单
  2595. cancelList, err := service.GetSupplyCancelWarehouse(id, orgId)
  2596. //获取采购单数据
  2597. outList, _ := service.GetGoodOrderListById(id, orgId)
  2598. //获取退货单数据
  2599. cancelOrderList, _ := service.GetGoodCanceListById(id, orgId)
  2600. //获取药品库数据
  2601. baseList, _ := service.GetSupplyDrugList(orgId)
  2602. if err == nil {
  2603. this.ServeSuccessJSON(map[string]interface{}{
  2604. "cancelList": cancelList,
  2605. "outList": outList,
  2606. "drugList": baseList,
  2607. "cancelOrderList": cancelOrderList,
  2608. })
  2609. } else {
  2610. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2611. }
  2612. }