Merge remote-tracking branch 'origin/mark' into don

This commit is contained in:
Rosy-zhudan
2019-08-16 14:29:07 +08:00
19 changed files with 262 additions and 37 deletions

View File

@@ -3,9 +3,9 @@ package model
type AppKeyConfig struct {
ModelIDCULD
VendorID int
AppKey string // 同一平台下不同的Key
AppCode string // 同一平台下不同的商户代码
Name string
AppName string
AppType int
Value1 string
Value2 string

View File

@@ -8,6 +8,10 @@ import (
"git.rosy.net.cn/jx-callback/business/model"
)
const (
AfsOrderStatus = -1
)
type StoresOrderSaleInfo struct {
StoreID int `orm:"column(store_id)" json:"storeID"`
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
@@ -122,6 +126,7 @@ func GetAfsOrders(db *DaoDB, vendorID int, vendorOrderID, afsOrderID string) (af
return afsOrderList, err
}
// 时间范围是订单完成时间
func GetStoresOrderSaleInfo(db *DaoDB, storeIDList []int, fromTime time.Time, toTime time.Time, statusList []int) (saleInfoList []*StoresOrderSaleInfo, err error) {
if utils.IsTimeZero(fromTime) {
return nil, fmt.Errorf("查询订单信息必须指定起始时间")
@@ -135,13 +140,13 @@ func GetStoresOrderSaleInfo(db *DaoDB, storeIDList []int, fromTime time.Time, to
// 用int64类型去取float型的数据库返回值会取不到
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, %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_finished_at >= ? AND t1.order_finished_at <= ?
`, model.DefaultEarningPricePercentage)
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, %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_finished_at >= ? AND t1.order_finished_at <= ?
`, model.DefaultEarningPricePercentage)
sqlParams := []interface{}{
model.OrderStatusEndBegin,
fromTime,
@@ -156,8 +161,29 @@ func GetStoresOrderSaleInfo(db *DaoDB, storeIDList []int, fromTime time.Time, to
sqlParams = append(sqlParams, statusList)
}
sql += `
GROUP BY 1,2,3
ORDER BY 1,2,3`
GROUP BY 1,2,3`
sql += fmt.Sprintf(`
UNION
SELECT IF(t0.jx_store_id > 0, t0.jx_store_id, t0.store_id) store_id, t0.vendor_id, -1 status,
COUNT(*) count, SUM(t1.shop_price) shop_price, SUM(t1.vendor_price) vendor_price, SUM(t1.sale_price) sale_price, 0 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, %d) / 100)) AS SIGNED) earning_price
FROM afs_order t0
JOIN order_sku_financial t2 ON t2.afs_order_id = t0.afs_order_id AND t2.vendor_id = t0.vendor_id AND t2.is_afs_order = 1
JOIN order_sku t1 ON t1.vendor_order_id = t2.vendor_order_id AND t1.vendor_id = t2.vendor_id AND t1.sku_id = t2.sku_id
LEFT JOIN store t5 ON t5.id = IF(t0.jx_store_id <> 0, t0.jx_store_id, t0.store_id)
WHERE t0.afs_finished_at >= ? AND t0.afs_finished_at <= ?`, model.DefaultEarningPricePercentage)
sqlParams = append(sqlParams, []interface{}{
fromTime,
toTime,
})
if len(storeIDList) > 0 {
sql += " AND IF(t0.jx_store_id > 0, t0.jx_store_id, t0.store_id) IN (" + GenQuestionMarks(len(storeIDList)) + ")"
sqlParams = append(sqlParams, storeIDList)
}
sql += `
GROUP BY 1,2,3`
sql += " ORDER BY 1,2,3"
err = GetRows(db, &saleInfoList, sql, sqlParams...)
return saleInfoList, err
}

View File

@@ -84,7 +84,7 @@ type OrderSku struct {
ID int64 `orm:"column(id)" json:"-"`
VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"`
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
StoreSubID int `orm:"column(store_sub_id)" json:"storeSubID"` // 当前这个字段被当成活动ID用
StoreSubID int `orm:"column(store_sub_id)" json:"storeSubID"` // 当前这个字段被当成结算活动ID用
StoreSubName string `orm:"size(64)" json:"storeSubName"` // 当前这个字段被用作vendorActType
Count int `json:"count"`
VendorSkuID string `orm:"column(vendor_sku_id);size(48)" json:"vendorSkuID"`
@@ -94,7 +94,7 @@ type OrderSku struct {
ShopPrice int64 `json:"shopPrice"` // 京西价
VendorPrice int64 `json:"vendorPrice"` // 平台价
SalePrice int64 `json:"salePrice"` // 售卖价
EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱
EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱如果结算活动ID为0是按结算比例算的否则就是结算表中的值
Weight int `json:"weight"` // 单位为克
SkuType int `json:"skuType"` // 当前如果为gift就为1否则缺省为0
PromotionType int `json:"promotionType"` // todo 当前是用于记录京东的PromotionType(生成jxorder用),没有做转换

View File

@@ -155,6 +155,13 @@ type OrderSkuFinancial struct {
StoreSubName string `orm:"size(64)" json:"storeSubName"` // 当前这个字段被用作vendorActType
}
// todo
// func (o *OrderSkuFinancial) TableUnique() [][]string {
// return [][]string{
// []string{"AfsOrderID", "VendorSkuID", "VendorID", "IsAfsOrder"},
// }
// }
func (o *OrderSkuFinancial) TableIndex() [][]string {
return [][]string{
[]string{"VendorOrderID", "VendorSkuID"},