Browse Source

Merge branch 'dev/v2.4.31_rjj' of jianyu/qmx_admin into feature/v2.4.31

renjiaojiao 1 year ago
parent
commit
79686df3fa
3 changed files with 81 additions and 58 deletions
  1. 9 2
      src/order/optimizeOrder.go
  2. 2 21
      src/order/otherOrderController.go
  3. 70 35
      src/order/serviceOpen.go

+ 9 - 2
src/order/optimizeOrder.go

@@ -87,14 +87,21 @@ func AddUpdateRecord(context *admin.Context) (interface{}, error) {
 		updateData["procedures_money"] = param.ProceduresMoney
 		insertData["proceduresMoney"] = param.ProceduresMoney - qutil.IntAll((*orderData)["procedures_money"])
 		filterMap["proceduresMoneyUpdate"] = param.ProceduresMoney - qutil.IntAll((*orderData)["procedures_money"])
-
+		if qutil.IntAll(filterMap["paybackNum"]) == 1 {
+			if list, ok := filterMap["paybackList"].([]interface{}); ok {
+				paybackList := qutil.ObjArrToMapArr(list)
+				paybackList[0]["money"] = param.PayMoney
+				bt, _ := json.Marshal(paybackList)
+				filterMap["paybackList"] = string(bt)
+			}
+		}
 		filterByte, _ := json.Marshal(filterMap)
 		updateData["filter"] = string(filterByte)
 		returnData := util.JysqlDB.SelectBySql(`select IFNULL(sum(return_money),0) as return_money from return_money_record where order_code=? and state=1`, param.OrderCode)
 		refundData := util.JysqlDB.SelectBySql(`select IFNULL(sum(refund_money),0) as refund_money from refund_record where order_code=?`, param.OrderCode)
 		return_money := qutil.IntAll((*returnData)[0]["return_money"])
 		refund_money := qutil.IntAll((*refundData)[0]["refund_money"])
-		if param.PayMoney-param.Commission-param.ProceduresMoney == return_money-refund_money {
+		if param.PayMoney-param.Commission-param.ProceduresMoney <= return_money-refund_money {
 			updateData["return_status"] = 1
 		} else if param.PayMoney-param.Commission-param.ProceduresMoney > return_money-refund_money && return_money-refund_money > 0 {
 			updateData["return_status"] = 2

+ 2 - 21
src/order/otherOrderController.go

@@ -1256,27 +1256,7 @@ func VipInfo(context *admin.Context) (interface{}, error) {
 	}
 	if userInfo != nil && len(userInfo) > 0 {
 		userId := mongodb.BsonIdToSId(userInfo["_id"])
-		if param.BuySubject == "2" {
-			res := util.JysqlDB.FindOne("entniche_info", map[string]interface{}{
-				"phone": param.Phone,
-				"name":  param.EntName,
-			}, "id", "")
-			if res == nil {
-				return map[string]interface{}{
-					"willEffect": false,
-					"userData":   userInfo,
-					"vipExist":   false,
-				}, nil
-			}
-			entId := qutil.IntAll((*res)["id"])
-			positionData := util.BaseDB.FindOne(util.BasePosition, map[string]interface{}{
-				"type":    1,
-				"user_id": qutil.IntAll(userInfo["base_user_id"]),
-				"ent_id":  entId,
-			}, "id", "")
-			if positionData != nil && len(*positionData) > 0 {
-				userId = fmt.Sprint(qutil.Int64All((*positionData)["id"]))
-			}
+		if param.BuySubject == "1" {
 			count := util.JysqlDB.CountBySql("SELECT * FROM dataexport_order WHERE product_type = 'VIP订阅' AND user_id = ? AND vip_starttime > ?", userId, time.Now().Format(qutil.Date_Full_Layout))
 			if count > 0 {
 				return map[string]interface{}{
@@ -1286,6 +1266,7 @@ func VipInfo(context *admin.Context) (interface{}, error) {
 				}, nil
 			}
 		}
+
 		//查询订单信息获取客户名称
 		orderInfo := util.JysqlDB.SelectBySql("SELECT c.customer_name,d.company_name FROM dataexport_order d LEFT JOIN contract c ON c.order_code = d.order_code WHERE product_type = 'VIP订阅' and user_id = ? ORDER BY d.id DESC", userId)
 		if len(*orderInfo) == 0 && param.BuySubject != "2" {

+ 70 - 35
src/order/serviceOpen.go

@@ -123,9 +123,43 @@ func ServiceOpen(context *admin.Context) (interface{}, error) {
 		if err := json.Unmarshal([]byte(filter.(string)), &filterData); err != nil {
 			return nil, err
 		}
-		var vipStartTime, vipEndTime time.Time
+		var (
+			userCount                int
+			entService               bool
+			vipStartTime, vipEndTime time.Time
+		)
 		vipStartTime, vipEndTime = GetStartAndEndTime(time.Unix(param.StartTime, 0).Format(cm.Date_Short_Layout), cm.IntAll(filterMap["cyclecount"]), cm.IntAll(filterMap["cycleunit"]))
-		VipServiceOpen(userId, param.Phone, filterMap, vipStartTime, vipEndTime, cm.IntAll((*order)["buy_subject"]), entId)
+		if cm.IntAll((*order)["buy_subject"]) == 2 {
+			entService, userCount = EntServiceOpen(entId, param.Phone, cm.ObjToString((*order)["product_type"]), param.StartTime)
+			orderId := cm.IntAll((*order)["id"])
+			if entId != 0 && param.StartTime != 4070880000 && cm.IntAll((*order)["buy_count"]) > 0 {
+				regRuler := "^1[3456789]{1}\\d{9}$"
+				reg := regexp.MustCompile(regRuler)
+				if cm.IntAll((*order)["order_status"]) == 1 && reg.MatchString(param.Phone) {
+					st := cm.FormatDate(&vipStartTime, cm.Date_Full_Layout)
+					et := cm.FormatDate(&vipEndTime, cm.Date_Full_Layout)
+					areaCount := -1
+					buyArea := map[string]interface{}{}
+					areaMap := cm.ObjToMap(filterMap["area"])
+					if areaMap != nil && len(*areaMap) > 0 {
+						for k, _ := range *areaMap {
+							buyArea[k] = []interface{}{}
+						}
+						areaCount = len(buyArea)
+					}
+					err := EntLicense(entId, cm.IntAll((*order)["buy_count"]), areaCount, orderId, userCount, cm.ObjToString((*order)["product_type"]), st, et, param.Phone)
+					if err != nil {
+						log.Printf("EntLicense 创建企业授权信息失败:code:%s,err:%s", param.OrderCode, err.Error())
+					}
+				}
+			}
+			if !entService {
+				ClearBigVipUserPower(userId)
+			}
+		}
+		if entService || cm.IntAll((*order)["buy_subject"]) == 1 {
+			VipServiceOpen(userId, param.Phone, filterMap, vipStartTime, vipEndTime, cm.IntAll((*order)["buy_subject"]), entId)
+		}
 		updateMap["vip_starttime"] = vipStartTime.Format(cm.Date_Full_Layout)
 		updateMap["vip_endtime"] = vipEndTime.Format(cm.Date_Full_Layout)
 		//updateMap["user_id"] = userId
@@ -171,16 +205,14 @@ func ServiceOpen(context *admin.Context) (interface{}, error) {
 				}
 				if !entService {
 					ClearBigVipUserPower(userId)
-					return map[string]interface{}{
-						"status": 1,
-					}, nil
 				}
 			}
-			//ClearBigVipUserPower(fmt.Sprint((*order)["user_id"])) //订单创建成功后默认清空权限缓存
-			status := cm.If(bigStartTime.Unix() <= time.Now().Unix(), 0, 1)
-			err := NewBigOpenService(filterMap, userId, param.Phone, bigStartTime, bigEndTime, cm.IntAll(status), cm.IntAll((*order)["buy_count"]), cm.IntAll((*order)["buy_subject"]), entId)
-			if err != nil {
-				return nil, errors.New(fmt.Sprintf("订单编号:%s,手机号:%s开通大会员权益失败", param.OrderCode, param.Phone))
+			if entService || cm.IntAll((*order)["buy_subject"]) == 1 {
+				status := cm.If(bigStartTime.Unix() <= time.Now().Unix(), 0, 1)
+				err := NewBigOpenService(filterMap, userId, param.Phone, bigStartTime, bigEndTime, cm.IntAll(status), cm.IntAll((*order)["buy_count"]), cm.IntAll((*order)["buy_subject"]), entId)
+				if err != nil {
+					return nil, errors.New(fmt.Sprintf("订单编号:%s,手机号:%s开通大会员权益失败", param.OrderCode, param.Phone))
+				}
 			}
 		}
 	}
@@ -431,6 +463,10 @@ func OpenUserService(tx *sql.Tx, orderCode string, orderInfo map[string]interfac
 	if productType == "VIP订阅" {
 		vipType := cm.IntAll(orderInfo["vip_type"])
 		if vipType == 0 {
+			var (
+				entService bool
+				userCount  int
+			)
 			vipStartTime, vipEndTime := GetStartAndEndTime(time.Now().Format(cm.Date_Short_Layout), cm.IntAll(filterMap["cyclecount"]), cm.IntAll(filterMap["cycleunit"]))
 			if cm.IntAll(orderInfo["buy_subject"]) == 2 { //购买主体是企业,手机号改变,需要重新创建企业
 				entId, err, userPositionId = AutomaticallyCreatingEnt(cm.ObjToString(orderInfo["company_name"]), cm.ObjToString(orderInfo["user_phone"]), orderCode, 1, userId)
@@ -439,10 +475,6 @@ func OpenUserService(tx *sql.Tx, orderCode string, orderInfo map[string]interfac
 					return err
 				}
 				userId = userPositionId
-				var (
-					entService bool
-					userCount  int
-				)
 				entService, userCount = EntServiceOpen(entId, cm.ObjToString(orderInfo["user_phone"]), cm.ObjToString(orderInfo["product_type"]), vipStartTime.Unix())
 				orderId := cm.IntAll(orderInfo["id"])
 				if entId != 0 && cm.IntAll(orderInfo["buy_count"]) > 0 {
@@ -461,10 +493,11 @@ func OpenUserService(tx *sql.Tx, orderCode string, orderInfo map[string]interfac
 				}
 				if !entService {
 					ClearBigVipUserPower(userId)
-					return nil
 				}
 			}
-			VipServiceOpen(userId, cm.ObjToString(orderInfo["user_phone"]), filterMap, vipStartTime, vipEndTime, cm.IntAll(orderInfo["buy_subject"]), entId)
+			if entService || cm.IntAll(orderInfo["buy_subject"]) == 1 {
+				VipServiceOpen(userId, cm.ObjToString(orderInfo["user_phone"]), filterMap, vipStartTime, vipEndTime, cm.IntAll(orderInfo["buy_subject"]), entId)
+			}
 			updateOrder["vip_starttime"] = vipStartTime.Format(cm.Date_Full_Layout)
 			updateOrder["vip_endtime"] = vipEndTime.Format(cm.Date_Full_Layout)
 			updateOrder["ent_id"] = entId
@@ -532,7 +565,6 @@ func OpenUserService(tx *sql.Tx, orderCode string, orderInfo map[string]interfac
 				updateOrder["vip_starttime"] = time.Now().Format(cm.Date_Full_Layout)
 			}
 		}
-
 	} else if productType == "大会员" {
 		createType := cm.IntAll(filterMap["createType"])
 		serverArr := make([]map[string]interface{}, 0)
@@ -541,6 +573,10 @@ func OpenUserService(tx *sql.Tx, orderCode string, orderInfo map[string]interfac
 			serverArr = cm.ObjArrToMapArr(supplys)
 		}
 		if createType == 1 {
+			var (
+				entService bool
+				userCount  int
+			)
 			bigStartTime := time.Now()
 			bigEndTime := GetDATE(cm.IntAll(filterMap["cycle"]), cm.IntAll(filterMap["cycleType"]), bigStartTime.Unix())
 			status := 0
@@ -552,6 +588,12 @@ func OpenUserService(tx *sql.Tx, orderCode string, orderInfo map[string]interfac
 					return err
 				}
 				userId = userPositionId
+			}
+			updateOrder["vip_starttime"] = bigStartTime.Format(cm.Date_Full_Layout)
+			updateOrder["vip_endtime"] = bigEndTime.Format(cm.Date_Full_Layout)
+			updateOrder["ent_id"] = entId
+			updateOrder["user_id"] = userId
+			if cm.IntAll(orderInfo["buy_subject"]) == 2 {
 				var sName string
 				if cm.IntAll(filterMap["comboId"]) != 0 {
 					if cm.IntAll(filterMap["comboId"]) == 5 {
@@ -565,20 +607,23 @@ func OpenUserService(tx *sql.Tx, orderCode string, orderInfo map[string]interfac
 				}
 				st := cm.FormatDate(&bigStartTime, cm.Date_Full_Layout)
 				et := cm.FormatDate(&bigEndTime, cm.Date_Full_Layout)
-				err := EntLicense(entId, cm.IntAll(orderInfo["buy_count"]), cm.IntAll(cm.If(cm.IntAll(filterMap["areaCount"]) > 0, cm.IntAll(filterMap["areaCount"]), -1)), cm.IntAll(orderInfo["id"]), cm.IntAll(orderInfo["buy_count"]), fmt.Sprintf("%s%s", "大会员", sName), st, et, cm.ObjToString(orderInfo["user_phone"]))
+				entService, userCount = EntServiceOpen(entId, cm.ObjToString(orderInfo["user_phone"]), cm.ObjToString(orderInfo["product_type"]), bigStartTime.Unix())
+				err := EntLicense(entId, cm.IntAll(orderInfo["buy_count"]), cm.IntAll(cm.If(cm.IntAll(filterMap["areaCount"]) > 0, cm.IntAll(filterMap["areaCount"]), -1)), cm.IntAll(orderInfo["id"]), userCount, 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
 				}
+				if !entService {
+					ClearBigVipUserPower(userId)
+				}
 			}
-			err := NewBigOpenService(filterMap, userId, cm.ObjToString(orderInfo["user_phone"]), bigStartTime, bigEndTime, cm.IntAll(status), cm.IntAll(orderInfo["buy_count"]), cm.IntAll(orderInfo["buy_subject"]), entId)
-			if err != nil {
-				return errors.New(fmt.Sprintf("订单编号:%s,开通大会员权益失败", orderCode))
+			if entService || cm.IntAll(orderInfo["buy_subject"]) == 1 {
+				err := NewBigOpenService(filterMap, userId, cm.ObjToString(orderInfo["user_phone"]), bigStartTime, bigEndTime, cm.IntAll(status), cm.IntAll(orderInfo["buy_count"]), cm.IntAll(orderInfo["buy_subject"]), entId)
+				if err != nil {
+					return errors.New(fmt.Sprintf("订单编号:%s,开通大会员权益失败", orderCode))
+				}
 			}
-			updateOrder["vip_starttime"] = bigStartTime.Format(cm.Date_Full_Layout)
-			updateOrder["vip_endtime"] = bigEndTime.Format(cm.Date_Full_Layout)
-			updateOrder["ent_id"] = entId
-			updateOrder["user_id"] = userId
+
 		} else { //1-新建 2-补充 3-延期
 			memberStatus := cm.IntAll(userData["i_member_status"])
 			bigEndTime := cm.Int64All(userData["i_member_endtime"])
@@ -602,16 +647,6 @@ func OpenUserService(tx *sql.Tx, orderCode string, orderInfo map[string]interfac
 				var newStartTime, newEndTime time.Time
 				effectState := true
 				if bmEndTime.Unix() < time.Now().Unix() || cm.IntAll(userData["i_member_status"]) < 0 { //原服务已过期
-					/*//查询回款记录,最近一笔回款时间
-					newReturnMoneyTime, checkPassTime, err := GetReturnTimeAndCheckTime(orderCode)
-					if err != nil {
-						return err
-					}
-					if newReturnMoneyTime.Unix() > checkPassTime.Unix() {
-						newStartTime = newReturnMoneyTime
-					} else {
-						newStartTime = checkPassTime
-					}*/
 					newStartTime = time.Now()
 					effectState = false
 					cycleCount := cm.IntAll(filterMap["cycle"])