Explorar o código

Merge remote-tracking branch 'origin/main'

wkyuer hai 4 meses
pai
achega
7af81a267d

+ 1 - 0
config.yaml

@@ -77,6 +77,7 @@ examineDiscount: #自动审批折扣率
     - min: 12
       max: -1
       discountRate: 0.6
+giftDiscount: 0.8
 
 entAnalysis: 19
 

+ 2 - 2
internal/controller/getSalesChannelItem.go

@@ -11,11 +11,11 @@ import (
 // GetSalesChannelItem 销售区点&0原订单类型
 func GetSalesChannelItem(r *ghttp.Request) {
 	rData, err := func() (interface{}, error) {
-		list, err := order.SalesChannelItem(r.Context())
+		data, err := order.SalesChannelItem(r.Context())
 		if err != nil {
 			return nil, errors.Wrap(err, "销售区点&0原订单类型异常")
 		}
-		return list, nil
+		return data, nil
 	}()
 	if err != nil {
 		g.Log().Errorf(r.Context(), "销售区点&0原订单类型异常 %v", err)

+ 2 - 2
internal/controller/orderGetWorkDay.go

@@ -18,11 +18,11 @@ func OrderGetWorkDay(r *ghttp.Request) {
 		if err != nil {
 			return nil, errors.Wrap(err, "数据校验异常")
 		}
-		list, err := order.GetWorkDay(r.Context(), param)
+		data, err := order.GetWorkDay(r.Context(), param)
 		if err != nil {
 			return nil, errors.Wrap(err, "计算预计回款时间异常")
 		}
-		return list, nil
+		return data, nil
 	}()
 	if err != nil {
 		g.Log().Errorf(r.Context(), "计算预计回款时间异常 %v", err)

+ 2 - 2
internal/controller/orderSeal.go

@@ -18,11 +18,11 @@ func OrderSeal(r *ghttp.Request) {
 		if err != nil {
 			return nil, errors.Wrap(err, "数据校验异常")
 		}
-		list, err := order.OperateOrderSeal(r.Context(), param)
+		data, err := order.OperateOrderSeal(r.Context(), param)
 		if err != nil {
 			return nil, errors.Wrap(err, "订单盖章异常")
 		}
-		return list, nil
+		return data, nil
 	}()
 	if err != nil {
 		g.Log().Errorf(r.Context(), "订单盖章异常 %v", err)

+ 2 - 2
internal/controller/orderSelfInvoice.go

@@ -18,11 +18,11 @@ func OrderSelfInvoice(r *ghttp.Request) {
 		if err != nil {
 			return nil, errors.Wrap(err, "数据校验异常")
 		}
-		list, err := order.SelfInvoice(r.Context(), param)
+		data, err := order.SelfInvoice(r.Context(), param)
 		if err != nil {
 			return nil, errors.Wrap(err, "订单创建异常")
 		}
-		return list, nil
+		return data, nil
 	}()
 	if err != nil {
 		g.Log().Errorf(r.Context(), "订单上传协议异常 %v", err)

+ 2 - 2
internal/controller/orderTransferAccounts.go

@@ -18,11 +18,11 @@ func TransferAccounts(r *ghttp.Request) {
 		if err != nil {
 			return nil, errors.Wrap(err, "数据校验异常")
 		}
-		list, err := order.TransferAccounts(r.Context(), param)
+		data, err := order.TransferAccounts(r.Context(), param)
 		if err != nil {
 			return nil, errors.Wrap(err, "订单创建异常")
 		}
-		return list, nil
+		return data, nil
 	}()
 	if err != nil {
 		g.Log().Errorf(r.Context(), "订单上传协议异常 %v", err)

+ 2 - 2
internal/controller/orderdetail.go

@@ -18,11 +18,11 @@ func OrderDetail(r *ghttp.Request) {
 		if err != nil {
 			return nil, errors.Wrap(err, "数据校验异常")
 		}
-		list, err := order.Detail(r.Context(), param)
+		data, err := order.Detail(r.Context(), param)
 		if err != nil {
 			return nil, errors.Wrap(err, "订单创建异常")
 		}
-		return list, nil
+		return data, nil
 	}()
 	if err != nil {
 		g.Log().Errorf(r.Context(), "创建订单异常 %v", err)

+ 33 - 7
internal/logic/order/examine.go

@@ -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 {

+ 11 - 11
internal/logic/user/getService.go

@@ -30,8 +30,8 @@ func GetUserService(ctx context.Context, param model.UserServiceParams) (interfa
 			})
 			if userData == nil || len(*userData) == 0 {
 				return map[string]interface{}{
-					"willEffect":    false,
-					"userData":      userData,
+					"willEffect": false,
+					//"userData":      userData,
 					"serviceArrMap": nil,
 				}, nil
 			}
@@ -40,7 +40,7 @@ func GetUserService(ctx context.Context, param model.UserServiceParams) (interfa
 				if param.ProductType != "大会员" && param.ProductType != "VIP订阅" {
 					serviceArrMap = SpecialService(ctx, userId, param.ProductType)
 				} else {
-					sqlStr := fmt.Sprintf(`SELECT  b.* FROM jy_order_detail 
+					sqlStr := fmt.Sprintf(`SELECT  * FROM jy_order_detail 
 WHERE status = 1 and is_service_open = 0 and user_id = '%s' and product_type like '%s'  AND service_endtime < '%s'`, userId, common.If(param.ProductType == "VIP订阅", "%VIP订阅%", "%大会员%"), time.Now().Format(date.Date_Full_Layout))
 					if param.OrderCode != "" {
 						sqlStr += fmt.Sprintf(" AND order_code != '%s'", param.OrderCode)
@@ -49,8 +49,8 @@ WHERE status = 1 and is_service_open = 0 and user_id = '%s' and product_type lik
 					order, _ := g.DB().Query(ctx, sqlStr)
 					if !order.IsEmpty() && order.Len() > 0 {
 						return map[string]interface{}{
-							"willEffect":    true,
-							"userData":      userData,
+							"willEffect": true,
+							//"userData":      userData,
 							"serviceArrMap": nil,
 						}, nil
 					}
@@ -69,9 +69,9 @@ WHERE status = 1 and is_service_open = 0 and user_id = '%s' and product_type lik
 						//续费升级关联
 						whereEntTime = "and b.order_status = 1"
 					}
-					orderData, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT  b.id,b.service_type,b.order_code,a.create_time  FROM jy_order_detail  a
+					orderData, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT   a.id,a.service_type,a.order_code,b.create_time   FROM jy_order_detail  a
 INNER JOIN dataexport_order b on a.order_code = b.order_code
-WHERE a.status = 1 %s and a.user_id = '%s' and a.product_type like '%s' ORDER BY a.create_time desc `, whereEntTime, userId, common.If(param.ProductType == "VIP订阅", "%VIP订阅%", "%大会员%")))
+WHERE a.status = 1 %s and a.user_id = '%s' and a.product_type like '%s' ORDER BY b.create_time desc `, whereEntTime, userId, common.If(param.ProductType == "VIP订阅", "%VIP订阅%", "%大会员%")))
 					if !orderData.IsEmpty() {
 						for _, m2 := range orderData.List() {
 							if linkedId == 0 {
@@ -195,8 +195,8 @@ WHERE a.status = 1 %s and a.user_id = '%s' and a.product_type like '%s' ORDER BY
 					nowTime := time.Now().Unix()
 					if nowTime < bigEnd && nowTime < bigStart {
 						return map[string]interface{}{
-							"willEffect":    true,
-							"userData":      userData,
+							"willEffect": true,
+							//"userData":      userData,
 							"serviceArrMap": nil,
 						}, nil
 					}
@@ -286,8 +286,8 @@ WHERE a.ent_id = '%s'  %s and a.product_type like '%s' and  ORDER BY a.end_time
 	}
 
 	return map[string]interface{}{
-		"willEffect":    false,
-		"userData":      userData,
+		"willEffect": false,
+		//"userData":      userData,
 		"serviceArrMap": serviceArrMap,
 	}, nil
 }

+ 1 - 1
internal/model/entOperation.go

@@ -8,7 +8,7 @@ type (
 		ProductType       string    `json:"productType,omitempty"`                             //产品类型
 		UserId            string    `json:"userId,omitempty"`                                  //产品类型
 		MogUserId         string    `json:"mgoUserId,omitempty"`                               //产品类型
-		ServiceType       int       `form:"serviceType" json:"ServiceType,omitempty"`          //付费类型 1:购买 2:续费 3:升级 4:试用
+		ServiceType       int       `json:"service_type,omitempty"`                            //付费类型 1:购买 2:续费 3:升级 4:试用
 		LinkedOrderId     int64     `json:"linkedOrderId,omitempty"`                           //关联订单明细id
 		PaybackOpenServer bool      `json:"paybackOpenServer,omitempty"`                       //是否全额回款开通
 		PayMoney          int       `form:"payMoney" json:"payMoney,omitempty"`                //合同金额

+ 1 - 1
internal/model/jyProductDetail.go

@@ -8,7 +8,7 @@ type (
 		ProductType string `json:"productType,omitempty"` //产品类型
 		//IsServiceOpen     string    `json:"is_service_open"`                                   //是否开通
 		UserId            string    `json:"userId,omitempty"`                                  //userid
-		ServiceType       int       `form:"serviceType" json:"serviceType,omitempty"`          //付费类型 1:购买 2:续费 3:升级 4:试用
+		ServiceType       int       `json:"service_type,omitempty"`                            //付费类型 1:购买 2:续费 3:升级 4:试用
 		LinkedOrderId     string    `json:"linkedOrderId,omitempty"`                           //关联订单明细id
 		PaybackOpenServer bool      `json:"paybackOpenServer,omitempty"`                       //是否全额回款开通
 		ServiceOpenTime   time.Time `json:"service_open_time" gorm:"column:service_open_time"` // 服务开通时间

+ 5 - 5
internal/model/orderFilterIntent.go

@@ -210,7 +210,7 @@ type MedicalDevicePass struct {
 	PaybackNum         string                 `json:"paybackNum"`
 	PaybackOpenServer  bool                   `json:"paybackOpenServer"`
 	PaybackWorkDayNum  int                    `json:"paybackWorkDayNum"`
-	ServiceType        string                 `json:"serviceType"`
+	ServiceType        string                 `json:"service_type"`
 	Remark             string                 `json:"remark"`
 	SellerGiveCycle    int                    `json:"seller_give_cycle"`
 	SellerGiveType     int                    `json:"seller_give_type"`
@@ -424,7 +424,7 @@ type BigMemberSupplementPackage struct {
 	OriginalCommission int           `json:"originalCommission"` //原始佣金
 	OriginalProcedures int           `json:"originalProcedures"` //原始手续费
 	PaySubNum          int           `json:"pay_sub_num"`
-	ServiceType        string        `json:"serviceType"`
+	ServiceType        string        `json:"service_type"`
 	ServersId          string        `json:"serversId"`
 	ServersName        string        `json:"serversName"`
 	Source             string        `json:"source"`
@@ -526,7 +526,7 @@ type BigMemberSubAccount struct {
 	PaybackNum         string      `json:"paybackNum"`
 	PaybackOpenServer  bool        `json:"paybackOpenServer"`
 	PaybackWorkDayNum  int         `json:"paybackWorkDayNum"`
-	ServiceType        string      `json:"serviceType"`
+	ServiceType        string      `json:"service_type"`
 	Remark             string      `json:"remark"`
 	ServersId          string      `json:"serversId"`
 	ServersName        string      `json:"serversName"`
@@ -794,7 +794,7 @@ type BigMemberTenderDocInterpretation struct {
 	OriginalAmount     int    `json:"originalAmount"`     //原始金额
 	OriginalCommission int    `json:"originalCommission"` //原始佣金
 	OriginalProcedures int    `json:"originalProcedures"` //原始手续费
-	ServiceType        string `json:"serviceType"`
+	ServiceType        string `json:"service_type"`
 }
 
 // 印务|综合服务结构体
@@ -887,7 +887,7 @@ type BigMemberAIBidPredictionPackage struct {
 	OriginalAmount     int    `json:"originalAmount"`     //原始金额
 	OriginalCommission int    `json:"originalCommission"` //原始佣金
 	OriginalProcedures int    `json:"originalProcedures"` //原始手续费
-	ServiceType        string `json:"serviceType"`
+	ServiceType        string `json:"service_type"`
 }
 
 // 车辆租赁|采购意向+最新采购结构体

+ 4 - 4
internal/model/orderParams.go

@@ -138,7 +138,7 @@ type (
 		ProductType    string   `json:"productType"`    //产品类型
 		OrderTimeStart string   `json:"orderTimeStart"` //订单其实日期
 		OrderTimeEnd   string   `json:"orderTimeEmd"`   //订单其实日期
-		ServiceType    int      `json:"serviceType"`    //类型  0 全部  1 新购  2 续签 3 升级 4试用
+		ServiceType    int      `json:"service_type"`   //类型  0 全部  1 新购  2 续签 3 升级 4试用
 
 		Page int `json:"page"` //页
 		Size int `json:"size"` //数
@@ -201,7 +201,7 @@ type (
 		BuySubject string `json:"buySubject"` // 购买主体,  1 个人, 2公司
 		EntName    string `json:"entName"`    // 购买企业
 
-		ServiceType int `json:"serviceType"` //付费类型 购买 续费 升级 试用
+		ServiceType int `json:"service_type"` //付费类型 购买 续费 升级 试用
 
 	}
 
@@ -237,7 +237,7 @@ type (
 		ProductType        string   `json:"productType,omitempty"`                  //产品类型
 		BuySubject         string   `json:"buySubject" json:"buySubject"`           //购买主体  1 个人, 2公司
 		BillingMode        string   `json:"billingMode"`                            //策略 购买 赠送
-		ServiceType        int      `json:"serviceType"`                            //付费类型 购买 续费 升级 试用
+		ServiceType        int      `json:"service_type"`                           //付费类型 购买 续费 升级 试用
 		ZeroOrderType      string   `json:"zeroOrderType"`                          //0原订单类型
 		LinkedOrderId      string   `json:"linkedOrderId,omitempty"`                //关联订单明细id
 		ComboId            int      `json:"comboId" json:"comboId,omitempty"`       //套餐id
@@ -270,7 +270,7 @@ type (
 	//	OrderCode          string `json:"orderCode"`
 	//	ProductType        string `json:"productType,omitempty"`                        //产品类型
 	//	BillingMode        int    `json:"billingMode"`                                  //策略 购买 赠送
-	//	ServiceType      int    `json:"serviceType" json:"ServiceType,omitempty"` //付费类型 购买 续费 升级 试用
+	//	ServiceType      int    `json:"service_type,omitempty"` //付费类型 购买 续费 升级 试用
 	//	ZeroOrderType      string `json:"zeroOrderType"`                                //0原订单类型
 	//	LinkedOrderId      string `json:"linkedOrderId,omitempty"`                      //关联订单明细id
 	//	SPayAccountNumber  int    `json:"sPayAccountNumber"`                            //子账号付费数量

+ 1 - 0
internal/model/product.go

@@ -15,6 +15,7 @@ type (
 		Attribute   int64      `json:"attribute"`   //产品属性 1会员服务 2 资源包 3实物 4其他
 		Tactics     int        `json:"tactics"`     //策略 1仅购买 2仅赠送 3购买+赠送
 		Auto        int        `json:"auto"`        //是否支持自动开通 1是 2否
+		Rate        int        `json:"rate"`        //自动审核折扣率
 		Trial       int        `json:"trial"`       //是否支持试用 1是 2否
 		Service     int        `json:"s_service"`   //是否需要提供客户成功服务 1是 2否
 		Subject     int        `json:"subject"`     //1个人 2企业 3个人和企业都支持