package imp import ( "fmt" "lot_interlligentControl/app/e" "lot_interlligentControl/global" "lot_interlligentControl/models" "lot_interlligentControl/unity" ) type Shop struct{} func (s Shop) AuditState(uid, id, state int) e.Rescode { //TODO implement me tx := global.DBLink.Model(models.Shop{}). Where("id = ?", id). Updates(&models.Shop{ ProductState: state, CreateBy: uid, }) if tx.RowsAffected > 0 { return e.SUCCESS } return e.ERROR } func (s Shop) GetShopByName(uid int, productName string, params unity.PageParams) ([]models.Shop, int64, error) { //TODO implement me var shop []models.Shop var count int64 if err := global.DBLink.Model(models.Shop{}). Where("product_name LIKE ?", fmt.Sprintf("%s%s%s", "%", productName, "%")). Where("create_by = ?", uid). Count(&count).Error; err != nil { return nil, 0, err } // 计算偏移量并设置分页大小 offset := (params.Page - 1) * params.Size // 执行实际分页查询 if err := global.DBLink. Where("product_name LIKE ?", fmt.Sprintf("%s%s%s", "%", productName, "%")). Where("create_by = ?", uid). Offset(offset).Limit(params.Size). Order(params.Desc). Find(&shop).Error; err != nil { return nil, 0, err } return shop, count, nil } func (s Shop) UpdateShop(uid, id int, shop models.ShopDto) e.Rescode { //TODO implement me tx := global.DBLink.Where("id = ?", id).Model(&models.Shop{}).Updates(map[string]interface{}{ "product_avatar": shop.ProductAvatar, "product_name": shop.ProductName, "product_price": shop.ProductPrice, "product_description": shop.ProductDescription, "product_type": shop.ProductType, "create_by": uid, "product_state": 0, }) if tx.RowsAffected > 0 { return e.SUCCESS } return e.ERROR } func (s Shop) AddShop(uid int, shop models.ShopDto) e.Rescode { //TODO implement me var shops models.Shop shops.ProductAvatar = shop.ProductAvatar shops.ProductType = shop.ProductType shops.ProductDescription = shop.ProductDescription shops.ProductPrice = shop.ProductPrice shops.ProductName = shop.ProductName shops.CreateBy = uid shops.ProductState = 0 tx := global.DBLink.Create(&shops) if tx.RowsAffected > 0 { return e.SUCCESS } return e.ERROR }