|
@@ -14,6 +14,7 @@ import (
|
|
|
"jyOrderManager/internal/jyutil"
|
|
|
"jyOrderManager/internal/logic/product"
|
|
|
"jyOrderManager/internal/model"
|
|
|
+ "jyOrderManager/internal/service"
|
|
|
"log"
|
|
|
"math"
|
|
|
"regexp"
|
|
@@ -53,6 +54,7 @@ type Discount struct {
|
|
|
}
|
|
|
|
|
|
var (
|
|
|
+ GiftDiscount float64
|
|
|
ExamineDiscountConfig map[string][]Discount
|
|
|
)
|
|
|
|
|
@@ -61,6 +63,7 @@ func init() {
|
|
|
if err != nil {
|
|
|
log.Println("examineDiscount", err)
|
|
|
}
|
|
|
+ GiftDiscount = g.Cfg().MustGet(context.Background(), "giftDiscount", 0.8).Float64()
|
|
|
}
|
|
|
|
|
|
// OrdersExamine 订单审核
|
|
@@ -194,8 +197,7 @@ func OrdersExamine(ctx context.Context, param model.OrdersExamine) error {
|
|
|
g.DB().Ctx(ctx).Exec(ctx, query, values...)
|
|
|
}
|
|
|
if contractArchiveTime != "" {
|
|
|
- //TODO 业绩
|
|
|
- //_ = CommonChange(ctx, param.OrderCode, contractArchiveTime, ReturnProtocol)
|
|
|
+ _ = CommonChange(ctx, param.OrderCode, contractArchiveTime, ReturnProtocol)
|
|
|
}
|
|
|
return nil
|
|
|
})
|
|
@@ -221,10 +223,32 @@ func CheckAutoAudit(ctx context.Context, orderData map[string]interface{}, produ
|
|
|
}
|
|
|
isEnt := gconv.Int(orderData["buy_subject"]) == 2
|
|
|
var (
|
|
|
- insertData []string
|
|
|
- activityProduct = make(map[string][]map[string]interface{})
|
|
|
+ insertData []string
|
|
|
+ activityProduct = make(map[string][]map[string]interface{})
|
|
|
+ isXwlp bool
|
|
|
+ beforePrice, afterPrice float64
|
|
|
)
|
|
|
+
|
|
|
for _, m := range productList {
|
|
|
+ productItem, err := service.Product().GetProduct(gconv.String(m["product_code"]))
|
|
|
+ if err != nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ productClass, err := service.Product().GetProductClass(productItem.ProductClassId)
|
|
|
+ if err != nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ //外采赠品
|
|
|
+ // 需“判断订单中常规商品/活动产品的折扣率是否都符合自动审核规则“的同时,
|
|
|
+ //除外采赠品外的其余产品的整体折扣率不得低于XX%,才能自动审核,否则需要人工审核。
|
|
|
+ switch productClass.TopClass == "外采赠品" {
|
|
|
+ case true:
|
|
|
+ isXwlp = true
|
|
|
+ case false:
|
|
|
+ beforePrice += gconv.Float64(m["original_price"])
|
|
|
+ afterPrice += gconv.Float64(m["final_price"])
|
|
|
+ }
|
|
|
+
|
|
|
if common.Float64All(m["original_price"]) < 0 {
|
|
|
return false
|
|
|
}
|
|
@@ -232,7 +256,6 @@ func CheckAutoAudit(ctx context.Context, orderData map[string]interface{}, produ
|
|
|
activityProduct[activityCode] = append(activityProduct[activityCode], m)
|
|
|
continue
|
|
|
}
|
|
|
-
|
|
|
filterMap := make(map[string]interface{})
|
|
|
filterData := common.ObjToString(m["filter"])
|
|
|
if err := json.Unmarshal([]byte(filterData), &filterMap); err != nil {
|
|
@@ -328,9 +351,9 @@ func CheckAutoAudit(ctx context.Context, orderData map[string]interface{}, produ
|
|
|
}
|
|
|
}
|
|
|
default:
|
|
|
- return false
|
|
|
+ examineDiscount = gconv.Float64(productClass.Rate) / 100
|
|
|
}
|
|
|
- if examineDiscount == 0 {
|
|
|
+ if examineDiscount <= 0 {
|
|
|
log.Println("自动审核商品折扣率获取失败")
|
|
|
return false
|
|
|
}
|
|
@@ -370,6 +393,9 @@ func CheckAutoAudit(ctx context.Context, orderData map[string]interface{}, produ
|
|
|
insertData = append(insertData, activityInsertData...)
|
|
|
}
|
|
|
}
|
|
|
+ if isXwlp && beforePrice/afterPrice < GiftDiscount {
|
|
|
+ return false
|
|
|
+ }
|
|
|
if len(insertData) > 0 {
|
|
|
_, err := g.DB().Ctx(ctx).Exec(ctx, fmt.Sprintf(`INSERT INTO audit_records (create_time,pay_money,original_price,discount_rate,order_code,product_type,monthCount,conditional_remarks) VALUES %s`, strings.Join(insertData, ",")))
|
|
|
if err != nil {
|