Compare commits
2
Commits
3027684395
...
7916c81ece
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7916c81ece | ||
|
|
f84d20ba20 |
@@ -20,14 +20,15 @@ func GetTopItems(c *gin.Context) {
|
|||||||
results := []TopItem{}
|
results := []TopItem{}
|
||||||
|
|
||||||
err := database.DB.Table("order_items").
|
err := database.DB.Table("order_items").
|
||||||
Select("items.name, SUM(order_items.price * order_items.quantity) AS revenue, order_items.price, SUM(order_items.quantity) as sale_quantity, items.unit").
|
Select("items.name, SUM(order_items.price * order_items.quantity) AS revenue, AVG(order_items.price) as price, SUM(order_items.quantity) as sale_quantity, items.unit").
|
||||||
Joins("JOIN items ON items.id = order_items.item_id").
|
Joins("JOIN items ON items.id = order_items.item_id").
|
||||||
Group("items.name, order_items.price, items.unit").
|
Group("items.name, items.unit").
|
||||||
Order("revenue DESC").
|
Order("revenue DESC").
|
||||||
Limit(5).
|
Limit(5).
|
||||||
Scan(&results).Error
|
Scan(&results).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, results)
|
c.JSON(http.StatusOK, results)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export default function AdminPage() {
|
|||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
{/* Вкладки */}
|
{/* Вкладки */}
|
||||||
<div className="flex gap-2 mb-8 border-b border-white/10">
|
<div className="flex overflow-x-auto whitespace-nowrap gap-2 mb-8 border-b border-white/10">
|
||||||
{tabs.map((t) => (
|
{tabs.map((t) => (
|
||||||
<button
|
<button
|
||||||
key={t.key}
|
key={t.key}
|
||||||
|
|||||||
Reference in New Issue
Block a user