stock_in_api_controller.go 111KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491
  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. }
  63. func (c *StockManagerApiController) CreateWarehouse() {
  64. warehousing_time := c.GetString("warehousing_time")
  65. dealer_id, _ := c.GetInt64("dealer_id", 0)
  66. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  67. types, _ := c.GetInt64("type", 0)
  68. ctime := time.Now().Unix()
  69. adminUserInfo := c.GetAdminUserInfo()
  70. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  71. if parseDateErr != nil {
  72. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  73. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  74. return
  75. }
  76. timeStr := time.Now().Format("2006-01-02")
  77. timeArr := strings.Split(timeStr, "-")
  78. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  79. total = total + 1
  80. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  81. operation_time := time.Now().Unix()
  82. creater := adminUserInfo.AdminUser.Id
  83. warehousing := models.Warehousing{
  84. WarehousingOrder: warehousing_order,
  85. OperationTime: operation_time,
  86. OrgId: adminUserInfo.CurrentOrgId,
  87. Creater: creater,
  88. Ctime: ctime,
  89. Status: 1,
  90. WarehousingTime: warehousingDate.Unix(),
  91. Dealer: dealer_id,
  92. Manufacturer: manufacturer_id,
  93. Type: types,
  94. }
  95. service.AddSigleWarehouse(&warehousing)
  96. dataBody := make(map[string]interface{}, 0)
  97. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  98. if err != nil {
  99. utils.ErrorLog(err.Error())
  100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  101. return
  102. }
  103. var warehousingInfo []*models.WarehousingInfo
  104. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  105. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  106. if len(thisStockIn) > 0 {
  107. for _, item := range thisStockIn {
  108. items := item.(map[string]interface{})
  109. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  110. utils.ErrorLog("good_id")
  111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  112. return
  113. }
  114. good_id := int64(items["good_id"].(float64))
  115. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  116. utils.ErrorLog("good_type_id")
  117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  118. return
  119. }
  120. good_type_id := int64(items["good_type_id"].(float64))
  121. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  122. utils.ErrorLog("warehousing_count")
  123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  124. return
  125. }
  126. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  127. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  128. utils.ErrorLog("price")
  129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  130. return
  131. }
  132. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  133. total := float64(warehousing_count) * price
  134. var productDates int64
  135. var expiryDates int64
  136. fmt.Println()
  137. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  138. expiryDates = 0
  139. } else {
  140. if len(items["expiry_date"].(string)) == 0 {
  141. expiryDates = 0
  142. } else {
  143. expiryDate, _ := items["expiry_date"].(string)
  144. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  145. expiryDates = expiry_date.Unix()
  146. }
  147. }
  148. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  149. productDates = 0
  150. } else {
  151. if len(items["product_date"].(string)) == 0 {
  152. productDates = 0
  153. } else {
  154. productDate, _ := items["product_date"].(string)
  155. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  156. productDates = product_date.Unix()
  157. }
  158. }
  159. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  160. utils.ErrorLog("number")
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  162. return
  163. }
  164. number, _ := items["number"].(string)
  165. var remark string
  166. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  167. remark = ""
  168. } else {
  169. remark = items["remark"].(string)
  170. }
  171. warehouseInfo := &models.WarehousingInfo{
  172. WarehousingOrder: warehousing.WarehousingOrder,
  173. WarehousingId: warehousing.ID,
  174. GoodId: good_id,
  175. Number: number,
  176. GoodTypeId: good_type_id,
  177. ProductDate: productDates,
  178. ExpiryDate: expiryDates,
  179. WarehousingCount: warehousing_count,
  180. Price: price,
  181. TotalPrice: total,
  182. Status: 1,
  183. Ctime: ctime,
  184. Remark: remark,
  185. OrgId: adminUserInfo.CurrentOrgId,
  186. Type: types,
  187. Manufacturer: manufacturer_id,
  188. Dealer: dealer_id,
  189. }
  190. warehousingInfo = append(warehousingInfo, warehouseInfo)
  191. }
  192. }
  193. }
  194. errs := service.CreateWarehousingInfo(warehousingInfo)
  195. info, _ := service.FindLastWarehousingInfo(warehousing.WarehousingOrder)
  196. if errs != nil {
  197. utils.ErrorLog(errs.Error())
  198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  199. return
  200. }
  201. c.ServeSuccessJSON(map[string]interface{}{
  202. "msg": "入库成功",
  203. "warehousing_order": warehousing_order,
  204. "info": info,
  205. })
  206. //}
  207. //else {
  208. // warehouse, err1 := service.FindWareHouseByOrderNumber(warehousing_order)
  209. // if (err1 != nil) {
  210. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  211. // return
  212. // }
  213. //
  214. // dataBody := make(map[string]interface{}, 0)
  215. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  216. // if err != nil {
  217. // utils.ErrorLog(err.Error())
  218. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  219. // return
  220. // }
  221. //
  222. // var warehousingInfo []*models.WarehousingInfo
  223. //
  224. // if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  225. // thisStockIn, _ := dataBody["stockIn"].([]interface{})
  226. // if len(thisStockIn) > 0 {
  227. // for _, item := range thisStockIn {
  228. // items := item.(map[string]interface{})
  229. //
  230. // if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  231. // utils.ErrorLog("good_id")
  232. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  233. // return
  234. // }
  235. // good_id := int64(items["good_id"].(float64))
  236. //
  237. // if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  238. // utils.ErrorLog("good_type_id")
  239. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  240. // return
  241. // }
  242. // good_type_id := int64(items["good_type_id"].(float64))
  243. //
  244. // if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  245. // utils.ErrorLog("warehousing_count")
  246. // c.ServeFailJSONWithSGJErrorCod Fe(enums.ErrorCodeParamWrong)
  247. // return
  248. // }
  249. //
  250. // warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  251. //
  252. // if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  253. // utils.ErrorLog("price")
  254. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  255. // return
  256. // }
  257. // price, _ := strconv.ParseFloat(items["price"].(string), 64)
  258. // total := float64(warehousing_count) * price
  259. //
  260. // if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  261. // utils.ErrorLog("expiry_date")
  262. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  263. // return
  264. // }
  265. //
  266. // expiryDate, _ := items["expiry_date"].(string)
  267. // if len(expiryDate) == 0 {
  268. // utils.ErrorLog("len(expiry_date) == 0")
  269. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  270. //
  271. // return
  272. // }
  273. //
  274. // expiry_date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  275. // if parseDateErr != nil {
  276. // c.ErrorLog("日期(%v)解析错误:%v", expiry_date, parseDateErr)
  277. // }
  278. //
  279. // var productDates int64
  280. //
  281. // if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  282. // productDates = 0;
  283. // } else {
  284. // productDate, _ := items["product_date"].(string)
  285. // product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  286. // productDates = product_date.Unix()
  287. //
  288. // }
  289. //
  290. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  291. // utils.ErrorLog("number")
  292. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  293. // return
  294. // }
  295. // number, _ := items["number"].(string)
  296. //
  297. // var remark string
  298. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  299. // remark = ""
  300. // } else {
  301. // remark = items["remark"].(string)
  302. // }
  303. //
  304. // warehouseInfo := &models.WarehousingInfo{
  305. // WarehousingOrder: warehousing_order,
  306. // WarehousingId: warehouse.ID,
  307. // GoodId: good_id,
  308. // Number: number,
  309. // GoodTypeId: good_type_id,
  310. // ProductDate: productDates,
  311. // ExpiryDate: expiry_date.Unix(),
  312. // WarehousingCount: warehousing_count,
  313. // Price: price,
  314. // TotalPrice: total,
  315. // Status: 1,
  316. // Ctime: ctime,
  317. // Remark: remark,
  318. // OrgId: adminUserInfo.CurrentOrgId,
  319. // }
  320. // warehousingInfo = append(warehousingInfo, warehouseInfo)
  321. //
  322. // }
  323. // }
  324. // }
  325. // errs := service.CreateWarehousingInfo(warehousingInfo)
  326. // info, _ := service.FindLastWarehousingInfo(warehousing_order)
  327. //
  328. // if (errs != nil) {
  329. // utils.ErrorLog(errs.Error())
  330. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  331. // return
  332. // }
  333. //
  334. // c.ServeSuccessJSON(map[string]interface{}{
  335. // "msg": "入库成功",
  336. // "info": info,
  337. // })
  338. //
  339. //}
  340. }
  341. func (c *StockManagerApiController) GetWarehouseList() {
  342. page, _ := c.GetInt64("page", -1)
  343. limit, _ := c.GetInt64("limit", -1)
  344. start_time := c.GetString("start_time")
  345. end_time := c.GetString("end_time")
  346. types, _ := c.GetInt64("type", 0)
  347. keywords := c.GetString("keywords")
  348. fmt.Println(start_time)
  349. fmt.Println(end_time)
  350. timeLayout := "2006-01-02"
  351. loc, _ := time.LoadLocation("Local")
  352. var startTime int64
  353. if len(start_time) > 0 {
  354. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  355. if err != nil {
  356. fmt.Println(err)
  357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  358. return
  359. }
  360. startTime = theTime.Unix()
  361. }
  362. var endTime int64
  363. if len(end_time) > 0 {
  364. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  365. if err != nil {
  366. utils.ErrorLog(err.Error())
  367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  368. return
  369. }
  370. endTime = theTime.Unix()
  371. }
  372. adminUserInfo := c.GetAdminUserInfo()
  373. warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  374. if err == nil {
  375. c.ServeSuccessJSON(map[string]interface{}{
  376. "list": warehouseList,
  377. "total": total,
  378. })
  379. } else {
  380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  381. }
  382. }
  383. func (c *StockManagerApiController) GetWarehouseInfoList() {
  384. id, _ := c.GetInt64("id", 0)
  385. if id <= 0 {
  386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  387. return
  388. }
  389. warehousing, err := service.FindWarehousingById(id)
  390. if err != nil {
  391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  392. return
  393. }
  394. if warehousing.ID <= 0 {
  395. return
  396. }
  397. warehousingInfo, err := service.FindWarehousingInfoById(id)
  398. if err == nil {
  399. c.ServeSuccessJSON(map[string]interface{}{
  400. "info": warehousingInfo,
  401. "warehousing": warehousing,
  402. })
  403. } else {
  404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  405. }
  406. }
  407. func (c *StockManagerApiController) EditWarehouse() {
  408. warehousing_time := c.GetString("warehousing_time")
  409. id, _ := c.GetInt64("id", 0)
  410. types, _ := c.GetInt64("type", 0)
  411. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  412. dealer_id, _ := c.GetInt64("dealer_id", 0)
  413. if id == 0 {
  414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  415. return
  416. }
  417. ctime := time.Now().Unix()
  418. mtime := time.Now().Unix()
  419. adminUserInfo := c.GetAdminUserInfo()
  420. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  421. if parseDateErr != nil {
  422. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  424. return
  425. }
  426. warehouse, _ := service.FindWarehousingById(id)
  427. warehousing := models.Warehousing{
  428. WarehousingOrder: warehouse.WarehousingOrder,
  429. OrgId: adminUserInfo.CurrentOrgId,
  430. Modifier: adminUserInfo.AdminUser.Id,
  431. Mtime: mtime,
  432. Status: 1,
  433. WarehousingTime: warehousingDate.Unix(),
  434. Type: warehouse.Type,
  435. Dealer: dealer_id,
  436. Manufacturer: manufacturer_id,
  437. }
  438. service.EditWarehousing(warehousing)
  439. dataBody := make(map[string]interface{}, 0)
  440. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  441. if err != nil {
  442. utils.ErrorLog(err.Error())
  443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  444. return
  445. }
  446. var warehousingInfo []*models.WarehousingInfo
  447. var upDateWarehousingInfo []*models.WarehousingInfo
  448. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  449. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  450. if len(thisStockIn) > 0 {
  451. for _, item := range thisStockIn {
  452. items := item.(map[string]interface{})
  453. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  454. utils.ErrorLog("good_id")
  455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  456. return
  457. }
  458. good_id := int64(items["good_id"].(float64))
  459. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  460. utils.ErrorLog("good_type_id")
  461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  462. return
  463. }
  464. good_type_id := int64(items["good_type_id"].(float64))
  465. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  466. utils.ErrorLog("warehousing_count")
  467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  468. return
  469. }
  470. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  471. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  472. utils.ErrorLog("price")
  473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  474. return
  475. }
  476. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  477. total := float64(warehousing_count) * price
  478. var productDates int64
  479. var expiryDates int64
  480. fmt.Println()
  481. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  482. expiryDates = 0
  483. } else {
  484. if len(items["expiry_date"].(string)) == 0 {
  485. expiryDates = 0
  486. } else {
  487. expiryDate, _ := items["expiry_date"].(string)
  488. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  489. expiryDates = expiry_date.Unix()
  490. }
  491. }
  492. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  493. productDates = 0
  494. } else {
  495. if len(items["product_date"].(string)) == 0 {
  496. productDates = 0
  497. } else {
  498. productDate, _ := items["product_date"].(string)
  499. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  500. productDates = product_date.Unix()
  501. }
  502. }
  503. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  504. utils.ErrorLog("number")
  505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  506. return
  507. }
  508. number, _ := items["number"].(string)
  509. var remark string
  510. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  511. remark = ""
  512. } else {
  513. remark = items["remark"].(string)
  514. }
  515. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  516. utils.ErrorLog("id")
  517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  518. return
  519. }
  520. id := int64(items["id"].(float64))
  521. if id == 0 {
  522. warehouseInfo := &models.WarehousingInfo{
  523. WarehousingOrder: warehouse.WarehousingOrder,
  524. WarehousingId: warehouse.ID,
  525. GoodId: good_id,
  526. Number: number,
  527. GoodTypeId: good_type_id,
  528. ProductDate: productDates,
  529. ExpiryDate: expiryDates,
  530. WarehousingCount: warehousing_count,
  531. Price: price,
  532. TotalPrice: total,
  533. Status: 1,
  534. Ctime: ctime,
  535. Remark: remark,
  536. OrgId: adminUserInfo.CurrentOrgId,
  537. Type: types,
  538. Manufacturer: manufacturer_id,
  539. Dealer: dealer_id,
  540. }
  541. warehousingInfo = append(warehousingInfo, warehouseInfo)
  542. } else {
  543. warehouseInfo := &models.WarehousingInfo{
  544. ID: id,
  545. WarehousingOrder: warehouse.WarehousingOrder,
  546. WarehousingId: warehouse.ID,
  547. GoodId: good_id,
  548. Number: number,
  549. GoodTypeId: good_type_id,
  550. ProductDate: productDates,
  551. ExpiryDate: expiryDates,
  552. WarehousingCount: warehousing_count,
  553. Price: price,
  554. TotalPrice: total,
  555. Status: 1,
  556. Ctime: ctime,
  557. Remark: remark,
  558. OrgId: adminUserInfo.CurrentOrgId,
  559. Type: types,
  560. Manufacturer: manufacturer_id,
  561. Dealer: dealer_id,
  562. }
  563. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  564. }
  565. }
  566. }
  567. }
  568. var errs error
  569. if len(warehousingInfo) > 0 {
  570. errs = service.CreateWarehousingInfo(warehousingInfo)
  571. }
  572. if len(upDateWarehousingInfo) > 0 {
  573. for _, item := range upDateWarehousingInfo {
  574. errs = service.UpDateWarehousingInfo(item)
  575. }
  576. }
  577. if errs != nil {
  578. utils.ErrorLog(errs.Error())
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  580. return
  581. }
  582. c.ServeSuccessJSON(map[string]interface{}{
  583. "msg": "编辑成功",
  584. })
  585. }
  586. func (c *StockManagerApiController) DeleteWarehouse() {
  587. ids := c.GetString("ids")
  588. if len(ids) == 0 {
  589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  590. return
  591. }
  592. idArray := strings.Split(ids, ",")
  593. err := service.DeleteWarehouse(idArray)
  594. if err != nil {
  595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  596. } else {
  597. c.ServeSuccessJSON(map[string]interface{}{
  598. "msg": "删除成功",
  599. })
  600. }
  601. }
  602. func (c *StockManagerApiController) DeleteWarehouseInfo() {
  603. id, _ := c.GetInt64("id", 0)
  604. if id == 0 {
  605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  606. return
  607. }
  608. err := service.UpDateWarehouseStatus(id)
  609. if err != nil {
  610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  611. } else {
  612. c.ServeSuccessJSON(map[string]interface{}{
  613. "msg": "删除成功",
  614. })
  615. }
  616. }
  617. func (c *StockManagerApiController) CreateSalesReturn() {
  618. dealer_id, _ := c.GetInt64("dealer_id", 0)
  619. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  620. sales_return_time := c.GetString("time")
  621. types, _ := c.GetInt64("type", 0)
  622. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  623. if parseDateErr != nil {
  624. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  626. return
  627. }
  628. adminUserInfo := c.GetAdminUserInfo()
  629. operation_time := time.Now().Unix()
  630. creater := adminUserInfo.AdminUser.Id
  631. ctime := time.Now().Unix()
  632. timeStr := time.Now().Format("2006-01-02")
  633. timeArr := strings.Split(timeStr, "-")
  634. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  635. total = total + 1
  636. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  637. salesReturn := models.SalesReturn{
  638. OrderNumber: orderNumber,
  639. OperaTime: operation_time,
  640. OrgId: adminUserInfo.CurrentOrgId,
  641. Creater: creater,
  642. Ctime: ctime,
  643. Status: 1,
  644. ReturnTime: salesReturnDate.Unix(),
  645. Dealer: dealer_id,
  646. Manufacturer: manufacturer_id,
  647. Type: types,
  648. }
  649. service.AddSigleSalesReturn(&salesReturn)
  650. dataBody := make(map[string]interface{}, 0)
  651. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  652. if err != nil {
  653. utils.ErrorLog(err.Error())
  654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  655. return
  656. }
  657. var salesReturnInfos []*models.SalesReturnInfo
  658. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  659. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  660. if len(thisStockIn) > 0 {
  661. for _, item := range thisStockIn {
  662. items := item.(map[string]interface{})
  663. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  664. utils.ErrorLog("good_id")
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  666. return
  667. }
  668. good_id := int64(items["good_id"].(float64))
  669. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  670. utils.ErrorLog("good_type_id")
  671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  672. return
  673. }
  674. good_type_id := int64(items["good_type_id"].(float64))
  675. return_count, _ := items["return_count"].(string)
  676. if len(return_count) == 0 {
  677. utils.ErrorLog("len(return_count) == 0")
  678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  679. return
  680. }
  681. count, _ := strconv.ParseInt(return_count, 10, 64)
  682. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  683. total := float64(count) * price
  684. salesReturnInfo := &models.SalesReturnInfo{
  685. OrderNumber: salesReturn.OrderNumber,
  686. SalesReturnId: salesReturn.ID,
  687. GoodId: good_id,
  688. GoodTypeId: good_type_id,
  689. Count: count,
  690. Price: price,
  691. Total: total,
  692. Status: 1,
  693. Ctime: ctime,
  694. OrgId: adminUserInfo.CurrentOrgId,
  695. Type: types,
  696. Manufacturer: manufacturer_id,
  697. Dealer: dealer_id,
  698. }
  699. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  700. }
  701. }
  702. }
  703. errs := service.CreateSalesReturnInfo(salesReturnInfos)
  704. if errs != nil {
  705. utils.ErrorLog(errs.Error())
  706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  707. return
  708. }
  709. c.ServeSuccessJSON(map[string]interface{}{
  710. "msg": "退货成功",
  711. })
  712. }
  713. func (c *StockManagerApiController) GetSalesReturnList() {
  714. page, _ := c.GetInt64("page", -1)
  715. limit, _ := c.GetInt64("limit", -1)
  716. start_time := c.GetString("start_time")
  717. end_time := c.GetString("end_time")
  718. types, _ := c.GetInt64("type", 0)
  719. keywords := c.GetString("keywords")
  720. timeLayout := "2006-01-02"
  721. loc, _ := time.LoadLocation("Local")
  722. var startTime int64
  723. if len(start_time) > 0 {
  724. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  725. if err != nil {
  726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  727. return
  728. }
  729. startTime = theTime.Unix()
  730. }
  731. var endTime int64
  732. if len(end_time) > 0 {
  733. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  734. if err != nil {
  735. utils.ErrorLog(err.Error())
  736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  737. return
  738. }
  739. endTime = theTime.Unix()
  740. }
  741. adminUserInfo := c.GetAdminUserInfo()
  742. returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  743. if err == nil {
  744. c.ServeSuccessJSON(map[string]interface{}{
  745. "list": returnList,
  746. "total": total,
  747. })
  748. } else {
  749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  750. }
  751. }
  752. func (this *StockManagerApiController) DeleteSalesReturn() {
  753. ids := this.GetString("ids")
  754. if len(ids) == 0 {
  755. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  756. return
  757. }
  758. idArray := strings.Split(ids, ",")
  759. err := service.DeleteSalesReturn(idArray)
  760. if err != nil {
  761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  762. } else {
  763. this.ServeSuccessJSON(map[string]interface{}{
  764. "msg": "删除成功",
  765. })
  766. }
  767. }
  768. func (this *StockManagerApiController) DeleteSalesReturnInfo() {
  769. id, _ := this.GetInt64("id", 0)
  770. fmt.Println(id)
  771. if id == 0 {
  772. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  773. return
  774. }
  775. err := service.UpDateSaleReturnStatus(id)
  776. if err != nil {
  777. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  778. } else {
  779. this.ServeSuccessJSON(map[string]interface{}{
  780. "msg": "删除成功",
  781. })
  782. }
  783. }
  784. func (this *StockManagerApiController) GetSalesReturnInfoList() {
  785. id, _ := this.GetInt64("id", 0)
  786. list, _ := service.FindAllSalesReturnInfoById(id)
  787. salesReturn, _ := service.FindAllSalesReturnById(id)
  788. this.ServeSuccessJSON(map[string]interface{}{
  789. "list": list,
  790. "salesReturn": salesReturn,
  791. })
  792. }
  793. func (c *StockManagerApiController) EditReturnInfo() {
  794. return_time := c.GetString("return_time")
  795. id, _ := c.GetInt64("id", 0)
  796. types, _ := c.GetInt64("type", 0)
  797. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  798. dealer_id, _ := c.GetInt64("dealer_id", 0)
  799. if id == 0 {
  800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  801. return
  802. }
  803. ctime := time.Now().Unix()
  804. mtime := time.Now().Unix()
  805. adminUserInfo := c.GetAdminUserInfo()
  806. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  807. if parseDateErr != nil {
  808. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  810. return
  811. }
  812. salesReturns, _ := service.FindSalesReturnById(id)
  813. sales := models.SalesReturn{
  814. ID: salesReturns.ID,
  815. Mtime: mtime,
  816. ReturnTime: returnDate.Unix(),
  817. Manufacturer: manufacturer_id,
  818. Dealer: dealer_id,
  819. }
  820. service.EditSaleReturn(sales)
  821. dataBody := make(map[string]interface{}, 0)
  822. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  823. if err != nil {
  824. utils.ErrorLog(err.Error())
  825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  826. return
  827. }
  828. var returnInfos []*models.SalesReturnInfo
  829. var upDateReturnInfos []*models.SalesReturnInfo
  830. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  831. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  832. if len(thisStockIn) > 0 {
  833. for _, item := range thisStockIn {
  834. items := item.(map[string]interface{})
  835. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  836. utils.ErrorLog("good_id")
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  838. return
  839. }
  840. good_id := int64(items["good_id"].(float64))
  841. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  842. utils.ErrorLog("good_type_id")
  843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  844. return
  845. }
  846. good_type_id := int64(items["good_type_id"].(float64))
  847. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  848. utils.ErrorLog("count")
  849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  850. return
  851. }
  852. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  853. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  854. utils.ErrorLog("id")
  855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  856. return
  857. }
  858. id := int64(items["id"].(float64))
  859. if id == 0 {
  860. returnInfo := &models.SalesReturnInfo{
  861. GoodId: good_id,
  862. GoodTypeId: good_type_id,
  863. Count: count,
  864. Status: 1,
  865. Ctime: ctime,
  866. OrgId: adminUserInfo.CurrentOrgId,
  867. OrderNumber: sales.OrderNumber,
  868. SalesReturnId: sales.ID,
  869. Mtime: time.Now().Unix(),
  870. Type: types,
  871. Manufacturer: manufacturer_id,
  872. Dealer: dealer_id,
  873. }
  874. returnInfos = append(returnInfos, returnInfo)
  875. } else {
  876. returnInfo := &models.SalesReturnInfo{
  877. ID: id,
  878. GoodId: good_id,
  879. GoodTypeId: good_type_id,
  880. Count: count,
  881. Status: 1,
  882. Ctime: ctime,
  883. OrgId: adminUserInfo.CurrentOrgId,
  884. OrderNumber: sales.OrderNumber,
  885. SalesReturnId: sales.ID,
  886. Mtime: time.Now().Unix(),
  887. Type: types,
  888. Manufacturer: manufacturer_id,
  889. Dealer: dealer_id,
  890. }
  891. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  892. }
  893. }
  894. }
  895. }
  896. var errs error
  897. if len(returnInfos) > 0 {
  898. errs = service.CreateSalesReturnInfo(returnInfos)
  899. }
  900. if len(upDateReturnInfos) > 0 {
  901. for _, item := range upDateReturnInfos {
  902. errs = service.UpDateSalesReturnInfo(item)
  903. }
  904. }
  905. if errs != nil {
  906. utils.ErrorLog(errs.Error())
  907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  908. return
  909. }
  910. c.ServeSuccessJSON(map[string]interface{}{
  911. "msg": "编辑成功",
  912. })
  913. }
  914. func (c *StockManagerApiController) CreateWarehouseOut() {
  915. dealer_id, _ := c.GetInt64("dealer_id", 0)
  916. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  917. types, _ := c.GetInt64("type", 0)
  918. ctime := time.Now().Unix()
  919. adminUserInfo := c.GetAdminUserInfo()
  920. warehousing_out_time := c.GetString("warehousing_out_time")
  921. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  922. if parseDateErr != nil {
  923. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  925. return
  926. }
  927. timeStr := time.Now().Format("2006-01-02")
  928. timeArr := strings.Split(timeStr, "-")
  929. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  930. total = total + 1
  931. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  932. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  933. number = number + total
  934. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  935. operation_time := time.Now().Unix()
  936. creater := adminUserInfo.AdminUser.Id
  937. warehouseOut := models.WarehouseOut{
  938. WarehouseOutOrderNumber: warehousing_out_order,
  939. OperationTime: operation_time,
  940. OrgId: adminUserInfo.CurrentOrgId,
  941. Creater: creater,
  942. Ctime: ctime,
  943. Status: 1,
  944. WarehouseOutTime: warehousingOutDate.Unix(),
  945. Dealer: dealer_id,
  946. Manufacturer: manufacturer_id,
  947. Type: types,
  948. }
  949. service.AddSigleWarehouseOut(&warehouseOut)
  950. dataBody := make(map[string]interface{}, 0)
  951. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  952. if err != nil {
  953. utils.ErrorLog(err.Error())
  954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  955. return
  956. }
  957. var warehousingOutInfo []*models.WarehouseOutInfo
  958. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  959. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  960. if len(thisStockIn) > 0 {
  961. for _, item := range thisStockIn {
  962. items := item.(map[string]interface{})
  963. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  964. utils.ErrorLog("good_id")
  965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  966. return
  967. }
  968. good_id := int64(items["good_id"].(float64))
  969. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  970. utils.ErrorLog("good_type_id")
  971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  972. return
  973. }
  974. good_type_id := int64(items["good_type_id"].(float64))
  975. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  976. utils.ErrorLog("count")
  977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  978. return
  979. }
  980. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  981. utils.ErrorLog("price")
  982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  983. return
  984. }
  985. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  986. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  987. total := float64(count) * price
  988. remark := items["remark"].(string)
  989. warehouseOutInfo := &models.WarehouseOutInfo{
  990. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  991. WarehouseOutId: warehouseOut.ID,
  992. GoodId: good_id,
  993. GoodTypeId: good_type_id,
  994. Count: count,
  995. Price: price,
  996. TotalPrice: total,
  997. Status: 1,
  998. Ctime: ctime,
  999. Remark: remark,
  1000. OrgId: adminUserInfo.CurrentOrgId,
  1001. Type: types,
  1002. Manufacturer: manufacturer_id,
  1003. Dealer: dealer_id,
  1004. }
  1005. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1006. }
  1007. }
  1008. }
  1009. errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
  1010. info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
  1011. if errs != nil {
  1012. utils.ErrorLog(errs.Error())
  1013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1014. return
  1015. }
  1016. c.ServeSuccessJSON(map[string]interface{}{
  1017. "msg": "出库成功",
  1018. "info": info,
  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["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  2284. utils.ErrorLog("drug_alias")
  2285. return
  2286. }
  2287. drug_alias, _ := goodNameM["drug_alias"].(string)
  2288. drug.DrugAlias = drug_alias
  2289. drug_spec, _ := goodNameM["drug_spec"].(string)
  2290. if len(drug_spec) == 0 { //名字为空则生成一条导入错误日志
  2291. err_log := models.ExportErrLog{
  2292. LogType: 4,
  2293. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2294. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品规格不能为空",
  2295. Status: 1,
  2296. CreateTime: time.Now().Unix(),
  2297. UpdateTime: time.Now().Unix(),
  2298. ExportTime: time.Now().Unix(),
  2299. }
  2300. service.CreateExportErrLog(&err_log)
  2301. continue
  2302. }
  2303. drug.DrugSpec = drug_spec
  2304. drug_type := goodNameM["drug_type"].(string)
  2305. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  2306. err_log := models.ExportErrLog{
  2307. LogType: 4,
  2308. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2309. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
  2310. Status: 1,
  2311. CreateTime: time.Now().Unix(),
  2312. UpdateTime: time.Now().Unix(),
  2313. ExportTime: time.Now().Unix(),
  2314. }
  2315. service.CreateExportErrLog(&err_log)
  2316. continue
  2317. }
  2318. var drug_type_id int64
  2319. var drugType = "药品类型"
  2320. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  2321. if len(drug_type) != 0 {
  2322. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  2323. if errcodes == gorm.ErrRecordNotFound {
  2324. //获取该型号最后一条数据型号
  2325. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  2326. dataconfig := models.DictDataconfig{
  2327. ParentId: drugconfig.ID,
  2328. Module: "system",
  2329. OrgId: orgId,
  2330. Name: drug_type,
  2331. FieldName: "",
  2332. Value: config.Value + 1,
  2333. CreatedTime: "",
  2334. UpdatedTime: "",
  2335. CreateUserId: adminUser.AdminUser.Id,
  2336. Status: 1,
  2337. Remark: "",
  2338. DeleteIdSystem: 0,
  2339. Title: "",
  2340. Content: "",
  2341. Order: 0,
  2342. Code: "",
  2343. }
  2344. service.CreatedDicConfig(&dataconfig)
  2345. }
  2346. }
  2347. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  2348. for _, it := range drugTypeList {
  2349. if drug_type == it.Name {
  2350. drug_type_id = int64(it.Value)
  2351. }
  2352. }
  2353. drug.DrugType = drug_type_id
  2354. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  2355. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  2356. err_log := models.ExportErrLog{
  2357. LogType: 4,
  2358. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2359. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  2360. Status: 1,
  2361. CreateTime: time.Now().Unix(),
  2362. UpdateTime: time.Now().Unix(),
  2363. ExportTime: time.Now().Unix(),
  2364. }
  2365. service.CreateExportErrLog(&err_log)
  2366. continue
  2367. }
  2368. drug.DrugStockLimit = drug_stock_limit
  2369. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  2370. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  2371. err_log := models.ExportErrLog{
  2372. LogType: 4,
  2373. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2374. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  2375. Status: 1,
  2376. CreateTime: time.Now().Unix(),
  2377. UpdateTime: time.Now().Unix(),
  2378. ExportTime: time.Now().Unix(),
  2379. }
  2380. service.CreateExportErrLog(&err_log)
  2381. continue
  2382. }
  2383. drug.DrugOriginPlace = drug_origin_place
  2384. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  2385. if len(drug_dosage_form) == 0 {
  2386. err_log := models.ExportErrLog{
  2387. LogType: 4,
  2388. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2389. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  2390. Status: 1,
  2391. CreateTime: time.Now().Unix(),
  2392. UpdateTime: time.Now().Unix(),
  2393. ExportTime: time.Now().Unix(),
  2394. }
  2395. service.CreateExportErrLog(&err_log)
  2396. continue
  2397. }
  2398. var drug_dosage = "药品剂型"
  2399. var drug_dosage_form_id int64
  2400. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  2401. if len(drug_dosage_form) != 0 {
  2402. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  2403. if errcodess == gorm.ErrRecordNotFound {
  2404. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  2405. dataconfig := models.DictDataconfig{
  2406. ParentId: drugDosageconfig.ID,
  2407. Module: "system",
  2408. OrgId: orgId,
  2409. Name: drug_dosage_form,
  2410. FieldName: "",
  2411. Value: configOne.Value + 1,
  2412. CreatedTime: "",
  2413. UpdatedTime: "",
  2414. CreateUserId: adminUser.AdminUser.Id,
  2415. Status: 1,
  2416. Remark: "",
  2417. DeleteIdSystem: 0,
  2418. Title: "",
  2419. Content: "",
  2420. Order: 0,
  2421. Code: "",
  2422. }
  2423. service.CreatedDicConfig(&dataconfig)
  2424. }
  2425. }
  2426. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  2427. for _, it := range drugDosageList {
  2428. if drug_dosage_form == it.Name {
  2429. drug_dosage_form_id = int64(it.Value)
  2430. }
  2431. }
  2432. drug.DrugDosageForm = drug_dosage_form_id
  2433. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  2434. var medical_insurance_level_id int64
  2435. if len(medical_insurance_level) == 0 { //名字为空则生成一条导入错误日志
  2436. err_log := models.ExportErrLog{
  2437. LogType: 4,
  2438. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2439. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  2440. Status: 1,
  2441. CreateTime: time.Now().Unix(),
  2442. UpdateTime: time.Now().Unix(),
  2443. ExportTime: time.Now().Unix(),
  2444. }
  2445. service.CreateExportErrLog(&err_log)
  2446. continue
  2447. }
  2448. var medicalInsuranceName = "医保等级"
  2449. medicalInsuranceConfig, _ := service.GetDrugDataConfig(0, medicalInsuranceName)
  2450. if len(medical_insurance_level) != 0 {
  2451. _, errcodemedical := service.IsExistDicConfig(medicalInsuranceConfig.ID, medical_insurance_level, orgId)
  2452. if errcodemedical == gorm.ErrRecordNotFound {
  2453. medConfig, _ := service.GetLastDicConfig(medicalInsuranceConfig.ID, orgId)
  2454. dataconfig := models.DictDataconfig{
  2455. ParentId: medicalInsuranceConfig.ID,
  2456. Module: "system",
  2457. OrgId: orgId,
  2458. Name: medical_insurance_level,
  2459. FieldName: "",
  2460. Value: medConfig.Value + 1,
  2461. CreatedTime: "",
  2462. UpdatedTime: "",
  2463. CreateUserId: adminUser.AdminUser.Id,
  2464. Status: 1,
  2465. Remark: "",
  2466. DeleteIdSystem: 0,
  2467. Title: "",
  2468. Content: "",
  2469. Order: 0,
  2470. Code: "",
  2471. }
  2472. service.CreatedDicConfig(&dataconfig)
  2473. }
  2474. }
  2475. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceConfig.ID, orgId)
  2476. for _, it := range medicalInsuranceList {
  2477. if medical_insurance_level == it.Name {
  2478. medical_insurance_level_id = int64(it.Value)
  2479. }
  2480. }
  2481. drug.MedicalInsuranceLevel = medical_insurance_level_id
  2482. max_unit_id := goodNameM["max_unit"].(string)
  2483. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  2484. err_log := models.ExportErrLog{
  2485. LogType: 4,
  2486. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2487. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的最大不能为空",
  2488. Status: 1,
  2489. CreateTime: time.Now().Unix(),
  2490. UpdateTime: time.Now().Unix(),
  2491. ExportTime: time.Now().Unix(),
  2492. }
  2493. service.CreateExportErrLog(&err_log)
  2494. continue
  2495. }
  2496. drug.MaxUnit = max_unit_id
  2497. min_unit := goodNameM["min_unit"].(string)
  2498. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  2499. err_log := models.ExportErrLog{
  2500. LogType: 4,
  2501. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2502. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的最小单位不能为空",
  2503. Status: 1,
  2504. CreateTime: time.Now().Unix(),
  2505. UpdateTime: time.Now().Unix(),
  2506. ExportTime: time.Now().Unix(),
  2507. }
  2508. service.CreateExportErrLog(&err_log)
  2509. continue
  2510. }
  2511. drug.MinUnit = min_unit
  2512. unit_matrixing := goodNameM["unit_matrixing"].(string)
  2513. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  2514. err_log := models.ExportErrLog{
  2515. LogType: 4,
  2516. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2517. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位换算不能为空",
  2518. Status: 1,
  2519. CreateTime: time.Now().Unix(),
  2520. UpdateTime: time.Now().Unix(),
  2521. ExportTime: time.Now().Unix(),
  2522. }
  2523. service.CreateExportErrLog(&err_log)
  2524. continue
  2525. }
  2526. drug.UnitMatrixing = unit_matrixing
  2527. retail_prices := goodNameM["retail_price"].(string)
  2528. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  2529. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  2530. err_log := models.ExportErrLog{
  2531. LogType: 4,
  2532. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2533. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的零售价不能为空",
  2534. Status: 1,
  2535. CreateTime: time.Now().Unix(),
  2536. UpdateTime: time.Now().Unix(),
  2537. ExportTime: time.Now().Unix(),
  2538. }
  2539. service.CreateExportErrLog(&err_log)
  2540. continue
  2541. }
  2542. drug.RetailPrice = retail_price
  2543. last_prices := goodNameM["last_price"].(string)
  2544. last_price, _ := strconv.ParseFloat(last_prices, 64)
  2545. if last_price <= 0 { //名字为空则生成一条导入错误日志
  2546. err_log := models.ExportErrLog{
  2547. LogType: 4,
  2548. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2549. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的上次进价不能为空",
  2550. Status: 1,
  2551. CreateTime: time.Now().Unix(),
  2552. UpdateTime: time.Now().Unix(),
  2553. ExportTime: time.Now().Unix(),
  2554. }
  2555. service.CreateExportErrLog(&err_log)
  2556. continue
  2557. }
  2558. drug.LastPrice = last_price
  2559. drug_classify := goodNameM["drug_classify"].(string)
  2560. if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
  2561. err_log := models.ExportErrLog{
  2562. LogType: 4,
  2563. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2564. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
  2565. Status: 1,
  2566. CreateTime: time.Now().Unix(),
  2567. UpdateTime: time.Now().Unix(),
  2568. ExportTime: time.Now().Unix(),
  2569. }
  2570. service.CreateExportErrLog(&err_log)
  2571. continue
  2572. }
  2573. var drugClassify = "药物分类"
  2574. var drug_classify_id int64
  2575. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  2576. if len(drug_classify) != 0 {
  2577. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  2578. if errcodesClass == gorm.ErrRecordNotFound {
  2579. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  2580. dataconfig := models.DictDataconfig{
  2581. ParentId: drugClassifyConfig.ID,
  2582. Module: "system",
  2583. OrgId: orgId,
  2584. Name: drug_classify,
  2585. FieldName: "",
  2586. Value: drugClassConfig.Value + 1,
  2587. CreatedTime: "",
  2588. UpdatedTime: "",
  2589. CreateUserId: adminUser.AdminUser.Id,
  2590. Status: 1,
  2591. Remark: "",
  2592. DeleteIdSystem: 0,
  2593. Title: "",
  2594. Content: "",
  2595. Order: 0,
  2596. Code: "",
  2597. }
  2598. service.CreatedDicConfig(&dataconfig)
  2599. }
  2600. }
  2601. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  2602. for _, it := range drugClassList {
  2603. if drug_classify == it.Name {
  2604. drug_classify_id = int64(it.Value)
  2605. }
  2606. }
  2607. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  2608. manufacturer := goodNameM["manufacturer"].(string)
  2609. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  2610. err_log := models.ExportErrLog{
  2611. LogType: 4,
  2612. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2613. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  2614. Status: 1,
  2615. CreateTime: time.Now().Unix(),
  2616. UpdateTime: time.Now().Unix(),
  2617. ExportTime: time.Now().Unix(),
  2618. }
  2619. service.CreateExportErrLog(&err_log)
  2620. continue
  2621. }
  2622. if len(manufacturer) != 0 {
  2623. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  2624. if errcodema == gorm.ErrRecordNotFound {
  2625. manufactur := models.Manufacturer{
  2626. OrgId: orgId,
  2627. Status: 1,
  2628. ManufacturerName: manufacturer,
  2629. Ctime: time.Now().Unix(),
  2630. Creater: adminUser.AdminUser.Id,
  2631. }
  2632. service.CreateManufacturer(&manufactur)
  2633. }
  2634. }
  2635. var manufacturer_id int64
  2636. manufacturList, _ := service.GetAllManufacturerList(orgId)
  2637. for _, it := range manufacturList {
  2638. if manufacturer == it.ManufacturerName {
  2639. manufacturer_id = it.ID
  2640. }
  2641. }
  2642. drug.Manufacturer = manufacturer_id
  2643. dealer := goodNameM["dealer"].(string)
  2644. if len(dealer) != 0 {
  2645. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  2646. if errcodesdealer == gorm.ErrRecordNotFound {
  2647. dealerconfig := models.Dealer{
  2648. DealerName: dealer,
  2649. Status: 1,
  2650. OrgId: orgId,
  2651. Ctime: time.Now().Unix(),
  2652. Creater: adminUser.AdminUser.Id,
  2653. }
  2654. service.CreateDealer(&dealerconfig)
  2655. }
  2656. }
  2657. var dealer_id int64
  2658. dealerList, _ := service.GetAllDealerList(orgId)
  2659. for _, it := range dealerList {
  2660. if dealer == it.DealerName {
  2661. dealer_id = it.ID
  2662. }
  2663. }
  2664. drug.Dealer = dealer_id
  2665. pinyin := goodNameM["pinyin"].(string)
  2666. drug.Pinyin = pinyin
  2667. wubi := goodNameM["wubi"].(string)
  2668. drug.Wubi = wubi
  2669. drug_alias_pinyin := goodNameM["drug_alias_pinyin"].(string)
  2670. drug.DrugAliasPinyin = drug_alias_pinyin
  2671. statistics_category := goodNameM["statistics_category"].(string)
  2672. var statisticsCategory = "统计分类"
  2673. var statistics_category_id int64
  2674. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  2675. if len(statistics_category) != 0 {
  2676. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  2677. if errcodestatistc == gorm.ErrRecordNotFound {
  2678. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  2679. dataconfig := models.DictDataconfig{
  2680. ParentId: statistcConfig.ID,
  2681. Module: "system",
  2682. OrgId: orgId,
  2683. Name: statistics_category,
  2684. FieldName: "",
  2685. Value: staConfig.Value + 1,
  2686. CreatedTime: "",
  2687. UpdatedTime: "",
  2688. CreateUserId: adminUser.AdminUser.Id,
  2689. Status: 1,
  2690. Remark: "",
  2691. DeleteIdSystem: 0,
  2692. Title: "",
  2693. Content: "",
  2694. Order: 0,
  2695. Code: "",
  2696. }
  2697. service.CreatedDicConfig(&dataconfig)
  2698. }
  2699. }
  2700. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  2701. for _, it := range statisticsCategoryList {
  2702. if statistics_category == it.Name {
  2703. statistics_category_id = int64(it.Value)
  2704. }
  2705. }
  2706. drug.StatisticsCategory = statistics_category_id
  2707. number := goodNameM["number"].(string)
  2708. drug.Number = number
  2709. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  2710. drug.HospApprFlag = hosp_appr_flag
  2711. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  2712. drug.MedicalInsuranceNumber = medical_insurance_number
  2713. pharmacology_category := goodNameM["pharmacology_category"].(string)
  2714. var pharmacology = "药理分类"
  2715. var pharmacology_category_id int64
  2716. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  2717. if len(pharmacology_category) != 0 {
  2718. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  2719. if errcodespharmacology == gorm.ErrRecordNotFound {
  2720. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  2721. dataconfig := models.DictDataconfig{
  2722. ParentId: pharmacologyConfig.ID,
  2723. Module: "system",
  2724. OrgId: orgId,
  2725. Name: pharmacology_category,
  2726. FieldName: "",
  2727. Value: dicConfig.Value + 1,
  2728. CreatedTime: "",
  2729. UpdatedTime: "",
  2730. CreateUserId: adminUser.AdminUser.Id,
  2731. Status: 1,
  2732. Remark: "",
  2733. DeleteIdSystem: 0,
  2734. Title: "",
  2735. Content: "",
  2736. Order: 0,
  2737. Code: "",
  2738. }
  2739. service.CreatedDicConfig(&dataconfig)
  2740. }
  2741. }
  2742. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  2743. for _, it := range pharmacologyList {
  2744. if pharmacology_category == it.Name {
  2745. pharmacology_category_id = int64(it.Value)
  2746. }
  2747. }
  2748. drug.PharmacologyCategory = pharmacology_category_id
  2749. code := goodNameM["code"].(string)
  2750. drug.Code = code
  2751. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  2752. drug.IsSpecialDiseases = is_special_diseases
  2753. is_record := int64(goodNameM["is_record"].(float64))
  2754. drug.IsRecord = is_record
  2755. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  2756. drug.PrescriptionMark = prescription_mark
  2757. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  2758. drug.SocialSecurityDirectoryCode = social_security_directory_code
  2759. record_date := goodNameM["record_date"].(string)
  2760. timeLayout := "2006-01-02"
  2761. loc, _ := time.LoadLocation("Local")
  2762. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2763. drug.RecordDate = theTime.Unix()
  2764. drug_remark := goodNameM["drug_remark"].(string)
  2765. drug.DrugRemark = drug_remark
  2766. drug_status := goodNameM["drug_status"].(string)
  2767. drug.DrugStatus = drug_status
  2768. limit_remark := goodNameM["limit_remark"].(string)
  2769. drug.LimitRemark = limit_remark
  2770. drug_alias_wubi := goodNameM["drug_alias_wubi"].(string)
  2771. drug.DrugAliasWubi = drug_alias_wubi
  2772. drug_control := goodNameM["drug_control"].(string)
  2773. var drugControl = "开药控制"
  2774. var drug_control_id int64
  2775. drugContorlConfig, _ := service.GetDrugDataConfig(0, drugControl)
  2776. if len(drug_control) != 0 {
  2777. _, errcodesdrugcontrol := service.IsExistDicConfig(drugContorlConfig.ID, drug_control, orgId)
  2778. if errcodesdrugcontrol == gorm.ErrRecordNotFound {
  2779. drugContorlConfigOne, _ := service.GetLastDicConfig(drugContorlConfig.ID, orgId)
  2780. dataconfig := models.DictDataconfig{
  2781. ParentId: drugContorlConfig.ID,
  2782. Module: "system",
  2783. OrgId: orgId,
  2784. Name: drug_control,
  2785. FieldName: "",
  2786. Value: drugContorlConfigOne.Value + 1,
  2787. CreatedTime: "",
  2788. UpdatedTime: "",
  2789. CreateUserId: adminUser.AdminUser.Id,
  2790. Status: 1,
  2791. Remark: "",
  2792. DeleteIdSystem: 0,
  2793. Title: "",
  2794. Content: "",
  2795. Order: 0,
  2796. Code: "",
  2797. }
  2798. service.CreatedDicConfig(&dataconfig)
  2799. }
  2800. }
  2801. drugContorlList, _ := service.GetParentDataConfig(drugContorlConfig.ID, orgId)
  2802. for _, it := range drugContorlList {
  2803. if drug_control == it.Name {
  2804. drug_control_id = int64(it.Value)
  2805. }
  2806. }
  2807. drug.DrugControl = drug_control_id
  2808. drug_category := goodNameM["drug_category"].(string)
  2809. var drugCategory = "药品类别"
  2810. var drug_category_id int64
  2811. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  2812. if len(drug_category) != 0 {
  2813. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  2814. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  2815. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  2816. dataconfig := models.DictDataconfig{
  2817. ParentId: drugCategoryConfig.ID,
  2818. Module: "system",
  2819. OrgId: orgId,
  2820. Name: drug_category,
  2821. FieldName: "",
  2822. Value: drugCategoryConfigSix.Value + 1,
  2823. CreatedTime: "",
  2824. UpdatedTime: "",
  2825. CreateUserId: adminUser.AdminUser.Id,
  2826. Status: 1,
  2827. Remark: "",
  2828. DeleteIdSystem: 0,
  2829. Title: "",
  2830. Content: "",
  2831. Order: 0,
  2832. Code: "",
  2833. }
  2834. service.CreatedDicConfig(&dataconfig)
  2835. }
  2836. }
  2837. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  2838. fmt.Println("drugCategoryList", drugCategoryList)
  2839. for _, it := range drugCategoryList {
  2840. if drug_category == it.Name {
  2841. drug_category_id = int64(it.Value)
  2842. }
  2843. }
  2844. drug.DrugCategory = drug_category_id
  2845. drug_dose := goodNameM["drug_dose"].(string)
  2846. if len(drug_dose) == 0 {
  2847. err_log := models.ExportErrLog{
  2848. LogType: 4,
  2849. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2850. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  2851. Status: 1,
  2852. CreateTime: time.Now().Unix(),
  2853. UpdateTime: time.Now().Unix(),
  2854. ExportTime: time.Now().Unix(),
  2855. }
  2856. service.CreateExportErrLog(&err_log)
  2857. continue
  2858. }
  2859. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  2860. drug.DrugDose = drugDoses
  2861. var units = "单位"
  2862. var unit_id int64
  2863. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  2864. if len(drugDoseUnit) == 0 {
  2865. err_log := models.ExportErrLog{
  2866. LogType: 4,
  2867. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2868. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  2869. Status: 1,
  2870. CreateTime: time.Now().Unix(),
  2871. UpdateTime: time.Now().Unix(),
  2872. ExportTime: time.Now().Unix(),
  2873. }
  2874. service.CreateExportErrLog(&err_log)
  2875. continue
  2876. }
  2877. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  2878. if len(drugDoseUnit) != 0 {
  2879. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  2880. if errcodedataconfig == gorm.ErrRecordNotFound {
  2881. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  2882. dataconfig := models.Dataconfig{
  2883. ParentId: dataConfig.ID,
  2884. Module: "hemodialysis",
  2885. OrgId: orgId,
  2886. Name: drugDoseUnit,
  2887. FieldName: "",
  2888. Value: childConfig.Value + 1,
  2889. CreatedTime: "",
  2890. UpdatedTime: "",
  2891. CreateUserId: adminUser.AdminUser.Id,
  2892. Status: 1,
  2893. Remark: "",
  2894. DeleteIdSystem: 0,
  2895. Title: "",
  2896. Content: "",
  2897. Order: 0,
  2898. Code: "",
  2899. FieldType: 0,
  2900. }
  2901. service.CreateDataConfig(&dataconfig)
  2902. }
  2903. }
  2904. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  2905. for _, it := range list {
  2906. if drugDoseUnit == it.Name {
  2907. unit_id = int64(it.Value)
  2908. }
  2909. }
  2910. drug.DrugDoseUnit = unit_id
  2911. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  2912. drug.LmtUsedFlag = lmt_used_flags
  2913. drugList = append(drugList, &drug)
  2914. }
  2915. export_time := time.Now().Unix()
  2916. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2917. if len(drugList) > 0 {
  2918. for _, item := range drugList {
  2919. goodInfo := models.BaseDrugLib{
  2920. DrugName: item.DrugName,
  2921. DrugAlias: item.DrugAlias,
  2922. DrugSpec: item.DrugSpec,
  2923. DrugType: item.DrugType,
  2924. DrugStockLimit: item.DrugStockLimit,
  2925. DrugOriginPlace: item.DrugOriginPlace,
  2926. DrugDosageForm: item.DrugDosageForm,
  2927. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  2928. MaxUnit: item.MaxUnit,
  2929. MinUnit: item.MinUnit,
  2930. UnitMatrixing: item.UnitMatrixing,
  2931. RetailPrice: item.RetailPrice,
  2932. LastPrice: item.LastPrice,
  2933. DrugClassify: item.DrugClassify,
  2934. Manufacturer: item.Manufacturer,
  2935. Dealer: item.Dealer,
  2936. OrgId: orgId,
  2937. Status: 1,
  2938. Ctime: time.Now().Unix(),
  2939. Pinyin: item.Pinyin,
  2940. Wubi: item.Wubi,
  2941. DrugAliasPinyin: item.DrugAliasPinyin,
  2942. DrugAliasWubi: item.DrugAliasWubi,
  2943. DrugControl: item.DrugControl,
  2944. Number: item.Number,
  2945. HospApprFlag: item.HospApprFlag,
  2946. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  2947. PharmacologyCategory: item.PharmacologyCategory,
  2948. StatisticsCategory: item.StatisticsCategory,
  2949. Code: item.Code,
  2950. IsSpecialDiseases: item.IsSpecialDiseases,
  2951. IsRecord: item.IsRecord,
  2952. PrescriptionMark: item.PrescriptionMark,
  2953. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  2954. RecordDate: item.RecordDate,
  2955. DrugRemark: item.DrugRemark,
  2956. DrugStatus: item.DrugStatus,
  2957. LimitRemark: item.LimitRemark,
  2958. DrugCategory: item.DrugCategory,
  2959. DrugDose: item.DrugDose,
  2960. DrugDoseUnit: item.DrugDoseUnit,
  2961. LmtUsedFlag: item.LmtUsedFlag,
  2962. }
  2963. //查询同种药品同种规格是否存在
  2964. _, drugerror := service.IsExistDrugByName(item.DrugName, item.DrugSpec, orgId)
  2965. if drugerror == gorm.ErrRecordNotFound {
  2966. service.CreateDrugsInfomation(&goodInfo)
  2967. } else if drugerror == nil {
  2968. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  2969. }
  2970. log := models.ExportLog{
  2971. LogType: 4,
  2972. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2973. TotalNum: int64(len(total_goods)),
  2974. FailNum: int64(len(errLogs)),
  2975. SuccessNum: int64(len(drugList)),
  2976. CreateTime: time.Now().Unix(),
  2977. UpdateTime: time.Now().Unix(),
  2978. ExportTime: export_time,
  2979. Status: 1,
  2980. }
  2981. service.CreateExportLog(&log)
  2982. this.ServeSuccessJSON(map[string]interface{}{
  2983. "msg": "导入成功",
  2984. "total_num": len(total_goods),
  2985. "success_num": len(drugList),
  2986. "fail_num": int64(len(errLogs)),
  2987. })
  2988. }
  2989. } else {
  2990. log := models.ExportLog{
  2991. LogType: 4,
  2992. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2993. TotalNum: int64(len(total_goods)),
  2994. FailNum: int64(len(errLogs)),
  2995. SuccessNum: int64(len(drugList)),
  2996. CreateTime: time.Now().Unix(),
  2997. UpdateTime: time.Now().Unix(),
  2998. ExportTime: export_time,
  2999. Status: 1,
  3000. }
  3001. service.CreateExportLog(&log)
  3002. this.ServeSuccessJSON(map[string]interface{}{
  3003. "msg": "导入成功",
  3004. "total_num": len(total_goods),
  3005. "success_num": len(drugList),
  3006. "fail_num": int64(len(errLogs)),
  3007. })
  3008. }
  3009. }
  3010. func (this *StockManagerApiController) GetInitializtion() {
  3011. orgId := this.GetAdminUserInfo().CurrentOrgId
  3012. var drugCategory = "药品类别"
  3013. var drugType = "药品类型"
  3014. var drugDosageForm = "药品剂型"
  3015. var medicalInsuranceLevel = "医保等级"
  3016. var drugControl = "开药控制"
  3017. var drugClassify = "药物分类"
  3018. var statisticsCategory = "统计分类"
  3019. var pharmacologyCategory = "药理分类"
  3020. var goodKind = "耗材种类"
  3021. var tubeColor = "试管颜色"
  3022. var costClassify = "费用类别"
  3023. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3024. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3025. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  3026. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  3027. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  3028. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  3029. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  3030. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  3031. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  3032. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  3033. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  3034. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  3035. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3036. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  3037. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  3038. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  3039. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  3040. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  3041. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  3042. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  3043. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  3044. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  3045. this.ServeSuccessJSON(map[string]interface{}{
  3046. "drugCategoryList": drugCategoryList,
  3047. "drugTypeList": drugTypeList,
  3048. "drugDosageFormList": drugDosageFormList,
  3049. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  3050. "drugControlList": drugControlList,
  3051. "drugClassifyList": drugClassifyList,
  3052. "statisticsCategoryList": statisticsCategoryList,
  3053. "pharmacologyCategoryList": pharmacologyCategoryList,
  3054. "goodKindList": goodKindList,
  3055. "tubeColorList": tubeColorList,
  3056. "costClassifyList": costClassifyList,
  3057. })
  3058. }
  3059. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  3060. adminUserInfo := this.GetAdminUserInfo()
  3061. orgId := adminUserInfo.CurrentOrgId
  3062. list, _ := service.GetWarehouseOrderInfoList(orgId)
  3063. this.ServeSuccessJSON(map[string]interface{}{
  3064. "list": list,
  3065. })
  3066. }