BaseBackEntity.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package vo
  2. import (
  3. "demo/configs"
  4. "demo/data/domain"
  5. )
  6. type GoodsSkuQuery struct {
  7. SkuName string `xorm:"sku_name" json:"skuName"` // 255 0 注释:商品sku名字
  8. PriceStart float64 `xorm:"price" json:"price"` // 10 2 注释:现在价格区间
  9. PriceEnd float64 `xorm:"price" json:"price"` // 10 2 注释:现在价格区间
  10. HistoricalPricesStart float64 `xorm:"historical_prices" json:"historicalPrices"`
  11. HistoricalPricesEnd float64 `xorm:"historical_prices" json:"historicalPrices"`
  12. InventoryNumberStart int64 `xorm:"inventory_number" json:"inventoryNumber"`
  13. InventoryNumberEnd int64 `xorm:"inventory_number" json:"inventoryNumber"`
  14. CommodityAreaId int64 `xorm:"commodity_area_id" json:"commodityAreaId"`
  15. GoodsId int64 `xorm:"goods_id" json:"goodsId"`
  16. }
  17. func GetGoodsSkuList(query GoodsSkuQuery, pageNum, pageSize int) (BaseListVo, error) {
  18. var arr []domain.GoodsSku
  19. session := configs.Engine.Table("goods_sku").Limit(pageSize, (pageNum-1)*pageSize)
  20. if query.SkuName != "" {
  21. session.Where("sku_name = ?", query.SkuName)
  22. }
  23. if query.PriceStart != 0 && query.PriceEnd != 0 {
  24. session.And("price >= ? && price <= ?", query.PriceStart, query.PriceEnd)
  25. }
  26. if query.HistoricalPricesStart != 0 && query.HistoricalPricesEnd != 0 {
  27. session.And("historical_prices >= ? && historical_prices <= ?", query.HistoricalPricesStart, query.HistoricalPricesEnd)
  28. }
  29. if query.InventoryNumberStart != 0 && query.InventoryNumberEnd != 0 {
  30. session.And("inventory_number >= ? && inventory_number <= ?", query.InventoryNumberStart, query.InventoryNumberEnd)
  31. }
  32. Count, err := session.FindAndCount(&arr, &query)
  33. var vo BaseListVo
  34. if err != nil {
  35. return vo, err
  36. }
  37. if err != nil {
  38. return vo, err
  39. }
  40. vo.PageNum = pageNum
  41. vo.PageSize = pageSize
  42. vo.List = make([]any, len(arr))
  43. for i, v := range arr {
  44. vo.List[i] = v
  45. }
  46. vo.Total = int(Count)
  47. return vo, nil
  48. }