- GetOrderSkuInfo返回RealEarningPrice代表单品实际结给商家的钱

This commit is contained in:
gazebo
2019-06-20 10:05:35 +08:00
parent faca22c993
commit 8a707df773
4 changed files with 77 additions and 99 deletions

View File

@@ -369,14 +369,7 @@ func caculateOrderEarningPrice(order *model.GoodsOrder, storePayPercentage int)
for _, v := range order.Skus {
skuEarningPrice := v.EarningPrice
if skuEarningPrice == 0 {
basePrice := v.SalePrice
if v.ShopPrice > 0 && v.ShopPrice < basePrice {
basePrice = v.ShopPrice
}
if storePayPercentage <= 0 {
storePayPercentage = model.DefaultEarningPricePercentage
}
skuEarningPrice = basePrice * int64(storePayPercentage) / 100
skuEarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage)
}
order.EarningPrice += skuEarningPrice
}

View File

@@ -74,94 +74,66 @@ func (c *OrderManager) GetOrderSkuInfo(ctx *jxcontext.Context, vendorOrderID str
if vendorID == model.VendorIDJD {
fullSkuNameSQL = "CONCAT(t1.sku_name, IF(t3.is_spu = 1 AND LOCATE(';', t1.sku_name) = 0, CONCAT('[约', t2.spec_quality, t2.spec_unit, '/', t3.unit, ']'), ''))"
}
sql := fmt.Sprintf(`
SELECT
t1.id,
t1.vendor_order_id,
t1.vendor_id,
t1.count,
t1.vendor_sku_id,
t1.sku_id,
t1.jx_sku_id,
t1.sku_name,
IF(t1.shop_price = 0, t1.sale_price, t1.shop_price) shop_price,
t1.sale_price,
t1.earning_price,
CAST(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, %d) / 100) AS SIGNED) real_earning_price,
t1.weight,
t1.sku_type,
t1.promotion_type,
t1.order_created_at,
t1.store_sub_id,
t1.store_sub_name,
t1.vendor_price,
%s full_sku_name,
`, model.DefaultEarningPricePercentage, fullSkuNameSQL)
db := dao.GetDB()
if vendorID == model.VendorIDELM {
err = dao.GetRows(db, &skus, fmt.Sprintf(`
SELECT
t1.id,
t1.vendor_order_id,
t1.vendor_id,
t1.count,
t1.vendor_sku_id,
t1.sku_id,
t1.jx_sku_id,
t1.sku_name,
IF(t1.shop_price = 0, t1.sale_price, t1.shop_price) shop_price,
t1.sale_price,
t1.earning_price,
t1.weight,
t1.sku_type,
t1.promotion_type,
t1.order_created_at,
t1.store_sub_id,
t1.store_sub_name,
t1.vendor_price,
IF(t3.img IS NULL OR t3.img = '', t4.col_imageUrl, t3.img) image, %s full_sku_name
FROM order_sku t1
LEFT JOIN sku t2 ON IF(t1.jx_sku_id != 0, t1.jx_sku_id, t1.sku_id) = t2.id/* AND t2.deleted_at = ?*/
LEFT JOIN sku_name t3 ON t2.name_id = t3.id/* AND t3.deleted_at = ?*/
LEFT JOIN ede_skus t4 ON t1.vendor_sku_id = t4.col_id
WHERE vendor_order_id = ? AND vendor_id = ?
ORDER BY t1.sku_name
`, fullSkuNameSQL), /*, utils.DefaultTimeValue, utils.DefaultTimeValue*/ vendorOrderID, vendorID)
err = dao.GetRows(db, &skus, sql+`
IF(t3.img <> '', t3.img, t4.col_imageUrl) image
FROM order_sku t1
LEFT JOIN goods_order t6 ON t6.vendor_order_id = t1.vendor_order_id AND t6.vendor_id = t1.vendor_id
LEFT JOIN store t5 ON t5.id = IF(t6.jx_store_id <> 0, t6.jx_store_id, t6.store_id)
LEFT JOIN sku t2 ON IF(t1.jx_sku_id != 0, t1.jx_sku_id, t1.sku_id) = t2.id/* AND t2.deleted_at = ?*/
LEFT JOIN sku_name t3 ON t2.name_id = t3.id/* AND t3.deleted_at = ?*/
LEFT JOIN ede_skus t4 ON t1.vendor_sku_id = t4.col_id
WHERE t1.vendor_order_id = ? AND t1.vendor_id = ?
ORDER BY t1.sku_name
`, /*, utils.DefaultTimeValue, utils.DefaultTimeValue*/ vendorOrderID, vendorID)
} else if vendorID == model.VendorIDJD {
err = dao.GetRows(db, &skus, fmt.Sprintf(`
SELECT
t1.id,
t1.vendor_order_id,
t1.vendor_id,
t1.count,
t1.vendor_sku_id,
t1.sku_id,
t1.jx_sku_id,
t1.sku_name,
IF(t1.shop_price = 0, t1.sale_price, t1.shop_price) shop_price,
t1.sale_price,
t1.earning_price,
t1.weight,
t1.sku_type,
t1.promotion_type,
t1.order_created_at,
t1.store_sub_id,
t1.store_sub_name,
t1.vendor_price,
IF(t3.img IS NULL OR t3.img = '', t4.image, t3.img) image, %s full_sku_name
FROM order_sku t1
LEFT JOIN sku t2 ON IF(t1.jx_sku_id != 0, t1.jx_sku_id, t1.sku_id) = t2.id/* AND t2.deleted_at = ?*/
LEFT JOIN sku_name t3 ON t2.name_id = t3.id/* AND t3.deleted_at = ?*/
LEFT JOIN jde_sku_infos t4 ON t1.vendor_sku_id = t4.skuId
WHERE vendor_order_id = ? AND vendor_id = ?
ORDER BY t1.sku_name
`, fullSkuNameSQL), /*, utils.DefaultTimeValue, utils.DefaultTimeValue*/ vendorOrderID, vendorID)
err = dao.GetRows(db, &skus, sql+`
IF(t3.img <> '', t3.img, t4.image) image
FROM order_sku t1
LEFT JOIN goods_order t6 ON t6.vendor_order_id = t1.vendor_order_id AND t6.vendor_id = t1.vendor_id
LEFT JOIN store t5 ON t5.id = IF(t6.jx_store_id <> 0, t6.jx_store_id, t6.store_id)
LEFT JOIN sku t2 ON IF(t1.jx_sku_id != 0, t1.jx_sku_id, t1.sku_id) = t2.id/* AND t2.deleted_at = ?*/
LEFT JOIN sku_name t3 ON t2.name_id = t3.id/* AND t3.deleted_at = ?*/
LEFT JOIN jde_sku_infos t4 ON t1.vendor_sku_id = t4.skuId
WHERE t1.vendor_order_id = ? AND t1.vendor_id = ?
ORDER BY t1.sku_name
`, /*, utils.DefaultTimeValue, utils.DefaultTimeValue*/ vendorOrderID, vendorID)
}
if err != nil || len(skus) == 0 {
err = dao.GetRows(db, &skus, fmt.Sprintf(`
SELECT
t1.id,
t1.vendor_order_id,
t1.vendor_id,
t1.count,
t1.vendor_sku_id,
t1.sku_id,
t1.jx_sku_id,
t1.sku_name,
IF(t1.shop_price = 0, t1.sale_price, t1.shop_price) shop_price,
t1.sale_price,
t1.earning_price,
t1.weight,
t1.sku_type,
t1.promotion_type,
t1.order_created_at,
t1.store_sub_id,
t1.store_sub_name,
t1.vendor_price,
t3.img image, %s full_sku_name
FROM order_sku t1
LEFT JOIN sku t2 ON IF(t1.jx_sku_id != 0, t1.jx_sku_id, t1.sku_id) = t2.id/* AND t2.deleted_at = ?*/
LEFT JOIN sku_name t3 ON t2.name_id = t3.id/* AND t3.deleted_at = ?*/
WHERE t1.vendor_order_id = ? AND t1.vendor_id = ?
ORDER BY t1.sku_name
`, fullSkuNameSQL), /*, utils.DefaultTimeValue, utils.DefaultTimeValue*/ vendorOrderID, vendorID)
err = dao.GetRows(db, &skus, sql+`
t3.img image
FROM order_sku t1
LEFT JOIN goods_order t6 ON t6.vendor_order_id = t1.vendor_order_id AND t6.vendor_id = t1.vendor_id
LEFT JOIN store t5 ON t5.id = IF(t6.jx_store_id <> 0, t6.jx_store_id, t6.store_id)
LEFT JOIN sku t2 ON IF(t1.jx_sku_id != 0, t1.jx_sku_id, t1.sku_id) = t2.id/* AND t2.deleted_at = ?*/
LEFT JOIN sku_name t3 ON t2.name_id = t3.id/* AND t3.deleted_at = ?*/
WHERE t1.vendor_order_id = ? AND t1.vendor_id = ?
ORDER BY t1.sku_name
`, /*, utils.DefaultTimeValue, utils.DefaultTimeValue*/ vendorOrderID, vendorID)
if err != nil {
globals.SugarLogger.Infof("GetOrderSkuInfo orderID:%s vendorID:%d failed with error:%v", vendorOrderID, vendorID, err)
return nil, err
@@ -281,11 +253,11 @@ func (c *OrderManager) getOrders(ctx *jxcontext.Context, isIncludeSku bool, from
if offset < 0 {
offset = 0
}
sql := `
sql := fmt.Sprintf(`
SELECT SQL_CALC_FOUND_ROWS t1.*,
CAST(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, 70) / 100) AS SIGNED) earning_price,
CAST(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, %d) / 100) AS SIGNED) earning_price,
t2.status waybill_status, t2.courier_name, t2.courier_mobile,
t2.actual_fee, t2.desired_fee, t2.waybill_created_at, t2.waybill_finished_at`
t2.actual_fee, t2.desired_fee, t2.waybill_created_at, t2.waybill_finished_at`, model.DefaultEarningPricePercentage)
if isIncludeSku {
sql += `,
t3.sku_id, t3.count sku_count2, t3.shop_price sku_shop_price, IF(t3.earning_price <> 0, t3.earning_price, t3.sale_price) sku_sale_price`
@@ -780,14 +752,14 @@ func (c *OrderManager) GetStoresOrderSaleInfo(ctx *jxcontext.Context, storeIDLis
return nil, fmt.Errorf("查询时间范围不能超过60天")
}
// 用int64类型去取float型的数据库返回值会取不到
sql := `
sql := fmt.Sprintf(`
SELECT IF(t1.jx_store_id > 0, t1.jx_store_id, t1.store_id) store_id, t1.vendor_id, IF(t1.status < ?, 0, t1.status) status,
COUNT(*) count, SUM(t1.shop_price) shop_price, SUM(t1.vendor_price) vendor_price, SUM(t1.sale_price) sale_price, SUM(t1.actual_pay_price) actual_pay_price,
CAST(SUM(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, 70) / 100)) AS SIGNED) earning_price
CAST(SUM(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, %d) / 100)) AS SIGNED) earning_price
FROM goods_order t1
LEFT JOIN store t5 ON t5.id = IF(t1.jx_store_id <> 0, t1.jx_store_id, t1.store_id)
WHERE t1.order_created_at >= ? AND t1.order_created_at <= ?
`
`, model.DefaultEarningPricePercentage)
sqlParams := []interface{}{
model.OrderStatusEndBegin,
fromTime,

View File

@@ -374,3 +374,15 @@ func GuessVendorIDFromVendorStoreID(vendorStoreID int64) (vendorID int) {
func GetVendorName(vendorID int) (vendorName string) {
return model.VendorChineseNames[vendorID]
}
func CaculateSkuEarningPrice(shopPrice, salePrice int64, storePayPercentage int) (earningPrice int64) {
earningPrice = salePrice
if shopPrice > 0 && shopPrice < earningPrice {
earningPrice = shopPrice
}
if storePayPercentage <= 0 {
storePayPercentage = model.DefaultEarningPricePercentage
}
earningPrice = earningPrice * int64(storePayPercentage) / 100
return earningPrice
}

View File

@@ -35,8 +35,9 @@ type GoodsOrderExt struct {
type OrderSkuExt struct {
OrderSku
FullSkuName string `json:"fullSkuName"`
Image string `json:"image"`
FullSkuName string `json:"fullSkuName"`
Image string `json:"image"`
RealEarningPrice int64 `json:"realEarningPrice"` // 实际单品结算给门店老板钱
}
type GoodsOrderCountInfo struct {