wkyuer 5 месяцев назад
Родитель
Сommit
9d79fa753d

+ 3 - 0
internal/consts/consts.go

@@ -4,6 +4,9 @@ import "github.com/gogf/gf/v2/errors/gcode"
 
 const (
 	ContextKey = "ContextKey"
+
+	OrderListTableName   = "dataexport_order"  //订单表
+	OrderDetailTableName = "jy_product_detail" //订单明细表
 )
 
 var (

+ 1 - 1
internal/logic/product/jyProductInterface.go

@@ -39,7 +39,7 @@ func getOnlyProductClassCode(code string) string {
 	return code[:i]
 }
 
-func (t *jyProductFuncMapping) registerJyProductCreateFunc(code string, f func(map[string]interface{}) JyProduct) {
+func (t *jyProductFuncMapping) RegisterJyProductCreateFunc(code string, f func(map[string]interface{}) JyProduct) {
 	t.initFuncMapping[code] = f
 }
 

+ 5 - 36
internal/logic/product/subvip.go → internal/logic/product/subvip/price.go

@@ -1,47 +1,16 @@
-package product
+package subvip
 
 import (
-	"context"
 	"github.com/gogf/gf/v2/errors/gcode"
 	"github.com/gogf/gf/v2/errors/gerror"
 	"github.com/gogf/gf/v2/util/gconv"
-	"jyOrderManager/internal/model"
 	"jyOrderManager/internal/service"
 )
 
-type (
-	//剑鱼超级订阅商品
-	jySubVipProduct struct {
-		param  model.SubVipParams
-		reqMap map[string]interface{}
-	}
-
-	priceSetting struct {
-		Moth   int64 `json:"moth"`
-		Season int64 `json:"season"`
-		Year   int64 `json:"year"`
-	}
-)
-
-func init() {
-	JyProFunc.registerJyProductCreateFunc("cjdy", NewSubVipProduct)
-}
-
-func NewSubVipProduct(reqParam map[string]interface{}) JyProduct {
-	var p model.SubVipParams
-	_ = gconv.Struct(reqParam, &p)
-	return jySubVipProduct{
-		param:  p,
-		reqMap: reqParam,
-	}
-}
-
-func (p jySubVipProduct) Check() error {
-	return nil
-}
-
-func (p jySubVipProduct) SaveUpdate(ctx context.Context) error {
-	return nil
+type priceSetting struct {
+	Moth   int64 `json:"moth"`
+	Season int64 `json:"season"`
+	Year   int64 `json:"year"`
 }
 
 func (p jySubVipProduct) GetPrice() (int64, error) {

+ 88 - 0
internal/logic/product/subvip/subvip.go

@@ -0,0 +1,88 @@
+package subvip
+
+import (
+	"context"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/util/gconv"
+	"github.com/pkg/errors"
+	"jyOrderManager/internal/consts"
+	"jyOrderManager/internal/logic/product"
+	"jyOrderManager/internal/model"
+	"jyOrderManager/internal/service"
+)
+
+type (
+	//剑鱼超级订阅商品
+	jySubVipProduct struct {
+		param  model.SubVipParams
+		reqMap map[string]interface{}
+	}
+)
+
+func init() {
+	product.JyProFunc.RegisterJyProductCreateFunc("cjdy", NewSubVipProduct)
+}
+
+func NewSubVipProduct(reqParam map[string]interface{}) product.JyProduct {
+	var p model.SubVipParams
+	_ = gconv.Struct(reqParam, &p)
+	return jySubVipProduct{
+		param:  p,
+		reqMap: reqParam,
+	}
+}
+
+func (p jySubVipProduct) Check() error {
+	m, err := p.GetPrice()
+	if err != nil {
+		return errors.Wrap(err, "金额校验计算异常")
+	}
+	if p.param.Amount != m {
+		return errors.New("金额校验异常")
+	}
+	pcls, err := service.Product().GetProduct(p.param.ProductCode)
+	if err != nil {
+		return errors.Wrap(err, "未知商品类型")
+	}
+	if pcls.ProductClass.Tactics != 3 && p.param.Tactics != pcls.ProductClass.Tactics {
+		return errors.New("销售策略不支持")
+	}
+	return nil
+}
+
+func (p jySubVipProduct) SaveUpdate(ctx context.Context) error {
+	newData := g.Map{
+		"order_code":     p.param.OrderCode,
+		"product_type":   "VIP订阅",
+		"phone":          p.param.Phone,
+		"original_price": p.param.OriginalPrice,
+		"final_price":    p.param.Amount,
+		"product_id":     p.param.ProductCode,
+		"filter": gconv.String(model.VIPSubscription{
+			CycleCount: p.param.PayCycle,
+			CycleUnit:  p.param.PayCycleType,
+			GiveCycle:  p.param.GifCycle,
+			GiveType:   p.param.GifCycleType,
+		}),
+		"billing_mode":     p.param.BillingMode,
+		"linked_detail_id": p.param.LinkedOrderId,
+	}
+	if p.param.Id > 0 {
+		res, err := g.DB().Ctx(ctx).Update(ctx, consts.OrderDetailTableName, newData, " id = ? ", p.param.Id)
+		if err != nil {
+			return errors.Wrap(err, "超级订阅明细更新异常")
+		}
+		if num, err := res.RowsAffected(); num != 1 || err != nil {
+			return errors.New("超级订阅明细更新异常")
+		}
+	} else {
+		res, err := g.DB().Ctx(ctx).Insert(ctx, consts.OrderDetailTableName, newData)
+		if err != nil {
+			return errors.Wrap(err, "超级订阅插入订单明细异常")
+		}
+		if num, err := res.RowsAffected(); num != 1 || err != nil {
+			return errors.New("超级订阅插入订单明细异常")
+		}
+	}
+	return nil
+}

+ 5 - 0
internal/logic/product/subvip/user.go

@@ -0,0 +1,5 @@
+package subvip
+
+func getUserVipStatus(phone string) (int, int64, int64) {
+	return -1, -1, -1
+}

+ 12 - 2
internal/logic/productManager/order.go

@@ -1,19 +1,28 @@
 package productManager
 
 import (
+	"app.yhyue.com/moapp/jybase/common"
 	"context"
+	"fmt"
 	"github.com/gogf/gf/v2/database/gdb"
 	"github.com/gogf/gf/v2/errors/gerror"
 	"github.com/gogf/gf/v2/frame/g"
 	"jyOrderManager/internal/logic/product"
 	"jyOrderManager/internal/model"
+	"time"
 )
 
 // SaveOrder 订单保存
 func (p *sProductManager) SaveOrder(ctx context.Context, param model.OrderParams) error {
 	// todo 参数校验
-	var productArr []product.JyProduct
+	var (
+		productArr []product.JyProduct
+		orderCode  = fmt.Sprintf("%s%s", time.Now().Format("150405"), common.GetRandom(6))
+	)
 	for _, tParam := range param.ProductArr {
+		//参数注入
+		tParam["phone"] = param.PersonPhone
+		tParam["order_code"] = orderCode
 		pFunc, err := product.JyProFunc.GetProductInitFuncByCode(tParam["code"])
 		if err != nil {
 			return err
@@ -24,11 +33,12 @@ func (p *sProductManager) SaveOrder(ctx context.Context, param model.OrderParams
 		}
 		productArr = append(productArr, pObj)
 	}
+
 	//数据操作
 	return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
 		//todo 插入订单表
 		if _, err := g.DB().Ctx(ctx).Insert(ctx, "dataexport_order", g.Map{
-			"": "",
+			"order_code": orderCode,
 		}); err != nil {
 			return gerror.Wrap(err, "插入订单表异常")
 		}

+ 12 - 2
internal/logic/productManager/productManager.go

@@ -52,7 +52,7 @@ func getInitJyProduct(ctx context.Context) (*sProductManager, error) {
 		return nil, err
 	}
 
-	for _, class := range productCLass {
+	for index, class := range productCLass {
 		var topRoot *model.ProductTop
 		for _, top := range productRoot {
 			if top.Name == class.TopClass {
@@ -69,8 +69,9 @@ func getInitJyProduct(ctx context.Context) (*sProductManager, error) {
 		}
 
 		for _, productItem := range productArray {
-			productCodeMapping[productItem.Code] = productItem
 			if class.ClassId == productItem.ProductClassId {
+				productCodeMapping[productItem.Code] = productItem
+				productItem.ProductClass = productCLass[index]
 				class.ProductList = append(class.ProductList, productItem)
 			}
 		}
@@ -99,3 +100,12 @@ func (p *sProductManager) GetPriceConfig(productCode string) (*model.PriceConfig
 	}
 	return &rData, nil
 }
+
+// GetProduct 根据产品信息
+func (p *sProductManager) GetProduct(productCode string) (*model.Product, error) {
+	product, ok := p.ProductCodeMapping[productCode]
+	if !ok {
+		return nil, gerror.NewCode(gcode.CodeValidationFailed)
+	}
+	return product, nil
+}

+ 10 - 46
internal/model/orderFilterIntent.go

@@ -119,53 +119,17 @@ type SwordfishLibraryMember struct {
 	Source             string `json:"source"`             // 订单来源
 }
 
-// VIP订阅结构体
+// VIPSubscription VIP订阅结构体
 type VIPSubscription struct {
-	AddAreaCount          interface{}            `json:"addareacount"`
-	AddBuyerClassCount    int                    `json:"addbuyerclasscount"`
-	Area                  map[string]interface{} `json:"area"` //订阅区域
-	AuditType             string                 `json:"audit_Type"`
-	Audit_type            string                 `json:"audit_type"`
-	Badge                 string                 `json:"badge"`
-	Buyset                interface{}            `json:"buyset"`
-	CommissionUpdate      int                    `json:"commissionUpdate"`
-	ContractStatus        int                    `json:"contractStatus"`
-	CycleCount            int                    `json:"cyclecount"`
-	CycleUnit             int                    `json:"cycleunit"` //日期单位(订单详情展示使用)
-	DisWord               string                 `json:"disWord"`
-	DiscountId            int                    `json:"discountId"`
-	GiveCycle             int                    `json:"give_cycle"` //赠送周期
-	GiveType              int                    `json:"give_type"`  //赠送周期 类型 1天 2月
-	Industry              []interface{}          `json:"industry"`
-	IsAll                 int                    `json:"isAll"` // 是否是全部认证
-	NewBuyset             map[string]interface{} `json:"newBuyset"`
-	OrderMoneyUpdate      int                    `json:"orderMoneyUpdate"`
-	OrderType             int                    `json:"ordertype"`          //1,3,5   类型 1:订单 2:续费 3:立即升级 4:下月升级 5:即将到期(可升降级续费)6:升级订单未生效再次升级
-	OriginalAmount        int                    `json:"originalAmount"`     //原始金额
-	OriginalCommission    int                    `json:"originalCommission"` //原始佣金
-	OriginalProcedures    int                    `json:"originalProcedures"` //原始手续费
-	OriginalPrice         int                    `json:"original_price"`
-	PayMoneyUpdate        int                    `json:"payMoneyUpdate"`
-	PaybackExpectDate     string                 `json:"paybackExpectDate"`
-	PaybackList           string                 `json:"paybackList"`
-	PaybackNum            string                 `json:"paybackNum"`
-	PaybackOpenServer     bool                   `json:"paybackOpenServer"`
-	PaybackWorkDayNum     int                    `json:"paybackWorkDayNum"`
-	ProceduresMoneyUpdate int                    `json:"proceduresMoneyUpdate"`
-	RecordPayType         string                 `json:"recordPayType"`
-	Remark                string                 `json:"remark"`
-	SellerGiveCycle       int                    `json:"seller_give_cycle"`
-	SellerGiveType        int                    `json:"seller_give_type"`
-	Source                string                 `json:"source"`
-	SubPayMoney           int                    `json:"subPayMoney"`
-	SubPayMoneyUpdate     int                    `json:"subPayMoneyUpdate"`
-	SubscriptionAreaCount int                    `json:"subscription_area_count"`
-	SupplyPayMoney        int                    `json:"supplyPayMoney"`
-	SupplyPayMoneyUpdate  int                    `json:"supplyPayMoneyUpdate"`
-	TransferV             string                 `json:"transferV"`
-	TransferVTime         string                 `json:"transferVTime"`
-	UpgradeSubtotail      interface{}            `json:"upgradeSubtotail"`
-	ZeroOrderType         string                 `json:"zeroOrderType"`
+	AddAreaCount       int         `json:"addareacount"`
+	AddBuyerClassCount int         `json:"addbuyerclasscount"`
+	CycleCount         int         `json:"cyclecount"`
+	CycleUnit          int         `json:"cycleunit"`  //日期单位(订单详情展示使用)
+	GiveCycle          int         `json:"give_cycle"` //赠送周期
+	GiveType           int         `json:"give_type"`  //赠送周期 类型 1天 2月
+	SellerGiveCycle    int         `json:"seller_give_cycle"`
+	SellerGiveType     int         `json:"seller_give_type"`
+	UpgradeSubtotail   interface{} `json:"upgradeSubtotail"`
 }
 
 // 剑鱼币结构体

+ 14 - 10
internal/model/orderParams.go

@@ -2,20 +2,24 @@ package model
 
 type (
 	ProductCommonParam struct {
-		Id          int    `json:"id"`           //订单详情表id
-		ProductCode string `json:"product_code"` //产品code
-		Phone       string `json:"phone"`        //开通手机号
-		Amount      int64  `json:"amount"`       //合同金额
-		Tactics     int    //策略 1仅购买 2仅赠送 3购买+赠送
+		Id            int    `json:"id"`                   //订单详情表id
+		ProductCode   string `json:"product_code"`         //产品code
+		OrderCode     string `json:"order_code,omitempty"` //订单编号
+		Phone         string `json:"phone,omitempty"`      //开通手机号
+		Amount        int64  `json:"amount"`               //实际价格
+		OriginalPrice int64  `json:"original_price"`       //原价
+
+		Tactics int `json:"tactics"` //策略 1仅购买 2仅赠送 3购买+赠送
 	}
 
 	OrderParams struct {
 		OrderStatus    int    `form:"order_status" json:"orderStatus,omitempty"`      // 订单状态  0 未完成 1 已完成
 		BuySubject     string `form:"buySubject" json:"buySubject"`                   // 购买主体  1 个人, 2公司
-		PaybackCompany string `form:"paybackCompany" json:"paybackCompany,omitempty"` //签约主体  回款公司
-		ContactsName   string `json:"personName,omitempty"`                           //联系人
-		ContactsPhone  string `json:"personPhone"`                                    //联系人手机号
-		PersonPhone    string `json:"userPhone"`                                      //开通服务手机号
+		PaybackCompany string `form:"paybackCompany" json:"paybackCompany,omitempty"` // 签约主体  回款公司
+		ContactsName   string `json:"personName,omitempty"`                           // 联系人
+		ContactsPhone  string `json:"personPhone"`                                    // 联系人手机号
+		PersonPhone    string `json:"userPhone"`                                      // 开通服务手机号
+		OrderCode      string `json:"orderCode,omitempty"`                            // 订单号
 
 		ProductArr        []map[string]interface{} `json:"productArr"`                                           //产品
 		ContractMoney     int                      `json:"contractMoney"`                                        //合同金额
@@ -83,7 +87,7 @@ type (
 		*ProductCommonParam
 		ProductType        string `json:"productType,omitempty"`                        //产品类型
 		BillingMode        int    `json:"billingMode"`                                  //策略 购买 赠送
-		RecordPayType      int    `form:"recordPayType" json:"recordPayType,omitempty"` //付费类型 购买 续费 升级 试用
+		RecordPayType      int    `form:"recordPayType" json:"recordPayType,omitempty"` //付费类型 1购买 2续费 3升级 0试用
 		LinkedOrderId      string `json:"linkedOrderId,omitempty"`                      //关联订单明细id
 		SPayAccountNumber  int    `json:"sPayAccountNumber"`                            //子账号付费数量
 		SGiftAccountNumber int    `json:"sGiftAccountNumber"`                           //子账号赠送数量

+ 2 - 1
internal/model/product.go

@@ -18,13 +18,14 @@ type (
 	}
 	Product struct {
 		Id             int64                  `json:"id"`
-		ProductClassId int64                  `json:"product_class_id"`
+		ProductClassId int64                  `json:"product_class_id,omitempty"`
 		Code           string                 `json:"code"`
 		Name           string                 `json:"name"`      //产品名称
 		UnitName       string                 `json:"unit_name"` //单位名称、数量名称
 		UnitNum        int                    `json:"unit_num"`  //数量
 		Cycle          string                 `json:"cycle"`     //有效周期
 		Price          map[string]interface{} `json:"price"`     //计价规则
+		ProductClass   *ProductClass          `json:"product_class,omitempty"`
 	}
 	PriceConfig struct {
 		Mode int    `json:"mode"`

+ 3 - 1
internal/service/producttManager.go

@@ -10,8 +10,10 @@ type (
 	IProducttManager interface {
 		// CheckParam 校验参数
 		GetList() []*model.ProductTop
-		// GetPrice 获取用户身份
+		// GetPriceConfig 获取价格计算
 		GetPriceConfig(productCode string) (*model.PriceConfig, error)
+		// GetProductTopClass 获取商品分离
+		GetProduct(productCode string) (*model.Product, error)
 	}
 )
 

+ 0 - 25
main.go

@@ -1,38 +1,13 @@
 package main
 
 import (
-	"fmt"
 	_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
 	_ "github.com/gogf/gf/contrib/nosql/redis/v2"
 	"github.com/gogf/gf/v2/os/gctx"
 	"jyOrderManager/internal/cmd"
 	_ "jyOrderManager/internal/logic"
-	"unicode"
 )
 
 func main() {
-
-	for _, s := range []string{"dyh001", "cjdy9881", "sw2281"} {
-		fmt.Println(getOnlyProductClassCode(s))
-	}
-
 	cmd.Main.Run(gctx.GetInitCtx())
 }
-
-// getOnlyProductClassCode 获取
-func getOnlyProductClassCode(code string) string {
-	if len(code) == 0 {
-		return ""
-	}
-	// 先检查是否是字母开头
-	if !unicode.IsLetter(rune(code[0])) {
-		return ""
-	}
-	i := 0
-	for ; i < len(code); i++ {
-		if unicode.IsDigit(rune(code[i])) {
-			break
-		}
-	}
-	return code[:i]
-}