12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- "reflect"
- "strconv"
- "strings"
- "time"
- )
-
- type StockManagerApiController struct {
- BaseAuthAPIController
- }
-
- func StockManagerApiRegistRouters() {
-
- //入库管理和其他入库管理相关接口
- beego.Router("/api/warehouse/create", &StockManagerApiController{}, "post:CreateWarehouse")
- beego.Router("/api/warehouse/list", &StockManagerApiController{}, "get:GetWarehouseList")
- beego.Router("/api/warehouse/delete", &StockManagerApiController{}, "post:DeleteWarehouse")
- beego.Router("/api/warehouseinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseInfo")
- beego.Router("/api/warehouseinfo/list", &StockManagerApiController{}, "get:GetWarehouseInfoList")
- beego.Router("/api/warehouse/edit", &StockManagerApiController{}, "post:EditWarehouse")
-
- //退货管理和其他退货管理相关接口
- beego.Router("/api/salesreturn/create", &StockManagerApiController{}, "post:CreateSalesReturn")
- beego.Router("/api/salesreturn/delete", &StockManagerApiController{}, "post:DeleteSalesReturn")
- beego.Router("/api/salesreturninfo/delete", &StockManagerApiController{}, "post:DeleteSalesReturnInfo")
- beego.Router("/api/salesreturninfo/list", &StockManagerApiController{}, "get:GetSalesReturnInfoList")
- beego.Router("/api/salesreturn/list", &StockManagerApiController{}, "get:GetSalesReturnList")
- beego.Router("/api/salesreturn/edit", &StockManagerApiController{}, "post:EditReturnInfo")
-
- //出库管理和其他出库管理相关接口
- beego.Router("/api/warehouseout/create", &StockManagerApiController{}, "post:CreateWarehouseOut")
- beego.Router("/api/warehouseout/delete", &StockManagerApiController{}, "post:DeleteWarehouseOut")
- beego.Router("/api/warehouseoutinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseOutInfo")
- beego.Router("/api/warehouseout/list", &StockManagerApiController{}, "get:GetWarehouseOutList")
- beego.Router("/api/warehouseout/edit", &StockManagerApiController{}, "post:EditWarehouseOut")
- beego.Router("/api/warehouseout/info", &StockManagerApiController{}, "get:GetWarehouseOutInfoList")
-
- //出库退库管理和其他出库退库管理相关接口
- beego.Router("/api/cancelstock/create", &StockManagerApiController{}, "post:CreateCancelStock")
- beego.Router("/api/cancelstock/list", &StockManagerApiController{}, "get:GetCancelStockList")
- beego.Router("/api/cancelstock/info", &StockManagerApiController{}, "get:GetCancelStockInfoList")
- beego.Router("/api/cancelstock/delete", &StockManagerApiController{}, "post:DeleteCancelStock")
- beego.Router("/api/cancelstockinfo/delete", &StockManagerApiController{}, "post:DeleteCancelStockInfo")
- beego.Router("/api/cancelstockinfo/edit", &StockManagerApiController{}, "post:EditCancelStock")
- beego.Router("/api/cancelstockinfo/config", &StockManagerApiController{}, "get:GetCancelStockConfig")
-
- //库存相关全局配置
- beego.Router("/api/stock/config", &StockManagerApiController{}, "get:GetAllConfig")
- beego.Router("/api/return/config", &StockManagerApiController{}, "get:GetAllSalesReturnConfig")
-
- //库存查询
- beego.Router("/api/stock/query", &StockManagerApiController{}, "get:GetQueryInfo")
-
- beego.Router("/api/stock/detail", &StockManagerApiController{}, "get:GetDetailInfo")
-
- beego.Router("/api/warehouseout/user", &StockManagerApiController{}, "get:GetUserDetailInfo")
-
- beego.Router("/api/warehouseout/postsearchstock", &StockManagerApiController{}, "Get:PostSearchStock")
-
- beego.Router("/api/warehouseout/getoutstocktotalcount", &StockManagerApiController{}, "Get:GetOutStockTotalCount")
-
- beego.Router("/api/good/postgoodinformation", &StockManagerApiController{}, "Post:AddGoodInformation")
-
- beego.Router("/api/good/postdruginformation", &StockManagerApiController{}, "Post:AddDrugInformation")
- }
-
- func (c *StockManagerApiController) CreateWarehouse() {
-
- warehousing_time := c.GetString("warehousing_time")
- dealer_id, _ := c.GetInt64("dealer_id", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
-
- types, _ := c.GetInt64("type", 0)
-
- ctime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
- total = total + 1
- warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- warehousing := models.Warehousing{
- WarehousingOrder: warehousing_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehousingTime: warehousingDate.Unix(),
- Dealer: dealer_id,
- Manufacturer: manufacturer_id,
- Type: types,
- }
- service.AddSigleWarehouse(&warehousing)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingInfo []*models.WarehousingInfo
-
- if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockIn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
- utils.ErrorLog("warehousing_count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- total := float64(warehousing_count) * price
-
- var productDates int64
- var expiryDates int64
-
- fmt.Println()
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- number, _ := items["number"].(string)
-
- var remark string
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- remark = ""
- } else {
- remark = items["remark"].(string)
- }
-
- warehouseInfo := &models.WarehousingInfo{
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: warehousing.ID,
- GoodId: good_id,
- Number: number,
- GoodTypeId: good_type_id,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- WarehousingCount: warehousing_count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
- warehousingInfo = append(warehousingInfo, warehouseInfo)
-
- }
- }
- }
- errs := service.CreateWarehousingInfo(warehousingInfo)
- info, _ := service.FindLastWarehousingInfo(warehousing.WarehousingOrder)
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "入库成功",
- "warehousing_order": warehousing_order,
- "info": info,
- })
- //}
-
- //else {
- // warehouse, err1 := service.FindWareHouseByOrderNumber(warehousing_order)
- // if (err1 != nil) {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- //
- // dataBody := make(map[string]interface{}, 0)
- // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- // if err != nil {
- // utils.ErrorLog(err.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- //
- // var warehousingInfo []*models.WarehousingInfo
- //
- // if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
- // thisStockIn, _ := dataBody["stockIn"].([]interface{})
- // if len(thisStockIn) > 0 {
- // for _, item := range thisStockIn {
- // items := item.(map[string]interface{})
- //
- // if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- // utils.ErrorLog("good_id")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // good_id := int64(items["good_id"].(float64))
- //
- // if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- // utils.ErrorLog("good_type_id")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // good_type_id := int64(items["good_type_id"].(float64))
- //
- // if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
- // utils.ErrorLog("warehousing_count")
- // c.ServeFailJSONWithSGJErrorCod Fe(enums.ErrorCodeParamWrong)
- // return
- // }
- //
- // warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
- //
- // if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- // utils.ErrorLog("price")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // price, _ := strconv.ParseFloat(items["price"].(string), 64)
- // total := float64(warehousing_count) * price
- //
- // if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- // utils.ErrorLog("expiry_date")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- //
- // expiryDate, _ := items["expiry_date"].(string)
- // if len(expiryDate) == 0 {
- // utils.ErrorLog("len(expiry_date) == 0")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- //
- // return
- // }
- //
- // expiry_date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- // if parseDateErr != nil {
- // c.ErrorLog("日期(%v)解析错误:%v", expiry_date, parseDateErr)
- // }
- //
- // var productDates int64
- //
- // if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- // productDates = 0;
- // } else {
- // productDate, _ := items["product_date"].(string)
- // product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- // productDates = product_date.Unix()
- //
- // }
- //
- // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- // utils.ErrorLog("number")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // number, _ := items["number"].(string)
- //
- // var remark string
- // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- // remark = ""
- // } else {
- // remark = items["remark"].(string)
- // }
- //
- // warehouseInfo := &models.WarehousingInfo{
- // WarehousingOrder: warehousing_order,
- // WarehousingId: warehouse.ID,
- // GoodId: good_id,
- // Number: number,
- // GoodTypeId: good_type_id,
- // ProductDate: productDates,
- // ExpiryDate: expiry_date.Unix(),
- // WarehousingCount: warehousing_count,
- // Price: price,
- // TotalPrice: total,
- // Status: 1,
- // Ctime: ctime,
- // Remark: remark,
- // OrgId: adminUserInfo.CurrentOrgId,
- // }
- // warehousingInfo = append(warehousingInfo, warehouseInfo)
- //
- // }
- // }
- // }
- // errs := service.CreateWarehousingInfo(warehousingInfo)
- // info, _ := service.FindLastWarehousingInfo(warehousing_order)
- //
- // if (errs != nil) {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "入库成功",
- // "info": info,
- // })
- //
- //}
-
- }
- func (c *StockManagerApiController) GetWarehouseList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
-
- fmt.Println(start_time)
- fmt.Println(end_time)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseList,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockManagerApiController) GetWarehouseInfoList() {
- id, _ := c.GetInt64("id", 0)
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing, err := service.FindWarehousingById(id)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- if warehousing.ID <= 0 {
- return
- }
-
- warehousingInfo, err := service.FindWarehousingInfoById(id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "info": warehousingInfo,
- "warehousing": warehousing,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockManagerApiController) EditWarehouse() {
- warehousing_time := c.GetString("warehousing_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- dealer_id, _ := c.GetInt64("dealer_id", 0)
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehouse, _ := service.FindWarehousingById(id)
-
- warehousing := models.Warehousing{
- WarehousingOrder: warehouse.WarehousingOrder,
- OrgId: adminUserInfo.CurrentOrgId,
- Modifier: adminUserInfo.AdminUser.Id,
- Mtime: mtime,
- Status: 1,
- WarehousingTime: warehousingDate.Unix(),
- Type: warehouse.Type,
- Dealer: dealer_id,
- Manufacturer: manufacturer_id,
- }
-
- service.EditWarehousing(warehousing)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingInfo []*models.WarehousingInfo
- var upDateWarehousingInfo []*models.WarehousingInfo
-
- if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockIn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
- utils.ErrorLog("warehousing_count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- total := float64(warehousing_count) * price
-
- var productDates int64
- var expiryDates int64
-
- fmt.Println()
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- number, _ := items["number"].(string)
-
- var remark string
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- remark = ""
- } else {
- remark = items["remark"].(string)
- }
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if id == 0 {
- warehouseInfo := &models.WarehousingInfo{
- WarehousingOrder: warehouse.WarehousingOrder,
- WarehousingId: warehouse.ID,
- GoodId: good_id,
- Number: number,
- GoodTypeId: good_type_id,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- WarehousingCount: warehousing_count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
- warehousingInfo = append(warehousingInfo, warehouseInfo)
-
- } else {
- warehouseInfo := &models.WarehousingInfo{
- ID: id,
- WarehousingOrder: warehouse.WarehousingOrder,
- WarehousingId: warehouse.ID,
- GoodId: good_id,
- Number: number,
- GoodTypeId: good_type_id,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- WarehousingCount: warehousing_count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
- upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
- }
- }
- }
- }
- var errs error
- if len(warehousingInfo) > 0 {
- errs = service.CreateWarehousingInfo(warehousingInfo)
- }
-
- if len(upDateWarehousingInfo) > 0 {
- for _, item := range upDateWarehousingInfo {
- errs = service.UpDateWarehousingInfo(item)
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "编辑成功",
- })
-
- }
- func (c *StockManagerApiController) DeleteWarehouse() {
- ids := c.GetString("ids")
-
- if len(ids) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- err := service.DeleteWarehouse(idArray)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (c *StockManagerApiController) DeleteWarehouseInfo() {
- id, _ := c.GetInt64("id", 0)
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- err := service.UpDateWarehouseStatus(id)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
-
- func (c *StockManagerApiController) CreateSalesReturn() {
- dealer_id, _ := c.GetInt64("dealer_id", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- sales_return_time := c.GetString("time")
- types, _ := c.GetInt64("type", 0)
-
- salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- ctime := time.Now().Unix()
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
- total = total + 1
- orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- salesReturn := models.SalesReturn{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: salesReturnDate.Unix(),
- Dealer: dealer_id,
- Manufacturer: manufacturer_id,
- Type: types,
- }
-
- service.AddSigleSalesReturn(&salesReturn)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var salesReturnInfos []*models.SalesReturnInfo
-
- if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["salesReturn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
- return_count, _ := items["return_count"].(string)
- if len(return_count) == 0 {
- utils.ErrorLog("len(return_count) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
-
- return
- }
-
- count, _ := strconv.ParseInt(return_count, 10, 64)
- price, _ := strconv.ParseFloat(items["price"].(string), 10)
- total := float64(count) * price
-
- salesReturnInfo := &models.SalesReturnInfo{
- OrderNumber: salesReturn.OrderNumber,
- SalesReturnId: salesReturn.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Price: price,
- Total: total,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
-
- salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
-
- }
- }
- }
- errs := service.CreateSalesReturnInfo(salesReturnInfos)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "退货成功",
- })
-
- }
- func (c *StockManagerApiController) GetSalesReturnList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": returnList,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- func (this *StockManagerApiController) DeleteSalesReturn() {
- ids := this.GetString("ids")
-
- if len(ids) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- err := service.DeleteSalesReturn(idArray)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (this *StockManagerApiController) DeleteSalesReturnInfo() {
- id, _ := this.GetInt64("id", 0)
- fmt.Println(id)
- if id == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- err := service.UpDateSaleReturnStatus(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
- func (this *StockManagerApiController) GetSalesReturnInfoList() {
- id, _ := this.GetInt64("id", 0)
- list, _ := service.FindAllSalesReturnInfoById(id)
- salesReturn, _ := service.FindAllSalesReturnById(id)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "salesReturn": salesReturn,
- })
-
- }
- func (c *StockManagerApiController) EditReturnInfo() {
- return_time := c.GetString("return_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- dealer_id, _ := c.GetInt64("dealer_id", 0)
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- salesReturns, _ := service.FindSalesReturnById(id)
-
- sales := models.SalesReturn{
- ID: salesReturns.ID,
- Mtime: mtime,
- ReturnTime: returnDate.Unix(),
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
-
- service.EditSaleReturn(sales)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var returnInfos []*models.SalesReturnInfo
- var upDateReturnInfos []*models.SalesReturnInfo
-
- if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["salesReturn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if id == 0 {
- returnInfo := &models.SalesReturnInfo{
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: sales.OrderNumber,
- SalesReturnId: sales.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
- returnInfos = append(returnInfos, returnInfo)
-
- } else {
- returnInfo := &models.SalesReturnInfo{
- ID: id,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: sales.OrderNumber,
- SalesReturnId: sales.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
- upDateReturnInfos = append(upDateReturnInfos, returnInfo)
- }
- }
- }
- }
- var errs error
- if len(returnInfos) > 0 {
- errs = service.CreateSalesReturnInfo(returnInfos)
- }
-
- if len(upDateReturnInfos) > 0 {
- for _, item := range upDateReturnInfos {
- errs = service.UpDateSalesReturnInfo(item)
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "编辑成功",
- })
-
- }
-
- func (c *StockManagerApiController) CreateWarehouseOut() {
- dealer_id, _ := c.GetInt64("dealer_id", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- types, _ := c.GetInt64("type", 0)
-
- ctime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehousing_out_time := c.GetString("warehousing_out_time")
- warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehouseOutTime: warehousingOutDate.Unix(),
- Dealer: dealer_id,
- Manufacturer: manufacturer_id,
- Type: types,
- }
- service.AddSigleWarehouseOut(&warehouseOut)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingOutInfo []*models.WarehouseOutInfo
-
- if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockOut"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- total := float64(count) * price
- remark := items["remark"].(string)
-
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
-
- }
- }
- }
- errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
- info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "出库成功",
- "info": info,
- "warehousing_out_order": warehousing_out_order,
- })
-
- }
- func (c *StockManagerApiController) GetWarehouseOutList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- warehouseOutList, total, err := service.FindAllWarehouseOutList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
- fmt.Println(err)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseOutList,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockManagerApiController) DeleteWarehouseOut() {
- ids := c.GetString("ids")
-
- if len(ids) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- err := service.DeleteWarehouseOut(idArray)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
- id, _ := this.GetInt64("id", 0)
- fmt.Println(id)
- if id == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- err := service.UpDateWarehouseOutStatus(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
- func (c *StockManagerApiController) GetWarehouseOutInfoList() {
- id, _ := c.GetInt64("id", 0)
- warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
- warehouseOut, _ := service.FindWareHouseOutById(id)
- adminUserInfo := c.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- wareoutList, _ := service.GetWareOutInfoById(id, orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseOutInfo,
- "info": warehouseOut,
- "wareoutList": wareoutList,
- })
-
- }
- func (c *StockManagerApiController) EditWarehouseOut() {
- warehouse_out_time := c.GetString("warehouse_out_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- dealer_id, _ := c.GetInt64("dealer_id", 0)
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehouseOut, _ := service.FindWareHouseOutById(id)
-
- tempWarehouseOut := models.WarehouseOut{
- ID: warehouseOut.ID,
- Mtime: mtime,
- WarehouseOutTime: warehouseOutDate.Unix(),
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
-
- service.EditWarehouseOut(tempWarehouseOut)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingOutInfo []*models.WarehouseOutInfo
- var upDateWarehouseOutInfos []*models.WarehouseOutInfo
-
- if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
- thisStockOut, _ := dataBody["stockOut"].([]interface{})
- if len(thisStockOut) > 0 {
- for _, item := range thisStockOut {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- total := float64(count) * price
- remark := items["remark"].(string)
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if id == 0 {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- IsSys: 0,
- SysRecordTime: 0,
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
-
- } else {
- if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
- utils.ErrorLog("is_sys")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- is_sys := int64(items["is_sys"].(float64))
-
- if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
- utils.ErrorLog("sys_record_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- sys_record_time := int64(items["sys_record_time"].(float64))
-
- warehouseOutInfo := &models.WarehouseOutInfo{
- ID: id,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- IsSys: is_sys,
- SysRecordTime: sys_record_time,
- }
- upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
- }
- }
- }
- }
- var errs error
- if len(warehousingOutInfo) > 0 {
- errs = service.CreateWarehousingOutInfo(warehousingOutInfo)
- }
-
- if len(upDateWarehouseOutInfos) > 0 {
- for _, item := range upDateWarehouseOutInfos {
- errs = service.UpDateWarehouseOutInfo(item)
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "编辑成功",
- })
-
- }
-
- func (c *StockManagerApiController) CreateCancelStock() {
- dealer_id, _ := c.GetInt64("dealer_id", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- cancel_stock_time := c.GetString("time")
- types, _ := c.GetInt64("type", 0)
-
- cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- ctime := time.Now().Unix()
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: cancelStockDate.Unix(),
- Dealer: dealer_id,
- Manufacturer: manufacturer_id,
- Type: types,
- }
- service.AddSigleCancelStock(&cancelStock)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var cancelStockInfos []*models.CancelStockInfo
-
- if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["cancelStock"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- return_count, _ := items["return_count"].(string)
- if len(return_count) == 0 {
- utils.ErrorLog("len(return_count) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
-
- return
- }
-
- count, _ := strconv.ParseInt(return_count, 10, 64)
-
- cancelStockInfo := &models.CancelStockInfo{
- OrderNumber: cancelStock.OrderNumber,
- CancelStockId: cancelStock.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
- cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
-
- }
- }
- }
- errs := service.CreateCancelStockInfo(cancelStockInfos)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "退库成功",
- })
-
- }
- func (c *StockManagerApiController) GetCancelStockInfoList() {
- id, _ := c.GetInt64("id", 0)
-
- cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
- info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": cancelStockInfoList,
- "info": info,
- })
-
- }
- func (c *StockManagerApiController) GetCancelStockList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": returnList,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- func (this *StockManagerApiController) DeleteCancelStock() {
- ids := this.GetString("ids")
-
- if len(ids) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- err := service.DeleteCancelStock(idArray)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (this *StockManagerApiController) DeleteCancelStockInfo() {
- id, _ := this.GetInt64("id", 0)
- fmt.Println(id)
- if id == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- err := service.UpDateCancleStockStatus(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
- func (c *StockManagerApiController) EditCancelStock() {
- cancel_time := c.GetString("cancel_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- dealer_id, _ := c.GetInt64("dealer_id", 0)
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
-
- tempCancelStock := models.CancelStock{
- ID: cancelStock.ID,
- Mtime: mtime,
- ReturnTime: cancelDate.Unix(),
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
-
- service.EditCancelStock(tempCancelStock)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var cancelStockInfos []*models.CancelStockInfo
- var upDateCancelStockInfos []*models.CancelStockInfo
-
- if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
- thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
- if len(thisCancelStock) > 0 {
- for _, item := range thisCancelStock {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if id == 0 {
- cancelStockInfo := &models.CancelStockInfo{
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: cancelStock.OrderNumber,
- CancelStockId: cancelStock.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
- cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
-
- } else {
- cancelStockInfo := &models.CancelStockInfo{
- ID: id,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: cancelStock.OrderNumber,
- CancelStockId: cancelStock.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
- upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
- }
- }
- }
- }
- var errs error
- if len(cancelStockInfos) > 0 {
- errs = service.CreateCancelStockInfo(cancelStockInfos)
- }
-
- if len(upDateCancelStockInfos) > 0 {
- for _, item := range upDateCancelStockInfos {
- errs = service.UpDateCancelStockInfo(item)
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "编辑成功",
- })
-
- }
- func (this *StockManagerApiController) GetCancelStockConfig() {
- types, _ := this.GetInt64("type", 0)
- adminUserInfo := this.GetAdminUserInfo()
- warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
- this.ServeSuccessJSON(map[string]interface{}{
- "warehouseOutInfoList": warehouseOutInfoList,
- })
- }
-
- func (c *StockManagerApiController) GetQueryInfo() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- keyword := c.GetString("keyword")
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- type_name, _ := c.GetInt64("type_name")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- adminUserInfo := c.GetAdminUserInfo()
- list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
- info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
-
- infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "info": info,
- "infomationList": infomationList,
- "orgid": adminUserInfo.CurrentOrgId,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (c *StockManagerApiController) SearchWarehouse() {
- keywords := c.GetString("keywords")
- adminUserInfo := c.GetAdminUserInfo()
- warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseList,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockManagerApiController) GetAllConfig() {
- adminUserInfo := c.GetAdminUserInfo()
- manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
- dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
- goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
- goodInfo, _ := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "manufacturer": manufacturer,
- "dealer": dealer,
- "goodType": goodType,
- "goodInfo": goodInfo,
- })
- }
- func (this *StockManagerApiController) GetAllSalesReturnConfig() {
- types, _ := this.GetInt64("type", 0)
- adminUserInfo := this.GetAdminUserInfo()
- warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
- this.ServeSuccessJSON(map[string]interface{}{
- "warehouseInfoList": warehouseInfoList,
- })
- }
-
- func (this *StockManagerApiController) GetDetailInfo() {
-
- page, _ := this.GetInt64("page", 0)
- limit, _ := this.GetInt64("limit", 0)
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- types, _ := this.GetInt64("type", 0)
-
- keywords := this.GetString("keywords")
- manufacturer, _ := this.GetInt64("manufacturer", 0)
- order_type, _ := this.GetInt64("order_type", 0)
- dealer, _ := this.GetInt64("dealer", 0)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := this.GetAdminUserInfo()
-
- var list []*models.WarehousingInfo
- var list1 []*models.WarehouseOutInfo
- var list2 []*models.SalesReturnInfo
- var list3 []*models.CancelStockInfo
-
- var total int64
- var err error
- var total_price float64
-
- if types == 1 {
- list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
- _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "total_price": total_price,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- } else if types == 2 {
- list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
- _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list1,
- "total": total,
- "total_price": total_price,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- } else if types == 3 {
- list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list2,
- "total": total,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- } else if types == 4 {
- list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list3,
- "total": total,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- }
-
- func (this *StockManagerApiController) GetUserDetailInfo() {
- order_id, _ := this.GetInt64("id")
- if order_id <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := this.GetAdminUserInfo()
- userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": userDetails,
- "total": total,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
-
- func (this *StockManagerApiController) PostSearchStock() {
-
- keyword := this.GetString("keyword")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- stock, err := service.PostSearchStock(keyword, orgId)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "stock": stock,
- })
- }
-
- func (this *StockManagerApiController) GetOutStockTotalCount() {
-
- warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
- adminUserInfo := this.GetAdminUserInfo()
- stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "stockCount": stockCount,
- })
- }
-
- func (this *StockManagerApiController) AddGoodInformation() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- utils.ErrorLog("%v", dataBody)
- var goods []*models.GoodInfo
- var total_goods []interface{}
- tempGoods := dataBody["goods"].([]interface{})
-
- total_goods = tempGoods
- for index, goodMap := range tempGoods {
- goodNameM := goodMap.(map[string]interface{})
-
- var good models.GoodInfo
-
- if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- return
- }
-
- good_name, _ := goodNameM["good_name"].(string)
- if len(good_name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.GoodName = good_name
-
- // 获取数据字典数据
- var good_kind_id int64
- var name = "耗材种类"
- config, _ := service.GetDrugDataConfig(0, name)
-
- good_kind := goodNameM["good_kind"].(string)
-
- if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- if len(good_kind) != 0 {
- _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
-
- dataconfig := models.DictDataconfig{
- ParentId: config.ID,
- Module: "system",
- OrgId: orgId,
- Name: good_kind,
- FieldName: "",
- Value: index + 50,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUserInfo.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- if errcodegoodkind == gorm.ErrRecordNotFound {
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
- for _, it := range dataConfig {
- if good_kind == it.Name {
- fmt.Println(it.Name)
- good_kind_id = int64(it.Value)
- }
- }
- good.GoodKind = good_kind_id
-
- good_type := goodNameM["type_name"].(string)
- if len(good_type) == 0 {
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- if len(good_type) != 0 {
- _, errcodegoodtype := service.GetGoodType(good_type, orgId)
- if errcodegoodtype == gorm.ErrRecordNotFound {
- goodsType := models.GoodsType{
- TypeName: good_type,
- Remark: "",
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Creater: adminUserInfo.AdminUser.Id,
- Modifier: 0,
- OrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- Type: 0,
- Number: 0,
- OutStock: 0,
- StockAttribute: 1,
- }
- service.CreatedGoodType(&goodsType)
- }
- }
-
- goodType, _ := service.GetAllGoodType(orgId)
- var good_type_id int64
- for _, it := range goodType {
- if good_type == it.TypeName {
- good_type_id = it.ID
- }
- }
- good.GoodTypeId = good_type_id
-
- medical_insurance_level := goodNameM["medical_insurance_level"].(string)
- if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var medical_insurance_id int64
- var medicalInsurance = "医保等级"
- medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
-
- if len(medical_insurance_level) != 0 {
- _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
- if errcodemedicalInsurance == gorm.ErrRecordNotFound {
- dataconfig := models.DictDataconfig{
- ParentId: medicalInsuranceDataConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: medical_insurance_level,
- FieldName: "",
- Value: index + 50,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUserInfo.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
- for _, it := range medicalInsuranceList {
- if medical_insurance_level == it.Name {
- medical_insurance_id = int64(it.Value)
- }
- }
- good.MedicalInsuranceLevel = medical_insurance_id
-
- if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- return
- }
- specification_name := goodNameM["specification_name"].(string)
- if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.SpecificationName = specification_name
-
- var manufacturer_id int64
- manufacturer := goodNameM["manufacturer"].(string)
- if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- if len(manufacturer) != 0 {
- _, errcodes := service.GetManufacturerName(orgId, manufacturer)
- manu := models.Manufacturer{
- ManufacturerName: manufacturer,
- Status: 1,
- OrgId: orgId,
- Creater: adminUserInfo.AdminUser.Id,
- }
- if errcodes == gorm.ErrRecordNotFound {
-
- service.CreateManufacturer(&manu)
-
- }
- }
-
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- for _, it := range manufacturerList {
- if manufacturer == it.ManufacturerName {
- manufacturer_id = it.ID
- }
- }
-
- good.Manufacturer = manufacturer_id
-
- if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
- utils.ErrorLog("unit_id")
- return
- }
-
- unit_id := int64(goodNameM["unit_id"].(float64))
- if unit_id <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- fmt.Println("33333333", unit_id)
- good.GoodUnit = unit_id
-
- if goodNameM["retail_price"] == nil || reflect.TypeOf(goodNameM["retail_price"]).String() != "float64" {
- utils.ErrorLog("retail_price")
- return
- }
-
- retail_price := goodNameM["retail_price"].(float64)
- if retail_price <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.RetailPrice = retail_price
-
- if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
- utils.ErrorLog("stock_warn_count")
- return
- }
-
- stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
- if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.StockWarnCount = stock_warn_count
-
- var dealer_id int64
- dealerName := goodNameM["dealer"].(string)
-
- dealer := models.Dealer{
- OrgId: orgId,
- Status: 1,
- DealerName: dealerName,
- Creater: adminUserInfo.AdminUser.Id,
- Ctime: time.Now().Unix(),
- }
- if len(dealerName) != 0 {
- _, errcodedealer := service.GetDealerByName(orgId, dealerName)
-
- if errcodedealer == gorm.ErrRecordNotFound {
- service.CreateDealer(&dealer)
- }
- }
-
- dealerList, _ := service.GetAllDealerList(orgId)
- for _, it := range dealerList {
- if dealerName == it.DealerName {
- dealer_id = it.ID
- }
- }
-
- good.Dealer = dealer_id
- if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
- utils.ErrorLog("pinyin")
- return
- }
- pinyin := goodNameM["pinyin"].(string)
-
- good.Pinyin = pinyin
-
- if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
- utils.ErrorLog("wubi")
- return
- }
- wubi := goodNameM["wubi"].(string)
-
- good.Pinyin = wubi
-
- if goodNameM["buy_price"] == nil || reflect.TypeOf(goodNameM["buy_price"]).String() != "float64" {
- utils.ErrorLog("buy_price")
- return
- }
-
- buy_price := goodNameM["buy_price"].(float64)
- good.BuyPrice = buy_price
-
- if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
- utils.ErrorLog("social_security_directory_code")
- return
- }
- social_security_directory_code := goodNameM["social_security_directory_code"].(string)
-
- good.SocialSecurityDirectoryCode = social_security_directory_code
-
- if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
- utils.ErrorLog("is_special_diseases")
- return
- }
-
- is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
- good.IsSpecialDiseases = is_special_diseases
-
- if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
- utils.ErrorLog("is_record")
- return
- }
-
- is_record := int64(goodNameM["is_record"].(float64))
- good.IsRecord = is_record
-
- if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
- utils.ErrorLog("good_status")
- return
- }
- good_status := goodNameM["good_status"].(string)
- good.GoodStatus = good_status
-
- if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
- utils.ErrorLog("medical_insurance_number")
- return
- }
- medical_insurance_number := goodNameM["medical_insurance_number"].(string)
- good.MedicalInsuranceNumber = medical_insurance_number
-
- if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
- utils.ErrorLog("production_type")
- return
- }
- production_type := goodNameM["production_type"].(string)
- good.ProductionType = production_type
-
- if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- return
- }
- remark := goodNameM["remark"].(string)
- good.Remark = remark
-
- statistics_category := goodNameM["statistics_category"].(string)
-
- var categoryName = "统计分类"
- var statistic_id int64
- drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
-
- if len(statistics_category) != 0 {
- _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
-
- if errcodecagegory == gorm.ErrRecordNotFound {
- dataconfig := models.DictDataconfig{
- ParentId: drugDataConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: statistics_category,
- FieldName: "",
- Value: index + 50,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUserInfo.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
-
- for _, it := range parentDataConfig {
- if statistics_category == it.Name {
- statistic_id = int64(it.Value)
- }
- }
-
- good.StatisticsCategory = statistic_id
- goods = append(goods, &good)
- }
-
- export_time := time.Now().Unix()
- errLogs, _ := service.FindPatientExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
- if len(goods) > 0 {
-
- for _, item := range goods {
- service.CreateGoodsInfomation(item, orgId)
-
- log := models.ExportLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(goods)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(goods),
- "fail_num": int64(len(errLogs)),
- })
- }
- } else {
- log := models.ExportLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(goods)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(goods),
- "fail_num": int64(len(errLogs)),
- })
- }
- }
-
- func (this *StockManagerApiController) AddDrugInformation() {
- adminUser := this.GetAdminUserInfo()
- orgId := adminUser.CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- utils.ErrorLog("%v", dataBody)
- var drugList []*models.BaseDrugLib
- var total_goods []interface{}
- tempDrugs := dataBody["drugs"].([]interface{})
-
- total_goods = tempDrugs
- for index, drugMap := range tempDrugs {
- goodNameM := drugMap.(map[string]interface{})
- var drug models.BaseDrugLib
- if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- return
- }
-
- drug_name, _ := goodNameM["drug_name"].(string)
- if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugName = drug_name
-
- if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
- utils.ErrorLog("drug_alias")
- return
- }
-
- drug_alias, _ := goodNameM["drug_alias"].(string)
- if len(drug_alias) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品别名不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugAlias = drug_alias
-
- drug_spec, _ := goodNameM["drug_spec"].(string)
- if len(drug_spec) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品规格不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugSpec = drug_spec
-
- drug_type := goodNameM["drug_type"].(string)
- if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var drug_type_id int64
- var drugType = "药品类型"
-
- drugconfig, _ := service.GetDrugDataConfig(0, drugType)
- if len(drug_type) == 0 {
- _, errcodes := service.IsExistDicConfig(drugconfig.ParentId, drug_type, orgId)
- if errcodes == gorm.ErrRecordNotFound {
- dataconfig := models.DictDataconfig{
- ParentId: drugconfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_type,
- FieldName: "",
- Value: index + 50,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
- for _, it := range drugTypeList {
- if drug_type == it.Name {
- drug_type_id = int64(it.Value)
- }
- }
-
- drug.DrugType = drug_type_id
-
- drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
- if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugStockLimit = drug_stock_limit
-
- drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
- if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugOriginPlace = drug_origin_place
-
- drug_dosage_form := goodNameM["drug_dosage_form"].(string)
-
- if len(drug_dosage_form) == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var drug_dosage = "药品剂型"
- var drug_dosage_form_id int64
- drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
- if len(drug_dosage_form) != 0 {
- _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
- if errcodess == gorm.ErrRecordNotFound {
- dataconfig := models.DictDataconfig{
- ParentId: drugDosageconfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_dosage,
- FieldName: "",
- Value: index + 50,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
- for _, it := range drugDosageList {
- if drug_dosage == it.Name {
- drug_dosage_form_id = int64(it.ID)
- }
- }
- drug.DrugDosageForm = drug_dosage_form_id
-
- medical_insurance_level := goodNameM["medical_insurance_level"].(string)
- var medical_insurance_level_id int64
- if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- var medicalInsuranceName = "医保等级"
- medicalInsuranceConfig, _ := service.GetDrugDataConfig(0, medicalInsuranceName)
- if len(medical_insurance_level) != 0 {
- _, errcodemedical := service.IsExistDicConfig(medicalInsuranceConfig.ID, medical_insurance_level, orgId)
- if errcodemedical == gorm.ErrRecordNotFound {
- dataconfig := models.DictDataconfig{
- ParentId: medicalInsuranceConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: medical_insurance_level,
- FieldName: "",
- Value: index + 50,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceConfig.ID, orgId)
- for _, it := range medicalInsuranceList {
- if medical_insurance_level == it.Name {
- medical_insurance_level_id = int64(it.Value)
- }
- }
- drug.MedicalInsuranceLevel = medical_insurance_level_id
-
- max_unit_id := goodNameM["max_unit"].(string)
- if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的最大不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.MaxUnit = max_unit_id
-
- min_unit := goodNameM["min_unit"].(string)
- if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的最小单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.MinUnit = min_unit
-
- unit_matrixing := goodNameM["unit_matrixing"].(string)
- if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位换算不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.UnitMatrixing = unit_matrixing
- retail_prices := goodNameM["retail_price"].(string)
- retail_price, _ := strconv.ParseFloat(retail_prices, 64)
-
- if retail_price <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的零售价不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.RetailPrice = retail_price
-
- last_prices := goodNameM["last_price"].(string)
- last_price, _ := strconv.ParseFloat(last_prices, 64)
- if last_price <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的上次进价不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.LastPrice = last_price
-
- drug_classify := goodNameM["drug_classify"].(string)
- fmt.Println("drug_classify22222222222222222", drug_classify)
- if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var drugClassify = "药物分类"
- var drug_classify_id int64
- drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
- fmt.Println("9999999999999999999", drugClassifyConfig)
- if len(drug_classify) != 0 {
- _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
- if errcodesClass == gorm.ErrRecordNotFound {
- dataconfig := models.DictDataconfig{
- ParentId: drugClassifyConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_classify,
- FieldName: "",
- Value: index + 50,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
- for _, it := range drugClassList {
- if drug_classify == it.Name {
- fmt.Println("88888888888888888", it.Name)
- fmt.Println("hhhhhhhhhhhh", drug_classify)
- drug_classify_id = int64(it.Value)
- }
- }
- drug.DrugCategory = drug_classify_id
-
- manufacturer := goodNameM["manufacturer"].(string)
- if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- if len(manufacturer) != 0 {
- _, errcodema := service.GetManufacturerName(orgId, manufacturer)
- if errcodema == gorm.ErrRecordNotFound {
- manufactur := models.Manufacturer{
- OrgId: orgId,
- Status: 1,
- ManufacturerName: manufacturer,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- }
- service.CreateManufacturer(&manufactur)
- }
- }
-
- var manufacturer_id int64
-
- manufacturList, _ := service.GetAllManufacturerList(orgId)
- for _, it := range manufacturList {
- if manufacturer == it.ManufacturerName {
- manufacturer_id = it.ID
- }
- }
-
- drug.Manufacturer = manufacturer_id
-
- dealer := goodNameM["dealer"].(string)
- _, errcodesdealer := service.GetDealerByName(orgId, dealer)
- if errcodesdealer == gorm.ErrRecordNotFound {
- dealerconfig := models.Dealer{
- DealerName: dealer,
- Status: 1,
- OrgId: orgId,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- }
- service.CreateDealer(&dealerconfig)
- }
- var dealer_id int64
- dealerList, _ := service.GetAllDealerList(orgId)
- for _, it := range dealerList {
- if dealer == it.DealerName {
- dealer_id = it.ID
- }
- }
- drug.Dealer = dealer_id
-
- pinyin := goodNameM["pinyin"].(string)
-
- drug.Pinyin = pinyin
- wubi := goodNameM["wubi"].(string)
- drug.Wubi = wubi
-
- drug_alias_pinyin := goodNameM["drug_alias_pinyin"].(string)
- drug.DrugAliasPinyin = drug_alias_pinyin
-
- statistics_category := goodNameM["statistics_category"].(string)
-
- var statisticsCategory = "统计分类"
- var statistics_category_id int64
-
- statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
- if len(statistics_category) != 0 {
- _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
- if errcodestatistc == gorm.ErrRecordNotFound {
-
- dataconfig := models.DictDataconfig{
- ParentId: statistcConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: statistics_category,
- FieldName: "",
- Value: index + 50,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
-
- }
-
- statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
- for _, it := range statisticsCategoryList {
- if statistics_category == it.Name {
- statistics_category_id = int64(it.Value)
- }
- }
- drug.StatisticsCategory = statistics_category_id
-
- number := goodNameM["number"].(string)
- drug.Number = number
- hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
- drug.HospApprFlag = hosp_appr_flag
- medical_insurance_number := goodNameM["medical_insurance_number"].(string)
- drug.MedicalInsuranceNumber = medical_insurance_number
-
- pharmacology_category := goodNameM["pharmacology_category"].(string)
-
- var pharmacology = "药理分类"
- var pharmacology_category_id int64
- pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
- if len(pharmacology_category) != 0 {
- _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
- if errcodespharmacology == gorm.ErrRecordNotFound {
- dataconfig := models.DictDataconfig{
- ParentId: pharmacologyConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: pharmacology_category,
- FieldName: "",
- Value: index + 50,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
- for _, it := range pharmacologyList {
- if pharmacology_category == it.Name {
- pharmacology_category_id = int64(it.Value)
- }
- }
- drug.PharmacologyCategory = pharmacology_category_id
-
- code := goodNameM["code"].(string)
- drug.Code = code
- is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
- drug.IsSpecialDiseases = is_special_diseases
- is_record := int64(goodNameM["is_record"].(float64))
- drug.IsRecord = is_record
- prescription_mark := int64(goodNameM["prescription_mark"].(float64))
- drug.PrescriptionMark = prescription_mark
- social_security_directory_code := goodNameM["social_security_directory_code"].(string)
- drug.SocialSecurityDirectoryCode = social_security_directory_code
- record_date := goodNameM["record_date"].(string)
- fmt.Println("日期2222222222", record_date)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- drug.RecordDate = theTime.Unix()
- drug_remark := goodNameM["drug_remark"].(string)
- drug.DrugRemark = drug_remark
- drug_status := goodNameM["drug_status"].(string)
- drug.DrugStatus = drug_status
- limit_remark := goodNameM["limit_remark"].(string)
- drug.LimitRemark = limit_remark
-
- drug_alias_wubi := goodNameM["drug_alias_wubi"].(string)
- drug.DrugAliasWubi = drug_alias_wubi
-
- drug_control := goodNameM["drug_control"].(string)
-
- var drugControl = "开药控制"
- var drug_control_id int64
-
- drugContorlConfig, _ := service.GetDrugDataConfig(0, drugControl)
- if len(drug_control) != 0 {
- _, errcodesdrugcontrol := service.IsExistDicConfig(drugContorlConfig.ID, drug_control, orgId)
- if errcodesdrugcontrol == gorm.ErrRecordNotFound {
- dataconfig := models.DictDataconfig{
- ParentId: drugContorlConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_control,
- FieldName: "",
- Value: index + 50,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugContorlList, _ := service.GetParentDataConfig(drugContorlConfig.ID, orgId)
- for _, it := range drugContorlList {
- if drug_control == it.Name {
- drug_control_id = int64(it.Value)
- }
- }
- drug.DrugControl = drug_control_id
-
- drug_category := goodNameM["drug_category"].(string)
-
- var drugCategory = "药品类别"
- var drug_category_id int64
-
- drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
- fmt.Println("33333drugCategoryConfig", drugCategoryConfig)
- if len(drug_category) != 0 {
- _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
- if drugcategoryerrcodes == gorm.ErrRecordNotFound {
- dataconfig := models.DictDataconfig{
- ParentId: drugCategoryConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_category,
- FieldName: "",
- Value: index + 50,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
- fmt.Println("drugCategoryList", drugCategoryList)
- for _, it := range drugCategoryList {
- if drug_category == it.Name {
- drug_category_id = int64(it.Value)
- }
- }
- fmt.Println("666666666666666666666", drug_category_id)
- drug.DrugCategory = drug_category_id
-
- drugList = append(drugList, &drug)
- }
-
- export_time := time.Now().Unix()
- errLogs, _ := service.FindPatientExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
- fmt.Println("数组", drugList)
- if len(drugList) > 0 {
- for _, item := range drugList {
-
- goodInfo := models.BaseDrugLib{
- DrugName: item.DrugName,
- DrugAlias: item.DrugAlias,
- DrugSpec: item.DrugSpec,
- DrugType: item.DrugType,
- DrugStockLimit: item.DrugStockLimit,
- DrugOriginPlace: item.DrugOriginPlace,
- DrugDosageForm: item.DrugDosageForm,
- MedicalInsuranceLevel: item.MedicalInsuranceLevel,
- MaxUnit: item.MaxUnit,
- MinUnit: item.MinUnit,
- UnitMatrixing: item.UnitMatrixing,
- RetailPrice: item.RetailPrice,
- LastPrice: item.LastPrice,
- DrugClassify: item.DrugClassify,
- Manufacturer: item.Manufacturer,
- Dealer: item.Dealer,
- OrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Pinyin: item.Pinyin,
- Wubi: item.Wubi,
- DrugAliasPinyin: item.DrugAliasPinyin,
- DrugAliasWubi: item.DrugAliasWubi,
- DrugControl: item.DrugControl,
- Number: item.Number,
- HospApprFlag: item.HospApprFlag,
- MedicalInsuranceNumber: item.MedicalInsuranceNumber,
- PharmacologyCategory: item.PharmacologyCategory,
- StatisticsCategory: item.StatisticsCategory,
- Code: item.Code,
- IsSpecialDiseases: item.IsSpecialDiseases,
- IsRecord: item.IsRecord,
- PrescriptionMark: item.PrescriptionMark,
- SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
- RecordDate: item.RecordDate,
- DrugRemark: item.DrugRemark,
- DrugStatus: item.DrugStatus,
- LimitRemark: item.LimitRemark,
- DrugCategory: item.DrugCategory,
- }
-
- //查询同种药品同种规格是否存在
- _, drugerror := service.IsExistDrugByName(item.DrugName, item.DrugSpec, orgId)
-
- if drugerror == gorm.ErrRecordNotFound {
- service.CreateDrugsInfomation(&goodInfo)
- } else if drugerror == nil {
- service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
- }
- log := models.ExportLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(drugList)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(drugList),
- "fail_num": int64(len(errLogs)),
- })
- }
- } else {
- log := models.ExportLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(drugList)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(drugList),
- "fail_num": int64(len(errLogs)),
- })
- }
- }
|