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.

88 lines
4.9 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 GysSummery struct {
SkuCode string `json:"skuCode"`
GoodsNum string `json:"goodsNum"`
GoodsName string `json:"goodsName"`
SendNum int `json:"sendNum"`
BackNum int `json:"backNum"`
FinishNum int `json:"finishNum"`
TaxPrice decimal.Decimal `json:"taxPrice"`
ExpressFree decimal.Decimal `json:"expressFree"`
FinishAmount decimal.Decimal `json:"finishAmount"`
NoTaxAmount decimal.Decimal `json:"noTaxAmount"`
TaxPrecent decimal.Decimal `json:"taxPrecent"`
TaxAmount decimal.Decimal `json:"taxAmount"`
Category string `json:"category"`
BuyerMessage string `json:"buyerMessage"`
Brand string `json:"brand"`
GysUser string `json:"gysUser"`
}
type GysSend struct {
OrderID string `json:"orderId"`
OrderType string `json:"orderType"`
GoodsStatus string `json:"goodsStatus"`
CreatedTime formatime.Second `json:"createdTime"`
ExpressTime formatime.Second `json:"expressTime"`
SkuCode string `json:"skuCode"`
GoodsNum string `json:"goodsNum"`
GoodsName string `json:"goodsName"`
SendNum int `json:"sendNum"`
Category string `json:"category"`
Brand string `json:"brand"`
BuyerMessage string `json:"buyerMessage"`
GysUser string `json:"gysUser"`
}
func GysList(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\tsku.goods_num as goods_num,\n\tdet.goods_name as goods_name,\n\tsum(det.quantity),\n\tIFNULL(\n\t\t(\n\t\t\tSELECT sum(det.quantity)\n\t\t\tFROM recook_after_sales_goods as afte\n\t\t\tWHERE afte.sku_code = det.sku_code\n\t\t\t\tAND (det.ass_type = 2)\n\t\t),\n\t\t0\n\t) as send_num,\n\tsum(\n\t\tIFNULL(\n\t\t\t(\n\t\t\t\tselect quantity\n\t\t\t\tfrom recook_order_goods_detail\n\t\t\t\twhere det.ass_type = 0\n\t\t\t\t\tand det.express_status = 2\n\t\t\t\t\tand recook_order_goods_detail.id = det.id\n\t\t\t),\n\t\t\t0\n\t\t)\n\t) as back_num,\n\tsku.purchase_price as tax_price,\n\tIFNULL(aft.express_free,0) as express_free,\n\tsum(det.quantity * sku.purchase_price) as finish_amount,\n\t0 as no_tax_amount,\n\t0 as tax_precent,\n\t0 as tax_amount,\n\tdet.category_name as category,\n\tdet.buyer_message as buyer_message,\n\tdet.brand_name as brand,\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_user\n\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\tleft join recook_after_sales_goods as aft on aft.order_id = det.order_id\n\tand aft.goods_id = det.goods_id\nWHERE MONTH (info.`completed_at`) = ?\n\tand det.express_status != 0\nGROUP BY sku.id"
var gysSummery []GysSummery
err = dbc.DB.Raw(sql, 8).Scan(&gysSummery).Error
if err != nil {
log.Println(err)
}
total := len(gysSummery)
back.Suc(c, "操作成功", gin.H{
"total": total,
"list": gysSummery,
})
//发货数据
case 1:
sql = "SELECT\n\tinfo.id AS order_id,\n\t\"普通订单\" AS order_type,\nCASE\n\t\tinfo.STATUS \n\t\tWHEN 1 THEN\n\t\t\"已支付\" \n\t\tWHEN 4 THEN\n\t\t\"交易完成\" \n\t\tWHEN 5 THEN\n\t\t\"交易关闭\" \n\tEND AS order_status,\n\tinfo.created_at AS created_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.category_name as category,\n\tdet.brand_name as brand,\n\tinfo.buyer_message as buyer_message,\n\tIF\n\t(\n\t\tdet.vendor_id = 0,\n\t\t\"自营\",(\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)) as gys_user\nFROM\n\trecook_order_goods_detail AS det\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=exp.order_id \n\tleft join recook_goods_sku as sku on sku.id=det.sku_id \n\t\n\tWHERE (det.express_status=1 or det.express_status=2)\n\t and MONTH ( info.`completed_at` )= ?\n\tgroup by info.id,sku.id"
var gysSend []GysSend
err = dbc.DB.Raw(sql, 8).Scan(&gysSend).Error
if err != nil {
log.Println(err)
}
total := len(gysSend)
back.Suc(c, "操作成功", gin.H{
"total": total,
"list": gysSend,
})
//退货数据
}
}