123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- package product
- import (
- "context"
- "fmt"
- "github.com/gogf/gf/v2/database/gdb"
- "github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/util/gconv"
- "github.com/pkg/errors"
- "jyOrderManager/internal/jyutil"
- "jyOrderManager/internal/model"
- "math"
- "time"
- )
- // GetLinkVipCycleFilter 获取关联订单
- func GetLinkVipCycleFilter(ctx context.Context, linkOrderDetailId int64) (filter *model.VipCycleFilter, st, et time.Time, err error) {
- var (
- re gdb.Record
- )
- re, err = g.DB().GetOne(ctx, "SELECT filter,service_starttime,service_endtime FROM jy_order_detail WHERE id =? and status =1", linkOrderDetailId)
- if err != nil {
- return
- }
- var (
- dMap = re.Map()
- )
- if len(dMap) == 0 {
- err = fmt.Errorf("获取关联订单异常")
- return
- }
- var ttt model.VipCycleFilter
- if err = gconv.Struct(dMap["filter"], &ttt); err != nil {
- return
- }
- filter = &ttt
- st, err = time.Parse("2006-01-02 15:04:05", gconv.String(dMap["service_starttime"]))
- if err != nil {
- return
- }
- et, err = time.Parse("2006-01-02 15:04:05", gconv.String(dMap["service_endtime"]))
- if err != nil {
- return
- }
- return
- }
- // GetLinkBigCycleFilter 获取关联订单
- func GetLinkBigCycleFilter(ctx context.Context, linkOrderDetailId string) (filter *model.JyBigProductFilter, st, et time.Time, err error) {
- var (
- re gdb.Record
- )
- re, err = g.DB().GetOne(ctx, fmt.Sprintf(`SELECT filter,service_starttime,service_endtime FROM jy_order_detail WHERE id =%s and status =1`, linkOrderDetailId))
- if err != nil {
- return
- }
- var (
- dMap = re.Map()
- )
- if len(dMap) == 0 {
- err = fmt.Errorf("获取关联订单异常")
- return
- }
- var ttt model.JyBigProductFilter
- err = gconv.Struct(dMap["filter"], &ttt)
- if err != nil {
- return
- }
- filter = &ttt
- st, err = time.Parse("2006-01-02 15:04:05", gconv.String(dMap["service_starttime"]))
- if err != nil {
- return
- }
- et, err = time.Parse("2006-01-02 15:04:05", gconv.String(dMap["service_endtime"]))
- if err != nil {
- return
- }
- return
- }
- // GetLinkBigUserNumber 通过关联订单获取升级前的子账号数量
- func GetLinkBigUserNumber(ctx context.Context, linkOrderDetailId, reqSubject int64, Phone string) (count int, err error) {
- var (
- re gdb.Record
- )
- switch reqSubject {
- case 2:
- re, err = g.DB().GetOne(ctx, fmt.Sprintf(`SELECT a.empower_count FROM entniche_wait_empower a
- INNER JOIN entniche_order b on a.id = b.wait_empower_id
- WHERE b.order_detail_id = %d`, linkOrderDetailId))
- if err != nil {
- return 0, err
- }
- count = gconv.Int(re.Map()["empower_count"])
- default:
- user, _, _, err := jyutil.GetCreateUserData(Phone, "", false)
- if err == nil && user != nil && len(user) > 0 {
- count = gconv.Int((user)["i_pay_sub_num"]) + 1
- } else {
- return 0, errors.New("用户信息获取错误")
- }
- }
- return
- }
- type NewPriceSetting struct {
- PrPi []ProductPricing `json:"prPi"`
- }
- type ProductPricing struct {
- Max int `json:"max"`
- Min int `json:"min"`
- TimeType int `json:"timeType"` // 类型 1天 2月 3年 4季度
- Unit int `json:"unit"` //折合单价数
- Price int64 `json:"price"` //单价费用
- Account int64 `json:"account"` //个人子账号费用
- EntAccount int64 `json:"entAccount"` //企业账号费用
- }
- // UnityPrice 计费
- func (ps NewPriceSetting) UnityPrice(num, cycleType, subAccount, price int, isEnt bool, sType ...string) int64 {
- switch cycleType { // 类型 1天 2月 3年 4季度
- case 1:
- //查找在哪个分类中
- for _, pricing := range ps.PrPi {
- var subPrice float64
- if isEnt {
- subPrice = gconv.Float64(pricing.EntAccount)
- } else {
- subPrice = gconv.Float64(pricing.Account)
- }
- var newPrice float64
- if price != 0 {
- newPrice = gconv.Float64(price)
- } else {
- newPrice = gconv.Float64(pricing.Price)
- }
- switch pricing.TimeType { // 类型 1月 2年 3季度
- case 1: //
- if float64(num)/30 >= gconv.Float64(pricing.Min) && float64(num)/30 < float64(pricing.Max) {
- return gconv.Int64(math.Floor((newPrice + subPrice*gconv.Float64(subAccount)) / (float64(pricing.Unit) / (float64(num) / 30))))
- }
- case 2:
- if float64(num)/360 >= gconv.Float64(pricing.Min) && float64(num)/360 < float64(pricing.Max) {
- return gconv.Int64(math.Floor((newPrice + subPrice*gconv.Float64(subAccount)) / (float64(pricing.Unit) / (float64(num) / 30))))
- }
- case 3:
- if float64(num)/90 >= gconv.Float64(pricing.Min) && float64(num)/90 < float64(pricing.Max) {
- return gconv.Int64(math.Floor((newPrice + subPrice*gconv.Float64(subAccount)) / (float64(pricing.Unit) / (float64(num) / 30))))
- }
- }
- }
- case 2:
- //查找在哪个分类中
- for _, pricing := range ps.PrPi {
- var subPrice float64
- if isEnt {
- subPrice = gconv.Float64(pricing.EntAccount)
- } else {
- subPrice = gconv.Float64(pricing.Account)
- }
- var newPrice float64
- if len(sType) == 0 { //升级服务 只升级账号费用
- if price != 0 {
- newPrice = gconv.Float64(price)
- } else {
- newPrice = gconv.Float64(pricing.Price)
- }
- }
- switch pricing.TimeType { // 类型 1月 2年
- case 1: //
- if num >= pricing.Min && num < pricing.Max {
- return gconv.Int64(math.Floor((newPrice + subPrice*gconv.Float64(subAccount)) / (float64(pricing.Unit) / float64(num))))
- }
- case 2:
- if float64(num/12) >= gconv.Float64(pricing.Min) && float64(num/12) < float64(pricing.Max) {
- return gconv.Int64(math.Floor((newPrice + subPrice*gconv.Float64(subAccount)) / (float64(pricing.Unit) / float64(num))))
- }
- case 3:
- if float64(num)/3 >= gconv.Float64(pricing.Min) && float64(num)/3 < float64(pricing.Max) {
- return gconv.Int64(math.Floor((newPrice + subPrice*gconv.Float64(subAccount)) / (float64(pricing.Unit) / float64(num))))
- }
- }
- }
- case 3:
- //查找在哪个分类中
- for _, pricing := range ps.PrPi {
- var subPrice float64
- if isEnt {
- subPrice = gconv.Float64(pricing.EntAccount)
- } else {
- subPrice = gconv.Float64(pricing.Account)
- }
- var newPrice float64
- if price != 0 {
- newPrice = gconv.Float64(price)
- } else {
- newPrice = gconv.Float64(pricing.Price)
- }
- switch pricing.TimeType { // 类型 1月 2年
- case 1: //
- if num*12 >= pricing.Min && num*12 < pricing.Max {
- return gconv.Int64(math.Floor((newPrice + subPrice*gconv.Float64(subAccount)) / (float64(pricing.Unit) / float64(num*12))))
- }
- case 2:
- if float64(num) >= gconv.Float64(pricing.Min) && float64(num) < float64(pricing.Max) {
- return gconv.Int64(math.Floor((newPrice + subPrice*gconv.Float64(subAccount)) / (float64(pricing.Unit) / float64(num*12))))
- }
- }
- }
- case 4:
- //查找在哪个分类中
- for _, pricing := range ps.PrPi {
- var subPrice float64
- if isEnt {
- subPrice = gconv.Float64(pricing.EntAccount)
- } else {
- subPrice = gconv.Float64(pricing.Account)
- }
- var newPrice float64
- if price != 0 {
- newPrice = gconv.Float64(price)
- } else {
- newPrice = gconv.Float64(pricing.Price)
- }
- switch pricing.TimeType { // 类型 1月 2年
- case 1:
- if num*3 >= pricing.Min && num*3 < pricing.Max {
- return gconv.Int64(math.Floor((newPrice + subPrice*gconv.Float64(subAccount)) / (float64(pricing.Unit) / float64(num*3))))
- }
- case 2: //
- if gconv.Float64(num) >= gconv.Float64(pricing.Min) && gconv.Float64(num) < gconv.Float64(pricing.Max) {
- return gconv.Int64(math.Floor((newPrice + subPrice*gconv.Float64(subAccount)) / (float64(pricing.Unit) / float64(num*3))))
- }
- case 3:
- if float64(num) >= gconv.Float64(pricing.Min) && float64(num) < float64(pricing.Max) {
- return gconv.Int64(math.Floor((newPrice + subPrice*gconv.Float64(subAccount)) / (float64(pricing.Unit) / float64(num*3))))
- }
- }
- }
- }
- return 0
- }
|