|
|
@@ -71,6 +71,9 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
|
//2、获取masterId |
|
|
|
masterId := utils.StrToInt(strings.Split(canalMsg.Database, "_")[1]) |
|
|
|
|
|
|
|
//TODO::日志记录 |
|
|
|
utils.FilePutContents("handleCanalGuideOrderForNumericalStatementTable_"+utils.IntToStr(masterId)+"_"+now.Format("2006-01-02"), string(msg)) |
|
|
|
|
|
|
|
//2、判断操作(insert | update) |
|
|
|
if canalMsg.Type == md.CanalMsgInsertSqlType || canalMsg.Type == md.CanalMsgUpdateSqlType { |
|
|
|
var isUpdate bool |
|
|
@@ -83,7 +86,7 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if statistics == nil { |
|
|
|
if statistics == nil && canalMsg.Type == md.CanalMsgInsertSqlType { |
|
|
|
statistics = &model.MasterGuideOrderStatistics{ |
|
|
|
MasterId: masterId, |
|
|
|
PaymentTotal: "", |
|
|
@@ -107,6 +110,9 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
if statistics == nil { |
|
|
|
return errors.New("过期订单数据不予处理") |
|
|
|
} |
|
|
|
|
|
|
|
paymentTotal := statistics.PaymentTotal |
|
|
|
orderCount := statistics.OrderCount |
|
|
@@ -116,20 +122,26 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
|
placeOrderNumOfPeople := statistics.PlaceOrderNumOfPeople |
|
|
|
effectiveOrderCount := statistics.EffectiveOrderCount |
|
|
|
effectiveCommission := statistics.EffectiveCommission |
|
|
|
receiveCommission := statistics.ReceiveCommission |
|
|
|
loseCommission := statistics.LoseCommission |
|
|
|
avgCommission := statistics.AvgCommission |
|
|
|
customerUnitPrice := statistics.CustomerUnitPrice |
|
|
|
effectivePaymentTotal := statistics.EffectivePaymentTotal |
|
|
|
if canalMsg.Type == md.CanalMsgInsertSqlType { |
|
|
|
for _, item := range canalMsg.Data { |
|
|
|
orderCount++ |
|
|
|
effectiveOrderCount++ |
|
|
|
if item.State == "4" { |
|
|
|
loseOrderCount++ |
|
|
|
} else { |
|
|
|
effectiveOrderCount++ |
|
|
|
} |
|
|
|
|
|
|
|
cacheKey := fmt.Sprintf(ZhiOsGuidePlaceOrderNumOfPeopleHashMapCacheKey, utils.IntToStr(masterId), ordDate) |
|
|
|
get, _ := cache.HGetString(cacheKey, item.Uid) |
|
|
|
paymentTotal = utils.Float64ToStr(utils.StrToFloat64(paymentTotal) + utils.StrToFloat64(item.PaidPrice)) |
|
|
|
estimatedCommission = utils.Float64ToStr(utils.StrToFloat64(estimatedCommission) + utils.StrToFloat64(item.BenefitAll)) |
|
|
|
estimatedProfit = utils.Float64ToStr(utils.StrToFloat64(estimatedProfit) + utils.StrToFloat64(item.SysCommission)) |
|
|
|
effectiveCommission = utils.Float64ToStr(utils.StrToFloat64(effectiveCommission) + utils.StrToFloat64(item.BenefitAll)) |
|
|
|
paymentTotal = utils.Float64ToStr(utils.StrToFloat64(paymentTotal) + utils.StrToFloat64(item.PaidPrice)) //付款金额 |
|
|
|
estimatedCommission = utils.Float64ToStr(utils.StrToFloat64(estimatedCommission) + utils.StrToFloat64(item.BenefitAll)) //预估佣金(元) |
|
|
|
estimatedProfit = utils.Float64ToStr(utils.StrToFloat64(estimatedProfit) + utils.StrToFloat64(item.SysCommission)) //预估利润(元) |
|
|
|
effectiveCommission = utils.Float64ToStr(utils.StrToFloat64(effectiveCommission) + utils.StrToFloat64(item.BenefitAll)) //有效佣金(元) |
|
|
|
effectivePaymentTotal = utils.Float64ToStr(utils.StrToFloat64(effectivePaymentTotal) + utils.StrToFloat64(item.PaidPrice)) //有效付款金额(元) |
|
|
|
|
|
|
|
estimatedCommissionValue, _ := decimal.NewFromString(estimatedCommission) |
|
|
|
orderCountValue := decimal.NewFromInt(int64(orderCount)) |
|
|
@@ -142,7 +154,6 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
|
cache.HSet(cacheKey, item.Uid, utils.IntToStr(utils.StrToInt(get)+1)) |
|
|
|
} |
|
|
|
cache.Expire(cacheKey, md.ZhiOsUserVisitIpAddressHashMapCacheTime) |
|
|
|
|
|
|
|
paymentTotalValue, _ := decimal.NewFromString(paymentTotal) |
|
|
|
if placeOrderNumOfPeople == 0 { |
|
|
|
return errors.New("divider cannot be 0 in division operation") |
|
|
@@ -156,13 +167,6 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
|
if canalMsg.Type == md.CanalMsgUpdateSqlType { |
|
|
|
judgeSate := JudgeSate(*canalMsg) |
|
|
|
if judgeSate > 0 { |
|
|
|
if judgeSate == 1 { |
|
|
|
//TODO::收货 |
|
|
|
for _, item := range canalMsg.Data { |
|
|
|
receiveCommission = utils.Float64ToStr(utils.StrToFloat64(receiveCommission) + utils.StrToFloat64(item.BenefitAll)) |
|
|
|
isUpdate = true |
|
|
|
} |
|
|
|
} |
|
|
|
if judgeSate == 2 { |
|
|
|
//TODO::未收货失效 |
|
|
|
loseOrderCount++ |
|
|
@@ -170,6 +174,7 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
|
for _, item := range canalMsg.Data { |
|
|
|
loseCommission = utils.Float64ToStr(utils.StrToFloat64(loseCommission) + utils.StrToFloat64(item.BenefitAll)) |
|
|
|
effectiveCommission = utils.Float64ToStr(utils.StrToFloat64(effectiveCommission) - utils.StrToFloat64(item.BenefitAll)) |
|
|
|
effectivePaymentTotal = utils.Float64ToStr(utils.StrToFloat64(effectivePaymentTotal) - utils.StrToFloat64(item.PaidPrice)) |
|
|
|
isUpdate = true |
|
|
|
} |
|
|
|
} |
|
|
@@ -180,10 +185,43 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
|
for _, item := range canalMsg.Data { |
|
|
|
loseCommission = utils.Float64ToStr(utils.StrToFloat64(loseCommission) + utils.StrToFloat64(item.BenefitAll)) |
|
|
|
effectiveCommission = utils.Float64ToStr(utils.StrToFloat64(effectiveCommission) - utils.StrToFloat64(item.BenefitAll)) |
|
|
|
receiveCommission = utils.Float64ToStr(utils.StrToFloat64(receiveCommission) - utils.StrToFloat64(item.BenefitAll)) |
|
|
|
effectivePaymentTotal = utils.Float64ToStr(utils.StrToFloat64(effectivePaymentTotal) - utils.StrToFloat64(item.PaidPrice)) |
|
|
|
isUpdate = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if judgeSate == 1 || judgeSate == 3 { |
|
|
|
//TODO::收货额外处理 |
|
|
|
|
|
|
|
//查找是否有数据 |
|
|
|
var ordConfirmAt string |
|
|
|
for _, item := range canalMsg.Data { |
|
|
|
ordConfirmAt = time.Unix(utils.StrToInt64(item.ConfirmAt), 0).Format("2006-01-02") |
|
|
|
} |
|
|
|
ordConfirmStatistics, err := db2.GetMasterGuideOrderStatistics(db.Db, masterId, ordConfirmAt) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if ordConfirmStatistics == nil { |
|
|
|
return errors.New("过期收货订单数据不予处理") |
|
|
|
} |
|
|
|
|
|
|
|
if judgeSate == 1 { |
|
|
|
//TODO::收货 |
|
|
|
for _, item := range canalMsg.Data { |
|
|
|
ordConfirmStatistics.ReceiveCommission = utils.Float64ToStr(utils.StrToFloat64(ordConfirmStatistics.ReceiveCommission) + utils.StrToFloat64(item.BenefitAll)) |
|
|
|
} |
|
|
|
} |
|
|
|
if judgeSate == 3 { |
|
|
|
//TODO::已收货失效 |
|
|
|
for _, item := range canalMsg.Data { |
|
|
|
ordConfirmStatistics.ReceiveCommission = utils.Float64ToStr(utils.StrToFloat64(ordConfirmStatistics.ReceiveCommission) - utils.StrToFloat64(item.BenefitAll)) |
|
|
|
} |
|
|
|
} |
|
|
|
ordConfirmStatistics.UpdateAt = now.Format("2006-01-02 15:04:05") |
|
|
|
_, err = db2.MasterGuideOrderStatisticsUpdate(db.Db, ordConfirmStatistics.Id, ordConfirmStatistics, |
|
|
|
"receive_commission", "update_at") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -196,19 +234,20 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
|
statistics.PlaceOrderNumOfPeople = placeOrderNumOfPeople |
|
|
|
statistics.EffectiveOrderCount = effectiveOrderCount |
|
|
|
statistics.EffectiveCommission = effectiveCommission |
|
|
|
statistics.ReceiveCommission = receiveCommission |
|
|
|
statistics.LoseCommission = loseCommission |
|
|
|
statistics.AvgCommission = avgCommission |
|
|
|
statistics.CustomerUnitPrice = customerUnitPrice |
|
|
|
statistics.EffectivePaymentTotal = effectivePaymentTotal |
|
|
|
statistics.UpdateAt = now.Format("2006-01-02 15:04:05") |
|
|
|
_, err = db2.MasterGuideOrderStatisticsUpdate(db.Db, statistics.Id, statistics, |
|
|
|
"payment_total", "order_count", "estimated_commission", "estimated_profit", "lose_order_count", |
|
|
|
"place_order_num_of_people", "effective_order_count", "effective_commission", "receive_commission", "lose_commission", |
|
|
|
"avg_commission", "customer_unit_price", "update_at") |
|
|
|
"place_order_num_of_people", "effective_order_count", "effective_commission", "lose_commission", |
|
|
|
"avg_commission", "customer_unit_price", "effective_payment_total", "update_at") |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return nil |
|
|
|
} |
|
|
|