|
@@ -0,0 +1,96 @@
|
|
|
+package subvip
|
|
|
+
|
|
|
+import (
|
|
|
+ "app.yhyue.com/moapp/jybase/date"
|
|
|
+ "context"
|
|
|
+ "fmt"
|
|
|
+ "github.com/gogf/gf/v2/frame/g"
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
|
+ "github.com/pkg/errors"
|
|
|
+ "jyOrderManager/internal/consts"
|
|
|
+ "jyOrderManager/utility"
|
|
|
+ "regexp"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+// OpenService 超级订阅开通服务
|
|
|
+func (p jySubVipProduct) OpenService(ctx context.Context) error {
|
|
|
+ record, err := g.DB().GetOne(ctx, fmt.Sprintf("SELECT * FROM %s WHERE order_code =?", consts.OrderListTableName), p.param.OrderCode)
|
|
|
+ if err != nil || record.IsEmpty() {
|
|
|
+ return errors.Wrap(err, "未知订单编号")
|
|
|
+ }
|
|
|
+ var (
|
|
|
+ userId, userData = FindUserDataByPhone(p.param.Phone)
|
|
|
+ orderId = gconv.Int(record["id"])
|
|
|
+ mgoUserId, userPositionId string
|
|
|
+ buySubject = gconv.Int64(record["buy_subject"])
|
|
|
+ companyName = gconv.String(record["company_name"])
|
|
|
+ entId = gconv.Int(record["ent_id"])
|
|
|
+ )
|
|
|
+
|
|
|
+ if p.param.RecordPayType == 1 || p.param.RecordPayType == 4 { //新购
|
|
|
+ var (
|
|
|
+ entService int
|
|
|
+ userCount int
|
|
|
+ )
|
|
|
+ mgoUserId = userId
|
|
|
+ vipStartTime, vipEndTime := utility.GetStartAndEndTime(time.Now(), utility.DateComp{
|
|
|
+ Num: p.param.PayCycle,
|
|
|
+ Unit: p.param.PayCycleType,
|
|
|
+ }, utility.DateComp{
|
|
|
+ Num: p.param.GifCycle,
|
|
|
+ Unit: p.param.GifCycleType,
|
|
|
+ })
|
|
|
+ if buySubject == 2 { //购买主体是企业,手机号改变,需要重新创建企业
|
|
|
+ entId, err, userPositionId = utility.AutomaticallyCreatingEnt(companyName, p.param.Phone, p.param.OrderCode, userId)
|
|
|
+ if err != nil {
|
|
|
+ return errors.Wrap(err, fmt.Sprintf("AutomaticallyCreatingEn 自动创建企业信息失败: %s", companyName))
|
|
|
+ }
|
|
|
+ var (
|
|
|
+ userId = userPositionId
|
|
|
+ entService, userCount = utility.EntServiceOpen(entId, p.param.Phone)
|
|
|
+ buyCount = p.param.SGiftAccountNumber + p.param.SPayAccountNumber
|
|
|
+ )
|
|
|
+
|
|
|
+ if entId != 0 && buyCount > 1 {
|
|
|
+ regRuler := "^1[3456789]{1}\\d{9}$"
|
|
|
+ reg := regexp.MustCompile(regRuler)
|
|
|
+ if reg.MatchString(p.param.Phone) && companyName != "" {
|
|
|
+ err, _ := utility.EntLicense(entId, buyCount, -1, orderId, userCount, "VIP订阅", vipStartTime.Format(date.Date_Full_Layout), vipEndTime.Format(date.Date_Full_Layout), p.param.Phone)
|
|
|
+ if err != nil {
|
|
|
+ return errors.Wrap(err, fmt.Sprintf("EntLicense 创建企业授权信息失败:%s", companyName))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if entService != 1 {
|
|
|
+ ClearBigVipUserPower(userId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if p.param.RecordPayType == 2 { //续费
|
|
|
+
|
|
|
+ } else if p.param.RecordPayType == 3 { //升级
|
|
|
+
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func GetStartAndEndTime(startTime string, cycleCount, cycleUnit int) (vipStartTime, endTime time.Time) {
|
|
|
+ //根据开始时间计算结束时间
|
|
|
+ month := 0
|
|
|
+ if cycleUnit == 1 {
|
|
|
+ month = cycleCount * 12
|
|
|
+ } else if cycleUnit == 2 {
|
|
|
+ month = cycleCount
|
|
|
+ } else if cycleUnit == 4 {
|
|
|
+ month = cycleCount * 3
|
|
|
+ }
|
|
|
+ vipStartTime, _ = time.ParseInLocation(date.Date_Short_Layout, startTime, time.Local)
|
|
|
+ if cycleUnit == 3 {
|
|
|
+ _endTime := vipStartTime.AddDate(0, 0, cycleCount)
|
|
|
+ t := _endTime.Format(date.Date_Short_Layout) + " 23:59:59"
|
|
|
+ endTime, _ = time.ParseInLocation(date.Date_Full_Layout, t, time.Local)
|
|
|
+ } else {
|
|
|
+ endTime = GetDATE1(month, vipStartTime.Unix())
|
|
|
+ }
|
|
|
+ return vipStartTime, endTime
|
|
|
+}
|