From 49dd477045c51371428291a5ea66a7332d907b33 Mon Sep 17 00:00:00 2001 From: suyl <770236076@qq.com> Date: Mon, 30 Aug 2021 15:24:15 +0800 Subject: [PATCH] aa --- business/jxstore/cms/store.go | 32 +++++++++++++++++++++++++++ business/model/dao/store.go | 17 ++++++++++++++ business/model/store.go | 15 ++++++++++++- controllers/cms_store.go | 30 +++++++++++++++++++++++++ routers/commentsRouter_controllers.go | 18 +++++++++++++++ 5 files changed, 111 insertions(+), 1 deletion(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 3c6f6e9f6..2eef60f80 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -5087,3 +5087,35 @@ func AuditStoreMap(ctx *jxcontext.Context, ID int, vendorOrgCode, vendorStoreID func GetStoreMapAudit(ctx *jxcontext.Context, storeIDs, vendorIDs, auditStatuss []int, fromTime, toTime string, offset, pageSize int) (page *model.PagedInfo, err error) { return dao.GetStoreMapAudit(dao.GetDB(), storeIDs, vendorIDs, auditStatuss, utils.Str2Time(fromTime), utils.Str2Time(toTime), offset, pageSize) } + +func GetBrandUser(ctx *jxcontext.Context, brandID int) (brandUsers []*model.BrandUser, err error) { + return dao.GetBrandUser(dao.GetDB(), brandID, "") +} + +func UpdateBrandUser(ctx *jxcontext.Context, brandID int, userID string, isDel bool) (err error) { + var ( + db = dao.GetDB() + ) + brandUsers, err := dao.GetBrandUser(db, brandID, userID) + if err != nil { + return err + } + if !isDel { + if len(brandUsers) > 0 { + return fmt.Errorf("此用户已经绑定了该品牌!") + } + brandUser := &model.BrandUser{ + BrandID: brandID, + UserID: userID, + } + dao.WrapAddIDCULDEntity(brandUser, ctx.GetUserName()) + dao.CreateEntity(db, brandUser) + } else { + if len(brandUsers) == 0 { + return fmt.Errorf("此用户没有绑定该品牌!") + } + brandUsers[0].DeletedAt = time.Now() + dao.UpdateEntity(db, brandUsers[0], "DeletedAt") + } + return err +} diff --git a/business/model/dao/store.go b/business/model/dao/store.go index 1259e4d63..a1016f2b9 100644 --- a/business/model/dao/store.go +++ b/business/model/dao/store.go @@ -1326,3 +1326,20 @@ func GetStoreMapAudit(db *DaoDB, storeIDs, vendorIDs, auditStatuss []int, fromTi } return page, err } + +func GetBrandUser(db *DaoDB, brandID int, userID string) (brandUsers []*model.BrandUser, err error) { + sql := ` + SELECT * FROM brand_user WHERE deleted_at = ? + ` + sqlParams := []interface{}{utils.DefaultTimeValue} + if brandID != 0 { + sql += " AND brand_id = ?" + sqlParams = append(sqlParams, brandID) + } + if userID != "" { + sql += " AND user_id = ?" + sqlParams = append(sqlParams, userID) + } + err = GetRows(db, &brandUsers, sql, sqlParams) + return brandUsers, err +} diff --git a/business/model/store.go b/business/model/store.go index 752fed625..ee41b49ef 100644 --- a/business/model/store.go +++ b/business/model/store.go @@ -812,12 +812,25 @@ type BrandBill struct { OrderID string `orm:"column(order_id)" json:"orderID"` //关联orderPay表的订单号 } -func (*BrandBill) TableUnique() [][]string { +func (*BrandBill) TableIndex() [][]string { return [][]string{ []string{"BrandID", "CreatedAt"}, } } +type BrandUser struct { + ModelIDCULD + + BrandID int `orm:"column(brand_id)" json:"brandID"` //品牌ID + UserID string `orm:"column(user_id) json:"userID"` +} + +func (*BrandUser) TableIndex() [][]string { + return [][]string{ + []string{"BrandID", "UserID"}, + } +} + type BrandStore struct { ModelIDCULD diff --git a/controllers/cms_store.go b/controllers/cms_store.go index dea3da936..9af02cd75 100644 --- a/controllers/cms_store.go +++ b/controllers/cms_store.go @@ -1165,3 +1165,33 @@ func (c *StoreController) GetStoreMapAudit() { return retVal, "", err }) } + +// @Title 查询品牌用户 +// @Description 查询品牌用户 +// @Param token header string true "认证token" +// @Param brandID query int true "brandID" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /GetBrandUser [get] +func (c *StoreController) GetBrandUser() { + c.callGetBrandUser(func(params *tStoreGetBrandUserParams) (retVal interface{}, errCode string, err error) { + retVal, err = cms.GetBrandUser(params.Ctx, params.BrandID) + return retVal, "", err + }) +} + +// @Title 修改品牌用户 +// @Description 修改品牌用户 +// @Param token header string true "认证token" +// @Param brandID formData int true "brandID" +// @Param userID formData string true "userID" +// @Param isDel formData bool true "true是删除,false是添加" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /UpdateBrandUser [post] +func (c *StoreController) UpdateBrandUser() { + c.callUpdateBrandUser(func(params *tStoreUpdateBrandUserParams) (retVal interface{}, errCode string, err error) { + err = cms.UpdateBrandUser(params.Ctx, params.BrandID, params.UserID, params.IsDel) + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 9d547a8d2..69f19772b 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -2160,6 +2160,24 @@ func init() { Filters: nil, Params: nil}) + web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"], + web.ControllerComments{ + Method: "GetBrandUser", + Router: `/GetBrandUser`, + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + + web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"], + web.ControllerComments{ + Method: "UpdateBrandUser", + Router: `/UpdateBrandUser`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"], web.ControllerComments{ Method: "AddStoreCategoryMap",