stock_in_api_controller.go 103KB

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