123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481 |
- 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"
- "math/rand"
- "reflect"
- "strconv"
- "strings"
- "time"
- )
-
- type SecondaryOrderApiController struct {
- BaseAuthAPIController
- }
-
- func SecondaryOrderApiRegistRouters() {
- beego.Router("/api/secondary/getcode", &SecondaryOrderApiController{}, "get:GetStoreCode") //获取仓库编码
- beego.Router("/api/secondary/updatestatus", &SecondaryOrderApiController{}, "get:UpdateStatus") //修改仓库状态
- beego.Router("/api/secondary/deletestorehouse", &SecondaryOrderApiController{}, "get:DeleteStorehouse") //删除仓库
- beego.Router("/api/secondary/isstorehousename", &SecondaryOrderApiController{}, "get:IsStorehouseName") //仓库名称是否重复
- beego.Router("/api/secondary/isstorehouseaddress", &SecondaryOrderApiController{}, "get:IsStorehouseAddress") //仓库地址是否重复
- beego.Router("/api/secondary/storehouselist", &SecondaryOrderApiController{}, "get:StorehouseList") //分页
- beego.Router("/api/secondary/addstorehouse", &SecondaryOrderApiController{}, "post:AddStorehouse") //新增仓库
- beego.Router("/api/secondary/updatestorehouse", &SecondaryOrderApiController{}, "post:UpdateStorehouse") //修改
- beego.Router("/api/secondary/getonestorehouse", &SecondaryOrderApiController{}, "get:GetOneStorehouse") //查一条仓库的信息
- beego.Router("/api/secondary/getallstorehousename", &SecondaryOrderApiController{}, "get:GetAllStorehouseName") //获取当前机构的所有可用仓库名称
- beego.Router("/api/secondary/findstorehouseconfig", &SecondaryOrderApiController{}, "get:FindStorehouseConfig") //查询该机构的仓库配置
- beego.Router("/api/secondary/updateinfo", &SecondaryOrderApiController{}, "get:UpdateInfo") //更改耗材自动入库仓库
- beego.Router("/api/secondary/updateoutinfo", &SecondaryOrderApiController{}, "get:UpdateOutInfo") //更改耗材自动出库仓库
- beego.Router("/api/secondary/updatedruginfo", &SecondaryOrderApiController{}, "get:UpdateDrugInfo") //更改药品自动入库仓库
- beego.Router("/api/secondary/updatedrugout", &SecondaryOrderApiController{}, "get:UpdateDrugOut") //更改药品自动出库仓库
- beego.Router("/api/secondary/getusername", &SecondaryOrderApiController{}, "get:GetuserName") //获取仓库管理员信息
- beego.Router("/api/secondary/byliinit", &SecondaryOrderApiController{}, "get:Byliinit") //初始化旧数据
- beego.Router("/api/secondary/getcreaterid", &SecondaryOrderApiController{}, "get:GetCreaterId") //获取当前登录的人的id
-
- beego.Router("/api/seconde/getsencondegoodlist", &SecondaryOrderApiController{}, "Get:GetSencondeGoodList")
- beego.Router("/api/senconde/savesencondorder", &SecondaryOrderApiController{}, "Post:SaveSencondOrder")
- beego.Router("/api/senconde/getallsecondeorderlist", &SecondaryOrderApiController{}, "Get:GetAllSecondeOrderList")
- beego.Router("/api/senconde/getsencondorderdetail", &SecondaryOrderApiController{}, "Get:GetSencondOrderDetail")
- beego.Router("/api/senconde/updatesencondorder", &SecondaryOrderApiController{}, "Post:UpdateSencondOrder")
- beego.Router("/api/sencond/getsecondorderbyid", &SecondaryOrderApiController{}, "Get:GetSecondOrderById")
- beego.Router("/api/sencond/checksecondorder", &SecondaryOrderApiController{}, "Get:CheckSecondOrer")
- beego.Router("/api/sencond/deletestorehouselist", &SecondaryOrderApiController{}, "Get:DeleteStorehouseList")
- beego.Router("/api/sencond/returnchecksecondeorder", &SecondaryOrderApiController{}, "Get:ReturnCheckSecondOrder")
- beego.Router("/api/second/getstorehousegoodlist", &SecondaryOrderApiController{}, "Get:GetStoreHouseGoodList")
- beego.Router("/api/second/getsumsecondecount", &SecondaryOrderApiController{}, "Get:GetSumSecondCount")
- beego.Router("/api/second/deletesecondorderinfo", &SecondaryOrderApiController{}, "Get:DeleteSecondOrderInfo")
- }
-
- //获取仓库编码
- func (this *SecondaryOrderApiController) GetStoreCode() {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- var code string
- for a := true; a == true; {
- code = service.CreateCode()
- tmp := service.FindStorehouseCode(orgId, code)
- //如果没有重复的编码结束循环
- if tmp == false {
- a = false
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": code,
- })
- return
- }
-
- //修改仓库状态
- func (this *SecondaryOrderApiController) UpdateStatus() {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- check := map[string][]string{
- "id": {"must", "int", "id"},
- }
- _, err := checkParams(this, &check)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- id, _ := this.GetInt64("id")
- //判断该仓库的库存是否为零
- boolean := service.IsStorehouseNil(id, orgId)
- if boolean == false {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
- return
- }
- //判断该仓库是否在仓库配置表中
- boolean = service.IsInConfig(orgId, id)
- if boolean == true {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
- return
- }
- //修改仓库状态
- err = service.UpdateStorehouseStatus(id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "修改成功",
- })
- return
- }
-
- //删除仓库
- func (this *SecondaryOrderApiController) DeleteStorehouse() {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- check := map[string][]string{
- "id": {"must", "int", "id"},
- }
- _, err := checkParams(this, &check)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- id, _ := this.GetInt64("id")
- //判断该仓库的库存是否为零
- boolean := service.IsStorehouseNil(id, orgId)
- if boolean == false {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
- return
- }
- //判断该仓库是否在仓库配置表中
- boolean = service.IsInConfig(orgId, id)
- if boolean == true {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
- return
- }
- err = service.DeleteStorehouse(id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "删除成功",
- })
- return
- }
-
- //仓库名称是否重复
- func (this *SecondaryOrderApiController) IsStorehouseName() {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- storehouse_name := this.GetString("storehouse_name")
- check := map[string][]string{
- "storehouse_name": {"must", "string", "storehouse_name"},
- }
- _, err := checkParams(this, &check)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- var bo bool
- bo, err = service.IsStorehouseName(orgId, storehouse_name)
- if bo == true {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "ok",
- })
- return
-
- }
-
- //仓库地址是否重复
- func (this *SecondaryOrderApiController) IsStorehouseAddress() {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- storehouse_address := this.GetString("storehouse_address")
- check := map[string][]string{
- "storehouse_address": {"must", "string", "storehouse_address"},
- }
- _, err := checkParams(this, &check)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- var bo bool
- bo, err = service.IsStorehouseAddress(orgId, storehouse_address)
- if bo == true {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "ok",
- })
- return
-
- }
-
- //分页
- func (this *SecondaryOrderApiController) StorehouseList() {
- adminUserInfo := this.GetAdminUserInfo()
- page, _ := this.GetInt64("page") //页码
- limit, _ := this.GetInt64("limit") //每一页查出来的条数
- check := map[string][]string{
- "page": {"must", "string", "page"},
- "limit": {"must", "string", "limit"},
- }
- _, err := checkParams(this, &check)
- keyword := this.GetString("keyword")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- }
- namemap := make(map[int64]string)
- //根据管理员id获取管理员
- viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
- for _, v := range viewModels {
- namemap[int64(v.AdminUserId)] = v.UserName
- }
- slicekey := make([]int64, 0)
- if len(keyword) > 0 {
- for k, v := range namemap {
- res := strings.Contains(v, keyword)
- if res == true {
- slicekey = append(slicekey, k)
- }
- }
- }
- //获取分页的数据
- list, total, err := service.StorehouseList(page, limit, orgId, keyword, slicekey)
-
- //分页
- type Storehouselist struct {
- ID int64
- StorehouseCode string //仓库编号
- StorehouseName string //仓库名称
- StorehouseAddress string //仓库地址
- StorehouseStatus int64 //仓库状态
- Status int64 //数据状态
- StorehouseAdminId int64 //仓库管理员id
- StorehouseAdminName string //仓库管理员名字
- UserOrgId int64
- }
- //初始化该结构体
- tmplist := []*Storehouselist{}
- for i := 0; i < len(list); i++ {
- tlist := &Storehouselist{
- list[i].ID,
- list[i].StorehouseCode,
- list[i].StorehouseName,
- list[i].StorehouseAddress,
- list[i].StorehouseStatus,
- list[i].Status,
- list[i].StorehouseAdminId,
- "",
- list[i].UserOrgId,
- }
- tmplist = append(tmplist, tlist)
- }
- for _, v := range tmplist {
- if k, ok := namemap[v.StorehouseAdminId]; ok {
- v.StorehouseAdminName = k
- } else {
- v.StorehouseAdminName = "超级管理员"
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": tmplist,
- "total": total,
- })
- }
-
- //新增仓库
- func (this *SecondaryOrderApiController) AddStorehouse() {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- defer func() {
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- var storehouse_status, admin_id int64
- tmpstatus := dataBody["storehouse_status"]
- tmpid := dataBody["storehouse_admin_id"] //管理员id
- if tmpstatus == nil {
- storehouse_status = 1
- } else {
- storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
- }
- if tmpid == nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
- return
- } else {
- admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
- }
- switch {
- case dataBody["storehouse_code"] == nil:
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库编号不能为空")
- return
- case dataBody["storehouse_name"] == nil:
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
- return
- case dataBody["storehouse_address"] == nil:
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
- return
- }
- code := dataBody["storehouse_code"].(string) //仓库编号
- name := dataBody["storehouse_name"].(string) //仓库名称
- address := dataBody["storehouse_address"].(string) //地址
- switch {
- case name == "":
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
- return
- case address == "":
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
- return
- }
-
- //判断仓库名称是否重复
- var bo bool
- bo, err = service.IsStorehouseName(orgId, name)
- if bo == true {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
- return
- }
- //判断仓库地址是否重复
- bo, err = service.IsStorehouseAddress(orgId, address)
- if bo == true {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
- return
- }
-
- storehouse := models.Storehouse{
- StorehouseCode: code,
- StorehouseName: name,
- StorehouseAddress: address,
- StorehouseStatus: storehouse_status,
- UserOrgId: orgId,
- Status: 1,
- StorehouseAdminId: admin_id,
- Ctime: time.Now().Unix(),
- }
- var shiwu string
- shiwu, err = service.AddStroehouse(storehouse)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "保存成功",
- "shiwu": shiwu,
- })
-
- return
-
- }
-
- //修改仓库
- func (this *SecondaryOrderApiController) UpdateStorehouse() {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- //orgId := this.GetAdminUserInfo().CurrentOrgId
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var storehouse_status, admin_id int64
- tmpstatus := dataBody["storehouse_status"]
- tmpid := dataBody["storehouse_admin_id"]
- if tmpstatus == nil {
- storehouse_status = 1
- } else {
- storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
- }
- if tmpid == nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
- return
- } else {
- admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
- }
-
- switch {
- case dataBody["id"] == nil:
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库id不能为空")
- return
- case dataBody["storehouse_name"] == nil:
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
- return
- case dataBody["storehouse_address"] == nil:
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
- return
- }
- id := int64(dataBody["id"].(float64))
- name := dataBody["storehouse_name"].(string) //仓库名称
- address := dataBody["storehouse_address"].(string) //地址
- //查询当前仓库状态,根据当前状态判断是否需要更改
- list, errs := service.GetOneStorehouse(id, orgId)
- if errs != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- if storehouse_status != list.StorehouseStatus && storehouse_status == 0 {
- //判断该仓库的库存是否为零
- boolean := service.IsStorehouseNil(id, orgId)
- if boolean == false {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
- return
- }
- //判断该仓库是否在仓库配置表中
- boolean = service.IsInConfig(orgId, id)
- if boolean == true {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
- return
- }
- }
- //判断仓库名称是否重复
- var bo bool
- bo, err = service.IsStorehouseNameUp(orgId, id, name)
- if bo == true {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
- return
- }
- //判断仓库地址是否重复
- bo, err = service.IsStorehouseAddressUp(orgId, id, address)
- if bo == true {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
- return
- }
- storehouse := models.Storehouse{
- ID: id,
- StorehouseName: name,
- StorehouseAddress: address,
- StorehouseStatus: storehouse_status,
- StorehouseAdminId: admin_id,
- Mtime: time.Now().Unix(),
- }
- err = service.UpdateStroehouse(storehouse)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "保存成功",
- })
- return
-
- }
-
- func (this *SecondaryOrderApiController) GetSencondeGoodList() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- houseList, _ := service.GetAllStoreHouseListThree(orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "houseList": houseList,
- })
- return
- }
-
- func (this *SecondaryOrderApiController) SaveSencondOrder() {
-
- start_date := this.GetString("record_date")
- storehouse_in_id, _ := this.GetInt64("storehouse_in_id")
- storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
- fmt.Println(storehouse_in_id, storehouse_out_id)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startDate int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startDate = theTime.Unix()
- }
- //生成购货订单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- warehousing_order := "DB1010" + timeArr[0] + timeArr[1] + timeArr[2] + fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000))
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- record_date := recordDate.Unix()
- creater := this.GetAdminUserInfo().AdminUser.Id
- warehouse := models.XtSecondWarehouse{
- SecondOrderNumber: warehousing_order,
- Creater: creater,
- RecordDate: startDate,
- Checker: 0,
- IsCheck: 2,
- UserOrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- StorehouseInId: storehouse_in_id,
- StorehouseOutId: storehouse_out_id,
- }
-
- //查询改订单号是否存在
- _, errcode := service.GetSecondWarehouseByNumber(orgId, warehousing_order)
- if errcode == gorm.ErrRecordNotFound {
- service.CreateSecondeWarehouse(warehouse)
- } else if errcode == nil {
- order := "DB1010" + timeArr[0] + timeArr[1] + timeArr[2] + fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000))
- warehouse.SecondOrderNumber = order
- service.CreateSecondeWarehouse(warehouse)
- }
-
- secondWarehouse, _ := service.GetLastSecondWarehouse(orgId)
- var warehousingInfo []*models.XtSecondWarehouseInfo
- dataBody := make(map[string]interface{}, 0)
-
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- 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["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
- utils.ErrorLog("project_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- project_id := int64(items["project_id"].(float64))
-
- if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
- utils.ErrorLog("name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- project_name := items["name"].(string)
-
- if items["project_type"] == nil || reflect.TypeOf(items["project_type"]).String() != "string" {
- utils.ErrorLog("project_type")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- project_type := items["project_type"].(string)
-
- if items["second_specification_name"] == nil || reflect.TypeOf(items["second_specification_name"]).String() != "string" {
- utils.ErrorLog("second_specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- second_specification_name := items["second_specification_name"].(string)
-
- if items["sencond_unit"] == nil || reflect.TypeOf(items["sencond_unit"]).String() != "string" {
- utils.ErrorLog("sencond_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- sencond_unit := items["sencond_unit"].(string)
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
- utils.ErrorLog("count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count := int64(items["count"].(float64))
-
- if items["is_source"] == nil || reflect.TypeOf(items["is_source"]).String() != "float64" {
- utils.ErrorLog("is_source")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- is_source := int64(items["is_source"].(float64))
-
- if items["second_total"] == nil || reflect.TypeOf(items["second_total"]).String() != "string" {
- utils.ErrorLog("second_total")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- second_total := items["second_total"].(string)
-
- if items["remake"] == nil || reflect.TypeOf(items["remake"]).String() != "string" {
- utils.ErrorLog("remake")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- remake := items["remake"].(string)
-
- if items["min_price"] == nil || reflect.TypeOf(items["min_price"]).String() != "float64" {
- utils.ErrorLog("min_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- min_price := items["min_price"].(float64)
-
- info := &models.XtSecondWarehouseInfo{
- ProjectName: project_name,
- SecondSpecificationName: second_specification_name,
- ProjectType: project_type,
- SencondUnit: sencond_unit,
- Count: count,
- SecondTotal: second_total,
- SecondOrderNumber: secondWarehouse.SecondOrderNumber,
- RecordDate: record_date,
- StorehouseInId: storehouse_in_id,
- StorehouseOutId: storehouse_out_id,
- Creater: creater,
- ProjectId: project_id,
- Remake: remake,
- UserOrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- MinPrice: min_price,
- IsSource: is_source,
- WarehouseId: secondWarehouse.ID,
- }
-
- warehousingInfo = append(warehousingInfo, info)
- }
- }
- }
-
- for _, item := range warehousingInfo {
- service.CreateSencondWarehousingInfo(item)
- }
-
- //获取最后一条入库单
- lastSecondWarehouse, _ := service.GetLastSecondWarehouse(orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "warehousingInfo": warehousingInfo,
- "id": lastSecondWarehouse.ID,
- })
- return
- }
-
- func (this *SecondaryOrderApiController) GetAllSecondeOrderList() {
-
- check_id, _ := this.GetInt64("check_id")
- start_time := this.GetString("start_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 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- end_time := this.GetString("end_time")
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- keyword := this.GetString("keyword")
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, total, _ := service.GetAllSecondeOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
- houseList, _ := service.GetAllStoreHouseList(orgId)
- appId := this.GetAdminUserInfo().CurrentAppId
- doctor, _ := service.GetAllDoctorListSix(orgId, appId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "houseList": houseList,
- "doctorList": doctor,
- })
- return
- }
-
- func (this *SecondaryOrderApiController) GetSencondOrderDetail() {
-
- id, _ := this.GetInt64("id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- warehouse, _ := service.GetSecondWarehouseOrderById(id)
-
- //获取药品库数据
- baseList, _ := service.GetSupplyDrugListOne(orgId, warehouse.StorehouseOutId)
-
- goodList, _ := service.GetSupplyGoodListOne(orgId, warehouse.StorehouseOutId)
-
- goodTypeList, _ := service.GetAllGoodType(orgId)
-
- configlist, _ := service.GetAllStoreHouseConfig(orgId)
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
-
- list, _ := service.GetSencondOrderDetail(id, orgId)
-
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "warehouse": warehouse,
- "drugList": baseList,
- "goodList": goodList,
- "goodTypeList": goodTypeList,
- "drugTypeList": drugTypeList,
- "configlist": configlist,
- "manufacturerList": manufacturerList,
- })
- return
- }
-
- func (this *SecondaryOrderApiController) UpdateSencondOrder() {
-
- warehouse_id, _ := this.GetInt64("id")
- start_date := this.GetString("record_date")
- storehouse_in_id, _ := this.GetInt64("storehouse_in_id")
- storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
- fmt.Println(storehouse_in_id, storehouse_out_id)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startDate int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startDate = theTime.Unix()
- }
-
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- record_date := recordDate.Unix()
- orgId := this.GetAdminUserInfo().CurrentOrgId
- creater := this.GetAdminUserInfo().AdminUser.Id
- warehouse := models.XtSecondWarehouse{
- StorehouseInId: storehouse_in_id,
- StorehouseOutId: storehouse_out_id,
- RecordDate: startDate,
- }
-
- service.UpdateModifySecondWarehouse(warehouse_id, warehouse)
-
- warehouseInfo, _ := service.GetSecondWarehouseOrderById(warehouse_id)
- var warehousingInfo []*models.XtSecondWarehouseInfo
-
- var updateWarehousingInfo []*models.XtSecondWarehouseInfo
- dataBody := make(map[string]interface{}, 0)
-
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- 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["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- id := int64(items["id"].(float64))
-
- if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
- utils.ErrorLog("project_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- project_id := int64(items["project_id"].(float64))
-
- if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
- utils.ErrorLog("name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- project_name := items["name"].(string)
-
- if items["project_type"] == nil || reflect.TypeOf(items["project_type"]).String() != "string" {
- utils.ErrorLog("project_type")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- project_type := items["project_type"].(string)
-
- if items["second_specification_name"] == nil || reflect.TypeOf(items["second_specification_name"]).String() != "string" {
- utils.ErrorLog("second_specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- second_specification_name := items["second_specification_name"].(string)
-
- if items["sencond_unit"] == nil || reflect.TypeOf(items["sencond_unit"]).String() != "string" {
- utils.ErrorLog("sencond_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- sencond_unit := items["sencond_unit"].(string)
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
- utils.ErrorLog("count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count := int64(items["count"].(float64))
-
- if items["is_source"] == nil || reflect.TypeOf(items["is_source"]).String() != "float64" {
- utils.ErrorLog("is_source")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- is_source := int64(items["is_source"].(float64))
-
- if items["second_total"] == nil || reflect.TypeOf(items["second_total"]).String() != "string" {
- utils.ErrorLog("second_total")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- second_total := items["second_total"].(string)
-
- if items["remake"] == nil || reflect.TypeOf(items["remake"]).String() != "string" {
- utils.ErrorLog("remake")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- remake := items["remake"].(string)
-
- if items["min_price"] == nil || reflect.TypeOf(items["min_price"]).String() != "float64" {
- utils.ErrorLog("min_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- min_price := items["min_price"].(float64)
-
- if id == 0 {
- info := &models.XtSecondWarehouseInfo{
- ProjectName: project_name,
- SecondSpecificationName: second_specification_name,
- ProjectType: project_type,
- SencondUnit: sencond_unit,
- Count: count,
- SecondTotal: second_total,
- RecordDate: record_date,
- StorehouseInId: storehouse_in_id,
- StorehouseOutId: storehouse_out_id,
- Creater: creater,
- ProjectId: project_id,
- Remake: remake,
- UserOrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- MinPrice: min_price,
- IsSource: is_source,
- WarehouseId: warehouse_id,
- SecondOrderNumber: warehouseInfo.SecondOrderNumber,
- }
- warehousingInfo = append(warehousingInfo, info)
- }
-
- if id > 0 {
- updateInfo := &models.XtSecondWarehouseInfo{
- ID: id,
- ProjectName: project_name,
- SecondSpecificationName: second_specification_name,
- ProjectType: project_type,
- SencondUnit: sencond_unit,
- Count: count,
- SecondTotal: second_total,
- SecondOrderNumber: warehouse.SecondOrderNumber,
- RecordDate: record_date,
- StorehouseInId: storehouse_in_id,
- StorehouseOutId: storehouse_out_id,
- Creater: creater,
- ProjectId: project_id,
- Remake: remake,
- UserOrgId: orgId,
- MinPrice: min_price,
- IsSource: is_source,
- }
- updateWarehousingInfo = append(updateWarehousingInfo, updateInfo)
- }
-
- }
- }
- }
-
- for _, item := range warehousingInfo {
- service.CreateSencondWarehousingInfo(item)
- }
-
- for _, item := range updateWarehousingInfo {
- service.UpdateStoreWarehousing(item)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "warehousingInfo": warehousingInfo,
- })
- return
- }
-
- func (this *SecondaryOrderApiController) GetSecondOrderById() {
-
- id, _ := this.GetInt64("id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- warehouse, _ := service.GetSecondWarehouseOrderById(id)
- list, _ := service.GetSencondOrderDetail(id, orgId)
- appId := this.GetAdminUserInfo().CurrentAppId
- doctor, _ := service.GetAllDoctorSix(orgId, appId)
- houseList, _ := service.GetAllStoreHouseList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "warehouse": warehouse,
- "list": list,
- "doctorList": doctor,
- "houseList": houseList,
- })
- return
- }
-
- func (this *SecondaryOrderApiController) CheckSecondOrer() {
-
- ids := this.GetString("ids")
- if len(ids) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- creater := this.GetAdminUserInfo().AdminUser.Id
-
- //根据订单id获取商品详情
- list, _ := service.GetSecondOrderList(idArray, orgId)
- for _, item := range list {
- if item.IsSource == 1 {
-
- medical, _ := service.GetBaseDrugMedical(item.ProjectId)
- //查询该仓库的药品库存是否满足调出数量
- drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
- var total int64
- var total_count int64
- for _, it := range drugInfoList {
- if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
- it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
- }
- }
- for _, it := range drugInfoList {
- total += it.StockMaxNumber + it.StockMinNumber
- }
- if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- total_count = item.Count * medical.MinNumber
- }
- if item.SencondUnit == medical.MinUnit {
- total_count = item.Count
- }
-
- if total_count > total {
- goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
- storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseOutId, item.UserOrgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "drug_name": goodObj.DrugName,
- "dose": goodObj.Dose,
- "dose_unit": goodObj.DoseUnit,
- "min_number": goodObj.MinNumber,
- "min_unit": goodObj.MinUnit,
- "max_unit": goodObj.MaxUnit,
- "storehose_name": storehouse.StorehouseName,
- })
- return
- }
- }
-
- if item.IsSource == 2 {
- //查询该仓库的耗材库存是否满足调出数量
- var total int64
- infoList, _ := service.GetWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
- for _, it := range infoList {
- total += it.StockCount
- }
- if item.Count > total {
- storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseOutId, item.UserOrgId)
- goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- "storehose_name": storehouse.StorehouseName,
- })
- return
- }
- }
-
- }
- err := service.UpdateStoreOrderByArray(idArray, orgId, creater)
- //如果审核成功
- if err == nil {
- //调用出库接口
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(orgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(orgId, 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 := this.GetAdminUserInfo().AdminUser.Id
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- record_date := recordDate.Unix()
-
- totals, _ := service.FindAllWarehouseTotal(orgId)
- totals = totals + 1
- warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(totals, 10)
-
- for _, item := range list {
- //药品
- if item.IsSource == 1 {
- medical, _ := service.GetBaseDrugMedical(item.ProjectId)
- //查询该仓库的药品库存是否满足调出数量
- drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
- var total int64
- var total_count int64
- for _, it := range drugInfoList {
- if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
- it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
- }
- }
- for _, it := range drugInfoList {
- total += it.StockMaxNumber + it.StockMinNumber
- }
- if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- total_count = item.Count * medical.MinNumber
- }
- if item.SencondUnit == medical.MinUnit {
- total_count = item.Count
- }
-
- if total_count <= total {
-
- drug_total, _ := service.FindAllDrugWarehouseOut(orgId)
-
- drug_total = drug_total + 1
- drug_warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(drug_warehousing_out_order, 10, 64)
- number = number + drug_total
- drug_warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
-
- drugWarehouseOut := models.DrugWarehouseOut{
- WarehouseOutOrderNumber: drug_warehousing_out_order,
- OperationTime: operation_time,
- OrgId: orgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: record_date,
- Type: 2,
- StorehouseId: item.StorehouseOutId,
- SecondWarehouseId: item.WarehouseId,
- IsSys: 12,
- IsCheck: 1,
- }
- _, drugerrcodes := service.GetDrugWarehouseBySyS(orgId, 12, item.WarehouseId, record_date)
-
- if drugerrcodes == gorm.ErrRecordNotFound {
- service.AddSigleDrugWarehouseOut(&drugWarehouseOut)
- }
-
- drugOut, _ := service.GetLastDrugWarehouseOutById(12, item.WarehouseId, orgId, record_date)
-
- warehouseOutInfo := &models.DrugWarehouseOutInfo{
- WarehouseOutOrderNumber: drugOut.WarehouseOutOrderNumber,
- WarehouseOutId: drugOut.ID,
- DrugId: item.ProjectId,
- Count: item.Count,
- Price: medical.RetailPrice,
- TotalPrice: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: item.Remake,
- OrgId: orgId,
- Type: 2,
- Manufacturer: 0,
- Dealer: 0,
- RetailPrice: item.MinPrice,
- RetailTotalPrice: 0,
- CountUnit: item.SencondUnit,
- ExpiryDate: 0,
- ProductDate: 0,
- Number: "",
- BatchNumber: "",
- IsSys: 0,
- WarehouseInfoId: 0,
- StorehouseId: item.StorehouseOutId,
- SecondWarehouseInfoId: item.ID,
- IsCheck: 1,
- }
- drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
-
- drug_in_total, _ := service.FindAllWarehouseTotalOne(orgId)
- drug_in_total = drug_in_total + 1
-
- warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(drug_in_total, 10)
-
- drug_warehousing := models.DrugWarehouse{
- WarehousingOrder: warehousing_order,
- OperationTime: operation_time,
- OrgId: orgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehousingTime: record_date,
- Type: 1,
- StorehouseId: item.StorehouseInId,
- IsSys: 13,
- SecondWarehouseId: item.WarehouseId,
- IsCheck: 1,
- }
-
- //查询该调拨单是否有生成入库单
- _, drugerrcodess := service.GetDrugWarehouseingBySys(13, item.WarehouseId, orgId, record_date)
- if drugerrcodess == gorm.ErrRecordNotFound {
- service.CreateDrugWaresing(drug_warehousing)
- }
-
- drugInfoObj, _ := service.GetLastDrugWarehouseBySys(13, item.WarehouseId, orgId, record_date)
-
- drugwarehouseInfo := &models.DrugWarehouseInfo{
- WarehousingOrder: drugInfoObj.WarehousingOrder,
- WarehousingId: drugInfoObj.ID,
- DrugId: item.ProjectId,
- Number: "",
- ProductDate: 0,
- ExpiryDate: 0,
- WarehousingCount: 0,
- Price: 0,
- TotalPrice: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: orgId,
- Type: 2,
- Manufacturer: 0,
- Dealer: 0,
- StockMaxNumber: 0,
- RetailTotalPrice: 0,
- BatchNumber: "",
- MaxUnit: "",
- MinUnit: "",
- RetailPrice: 0,
- StorehouseId: item.StorehouseInId,
- SecondWarehouseInfoId: item.ID,
- IsCheck: 1,
- }
- service.AutoDrugDeliverInfoTwelve(orgId, item.Count, &drugWarehouseOut, &drup, warehouseOutInfo, drugwarehouseInfo)
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- //更新字典里面的库存
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.ProjectId)
- var sum_count int64
- for _, its := range stockInfo {
- baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
- if its.MaxUnit == baseDrug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
- }
-
- //查询该药品该仓库是否有数据
- drug, _ := service.GetDrugStockCout(item.ProjectId, item.StorehouseInId, item.UserOrgId)
- var sum_out_count int64
- baseDrug, _ := service.GetBaseDrugMedical(item.ProjectId)
- if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
- sum_out_count = item.Count * baseDrug.MinNumber
- }
- if item.SencondUnit == baseDrug.MinUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
- sum_out_count = item.Count
- }
-
- if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit == baseDrug.MinUnit {
- sum_out_count = item.Count
- }
- if drug.ID == 0 {
- drugstock := models.XtDrugStockCount{
- UserOrgId: orgId,
- StorehouseId: item.StorehouseInId,
- SumInCount: sum_out_count,
- SumOutCount: 0,
- SumCancelCount: 0,
- DrugId: item.ProjectId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- FlushCount: sum_out_count,
- SumActOutCount: 0,
- }
- service.CreateDrugStockCount(drugstock)
- }
-
- if drug.ID > 0 {
-
- service.AddDrugStockCount(item.StorehouseInId, item.ProjectId, item.UserOrgId, sum_out_count)
- }
-
- //更新出库数据
- service.ReduceDrugStockCountSix(item.StorehouseOutId, item.ProjectId, item.UserOrgId, sum_out_count)
- }
-
- //耗材
- if item.IsSource == 2 {
-
- //查询该仓库的耗材库存是否满足调出数量
- var total int64
- infoList, _ := service.GetWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
- for _, it := range infoList {
- total += it.StockCount
- }
- //满足调拨
- if item.Count <= total {
- goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: orgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: record_date,
- Type: 1,
- StorehouseId: item.StorehouseOutId,
- IsSys: 12,
- SecondWarehouseId: item.WarehouseId,
- IsCheck: 1,
- }
-
- //查询今日是否存在调拨出库
- _, errcodes := service.FindStockOutByIsSysSix(orgId, 12, record_date, item.WarehouseId)
- if errcodes == gorm.ErrRecordNotFound {
- service.AddSigleWarehouseOut(&warehouseOut)
- }
-
- out, _ := service.GetLastWarehouseOutBySys(12, orgId, record_date, item.WarehouseId)
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- GoodId: item.ProjectId,
- GoodTypeId: goodObj.GoodTypeId,
- Count: item.Count,
- Price: item.MinPrice,
- TotalPrice: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: item.Remake,
- OrgId: orgId,
- Type: 1,
- Manufacturer: 0,
- Number: "",
- ExpiryDate: 0,
- ProductDate: 0,
- Dealer: 0,
- LicenseNumber: "",
- WarehouseInfotId: 0,
- StorehouseId: item.StorehouseOutId,
- SecondWarehouseInfoId: item.ID,
- IsCheck: 1,
- }
-
- //入库操作
- warehousing := models.Warehousing{
- WarehousingOrder: warehousing_order,
- OperationTime: operation_time,
- OrgId: orgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehousingTime: record_date,
- Type: 1,
- StorehouseId: item.StorehouseInId,
- IsSys: 12,
- SecondWarehouseId: item.WarehouseId,
- IsCheck: 1,
- }
- //查询该调拨单是否有生成入库单
- _, errcodess := service.GetWarehouseBySecondWarehouseId(12, item.WarehouseId, orgId, record_date)
- if errcodess == gorm.ErrRecordNotFound {
- service.AddSigleWarehouse(&warehousing)
- }
- infoObj, _ := service.GetLastWarehouseById(12, item.WarehouseId, orgId, record_date)
-
- warehouseInfo := &models.WarehousingInfo{
- WarehousingOrder: infoObj.WarehousingOrder,
- WarehousingId: infoObj.ID,
- GoodId: item.ProjectId,
- Number: "",
- GoodTypeId: goodObj.GoodTypeId,
- ProductDate: 0,
- ExpiryDate: 0,
- WarehousingCount: item.Count,
- Price: goodObj.BuyPrice,
- TotalPrice: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: item.Remake,
- OrgId: orgId,
- Type: 1,
- Manufacturer: 0,
- StockCount: item.Count,
- Dealer: 0,
- LicenseNumber: "",
- PackingPrice: item.MinPrice,
- StorehouseId: item.StorehouseInId,
- SecondWarehouseInfoId: item.ID,
- IsCheck: 1,
- }
-
- //出库逻辑
- parseDateErr := service.ConsumablesDeliveryTwelve(orgId, record_date, warehouseOutInfo, &warehouseOut, item.Count, creater, warehouseInfo)
- fmt.Println(parseDateErr)
-
- }
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- stockList, _ := service.GetStockCountByGoodId(item.ProjectId, storeHouseConfig.StorehouseOutInfo, orgId)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoSumCountSix(item.ProjectId, total_count, orgId)
-
- //查询是否有数据
- _, errcodes := service.GetStockFlush(item.StorehouseInId, item.ProjectId, item.UserOrgId)
- if errcodes == gorm.ErrRecordNotFound {
- good := models.XtGoodStockCount{
- UserOrgId: item.UserOrgId,
- GoodId: item.ProjectId,
- StorehouseId: item.StorehouseInId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- StockInCount: item.Count,
- StockOutCount: 0,
- StockCancelCount: 0,
- FlushCount: item.Count,
- StockActOutCount: 0,
- }
- service.CreateGoodCountSix(good)
- } else if errcodes == nil {
-
- service.AddGoodStockCount(item.StorehouseInId, item.ProjectId, item.UserOrgId, item.Count)
- }
-
- //更新出库数据
- service.ReduceStockCount(item.StorehouseOutId, item.ProjectId, item.UserOrgId, item.Count)
-
- }
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": 1,
- })
- return
- }
-
- func (this *SecondaryOrderApiController) DeleteStorehouseList() {
-
- id, _ := this.GetInt64("id")
- err := service.DeleteStorehouseList(id)
- if err == nil {
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
-
- ids := this.GetString("ids")
-
- if len(ids) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- //根据订单id获取商品详情
- list, _ := service.GetSecondOrderList(idArray, orgId)
- //药品
- for _, item := range list {
- //药品
- if item.IsSource == 1 {
-
- medical, _ := service.GetBaseDrugMedical(item.ProjectId)
- //查询该仓库的药品库存是否满足调出数量
- drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
- var total int64
- var total_count int64
- for _, it := range drugInfoList {
- if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
- it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
- }
- }
- for _, it := range drugInfoList {
- total += it.StockMaxNumber + it.StockMinNumber
- }
- if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- total_count = item.Count * medical.MinNumber
- }
- if item.SencondUnit == medical.MinUnit {
- total_count = item.Count
- }
-
- if total_count > total {
-
- goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
- storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "drug_name": goodObj.DrugName,
- "dose": goodObj.Dose,
- "dose_unit": goodObj.DoseUnit,
- "min_number": goodObj.MinNumber,
- "min_unit": goodObj.MinUnit,
- "max_unit": goodObj.MaxUnit,
- "storehose_name": storehouse.StorehouseName,
- })
- return
- }
- }
-
- //耗材
- if item.IsSource == 2 {
- //查询该仓库的耗材库存是否满足调出数量
- var total int64
- infoList, _ := service.GetWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
- for _, it := range infoList {
- total += it.StockCount
- }
- if item.Count > total {
- storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
- goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- "storehose_name": storehouse.StorehouseName,
- })
- return
- }
- }
- }
- //反审核操作
- err := service.ModifyStoreHouseById(idArray, orgId)
- if err != nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "0",
- })
- return
- }
-
- for _, item := range list {
-
- //药品
- if item.IsSource == 1 {
-
- medical, _ := service.GetBaseDrugMedical(item.ProjectId)
- //查询该仓库的药品库存是否满足调出数量
- drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
- var total int64
- var total_count int64
- for _, it := range drugInfoList {
- if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
- it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
- }
- }
- for _, it := range drugInfoList {
- total += it.StockMaxNumber + it.StockMinNumber
- }
- if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- total_count = item.Count * medical.MinNumber
- }
- if item.SencondUnit == medical.MinUnit {
- total_count = item.Count
- }
-
- fmt.Println("total_count2332232333233223", total_count)
- fmt.Println("totoal2323232332322332", total)
- if total_count <= total {
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- creater := this.GetAdminUserInfo().AdminUser.Id
- drug_total, _ := service.FindAllDrugWarehouseOut(orgId)
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- record_date := recordDate.Unix()
- drug_total = drug_total + 1
- drug_warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(drug_warehousing_out_order, 10, 64)
- number = number + drug_total
- drug_warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
-
- drugWarehouseOut := models.DrugWarehouseOut{
- WarehouseOutOrderNumber: drug_warehousing_out_order,
- OperationTime: operation_time,
- OrgId: orgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: record_date,
- Type: 2,
- StorehouseId: item.StorehouseInId,
- SecondWarehouseId: item.WarehouseId,
- IsSys: 12,
- IsCheck: 1,
- }
- _, drugerrcodes := service.GetDrugWarehouseBySyS(orgId, 12, item.WarehouseId, record_date)
-
- if drugerrcodes == gorm.ErrRecordNotFound {
- service.AddSigleDrugWarehouseOut(&drugWarehouseOut)
- }
-
- drugOut, _ := service.GetLastDrugWarehouseOutById(12, item.WarehouseId, orgId, record_date)
-
- warehouseOutInfo := &models.DrugWarehouseOutInfo{
- WarehouseOutOrderNumber: drugOut.WarehouseOutOrderNumber,
- WarehouseOutId: drugOut.ID,
- DrugId: item.ProjectId,
- Count: item.Count,
- Price: medical.RetailPrice,
- TotalPrice: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: item.Remake,
- OrgId: orgId,
- Type: 2,
- Manufacturer: 0,
- Dealer: 0,
- RetailPrice: item.MinPrice,
- RetailTotalPrice: 0,
- CountUnit: item.SencondUnit,
- ExpiryDate: 0,
- ProductDate: 0,
- Number: "",
- BatchNumber: "",
- IsSys: 0,
- WarehouseInfoId: 0,
- StorehouseId: item.StorehouseInId,
- SecondWarehouseInfoId: item.ID,
- IsCheck: 1,
- }
- drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
-
- drug_in_total, _ := service.FindAllWarehouseTotalOne(orgId)
- drug_in_total = drug_in_total + 1
-
- warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(drug_in_total, 10)
-
- drug_warehousing := models.DrugWarehouse{
- WarehousingOrder: warehousing_order,
- OperationTime: operation_time,
- OrgId: orgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehousingTime: record_date,
- Type: 1,
- StorehouseId: item.StorehouseOutId,
- IsSys: 13,
- SecondWarehouseId: item.WarehouseId,
- IsCheck: 1,
- }
-
- //查询该调拨单是否有生成入库单
- _, drugerrcodess := service.GetDrugWarehouseingBySys(13, item.WarehouseId, orgId, record_date)
- if drugerrcodess == gorm.ErrRecordNotFound {
- service.CreateDrugWaresing(drug_warehousing)
- }
-
- drugInfoObj, _ := service.GetLastDrugWarehouseBySys(13, item.WarehouseId, orgId, record_date)
-
- drugwarehouseInfo := &models.DrugWarehouseInfo{
- WarehousingOrder: drugInfoObj.WarehousingOrder,
- WarehousingId: drugInfoObj.ID,
- DrugId: item.ProjectId,
- Number: "",
- ProductDate: 0,
- ExpiryDate: 0,
- WarehousingCount: 0,
- Price: 0,
- TotalPrice: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: orgId,
- Type: 2,
- Manufacturer: 0,
- Dealer: 0,
- StockMaxNumber: 0,
- RetailTotalPrice: 0,
- BatchNumber: "",
- MaxUnit: "",
- MinUnit: "",
- RetailPrice: 0,
- StorehouseId: item.StorehouseOutId,
- SecondWarehouseInfoId: item.ID,
- IsCheck: 1,
- }
- fmt.Println("尽力发的233223323232")
- service.AutoDrugDeliverInfoTwelve(orgId, item.Count, &drugWarehouseOut, &drup, warehouseOutInfo, drugwarehouseInfo)
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- //更新字典里面的库存
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.ProjectId)
- var sum_count int64
- for _, its := range stockInfo {
- baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
- if its.MaxUnit == baseDrug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
-
- //回退库存,查询该订单出库记录
- //drugOutList, _ := service.GetStoreDrugWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
- //for _, it := range drugOutList {
- //
- // if medical.MaxUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
- // //回退库存
- // service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
- // }
- //
- // if medical.MaxUnit == it.CountUnit && medical.MaxUnit == medical.MinUnit {
- // //回退库存
- // service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
- // }
- //
- // if medical.MinUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
- //
- // service.ModifyDrugStoreWarehouseInfoOne(it.WarehouseInfoId, it.Count)
- // }
- //
- // //查询入库单
- // //storeWareing, _ := service.GetStoreDrugWarehouseById(item.WarehouseId, it.OrgId)
- // //删除入库单
- // //service.DeleteStoreWarehousingId(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
- //
- // //查询出单
- // //storeWarehouseOut, _ := service.GetStoreDrugWarehouseOutById(it.WarehouseOutId, it.OrgId)
- //
- // //删除出库单
- // //service.DeleteStoreWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
- //}
-
- }
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- var sum_count int64
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.ProjectId)
- for _, its := range stockInfo {
- baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
- if its.MaxUnit == baseDrug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
-
- var sum_out_count int64
- baseDrug, _ := service.GetBaseDrugMedical(item.ProjectId)
- if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
- sum_out_count = item.Count * baseDrug.MinNumber
- }
- if item.SencondUnit == baseDrug.MinUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
- sum_out_count = item.Count
- }
-
- if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit == baseDrug.MinUnit {
- sum_out_count = item.Count
- }
- //入库仓库减少
- service.ReduceDrugStockCountSeven(item.StorehouseInId, item.ProjectId, item.UserOrgId, sum_out_count)
-
- //出库仓库增加
- service.AddDrugStockCount(item.StorehouseOutId, item.ProjectId, item.UserOrgId, sum_out_count)
- }
-
- //耗材
- if item.IsSource == 2 {
- //查询该仓库的耗材库存是否满足调出数量
- var total int64
- infoList, _ := service.GetWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
- for _, it := range infoList {
- total += it.StockCount
- }
- //满足调拨
- if item.Count <= total {
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(orgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(orgId, 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 := this.GetAdminUserInfo().AdminUser.Id
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- record_date := recordDate.Unix()
-
- totals, _ := service.FindAllWarehouseTotal(orgId)
- totals = totals + 1
- warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(totals, 10)
- //创建出库单
- goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: orgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: record_date,
- Type: 1,
- StorehouseId: item.StorehouseInId,
- IsSys: 12,
- SecondWarehouseId: item.WarehouseId,
- IsCheck: 1,
- }
-
- //查询今日是否存在调拨出库
- _, errcodes := service.FindStockOutByIsSysSix(orgId, 12, record_date, item.WarehouseId)
- if errcodes == gorm.ErrRecordNotFound {
- service.AddSigleWarehouseOut(&warehouseOut)
- }
-
- out, _ := service.GetLastWarehouseOutBySys(12, orgId, record_date, item.WarehouseId)
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- GoodId: item.ProjectId,
- GoodTypeId: goodObj.GoodTypeId,
- Count: item.Count,
- Price: item.MinPrice,
- TotalPrice: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: item.Remake,
- OrgId: orgId,
- Type: 1,
- Manufacturer: 0,
- Number: "",
- ExpiryDate: 0,
- ProductDate: 0,
- Dealer: 0,
- LicenseNumber: "",
- WarehouseInfotId: 0,
- StorehouseId: item.StorehouseInId,
- SecondWarehouseInfoId: item.ID,
- IsCheck: 1,
- }
-
- //入库操作
- warehousing := models.Warehousing{
- WarehousingOrder: warehousing_order,
- OperationTime: operation_time,
- OrgId: orgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehousingTime: record_date,
- Type: 1,
- StorehouseId: item.StorehouseOutId,
- IsSys: 12,
- SecondWarehouseId: item.WarehouseId,
- IsCheck: 1,
- }
- //查询该调拨单是否有生成入库单
- _, errcodess := service.GetWarehouseBySecondWarehouseId(12, item.WarehouseId, orgId, record_date)
- if errcodess == gorm.ErrRecordNotFound {
- service.AddSigleWarehouse(&warehousing)
- }
- infoObj, _ := service.GetLastWarehouseById(12, item.WarehouseId, orgId, record_date)
-
- warehouseInfo := &models.WarehousingInfo{
- WarehousingOrder: infoObj.WarehousingOrder,
- WarehousingId: infoObj.ID,
- GoodId: item.ProjectId,
- Number: "",
- GoodTypeId: goodObj.GoodTypeId,
- ProductDate: 0,
- ExpiryDate: 0,
- WarehousingCount: item.Count,
- Price: goodObj.BuyPrice,
- TotalPrice: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: item.Remake,
- OrgId: orgId,
- Type: 1,
- Manufacturer: 0,
- StockCount: item.Count,
- Dealer: 0,
- LicenseNumber: "",
- PackingPrice: item.MinPrice,
- StorehouseId: item.StorehouseOutId,
- SecondWarehouseInfoId: item.ID,
- IsCheck: 1,
- }
-
- //出库逻辑
- parseDateErr := service.ConsumablesDeliveryTwelve(orgId, record_date, warehouseOutInfo, &warehouseOut, item.Count, creater, warehouseInfo)
- fmt.Println(parseDateErr)
-
- //回退库存,查询该订单出库记录
- //outList, _ := service.GetStoreWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
- //for _, it := range outList {
- // //回退库存
- // service.ModifyStoreWarehouseById(it.WarehouseInfotId, it.Count)
- //
- // //获取入库单
- // //storeWareing, _ := service.GetStoreWarehouseById(item.WarehouseId, it.OrgId)
- // //删除入库单 入库流水
- // //service.ModifyStoreWarehouse(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
- // //获取出库单
- // //storeWarehouseOut, _ := service.GetStoreWarehouseOutById(it.WarehouseOutId, it.OrgId)
- // //删除出库单
- // //service.ModifyWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
- //}
- }
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- stockList, _ := service.GetStockCountByGoodId(item.ProjectId, storeHouseConfig.StorehouseOutInfo, orgId)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoSumCount(item.ProjectId, total_count, orgId)
-
- //入库仓库减少
- service.ReduceStockCountTwo(item.StorehouseInId, item.ProjectId, item.UserOrgId, item.Count)
-
- //出库仓库增加
- service.AddGoodStockCount(item.StorehouseOutId, item.ProjectId, item.UserOrgId, item.Count)
- }
- }
-
- ////获取所有的入库仓库
- //druglist, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
- //for _, item := range druglist {
- // //查询该药品该仓库是否有数据
- // drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
- //
- // //查询该仓库该药品的入库数量
- // medical, _ := service.GetBaseDrugMedical(item.DrugId)
- //
- // var sum_in_count int64
- // var flush_count int64
- // var sum_out_count int64
- // var cancel_out_count int64
- // //查询入库数量和剩余库存
- // infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
- // for _, it := range infolist {
- // if it.MaxUnit == medical.MaxUnit {
- // it.WarehousingCount = it.WarehousingCount * medical.MinNumber
- // it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
- // }
- // sum_in_count += it.WarehousingCount
- // flush_count += it.StockMaxNumber + it.StockMinNumber
- // }
- //
- // //获取出库数量
- // outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
- // for _, it := range outinfolist {
- // if it.MaxUnit == medical.MaxUnit {
- // it.Count = it.Count * medical.MinNumber
- // }
- // sum_out_count += it.Count
- // }
- //
- // //获取退库数量
- // cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
- // for _, it := range cancelinfolist {
- // if it.MaxUnit == medical.MaxUnit {
- // it.Count = it.Count * medical.MinNumber
- // }
- // cancel_out_count += it.Count
- // }
- //
- // //新增
- // if drug.ID == 0 {
- // drugstock := models.XtDrugStockCount{
- // UserOrgId: orgId,
- // StorehouseId: item.StorehouseId,
- // SumInCount: sum_in_count,
- // SumOutCount: sum_out_count - cancel_out_count,
- // SumCancelCount: cancel_out_count,
- // DrugId: item.DrugId,
- // Ctime: time.Now().Unix(),
- // Mtime: 0,
- // Status: 1,
- // FlushCount: flush_count,
- // SumActOutCount: sum_out_count,
- // }
- // service.CreateDrugStockCount(drugstock)
- // }
- //}
-
- ////获取入库数据
- //goodlist, _ := service.GetSendGoodInformation(orgId)
- //for _, it := range goodlist {
- // //查询是否有数据
- // _, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
- // //获取总退库数量
- // var cancel_count int64
- // var out_count int64
- // var act_count int64
- // //退库总数量
- // cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
- // for _, item := range cancellist {
- // cancel_count += item.Count
- // }
- // //出库总数量
- // outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
- // for _, item := range outlist {
- // out_count += item.Count
- // }
- //
- // //实际出库总数量
- // actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
- // for _, item := range actlist {
- // act_count += item.Count
- // }
- //
- // if errcode == gorm.ErrRecordNotFound {
- // good := models.XtGoodStockCount{
- // UserOrgId: it.OrgId,
- // GoodId: it.GoodId,
- // StorehouseId: it.StorehouseId,
- // Status: 1,
- // Ctime: time.Now().Unix(),
- // Mtime: 0,
- // StockInCount: it.WarehousingCount,
- // StockOutCount: out_count - cancel_count,
- // StockCancelCount: cancel_count,
- // FlushCount: it.StockCount,
- // StockActOutCount: act_count,
- // }
- // service.CreateGoodCountSix(good)
- // }
- // if errcode == nil {
- // service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
- // }
- //}
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- })
- return
- }
-
- func (this *SecondaryOrderApiController) GetStoreHouseGoodList() {
-
- storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- //获取药品库数据
- baseList, _ := service.GetSupplyDrugListOne(orgId, storehouse_out_id)
-
- goodList, _ := service.GetSupplyGoodListOne(orgId, storehouse_out_id)
-
- goodTypeList, _ := service.GetAllGoodType(orgId)
-
- configlist, _ := service.GetAllStoreHouseConfig(orgId)
-
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "drugList": baseList,
- "goodList": goodList,
- "goodTypeList": goodTypeList,
- "drugTypeList": drugTypeList,
- "configlist": configlist,
- "manufacturerList": manufacturerList,
- })
- return
- }
-
- func (this *SecondaryOrderApiController) GetSumSecondCount() {
-
- project_id, _ := this.GetInt64("project_id")
- sencond_unit := this.GetString("sencond_unit")
-
- is_source, _ := this.GetInt64("is_source")
- count, _ := this.GetInt64("count")
- storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- var sum_in_count int64
- var sum_count int64
- //药品
- if is_source == 1 {
-
- medical, _ := service.GetBaseDrugMedical(project_id)
- fmt.Println("senconde_unit233223", sencond_unit)
- if sencond_unit == medical.MaxUnit {
- sum_in_count = count * medical.MinNumber
- }
- if sencond_unit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- sum_in_count = count
- }
- //查询该药品剩余的库存
- secondCountList, _ := service.GetDrugSumSecondCount(project_id, storehouse_out_id, orgId)
-
- for _, it := range secondCountList {
- if it.MaxUnit == medical.MaxUnit {
- sum_count += (it.StockMaxNumber * medical.MinNumber) + it.StockMinNumber
- }
- if it.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- sum_count += (it.StockMaxNumber + it.StockMinNumber)
- }
- }
- fmt.Println("sum_iin_coutn23232323", sum_in_count)
- fmt.Println("sum_count", sum_count)
- if sum_in_count > sum_count {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- })
- return
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- })
- return
- }
- }
-
- //耗材
- if is_source == 2 {
- var sum_good_count int64
- secondCountGoodList, _ := service.GetGoodSumSecondCount(project_id, storehouse_out_id, orgId)
- for _, it := range secondCountGoodList {
- sum_good_count += it.StockCount
- }
- if count > sum_good_count {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- })
- return
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- })
- return
- }
- }
- }
-
- func (this *SecondaryOrderApiController) DeleteSecondOrderInfo() {
-
- id, _ := this.GetInt64("id")
-
- err := service.DeleteSecondOrderInfo(id)
- if err == nil {
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- //查询一条仓库信息
- func (this *SecondaryOrderApiController) GetOneStorehouse() {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- check := map[string][]string{
- "id": {"must", "int", "id"},
- }
- _, err := checkParams(this, &check)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- id, _ := this.GetInt64("id")
- var list models.Storehouse
- list, err = service.GetOneStorehouse(id, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
-
- //获取当前机构所有可用仓库的名字
- func (this *SecondaryOrderApiController) GetAllStorehouseName() {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, err := service.GetAllStorehouseName(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
-
- }
-
- //根据机构id查询仓库配置
- func (this *SecondaryOrderApiController) FindStorehouseConfig() {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- storehouse, err := service.FindStorehouseConfig(orgId)
- //如果没有仓库配置信息就新建一个
- if err == gorm.ErrRecordNotFound {
- err := service.GetDefaultStorehouse(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- storehouse, err = service.FindStorehouseConfig(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- }
- if err != nil && err.Error() != "record not found" {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- var storehouse_info, storehouse_out_info, drug_storehouse_info, drug_storehouse_out models.Storehouse
- storehouse_info, err = service.FindStorehouseName(storehouse.StorehouseInfo)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- storehouse_out_info, err = service.FindStorehouseName(storehouse.StorehouseOutInfo)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- drug_storehouse_info, err = service.FindStorehouseName(storehouse.DrugStorehouseInfo)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- drug_storehouse_out, err = service.FindStorehouseName(storehouse.DrugStorehouseOut)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "storehouse_info": storehouse_info.StorehouseName,
- "storehouse_out_info": storehouse_out_info.StorehouseName,
- "drug_storehouse_info": drug_storehouse_info.StorehouseName,
- "drug_storehouse_out": drug_storehouse_out.StorehouseName,
- })
- return
- }
-
- //更改耗材自动入库仓库
- func (this *SecondaryOrderApiController) UpdateInfo() {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- check := map[string][]string{
- "id": {"must", "int", "id"},
- }
- _, err := checkParams(this, &check)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- id, _ := this.GetInt64("id")
- err = service.UpdateInfo(orgId, id)
-
- //查询默认仓库
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
-
- list, _ := service.GetAllGoodList(orgId)
- for _, item := range list {
- var sum_count int64
- var sum_in_count int64
- goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ID, orgId)
- for _, it := range goodList {
- sum_count += it.StockCount
- sum_in_count += it.WarehousingCount
- }
- service.UpdateGoodByGoodId(item.ID, sum_count, sum_in_count, orgId)
- }
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "修改成功",
- })
- return
-
- }
-
- //更改耗材自动出库仓库
- func (this *SecondaryOrderApiController) UpdateOutInfo() {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- check := map[string][]string{
- "id": {"must", "int", "id"},
- }
- _, err := checkParams(this, &check)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- id, _ := this.GetInt64("id")
- err = service.UpdateOutInfo(orgId, id)
-
- //查询默认仓库
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
-
- list, _ := service.GetAllGoodList(orgId)
- for _, item := range list {
- var sum_count int64
- var sum_in_count int64
- goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ID, orgId)
- for _, it := range goodList {
- sum_count += it.StockCount
- sum_in_count += it.WarehousingCount
- }
- service.UpdateGoodByGoodId(item.ID, sum_count, sum_in_count, orgId)
- }
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "修改成功",
- })
- return
-
- }
-
- //更改药品自动入库仓库
- func (this *SecondaryOrderApiController) UpdateDrugInfo() {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- check := map[string][]string{
- "id": {"must", "int", "id"},
- }
- _, err := checkParams(this, &check)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- id, _ := this.GetInt64("id")
-
- err = service.UpdateDrugInfo2(orgId, id)
-
- //查询默认仓库
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- baseDrug, _ := service.GetAllBaseDrugList(orgId)
-
- for _, item := range baseDrug {
- var sum_drug_count int64
- var sum_drug_in_count int64
-
- //查询默认仓库剩余多少库存
- list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ID)
- for _, it := range list {
- if it.MaxUnit == item.MaxUnit {
- it.StockMaxNumber = it.StockMaxNumber * item.MinNumber
- it.WarehousingCount = it.WarehousingCount * item.MinNumber
- }
- sum_drug_count += it.StockMaxNumber + it.StockMinNumber
- sum_drug_in_count += it.WarehousingCount
- }
- service.UpdateMedicalSumCount(item.ID, sum_drug_count, sum_drug_in_count, orgId)
- }
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "修改成功",
- })
- return
-
- }
-
- //更改药品自动出库仓库
- func (this *SecondaryOrderApiController) UpdateDrugOut() {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- check := map[string][]string{
- "id": {"must", "int", "id"},
- }
- _, err := checkParams(this, &check)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- id, _ := this.GetInt64("id")
- err = service.UpdateDrugOut(orgId, id)
-
- //查询默认仓库
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- baseDrug, _ := service.GetAllBaseDrugList(orgId)
-
- for _, item := range baseDrug {
- var sum_drug_count int64
- var sum_drug_in_count int64
-
- //查询默认仓库剩余多少库存
- list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ID)
- for _, it := range list {
- if it.MaxUnit == item.MaxUnit {
- it.StockMaxNumber = it.StockMaxNumber * item.MinNumber
- it.WarehousingCount = it.WarehousingCount * item.MinNumber
- }
- sum_drug_count += it.StockMaxNumber + it.StockMinNumber
- sum_drug_in_count += it.WarehousingCount
- }
- service.UpdateMedicalSumCount(item.ID, sum_drug_count, sum_drug_in_count, orgId)
- }
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "修改成功",
- })
- return
-
- }
-
- //判断前端参数是否为空
- func checkParams(this *SecondaryOrderApiController, m *map[string][]string) (map[string]string, error) {
- tmp := make(map[string]string)
- for k, v := range *m {
- t := this.GetString(k)
- if v[0] == "must" && t == "" {
- return nil, fmt.Errorf(v[2] + "不能为空")
- }
- tmp[k] = t
- }
- return tmp, nil
- }
-
- //兼容旧数据
- func (this *SecondaryOrderApiController) Byliinit() {
- err := service.Byliinit()
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "初始化成功",
- })
- return
- }
-
- //查询机构所属管理员
- func (this *SecondaryOrderApiController) GetuserName() {
- adminUserInfo := this.GetAdminUserInfo()
- viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
- //viewModels, _, _ := service.GetAdminUsersAndLoginInfo(10164, 12123, 1, 100)
- c, _ := service.Getcreateid(adminUserInfo.CurrentOrgId)
- //c, _ := service.Getcreateid(10164)
- admin := []*service.AdminUserManageViewModel{} //记录当前管理员的信息
- //去除禁用的角色
- tmp := []*service.AdminUserManageViewModel{}
- for i := 0; i < len(viewModels); i++ {
- if viewModels[i].Status == 1 {
- tmp = append(tmp, viewModels[i])
- }
- if int64(viewModels[i].AdminUserId) == c.Creator {
- admin = append(admin, viewModels[i])
- }
- }
- roles := service.FindRoles(adminUserInfo.CurrentOrgId)
- //roles := service.FindRoles(10164)
- //去除没有权限的角色
- tmplist := []*service.AdminUserManageViewModel{}
- if roles == nil || len(roles) == 0 {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": admin,
- })
- return
- }
- for i := 0; i < len(tmp); i++ {
- boolean := false
- //获取并解析当前用户的角色
- tmproles := strings.Split(tmp[i].RoleIds, ",")
- for j := 0; j < len(tmproles); j++ {
- //判断这些角色是否有权限
- if _, ok := roles[tmproles[j]]; ok {
- boolean = true
- }
- }
- if boolean {
- tmplist = append(tmplist, tmp[i])
- }
- }
- isappend := true //判断结果中是否添加机构创建者,true添加,false不添加
- if len(tmplist) > 0 {
- for i := 0; i < len(tmplist); i++ {
- if int64(tmplist[i].AdminUserId) == c.Creator {
- isappend = false
- }
- }
- }
- if isappend {
- tmplist = append(tmplist, admin...)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": tmplist,
- })
- return
- }
-
- func (this *SecondaryOrderApiController) GetCreaterId() {
- creater := this.GetAdminUserInfo().AdminUser.Id
- this.ServeSuccessJSON(map[string]interface{}{
- "list": creater,
- })
- }
|