supply_order_api_contorller.go 66KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905
  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. "reflect"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. type SupplyOrderApiController struct {
  16. BaseAuthAPIController
  17. }
  18. func SupplyOrderApiRegistRouters() {
  19. //获取供应商列表GetSupplyList
  20. beego.Router("/api/supply/getsupplylist", &SupplyOrderApiController{}, "get:GetSupplyList")
  21. //保存供应商及联系人(用于更改)
  22. beego.Router("/api/supply/updatesupply", &SupplyOrderApiController{}, "post:UpdateSupply")
  23. //删除单条联系人
  24. beego.Router("/api/supply/delcontactone", &SupplyOrderApiController{}, "get:DelContactOne")
  25. //获取单条供应商和涉及到的联系人记录
  26. beego.Router("/api/supply/getsupplyandcontactone", &SupplyOrderApiController{}, "get:GetSupplyAndContactOne")
  27. //获取供应商类别
  28. beego.Router("/api/supply/getsupplytype", &SupplyOrderApiController{}, "get:GetSupplyType")
  29. //删除供应商及联系人
  30. beego.Router("/api/supply/delsupply", &SupplyOrderApiController{}, "post:DelSupply")
  31. //获取供应商编码
  32. beego.Router("/api/supply/getsupplycode", &SupplyOrderApiController{}, "get:GetSupplyCode")
  33. //保存供应商及联系人(用于新增)
  34. beego.Router("/api/supply/savesupply", &SupplyOrderApiController{}, "post:SaveSupply")
  35. beego.Router("/api/supply/getinitorder", &SupplyOrderApiController{}, "get:GetInitOrder")
  36. //保存购货订单
  37. beego.Router("/api/supply/savepurchaseorder", &SupplyOrderApiController{}, "post:SavePurchaseOrder")
  38. //获取所有供应商
  39. beego.Router("/api/supply/getallsupply", &SupplyOrderApiController{}, "get:GetAllSupply")
  40. //获取供应商订单列表
  41. beego.Router("/api/supply/getallpurchaseorderlist", &SupplyOrderApiController{}, "get:GetAllPurchaseOrderList")
  42. //修改购货订单
  43. beego.Router("/api/supply/updatepurchaseorder", &SupplyOrderApiController{}, "Post:UpdatePurchaseOrder")
  44. //审核购货订单
  45. beego.Router("/api/supply/checkpurchaseorder", &SupplyOrderApiController{}, "get:UpdateSupplyWaresing")
  46. //获取购货订单详情
  47. beego.Router("/api/supply/getpurchaseorderdetail", &SupplyOrderApiController{}, "get:GetPurchaseOrderDetail")
  48. //新增购货单
  49. beego.Router("/api/supply/addgoodorder", &SupplyOrderApiController{}, "post:AddGoodOrder")
  50. //获取购货单列表
  51. beego.Router("/api/supply/getallgoodorderlist", &SupplyOrderApiController{}, "Get:GetAllGoodOderList")
  52. //修改购货订单详情
  53. beego.Router("/api/supply/getgoodorderdetail", &SupplyOrderApiController{}, "Get:GetGoodOrderDetail")
  54. //修改购货订单
  55. beego.Router("/api/supply/updategoodorder", &SupplyOrderApiController{}, "Post:UpdateGoodOrder")
  56. //删除购货订单
  57. beego.Router("/api/supply/deletepurchorder", &SupplyOrderApiController{}, "Get:DeletePurchOrder")
  58. //生成购货单的判断
  59. beego.Router("/api/supply/getallordercountlist", &SupplyOrderApiController{}, "Get:GetAllOrderCountList")
  60. // 生成购货单
  61. beego.Router("/api/supply/getpurchaseorderinfo", &SupplyOrderApiController{}, "Get:GetPurchOrderInfo")
  62. //反审核 获取关联的购货单数据
  63. beego.Router("/api/supply/getgoodorderlist", &SupplyOrderApiController{}, "Get:GetGoodOrderList")
  64. //反审核购货订单
  65. beego.Router("/api/supply/getreturnorder", &SupplyOrderApiController{}, "Get:GetReturnOrder")
  66. //判断是否全部入库
  67. beego.Router("/api/supply/getgoodordercountlist", &SupplyOrderApiController{}, "Get:GetGoodOrderCountList")
  68. }
  69. //获取供应商列表GetSupplyList
  70. func (this *SupplyOrderApiController) GetSupplyList() {
  71. ctype, _ := this.GetInt64("ctype") //供应商类别
  72. page, _ := this.GetInt64("page") //页码
  73. limit, _ := this.GetInt64("limit") //每一页查出来的条数
  74. if page == 0 || limit == 0 {
  75. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "page或limit参数不能为空")
  76. return
  77. }
  78. code := this.GetString("code") //供应商编号
  79. sname := this.GetString("sname") //供应商名称
  80. cname := this.GetString("cname") //联系人名字
  81. orgId := this.GetAdminUserInfo().CurrentOrgId
  82. //获取分页的数据
  83. list, total, err := service.GetSupplyList(ctype, page, limit, code, sname, cname)
  84. //获取供应商类别
  85. costClassify := "供应商类别"
  86. drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
  87. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  88. tmpmap := make(map[int64]string) //储存供应商类别
  89. namemap := make(map[string]string) //储存首要联系人
  90. phonemap := make(map[string]string) //手机号
  91. for i := 0; i < len(drugTypeList); i++ {
  92. k := int64(drugTypeList[i].Value)
  93. v := drugTypeList[i].Name
  94. tmpmap[k] = v
  95. }
  96. if err == nil {
  97. for i := 0; i < len(list); i++ {
  98. code := list[i].SupplierCode
  99. fistname, errs := service.FindName(code)
  100. if errs != nil && errs.Error() != "record not found" {
  101. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  102. return
  103. }
  104. namemap[code] = fistname.Name
  105. phonemap[code] = fistname.Phone
  106. }
  107. type SpSupplierNameList struct { //基于SpSupplierName结构体修改的,为了方便前端取数据整合了一下,删除了几个用不到的字段,添加了联系人名字和供应商类别两个字段
  108. ID int64
  109. SupplierCode string
  110. SupplierName string
  111. SupplierType int64
  112. VatRate float64
  113. Number string
  114. Bank string
  115. BankAccount string
  116. UserOrgId int64
  117. Status int64
  118. ContactsId int64
  119. ConName string //供应商主要联系人名字
  120. TypeName string //供应商类别
  121. Phone string //电话
  122. }
  123. //初始化该结构体
  124. tmplist := []*SpSupplierNameList{}
  125. for i := 0; i < len(list); i++ {
  126. var typename string //类别名称
  127. if list[i].SupplierType == 0 {
  128. typename = ""
  129. } else {
  130. typename = tmpmap[list[i].SupplierType]
  131. }
  132. tlist := &SpSupplierNameList{
  133. list[i].ID,
  134. list[i].SupplierCode,
  135. list[i].SupplierName,
  136. list[i].SupplierType,
  137. list[i].VatRate,
  138. list[i].Number,
  139. list[i].Bank,
  140. list[i].BankAccount,
  141. list[i].UserOrgId,
  142. list[i].Status,
  143. list[i].ContactsId,
  144. namemap[list[i].SupplierCode],
  145. typename,
  146. phonemap[list[i].SupplierCode],
  147. }
  148. tmplist = append(tmplist, tlist)
  149. }
  150. this.ServeSuccessJSON(map[string]interface{}{
  151. "list": tmplist,
  152. "total": total,
  153. })
  154. } else {
  155. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. }
  157. }
  158. //保存供应商及联系人(用于更改)
  159. func (this *SupplyOrderApiController) UpdateSupply() {
  160. supplierName := this.GetString("suppliername") //供应商名称
  161. if supplierName == "" {
  162. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称不能为空")
  163. return
  164. }
  165. supplierCode := this.GetString("suppliercode") //供应商编码
  166. if supplierCode == "" {
  167. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
  168. return
  169. }
  170. supplierid, _ := this.GetInt64("id") //供应商id
  171. if supplierid == 0 {
  172. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
  173. return
  174. }
  175. //查询供应商的信息
  176. supply, err := service.GetSupplyOne(supplierid)
  177. if err != nil {
  178. utils.ErrorLog(err.Error())
  179. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  180. return
  181. }
  182. if supplierName != supply.SupplierName {
  183. //判断供应商名称是否有重复的
  184. sbool, _ := service.FindSupplierName(supplierName)
  185. if sbool { //有重复的
  186. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
  187. return
  188. }
  189. }
  190. if supplierCode != supply.SupplierCode {
  191. //判断供应商编号是否有重复的
  192. codebool, _ := service.FindSupplierCode(supplierCode)
  193. if codebool {
  194. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
  195. return
  196. }
  197. }
  198. supplierType, _ := this.GetInt64("suppliertype") //供应商类别
  199. vatRate, _ := this.GetFloat("vatrate") //增值税税率
  200. number := this.GetString("number") //纳税人识别号
  201. bank := this.GetString("bank") //开户银行
  202. bankAccount := this.GetString("bankAccount") //银行账号
  203. orgId := this.GetAdminUserInfo().CurrentOrgId
  204. //contacts := this.Get("contacts")//联系人
  205. dataBody := make(map[string]interface{}, 0)
  206. err = json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  207. if err != nil {
  208. utils.ErrorLog(err.Error())
  209. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. //保存联系人
  213. if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
  214. thisStockIn, _ := dataBody["contacts"].([]interface{})
  215. if len(thisStockIn) > 0 {
  216. if len(thisStockIn) == 1 {
  217. for _, item := range thisStockIn {
  218. items := item.(map[string]interface{})
  219. items["IsFirst"] = 1
  220. }
  221. }
  222. tmodify := this.GetAdminUserInfo().AdminUser.Id
  223. err = service.UpdateSupplyAndContact(thisStockIn, supplierid, orgId, supplierType, tmodify, supplierCode, supplierName, number, bank, bankAccount, vatRate)
  224. if err != nil {
  225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  226. return
  227. }
  228. } else {
  229. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
  230. return
  231. }
  232. }
  233. this.ServeSuccessJSON(map[string]interface{}{
  234. "list": "保存成功",
  235. })
  236. return
  237. }
  238. //获取单条供应商和涉及到的联系人记录
  239. func (this *SupplyOrderApiController) GetSupplyAndContactOne() {
  240. id, _ := this.GetInt64("id")
  241. if id == 0 {
  242. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
  243. return
  244. }
  245. supply, contact, err := service.GetSupplyAndContactOne(id)
  246. if err != nil {
  247. utils.ErrorLog(err.Error())
  248. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  249. return
  250. }
  251. this.ServeSuccessJSON(map[string]interface{}{
  252. "supply": supply,
  253. "contact": contact,
  254. })
  255. return
  256. }
  257. //获取供应商类别
  258. func (this *SupplyOrderApiController) GetSupplyType() {
  259. orgId := this.GetAdminUserInfo().CurrentOrgId
  260. costClassify := "供应商类别"
  261. drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
  262. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  263. this.ServeSuccessJSON(map[string]interface{}{
  264. "list": drugTypeList,
  265. })
  266. return
  267. }
  268. //删除供应商及联系人
  269. func (this *SupplyOrderApiController) DelSupply() {
  270. //拿到供应商的id
  271. suid, _ := this.GetInt64("id")
  272. if suid == 0 {
  273. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
  274. return
  275. }
  276. supply := models.SpSupplierName{
  277. ID: suid,
  278. }
  279. err := service.DelSupply(supply)
  280. if err != nil {
  281. utils.ErrorLog(err.Error())
  282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  283. return
  284. }
  285. this.ServeSuccessJSON(map[string]interface{}{
  286. "list": "删除成功",
  287. })
  288. return
  289. }
  290. //删除单条联系人记录
  291. func (this *SupplyOrderApiController) DelContactOne() {
  292. id, _ := this.GetInt64("id")
  293. if id == 0 {
  294. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人id不能为空")
  295. return
  296. }
  297. err := service.DelContactOne(id)
  298. if err != nil {
  299. utils.ErrorLog(err.Error())
  300. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  301. return
  302. }
  303. this.ServeSuccessJSON(map[string]interface{}{
  304. "list": "删除成功",
  305. })
  306. return
  307. }
  308. //获取供应商编码
  309. func (this *SupplyOrderApiController) GetSupplyCode() {
  310. supply, err := service.GetSuppliyCode()
  311. if err != nil {
  312. return
  313. }
  314. if len(supply) == 0 { //如果数据库中没有gys类型的编码则设置默认值
  315. //supply[0].SupplierCode ="gys001"
  316. supply = []*models.SpSupplierName{
  317. {
  318. SupplierCode: "gys001",
  319. },
  320. }
  321. } else { //获取数据库中最大的编码值,并加一
  322. tmp := supply[0].SupplierCode
  323. tmp = tmp[3:]
  324. var code int
  325. code, err = strconv.Atoi(tmp)
  326. code++
  327. tmp = strconv.Itoa(code)
  328. for len(tmp) < 3 {
  329. tmp = "0" + tmp
  330. }
  331. tmp = "gys" + tmp
  332. supply[0].SupplierCode = tmp
  333. }
  334. this.ServeSuccessJSON(map[string]interface{}{
  335. "supplycode": supply,
  336. })
  337. return
  338. }
  339. //保存供应商
  340. func (this *SupplyOrderApiController) SaveSupply() {
  341. supplierName := this.GetString("suppliername") //供应商名称
  342. if supplierName == "" {
  343. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称不能为空")
  344. return
  345. }
  346. //判断供应商名称是否有重复的
  347. sbool, _ := service.FindSupplierName(supplierName)
  348. if sbool { //有重复的
  349. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
  350. return
  351. }
  352. supplierCode := this.GetString("suppliercode") //供应商编码
  353. if supplierCode == "" {
  354. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
  355. return
  356. }
  357. //判断供应商编号是否有重复的
  358. codebool, _ := service.FindSupplierCode(supplierCode)
  359. if codebool {
  360. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
  361. return
  362. }
  363. supplierType, _ := this.GetInt64("suppliertype") //供应商类别
  364. vatRate, _ := this.GetFloat("vatrate") //增值税税率
  365. number := this.GetString("number") //纳税人识别号
  366. bank := this.GetString("bank") //开户银行
  367. bankAccount := this.GetString("bankAccount") //银行账号
  368. orgId := this.GetAdminUserInfo().CurrentOrgId
  369. //contacts := this.Get("contacts")//联系人
  370. dataBody := make(map[string]interface{}, 0)
  371. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  372. if err != nil {
  373. utils.ErrorLog(err.Error())
  374. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  375. return
  376. }
  377. //保存联系人
  378. if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
  379. thisStockIn, _ := dataBody["contacts"].([]interface{})
  380. if len(thisStockIn) > 0 {
  381. if len(thisStockIn) == 1 {
  382. for _, item := range thisStockIn {
  383. items := item.(map[string]interface{})
  384. items["IsFirst"] = 1
  385. }
  386. }
  387. tcreater := this.GetAdminUserInfo().AdminUser.Id
  388. err = service.SaveSupplyAndContact(thisStockIn, orgId, supplierType, tcreater, supplierCode, supplierName, number, bank, bankAccount, vatRate)
  389. if err != nil {
  390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  391. return
  392. }
  393. } else {
  394. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
  395. return
  396. }
  397. }
  398. this.ServeSuccessJSON(map[string]interface{}{
  399. "list": "保存成功",
  400. })
  401. return
  402. }
  403. func (this *SupplyOrderApiController) GetInitOrder() {
  404. orgId := this.GetAdminUserInfo().CurrentOrgId
  405. //获取药品库数据
  406. baseList, _ := service.GetSupplyDrugList(orgId)
  407. goodList, _ := service.GetSupplyGoodList(orgId)
  408. manufactuerList, _ := service.GetAllManufacturerList(orgId)
  409. goodTypeList, _ := service.GetAllGoodType(orgId)
  410. supplyList, _ := service.GetSupplierList(orgId)
  411. var drugType = "药品类型"
  412. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  413. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  414. this.ServeSuccessJSON(map[string]interface{}{
  415. "drugList": baseList,
  416. "goodList": goodList,
  417. "manufactuerList": manufactuerList,
  418. "goodTypeList": goodTypeList,
  419. "drugTypeList": drugTypeList,
  420. "supplyList": supplyList,
  421. })
  422. return
  423. }
  424. func (this *SupplyOrderApiController) SavePurchaseOrder() {
  425. supplier_id, _ := this.GetInt64("supplier_name")
  426. start_time := this.GetString("start_time")
  427. end_time := this.GetString("end_time")
  428. timeLayout := "2006-01-02"
  429. loc, _ := time.LoadLocation("Local")
  430. var startTime int64
  431. if len(start_time) > 0 {
  432. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  433. if err != nil {
  434. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  435. return
  436. }
  437. startTime = theTime.Unix()
  438. }
  439. var endTime int64
  440. if len(end_time) > 0 {
  441. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  442. if err != nil {
  443. utils.ErrorLog(err.Error())
  444. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  445. return
  446. }
  447. endTime = theTime.Unix()
  448. }
  449. rate_of_concession := this.GetString("rate_of_concession")
  450. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  451. discount_amount := this.GetString("discount_amount")
  452. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  453. fmt.Println("supplier_id23323232323232", supplier_id, startTime, endTime, rate_of_concession, rate_of_concession_float, discount_amount, discount_amount_float)
  454. dataBody := make(map[string]interface{}, 0)
  455. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  456. if err != nil {
  457. utils.ErrorLog(err.Error())
  458. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  459. return
  460. }
  461. //生成购货订单
  462. timeStr := time.Now().Format("2006-01-02")
  463. timeArr := strings.Split(timeStr, "-")
  464. orgId := this.GetAdminUserInfo().CurrentOrgId
  465. total, _ := service.FindAllSupplyOrder(orgId)
  466. total = total + 1
  467. warehousing_order := "CGDD" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  468. recordDateStr := time.Now().Format("2006-01-02")
  469. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  470. fmt.Scan("parseDateErr", parseDateErr)
  471. record_date := recordDate.Unix()
  472. info := models.SupplierWarehouseInfo{
  473. Number: warehousing_order,
  474. UserOrgId: orgId,
  475. Creater: this.GetAdminUserInfo().AdminUser.Id,
  476. Ctime: time.Now().Unix(),
  477. Mtime: 0,
  478. Status: 1,
  479. RecordDate: record_date,
  480. IsCheck: 2,
  481. RateOfConcession: rate_of_concession_float,
  482. DiscountAmount: discount_amount_float,
  483. DocumentDate: startTime,
  484. DeliveryDate: endTime,
  485. SupplierId: supplier_id,
  486. IsWarehouse: 2,
  487. }
  488. err = service.CreateSupplyWarehouse(info)
  489. warehouseInfo, _ := service.FindLastSupplyWarehouseInfo(orgId)
  490. var warehousingInfo []*models.SupplierWarehousingInfoOrder
  491. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  492. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  493. if len(thisStockIn) > 0 {
  494. for _, item := range thisStockIn {
  495. items := item.(map[string]interface{})
  496. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  497. utils.ErrorLog("project_id")
  498. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  499. return
  500. }
  501. project_id := int64(items["project_id"].(float64))
  502. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  503. utils.ErrorLog("supply_count")
  504. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  505. return
  506. }
  507. supply_count := int64(items["supply_count"].(float64))
  508. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  509. utils.ErrorLog("supply_license_number")
  510. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  511. return
  512. }
  513. supply_license_number := items["supply_license_number"].(string)
  514. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  515. utils.ErrorLog("supply_price")
  516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  517. return
  518. }
  519. supply_price := items["supply_price"].(string)
  520. supply_price_float, _ := strconv.ParseFloat(supply_price, 64)
  521. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  522. utils.ErrorLog("supply_remake")
  523. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  524. return
  525. }
  526. supply_remake := items["supply_remake"].(string)
  527. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  528. utils.ErrorLog("supply_total_price")
  529. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  530. return
  531. }
  532. supply_total_price := items["supply_total_price"].(string)
  533. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  534. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  535. utils.ErrorLog("type")
  536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  537. return
  538. }
  539. is_source := int64(items["type"].(float64))
  540. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  541. utils.ErrorLog("supply_type")
  542. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  543. return
  544. }
  545. supply_type := items["supply_type"].(string)
  546. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  547. utils.ErrorLog("supply_specification_name")
  548. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  549. return
  550. }
  551. supply_specification_name := items["supply_specification_name"].(string)
  552. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  553. utils.ErrorLog("supply_total")
  554. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  555. return
  556. }
  557. supply_total := items["supply_total"].(string)
  558. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  559. utils.ErrorLog("supply_manufacturer")
  560. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  561. return
  562. }
  563. supply_manufacturer := items["supply_manufacturer"].(string)
  564. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  565. utils.ErrorLog("name")
  566. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  567. return
  568. }
  569. name := items["name"].(string)
  570. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  571. utils.ErrorLog("supply_unit")
  572. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  573. return
  574. }
  575. supply_unit := items["supply_unit"].(string)
  576. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  577. utils.ErrorLog("manufacturer_id")
  578. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  579. return
  580. }
  581. manufacturer_id := int64(items["manufacturer_id"].(float64))
  582. order := models.SupplierWarehousingInfoOrder{
  583. OrderNumber: warehousing_order,
  584. IsSource: is_source,
  585. Count: supply_count,
  586. Price: supply_price_float,
  587. Amount: supply_total_price_float,
  588. Remark: supply_remake,
  589. UserOrgId: orgId,
  590. Ctime: time.Now().Unix(),
  591. Status: 1,
  592. Mtime: 0,
  593. WarehousingId: warehouseInfo.ID,
  594. ProjectId: project_id,
  595. SupplyLicenseNumber: supply_license_number,
  596. SupplyType: supply_type,
  597. SupplySpecificationName: supply_specification_name,
  598. SupplyTotal: supply_total,
  599. SupplyManufacturer: supply_manufacturer,
  600. Name: name,
  601. SupplyUnit: supply_unit,
  602. ManufacturerId: manufacturer_id,
  603. }
  604. warehousingInfo = append(warehousingInfo, &order)
  605. }
  606. }
  607. }
  608. for _, item := range warehousingInfo {
  609. err = service.CreateSupplyWarehousingOrder(item)
  610. }
  611. //查询
  612. orderInfo, err := service.GetSupplyWarehousingOrderInfo(warehouseInfo.ID)
  613. if err == nil {
  614. this.ServeSuccessJSON(map[string]interface{}{
  615. "order": warehousingInfo,
  616. "warehouseInfo": warehouseInfo,
  617. "orderInfo": orderInfo,
  618. })
  619. } else {
  620. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  621. }
  622. }
  623. func (this *SupplyOrderApiController) GetAllSupply() {
  624. orgId := this.GetAdminUserInfo().CurrentOrgId
  625. appId := this.GetAdminUserInfo().CurrentAppId
  626. supplyList, err := service.GetSupplierList(orgId)
  627. doctorList, err := service.GetAllDoctor(orgId, appId)
  628. if err == nil {
  629. this.ServeSuccessJSON(map[string]interface{}{
  630. "supplyList": supplyList,
  631. "doctorList": doctorList,
  632. })
  633. } else {
  634. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  635. }
  636. }
  637. func (this *SupplyOrderApiController) GetAllPurchaseOrderList() {
  638. check_id, _ := this.GetInt64("check_id")
  639. start_time := this.GetString("start_time")
  640. end_time := this.GetString("end_time")
  641. timeLayout := "2006-01-02"
  642. loc, _ := time.LoadLocation("Local")
  643. var startTime int64
  644. if len(start_time) > 0 {
  645. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  646. if err != nil {
  647. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  648. return
  649. }
  650. startTime = theTime.Unix()
  651. }
  652. var endTime int64
  653. if len(end_time) > 0 {
  654. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  655. if err != nil {
  656. utils.ErrorLog(err.Error())
  657. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  658. return
  659. }
  660. endTime = theTime.Unix()
  661. }
  662. keyword := this.GetString("keyword")
  663. page, _ := this.GetInt64("page")
  664. limit, _ := this.GetInt64("limit")
  665. orgId := this.GetAdminUserInfo().CurrentOrgId
  666. list, total, err := service.GetAllPurchaseOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
  667. if err == nil {
  668. this.ServeSuccessJSON(map[string]interface{}{
  669. "list": list,
  670. "total": total,
  671. })
  672. } else {
  673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  674. }
  675. }
  676. func (this *SupplyOrderApiController) UpdatePurchaseOrder() {
  677. supplier_id, _ := this.GetInt64("supplier_name")
  678. start_time := this.GetString("start_time")
  679. end_time := this.GetString("end_time")
  680. timeLayout := "2006-01-02"
  681. loc, _ := time.LoadLocation("Local")
  682. var startTime int64
  683. if len(start_time) > 0 {
  684. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  685. if err != nil {
  686. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  687. return
  688. }
  689. startTime = theTime.Unix()
  690. }
  691. var endTime int64
  692. if len(end_time) > 0 {
  693. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  694. if err != nil {
  695. utils.ErrorLog(err.Error())
  696. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  697. return
  698. }
  699. endTime = theTime.Unix()
  700. }
  701. rate_of_concession := this.GetString("rate_of_concession")
  702. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  703. discount_amount := this.GetString("discount_amount")
  704. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  705. warehousing_id, _ := this.GetInt64("id")
  706. number := this.GetString("number")
  707. //fmt.Println("supplier_id23323232323232", supplier_id, startTime, endTime, rate_of_concession, rate_of_concession_float, discount_amount, discount_amount_float)
  708. orgId := this.GetAdminUserInfo().CurrentOrgId
  709. info := models.SupplierWarehouseInfo{
  710. RateOfConcession: rate_of_concession_float,
  711. DiscountAmount: discount_amount_float,
  712. DocumentDate: startTime,
  713. DeliveryDate: endTime,
  714. SupplierId: supplier_id,
  715. Mtime: time.Now().Unix(),
  716. }
  717. service.ModefySupplyWarehouseInfo(warehousing_id, info)
  718. dataBody := make(map[string]interface{}, 0)
  719. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  720. if err != nil {
  721. utils.ErrorLog(err.Error())
  722. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  723. return
  724. }
  725. var warehousingInfo []*models.SupplierWarehousingInfoOrder
  726. var updateWarehousingInfo []*models.SupplierWarehousingInfoOrder
  727. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  728. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  729. if len(thisStockIn) > 0 {
  730. for _, item := range thisStockIn {
  731. items := item.(map[string]interface{})
  732. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  733. utils.ErrorLog("id")
  734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  735. return
  736. }
  737. id := int64(items["id"].(float64))
  738. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  739. utils.ErrorLog("project_id")
  740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. project_id := int64(items["project_id"].(float64))
  744. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  745. utils.ErrorLog("supply_count")
  746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  747. return
  748. }
  749. supply_count := int64(items["supply_count"].(float64))
  750. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  751. utils.ErrorLog("supply_license_number")
  752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  753. return
  754. }
  755. supply_license_number := items["supply_license_number"].(string)
  756. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  757. utils.ErrorLog("supply_price")
  758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  759. return
  760. }
  761. supply_price := items["supply_price"].(string)
  762. supply_price_float, _ := strconv.ParseFloat(supply_price, 64)
  763. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  764. utils.ErrorLog("supply_remake")
  765. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  766. return
  767. }
  768. supply_remake := items["supply_remake"].(string)
  769. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  770. utils.ErrorLog("supply_total_price")
  771. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  772. return
  773. }
  774. supply_total_price := items["supply_total_price"].(string)
  775. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  776. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  777. utils.ErrorLog("type")
  778. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  779. return
  780. }
  781. is_source := int64(items["type"].(float64))
  782. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  783. utils.ErrorLog("supply_type")
  784. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  785. return
  786. }
  787. supply_type := items["supply_type"].(string)
  788. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  789. utils.ErrorLog("supply_specification_name")
  790. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  791. return
  792. }
  793. supply_specification_name := items["supply_specification_name"].(string)
  794. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  795. utils.ErrorLog("supply_total")
  796. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  797. return
  798. }
  799. supply_total := items["supply_total"].(string)
  800. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  801. utils.ErrorLog("supply_manufacturer")
  802. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  803. return
  804. }
  805. supply_manufacturer := items["supply_manufacturer"].(string)
  806. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  807. utils.ErrorLog("name")
  808. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  809. return
  810. }
  811. name := items["name"].(string)
  812. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  813. utils.ErrorLog("supply_unit")
  814. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  815. return
  816. }
  817. supply_unit := items["supply_unit"].(string)
  818. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  819. utils.ErrorLog("manufacturer_id")
  820. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  821. return
  822. }
  823. manufacturer_id := int64(items["manufacturer_id"].(float64))
  824. if id > 0 {
  825. order := models.SupplierWarehousingInfoOrder{
  826. ID: id,
  827. IsSource: is_source,
  828. Count: supply_count,
  829. Price: supply_price_float,
  830. Amount: supply_total_price_float,
  831. Remark: supply_remake,
  832. Ctime: time.Now().Unix(),
  833. Status: 1,
  834. Mtime: 0,
  835. ProjectId: project_id,
  836. SupplyLicenseNumber: supply_license_number,
  837. SupplyType: supply_type,
  838. SupplySpecificationName: supply_specification_name,
  839. SupplyTotal: supply_total,
  840. SupplyManufacturer: supply_manufacturer,
  841. Name: name,
  842. SupplyUnit: supply_unit,
  843. ManufacturerId: manufacturer_id,
  844. }
  845. updateWarehousingInfo = append(updateWarehousingInfo, &order)
  846. }
  847. if id == 0 {
  848. order := models.SupplierWarehousingInfoOrder{
  849. OrderNumber: number,
  850. IsSource: is_source,
  851. Count: supply_count,
  852. Price: supply_price_float,
  853. Amount: supply_total_price_float,
  854. Remark: supply_remake,
  855. UserOrgId: orgId,
  856. Ctime: time.Now().Unix(),
  857. Status: 1,
  858. Mtime: 0,
  859. WarehousingId: warehousing_id,
  860. ProjectId: project_id,
  861. SupplyLicenseNumber: supply_license_number,
  862. SupplyType: supply_type,
  863. SupplySpecificationName: supply_specification_name,
  864. SupplyTotal: supply_total,
  865. SupplyManufacturer: supply_manufacturer,
  866. Name: name,
  867. SupplyUnit: supply_unit,
  868. ManufacturerId: manufacturer_id,
  869. }
  870. warehousingInfo = append(warehousingInfo, &order)
  871. }
  872. }
  873. }
  874. if len(warehousingInfo) > 0 {
  875. for _, item := range warehousingInfo {
  876. service.CreateSupplyWarehousingOrder(item)
  877. }
  878. }
  879. if len(updateWarehousingInfo) > 0 {
  880. for _, item := range updateWarehousingInfo {
  881. service.ModifySupplyWarehouseOrder(item)
  882. }
  883. }
  884. this.ServeSuccessJSON(map[string]interface{}{
  885. "warehousingInfo": warehousingInfo,
  886. })
  887. }
  888. }
  889. func (this *SupplyOrderApiController) UpdateSupplyWaresing() {
  890. id, _ := this.GetInt64("id")
  891. recordDateStr := time.Now().Format("2006-01-02")
  892. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  893. record_date := recordDate.Unix()
  894. checker := this.GetAdminUserInfo().AdminUser.Id
  895. info := models.SupplierWarehouseInfo{
  896. Mtime: time.Now().Unix(),
  897. Status: 1,
  898. IsCheck: 1,
  899. Checker: checker,
  900. CheckTime: record_date,
  901. }
  902. parseDateErr := service.UpdateSupplyWaresing(id, info)
  903. if parseDateErr == nil {
  904. this.ServeSuccessJSON(map[string]interface{}{
  905. "info": info,
  906. })
  907. } else {
  908. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  909. }
  910. }
  911. func (this *SupplyOrderApiController) GetPurchaseOrderDetail() {
  912. id, _ := this.GetInt64("id")
  913. info, _ := service.GetPurchaseOrderDetail(id)
  914. //查询
  915. orderInfo, err := service.GetSupplyWarehousingOrderInfo(id)
  916. orgId := this.GetAdminUserInfo().CurrentOrgId
  917. supplyList, _ := service.GetSupplierList(orgId)
  918. //获取药品库数据
  919. baseList, _ := service.GetSupplyDrugList(orgId)
  920. goodList, _ := service.GetSupplyGoodList(orgId)
  921. if err == nil {
  922. this.ServeSuccessJSON(map[string]interface{}{
  923. "info": info,
  924. "orderInfo": orderInfo,
  925. "supplyList": supplyList,
  926. "baseList": baseList,
  927. "goodList": goodList,
  928. })
  929. } else {
  930. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  931. }
  932. }
  933. func (this *SupplyOrderApiController) AddGoodOrder() {
  934. supplier_id, _ := this.GetInt64("supplier_id")
  935. start_time := this.GetString("start")
  936. timeLayout := "2006-01-02"
  937. loc, _ := time.LoadLocation("Local")
  938. var startTime int64
  939. if len(start_time) > 0 {
  940. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  941. if err != nil {
  942. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  943. return
  944. }
  945. startTime = theTime.Unix()
  946. }
  947. arrerage := this.GetString("arrerage")
  948. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  949. payment := this.GetString("payment")
  950. payment_float, _ := strconv.ParseFloat(payment, 64)
  951. warehousing_id, _ := this.GetInt64("warehousing_id")
  952. number := this.GetString("number")
  953. rate_of_concession := this.GetString("rate_of_concession")
  954. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  955. discount_amount := this.GetString("discount_amount")
  956. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  957. fmt.Println(supplier_id, startTime, arrerage, payment, warehousing_id, number, rate_of_concession, discount_amount)
  958. orgId := this.GetAdminUserInfo().CurrentOrgId
  959. creater := this.GetAdminUserInfo().AdminUser.Id
  960. //生成购货单
  961. timeStr := time.Now().Format("2006-01-02")
  962. timeArr := strings.Split(timeStr, "-")
  963. total, _ := service.FindAllSupplyWarehouseOutOrder(orgId)
  964. total = total + 1
  965. warehousing_order := "CG" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  966. recordDateStr := time.Now().Format("2006-01-02")
  967. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  968. warehouse_out := models.SpSupplierWarehouseOut{
  969. Number: number,
  970. UserOrgId: orgId,
  971. Creater: creater,
  972. Ctime: time.Now().Unix(),
  973. Mtime: 0,
  974. Status: 1,
  975. RecordDate: recordDate.Unix(),
  976. IsCheck: 2,
  977. WarehousingId: warehousing_id,
  978. GoodNumber: warehousing_order,
  979. Arrearage: arrerage_float,
  980. Payment: payment_float,
  981. RateOfConcession: rate_of_concession_float,
  982. DiscountAmount: discount_amount_float,
  983. DocumentDate: startTime,
  984. SupplierId: supplier_id,
  985. Checker: 0,
  986. CheckTime: 0,
  987. }
  988. service.CreateSupplyWarehouseOut(warehouse_out)
  989. //获取最后一条
  990. warehouseOut, _ := service.FindSupplyWarehouseOutById(orgId)
  991. dataBody := make(map[string]interface{}, 0)
  992. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  993. if err != nil {
  994. utils.ErrorLog(err.Error())
  995. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  996. return
  997. }
  998. var warehousingOut []*models.SpSupplierWarehousingOutOrder
  999. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  1000. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  1001. if len(thisStockIn) > 0 {
  1002. for _, item := range thisStockIn {
  1003. items := item.(map[string]interface{})
  1004. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  1005. utils.ErrorLog("supply_count")
  1006. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1007. return
  1008. }
  1009. supply_count := int64(items["supply_count"].(float64))
  1010. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1011. utils.ErrorLog("id")
  1012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1013. return
  1014. }
  1015. id := int64(items["id"].(float64))
  1016. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  1017. utils.ErrorLog("manufacturer_id")
  1018. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1019. return
  1020. }
  1021. manufacturer_id := int64(items["manufacturer_id"].(float64))
  1022. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1023. utils.ErrorLog("name")
  1024. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1025. return
  1026. }
  1027. name := items["name"].(string)
  1028. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  1029. utils.ErrorLog("order_number")
  1030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1031. return
  1032. }
  1033. order_number := items["order_number"].(string)
  1034. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  1035. utils.ErrorLog("supply_price")
  1036. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1037. return
  1038. }
  1039. supply_price := items["supply_price"].(string)
  1040. price_float, _ := strconv.ParseFloat(supply_price, 64)
  1041. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  1042. utils.ErrorLog("supply_total_price")
  1043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1044. return
  1045. }
  1046. supply_total_price := items["supply_total_price"].(string)
  1047. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  1048. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  1049. utils.ErrorLog("project_id")
  1050. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1051. return
  1052. }
  1053. project_id := int64(items["project_id"].(float64))
  1054. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  1055. utils.ErrorLog("supply_remake")
  1056. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1057. return
  1058. }
  1059. supply_remake := items["supply_remake"].(string)
  1060. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  1061. utils.ErrorLog("supply_batch_number")
  1062. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1063. return
  1064. }
  1065. supply_batch_number := items["supply_batch_number"].(string)
  1066. var supply_expiry_date_time int64
  1067. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "string" {
  1068. utils.ErrorLog("supply_expiry_date")
  1069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1070. return
  1071. }
  1072. supply_expiry_date := items["supply_expiry_date"].(string)
  1073. if len(supply_expiry_date) > 0 {
  1074. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_expiry_date+" 00:00:00", loc)
  1075. if err != nil {
  1076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1077. return
  1078. }
  1079. supply_expiry_date_time = theTime.Unix()
  1080. }
  1081. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  1082. utils.ErrorLog("supply_license_number")
  1083. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1084. return
  1085. }
  1086. supply_license_number := items["supply_license_number"].(string)
  1087. var supply_product_date_time int64
  1088. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "string" {
  1089. utils.ErrorLog("supply_product_date")
  1090. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1091. return
  1092. }
  1093. supply_product_date := items["supply_product_date"].(string)
  1094. if len(supply_product_date) > 0 {
  1095. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_product_date+" 00:00:00", loc)
  1096. if err != nil {
  1097. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1098. return
  1099. }
  1100. supply_product_date_time = theTime.Unix()
  1101. }
  1102. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  1103. utils.ErrorLog("supply_specification_name")
  1104. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1105. return
  1106. }
  1107. supply_specification_name := items["supply_specification_name"].(string)
  1108. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  1109. utils.ErrorLog("supply_total")
  1110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1111. return
  1112. }
  1113. supply_total := items["supply_total"].(string)
  1114. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  1115. utils.ErrorLog("supply_type")
  1116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1117. return
  1118. }
  1119. supply_type := items["supply_type"].(string)
  1120. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  1121. utils.ErrorLog("supply_unit")
  1122. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1123. return
  1124. }
  1125. supply_unit := items["supply_unit"].(string)
  1126. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1127. utils.ErrorLog("type")
  1128. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1129. return
  1130. }
  1131. is_source := int64(items["type"].(float64))
  1132. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  1133. utils.ErrorLog("supply_manufacturer")
  1134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1135. return
  1136. }
  1137. supply_manufacturer := items["supply_manufacturer"].(string)
  1138. order := models.SpSupplierWarehousingOutOrder{
  1139. OrderNumber: order_number,
  1140. ProjectId: project_id,
  1141. IsSource: is_source,
  1142. Count: supply_count,
  1143. Amount: supply_total_price_float,
  1144. Price: price_float,
  1145. Remark: supply_remake,
  1146. IsCheck: 2,
  1147. UserOrgId: orgId,
  1148. Status: 1,
  1149. Ctime: time.Now().Unix(),
  1150. Mtime: 0,
  1151. WarehouseOutId: warehouseOut.ID,
  1152. Type: 1,
  1153. SupplyBatchNumber: supply_batch_number,
  1154. SupplyProductDate: supply_product_date_time,
  1155. SupplyExpiryDate: supply_expiry_date_time,
  1156. WarehousingId: warehousing_id,
  1157. WarehouseInfoId: id,
  1158. SupplyType: supply_type,
  1159. SupplyUnit: supply_unit,
  1160. SupplyTotal: supply_total,
  1161. SupplySpecificationName: supply_specification_name,
  1162. SupplyLicenseNumber: supply_license_number,
  1163. Name: name,
  1164. ManufacturerId: manufacturer_id,
  1165. GoodNumber: warehouseOut.GoodNumber,
  1166. SupplyManufacturer: supply_manufacturer,
  1167. }
  1168. warehousingOut = append(warehousingOut, &order)
  1169. }
  1170. }
  1171. }
  1172. for _, item := range warehousingOut {
  1173. //如果是手动新增的,type 等于2
  1174. if item.WarehouseInfoId == 0 {
  1175. item.Type = 2
  1176. }
  1177. err = service.CreateSupplyWarehousOutOrder(item)
  1178. }
  1179. list, parseDateErr := service.GetSupplyWarehouseOutById(warehouseOut.ID, orgId)
  1180. if parseDateErr == nil {
  1181. this.ServeSuccessJSON(map[string]interface{}{
  1182. "list": list,
  1183. "warehouseOut": warehouseOut,
  1184. })
  1185. } else {
  1186. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1187. }
  1188. }
  1189. func (this *SupplyOrderApiController) GetAllGoodOderList() {
  1190. check_id, _ := this.GetInt64("check_id")
  1191. start_time := this.GetString("start_time")
  1192. end_time := this.GetString("end_time")
  1193. keyword := this.GetString("keyword")
  1194. page, _ := this.GetInt64("page")
  1195. limit, _ := this.GetInt64("limit")
  1196. timeLayout := "2006-01-02"
  1197. loc, _ := time.LoadLocation("Local")
  1198. var startTime int64
  1199. if len(start_time) > 0 {
  1200. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1201. if err != nil {
  1202. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1203. return
  1204. }
  1205. startTime = theTime.Unix()
  1206. }
  1207. var endTime int64
  1208. if len(end_time) > 0 {
  1209. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1210. if err != nil {
  1211. utils.ErrorLog(err.Error())
  1212. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1213. return
  1214. }
  1215. endTime = theTime.Unix()
  1216. }
  1217. orgId := this.GetAdminUserInfo().CurrentOrgId
  1218. list, total, err := service.GetAllGoodOderList(check_id, keyword, page, limit, startTime, endTime, orgId)
  1219. if err == nil {
  1220. this.ServeSuccessJSON(map[string]interface{}{
  1221. "list": list,
  1222. "total": total,
  1223. })
  1224. } else {
  1225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1226. }
  1227. }
  1228. func (this *SupplyOrderApiController) GetGoodOrderDetail() {
  1229. id, _ := this.GetInt64("id")
  1230. orgId := this.GetAdminUserInfo().CurrentOrgId
  1231. out, err := service.GetGoodOrderDetail(id, orgId)
  1232. list, _ := service.GetSupplyWarehouseOutById(id, orgId)
  1233. drugList, _ := service.GetSupplyDrugList(orgId)
  1234. goodList, _ := service.GetSupplyGoodList(orgId)
  1235. if err == nil {
  1236. this.ServeSuccessJSON(map[string]interface{}{
  1237. "out": out,
  1238. "list": list,
  1239. "goodList": goodList,
  1240. "drugList": drugList,
  1241. })
  1242. } else {
  1243. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1244. }
  1245. }
  1246. func (this *SupplyOrderApiController) UpdateGoodOrder() {
  1247. supplier_id, _ := this.GetInt64("supplier_id")
  1248. start_time := this.GetString("start")
  1249. timeLayout := "2006-01-02"
  1250. loc, _ := time.LoadLocation("Local")
  1251. var startTime int64
  1252. if len(start_time) > 0 {
  1253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1254. if err != nil {
  1255. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. startTime = theTime.Unix()
  1259. }
  1260. arrerage := this.GetString("arrerage")
  1261. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  1262. payment := this.GetString("payment")
  1263. payment_float, _ := strconv.ParseFloat(payment, 64)
  1264. warehose_out_id, _ := this.GetInt64("warehose_out_id")
  1265. number := this.GetString("number")
  1266. rate_of_concession := this.GetString("rate_of_concession")
  1267. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  1268. discount_amount := this.GetString("discount_amount")
  1269. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  1270. good_number := this.GetString("good_number")
  1271. fmt.Println(supplier_id, startTime, arrerage, payment, warehose_out_id, number, rate_of_concession, discount_amount)
  1272. orgId := this.GetAdminUserInfo().CurrentOrgId
  1273. dataBody := make(map[string]interface{}, 0)
  1274. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1275. if err != nil {
  1276. utils.ErrorLog(err.Error())
  1277. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1278. return
  1279. }
  1280. var warehousingOut []*models.SpSupplierWarehousingOutOrder
  1281. var updateWarehout []*models.SpSupplierWarehousingOutOrder
  1282. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  1283. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  1284. if len(thisStockIn) > 0 {
  1285. for _, item := range thisStockIn {
  1286. items := item.(map[string]interface{})
  1287. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1288. utils.ErrorLog("id")
  1289. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1290. return
  1291. }
  1292. id := int64(items["id"].(float64))
  1293. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  1294. utils.ErrorLog("supply_count")
  1295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1296. return
  1297. }
  1298. supply_count := int64(items["supply_count"].(float64))
  1299. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  1300. utils.ErrorLog("manufacturer_id")
  1301. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1302. return
  1303. }
  1304. manufacturer_id := int64(items["manufacturer_id"].(float64))
  1305. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1306. utils.ErrorLog("name")
  1307. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1308. return
  1309. }
  1310. name := items["name"].(string)
  1311. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  1312. utils.ErrorLog("order_number")
  1313. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1314. return
  1315. }
  1316. order_number := items["order_number"].(string)
  1317. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  1318. utils.ErrorLog("supply_price")
  1319. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1320. return
  1321. }
  1322. supply_price := items["supply_price"].(string)
  1323. price_float, _ := strconv.ParseFloat(supply_price, 64)
  1324. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  1325. utils.ErrorLog("supply_total_price")
  1326. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1327. return
  1328. }
  1329. supply_total_price := items["supply_total_price"].(string)
  1330. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  1331. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  1332. utils.ErrorLog("project_id")
  1333. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1334. return
  1335. }
  1336. project_id := int64(items["project_id"].(float64))
  1337. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  1338. utils.ErrorLog("supply_remake")
  1339. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1340. return
  1341. }
  1342. supply_remake := items["supply_remake"].(string)
  1343. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  1344. utils.ErrorLog("supply_batch_number")
  1345. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1346. return
  1347. }
  1348. supply_batch_number := items["supply_batch_number"].(string)
  1349. var supply_expiry_date_time int64
  1350. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "string" {
  1351. utils.ErrorLog("supply_expiry_date")
  1352. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1353. return
  1354. }
  1355. supply_expiry_date := items["supply_expiry_date"].(string)
  1356. if len(supply_expiry_date) > 0 {
  1357. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_expiry_date+" 00:00:00", loc)
  1358. if err != nil {
  1359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1360. return
  1361. }
  1362. supply_expiry_date_time = theTime.Unix()
  1363. }
  1364. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  1365. utils.ErrorLog("supply_license_number")
  1366. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1367. return
  1368. }
  1369. supply_license_number := items["supply_license_number"].(string)
  1370. var supply_product_date_time int64
  1371. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "string" {
  1372. utils.ErrorLog("supply_product_date")
  1373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1374. return
  1375. }
  1376. supply_product_date := items["supply_product_date"].(string)
  1377. if len(supply_product_date) > 0 {
  1378. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_product_date+" 00:00:00", loc)
  1379. if err != nil {
  1380. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1381. return
  1382. }
  1383. supply_product_date_time = theTime.Unix()
  1384. }
  1385. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  1386. utils.ErrorLog("supply_specification_name")
  1387. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1388. return
  1389. }
  1390. supply_specification_name := items["supply_specification_name"].(string)
  1391. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  1392. utils.ErrorLog("supply_total")
  1393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1394. return
  1395. }
  1396. supply_total := items["supply_total"].(string)
  1397. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  1398. utils.ErrorLog("supply_type")
  1399. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1400. return
  1401. }
  1402. supply_type := items["supply_type"].(string)
  1403. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  1404. utils.ErrorLog("supply_unit")
  1405. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1406. return
  1407. }
  1408. supply_unit := items["supply_unit"].(string)
  1409. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1410. utils.ErrorLog("type")
  1411. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1412. return
  1413. }
  1414. is_source := int64(items["type"].(float64))
  1415. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  1416. utils.ErrorLog("supply_manufacturer")
  1417. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1418. return
  1419. }
  1420. supply_manufacturer := items["supply_manufacturer"].(string)
  1421. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  1422. utils.ErrorLog("warehouse_info_id")
  1423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1424. return
  1425. }
  1426. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1427. if items["warehousing_id"] == nil || reflect.TypeOf(items["warehousing_id"]).String() != "float64" {
  1428. utils.ErrorLog("warehouse_info_id")
  1429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1430. return
  1431. }
  1432. warehousing_id := int64(items["warehousing_id"].(float64))
  1433. if id > 0 {
  1434. order := models.SpSupplierWarehousingOutOrder{
  1435. ID: id,
  1436. OrderNumber: order_number,
  1437. ProjectId: project_id,
  1438. IsSource: is_source,
  1439. Count: supply_count,
  1440. Amount: supply_total_price_float,
  1441. Price: price_float,
  1442. Remark: supply_remake,
  1443. IsCheck: 2,
  1444. UserOrgId: orgId,
  1445. Status: 1,
  1446. Ctime: time.Now().Unix(),
  1447. Mtime: 0,
  1448. WarehouseOutId: warehose_out_id,
  1449. Type: 1,
  1450. SupplyBatchNumber: supply_batch_number,
  1451. SupplyProductDate: supply_product_date_time,
  1452. SupplyExpiryDate: supply_expiry_date_time,
  1453. SupplyType: supply_type,
  1454. SupplyUnit: supply_unit,
  1455. SupplyTotal: supply_total,
  1456. SupplySpecificationName: supply_specification_name,
  1457. SupplyLicenseNumber: supply_license_number,
  1458. Name: name,
  1459. ManufacturerId: manufacturer_id,
  1460. GoodNumber: good_number,
  1461. SupplyManufacturer: supply_manufacturer,
  1462. WarehouseInfoId: warehouse_info_id,
  1463. WarehousingId: warehousing_id,
  1464. }
  1465. updateWarehout = append(updateWarehout, &order)
  1466. }
  1467. if id == 0 {
  1468. order := models.SpSupplierWarehousingOutOrder{
  1469. OrderNumber: order_number,
  1470. ProjectId: project_id,
  1471. IsSource: is_source,
  1472. Count: supply_count,
  1473. Amount: supply_total_price_float,
  1474. Price: price_float,
  1475. Remark: supply_remake,
  1476. IsCheck: 2,
  1477. UserOrgId: orgId,
  1478. Status: 1,
  1479. Ctime: time.Now().Unix(),
  1480. Mtime: 0,
  1481. WarehouseOutId: warehose_out_id,
  1482. Type: 1,
  1483. SupplyBatchNumber: supply_batch_number,
  1484. SupplyProductDate: supply_product_date_time,
  1485. SupplyExpiryDate: supply_expiry_date_time,
  1486. WarehouseInfoId: id,
  1487. SupplyType: supply_type,
  1488. SupplyUnit: supply_unit,
  1489. SupplyTotal: supply_total,
  1490. SupplySpecificationName: supply_specification_name,
  1491. SupplyLicenseNumber: supply_license_number,
  1492. Name: name,
  1493. ManufacturerId: manufacturer_id,
  1494. GoodNumber: good_number,
  1495. SupplyManufacturer: supply_manufacturer,
  1496. }
  1497. warehousingOut = append(warehousingOut, &order)
  1498. }
  1499. }
  1500. }
  1501. }
  1502. out := models.SpSupplierWarehouseOut{
  1503. Arrearage: arrerage_float,
  1504. Payment: payment_float,
  1505. RateOfConcession: rate_of_concession_float,
  1506. DiscountAmount: discount_amount_float,
  1507. SupplierId: supplier_id,
  1508. DocumentDate: startTime,
  1509. }
  1510. //更改购货单据
  1511. service.UpdateGoodWarehouseOut(warehose_out_id, out)
  1512. for _, item := range warehousingOut {
  1513. //如果是手动新增的,type 等于2
  1514. if item.WarehouseInfoId == 0 {
  1515. item.Type = 2
  1516. }
  1517. err = service.CreateSupplyWarehousOutOrder(item)
  1518. }
  1519. for _, item := range updateWarehout {
  1520. service.UpdateGoodWarehouseOutOrder(item)
  1521. }
  1522. if err == nil {
  1523. this.ServeSuccessJSON(map[string]interface{}{
  1524. "out": out,
  1525. })
  1526. } else {
  1527. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1528. }
  1529. }
  1530. func (this *SupplyOrderApiController) DeletePurchOrder() {
  1531. id, _ := this.GetInt64("id")
  1532. orgId := this.GetAdminUserInfo().CurrentOrgId
  1533. err := service.DeletePurchOrder(id, orgId)
  1534. if err == nil {
  1535. returnData := make(map[string]interface{}, 0)
  1536. returnData["msg"] = "ok"
  1537. this.ServeSuccessJSON(returnData)
  1538. return
  1539. } else {
  1540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1541. }
  1542. }
  1543. func (this *SupplyOrderApiController) GetAllOrderCountList() {
  1544. id, _ := this.GetInt64("id")
  1545. orgId := this.GetAdminUserInfo().CurrentOrgId
  1546. //获取购货订单的数据
  1547. purcaseOrder, _ := service.GetAllPurcaseOrderById(id, orgId)
  1548. //获取购货单的数据
  1549. goodOrder, err := service.GetAllGoodOrderById(id, orgId)
  1550. drugList, err := service.GetSupplyDrugList(orgId)
  1551. if err == nil {
  1552. this.ServeSuccessJSON(map[string]interface{}{
  1553. "purcaseOrder": purcaseOrder,
  1554. "goodOrder": goodOrder,
  1555. "drugList": drugList,
  1556. })
  1557. } else {
  1558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1559. }
  1560. }
  1561. func (this *SupplyOrderApiController) GetPurchOrderInfo() {
  1562. id, _ := this.GetInt64("id")
  1563. ids := this.GetString("ids")
  1564. if len(ids) == 0 {
  1565. info, _ := service.GetPurchaseOrderDetail(id)
  1566. //查询
  1567. orderInfo, err := service.GetSupplyWarehousingOrderInfo(id)
  1568. orgId := this.GetAdminUserInfo().CurrentOrgId
  1569. supplyList, _ := service.GetSupplierList(orgId)
  1570. //获取药品库数据
  1571. baseList, _ := service.GetSupplyDrugList(orgId)
  1572. goodList, _ := service.GetSupplyGoodList(orgId)
  1573. if err == nil {
  1574. this.ServeSuccessJSON(map[string]interface{}{
  1575. "info": info,
  1576. "orderInfo": orderInfo,
  1577. "supplyList": supplyList,
  1578. "baseList": baseList,
  1579. "goodList": goodList,
  1580. })
  1581. } else {
  1582. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1583. }
  1584. }
  1585. if len(ids) > 0 {
  1586. idArray := strings.Split(ids, ",")
  1587. info, _ := service.GetPurchaseOrderDetail(id)
  1588. //查询
  1589. orderInfo, err := service.GetSupplyWarehousingOrderInfoTwo(id, idArray)
  1590. orgId := this.GetAdminUserInfo().CurrentOrgId
  1591. supplyList, _ := service.GetSupplierList(orgId)
  1592. //获取药品库数据
  1593. baseList, _ := service.GetSupplyDrugList(orgId)
  1594. goodList, _ := service.GetSupplyGoodList(orgId)
  1595. if err == nil {
  1596. this.ServeSuccessJSON(map[string]interface{}{
  1597. "info": info,
  1598. "orderInfo": orderInfo,
  1599. "supplyList": supplyList,
  1600. "baseList": baseList,
  1601. "goodList": goodList,
  1602. })
  1603. } else {
  1604. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1605. }
  1606. }
  1607. }
  1608. func (this *SupplyOrderApiController) GetGoodOrderList() {
  1609. id, _ := this.GetInt64("id")
  1610. orgId := this.GetAdminUserInfo().CurrentOrgId
  1611. list, err := service.GetGoodOrderList(id, orgId)
  1612. if err == nil {
  1613. this.ServeSuccessJSON(map[string]interface{}{
  1614. "list": list,
  1615. })
  1616. } else {
  1617. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1618. }
  1619. }
  1620. func (this *SupplyOrderApiController) GetReturnOrder() {
  1621. id, _ := this.GetInt64("id")
  1622. orgId := this.GetAdminUserInfo().CurrentOrgId
  1623. err := service.GetReturnOrder(id, orgId)
  1624. if err == nil {
  1625. returnData := make(map[string]interface{}, 0)
  1626. returnData["msg"] = "ok"
  1627. this.ServeSuccessJSON(returnData)
  1628. return
  1629. } else {
  1630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1631. }
  1632. }
  1633. func (this *SupplyOrderApiController) GetGoodOrderCountList() {
  1634. id, _ := this.GetInt64("id")
  1635. warehousing_id, _ := this.GetInt64("warehousing_id")
  1636. orgId := this.GetAdminUserInfo().CurrentOrgId
  1637. checker := this.GetAdminUserInfo().AdminUser.Id
  1638. recordDateStr := time.Now().Format("2006-01-02")
  1639. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1640. record_date := recordDate.Unix()
  1641. out := models.SpSupplierWarehouseOut{
  1642. IsCheck: 1,
  1643. Checker: checker,
  1644. CheckTime: record_date,
  1645. }
  1646. err := service.CheckGoodOrder(id, orgId, out)
  1647. //获取购货订单的数据
  1648. purcaseOrder, _ := service.GetAllPurcaseOrderById(warehousing_id, orgId)
  1649. //获取购货单的数据
  1650. goodOrder, _ := service.GetAllGoodOrderByIdTwo(warehousing_id, orgId)
  1651. //查询该购货单是否审核成功
  1652. detail, _ := service.GetGoodOrderDetail(id, orgId)
  1653. var warehousingInfo []*models.WarehousingInfo
  1654. //如果审核成功
  1655. if detail.IsCheck == 1 {
  1656. //入库
  1657. if len(goodOrder) > 0 {
  1658. for _, item := range goodOrder {
  1659. //药品
  1660. if item.IsSource == 1 {
  1661. }
  1662. //耗材
  1663. if item.IsSource == 2 {
  1664. //获取耗材类型
  1665. good, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1666. timeStr := time.Now().Format("2006-01-02")
  1667. timeArr := strings.Split(timeStr, "-")
  1668. total, _ := service.FindAllWarehouseTotal(orgId)
  1669. total = total + 1
  1670. warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1671. operation_time := time.Now().Unix()
  1672. creater := this.GetAdminUserInfo().AdminUser.Id
  1673. warehousing := models.Warehousing{
  1674. WarehousingOrder: warehousing_order,
  1675. OperationTime: operation_time,
  1676. OrgId: orgId,
  1677. Creater: creater,
  1678. Ctime: time.Now().Unix(),
  1679. Status: 1,
  1680. WarehousingTime: record_date,
  1681. Type: 1,
  1682. }
  1683. service.AddSigleWarehouse(&warehousing)
  1684. //入库单表格
  1685. warehouseInfo := &models.WarehousingInfo{
  1686. WarehousingOrder: warehousing.WarehousingOrder,
  1687. WarehousingId: warehousing.ID,
  1688. GoodId: item.ProjectId,
  1689. Number: item.SupplyBatchNumber,
  1690. GoodTypeId: good.GoodTypeId,
  1691. ProductDate: item.SupplyProductDate,
  1692. ExpiryDate: item.SupplyExpiryDate,
  1693. WarehousingCount: item.Count,
  1694. Price: item.Price,
  1695. TotalPrice: 0,
  1696. Status: 1,
  1697. Ctime: time.Now().Unix(),
  1698. Remark: item.Remark,
  1699. OrgId: orgId,
  1700. Type: 1,
  1701. Manufacturer: item.ManufacturerId,
  1702. StockCount: item.Count,
  1703. Dealer: good.Dealer,
  1704. LicenseNumber: item.SupplyLicenseNumber,
  1705. PackingPrice: good.PackingPrice,
  1706. }
  1707. warehousingInfo = append(warehousingInfo, warehouseInfo)
  1708. }
  1709. }
  1710. }
  1711. }
  1712. drugList, _ := service.GetSupplyDrugList(orgId)
  1713. if err == nil {
  1714. this.ServeSuccessJSON(map[string]interface{}{
  1715. "purcaseOrder": purcaseOrder,
  1716. "goodOrder": goodOrder,
  1717. "drugList": drugList,
  1718. })
  1719. } else {
  1720. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1721. }
  1722. }