Bläddra i källkod

标准售价计算

renjiaojiao 1 år sedan
förälder
incheckning
862a41958b

+ 14 - 1
src/order/orderSellingPrice.go

@@ -31,6 +31,7 @@ type OrderPriceParams struct {
 	VipType           int    `form:"vipType"`           //VIP类型 0 购买  1:续费 2:升级
 	Products          int    `form:"products"`          // 1 大会员  2  创建子账号订单  3创建补充包订单
 	OriginalAreaCount int    `form:"originalAreaCount"` //超级订阅原来区域数量
+	OrderCode         string `form:"orderCode"`         //关联订单编号
 }
 
 func orderPriceCount(context *admin.Context) (interface{}, error) {
@@ -63,9 +64,12 @@ func orderPriceCount(context *admin.Context) (interface{}, error) {
 	case 4:
 		monthCount = param.CycleCount * 3
 	}
-	if param.Products == 2 || param.Products == 3 || param.CreateType == 2 {
+	if param.Products == 3 || param.CreateType == 2 {
 		monthCount, userId = GetUserBigTime(param.Phone, false)
 	}
+	if param.Products == 2 {
+		monthCount = GetEntBigMemberMonthCount(param.OrderCode)
+	}
 	if param.VipType == 2 {
 		monthCount, userId = GetUserBigTime(param.Phone, true)
 		//fmt.Println("*******", monthCount)
@@ -237,6 +241,15 @@ func orderPriceCount(context *admin.Context) (interface{}, error) {
 	}, err
 }
 
+func GetEntBigMemberMonthCount(orderCode string) (monthCount int) {
+	var endTime time.Time
+	res := util.JysqlDB.SelectBySql("SELECT c.end_time FROM dataexport_order a LEFT JOIN entniche_order b on a.id = b.order_id LEFT JOIN entniche_wait_empower c ON b.wait_empower_id = c.id WHERE a.order_code = '?'", orderCode)
+	if res != nil && len(*res) > 0 {
+		endTime, _ = time.Parse(qutil.Date_Full_Layout, qutil.ObjToString((*res)[0]["end_time"]))
+	}
+	return GetMonthNum(time.Now(), endTime)
+}
+
 func GetUserBigTime(phone string, isVip bool) (monthCount int, userId string) {
 	//查询用户大会员权益剩余服务周期
 	userData, ok := util.MQFW.FindOneByField("user", map[string]interface{}{"s_phone": phone}, `"_id":1,"i_member_starttime":1,"i_member_endtime":1,"l_vip_starttime":1,"l_vip_endtime":1`)

+ 8 - 1
src/order/otherOrderService.go

@@ -1686,7 +1686,7 @@ func UpdateBatchReturnInfo(transactionData *map[string]interface{}, orderArr map
 			if ok_1 && ok_2 != -1 {
 				//修改成功,判断是否全额回款并且创建订单勾选回款开通权益 paybackOpenServer
 				if qutil.IntAll(updateData["return_status"]) == 1 && qutil.IntAll((*filterMap)["isServiceOpen"]) == 0 {
-					err := OpenUserService(key, value)
+					err := OpenUserService(tx, key, value)
 					if err != nil {
 						return false
 					}
@@ -1763,6 +1763,13 @@ func ManualUpdateBatchReturnInfo(orderArr map[string]map[string]interface{}, ope
 			ok1 := util.JysqlDB.UpdateByTx(tx, "dataexport_order", map[string]interface{}{"id": value["id"]}, updateData)
 			ok2 := util.JysqlDB.InsertByTx(tx, "return_money_record", insertData)
 			if ok1 && ok2 != -1 {
+				//修改成功,判断是否全额回款并且创建订单勾选回款开通权益 paybackOpenServer
+				if qutil.IntAll(updateData["return_status"]) == 1 && qutil.IntAll((*filterMap)["isServiceOpen"]) == 0 {
+					err := OpenUserService(tx, key, value)
+					if err != nil {
+						return false
+					}
+				}
 				return_id = return_id + fmt.Sprint(ok2) + ","
 			} else {
 				return false

+ 52 - 7
src/order/serviceOpen.go

@@ -1,6 +1,7 @@
 package order
 
 import (
+	"database/sql"
 	"encoding/json"
 	"errors"
 	"fmt"
@@ -105,10 +106,11 @@ func ServiceOpen(context *admin.Context) (interface{}, error) {
 		return nil, err
 	}
 	filterMap["isServiceOpen"] = 1 //是否已开通权益 1开通
+	filter, _ := json.Marshal(filterMap)
 	updateMap := map[string]interface{}{
 		"user_phone": param.Phone,
 		"user_id":    userId,
-		"filter":     fmt.Sprintf("%v", filterMap),
+		"filter":     string(filter),
 	}
 	if productType == "VIP订阅" {
 		if cm.IntAll(userData["i_vip_status"]) > 0 {
@@ -381,7 +383,7 @@ func GetReturnTimeAndCheckTime(orderCode string) (newReturnMoneyTime, checkPassT
 }
 
 // OpenUserService 全额回款后开通权益
-func OpenUserService(orderCode string, orderInfo map[string]interface{}) error {
+func OpenUserService(tx *sql.Tx, orderCode string, orderInfo map[string]interface{}) error {
 	var err error
 	productType := cm.ObjToString(orderInfo["product_type"])
 	filterMap := map[string]interface{}{}
@@ -482,6 +484,26 @@ func OpenUserService(orderCode string, orderInfo map[string]interface{}) error {
 			bigStartTime := time.Now()
 			bigEndTime := GetDATE(cm.IntAll(filterMap["cycle"]), cm.IntAll(filterMap["cycleType"]), bigStartTime.Unix())
 			status := cm.If(bigStartTime.Unix() > time.Now().Unix(), 0, 1)
+			if cm.IntAll(orderInfo["buy_subject"]) == 2 {
+				var sName string
+				if cm.IntAll(filterMap["comboId"]) != 0 {
+					if cm.IntAll(filterMap["comboId"]) == 5 {
+						sName = ComboCustom
+					} else {
+						combo := util.JysqlDB.FindOne("bigmember_combo", map[string]interface{}{"id": cm.IntAll(filterMap["comboId"])}, "", "")
+						if combo != nil && len(*combo) > 0 {
+							sName = cm.ObjToString((*combo)["s_name"])
+						}
+					}
+				}
+				st := cm.FormatDate(&bigStartTime, cm.Date_Full_Layout)
+				et := cm.FormatDate(&bigEndTime, cm.Date_Full_Layout)
+				err := EntLicense(cm.IntAll(orderInfo["entId"]), cm.IntAll(orderInfo["buy_count"]), cm.IntAll(cm.If(cm.IntAll(filterMap["areaCount"]) > 0, cm.IntAll(filterMap["areaCount"]), -1)), cm.IntAll(orderInfo["id"]), 0, fmt.Sprintf("%s%s", "大会员", sName), st, et, cm.ObjToString(orderInfo["user_phone"]))
+				if err != nil {
+					log.Printf("EntLicense 创建企业授权信息失败:code:%s,err:%s", orderCode, err.Error())
+					return err
+				}
+			}
 			err := NewBigOpenService(filterMap, userId, bigStartTime, bigEndTime, cm.IntAll(status), cm.IntAll(orderInfo["buy_count"]))
 			if err != nil {
 				return errors.New(fmt.Sprintf("订单编号:%s,开通大会员权益失败", orderCode))
@@ -549,7 +571,7 @@ func OpenUserService(orderCode string, orderInfo map[string]interface{}) error {
 		bigEnd := cm.Int64All(userData["i_member_endtime"])
 		areaCount := cm.IntAll(filterMap["areaCount"])
 		ok, err := SubAccount(SubAccountParam{
-			BuyCount:         cm.IntAll(orderInfo["buy_count"]),
+			BuyCount:         cm.IntAll(orderInfo["buy_count"]) + freeSubNum + paySubNum,
 			BuySubject:       cm.IntAll(orderInfo["buy_subject"]),
 			StartTime:        time.Unix(bigStart, 0),
 			EndTime:          time.Unix(bigEnd, 0),
@@ -564,8 +586,29 @@ func OpenUserService(orderCode string, orderInfo map[string]interface{}) error {
 		if !ok && err != nil {
 			return err
 		}
+		if cm.IntAll(orderInfo["buy_subject"]) == 2 {
+			var sName string
+			if cm.IntAll(filterMap["comboId"]) != 0 {
+				if cm.IntAll(filterMap["comboId"]) == 5 {
+					sName = ComboCustom
+				} else {
+					combo := util.JysqlDB.FindOne("bigmember_combo", map[string]interface{}{"id": cm.IntAll(filterMap["comboId"])}, "", "")
+					if combo != nil && len(*combo) > 0 {
+						sName = cm.ObjToString((*combo)["s_name"])
+					}
+				}
+			}
+
+			st := time.Unix(bigStart, 0).Format(cm.Date_Full_Layout)
+			et := time.Unix(bigEnd, 0).Format(cm.Date_Full_Layout)
+			err := EntLicense(cm.IntAll(orderInfo["entId"]), cm.IntAll(orderInfo["buy_count"]), cm.IntAll(cm.If(cm.IntAll(filterMap["areaCount"]) > 0, cm.IntAll(filterMap["areaCount"]), -1)), cm.IntAll(orderInfo["id"]), 0, fmt.Sprintf("%s%s", "大会员", sName), st, et, cm.ObjToString(orderInfo["user_phone"]))
+			if err != nil {
+				log.Printf("EntLicense 创建企业授权信息失败:code:%s,err:%s", orderCode, err.Error())
+				return err
+			}
+		}
 		updateOrder["vip_starttime"] = time.Now().Format(cm.Date_Full_Layout)
-		updateOrder["vip_endtime"] = time.Unix(bigEnd, 0)
+		updateOrder["vip_endtime"] = time.Unix(bigEnd, 0).Format(cm.Date_Full_Layout)
 
 	} else if productType == "大会员-补充包" {
 		bigEnd := cm.Int64All(userData["i_member_endtime"])
@@ -583,12 +626,14 @@ func OpenUserService(orderCode string, orderInfo map[string]interface{}) error {
 			return err
 		}
 		updateOrder["vip_starttime"] = time.Now().Format(cm.Date_Full_Layout)
-		updateOrder["vip_endtime"] = time.Unix(bigEnd, 0)
+		updateOrder["vip_endtime"] = time.Unix(bigEnd, 0).Format(cm.Date_Full_Layout)
 	}
 	filterMap["isServiceOpen"] = 1
-	updateOrder["filter"] = fmt.Sprintf("%v", filterMap)
+	filter, _ := json.Marshal(filterMap)
+	updateOrder["filter"] = string(filter)
+
 	//更新订单
-	if !util.JysqlDB.Update("dataexport_order", map[string]interface{}{"order_code": orderCode}, updateOrder) {
+	if !util.JysqlDB.UpdateByTx(tx, "dataexport_order", map[string]interface{}{"order_code": orderCode}, updateOrder) {
 		return errors.New("更新订单出错")
 	}
 

+ 1 - 1
src/task/returnMoneyTask.go

@@ -84,7 +84,7 @@ func StartTask1() {
 								util.CbsDB.Update("transaction", map[string]interface{}{"id": id}, map[string]interface{}{"ISRELATION": 1, "return_id": fmt.Sprint(returnId)})
 								filterMap := qu.ObjToMap(o["filter"])
 								if qu.IntAll(o["return_status"]) == 1 && qu.IntAll((*filterMap)["isServiceOpen"]) == 0 {
-									err := order.OpenUserService(orderCode, o)
+									err := order.OpenUserService(nil, orderCode, o)
 									if err != nil {
 										log.Println("自动回款开通权益失败", id, orderCode)
 									}