|
@@ -71,6 +71,9 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
//2、获取masterId |
|
|
//2、获取masterId |
|
|
masterId := utils.StrToInt(strings.Split(canalMsg.Database, "_")[1]) |
|
|
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) |
|
|
//2、判断操作(insert | update) |
|
|
if canalMsg.Type == md.CanalMsgInsertSqlType || canalMsg.Type == md.CanalMsgUpdateSqlType { |
|
|
if canalMsg.Type == md.CanalMsgInsertSqlType || canalMsg.Type == md.CanalMsgUpdateSqlType { |
|
|
var isUpdate bool |
|
|
var isUpdate bool |
|
@@ -83,7 +86,7 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
if statistics == nil { |
|
|
|
|
|
|
|
|
if statistics == nil && canalMsg.Type == md.CanalMsgInsertSqlType { |
|
|
statistics = &model.MasterGuideOrderStatistics{ |
|
|
statistics = &model.MasterGuideOrderStatistics{ |
|
|
MasterId: masterId, |
|
|
MasterId: masterId, |
|
|
PaymentTotal: "", |
|
|
PaymentTotal: "", |
|
@@ -107,6 +110,9 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if statistics == nil { |
|
|
|
|
|
return errors.New("过期订单数据不予处理") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
paymentTotal := statistics.PaymentTotal |
|
|
paymentTotal := statistics.PaymentTotal |
|
|
orderCount := statistics.OrderCount |
|
|
orderCount := statistics.OrderCount |
|
@@ -116,20 +122,26 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
placeOrderNumOfPeople := statistics.PlaceOrderNumOfPeople |
|
|
placeOrderNumOfPeople := statistics.PlaceOrderNumOfPeople |
|
|
effectiveOrderCount := statistics.EffectiveOrderCount |
|
|
effectiveOrderCount := statistics.EffectiveOrderCount |
|
|
effectiveCommission := statistics.EffectiveCommission |
|
|
effectiveCommission := statistics.EffectiveCommission |
|
|
receiveCommission := statistics.ReceiveCommission |
|
|
|
|
|
loseCommission := statistics.LoseCommission |
|
|
loseCommission := statistics.LoseCommission |
|
|
avgCommission := statistics.AvgCommission |
|
|
avgCommission := statistics.AvgCommission |
|
|
customerUnitPrice := statistics.CustomerUnitPrice |
|
|
customerUnitPrice := statistics.CustomerUnitPrice |
|
|
|
|
|
effectivePaymentTotal := statistics.EffectivePaymentTotal |
|
|
if canalMsg.Type == md.CanalMsgInsertSqlType { |
|
|
if canalMsg.Type == md.CanalMsgInsertSqlType { |
|
|
for _, item := range canalMsg.Data { |
|
|
for _, item := range canalMsg.Data { |
|
|
orderCount++ |
|
|
orderCount++ |
|
|
effectiveOrderCount++ |
|
|
|
|
|
|
|
|
if item.State == "4" { |
|
|
|
|
|
loseOrderCount++ |
|
|
|
|
|
} else { |
|
|
|
|
|
effectiveOrderCount++ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
cacheKey := fmt.Sprintf(ZhiOsGuidePlaceOrderNumOfPeopleHashMapCacheKey, utils.IntToStr(masterId), ordDate) |
|
|
cacheKey := fmt.Sprintf(ZhiOsGuidePlaceOrderNumOfPeopleHashMapCacheKey, utils.IntToStr(masterId), ordDate) |
|
|
get, _ := cache.HGetString(cacheKey, item.Uid) |
|
|
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) |
|
|
estimatedCommissionValue, _ := decimal.NewFromString(estimatedCommission) |
|
|
orderCountValue := decimal.NewFromInt(int64(orderCount)) |
|
|
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.HSet(cacheKey, item.Uid, utils.IntToStr(utils.StrToInt(get)+1)) |
|
|
} |
|
|
} |
|
|
cache.Expire(cacheKey, md.ZhiOsUserVisitIpAddressHashMapCacheTime) |
|
|
cache.Expire(cacheKey, md.ZhiOsUserVisitIpAddressHashMapCacheTime) |
|
|
|
|
|
|
|
|
paymentTotalValue, _ := decimal.NewFromString(paymentTotal) |
|
|
paymentTotalValue, _ := decimal.NewFromString(paymentTotal) |
|
|
if placeOrderNumOfPeople == 0 { |
|
|
if placeOrderNumOfPeople == 0 { |
|
|
return errors.New("divider cannot be 0 in division operation") |
|
|
return errors.New("divider cannot be 0 in division operation") |
|
@@ -156,13 +167,6 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
if canalMsg.Type == md.CanalMsgUpdateSqlType { |
|
|
if canalMsg.Type == md.CanalMsgUpdateSqlType { |
|
|
judgeSate := JudgeSate(*canalMsg) |
|
|
judgeSate := JudgeSate(*canalMsg) |
|
|
if judgeSate > 0 { |
|
|
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 { |
|
|
if judgeSate == 2 { |
|
|
//TODO::未收货失效 |
|
|
//TODO::未收货失效 |
|
|
loseOrderCount++ |
|
|
loseOrderCount++ |
|
@@ -170,6 +174,7 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
for _, item := range canalMsg.Data { |
|
|
for _, item := range canalMsg.Data { |
|
|
loseCommission = utils.Float64ToStr(utils.StrToFloat64(loseCommission) + utils.StrToFloat64(item.BenefitAll)) |
|
|
loseCommission = utils.Float64ToStr(utils.StrToFloat64(loseCommission) + utils.StrToFloat64(item.BenefitAll)) |
|
|
effectiveCommission = utils.Float64ToStr(utils.StrToFloat64(effectiveCommission) - 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 |
|
|
isUpdate = true |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@@ -180,10 +185,43 @@ func handleCanalGuideOrderForNumericalStatementTable(msg []byte) error { |
|
|
for _, item := range canalMsg.Data { |
|
|
for _, item := range canalMsg.Data { |
|
|
loseCommission = utils.Float64ToStr(utils.StrToFloat64(loseCommission) + utils.StrToFloat64(item.BenefitAll)) |
|
|
loseCommission = utils.Float64ToStr(utils.StrToFloat64(loseCommission) + utils.StrToFloat64(item.BenefitAll)) |
|
|
effectiveCommission = utils.Float64ToStr(utils.StrToFloat64(effectiveCommission) - 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 |
|
|
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.PlaceOrderNumOfPeople = placeOrderNumOfPeople |
|
|
statistics.EffectiveOrderCount = effectiveOrderCount |
|
|
statistics.EffectiveOrderCount = effectiveOrderCount |
|
|
statistics.EffectiveCommission = effectiveCommission |
|
|
statistics.EffectiveCommission = effectiveCommission |
|
|
statistics.ReceiveCommission = receiveCommission |
|
|
|
|
|
statistics.LoseCommission = loseCommission |
|
|
statistics.LoseCommission = loseCommission |
|
|
statistics.AvgCommission = avgCommission |
|
|
statistics.AvgCommission = avgCommission |
|
|
statistics.CustomerUnitPrice = customerUnitPrice |
|
|
statistics.CustomerUnitPrice = customerUnitPrice |
|
|
|
|
|
statistics.EffectivePaymentTotal = effectivePaymentTotal |
|
|
statistics.UpdateAt = now.Format("2006-01-02 15:04:05") |
|
|
statistics.UpdateAt = now.Format("2006-01-02 15:04:05") |
|
|
_, err = db2.MasterGuideOrderStatisticsUpdate(db.Db, statistics.Id, statistics, |
|
|
_, err = db2.MasterGuideOrderStatisticsUpdate(db.Db, statistics.Id, statistics, |
|
|
"payment_total", "order_count", "estimated_commission", "estimated_profit", "lose_order_count", |
|
|
"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 { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|