From 6f4158764ef68e815febf3fff7b5bbf47f40596e Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Wed, 6 Mar 2024 17:56:50 +0800 Subject: [PATCH] update --- app/admin/hdl/hdl_device.go | 24 ++++++++++++++++++++++-- app/admin/hdl/hdl_merchant.go | 2 +- app/admin/md/md_device.go | 1 + app/db/db_device.go | 1 + app/db/model/device.go | 1 + app/router/admin_router.go | 9 +++++---- 6 files changed, 31 insertions(+), 7 deletions(-) diff --git a/app/admin/hdl/hdl_device.go b/app/admin/hdl/hdl_device.go index 31eeeb8..92e75c3 100644 --- a/app/admin/hdl/hdl_device.go +++ b/app/admin/hdl/hdl_device.go @@ -62,7 +62,9 @@ func DeviceList(c *gin.Context) { } var m []*db.DeviceWithEnterprise total, err := sess. - Join("LEFT", "enterprise", "enterprise.id = device.enterprise_id").Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) + Join("LEFT", "enterprise", "enterprise.id = device.enterprise_id"). + Join("LEFT", "merchant", "merchant.id = device.merchant_id"). + Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return @@ -75,10 +77,12 @@ func DeviceList(c *gin.Context) { "name": v.Device.Name, "device_sn": v.Device.DeviceSn, "enterprise_id": v.Device.EnterpriseId, + "merchant_id": v.Device.MerchantId, "memo": v.Device.Memo, "create_at": v.Device.CreateAt, "update_at": v.Device.UpdateAt, "enterprise_name": v.Enterprise.Name, + "merchant_name": v.Merchant.Name, }) } e.OutSuc(c, map[string]interface{}{ @@ -110,6 +114,7 @@ func DeviceSave(c *gin.Context) { Name: req.Name, DeviceSn: req.DeviceSn, EnterpriseId: req.EnterpriseId, + MerchantId: req.MerchantId, Memo: req.Memo, CreateAt: time.Now().Format("2006-01-02 15:04:05"), UpdateAt: time.Now().Format("2006-01-02 15:04:05"), @@ -126,8 +131,9 @@ func DeviceSave(c *gin.Context) { device.EnterpriseId = req.EnterpriseId device.Name = req.Name device.Memo = req.Memo + device.MerchantId = req.MerchantId device.UpdateAt = time.Now().Format("2006-01-02 15:04:05") - updateAffected, err1 := deviceDd.DeviceUpdate(device, "enterprise_id", "name", "memo", "update_at") + updateAffected, err1 := deviceDd.DeviceUpdate(device, "enterprise_id", "merchant_id", "name", "memo", "update_at") if err1 != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return @@ -158,3 +164,17 @@ func DeviceDelete(c *gin.Context) { e.OutSuc(c, "success", nil) return } + +func EnterPriseMerchantList(c *gin.Context) { + enterpriseId := c.DefaultQuery("enterprise_id", "0") + var m []model2.Merchant + if err := db.Db.Where("enterprise_id = ?", enterpriseId).Find(&m); err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + + e.OutSuc(c, map[string]interface{}{ + "list": m, + }, nil) + return +} diff --git a/app/admin/hdl/hdl_merchant.go b/app/admin/hdl/hdl_merchant.go index b30e9f8..b20bdf0 100644 --- a/app/admin/hdl/hdl_merchant.go +++ b/app/admin/hdl/hdl_merchant.go @@ -32,7 +32,7 @@ func MerchantList(c *gin.Context) { engine = engine.And("merchant.enterprise_id =?", req.EnterpriseId) } if req.Name != "" { - engine = engine.And("merchant.name like =?", "%"+req.Name+"%") + engine = engine.And("merchant.name like ?", "%"+req.Name+"%") } total, err := engine.Join("LEFT", "enterprise", "enterprise.id = merchant.enterprise_id"). Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) diff --git a/app/admin/md/md_device.go b/app/admin/md/md_device.go index 14e14ac..95dc3d8 100644 --- a/app/admin/md/md_device.go +++ b/app/admin/md/md_device.go @@ -13,5 +13,6 @@ type DeviceSaveReq struct { Name string `json:"name" binding:"required"` DeviceSn string `json:"device_sn" binding:"required"` EnterpriseId int `json:"enterprise_id" binding:"required"` + MerchantId int `json:"merchant_id" binding:"required"` Memo string `json:"memo"` } diff --git a/app/db/db_device.go b/app/db/db_device.go index e4ebd4e..b90585f 100644 --- a/app/db/db_device.go +++ b/app/db/db_device.go @@ -96,6 +96,7 @@ func (deviceOrdDb *Device) DeviceUpdate(m *model.Device, forceColums ...string) type DeviceWithEnterprise struct { model.Device `xorm:"extends"` model.Enterprise `xorm:"extends"` + model.Merchant `xorm:"extends"` } func (DeviceWithEnterprise) TableName() string { diff --git a/app/db/model/device.go b/app/db/model/device.go index bcfddff..89020f1 100644 --- a/app/db/model/device.go +++ b/app/db/model/device.go @@ -4,6 +4,7 @@ type Device struct { Id int `json:"id" xorm:"not null pk autoincr INT(11)"` Name string `json:"name" xorm:"not null default '' comment('档口名称') VARCHAR(255)"` DeviceSn string `json:"device_sn" xorm:"not null default '' comment('设备编号') unique VARCHAR(255)"` + MerchantId int `json:"merchant_id" xorm:"not null default 0 comment('商家id') INT(11)"` EnterpriseId int `json:"enterprise_id" xorm:"not null default 0 comment('校企id') INT(11)"` Memo string `json:"memo" xorm:"not null default '' comment('备注信息') VARCHAR(255)"` CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` diff --git a/app/router/admin_router.go b/app/router/admin_router.go index 559f653..536c486 100644 --- a/app/router/admin_router.go +++ b/app/router/admin_router.go @@ -111,9 +111,10 @@ func rFinanceManage(r *gin.RouterGroup) { } func rDeviceManage(r *gin.RouterGroup) { - r.POST("/save", hdl2.DeviceSave) //设备管理-编辑/新增 - r.POST("/list", hdl2.DeviceList) //设备管理-列表 - r.DELETE("/delete/:device_sn", hdl2.DeviceDelete) //设备管理-删除 + r.POST("/save", hdl2.DeviceSave) //设备管理-编辑/新增 + r.POST("/list", hdl2.DeviceList) //设备管理-列表 + r.GET("/enterPriseMerchantList", hdl2.EnterPriseMerchantList) //设备管理-学校下商家列表 + r.DELETE("/delete/:device_sn", hdl2.DeviceDelete) //设备管理-删除 } func rMerchant(r *gin.RouterGroup) { @@ -318,5 +319,5 @@ func AdminRoute(r *gin.RouterGroup) { rFinanceManage(r.Group("/financeManage")) //财务管理 rDeviceManage(r.Group("/deviceManage")) //设备管理 rDataStatistics(r.Group("/dataStatistics")) //数据统计 - rMerchant(r.Group("/merchant")) + rMerchant(r.Group("/merchant")) //商家管理 }