1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/astaxie/beego"
- "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")
-
- }
-
- 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)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseOutInfo,
- "info": warehouseOut,
- })
-
- }
- 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 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))
-
- 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 {
- 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.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)
-
- 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")
-
- adminUserInfo := c.GetAdminUserInfo()
- list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- })
- } 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
- }
-
- }
|