You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
5.8 KiB
99 lines
5.8 KiB
package finance
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/golangkit/formatime"
|
|
"github.com/shopspring/decimal"
|
|
"log"
|
|
"recook/internal/back"
|
|
"recook/internal/dbc"
|
|
"recook/tools"
|
|
)
|
|
|
|
type queryParams struct {
|
|
Type int
|
|
}
|
|
type SaleSummery struct {
|
|
SkuCode string `json:"skuCode"`
|
|
Category string `json:"category"`
|
|
Brand string `json:"brand"`
|
|
GoodsNum string `json:"goodsNum"` //商品编码
|
|
GoodsName string `json:"goodsName"`
|
|
SendNum int `json:"sendNum"`
|
|
SendAmount decimal.Decimal `json:"sendAmount"`
|
|
BackNum int `json:"backNum"`
|
|
BackAmount decimal.Decimal `json:"backAmount"`
|
|
ExpressFree decimal.Decimal `json:"expressFree"`
|
|
SaleNum int `json:"saleNum"`
|
|
SaleAmount decimal.Decimal `json:"saleAmount"`
|
|
CostAmount decimal.Decimal `json:"costAmount"`
|
|
TotalCommission decimal.Decimal `json:"totalCommission"`
|
|
TeamCoin decimal.Decimal `json:"teamCoin"`
|
|
SaleProfit decimal.Decimal `json:"saleProfit"`
|
|
ProfitPercent decimal.Decimal `json:"profitPercent"`
|
|
GysUser string `json:"gysUser"`
|
|
}
|
|
type SaleSend struct {
|
|
OrderID string `json:"orderId"`
|
|
OrderType string `json:"orderType"`
|
|
OrderStatus string `json:"orderStatus"`
|
|
CreateTime formatime.Second `json:"createTime"` //商品编码
|
|
GoodsStatus string `json:"goodsStatus"`
|
|
ExpressTime formatime.Second `json:"expressTime"`
|
|
SkuCode string `json:"skuCode"`
|
|
GoodsNum string `json:"goodsNum"`
|
|
GoodsName string `json:"goodsName"`
|
|
SendNum int `json:"sendNum"`
|
|
UnitPrice decimal.Decimal `json:"unitPrice"`
|
|
SendAmount decimal.Decimal `json:"sendAmount"`
|
|
TotalCommission decimal.Decimal `json:"totalCommission"`
|
|
CostAmount decimal.Decimal `json:"costAmount"`
|
|
CoinAmount decimal.Decimal `json:"coinAmount"`
|
|
Category string `json:"category"`
|
|
Brand string `json:"brand"`
|
|
BuyerMessage string `json:"buyerMessage"`
|
|
GysUser string `json:"gysUser"`
|
|
}
|
|
|
|
func SaleList(c *gin.Context) {
|
|
var p queryParams
|
|
err := tools.Params(&p, c)
|
|
if err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
//sql 原型位于/recook/SQL/Summary路径下
|
|
var sql string
|
|
switch p.Type {
|
|
//汇总数据
|
|
case 0:
|
|
sql = "SELECT\n\tdet.sku_code as sku_code,\n\tdet.category_name as category,\n\tdet.brand_name as brand,\n\tsku.`goods_num` as goods_num,\n\tdet.goods_name as goods_name,\n\tsum(det.quantity) as send_num,\n\tsum( det.quantity * det.unit_price ) as send_amount,\n\tIFNULL(\n\t\t(\n\t\tSELECT\n\t\t\tsum( quantity )\n\t\tFROM\n\t\t\trecook_after_sales_goods as afte\n\t\tWHERE\n\t\t\tafte.sku_code = det.sku_code\n\t\t\tAND (\n\t\t\t\tdet.ass_type = 2\n\t\t\t)),\n\t\t0\n\t) as back_num,\n\tIFNULL((\n\t\tSELECT\n\t\t\tsum( quantity * det.unit_price )\n\t\tFROM\n\t\t\trecook_after_sales_goods as afte\n\t\tWHERE\n\t\t\tafte.sku_code = det.sku_code\n\t\t\tAND (\n\t\t\t\tdet.ass_type = 2\n\t\t\t)\n\t\t\t),\n\t\t0\n\t) as back_amount,\n\tIFNULL(\n\t\t(\n\t\t\tSELECT express_free\n\t\t\tFROM recook_after_sales_goods as afte\n\t\t\tWHERE afte.goods_id = det.goods_id and afte.order_id = det.order_id\n\t\t),\n\t\t0\n\t) as express_free,\n\tsum(det.`quantity`) as sale_num,\n\tsum(det.`unit_price`*det.`quantity`) as sale_amount,\n\tsum(sku.purchase_price*det.`quantity`) as cost_amount,\n\tdet.`total_commission` as total_commission,\n\t0 as team_coin,\n\t0 as sale_profit,\n 0 as profit_percent,\n IF(\n det.vendor_id = 0,\n \"自营\",(\n\t\tSELECT\n\t\t\tusername\n\t\tFROM\n\t\t\tgys_users\n\t\tWHERE\n\t\t\tdet.vendor_id = gys_users.id\n\t\t)) as gys_user\nFROM recook_order_goods_detail AS det\n\tLEFT JOIN `recook_goods_sku` AS sku ON sku.id = det.sku_id\n\tleft join recook_order_info as info on info.id = det.order_id\n\nWHERE MONTH (info.`completed_at`) = ?\n\tand det.express_status != 0\nGROUP BY sku.id"
|
|
var saleSummery []SaleSummery
|
|
err = dbc.DB.Raw(sql, 8).Scan(&saleSummery).Error
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
total := len(saleSummery)
|
|
back.Suc(c, "操作成功", gin.H{
|
|
"total": total,
|
|
"list": saleSummery,
|
|
})
|
|
//发货数据
|
|
case 1:
|
|
sql = "\nSELECT\n\tinfo.id as order_id,\n\t\"普通订单\" as order_type,\n\t\"交易完成\" as order_status,\n\tinfo.`created_at` as create_time,\n\t\"已发货\" as goods_status,\n\texp.`express_time` as express_time,\n\tdet.sku_code as sku_code,\n\tsku.goods_num as goods_num,\n\tdet.goods_name as goods_name,\n\tdet.`quantity` as send_num,\n\tdet.`unit_price` as unit_price,\n\tdet.quantity * det.unit_price as send_amount,\n\tdet.`total_commission` as total_commission,\n\tdet.quantity*sku.purchase_price as cost_amount,\n\tdet.`coin_amount` as coin_amount,\n\tdet.category_name as category,\n\tdet.brand_name as brand,\n\tdet.`buyer_message` as buyer_message,\n\tIF (\n\t\tdet.vendor_id = 0 ,\n\t\t\"自营\",\n\t\t(\n\t\t\tSELECT username\n\t\t\tFROM gys_users\n\t\t\tWHERE det.vendor_id = gys_users.id\n\t\t)\n\t) as gys_name,\n\tinfo.`completed_at` as completed_at\nFROM recook_order_goods_detail AS det\n\tLEFT JOIN `recook_goods_sku` AS sku ON sku.id = det.sku_id\n\tleft join `recook_order_goods_express` as exp on det.order_id=exp.order_id and det.id=exp.order_goods_id\n\tleft join recook_order_info as info on info.id = det.order_id\nWHERE MONTH(info.`completed_at`) = ?\n\tand det.express_status != 0\nGROUP BY info.id,sku.id\n"
|
|
var saleSend []SaleSend
|
|
err = dbc.DB.Raw(sql, 8).Scan(&saleSend).Error
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
total := len(saleSend)
|
|
back.Suc(c, "操作成功", gin.H{
|
|
"total": total,
|
|
"list": saleSend,
|
|
})
|
|
//退货数据
|
|
}
|
|
|
|
}
|