29 lines
491 B
Go
29 lines
491 B
Go
package api
|
|
|
|
import (
|
|
"github.com/gin-contrib/sessions"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func handleCustomerReport(c *gin.Context) {
|
|
session := sessions.Default(c)
|
|
userId := session.Get("userid").(int64)
|
|
|
|
row := db.QueryRow(`select sum(g.price)
|
|
from purchase p
|
|
join goods g on p.goods_id = g.id
|
|
where p.user_id = $1`,
|
|
userId)
|
|
|
|
var sumPrice string
|
|
err := row.Scan(&sumPrice)
|
|
if err != nil {
|
|
c.AbortWithError(500, err)
|
|
return
|
|
}
|
|
|
|
c.JSON(200, gin.H{
|
|
"sum": sumPrice,
|
|
})
|
|
}
|