stock_in_api_controller.go 115KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611
  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 StockManagerApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func StockManagerApiRegistRouters() {
  20. //入库管理和其他入库管理相关接口
  21. beego.Router("/api/warehouse/create", &StockManagerApiController{}, "post:CreateWarehouse")
  22. beego.Router("/api/warehouse/list", &StockManagerApiController{}, "get:GetWarehouseList")
  23. beego.Router("/api/warehouse/delete", &StockManagerApiController{}, "post:DeleteWarehouse")
  24. beego.Router("/api/warehouseinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseInfo")
  25. beego.Router("/api/warehouseinfo/list", &StockManagerApiController{}, "get:GetWarehouseInfoList")
  26. beego.Router("/api/warehouse/edit", &StockManagerApiController{}, "post:EditWarehouse")
  27. //退货管理和其他退货管理相关接口
  28. beego.Router("/api/salesreturn/create", &StockManagerApiController{}, "post:CreateSalesReturn")
  29. beego.Router("/api/salesreturn/delete", &StockManagerApiController{}, "post:DeleteSalesReturn")
  30. beego.Router("/api/salesreturninfo/delete", &StockManagerApiController{}, "post:DeleteSalesReturnInfo")
  31. beego.Router("/api/salesreturninfo/list", &StockManagerApiController{}, "get:GetSalesReturnInfoList")
  32. beego.Router("/api/salesreturn/list", &StockManagerApiController{}, "get:GetSalesReturnList")
  33. beego.Router("/api/salesreturn/edit", &StockManagerApiController{}, "post:EditReturnInfo")
  34. //出库管理和其他出库管理相关接口
  35. beego.Router("/api/warehouseout/create", &StockManagerApiController{}, "post:CreateWarehouseOut")
  36. beego.Router("/api/warehouseout/delete", &StockManagerApiController{}, "post:DeleteWarehouseOut")
  37. beego.Router("/api/warehouseoutinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseOutInfo")
  38. beego.Router("/api/warehouseout/list", &StockManagerApiController{}, "get:GetWarehouseOutList")
  39. beego.Router("/api/warehouseout/edit", &StockManagerApiController{}, "post:EditWarehouseOut")
  40. beego.Router("/api/warehouseout/info", &StockManagerApiController{}, "get:GetWarehouseOutInfoList")
  41. //出库退库管理和其他出库退库管理相关接口
  42. beego.Router("/api/cancelstock/create", &StockManagerApiController{}, "post:CreateCancelStock")
  43. beego.Router("/api/cancelstock/list", &StockManagerApiController{}, "get:GetCancelStockList")
  44. beego.Router("/api/cancelstock/info", &StockManagerApiController{}, "get:GetCancelStockInfoList")
  45. beego.Router("/api/cancelstock/delete", &StockManagerApiController{}, "post:DeleteCancelStock")
  46. beego.Router("/api/cancelstockinfo/delete", &StockManagerApiController{}, "post:DeleteCancelStockInfo")
  47. beego.Router("/api/cancelstockinfo/edit", &StockManagerApiController{}, "post:EditCancelStock")
  48. beego.Router("/api/cancelstockinfo/config", &StockManagerApiController{}, "get:GetCancelStockConfig")
  49. //库存相关全局配置
  50. beego.Router("/api/stock/config", &StockManagerApiController{}, "get:GetAllConfig")
  51. beego.Router("/api/return/config", &StockManagerApiController{}, "get:GetAllSalesReturnConfig")
  52. //库存查询
  53. beego.Router("/api/stock/query", &StockManagerApiController{}, "get:GetQueryInfo")
  54. beego.Router("/api/stock/detail", &StockManagerApiController{}, "get:GetDetailInfo")
  55. beego.Router("/api/warehouseout/user", &StockManagerApiController{}, "get:GetUserDetailInfo")
  56. beego.Router("/api/warehouseout/postsearchstock", &StockManagerApiController{}, "Get:PostSearchStock")
  57. beego.Router("/api/warehouseout/getoutstocktotalcount", &StockManagerApiController{}, "Get:GetOutStockTotalCount")
  58. beego.Router("/api/good/postgoodinformation", &StockManagerApiController{}, "Post:AddGoodInformation")
  59. beego.Router("/api/good/postdruginformation", &StockManagerApiController{}, "Post:AddDrugInformation")
  60. beego.Router("/api/good/initializtion", &StockManagerApiController{}, "Get:GetInitializtion")
  61. beego.Router("/api/good/getwarehouseorderinfolist", &StockManagerApiController{}, "Get:GetWarehouseOrderInfolist")
  62. beego.Router("/api/good/postsearchgoodlist", &StockManagerApiController{}, "Get:PostSearchGoodList")
  63. }
  64. func (c *StockManagerApiController) CreateWarehouse() {
  65. warehousing_time := c.GetString("warehousing_time")
  66. dealer_id, _ := c.GetInt64("dealer_id", 0)
  67. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  68. types, _ := c.GetInt64("type", 0)
  69. ctime := time.Now().Unix()
  70. adminUserInfo := c.GetAdminUserInfo()
  71. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  72. if parseDateErr != nil {
  73. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  74. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  75. return
  76. }
  77. timeStr := time.Now().Format("2006-01-02")
  78. timeArr := strings.Split(timeStr, "-")
  79. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  80. total = total + 1
  81. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  82. operation_time := time.Now().Unix()
  83. creater := adminUserInfo.AdminUser.Id
  84. warehousing := models.Warehousing{
  85. WarehousingOrder: warehousing_order,
  86. OperationTime: operation_time,
  87. OrgId: adminUserInfo.CurrentOrgId,
  88. Creater: creater,
  89. Ctime: ctime,
  90. Status: 1,
  91. WarehousingTime: warehousingDate.Unix(),
  92. Dealer: dealer_id,
  93. Manufacturer: manufacturer_id,
  94. Type: types,
  95. }
  96. service.AddSigleWarehouse(&warehousing)
  97. dataBody := make(map[string]interface{}, 0)
  98. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  99. if err != nil {
  100. utils.ErrorLog(err.Error())
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. return
  103. }
  104. var warehousingInfo []*models.WarehousingInfo
  105. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  106. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  107. if len(thisStockIn) > 0 {
  108. for _, item := range thisStockIn {
  109. items := item.(map[string]interface{})
  110. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  111. utils.ErrorLog("good_id")
  112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  113. return
  114. }
  115. good_id := int64(items["good_id"].(float64))
  116. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  117. utils.ErrorLog("good_type_id")
  118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  119. return
  120. }
  121. good_type_id := int64(items["good_type_id"].(float64))
  122. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  123. utils.ErrorLog("warehousing_count")
  124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  125. return
  126. }
  127. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  128. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  129. utils.ErrorLog("price")
  130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  131. return
  132. }
  133. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  134. total := float64(warehousing_count) * price
  135. var productDates int64
  136. var expiryDates int64
  137. fmt.Println()
  138. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  139. expiryDates = 0
  140. } else {
  141. if len(items["expiry_date"].(string)) == 0 {
  142. expiryDates = 0
  143. } else {
  144. expiryDate, _ := items["expiry_date"].(string)
  145. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  146. expiryDates = expiry_date.Unix()
  147. }
  148. }
  149. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  150. productDates = 0
  151. } else {
  152. if len(items["product_date"].(string)) == 0 {
  153. productDates = 0
  154. } else {
  155. productDate, _ := items["product_date"].(string)
  156. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  157. productDates = product_date.Unix()
  158. }
  159. }
  160. number, _ := items["number"].(string)
  161. remark, _ := items["remark"].(string)
  162. warehouseInfo := &models.WarehousingInfo{
  163. WarehousingOrder: warehousing.WarehousingOrder,
  164. WarehousingId: warehousing.ID,
  165. GoodId: good_id,
  166. Number: number,
  167. GoodTypeId: good_type_id,
  168. ProductDate: productDates,
  169. ExpiryDate: expiryDates,
  170. WarehousingCount: warehousing_count,
  171. Price: price,
  172. TotalPrice: total,
  173. Status: 1,
  174. Ctime: ctime,
  175. Remark: remark,
  176. OrgId: adminUserInfo.CurrentOrgId,
  177. Type: types,
  178. Manufacturer: manufacturer_id,
  179. Dealer: dealer_id,
  180. StockCount: warehousing_count,
  181. }
  182. warehousingInfo = append(warehousingInfo, warehouseInfo)
  183. }
  184. }
  185. }
  186. errs := service.CreateWarehousingInfo(warehousingInfo)
  187. info, _ := service.FindLastWarehousingInfo(warehousing.WarehousingOrder)
  188. if errs != nil {
  189. utils.ErrorLog(errs.Error())
  190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  191. return
  192. }
  193. c.ServeSuccessJSON(map[string]interface{}{
  194. "msg": "入库成功",
  195. "warehousing_order": warehousing_order,
  196. "info": info,
  197. })
  198. //}
  199. //else {
  200. // warehouse, err1 := service.FindWareHouseByOrderNumber(warehousing_order)
  201. // if (err1 != nil) {
  202. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  203. // return
  204. // }
  205. //
  206. // dataBody := make(map[string]interface{}, 0)
  207. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  208. // if err != nil {
  209. // utils.ErrorLog(err.Error())
  210. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  211. // return
  212. // }
  213. //
  214. // var warehousingInfo []*models.WarehousingInfo
  215. //
  216. // if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  217. // thisStockIn, _ := dataBody["stockIn"].([]interface{})
  218. // if len(thisStockIn) > 0 {
  219. // for _, item := range thisStockIn {
  220. // items := item.(map[string]interface{})
  221. //
  222. // if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  223. // utils.ErrorLog("good_id")
  224. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  225. // return
  226. // }
  227. // good_id := int64(items["good_id"].(float64))
  228. //
  229. // if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  230. // utils.ErrorLog("good_type_id")
  231. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  232. // return
  233. // }
  234. // good_type_id := int64(items["good_type_id"].(float64))
  235. //
  236. // if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  237. // utils.ErrorLog("warehousing_count")
  238. // c.ServeFailJSONWithSGJErrorCod Fe(enums.ErrorCodeParamWrong)
  239. // return
  240. // }
  241. //
  242. // warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  243. //
  244. // if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  245. // utils.ErrorLog("price")
  246. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  247. // return
  248. // }
  249. // price, _ := strconv.ParseFloat(items["price"].(string), 64)
  250. // total := float64(warehousing_count) * price
  251. //
  252. // if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  253. // utils.ErrorLog("expiry_date")
  254. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  255. // return
  256. // }
  257. //
  258. // expiryDate, _ := items["expiry_date"].(string)
  259. // if len(expiryDate) == 0 {
  260. // utils.ErrorLog("len(expiry_date) == 0")
  261. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  262. //
  263. // return
  264. // }
  265. //
  266. // expiry_date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  267. // if parseDateErr != nil {
  268. // c.ErrorLog("日期(%v)解析错误:%v", expiry_date, parseDateErr)
  269. // }
  270. //
  271. // var productDates int64
  272. //
  273. // if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  274. // productDates = 0;
  275. // } else {
  276. // productDate, _ := items["product_date"].(string)
  277. // product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  278. // productDates = product_date.Unix()
  279. //
  280. // }
  281. //
  282. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  283. // utils.ErrorLog("number")
  284. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  285. // return
  286. // }
  287. // number, _ := items["number"].(string)
  288. //
  289. // var remark string
  290. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  291. // remark = ""
  292. // } else {
  293. // remark = items["remark"].(string)
  294. // }
  295. //
  296. // warehouseInfo := &models.WarehousingInfo{
  297. // WarehousingOrder: warehousing_order,
  298. // WarehousingId: warehouse.ID,
  299. // GoodId: good_id,
  300. // Number: number,
  301. // GoodTypeId: good_type_id,
  302. // ProductDate: productDates,
  303. // ExpiryDate: expiry_date.Unix(),
  304. // WarehousingCount: warehousing_count,
  305. // Price: price,
  306. // TotalPrice: total,
  307. // Status: 1,
  308. // Ctime: ctime,
  309. // Remark: remark,
  310. // OrgId: adminUserInfo.CurrentOrgId,
  311. // }
  312. // warehousingInfo = append(warehousingInfo, warehouseInfo)
  313. //
  314. // }
  315. // }
  316. // }
  317. // errs := service.CreateWarehousingInfo(warehousingInfo)
  318. // info, _ := service.FindLastWarehousingInfo(warehousing_order)
  319. //
  320. // if (errs != nil) {
  321. // utils.ErrorLog(errs.Error())
  322. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  323. // return
  324. // }
  325. //
  326. // c.ServeSuccessJSON(map[string]interface{}{
  327. // "msg": "入库成功",
  328. // "info": info,
  329. // })
  330. //
  331. //}
  332. }
  333. func (c *StockManagerApiController) GetWarehouseList() {
  334. page, _ := c.GetInt64("page", -1)
  335. limit, _ := c.GetInt64("limit", -1)
  336. start_time := c.GetString("start_time")
  337. end_time := c.GetString("end_time")
  338. types, _ := c.GetInt64("type", 0)
  339. keywords := c.GetString("keywords")
  340. fmt.Println(start_time)
  341. fmt.Println(end_time)
  342. timeLayout := "2006-01-02"
  343. loc, _ := time.LoadLocation("Local")
  344. var startTime int64
  345. if len(start_time) > 0 {
  346. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  347. if err != nil {
  348. fmt.Println(err)
  349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  350. return
  351. }
  352. startTime = theTime.Unix()
  353. }
  354. var endTime int64
  355. if len(end_time) > 0 {
  356. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  357. if err != nil {
  358. utils.ErrorLog(err.Error())
  359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  360. return
  361. }
  362. endTime = theTime.Unix()
  363. }
  364. adminUserInfo := c.GetAdminUserInfo()
  365. warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  366. if err == nil {
  367. c.ServeSuccessJSON(map[string]interface{}{
  368. "list": warehouseList,
  369. "total": total,
  370. })
  371. } else {
  372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  373. }
  374. }
  375. func (c *StockManagerApiController) GetWarehouseInfoList() {
  376. id, _ := c.GetInt64("id", 0)
  377. if id <= 0 {
  378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  379. return
  380. }
  381. warehousing, err := service.FindWarehousingById(id)
  382. if err != nil {
  383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  384. return
  385. }
  386. if warehousing.ID <= 0 {
  387. return
  388. }
  389. warehousingInfo, err := service.FindWarehousingInfoById(id)
  390. if err == nil {
  391. c.ServeSuccessJSON(map[string]interface{}{
  392. "info": warehousingInfo,
  393. "warehousing": warehousing,
  394. })
  395. } else {
  396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  397. }
  398. }
  399. func (c *StockManagerApiController) EditWarehouse() {
  400. warehousing_time := c.GetString("warehousing_time")
  401. id, _ := c.GetInt64("id", 0)
  402. types, _ := c.GetInt64("type", 0)
  403. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  404. dealer_id, _ := c.GetInt64("dealer_id", 0)
  405. if id == 0 {
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  407. return
  408. }
  409. ctime := time.Now().Unix()
  410. mtime := time.Now().Unix()
  411. adminUserInfo := c.GetAdminUserInfo()
  412. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  413. if parseDateErr != nil {
  414. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  416. return
  417. }
  418. warehouse, _ := service.FindWarehousingById(id)
  419. warehousing := models.Warehousing{
  420. WarehousingOrder: warehouse.WarehousingOrder,
  421. OrgId: adminUserInfo.CurrentOrgId,
  422. Modifier: adminUserInfo.AdminUser.Id,
  423. Mtime: mtime,
  424. Status: 1,
  425. WarehousingTime: warehousingDate.Unix(),
  426. Type: warehouse.Type,
  427. Dealer: dealer_id,
  428. Manufacturer: manufacturer_id,
  429. }
  430. service.EditWarehousing(warehousing)
  431. dataBody := make(map[string]interface{}, 0)
  432. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  433. if err != nil {
  434. utils.ErrorLog(err.Error())
  435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  436. return
  437. }
  438. var warehousingInfo []*models.WarehousingInfo
  439. var upDateWarehousingInfo []*models.WarehousingInfo
  440. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  441. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  442. if len(thisStockIn) > 0 {
  443. for _, item := range thisStockIn {
  444. items := item.(map[string]interface{})
  445. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  446. utils.ErrorLog("good_id")
  447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  448. return
  449. }
  450. good_id := int64(items["good_id"].(float64))
  451. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  452. utils.ErrorLog("good_type_id")
  453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  454. return
  455. }
  456. good_type_id := int64(items["good_type_id"].(float64))
  457. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  458. utils.ErrorLog("warehousing_count")
  459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  460. return
  461. }
  462. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  463. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  464. utils.ErrorLog("price")
  465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  466. return
  467. }
  468. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  469. total := float64(warehousing_count) * price
  470. var productDates int64
  471. var expiryDates int64
  472. fmt.Println()
  473. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  474. expiryDates = 0
  475. } else {
  476. if len(items["expiry_date"].(string)) == 0 {
  477. expiryDates = 0
  478. } else {
  479. expiryDate, _ := items["expiry_date"].(string)
  480. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  481. expiryDates = expiry_date.Unix()
  482. }
  483. }
  484. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  485. productDates = 0
  486. } else {
  487. if len(items["product_date"].(string)) == 0 {
  488. productDates = 0
  489. } else {
  490. productDate, _ := items["product_date"].(string)
  491. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  492. productDates = product_date.Unix()
  493. }
  494. }
  495. number, _ := items["number"].(string)
  496. remark, _ := items["remark"].(string)
  497. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  498. utils.ErrorLog("id")
  499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  500. return
  501. }
  502. id := int64(items["id"].(float64))
  503. if id == 0 {
  504. warehouseInfo := &models.WarehousingInfo{
  505. WarehousingOrder: warehouse.WarehousingOrder,
  506. WarehousingId: warehouse.ID,
  507. GoodId: good_id,
  508. Number: number,
  509. GoodTypeId: good_type_id,
  510. ProductDate: productDates,
  511. ExpiryDate: expiryDates,
  512. WarehousingCount: warehousing_count,
  513. Price: price,
  514. TotalPrice: total,
  515. Status: 1,
  516. Ctime: ctime,
  517. Remark: remark,
  518. OrgId: adminUserInfo.CurrentOrgId,
  519. Type: types,
  520. Manufacturer: manufacturer_id,
  521. Dealer: dealer_id,
  522. }
  523. warehousingInfo = append(warehousingInfo, warehouseInfo)
  524. } else {
  525. warehouseInfo := &models.WarehousingInfo{
  526. ID: id,
  527. WarehousingOrder: warehouse.WarehousingOrder,
  528. WarehousingId: warehouse.ID,
  529. GoodId: good_id,
  530. Number: number,
  531. GoodTypeId: good_type_id,
  532. ProductDate: productDates,
  533. ExpiryDate: expiryDates,
  534. WarehousingCount: warehousing_count,
  535. Price: price,
  536. TotalPrice: total,
  537. Status: 1,
  538. Ctime: ctime,
  539. Remark: remark,
  540. OrgId: adminUserInfo.CurrentOrgId,
  541. Type: types,
  542. Manufacturer: manufacturer_id,
  543. Dealer: dealer_id,
  544. }
  545. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  546. }
  547. }
  548. }
  549. }
  550. var errs error
  551. if len(warehousingInfo) > 0 {
  552. errs = service.CreateWarehousingInfo(warehousingInfo)
  553. }
  554. if len(upDateWarehousingInfo) > 0 {
  555. for _, item := range upDateWarehousingInfo {
  556. errs = service.UpDateWarehousingInfo(item)
  557. }
  558. }
  559. if errs != nil {
  560. utils.ErrorLog(errs.Error())
  561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  562. return
  563. }
  564. c.ServeSuccessJSON(map[string]interface{}{
  565. "msg": "编辑成功",
  566. })
  567. }
  568. func (c *StockManagerApiController) DeleteWarehouse() {
  569. ids := c.GetString("ids")
  570. if len(ids) == 0 {
  571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  572. return
  573. }
  574. idArray := strings.Split(ids, ",")
  575. err := service.DeleteWarehouse(idArray)
  576. if err != nil {
  577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  578. } else {
  579. c.ServeSuccessJSON(map[string]interface{}{
  580. "msg": "删除成功",
  581. })
  582. }
  583. }
  584. func (c *StockManagerApiController) DeleteWarehouseInfo() {
  585. id, _ := c.GetInt64("id", 0)
  586. if id == 0 {
  587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  588. return
  589. }
  590. err := service.UpDateWarehouseStatus(id)
  591. if err != nil {
  592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  593. } else {
  594. c.ServeSuccessJSON(map[string]interface{}{
  595. "msg": "删除成功",
  596. })
  597. }
  598. }
  599. func (c *StockManagerApiController) CreateSalesReturn() {
  600. dealer_id, _ := c.GetInt64("dealer_id", 0)
  601. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  602. sales_return_time := c.GetString("time")
  603. types, _ := c.GetInt64("type", 0)
  604. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  605. if parseDateErr != nil {
  606. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  608. return
  609. }
  610. adminUserInfo := c.GetAdminUserInfo()
  611. operation_time := time.Now().Unix()
  612. creater := adminUserInfo.AdminUser.Id
  613. ctime := time.Now().Unix()
  614. timeStr := time.Now().Format("2006-01-02")
  615. timeArr := strings.Split(timeStr, "-")
  616. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  617. total = total + 1
  618. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  619. salesReturn := models.SalesReturn{
  620. OrderNumber: orderNumber,
  621. OperaTime: operation_time,
  622. OrgId: adminUserInfo.CurrentOrgId,
  623. Creater: creater,
  624. Ctime: ctime,
  625. Status: 1,
  626. ReturnTime: salesReturnDate.Unix(),
  627. Dealer: dealer_id,
  628. Manufacturer: manufacturer_id,
  629. Type: types,
  630. }
  631. service.AddSigleSalesReturn(&salesReturn)
  632. dataBody := make(map[string]interface{}, 0)
  633. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  634. if err != nil {
  635. utils.ErrorLog(err.Error())
  636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  637. return
  638. }
  639. var salesReturnInfos []*models.SalesReturnInfo
  640. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  641. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  642. if len(thisStockIn) > 0 {
  643. for _, item := range thisStockIn {
  644. items := item.(map[string]interface{})
  645. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  646. utils.ErrorLog("good_id")
  647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  648. return
  649. }
  650. good_id := int64(items["good_id"].(float64))
  651. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  652. utils.ErrorLog("good_type_id")
  653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  654. return
  655. }
  656. good_type_id := int64(items["good_type_id"].(float64))
  657. return_count, _ := items["return_count"].(string)
  658. if len(return_count) == 0 {
  659. utils.ErrorLog("len(return_count) == 0")
  660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  661. return
  662. }
  663. count, _ := strconv.ParseInt(return_count, 10, 64)
  664. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  665. total := float64(count) * price
  666. salesReturnInfo := &models.SalesReturnInfo{
  667. OrderNumber: salesReturn.OrderNumber,
  668. SalesReturnId: salesReturn.ID,
  669. GoodId: good_id,
  670. GoodTypeId: good_type_id,
  671. Count: count,
  672. Price: price,
  673. Total: total,
  674. Status: 1,
  675. Ctime: ctime,
  676. OrgId: adminUserInfo.CurrentOrgId,
  677. Type: types,
  678. Manufacturer: manufacturer_id,
  679. Dealer: dealer_id,
  680. }
  681. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  682. }
  683. }
  684. }
  685. errs := service.CreateSalesReturnInfo(salesReturnInfos)
  686. if errs != nil {
  687. utils.ErrorLog(errs.Error())
  688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  689. return
  690. }
  691. c.ServeSuccessJSON(map[string]interface{}{
  692. "msg": "退货成功",
  693. })
  694. }
  695. func (c *StockManagerApiController) GetSalesReturnList() {
  696. page, _ := c.GetInt64("page", -1)
  697. limit, _ := c.GetInt64("limit", -1)
  698. start_time := c.GetString("start_time")
  699. end_time := c.GetString("end_time")
  700. types, _ := c.GetInt64("type", 0)
  701. keywords := c.GetString("keywords")
  702. timeLayout := "2006-01-02"
  703. loc, _ := time.LoadLocation("Local")
  704. var startTime int64
  705. if len(start_time) > 0 {
  706. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  707. if err != nil {
  708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  709. return
  710. }
  711. startTime = theTime.Unix()
  712. }
  713. var endTime int64
  714. if len(end_time) > 0 {
  715. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  716. if err != nil {
  717. utils.ErrorLog(err.Error())
  718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  719. return
  720. }
  721. endTime = theTime.Unix()
  722. }
  723. adminUserInfo := c.GetAdminUserInfo()
  724. returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  725. if err == nil {
  726. c.ServeSuccessJSON(map[string]interface{}{
  727. "list": returnList,
  728. "total": total,
  729. })
  730. } else {
  731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  732. }
  733. }
  734. func (this *StockManagerApiController) DeleteSalesReturn() {
  735. ids := this.GetString("ids")
  736. if len(ids) == 0 {
  737. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  738. return
  739. }
  740. idArray := strings.Split(ids, ",")
  741. err := service.DeleteSalesReturn(idArray)
  742. if err != nil {
  743. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  744. } else {
  745. this.ServeSuccessJSON(map[string]interface{}{
  746. "msg": "删除成功",
  747. })
  748. }
  749. }
  750. func (this *StockManagerApiController) DeleteSalesReturnInfo() {
  751. id, _ := this.GetInt64("id", 0)
  752. fmt.Println(id)
  753. if id == 0 {
  754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  755. return
  756. }
  757. err := service.UpDateSaleReturnStatus(id)
  758. if err != nil {
  759. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  760. } else {
  761. this.ServeSuccessJSON(map[string]interface{}{
  762. "msg": "删除成功",
  763. })
  764. }
  765. }
  766. func (this *StockManagerApiController) GetSalesReturnInfoList() {
  767. id, _ := this.GetInt64("id", 0)
  768. list, _ := service.FindAllSalesReturnInfoById(id)
  769. salesReturn, _ := service.FindAllSalesReturnById(id)
  770. this.ServeSuccessJSON(map[string]interface{}{
  771. "list": list,
  772. "salesReturn": salesReturn,
  773. })
  774. }
  775. func (c *StockManagerApiController) EditReturnInfo() {
  776. return_time := c.GetString("return_time")
  777. id, _ := c.GetInt64("id", 0)
  778. types, _ := c.GetInt64("type", 0)
  779. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  780. dealer_id, _ := c.GetInt64("dealer_id", 0)
  781. if id == 0 {
  782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  783. return
  784. }
  785. ctime := time.Now().Unix()
  786. mtime := time.Now().Unix()
  787. adminUserInfo := c.GetAdminUserInfo()
  788. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  789. if parseDateErr != nil {
  790. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  792. return
  793. }
  794. salesReturns, _ := service.FindSalesReturnById(id)
  795. sales := models.SalesReturn{
  796. ID: salesReturns.ID,
  797. Mtime: mtime,
  798. ReturnTime: returnDate.Unix(),
  799. Manufacturer: manufacturer_id,
  800. Dealer: dealer_id,
  801. }
  802. service.EditSaleReturn(sales)
  803. dataBody := make(map[string]interface{}, 0)
  804. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  805. if err != nil {
  806. utils.ErrorLog(err.Error())
  807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  808. return
  809. }
  810. var returnInfos []*models.SalesReturnInfo
  811. var upDateReturnInfos []*models.SalesReturnInfo
  812. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  813. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  814. if len(thisStockIn) > 0 {
  815. for _, item := range thisStockIn {
  816. items := item.(map[string]interface{})
  817. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  818. utils.ErrorLog("good_id")
  819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  820. return
  821. }
  822. good_id := int64(items["good_id"].(float64))
  823. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  824. utils.ErrorLog("good_type_id")
  825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  826. return
  827. }
  828. good_type_id := int64(items["good_type_id"].(float64))
  829. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  830. utils.ErrorLog("count")
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  832. return
  833. }
  834. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  835. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  836. utils.ErrorLog("id")
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  838. return
  839. }
  840. id := int64(items["id"].(float64))
  841. if id == 0 {
  842. returnInfo := &models.SalesReturnInfo{
  843. GoodId: good_id,
  844. GoodTypeId: good_type_id,
  845. Count: count,
  846. Status: 1,
  847. Ctime: ctime,
  848. OrgId: adminUserInfo.CurrentOrgId,
  849. OrderNumber: sales.OrderNumber,
  850. SalesReturnId: sales.ID,
  851. Mtime: time.Now().Unix(),
  852. Type: types,
  853. Manufacturer: manufacturer_id,
  854. Dealer: dealer_id,
  855. }
  856. returnInfos = append(returnInfos, returnInfo)
  857. } else {
  858. returnInfo := &models.SalesReturnInfo{
  859. ID: id,
  860. GoodId: good_id,
  861. GoodTypeId: good_type_id,
  862. Count: count,
  863. Status: 1,
  864. Ctime: ctime,
  865. OrgId: adminUserInfo.CurrentOrgId,
  866. OrderNumber: sales.OrderNumber,
  867. SalesReturnId: sales.ID,
  868. Mtime: time.Now().Unix(),
  869. Type: types,
  870. Manufacturer: manufacturer_id,
  871. Dealer: dealer_id,
  872. }
  873. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  874. }
  875. }
  876. }
  877. }
  878. var errs error
  879. if len(returnInfos) > 0 {
  880. errs = service.CreateSalesReturnInfo(returnInfos)
  881. }
  882. if len(upDateReturnInfos) > 0 {
  883. for _, item := range upDateReturnInfos {
  884. errs = service.UpDateSalesReturnInfo(item)
  885. }
  886. }
  887. if errs != nil {
  888. utils.ErrorLog(errs.Error())
  889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  890. return
  891. }
  892. c.ServeSuccessJSON(map[string]interface{}{
  893. "msg": "编辑成功",
  894. })
  895. }
  896. func (c *StockManagerApiController) CreateWarehouseOut() {
  897. dealer_id, _ := c.GetInt64("dealer_id", 0)
  898. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  899. types, _ := c.GetInt64("type", 0)
  900. ctime := time.Now().Unix()
  901. adminUserInfo := c.GetAdminUserInfo()
  902. warehousing_out_time := c.GetString("warehousing_out_time")
  903. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  904. if parseDateErr != nil {
  905. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  907. return
  908. }
  909. timeStr := time.Now().Format("2006-01-02")
  910. timeArr := strings.Split(timeStr, "-")
  911. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  912. total = total + 1
  913. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  914. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  915. number = number + total
  916. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  917. operation_time := time.Now().Unix()
  918. creater := adminUserInfo.AdminUser.Id
  919. warehouseOut := models.WarehouseOut{
  920. WarehouseOutOrderNumber: warehousing_out_order,
  921. OperationTime: operation_time,
  922. OrgId: adminUserInfo.CurrentOrgId,
  923. Creater: creater,
  924. Ctime: ctime,
  925. Status: 1,
  926. WarehouseOutTime: warehousingOutDate.Unix(),
  927. Dealer: dealer_id,
  928. Manufacturer: manufacturer_id,
  929. Type: types,
  930. }
  931. service.AddSigleWarehouseOut(&warehouseOut)
  932. dataBody := make(map[string]interface{}, 0)
  933. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  934. if err != nil {
  935. utils.ErrorLog(err.Error())
  936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  937. return
  938. }
  939. var warehousingOutInfo []*models.WarehouseOutInfo
  940. var beforePrepares []*models.DialysisBeforePrepareGoods
  941. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  942. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  943. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  944. if len(thisStockIn) > 0 {
  945. for _, item := range thisStockIn {
  946. items := item.(map[string]interface{})
  947. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  948. utils.ErrorLog("good_id")
  949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  950. return
  951. }
  952. good_id := int64(items["good_id"].(float64))
  953. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  954. utils.ErrorLog("good_type_id")
  955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  956. return
  957. }
  958. good_type_id := int64(items["good_type_id"].(float64))
  959. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  960. utils.ErrorLog("count")
  961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  962. return
  963. }
  964. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  965. utils.ErrorLog("price")
  966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  967. return
  968. }
  969. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  970. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  971. total := float64(count) * price
  972. remark := items["remark"].(string)
  973. warehouseOutInfo := &models.WarehouseOutInfo{
  974. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  975. WarehouseOutId: warehouseOut.ID,
  976. GoodId: good_id,
  977. GoodTypeId: good_type_id,
  978. Count: count,
  979. Price: price,
  980. TotalPrice: total,
  981. Status: 1,
  982. Ctime: ctime,
  983. Remark: remark,
  984. OrgId: adminUserInfo.CurrentOrgId,
  985. Type: types,
  986. Manufacturer: manufacturer_id,
  987. Dealer: dealer_id,
  988. }
  989. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  990. prepareGoods := &models.DialysisBeforePrepareGoods{
  991. GoodTypeId: good_type_id,
  992. GoodId: good_id,
  993. Count: count,
  994. }
  995. beforePrepares = append(beforePrepares, prepareGoods)
  996. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  997. GoodTypeId: good_type_id,
  998. GoodId: good_id,
  999. Count: count,
  1000. }
  1001. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  1002. }
  1003. }
  1004. }
  1005. //查询库存
  1006. for _, item := range warehousingOutInfo {
  1007. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count)
  1008. fmt.Println(parseDateErr)
  1009. }
  1010. //errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
  1011. //info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
  1012. //if errs != nil {
  1013. // utils.ErrorLog(errs.Error())
  1014. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1015. // return
  1016. //}
  1017. c.ServeSuccessJSON(map[string]interface{}{
  1018. "msg": "出库成功",
  1019. "warehousing_out_order": warehousing_out_order,
  1020. })
  1021. }
  1022. func (c *StockManagerApiController) GetWarehouseOutList() {
  1023. page, _ := c.GetInt64("page", -1)
  1024. limit, _ := c.GetInt64("limit", -1)
  1025. start_time := c.GetString("start_time")
  1026. end_time := c.GetString("end_time")
  1027. types, _ := c.GetInt64("type", 0)
  1028. keywords := c.GetString("keywords")
  1029. timeLayout := "2006-01-02"
  1030. loc, _ := time.LoadLocation("Local")
  1031. var startTime int64
  1032. if len(start_time) > 0 {
  1033. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1034. if err != nil {
  1035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1036. return
  1037. }
  1038. startTime = theTime.Unix()
  1039. }
  1040. var endTime int64
  1041. if len(end_time) > 0 {
  1042. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1043. if err != nil {
  1044. utils.ErrorLog(err.Error())
  1045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1046. return
  1047. }
  1048. endTime = theTime.Unix()
  1049. }
  1050. adminUserInfo := c.GetAdminUserInfo()
  1051. warehouseOutList, total, err := service.FindAllWarehouseOutList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1052. fmt.Println(err)
  1053. if err == nil {
  1054. c.ServeSuccessJSON(map[string]interface{}{
  1055. "list": warehouseOutList,
  1056. "total": total,
  1057. })
  1058. } else {
  1059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1060. }
  1061. }
  1062. func (c *StockManagerApiController) DeleteWarehouseOut() {
  1063. ids := c.GetString("ids")
  1064. if len(ids) == 0 {
  1065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1066. return
  1067. }
  1068. idArray := strings.Split(ids, ",")
  1069. err := service.DeleteWarehouseOut(idArray)
  1070. if err != nil {
  1071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1072. } else {
  1073. c.ServeSuccessJSON(map[string]interface{}{
  1074. "msg": "删除成功",
  1075. })
  1076. }
  1077. }
  1078. func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
  1079. id, _ := this.GetInt64("id", 0)
  1080. fmt.Println(id)
  1081. if id == 0 {
  1082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1083. return
  1084. }
  1085. err := service.UpDateWarehouseOutStatus(id)
  1086. if err != nil {
  1087. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1088. } else {
  1089. this.ServeSuccessJSON(map[string]interface{}{
  1090. "msg": "删除成功",
  1091. })
  1092. }
  1093. }
  1094. func (c *StockManagerApiController) GetWarehouseOutInfoList() {
  1095. id, _ := c.GetInt64("id", 0)
  1096. warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
  1097. warehouseOut, _ := service.FindWareHouseOutById(id)
  1098. adminUserInfo := c.GetAdminUserInfo()
  1099. orgId := adminUserInfo.CurrentOrgId
  1100. wareoutList, _ := service.GetWareOutInfoById(id, orgId)
  1101. c.ServeSuccessJSON(map[string]interface{}{
  1102. "list": warehouseOutInfo,
  1103. "info": warehouseOut,
  1104. "wareoutList": wareoutList,
  1105. })
  1106. }
  1107. func (c *StockManagerApiController) EditWarehouseOut() {
  1108. warehouse_out_time := c.GetString("warehouse_out_time")
  1109. id, _ := c.GetInt64("id", 0)
  1110. types, _ := c.GetInt64("type", 0)
  1111. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1112. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1113. if id == 0 {
  1114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1115. return
  1116. }
  1117. ctime := time.Now().Unix()
  1118. mtime := time.Now().Unix()
  1119. adminUserInfo := c.GetAdminUserInfo()
  1120. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1121. if parseDateErr != nil {
  1122. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1124. return
  1125. }
  1126. warehouseOut, _ := service.FindWareHouseOutById(id)
  1127. tempWarehouseOut := models.WarehouseOut{
  1128. ID: warehouseOut.ID,
  1129. Mtime: mtime,
  1130. WarehouseOutTime: warehouseOutDate.Unix(),
  1131. Manufacturer: manufacturer_id,
  1132. Dealer: dealer_id,
  1133. }
  1134. service.EditWarehouseOut(tempWarehouseOut)
  1135. dataBody := make(map[string]interface{}, 0)
  1136. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1137. if err != nil {
  1138. utils.ErrorLog(err.Error())
  1139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1140. return
  1141. }
  1142. var warehousingOutInfo []*models.WarehouseOutInfo
  1143. var upDateWarehouseOutInfos []*models.WarehouseOutInfo
  1144. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1145. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1146. if len(thisStockOut) > 0 {
  1147. for _, item := range thisStockOut {
  1148. items := item.(map[string]interface{})
  1149. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1150. utils.ErrorLog("good_id")
  1151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1152. return
  1153. }
  1154. good_id := int64(items["good_id"].(float64))
  1155. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1156. utils.ErrorLog("good_type_id")
  1157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1158. return
  1159. }
  1160. good_type_id := int64(items["good_type_id"].(float64))
  1161. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1162. utils.ErrorLog("count")
  1163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1164. return
  1165. }
  1166. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1167. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1168. utils.ErrorLog("price")
  1169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1170. return
  1171. }
  1172. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1173. total := float64(count) * price
  1174. remark := items["remark"].(string)
  1175. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1176. utils.ErrorLog("id")
  1177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1178. return
  1179. }
  1180. id := int64(items["id"].(float64))
  1181. if id == 0 {
  1182. warehouseOutInfo := &models.WarehouseOutInfo{
  1183. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1184. WarehouseOutId: warehouseOut.ID,
  1185. GoodId: good_id,
  1186. GoodTypeId: good_type_id,
  1187. Count: count,
  1188. Price: price,
  1189. TotalPrice: total,
  1190. Status: 1,
  1191. Ctime: ctime,
  1192. Remark: remark,
  1193. OrgId: adminUserInfo.CurrentOrgId,
  1194. Type: types,
  1195. Manufacturer: manufacturer_id,
  1196. Dealer: dealer_id,
  1197. IsSys: 0,
  1198. SysRecordTime: 0,
  1199. }
  1200. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1201. } else {
  1202. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1203. utils.ErrorLog("is_sys")
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. is_sys := int64(items["is_sys"].(float64))
  1208. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1209. utils.ErrorLog("sys_record_time")
  1210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1211. return
  1212. }
  1213. sys_record_time := int64(items["sys_record_time"].(float64))
  1214. warehouseOutInfo := &models.WarehouseOutInfo{
  1215. ID: id,
  1216. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1217. WarehouseOutId: warehouseOut.ID,
  1218. GoodId: good_id,
  1219. GoodTypeId: good_type_id,
  1220. Count: count,
  1221. Price: price,
  1222. TotalPrice: total,
  1223. Status: 1,
  1224. Ctime: ctime,
  1225. Remark: remark,
  1226. OrgId: adminUserInfo.CurrentOrgId,
  1227. Mtime: time.Now().Unix(),
  1228. Type: types,
  1229. Manufacturer: manufacturer_id,
  1230. Dealer: dealer_id,
  1231. IsSys: is_sys,
  1232. SysRecordTime: sys_record_time,
  1233. }
  1234. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1235. }
  1236. }
  1237. }
  1238. }
  1239. var errs error
  1240. if len(warehousingOutInfo) > 0 {
  1241. errs = service.CreateWarehousingOutInfo(warehousingOutInfo)
  1242. }
  1243. if len(upDateWarehouseOutInfos) > 0 {
  1244. for _, item := range upDateWarehouseOutInfos {
  1245. errs = service.UpDateWarehouseOutInfo(item)
  1246. }
  1247. }
  1248. if errs != nil {
  1249. utils.ErrorLog(errs.Error())
  1250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1251. return
  1252. }
  1253. c.ServeSuccessJSON(map[string]interface{}{
  1254. "msg": "编辑成功",
  1255. })
  1256. }
  1257. func (c *StockManagerApiController) CreateCancelStock() {
  1258. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1259. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1260. cancel_stock_time := c.GetString("time")
  1261. types, _ := c.GetInt64("type", 0)
  1262. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1263. if parseDateErr != nil {
  1264. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1266. return
  1267. }
  1268. adminUserInfo := c.GetAdminUserInfo()
  1269. operation_time := time.Now().Unix()
  1270. creater := adminUserInfo.AdminUser.Id
  1271. ctime := time.Now().Unix()
  1272. timeStr := time.Now().Format("2006-01-02")
  1273. timeArr := strings.Split(timeStr, "-")
  1274. total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
  1275. total = total + 1
  1276. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1277. cancelStock := models.CancelStock{
  1278. OrderNumber: orderNumber,
  1279. OperaTime: operation_time,
  1280. OrgId: adminUserInfo.CurrentOrgId,
  1281. Creater: creater,
  1282. Ctime: ctime,
  1283. Status: 1,
  1284. ReturnTime: cancelStockDate.Unix(),
  1285. Dealer: dealer_id,
  1286. Manufacturer: manufacturer_id,
  1287. Type: types,
  1288. }
  1289. service.AddSigleCancelStock(&cancelStock)
  1290. dataBody := make(map[string]interface{}, 0)
  1291. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1292. if err != nil {
  1293. utils.ErrorLog(err.Error())
  1294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1295. return
  1296. }
  1297. var cancelStockInfos []*models.CancelStockInfo
  1298. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1299. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1300. if len(thisStockIn) > 0 {
  1301. for _, item := range thisStockIn {
  1302. items := item.(map[string]interface{})
  1303. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1304. utils.ErrorLog("good_id")
  1305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1306. return
  1307. }
  1308. good_id := int64(items["good_id"].(float64))
  1309. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1310. utils.ErrorLog("good_type_id")
  1311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1312. return
  1313. }
  1314. good_type_id := int64(items["good_type_id"].(float64))
  1315. return_count, _ := items["return_count"].(string)
  1316. if len(return_count) == 0 {
  1317. utils.ErrorLog("len(return_count) == 0")
  1318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1319. return
  1320. }
  1321. count, _ := strconv.ParseInt(return_count, 10, 64)
  1322. cancelStockInfo := &models.CancelStockInfo{
  1323. OrderNumber: cancelStock.OrderNumber,
  1324. CancelStockId: cancelStock.ID,
  1325. GoodId: good_id,
  1326. GoodTypeId: good_type_id,
  1327. Count: count,
  1328. Status: 1,
  1329. Ctime: ctime,
  1330. OrgId: adminUserInfo.CurrentOrgId,
  1331. Type: types,
  1332. Manufacturer: manufacturer_id,
  1333. Dealer: dealer_id,
  1334. }
  1335. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1336. }
  1337. }
  1338. }
  1339. errs := service.CreateCancelStockInfo(cancelStockInfos)
  1340. if errs != nil {
  1341. utils.ErrorLog(errs.Error())
  1342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1343. return
  1344. }
  1345. c.ServeSuccessJSON(map[string]interface{}{
  1346. "msg": "退库成功",
  1347. })
  1348. }
  1349. func (c *StockManagerApiController) GetCancelStockInfoList() {
  1350. id, _ := c.GetInt64("id", 0)
  1351. cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
  1352. info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1353. c.ServeSuccessJSON(map[string]interface{}{
  1354. "list": cancelStockInfoList,
  1355. "info": info,
  1356. })
  1357. }
  1358. func (c *StockManagerApiController) GetCancelStockList() {
  1359. page, _ := c.GetInt64("page", -1)
  1360. limit, _ := c.GetInt64("limit", -1)
  1361. start_time := c.GetString("start_time")
  1362. end_time := c.GetString("end_time")
  1363. types, _ := c.GetInt64("type", 0)
  1364. keywords := c.GetString("keywords")
  1365. timeLayout := "2006-01-02"
  1366. loc, _ := time.LoadLocation("Local")
  1367. var startTime int64
  1368. if len(start_time) > 0 {
  1369. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1370. if err != nil {
  1371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1372. return
  1373. }
  1374. startTime = theTime.Unix()
  1375. }
  1376. var endTime int64
  1377. if len(end_time) > 0 {
  1378. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1379. if err != nil {
  1380. utils.ErrorLog(err.Error())
  1381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1382. return
  1383. }
  1384. endTime = theTime.Unix()
  1385. }
  1386. adminUserInfo := c.GetAdminUserInfo()
  1387. returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1388. if err == nil {
  1389. c.ServeSuccessJSON(map[string]interface{}{
  1390. "list": returnList,
  1391. "total": total,
  1392. })
  1393. } else {
  1394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1395. }
  1396. }
  1397. func (this *StockManagerApiController) DeleteCancelStock() {
  1398. ids := this.GetString("ids")
  1399. if len(ids) == 0 {
  1400. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1401. return
  1402. }
  1403. idArray := strings.Split(ids, ",")
  1404. err := service.DeleteCancelStock(idArray)
  1405. if err != nil {
  1406. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1407. } else {
  1408. this.ServeSuccessJSON(map[string]interface{}{
  1409. "msg": "删除成功",
  1410. })
  1411. }
  1412. }
  1413. func (this *StockManagerApiController) DeleteCancelStockInfo() {
  1414. id, _ := this.GetInt64("id", 0)
  1415. fmt.Println(id)
  1416. if id == 0 {
  1417. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1418. return
  1419. }
  1420. err := service.UpDateCancleStockStatus(id)
  1421. if err != nil {
  1422. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1423. } else {
  1424. this.ServeSuccessJSON(map[string]interface{}{
  1425. "msg": "删除成功",
  1426. })
  1427. }
  1428. }
  1429. func (c *StockManagerApiController) EditCancelStock() {
  1430. cancel_time := c.GetString("cancel_time")
  1431. id, _ := c.GetInt64("id", 0)
  1432. types, _ := c.GetInt64("type", 0)
  1433. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1434. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1435. if id == 0 {
  1436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1437. return
  1438. }
  1439. ctime := time.Now().Unix()
  1440. mtime := time.Now().Unix()
  1441. adminUserInfo := c.GetAdminUserInfo()
  1442. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  1443. if parseDateErr != nil {
  1444. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  1445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1446. return
  1447. }
  1448. cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1449. tempCancelStock := models.CancelStock{
  1450. ID: cancelStock.ID,
  1451. Mtime: mtime,
  1452. ReturnTime: cancelDate.Unix(),
  1453. Manufacturer: manufacturer_id,
  1454. Dealer: dealer_id,
  1455. }
  1456. service.EditCancelStock(tempCancelStock)
  1457. dataBody := make(map[string]interface{}, 0)
  1458. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1459. if err != nil {
  1460. utils.ErrorLog(err.Error())
  1461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1462. return
  1463. }
  1464. var cancelStockInfos []*models.CancelStockInfo
  1465. var upDateCancelStockInfos []*models.CancelStockInfo
  1466. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1467. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  1468. if len(thisCancelStock) > 0 {
  1469. for _, item := range thisCancelStock {
  1470. items := item.(map[string]interface{})
  1471. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1472. utils.ErrorLog("good_id")
  1473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1474. return
  1475. }
  1476. good_id := int64(items["good_id"].(float64))
  1477. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1478. utils.ErrorLog("good_type_id")
  1479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1480. return
  1481. }
  1482. good_type_id := int64(items["good_type_id"].(float64))
  1483. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1484. utils.ErrorLog("count")
  1485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1486. return
  1487. }
  1488. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1489. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1490. utils.ErrorLog("id")
  1491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1492. return
  1493. }
  1494. id := int64(items["id"].(float64))
  1495. if id == 0 {
  1496. cancelStockInfo := &models.CancelStockInfo{
  1497. GoodId: good_id,
  1498. GoodTypeId: good_type_id,
  1499. Count: count,
  1500. Status: 1,
  1501. Ctime: ctime,
  1502. OrgId: adminUserInfo.CurrentOrgId,
  1503. OrderNumber: cancelStock.OrderNumber,
  1504. CancelStockId: cancelStock.ID,
  1505. Mtime: time.Now().Unix(),
  1506. Type: types,
  1507. Manufacturer: manufacturer_id,
  1508. Dealer: dealer_id,
  1509. }
  1510. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1511. } else {
  1512. cancelStockInfo := &models.CancelStockInfo{
  1513. ID: id,
  1514. GoodId: good_id,
  1515. GoodTypeId: good_type_id,
  1516. Count: count,
  1517. Status: 1,
  1518. Ctime: ctime,
  1519. OrgId: adminUserInfo.CurrentOrgId,
  1520. OrderNumber: cancelStock.OrderNumber,
  1521. CancelStockId: cancelStock.ID,
  1522. Mtime: time.Now().Unix(),
  1523. Type: types,
  1524. Manufacturer: manufacturer_id,
  1525. Dealer: dealer_id,
  1526. }
  1527. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  1528. }
  1529. }
  1530. }
  1531. }
  1532. var errs error
  1533. if len(cancelStockInfos) > 0 {
  1534. errs = service.CreateCancelStockInfo(cancelStockInfos)
  1535. }
  1536. if len(upDateCancelStockInfos) > 0 {
  1537. for _, item := range upDateCancelStockInfos {
  1538. errs = service.UpDateCancelStockInfo(item)
  1539. }
  1540. }
  1541. if errs != nil {
  1542. utils.ErrorLog(errs.Error())
  1543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1544. return
  1545. }
  1546. c.ServeSuccessJSON(map[string]interface{}{
  1547. "msg": "编辑成功",
  1548. })
  1549. }
  1550. func (this *StockManagerApiController) GetCancelStockConfig() {
  1551. types, _ := this.GetInt64("type", 0)
  1552. adminUserInfo := this.GetAdminUserInfo()
  1553. warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
  1554. this.ServeSuccessJSON(map[string]interface{}{
  1555. "warehouseOutInfoList": warehouseOutInfoList,
  1556. })
  1557. }
  1558. func (c *StockManagerApiController) GetQueryInfo() {
  1559. page, _ := c.GetInt64("page", -1)
  1560. limit, _ := c.GetInt64("limit", -1)
  1561. keyword := c.GetString("keyword")
  1562. start_time := c.GetString("start_time")
  1563. end_time := c.GetString("end_time")
  1564. type_name, _ := c.GetInt64("type_name")
  1565. timeLayout := "2006-01-02"
  1566. loc, _ := time.LoadLocation("Local")
  1567. var startTime int64
  1568. if len(start_time) > 0 {
  1569. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1570. if err != nil {
  1571. fmt.Println(err)
  1572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1573. return
  1574. }
  1575. startTime = theTime.Unix()
  1576. }
  1577. var endTime int64
  1578. if len(end_time) > 0 {
  1579. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1580. if err != nil {
  1581. utils.ErrorLog(err.Error())
  1582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1583. return
  1584. }
  1585. endTime = theTime.Unix()
  1586. }
  1587. adminUserInfo := c.GetAdminUserInfo()
  1588. list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
  1589. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  1590. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId, "")
  1591. if err == nil {
  1592. c.ServeSuccessJSON(map[string]interface{}{
  1593. "list": list,
  1594. "total": total,
  1595. "info": info,
  1596. "infomationList": infomationList,
  1597. "orgid": adminUserInfo.CurrentOrgId,
  1598. })
  1599. } else {
  1600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1601. }
  1602. }
  1603. func (c *StockManagerApiController) SearchWarehouse() {
  1604. keywords := c.GetString("keywords")
  1605. adminUserInfo := c.GetAdminUserInfo()
  1606. warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
  1607. if err == nil {
  1608. c.ServeSuccessJSON(map[string]interface{}{
  1609. "list": warehouseList,
  1610. "total": total,
  1611. })
  1612. } else {
  1613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1614. }
  1615. }
  1616. func (c *StockManagerApiController) GetAllConfig() {
  1617. adminUserInfo := c.GetAdminUserInfo()
  1618. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  1619. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  1620. goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  1621. goodInfo, _ := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  1622. c.ServeSuccessJSON(map[string]interface{}{
  1623. "manufacturer": manufacturer,
  1624. "dealer": dealer,
  1625. "goodType": goodType,
  1626. "goodInfo": goodInfo,
  1627. })
  1628. }
  1629. func (this *StockManagerApiController) GetAllSalesReturnConfig() {
  1630. types, _ := this.GetInt64("type", 0)
  1631. adminUserInfo := this.GetAdminUserInfo()
  1632. warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
  1633. this.ServeSuccessJSON(map[string]interface{}{
  1634. "warehouseInfoList": warehouseInfoList,
  1635. })
  1636. }
  1637. func (this *StockManagerApiController) GetDetailInfo() {
  1638. page, _ := this.GetInt64("page", 0)
  1639. limit, _ := this.GetInt64("limit", 0)
  1640. start_time := this.GetString("start_time")
  1641. end_time := this.GetString("end_time")
  1642. types, _ := this.GetInt64("type", 0)
  1643. keywords := this.GetString("keywords")
  1644. manufacturer, _ := this.GetInt64("manufacturer", 0)
  1645. order_type, _ := this.GetInt64("order_type", 0)
  1646. dealer, _ := this.GetInt64("dealer", 0)
  1647. timeLayout := "2006-01-02"
  1648. loc, _ := time.LoadLocation("Local")
  1649. var startTime int64
  1650. if len(start_time) > 0 {
  1651. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1652. if err != nil {
  1653. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1654. return
  1655. }
  1656. startTime = theTime.Unix()
  1657. }
  1658. var endTime int64
  1659. if len(end_time) > 0 {
  1660. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1661. if err != nil {
  1662. utils.ErrorLog(err.Error())
  1663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1664. return
  1665. }
  1666. endTime = theTime.Unix()
  1667. }
  1668. adminUserInfo := this.GetAdminUserInfo()
  1669. var list []*models.WarehousingInfo
  1670. var list1 []*models.WarehouseOutInfo
  1671. var list2 []*models.SalesReturnInfo
  1672. var list3 []*models.CancelStockInfo
  1673. var total int64
  1674. var err error
  1675. var total_price float64
  1676. if types == 1 {
  1677. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1678. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1679. if err == nil {
  1680. this.ServeSuccessJSON(map[string]interface{}{
  1681. "list": list,
  1682. "total": total,
  1683. "total_price": total_price,
  1684. })
  1685. } else {
  1686. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1687. }
  1688. } else if types == 2 {
  1689. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1690. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1691. if err == nil {
  1692. this.ServeSuccessJSON(map[string]interface{}{
  1693. "list": list1,
  1694. "total": total,
  1695. "total_price": total_price,
  1696. })
  1697. } else {
  1698. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1699. }
  1700. } else if types == 3 {
  1701. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1702. if err == nil {
  1703. this.ServeSuccessJSON(map[string]interface{}{
  1704. "list": list2,
  1705. "total": total,
  1706. })
  1707. } else {
  1708. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1709. }
  1710. } else if types == 4 {
  1711. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  1712. if err == nil {
  1713. this.ServeSuccessJSON(map[string]interface{}{
  1714. "list": list3,
  1715. "total": total,
  1716. })
  1717. } else {
  1718. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1719. }
  1720. }
  1721. }
  1722. func (this *StockManagerApiController) GetUserDetailInfo() {
  1723. order_id, _ := this.GetInt64("id")
  1724. if order_id <= 0 {
  1725. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1726. return
  1727. }
  1728. adminUserInfo := this.GetAdminUserInfo()
  1729. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  1730. if err == nil {
  1731. this.ServeSuccessJSON(map[string]interface{}{
  1732. "list": userDetails,
  1733. "total": total,
  1734. })
  1735. } else {
  1736. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1737. return
  1738. }
  1739. }
  1740. func (this *StockManagerApiController) PostSearchStock() {
  1741. keyword := this.GetString("keyword")
  1742. adminUserInfo := this.GetAdminUserInfo()
  1743. orgId := adminUserInfo.CurrentOrgId
  1744. stock, err := service.PostSearchStock(keyword, orgId)
  1745. if err != nil {
  1746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1747. }
  1748. this.ServeSuccessJSON(map[string]interface{}{
  1749. "stock": stock,
  1750. })
  1751. }
  1752. func (this *StockManagerApiController) GetOutStockTotalCount() {
  1753. warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
  1754. adminUserInfo := this.GetAdminUserInfo()
  1755. stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
  1756. if err != nil {
  1757. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1758. }
  1759. this.ServeSuccessJSON(map[string]interface{}{
  1760. "stockCount": stockCount,
  1761. })
  1762. }
  1763. func (this *StockManagerApiController) AddGoodInformation() {
  1764. adminUserInfo := this.GetAdminUserInfo()
  1765. orgId := adminUserInfo.CurrentOrgId
  1766. dataBody := make(map[string]interface{}, 0)
  1767. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1768. if err != nil {
  1769. utils.ErrorLog(err.Error())
  1770. return
  1771. }
  1772. utils.ErrorLog("%v", dataBody)
  1773. var goods []*models.GoodInfo
  1774. var total_goods []interface{}
  1775. tempGoods := dataBody["goods"].([]interface{})
  1776. total_goods = tempGoods
  1777. for index, goodMap := range tempGoods {
  1778. goodNameM := goodMap.(map[string]interface{})
  1779. var good models.GoodInfo
  1780. if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
  1781. utils.ErrorLog("good_name")
  1782. return
  1783. }
  1784. good_name, _ := goodNameM["good_name"].(string)
  1785. if len(good_name) == 0 { //名字为空则生成一条导入错误日志
  1786. err_log := models.ExportErrLog{
  1787. LogType: 5,
  1788. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1789. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
  1790. Status: 1,
  1791. CreateTime: time.Now().Unix(),
  1792. UpdateTime: time.Now().Unix(),
  1793. ExportTime: time.Now().Unix(),
  1794. }
  1795. service.CreateExportErrLog(&err_log)
  1796. continue
  1797. }
  1798. good.GoodName = good_name
  1799. // 获取数据字典数据
  1800. var good_kind_id int64
  1801. var name = "耗材种类"
  1802. config, _ := service.GetDrugDataConfig(0, name)
  1803. good_kind := goodNameM["good_kind"].(string)
  1804. if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
  1805. err_log := models.ExportErrLog{
  1806. LogType: 5,
  1807. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1808. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
  1809. Status: 1,
  1810. CreateTime: time.Now().Unix(),
  1811. UpdateTime: time.Now().Unix(),
  1812. ExportTime: time.Now().Unix(),
  1813. }
  1814. service.CreateExportErrLog(&err_log)
  1815. continue
  1816. }
  1817. if len(good_kind) != 0 {
  1818. _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
  1819. lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
  1820. dataconfig := models.DictDataconfig{
  1821. ParentId: config.ID,
  1822. Module: "system",
  1823. OrgId: orgId,
  1824. Name: good_kind,
  1825. FieldName: "",
  1826. Value: lastConfig.Value + 1,
  1827. CreatedTime: "",
  1828. UpdatedTime: "",
  1829. CreateUserId: adminUserInfo.AdminUser.Id,
  1830. Status: 1,
  1831. Remark: "",
  1832. DeleteIdSystem: 0,
  1833. Title: "",
  1834. Content: "",
  1835. Order: 0,
  1836. Code: "",
  1837. }
  1838. if errcodegoodkind == gorm.ErrRecordNotFound {
  1839. service.CreatedDicConfig(&dataconfig)
  1840. }
  1841. }
  1842. dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
  1843. for _, it := range dataConfig {
  1844. if good_kind == it.Name {
  1845. fmt.Println(it.Name)
  1846. good_kind_id = int64(it.Value)
  1847. }
  1848. }
  1849. good.GoodKind = good_kind_id
  1850. good_type := goodNameM["type_name"].(string)
  1851. if len(good_type) == 0 {
  1852. err_log := models.ExportErrLog{
  1853. LogType: 5,
  1854. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1855. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
  1856. Status: 1,
  1857. CreateTime: time.Now().Unix(),
  1858. UpdateTime: time.Now().Unix(),
  1859. ExportTime: time.Now().Unix(),
  1860. }
  1861. service.CreateExportErrLog(&err_log)
  1862. continue
  1863. }
  1864. if len(good_type) != 0 {
  1865. _, errcodegoodtype := service.GetGoodType(good_type, orgId)
  1866. if errcodegoodtype == gorm.ErrRecordNotFound {
  1867. goodsType := models.GoodsType{
  1868. TypeName: good_type,
  1869. Remark: "",
  1870. Ctime: time.Now().Unix(),
  1871. Mtime: 0,
  1872. Creater: adminUserInfo.AdminUser.Id,
  1873. Modifier: 0,
  1874. OrgId: adminUserInfo.CurrentOrgId,
  1875. Status: 1,
  1876. Type: 0,
  1877. Number: 0,
  1878. OutStock: 0,
  1879. StockAttribute: 1,
  1880. }
  1881. service.CreatedGoodType(&goodsType)
  1882. }
  1883. }
  1884. goodType, _ := service.GetAllGoodType(orgId)
  1885. var good_type_id int64
  1886. for _, it := range goodType {
  1887. if good_type == it.TypeName {
  1888. good_type_id = it.ID
  1889. }
  1890. }
  1891. good.GoodTypeId = good_type_id
  1892. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  1893. if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
  1894. err_log := models.ExportErrLog{
  1895. LogType: 5,
  1896. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1897. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  1898. Status: 1,
  1899. CreateTime: time.Now().Unix(),
  1900. UpdateTime: time.Now().Unix(),
  1901. ExportTime: time.Now().Unix(),
  1902. }
  1903. service.CreateExportErrLog(&err_log)
  1904. continue
  1905. }
  1906. var medical_insurance_id int64
  1907. var medicalInsurance = "医保等级"
  1908. medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
  1909. if len(medical_insurance_level) != 0 {
  1910. _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
  1911. if errcodemedicalInsurance == gorm.ErrRecordNotFound {
  1912. mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
  1913. dataconfig := models.DictDataconfig{
  1914. ParentId: medicalInsuranceDataConfig.ID,
  1915. Module: "system",
  1916. OrgId: orgId,
  1917. Name: medical_insurance_level,
  1918. FieldName: "",
  1919. Value: mediConfigOne.Value + 1,
  1920. CreatedTime: "",
  1921. UpdatedTime: "",
  1922. CreateUserId: adminUserInfo.AdminUser.Id,
  1923. Status: 1,
  1924. Remark: "",
  1925. DeleteIdSystem: 0,
  1926. Title: "",
  1927. Content: "",
  1928. Order: 0,
  1929. Code: "",
  1930. }
  1931. service.CreatedDicConfig(&dataconfig)
  1932. }
  1933. }
  1934. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
  1935. for _, it := range medicalInsuranceList {
  1936. if medical_insurance_level == it.Name {
  1937. medical_insurance_id = int64(it.Value)
  1938. }
  1939. }
  1940. good.MedicalInsuranceLevel = medical_insurance_id
  1941. if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
  1942. utils.ErrorLog("specification_name")
  1943. return
  1944. }
  1945. specification_name := goodNameM["specification_name"].(string)
  1946. if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
  1947. err_log := models.ExportErrLog{
  1948. LogType: 5,
  1949. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1950. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
  1951. Status: 1,
  1952. CreateTime: time.Now().Unix(),
  1953. UpdateTime: time.Now().Unix(),
  1954. ExportTime: time.Now().Unix(),
  1955. }
  1956. service.CreateExportErrLog(&err_log)
  1957. continue
  1958. }
  1959. good.SpecificationName = specification_name
  1960. var manufacturer_id int64
  1961. manufacturer := goodNameM["manufacturer"].(string)
  1962. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  1963. err_log := models.ExportErrLog{
  1964. LogType: 5,
  1965. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1966. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
  1967. Status: 1,
  1968. CreateTime: time.Now().Unix(),
  1969. UpdateTime: time.Now().Unix(),
  1970. ExportTime: time.Now().Unix(),
  1971. }
  1972. service.CreateExportErrLog(&err_log)
  1973. continue
  1974. }
  1975. if len(manufacturer) != 0 {
  1976. _, errcodes := service.GetManufacturerName(orgId, manufacturer)
  1977. manu := models.Manufacturer{
  1978. ManufacturerName: manufacturer,
  1979. Status: 1,
  1980. OrgId: orgId,
  1981. Creater: adminUserInfo.AdminUser.Id,
  1982. }
  1983. if errcodes == gorm.ErrRecordNotFound {
  1984. service.CreateManufacturer(&manu)
  1985. }
  1986. }
  1987. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1988. for _, it := range manufacturerList {
  1989. if manufacturer == it.ManufacturerName {
  1990. manufacturer_id = it.ID
  1991. }
  1992. }
  1993. good.Manufacturer = manufacturer_id
  1994. if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
  1995. utils.ErrorLog("unit_id")
  1996. return
  1997. }
  1998. unit_id := int64(goodNameM["unit_id"].(float64))
  1999. if unit_id <= 0 { //名字为空则生成一条导入错误日志
  2000. err_log := models.ExportErrLog{
  2001. LogType: 5,
  2002. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2003. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
  2004. Status: 1,
  2005. CreateTime: time.Now().Unix(),
  2006. UpdateTime: time.Now().Unix(),
  2007. ExportTime: time.Now().Unix(),
  2008. }
  2009. service.CreateExportErrLog(&err_log)
  2010. continue
  2011. }
  2012. good.GoodUnit = unit_id
  2013. retail_prices := goodNameM["retail_price"].(string)
  2014. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  2015. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  2016. err_log := models.ExportErrLog{
  2017. LogType: 5,
  2018. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2019. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
  2020. Status: 1,
  2021. CreateTime: time.Now().Unix(),
  2022. UpdateTime: time.Now().Unix(),
  2023. ExportTime: time.Now().Unix(),
  2024. }
  2025. service.CreateExportErrLog(&err_log)
  2026. continue
  2027. }
  2028. good.RetailPrice = retail_price
  2029. if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
  2030. utils.ErrorLog("stock_warn_count")
  2031. return
  2032. }
  2033. stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
  2034. if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
  2035. err_log := models.ExportErrLog{
  2036. LogType: 5,
  2037. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2038. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
  2039. Status: 1,
  2040. CreateTime: time.Now().Unix(),
  2041. UpdateTime: time.Now().Unix(),
  2042. ExportTime: time.Now().Unix(),
  2043. }
  2044. service.CreateExportErrLog(&err_log)
  2045. continue
  2046. }
  2047. good.StockWarnCount = stock_warn_count
  2048. var dealer_id int64
  2049. dealerName := goodNameM["dealer"].(string)
  2050. fmt.Println("经销商", dealerName)
  2051. dealer := models.Dealer{
  2052. OrgId: orgId,
  2053. Status: 1,
  2054. DealerName: dealerName,
  2055. Creater: adminUserInfo.AdminUser.Id,
  2056. Ctime: time.Now().Unix(),
  2057. }
  2058. if len(dealerName) != 0 {
  2059. _, errcodedealer := service.GetDealerByName(orgId, dealerName)
  2060. if errcodedealer == gorm.ErrRecordNotFound {
  2061. service.CreateDealer(&dealer)
  2062. }
  2063. }
  2064. dealerList, _ := service.GetAllDealerList(orgId)
  2065. for _, it := range dealerList {
  2066. if dealerName == it.DealerName {
  2067. dealer_id = it.ID
  2068. }
  2069. }
  2070. good.Dealer = dealer_id
  2071. if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
  2072. utils.ErrorLog("pinyin")
  2073. return
  2074. }
  2075. pinyin := goodNameM["pinyin"].(string)
  2076. good.Pinyin = pinyin
  2077. if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
  2078. utils.ErrorLog("wubi")
  2079. return
  2080. }
  2081. wubi := goodNameM["wubi"].(string)
  2082. good.Wubi = wubi
  2083. buy_prices := goodNameM["buy_price"].(string)
  2084. buy_price, _ := strconv.ParseFloat(buy_prices, 64)
  2085. good.BuyPrice = buy_price
  2086. if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
  2087. utils.ErrorLog("social_security_directory_code")
  2088. return
  2089. }
  2090. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  2091. good.SocialSecurityDirectoryCode = social_security_directory_code
  2092. if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
  2093. utils.ErrorLog("is_special_diseases")
  2094. return
  2095. }
  2096. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  2097. good.IsSpecialDiseases = is_special_diseases
  2098. if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
  2099. utils.ErrorLog("is_record")
  2100. return
  2101. }
  2102. is_record := int64(goodNameM["is_record"].(float64))
  2103. good.IsRecord = is_record
  2104. if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
  2105. utils.ErrorLog("good_status")
  2106. return
  2107. }
  2108. good_status := goodNameM["good_status"].(string)
  2109. good.GoodStatus = good_status
  2110. if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
  2111. utils.ErrorLog("medical_insurance_number")
  2112. return
  2113. }
  2114. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  2115. good.MedicalInsuranceNumber = medical_insurance_number
  2116. if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
  2117. utils.ErrorLog("production_type")
  2118. return
  2119. }
  2120. production_type := goodNameM["production_type"].(string)
  2121. good.ProductionType = production_type
  2122. if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
  2123. utils.ErrorLog("remark")
  2124. return
  2125. }
  2126. remark := goodNameM["remark"].(string)
  2127. good.Remark = remark
  2128. statistics_category := goodNameM["statistics_category"].(string)
  2129. var categoryName = "统计分类"
  2130. var statistic_id int64
  2131. drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
  2132. if len(statistics_category) != 0 {
  2133. _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
  2134. if errcodecagegory == gorm.ErrRecordNotFound {
  2135. dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
  2136. dataconfig := models.DictDataconfig{
  2137. ParentId: drugDataConfig.ID,
  2138. Module: "system",
  2139. OrgId: orgId,
  2140. Name: statistics_category,
  2141. FieldName: "",
  2142. Value: dicConfigThree.Value + 1,
  2143. CreatedTime: "",
  2144. UpdatedTime: "",
  2145. CreateUserId: adminUserInfo.AdminUser.Id,
  2146. Status: 1,
  2147. Remark: "",
  2148. DeleteIdSystem: 0,
  2149. Title: "",
  2150. Content: "",
  2151. Order: 0,
  2152. Code: "",
  2153. }
  2154. service.CreatedDicConfig(&dataconfig)
  2155. }
  2156. }
  2157. parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
  2158. for _, it := range parentDataConfig {
  2159. if statistics_category == it.Name {
  2160. statistic_id = int64(it.Value)
  2161. }
  2162. }
  2163. good.StatisticsCategory = statistic_id
  2164. special_medical := goodNameM["special_medical"].(string)
  2165. good.SpecialMedical = special_medical
  2166. goods = append(goods, &good)
  2167. }
  2168. export_time := time.Now().Unix()
  2169. errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2170. if len(goods) > 0 {
  2171. for _, item := range goods {
  2172. goodInfo := models.GoodInfo{
  2173. GoodName: item.GoodName,
  2174. SpecificationName: item.SpecificationName,
  2175. GoodKind: item.GoodKind,
  2176. GoodTypeId: item.GoodTypeId,
  2177. Dealer: item.Dealer,
  2178. GoodUnit: item.GoodUnit,
  2179. IsRecord: item.IsRecord,
  2180. IsSpecialDiseases: item.IsSpecialDiseases,
  2181. Manufacturer: item.Manufacturer,
  2182. Pinyin: item.Pinyin,
  2183. GoodStatus: item.GoodStatus,
  2184. ProductionType: item.ProductionType,
  2185. Remark: item.Remark,
  2186. RetailPrice: item.RetailPrice,
  2187. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  2188. SpecialMedical: item.SpecialMedical,
  2189. Wubi: item.Wubi,
  2190. StockWarnCount: item.StockWarnCount,
  2191. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  2192. OrgId: orgId,
  2193. Status: 1,
  2194. Ctime: time.Now().Unix(),
  2195. StatisticsCategory: item.StatisticsCategory,
  2196. GoodCode: item.GoodCode,
  2197. BuyPrice: item.BuyPrice,
  2198. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  2199. }
  2200. //查询同种耗材名称同种类型同种规格的耗材是否存在
  2201. _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2202. if errcodegood == gorm.ErrRecordNotFound {
  2203. service.CreateGoodsInfomation(&goodInfo)
  2204. } else if errcodegood == nil {
  2205. service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2206. }
  2207. log := models.ExportLog{
  2208. LogType: 5,
  2209. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2210. TotalNum: int64(len(total_goods)),
  2211. FailNum: int64(len(errLogs)),
  2212. SuccessNum: int64(len(goods)),
  2213. CreateTime: time.Now().Unix(),
  2214. UpdateTime: time.Now().Unix(),
  2215. ExportTime: export_time,
  2216. Status: 1,
  2217. }
  2218. service.CreateExportLog(&log)
  2219. this.ServeSuccessJSON(map[string]interface{}{
  2220. "msg": "导入成功",
  2221. "total_num": len(total_goods),
  2222. "success_num": len(goods),
  2223. "fail_num": int64(len(errLogs)),
  2224. })
  2225. }
  2226. } else {
  2227. log := models.ExportLog{
  2228. LogType: 5,
  2229. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2230. TotalNum: int64(len(total_goods)),
  2231. FailNum: int64(len(errLogs)),
  2232. SuccessNum: int64(len(goods)),
  2233. CreateTime: time.Now().Unix(),
  2234. UpdateTime: time.Now().Unix(),
  2235. ExportTime: export_time,
  2236. Status: 1,
  2237. }
  2238. service.CreateExportLog(&log)
  2239. this.ServeSuccessJSON(map[string]interface{}{
  2240. "msg": "导入成功",
  2241. "total_num": len(total_goods),
  2242. "success_num": len(goods),
  2243. "fail_num": int64(len(errLogs)),
  2244. })
  2245. }
  2246. }
  2247. func (this *StockManagerApiController) AddDrugInformation() {
  2248. adminUser := this.GetAdminUserInfo()
  2249. orgId := adminUser.CurrentOrgId
  2250. dataBody := make(map[string]interface{}, 0)
  2251. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2252. if err != nil {
  2253. utils.ErrorLog(err.Error())
  2254. return
  2255. }
  2256. utils.ErrorLog("%v", dataBody)
  2257. var drugList []*models.BaseDrugLib
  2258. var total_goods []interface{}
  2259. tempDrugs := dataBody["drugs"].([]interface{})
  2260. total_goods = tempDrugs
  2261. for index, drugMap := range tempDrugs {
  2262. goodNameM := drugMap.(map[string]interface{})
  2263. var drug models.BaseDrugLib
  2264. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  2265. utils.ErrorLog("drug_name")
  2266. return
  2267. }
  2268. drug_name, _ := goodNameM["drug_name"].(string)
  2269. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2270. err_log := models.ExportErrLog{
  2271. LogType: 4,
  2272. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2273. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  2274. Status: 1,
  2275. CreateTime: time.Now().Unix(),
  2276. UpdateTime: time.Now().Unix(),
  2277. ExportTime: time.Now().Unix(),
  2278. }
  2279. service.CreateExportErrLog(&err_log)
  2280. continue
  2281. }
  2282. drug.DrugName = drug_name
  2283. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  2284. utils.ErrorLog("min_number")
  2285. return
  2286. }
  2287. min_number, _ := goodNameM["min_number"].(string)
  2288. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  2289. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2290. err_log := models.ExportErrLog{
  2291. LogType: 4,
  2292. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2293. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  2294. Status: 1,
  2295. CreateTime: time.Now().Unix(),
  2296. UpdateTime: time.Now().Unix(),
  2297. ExportTime: time.Now().Unix(),
  2298. }
  2299. service.CreateExportErrLog(&err_log)
  2300. continue
  2301. }
  2302. drug.MinNumber = minNumber
  2303. min_unit := goodNameM["min_unit"].(string)
  2304. if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
  2305. err_log := models.ExportErrLog{
  2306. LogType: 4,
  2307. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2308. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
  2309. Status: 1,
  2310. CreateTime: time.Now().Unix(),
  2311. UpdateTime: time.Now().Unix(),
  2312. ExportTime: time.Now().Unix(),
  2313. }
  2314. service.CreateExportErrLog(&err_log)
  2315. continue
  2316. }
  2317. drug.MinUnit = min_unit
  2318. dose := goodNameM["dose"].(float64)
  2319. if dose < 0 { //名字为空则生成一条导入错误日志
  2320. err_log := models.ExportErrLog{
  2321. LogType: 4,
  2322. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2323. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  2324. Status: 1,
  2325. CreateTime: time.Now().Unix(),
  2326. UpdateTime: time.Now().Unix(),
  2327. ExportTime: time.Now().Unix(),
  2328. }
  2329. service.CreateExportErrLog(&err_log)
  2330. continue
  2331. }
  2332. drug.Dose = dose
  2333. max_unit_id := goodNameM["max_unit"].(string)
  2334. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  2335. err_log := models.ExportErrLog{
  2336. LogType: 4,
  2337. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2338. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  2339. Status: 1,
  2340. CreateTime: time.Now().Unix(),
  2341. UpdateTime: time.Now().Unix(),
  2342. ExportTime: time.Now().Unix(),
  2343. }
  2344. service.CreateExportErrLog(&err_log)
  2345. continue
  2346. }
  2347. drug.MaxUnit = max_unit_id
  2348. max_unit := goodNameM["max_unit"].(string)
  2349. if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
  2350. err_log := models.ExportErrLog{
  2351. LogType: 4,
  2352. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2353. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
  2354. Status: 1,
  2355. CreateTime: time.Now().Unix(),
  2356. UpdateTime: time.Now().Unix(),
  2357. ExportTime: time.Now().Unix(),
  2358. }
  2359. service.CreateExportErrLog(&err_log)
  2360. continue
  2361. }
  2362. drug.MaxUnit = max_unit
  2363. delivery_way := goodNameM["delivery_way"].(string)
  2364. if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
  2365. err_log := models.ExportErrLog{
  2366. LogType: 4,
  2367. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2368. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
  2369. Status: 1,
  2370. CreateTime: time.Now().Unix(),
  2371. UpdateTime: time.Now().Unix(),
  2372. ExportTime: time.Now().Unix(),
  2373. }
  2374. service.CreateExportErrLog(&err_log)
  2375. continue
  2376. }
  2377. drug.DeliveryWay = delivery_way
  2378. execution_frequency := goodNameM["execution_frequency"].(string)
  2379. if len(execution_frequency) == 0 { //名字为空则生成一条导入错误日志
  2380. err_log := models.ExportErrLog{
  2381. LogType: 4,
  2382. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2383. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  2384. Status: 1,
  2385. CreateTime: time.Now().Unix(),
  2386. UpdateTime: time.Now().Unix(),
  2387. ExportTime: time.Now().Unix(),
  2388. }
  2389. service.CreateExportErrLog(&err_log)
  2390. continue
  2391. }
  2392. drug.ExecutionFrequency = execution_frequency
  2393. drug_day := goodNameM["drug_day"].(string)
  2394. if len(drug_day) == 0 { //名字为空则生成一条导入错误日志
  2395. err_log := models.ExportErrLog{
  2396. LogType: 4,
  2397. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2398. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  2399. Status: 1,
  2400. CreateTime: time.Now().Unix(),
  2401. UpdateTime: time.Now().Unix(),
  2402. ExportTime: time.Now().Unix(),
  2403. }
  2404. service.CreateExportErrLog(&err_log)
  2405. continue
  2406. }
  2407. drug.DrugDay = drug_day
  2408. drug_type := goodNameM["drug_type"].(string)
  2409. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  2410. err_log := models.ExportErrLog{
  2411. LogType: 4,
  2412. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2413. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
  2414. Status: 1,
  2415. CreateTime: time.Now().Unix(),
  2416. UpdateTime: time.Now().Unix(),
  2417. ExportTime: time.Now().Unix(),
  2418. }
  2419. service.CreateExportErrLog(&err_log)
  2420. continue
  2421. }
  2422. var drug_type_id int64
  2423. var drugType = "药品类型"
  2424. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  2425. if len(drug_type) != 0 {
  2426. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  2427. if errcodes == gorm.ErrRecordNotFound {
  2428. //获取该型号最后一条数据型号
  2429. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  2430. dataconfig := models.DictDataconfig{
  2431. ParentId: drugconfig.ID,
  2432. Module: "system",
  2433. OrgId: orgId,
  2434. Name: drug_type,
  2435. FieldName: "",
  2436. Value: config.Value + 1,
  2437. CreatedTime: "",
  2438. UpdatedTime: "",
  2439. CreateUserId: adminUser.AdminUser.Id,
  2440. Status: 1,
  2441. Remark: "",
  2442. DeleteIdSystem: 0,
  2443. Title: "",
  2444. Content: "",
  2445. Order: 0,
  2446. Code: "",
  2447. }
  2448. service.CreatedDicConfig(&dataconfig)
  2449. }
  2450. }
  2451. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  2452. for _, it := range drugTypeList {
  2453. if drug_type == it.Name {
  2454. drug_type_id = int64(it.Value)
  2455. }
  2456. }
  2457. drug.DrugType = drug_type_id
  2458. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  2459. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  2460. err_log := models.ExportErrLog{
  2461. LogType: 4,
  2462. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2463. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  2464. Status: 1,
  2465. CreateTime: time.Now().Unix(),
  2466. UpdateTime: time.Now().Unix(),
  2467. ExportTime: time.Now().Unix(),
  2468. }
  2469. service.CreateExportErrLog(&err_log)
  2470. continue
  2471. }
  2472. drug.DrugStockLimit = drug_stock_limit
  2473. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  2474. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  2475. err_log := models.ExportErrLog{
  2476. LogType: 4,
  2477. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2478. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  2479. Status: 1,
  2480. CreateTime: time.Now().Unix(),
  2481. UpdateTime: time.Now().Unix(),
  2482. ExportTime: time.Now().Unix(),
  2483. }
  2484. service.CreateExportErrLog(&err_log)
  2485. continue
  2486. }
  2487. drug.DrugOriginPlace = drug_origin_place
  2488. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  2489. if len(drug_dosage_form) == 0 {
  2490. err_log := models.ExportErrLog{
  2491. LogType: 4,
  2492. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2493. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  2494. Status: 1,
  2495. CreateTime: time.Now().Unix(),
  2496. UpdateTime: time.Now().Unix(),
  2497. ExportTime: time.Now().Unix(),
  2498. }
  2499. service.CreateExportErrLog(&err_log)
  2500. continue
  2501. }
  2502. var drug_dosage = "药品剂型"
  2503. var drug_dosage_form_id int64
  2504. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  2505. if len(drug_dosage_form) != 0 {
  2506. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  2507. if errcodess == gorm.ErrRecordNotFound {
  2508. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  2509. dataconfig := models.DictDataconfig{
  2510. ParentId: drugDosageconfig.ID,
  2511. Module: "system",
  2512. OrgId: orgId,
  2513. Name: drug_dosage_form,
  2514. FieldName: "",
  2515. Value: configOne.Value + 1,
  2516. CreatedTime: "",
  2517. UpdatedTime: "",
  2518. CreateUserId: adminUser.AdminUser.Id,
  2519. Status: 1,
  2520. Remark: "",
  2521. DeleteIdSystem: 0,
  2522. Title: "",
  2523. Content: "",
  2524. Order: 0,
  2525. Code: "",
  2526. }
  2527. service.CreatedDicConfig(&dataconfig)
  2528. }
  2529. }
  2530. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  2531. for _, it := range drugDosageList {
  2532. if drug_dosage_form == it.Name {
  2533. drug_dosage_form_id = int64(it.Value)
  2534. }
  2535. }
  2536. drug.DrugDosageForm = drug_dosage_form_id
  2537. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  2538. var medical_insurance_level_id int64
  2539. if len(medical_insurance_level) == 0 { //名字为空则生成一条导入错误日志
  2540. err_log := models.ExportErrLog{
  2541. LogType: 4,
  2542. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2543. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  2544. Status: 1,
  2545. CreateTime: time.Now().Unix(),
  2546. UpdateTime: time.Now().Unix(),
  2547. ExportTime: time.Now().Unix(),
  2548. }
  2549. service.CreateExportErrLog(&err_log)
  2550. continue
  2551. }
  2552. var medicalInsuranceName = "医保等级"
  2553. medicalInsuranceConfig, _ := service.GetDrugDataConfig(0, medicalInsuranceName)
  2554. if len(medical_insurance_level) != 0 {
  2555. _, errcodemedical := service.IsExistDicConfig(medicalInsuranceConfig.ID, medical_insurance_level, orgId)
  2556. if errcodemedical == gorm.ErrRecordNotFound {
  2557. medConfig, _ := service.GetLastDicConfig(medicalInsuranceConfig.ID, orgId)
  2558. dataconfig := models.DictDataconfig{
  2559. ParentId: medicalInsuranceConfig.ID,
  2560. Module: "system",
  2561. OrgId: orgId,
  2562. Name: medical_insurance_level,
  2563. FieldName: "",
  2564. Value: medConfig.Value + 1,
  2565. CreatedTime: "",
  2566. UpdatedTime: "",
  2567. CreateUserId: adminUser.AdminUser.Id,
  2568. Status: 1,
  2569. Remark: "",
  2570. DeleteIdSystem: 0,
  2571. Title: "",
  2572. Content: "",
  2573. Order: 0,
  2574. Code: "",
  2575. }
  2576. service.CreatedDicConfig(&dataconfig)
  2577. }
  2578. }
  2579. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceConfig.ID, orgId)
  2580. for _, it := range medicalInsuranceList {
  2581. if medical_insurance_level == it.Name {
  2582. medical_insurance_level_id = int64(it.Value)
  2583. }
  2584. }
  2585. drug.MedicalInsuranceLevel = medical_insurance_level_id
  2586. unit_matrixing := goodNameM["unit_matrixing"].(string)
  2587. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  2588. err_log := models.ExportErrLog{
  2589. LogType: 4,
  2590. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2591. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位换算不能为空",
  2592. Status: 1,
  2593. CreateTime: time.Now().Unix(),
  2594. UpdateTime: time.Now().Unix(),
  2595. ExportTime: time.Now().Unix(),
  2596. }
  2597. service.CreateExportErrLog(&err_log)
  2598. continue
  2599. }
  2600. drug.UnitMatrixing = unit_matrixing
  2601. retail_prices := goodNameM["retail_price"].(string)
  2602. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  2603. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  2604. err_log := models.ExportErrLog{
  2605. LogType: 4,
  2606. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2607. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  2608. Status: 1,
  2609. CreateTime: time.Now().Unix(),
  2610. UpdateTime: time.Now().Unix(),
  2611. ExportTime: time.Now().Unix(),
  2612. }
  2613. service.CreateExportErrLog(&err_log)
  2614. continue
  2615. }
  2616. drug.RetailPrice = retail_price
  2617. packing_prices := goodNameM["packing_price"].(string)
  2618. packing_price, _ := strconv.ParseFloat(packing_prices, 64)
  2619. if packing_price <= 0 { //名字为空则生成一条导入错误日志
  2620. err_log := models.ExportErrLog{
  2621. LogType: 4,
  2622. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2623. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装零售价不能为空",
  2624. Status: 1,
  2625. CreateTime: time.Now().Unix(),
  2626. UpdateTime: time.Now().Unix(),
  2627. ExportTime: time.Now().Unix(),
  2628. }
  2629. service.CreateExportErrLog(&err_log)
  2630. continue
  2631. }
  2632. drug.RetailPrice = retail_price
  2633. last_prices := goodNameM["last_price"].(string)
  2634. last_price, _ := strconv.ParseFloat(last_prices, 64)
  2635. if last_price <= 0 { //名字为空则生成一条导入错误日志
  2636. err_log := models.ExportErrLog{
  2637. LogType: 4,
  2638. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2639. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  2640. Status: 1,
  2641. CreateTime: time.Now().Unix(),
  2642. UpdateTime: time.Now().Unix(),
  2643. ExportTime: time.Now().Unix(),
  2644. }
  2645. service.CreateExportErrLog(&err_log)
  2646. continue
  2647. }
  2648. drug.LastPrice = last_price
  2649. drug_classify := goodNameM["drug_classify"].(string)
  2650. if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
  2651. err_log := models.ExportErrLog{
  2652. LogType: 4,
  2653. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2654. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
  2655. Status: 1,
  2656. CreateTime: time.Now().Unix(),
  2657. UpdateTime: time.Now().Unix(),
  2658. ExportTime: time.Now().Unix(),
  2659. }
  2660. service.CreateExportErrLog(&err_log)
  2661. continue
  2662. }
  2663. var drugClassify = "药物分类"
  2664. var drug_classify_id int64
  2665. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  2666. if len(drug_classify) != 0 {
  2667. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  2668. if errcodesClass == gorm.ErrRecordNotFound {
  2669. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  2670. dataconfig := models.DictDataconfig{
  2671. ParentId: drugClassifyConfig.ID,
  2672. Module: "system",
  2673. OrgId: orgId,
  2674. Name: drug_classify,
  2675. FieldName: "",
  2676. Value: drugClassConfig.Value + 1,
  2677. CreatedTime: "",
  2678. UpdatedTime: "",
  2679. CreateUserId: adminUser.AdminUser.Id,
  2680. Status: 1,
  2681. Remark: "",
  2682. DeleteIdSystem: 0,
  2683. Title: "",
  2684. Content: "",
  2685. Order: 0,
  2686. Code: "",
  2687. }
  2688. service.CreatedDicConfig(&dataconfig)
  2689. }
  2690. }
  2691. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  2692. for _, it := range drugClassList {
  2693. if drug_classify == it.Name {
  2694. drug_classify_id = int64(it.Value)
  2695. }
  2696. }
  2697. drug_dose := goodNameM["drug_dose"].(string)
  2698. if len(drug_dose) == 0 {
  2699. err_log := models.ExportErrLog{
  2700. LogType: 4,
  2701. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2702. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
  2703. Status: 1,
  2704. CreateTime: time.Now().Unix(),
  2705. UpdateTime: time.Now().Unix(),
  2706. ExportTime: time.Now().Unix(),
  2707. }
  2708. service.CreateExportErrLog(&err_log)
  2709. continue
  2710. }
  2711. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  2712. drug.DrugDose = drugDoses
  2713. var units = "单位"
  2714. var unit_id int64
  2715. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  2716. if len(drugDoseUnit) == 0 {
  2717. err_log := models.ExportErrLog{
  2718. LogType: 4,
  2719. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2720. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  2721. Status: 1,
  2722. CreateTime: time.Now().Unix(),
  2723. UpdateTime: time.Now().Unix(),
  2724. ExportTime: time.Now().Unix(),
  2725. }
  2726. service.CreateExportErrLog(&err_log)
  2727. continue
  2728. }
  2729. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  2730. if len(drugDoseUnit) != 0 {
  2731. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  2732. if errcodedataconfig == gorm.ErrRecordNotFound {
  2733. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  2734. dataconfig := models.Dataconfig{
  2735. ParentId: dataConfig.ID,
  2736. Module: "hemodialysis",
  2737. OrgId: orgId,
  2738. Name: drugDoseUnit,
  2739. FieldName: "",
  2740. Value: childConfig.Value + 1,
  2741. CreatedTime: "",
  2742. UpdatedTime: "",
  2743. CreateUserId: adminUser.AdminUser.Id,
  2744. Status: 1,
  2745. Remark: "",
  2746. DeleteIdSystem: 0,
  2747. Title: "",
  2748. Content: "",
  2749. Order: 0,
  2750. Code: "",
  2751. FieldType: 0,
  2752. }
  2753. service.CreateDataConfig(&dataconfig)
  2754. }
  2755. }
  2756. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  2757. for _, it := range list {
  2758. if drugDoseUnit == it.Name {
  2759. unit_id = int64(it.Value)
  2760. }
  2761. }
  2762. drug.DrugDoseUnit = unit_id
  2763. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  2764. manufacturer := goodNameM["manufacturer"].(string)
  2765. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  2766. err_log := models.ExportErrLog{
  2767. LogType: 4,
  2768. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2769. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  2770. Status: 1,
  2771. CreateTime: time.Now().Unix(),
  2772. UpdateTime: time.Now().Unix(),
  2773. ExportTime: time.Now().Unix(),
  2774. }
  2775. service.CreateExportErrLog(&err_log)
  2776. continue
  2777. }
  2778. if len(manufacturer) != 0 {
  2779. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  2780. if errcodema == gorm.ErrRecordNotFound {
  2781. manufactur := models.Manufacturer{
  2782. OrgId: orgId,
  2783. Status: 1,
  2784. ManufacturerName: manufacturer,
  2785. Ctime: time.Now().Unix(),
  2786. Creater: adminUser.AdminUser.Id,
  2787. }
  2788. service.CreateManufacturer(&manufactur)
  2789. }
  2790. }
  2791. var manufacturer_id int64
  2792. manufacturList, _ := service.GetAllManufacturerList(orgId)
  2793. for _, it := range manufacturList {
  2794. if manufacturer == it.ManufacturerName {
  2795. manufacturer_id = it.ID
  2796. }
  2797. }
  2798. drug.Manufacturer = manufacturer_id
  2799. dealer := goodNameM["dealer"].(string)
  2800. if len(dealer) != 0 {
  2801. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  2802. if errcodesdealer == gorm.ErrRecordNotFound {
  2803. dealerconfig := models.Dealer{
  2804. DealerName: dealer,
  2805. Status: 1,
  2806. OrgId: orgId,
  2807. Ctime: time.Now().Unix(),
  2808. Creater: adminUser.AdminUser.Id,
  2809. }
  2810. service.CreateDealer(&dealerconfig)
  2811. }
  2812. }
  2813. var dealer_id int64
  2814. dealerList, _ := service.GetAllDealerList(orgId)
  2815. for _, it := range dealerList {
  2816. if dealer == it.DealerName {
  2817. dealer_id = it.ID
  2818. }
  2819. }
  2820. drug.Dealer = dealer_id
  2821. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  2822. drug.LmtUsedFlag = lmt_used_flags
  2823. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  2824. utils.ErrorLog("drug_alias")
  2825. return
  2826. }
  2827. drug_alias, _ := goodNameM["drug_alias"].(string)
  2828. drug.DrugAlias = drug_alias
  2829. drug_category := goodNameM["drug_category"].(string)
  2830. var drugCategory = "药品类别"
  2831. var drug_category_id int64
  2832. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  2833. if len(drug_category) != 0 {
  2834. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  2835. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  2836. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  2837. dataconfig := models.DictDataconfig{
  2838. ParentId: drugCategoryConfig.ID,
  2839. Module: "system",
  2840. OrgId: orgId,
  2841. Name: drug_category,
  2842. FieldName: "",
  2843. Value: drugCategoryConfigSix.Value + 1,
  2844. CreatedTime: "",
  2845. UpdatedTime: "",
  2846. CreateUserId: adminUser.AdminUser.Id,
  2847. Status: 1,
  2848. Remark: "",
  2849. DeleteIdSystem: 0,
  2850. Title: "",
  2851. Content: "",
  2852. Order: 0,
  2853. Code: "",
  2854. }
  2855. service.CreatedDicConfig(&dataconfig)
  2856. }
  2857. }
  2858. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  2859. fmt.Println("drugCategoryList", drugCategoryList)
  2860. for _, it := range drugCategoryList {
  2861. if drug_category == it.Name {
  2862. drug_category_id = int64(it.Value)
  2863. }
  2864. }
  2865. drug.DrugCategory = drug_category_id
  2866. statistics_category := goodNameM["statistics_category"].(string)
  2867. var statisticsCategory = "统计分类"
  2868. var statistics_category_id int64
  2869. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  2870. if len(statistics_category) != 0 {
  2871. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  2872. if errcodestatistc == gorm.ErrRecordNotFound {
  2873. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  2874. dataconfig := models.DictDataconfig{
  2875. ParentId: statistcConfig.ID,
  2876. Module: "system",
  2877. OrgId: orgId,
  2878. Name: statistics_category,
  2879. FieldName: "",
  2880. Value: staConfig.Value + 1,
  2881. CreatedTime: "",
  2882. UpdatedTime: "",
  2883. CreateUserId: adminUser.AdminUser.Id,
  2884. Status: 1,
  2885. Remark: "",
  2886. DeleteIdSystem: 0,
  2887. Title: "",
  2888. Content: "",
  2889. Order: 0,
  2890. Code: "",
  2891. }
  2892. service.CreatedDicConfig(&dataconfig)
  2893. }
  2894. }
  2895. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  2896. for _, it := range statisticsCategoryList {
  2897. if statistics_category == it.Name {
  2898. statistics_category_id = int64(it.Value)
  2899. }
  2900. }
  2901. drug.StatisticsCategory = statistics_category_id
  2902. number := goodNameM["number"].(string)
  2903. drug.Number = number
  2904. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  2905. drug.HospApprFlag = hosp_appr_flag
  2906. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  2907. drug.MedicalInsuranceNumber = medical_insurance_number
  2908. pharmacology_category := goodNameM["pharmacology_category"].(string)
  2909. var pharmacology = "药理分类"
  2910. var pharmacology_category_id int64
  2911. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  2912. if len(pharmacology_category) != 0 {
  2913. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  2914. if errcodespharmacology == gorm.ErrRecordNotFound {
  2915. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  2916. dataconfig := models.DictDataconfig{
  2917. ParentId: pharmacologyConfig.ID,
  2918. Module: "system",
  2919. OrgId: orgId,
  2920. Name: pharmacology_category,
  2921. FieldName: "",
  2922. Value: dicConfig.Value + 1,
  2923. CreatedTime: "",
  2924. UpdatedTime: "",
  2925. CreateUserId: adminUser.AdminUser.Id,
  2926. Status: 1,
  2927. Remark: "",
  2928. DeleteIdSystem: 0,
  2929. Title: "",
  2930. Content: "",
  2931. Order: 0,
  2932. Code: "",
  2933. }
  2934. service.CreatedDicConfig(&dataconfig)
  2935. }
  2936. }
  2937. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  2938. for _, it := range pharmacologyList {
  2939. if pharmacology_category == it.Name {
  2940. pharmacology_category_id = int64(it.Value)
  2941. }
  2942. }
  2943. drug.PharmacologyCategory = pharmacology_category_id
  2944. code := goodNameM["code"].(string)
  2945. drug.Code = code
  2946. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  2947. drug.IsSpecialDiseases = is_special_diseases
  2948. is_record := int64(goodNameM["is_record"].(float64))
  2949. drug.IsRecord = is_record
  2950. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  2951. drug.PrescriptionMark = prescription_mark
  2952. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  2953. drug.SocialSecurityDirectoryCode = social_security_directory_code
  2954. record_date := goodNameM["record_date"].(string)
  2955. timeLayout := "2006-01-02"
  2956. loc, _ := time.LoadLocation("Local")
  2957. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2958. drug.RecordDate = theTime.Unix()
  2959. drug_remark := goodNameM["drug_remark"].(string)
  2960. drug.DrugRemark = drug_remark
  2961. drug_status := goodNameM["drug_status"].(string)
  2962. drug.DrugStatus = drug_status
  2963. limit_remark := goodNameM["limit_remark"].(string)
  2964. drug.LimitRemark = limit_remark
  2965. drug_control := goodNameM["drug_control"].(string)
  2966. var drugControl = "开药控制"
  2967. var drug_control_id int64
  2968. drugContorlConfig, _ := service.GetDrugDataConfig(0, drugControl)
  2969. if len(drug_control) != 0 {
  2970. _, errcodesdrugcontrol := service.IsExistDicConfig(drugContorlConfig.ID, drug_control, orgId)
  2971. if errcodesdrugcontrol == gorm.ErrRecordNotFound {
  2972. drugContorlConfigOne, _ := service.GetLastDicConfig(drugContorlConfig.ID, orgId)
  2973. dataconfig := models.DictDataconfig{
  2974. ParentId: drugContorlConfig.ID,
  2975. Module: "system",
  2976. OrgId: orgId,
  2977. Name: drug_control,
  2978. FieldName: "",
  2979. Value: drugContorlConfigOne.Value + 1,
  2980. CreatedTime: "",
  2981. UpdatedTime: "",
  2982. CreateUserId: adminUser.AdminUser.Id,
  2983. Status: 1,
  2984. Remark: "",
  2985. DeleteIdSystem: 0,
  2986. Title: "",
  2987. Content: "",
  2988. Order: 0,
  2989. Code: "",
  2990. }
  2991. service.CreatedDicConfig(&dataconfig)
  2992. }
  2993. }
  2994. drugContorlList, _ := service.GetParentDataConfig(drugContorlConfig.ID, orgId)
  2995. for _, it := range drugContorlList {
  2996. if drug_control == it.Name {
  2997. drug_control_id = int64(it.Value)
  2998. }
  2999. }
  3000. drug.DrugControl = drug_control_id
  3001. drugList = append(drugList, &drug)
  3002. }
  3003. export_time := time.Now().Unix()
  3004. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3005. if len(drugList) > 0 {
  3006. for _, item := range drugList {
  3007. goodInfo := models.BaseDrugLib{
  3008. DrugName: item.DrugName,
  3009. DrugAlias: item.DrugAlias,
  3010. DrugSpec: item.DrugSpec,
  3011. DrugType: item.DrugType,
  3012. DrugStockLimit: item.DrugStockLimit,
  3013. DrugOriginPlace: item.DrugOriginPlace,
  3014. DrugDosageForm: item.DrugDosageForm,
  3015. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3016. MaxUnit: item.MaxUnit,
  3017. MinUnit: item.MinUnit,
  3018. UnitMatrixing: item.UnitMatrixing,
  3019. RetailPrice: item.RetailPrice,
  3020. LastPrice: item.LastPrice,
  3021. DrugClassify: item.DrugClassify,
  3022. Manufacturer: item.Manufacturer,
  3023. Dealer: item.Dealer,
  3024. OrgId: orgId,
  3025. Status: 1,
  3026. Ctime: time.Now().Unix(),
  3027. Pinyin: item.Pinyin,
  3028. Wubi: item.Wubi,
  3029. DrugAliasPinyin: item.DrugAliasPinyin,
  3030. DrugAliasWubi: item.DrugAliasWubi,
  3031. DrugControl: item.DrugControl,
  3032. Number: item.Number,
  3033. HospApprFlag: item.HospApprFlag,
  3034. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3035. PharmacologyCategory: item.PharmacologyCategory,
  3036. StatisticsCategory: item.StatisticsCategory,
  3037. Code: item.Code,
  3038. IsSpecialDiseases: item.IsSpecialDiseases,
  3039. IsRecord: item.IsRecord,
  3040. PrescriptionMark: item.PrescriptionMark,
  3041. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3042. RecordDate: item.RecordDate,
  3043. DrugRemark: item.DrugRemark,
  3044. DrugStatus: item.DrugStatus,
  3045. LimitRemark: item.LimitRemark,
  3046. DrugCategory: item.DrugCategory,
  3047. DrugDose: item.DrugDose,
  3048. DrugDoseUnit: item.DrugDoseUnit,
  3049. LmtUsedFlag: item.LmtUsedFlag,
  3050. DrugDay: item.DrugDay,
  3051. DeliveryWay: item.DeliveryWay,
  3052. ExecutionFrequency: item.ExecutionFrequency,
  3053. DoseUnit: item.DoseUnit,
  3054. }
  3055. //查询同种药品同种规格是否存在
  3056. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.MaxUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  3057. if drugerror == gorm.ErrRecordNotFound {
  3058. service.CreateDrugsInfomation(&goodInfo)
  3059. } else if drugerror == nil {
  3060. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  3061. }
  3062. log := models.ExportLog{
  3063. LogType: 4,
  3064. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3065. TotalNum: int64(len(total_goods)),
  3066. FailNum: int64(len(errLogs)),
  3067. SuccessNum: int64(len(drugList)),
  3068. CreateTime: time.Now().Unix(),
  3069. UpdateTime: time.Now().Unix(),
  3070. ExportTime: export_time,
  3071. Status: 1,
  3072. }
  3073. service.CreateExportLog(&log)
  3074. this.ServeSuccessJSON(map[string]interface{}{
  3075. "msg": "导入成功",
  3076. "total_num": len(total_goods),
  3077. "success_num": len(drugList),
  3078. "fail_num": int64(len(errLogs)),
  3079. })
  3080. }
  3081. } else {
  3082. log := models.ExportLog{
  3083. LogType: 4,
  3084. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3085. TotalNum: int64(len(total_goods)),
  3086. FailNum: int64(len(errLogs)),
  3087. SuccessNum: int64(len(drugList)),
  3088. CreateTime: time.Now().Unix(),
  3089. UpdateTime: time.Now().Unix(),
  3090. ExportTime: export_time,
  3091. Status: 1,
  3092. }
  3093. service.CreateExportLog(&log)
  3094. this.ServeSuccessJSON(map[string]interface{}{
  3095. "msg": "导入成功",
  3096. "total_num": len(total_goods),
  3097. "success_num": len(drugList),
  3098. "fail_num": int64(len(errLogs)),
  3099. })
  3100. }
  3101. }
  3102. func (this *StockManagerApiController) GetInitializtion() {
  3103. orgId := this.GetAdminUserInfo().CurrentOrgId
  3104. var drugCategory = "药品类别"
  3105. var drugType = "药品类型"
  3106. var drugDosageForm = "药品剂型"
  3107. var medicalInsuranceLevel = "医保等级"
  3108. var drugControl = "开药控制"
  3109. var drugClassify = "药物分类"
  3110. var statisticsCategory = "统计分类"
  3111. var pharmacologyCategory = "药理分类"
  3112. var goodKind = "耗材种类"
  3113. var tubeColor = "试管颜色"
  3114. var costClassify = "费用类别"
  3115. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3116. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3117. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  3118. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  3119. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  3120. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  3121. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  3122. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  3123. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  3124. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  3125. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  3126. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  3127. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3128. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  3129. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  3130. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  3131. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  3132. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  3133. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  3134. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  3135. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  3136. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  3137. this.ServeSuccessJSON(map[string]interface{}{
  3138. "drugCategoryList": drugCategoryList,
  3139. "drugTypeList": drugTypeList,
  3140. "drugDosageFormList": drugDosageFormList,
  3141. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  3142. "drugControlList": drugControlList,
  3143. "drugClassifyList": drugClassifyList,
  3144. "statisticsCategoryList": statisticsCategoryList,
  3145. "pharmacologyCategoryList": pharmacologyCategoryList,
  3146. "goodKindList": goodKindList,
  3147. "tubeColorList": tubeColorList,
  3148. "costClassifyList": costClassifyList,
  3149. })
  3150. }
  3151. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  3152. adminUserInfo := this.GetAdminUserInfo()
  3153. orgId := adminUserInfo.CurrentOrgId
  3154. list, _ := service.GetWarehouseOrderInfoList(orgId)
  3155. this.ServeSuccessJSON(map[string]interface{}{
  3156. "list": list,
  3157. })
  3158. }
  3159. func (this *StockManagerApiController) PostSearchGoodList() {
  3160. keyword := this.GetString("keyword")
  3161. adminUserInfo := this.GetAdminUserInfo()
  3162. orgId := adminUserInfo.CurrentOrgId
  3163. list, _ := service.GetSearchGoodList(keyword, orgId)
  3164. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3165. this.ServeSuccessJSON(map[string]interface{}{
  3166. "list": list,
  3167. "manufacturerList": manufacturerList,
  3168. })
  3169. }