This commit is contained in:
苏尹岚
2021-03-26 17:31:10 +08:00
parent d56beac926
commit 8cb61ef62d
5 changed files with 69 additions and 45 deletions

View File

@@ -225,6 +225,8 @@ func (c *OrderManager) OnOrderStatusChanged(vendorOrgCode string, orderStatus *m
//如果取消订单则要把库存加回去 //如果取消订单则要把库存加回去
if order, err2 := c.LoadOrder(orderStatus.VendorOrderID, orderStatus.VendorID); err2 == nil { if order, err2 := c.LoadOrder(orderStatus.VendorOrderID, orderStatus.VendorID); err2 == nil {
ModifyOrderSkusStock(db, order, true) ModifyOrderSkusStock(db, order, true)
//门店发单的订单,取消后要退回配送费
resetCreateWaybillFee(db, order)
} }
} }
if !isDuplicated { if !isDuplicated {
@@ -405,6 +407,16 @@ func filterOrderInfo(order *model.GoodsOrder) {
order.ConsigneeAddress = strings.ReplaceAll(order.ConsigneeAddress, "·", "") order.ConsigneeAddress = strings.ReplaceAll(order.ConsigneeAddress, "·", "")
} }
func resetCreateWaybillFee(db *dao.DaoDB, order *model.GoodsOrder) (err error) {
store, _ := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, order.VendorOrgCode)
if store != nil {
if expend, lastFee, err := partner.CurStoreAcctManager.GetStoreAcctExpendLastCreateWayBillFee(order.VendorOrderID); err == nil {
partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(jxcontext.AdminCtx, jxutils.GetSaleStoreIDFromOrder(order), lastFee, partner.StoreAcctTypeIncomeCancelReal, order.VendorOrderID, expend.ID)
}
}
return err
}
func checkPriceDefendOrderByStock(db *dao.DaoDB, storeID, skuID, stock, jxPrice int) (realStock int) { func checkPriceDefendOrderByStock(db *dao.DaoDB, storeID, skuID, stock, jxPrice int) (realStock int) {
var ( var (
sumStock = 0 sumStock = 0

View File

@@ -587,7 +587,9 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
s.solutionJdsOrder(bill) s.solutionJdsOrder(bill)
} }
//门店发单的门店,需要根据实际运费更新账户(多退少补) //门店发单的门店,需要根据实际运费更新账户(多退少补)
s.updateStoreAccount(order, bill) if savedOrderInfo.storeDetail.CreateDeliveryType == model.YES {
s.updateStoreAccount(order, bill)
}
//订单已经是结束状态之后来的运单143945553920000001 //订单已经是结束状态之后来的运单143945553920000001
if order.Status > model.OrderStatusEndBegin { if order.Status > model.OrderStatusEndBegin {
s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime) s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime)
@@ -1321,7 +1323,20 @@ func (s *DefScheduler) updateOrderByBill(order *model.GoodsOrder, bill *model.Wa
} }
func (s *DefScheduler) updateStoreAccount(order *model.GoodsOrder, bill *model.Waybill) { func (s *DefScheduler) updateStoreAccount(order *model.GoodsOrder, bill *model.Waybill) {
realDesiredFee := bill.DesiredFee
if expend, lastFee, err := partner.CurStoreAcctManager.GetStoreAcctExpendLastCreateWayBillFee(order.VendorOrderID); err == nil {
lastFee64 := int64(lastFee)
if lastFee64 != realDesiredFee {
var diffFee int64
if lastFee64 > realDesiredFee {
diffFee = lastFee64 - realDesiredFee
partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(jxcontext.AdminCtx, jxutils.GetSaleStoreIDFromOrder(order), int(diffFee), partner.StoreAcctTypeRealFeeIncome, order.VendorOrderID, expend.ID)
} else {
diffFee = realDesiredFee - lastFee64
partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(jxcontext.AdminCtx, jxutils.GetSaleStoreIDFromOrder(order), int(diffFee), partner.StoreAcctTypeRealFeeExpend, order.VendorOrderID, expend.ID)
}
}
}
} }
func (s *DefScheduler) updateBillsInfo(savedOrderInfo *WatchOrderInfo, bill *model.Waybill) (isBillExist bool) { func (s *DefScheduler) updateBillsInfo(savedOrderInfo *WatchOrderInfo, bill *model.Waybill) (isBillExist bool) {

View File

@@ -2052,9 +2052,9 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
case 1: case 1:
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
var ( var (
v = batchItemList[0].(*model.SkuName) v = batchItemList[0].(*model.SkuName)
skuNames []model.SkuName sku *model.SkuName
skuName = &model.SkuNameExt{ skuName = &model.SkuNameExt{
SkuName: model.SkuName{}, SkuName: model.SkuName{},
Skus: []*model.SkuWithVendor{ Skus: []*model.SkuWithVendor{
&model.SkuWithVendor{ &model.SkuWithVendor{
@@ -2078,8 +2078,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
SELECT * FROM sku_name WHERE upc = ? AND deleted_at = ? SELECT * FROM sku_name WHERE upc = ? AND deleted_at = ?
` `
sqlParams := []interface{}{*v.Upc, utils.DefaultTimeValue} sqlParams := []interface{}{*v.Upc, utils.DefaultTimeValue}
err = dao.GetRows(db, &skuNames, sql, sqlParams) if err = dao.GetRow(db, &sku, sql, sqlParams); err == nil && sku != nil {
if len(skuNames) > 0 {
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "商品在京西库中已存在!")} // retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "商品在京西库中已存在!")}
return retVal, err return retVal, err
} }
@@ -2123,32 +2122,27 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
} }
} }
if v.Price == 0 { if v.Price == 0 {
result, err := api.AliUpcAPI.GetAliUpcInfo(*v.Upc) if productInfo.Price != 0 {
if err != nil { skuName.Price = productInfo.Price
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())} } else {
return retVal, err
}
if result.Price == "" {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品售价,请补充商品售价!")} retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品售价,请补充商品售价!")}
return retVal, err return retVal, err
} else {
skuName.Price = int(utils.Str2Int64(result.Price) * 100)
} }
} else { } else {
skuName.Price = v.Price skuName.Price = v.Price
} }
skuName.Name = productInfo.Name skuName.Name = productInfo.Name
getNetUpcInfo, err := api.AliUpcAPI.GetNetUpcInfo(*v.Upc) // getNetUpcInfo, err := api.AliUpcAPI.GetNetUpcInfo(*v.Upc)
if v.Unit != "" { if v.Unit != "" {
skuName.Unit = v.Unit skuName.Unit = v.Unit
} else { } else {
if productInfo.Unit == "" { if productInfo.Unit == "" {
if getNetUpcInfo.Unit != "" { // if getNetUpcInfo.Unit != "" {
skuName.Unit = getNetUpcInfo.Unit // skuName.Unit = getNetUpcInfo.Unit
} else { // } else {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品单位,请补充商品单位!")} retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品单位,请补充商品单位!")}
return retVal, err return retVal, err
} // }
} else { } else {
skuName.Unit = productInfo.Unit skuName.Unit = productInfo.Unit
} }
@@ -2168,18 +2162,18 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
} }
} else { } else {
if productInfo.SpecQuality == 0 { if productInfo.SpecQuality == 0 {
if getNetUpcInfo.SpecQuality != 0 { // if getNetUpcInfo.SpecQuality != 0 {
if getNetUpcInfo.SpecUnit == model.SpecUnitNames[1] || getNetUpcInfo.SpecUnit == model.SpecUnitNames[2] || // if getNetUpcInfo.SpecUnit == model.SpecUnitNames[1] || getNetUpcInfo.SpecUnit == model.SpecUnitNames[2] ||
getNetUpcInfo.SpecUnit == "KG" || getNetUpcInfo.SpecUnit == "l" { // getNetUpcInfo.SpecUnit == "KG" || getNetUpcInfo.SpecUnit == "l" {
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(getNetUpcInfo.SpecQuality) * 1000))) // skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(getNetUpcInfo.SpecQuality) * 1000)))
} else { // } else {
skuName.Skus[0].Weight = utils.Float32ToInt(getNetUpcInfo.SpecQuality) // skuName.Skus[0].Weight = utils.Float32ToInt(getNetUpcInfo.SpecQuality)
} // }
skuName.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality // skuName.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality
} else { // } else {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品重量,请补充商品重量!")} retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品重量,请补充商品重量!")}
return retVal, err return retVal, err
} // }
} else { } else {
if productInfo.Weight != 0 { if productInfo.Weight != 0 {
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(productInfo.Weight)))) skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(productInfo.Weight))))
@@ -2190,11 +2184,11 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
} }
} }
if productInfo.SpecUnit == "" { if productInfo.SpecUnit == "" {
if getNetUpcInfo.SpecUnit != "" { // if getNetUpcInfo.SpecUnit != "" {
skuName.Skus[0].SpecUnit = getNetUpcInfo.SpecUnit // skuName.Skus[0].SpecUnit = getNetUpcInfo.SpecUnit
} else { // } else {
skuName.Skus[0].SpecUnit = model.SpecUnitNames[0] skuName.Skus[0].SpecUnit = model.SpecUnitNames[0]
} // }
} else { } else {
skuName.Skus[0].SpecUnit = productInfo.SpecUnit skuName.Skus[0].SpecUnit = productInfo.SpecUnit
} }

View File

@@ -21,7 +21,7 @@ func init() {
partner.InitStoreAcctManager(FixedStoreAcctManager) partner.InitStoreAcctManager(FixedStoreAcctManager)
} }
func (s *StoreAcctManager) InsertStoreAcctIncome(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string) (err error) { func (s *StoreAcctManager) InsertStoreAcctIncome(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error) {
var ( var (
userID, userName string userID, userName string
goodsVendorOrderID string goodsVendorOrderID string
@@ -49,6 +49,9 @@ func (s *StoreAcctManager) InsertStoreAcctIncome(ctx *jxcontext.Context, storeID
VendorOrderID: goodsVendorOrderID, VendorOrderID: goodsVendorOrderID,
} }
dao.WrapAddIDCULEntity(storeAcctIncome, userName) dao.WrapAddIDCULEntity(storeAcctIncome, userName)
if expendID != 0 {
storeAcctIncome.ExpID = expendID
}
err = dao.CreateEntity(db, storeAcctIncome) err = dao.CreateEntity(db, storeAcctIncome)
globals.SugarLogger.Debugf("InsertStoreAcctIncome orderID: [%v] , price :[%v] , type :[%v]", vendorOrderID, price, acctType) globals.SugarLogger.Debugf("InsertStoreAcctIncome orderID: [%v] , price :[%v] , type :[%v]", vendorOrderID, price, acctType)
return err return err
@@ -80,7 +83,7 @@ func (s *StoreAcctManager) InsertStoreAcctExpend(ctx *jxcontext.Context, storeID
} }
dao.WrapAddIDCULEntity(storeAcctExpend, userName) dao.WrapAddIDCULEntity(storeAcctExpend, userName)
if expendID != 0 { if expendID != 0 {
storeAcctExpend.ExpID = expendID
} }
err = dao.CreateEntity(db, storeAcctExpend) err = dao.CreateEntity(db, storeAcctExpend)
globals.SugarLogger.Debugf("InsertStoreAcctExpend orderID: [%v] , price :[%v] , type :[%v]", vendorOrderID, price, acctType) globals.SugarLogger.Debugf("InsertStoreAcctExpend orderID: [%v] , price :[%v] , type :[%v]", vendorOrderID, price, acctType)
@@ -140,9 +143,9 @@ func (s *StoreAcctManager) InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx *j
return err return err
} }
func (s *StoreAcctManager) InsertStoreAcctIncomeAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string) (err error) { func (s *StoreAcctManager) InsertStoreAcctIncomeAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error) {
utils.CallFuncAsync(func() { utils.CallFuncAsync(func() {
if err = s.InsertStoreAcctIncome(ctx, storeID, price, acctType, vendorOrderID); err == nil { if err = s.InsertStoreAcctIncome(ctx, storeID, price, acctType, vendorOrderID, expendID); err == nil {
s.UpdateStoreAcctBalance(ctx, storeID, price, true) s.UpdateStoreAcctBalance(ctx, storeID, price, true)
} }
}) })

View File

@@ -33,13 +33,13 @@ func InitStoreAcctManager(curStoreManager IStoreAcctManager) {
type IStoreAcctManager interface { type IStoreAcctManager interface {
//增加一条收入流水 //增加一条收入流水
InsertStoreAcctIncome(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string) (err error) InsertStoreAcctIncome(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error)
//增加一条支出流水 //增加一条支出流水
InsertStoreAcctExpend(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error) InsertStoreAcctExpend(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error)
//更新门店账户 //更新门店账户
UpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price int, isIncome bool) (err error) UpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price int, isIncome bool) (err error)
InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error) InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error)
InsertStoreAcctIncomeAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string) (err error) InsertStoreAcctIncomeAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error)
CheckStoreAcctExpendExist(vendorOrderID string) (isEqual, isZero bool, err error) CheckStoreAcctExpendExist(vendorOrderID string) (isEqual, isZero bool, err error)
GetStoreAcctExpendLastCreateWayBillFee(vendorOrderID string) (expend *dao.GetStoreAcctExpendLastCreateWayBillFeeResult, lastFee int, err error) GetStoreAcctExpendLastCreateWayBillFee(vendorOrderID string) (expend *dao.GetStoreAcctExpendLastCreateWayBillFeeResult, lastFee int, err error)
} }