|
@@ -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("更新订单出错")
|
|
|
}
|
|
|
|