|
@@ -1,18 +1,85 @@
|
|
|
package product
|
|
|
|
|
|
+import (
|
|
|
+ "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 {
|
|
|
}
|
|
|
+
|
|
|
+ priceSetting struct {
|
|
|
+ Moth int64 `json:"moth"`
|
|
|
+ Season int64 `json:"season"`
|
|
|
+ Year int64 `json:"year"`
|
|
|
+ }
|
|
|
)
|
|
|
|
|
|
-func (p *jySubVipProduct) Check(param interface{}) error {
|
|
|
+func (p *jySubVipProduct) CheckParam(param model.SubVipParams) error {
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (p *jySubVipProduct) GetPrice(param interface{}) (int64, error) {
|
|
|
+func (p *jySubVipProduct) GetPrice(param model.SubVipParams) (int64, error) {
|
|
|
+ var (
|
|
|
+ fPrice int64
|
|
|
+ totalNum = param.SPayAccountNumber + param.SGiftAccountNumber
|
|
|
+ )
|
|
|
+ sVal, err := service.Product().GetPriceConfig(param.ProductCode)
|
|
|
+ if err != nil {
|
|
|
+ return 0, err
|
|
|
+ }
|
|
|
+ var thisPriceSetting priceSetting
|
|
|
+ if err := gconv.Struct(sVal.Rule, &thisPriceSetting); err != nil {
|
|
|
+ return 0, gerror.NewCode(gcode.CodeValidationFailed, "价格格式配置异常")
|
|
|
+ }
|
|
|
+
|
|
|
+ if param.PayCycleType == param.GifCycleType { //购买周期和送的周期一样
|
|
|
+ p, err := thisPriceSetting.GetPrice(param.GifCycle+param.PayCycle, param.GifCycleType)
|
|
|
+ if err != nil {
|
|
|
+ return 0, err
|
|
|
+ }
|
|
|
+ fPrice = p * gconv.Int64(totalNum)
|
|
|
+ } else {
|
|
|
+ var (
|
|
|
+ p1, p2 int64
|
|
|
+ err error
|
|
|
+ )
|
|
|
+ p1, err = thisPriceSetting.GetPrice(param.PayCycleType, param.PayCycleType)
|
|
|
+ if err != nil {
|
|
|
+ return p1, err
|
|
|
+ }
|
|
|
+ p2, err = thisPriceSetting.GetPrice(param.GifCycle, param.GifCycleType)
|
|
|
+ if err != nil {
|
|
|
+ return p2, err
|
|
|
+ }
|
|
|
+ fPrice = (p1 + p2) * gconv.Int64(totalNum)
|
|
|
+ }
|
|
|
+ return fPrice, nil
|
|
|
+}
|
|
|
|
|
|
- return -1, nil
|
|
|
+func (ps *priceSetting) GetPrice(num, cycleType int) (int64, error) {
|
|
|
+ switch cycleType { // 1-天 2-月 3-季 4-年
|
|
|
+ case 1:
|
|
|
+ return ps.Moth / 30 * gconv.Int64(num), nil
|
|
|
+ case 2:
|
|
|
+ if num >= 12 && ps.Year > 0 {
|
|
|
+ return ps.Year / 12 * gconv.Int64(num), nil
|
|
|
+ }
|
|
|
+ if num >= 3 && ps.Season > 0 {
|
|
|
+ return ps.Season / 3 * gconv.Int64(num), nil
|
|
|
+ }
|
|
|
+ return ps.Moth * gconv.Int64(num), nil
|
|
|
+ case 3:
|
|
|
+ return ps.Season * gconv.Int64(num), nil
|
|
|
+ case 4:
|
|
|
+ return ps.Year * gconv.Int64(num), nil
|
|
|
+ }
|
|
|
+ return -1, gerror.NewCode(gcode.CodeInvalidParameter, "位置时间参数")
|
|
|
}
|
|
|
|
|
|
func (p *jySubVipProduct) OpenService(param interface{}) {
|