Ver Fonte

订单导出。职位id. 代用户下单根据注册来源控制购买超级订阅

xuzhiheng há 2 anos atrás
pai
commit
c30c72273b
3 ficheiros alterados com 114 adições e 20 exclusões
  1. 95 0
      src/order/optimizeOrder.go
  2. 18 20
      src/order/orderManageController.go
  3. 1 0
      src/order/router.go

+ 95 - 0
src/order/optimizeOrder.go

@@ -6,6 +6,7 @@ import (
 	"mongodb"
 	qutil "qfw/util"
 	"strings"
+	"time"
 	"util"
 
 	"github.com/baiy/Cadmin-server-go/admin"
@@ -132,3 +133,97 @@ func FindUserAccount(context *admin.Context) (interface{}, error) {
 	}
 	return map[string]interface{}{"data": userData}, nil
 }
+
+func HelpVipInfo(context *admin.Context) (interface{}, error) {
+	param := new(struct {
+		Phone   string `form:"phone"`
+		RegType string `form:"regType"`
+	})
+	err := context.Form(param)
+	if err != nil {
+		return nil, err
+	}
+	willEffect, regType := false, "s_phone"
+	//先判断用户是否有即将生效的超级订阅订单
+	if strings.Contains(param.RegType, "微信") && !strings.Contains(param.RegType, "APP") {
+		regType = "s_m_phone"
+	}
+	query := map[string]interface{}{
+		regType: param.Phone,
+		"l_vip_starttime": map[string]interface{}{
+			"$gt": time.Now().Unix(),
+		},
+	}
+	count1 := util.MQFW.Count("user", query)
+	if count1 > 0 {
+		willEffect = true
+	}
+	// 增加如若存在订单审核状态为“待一审”、“待二审”、“已退回”的超级订阅订单的则不允许创建
+	if ExistProcessOrder(param.Phone, SUPERSUB, "") {
+		willEffect = true
+	}
+	if willEffect {
+		return map[string]interface{}{
+			"willEffect": true,
+		}, nil
+	}
+	//判断用户购买过超级订阅并且在有效期内   i_vip_status 开启状态:0-暂不使用vip订阅 1-试用 2-正式 -1-试用到期 -2-正式到期
+	userInfo := map[string]interface{}{}
+	userData, ok := util.MQFW.FindOneByField("user", map[string]interface{}{regType: param.Phone, "i_vip_status": 2}, `{"_id":1,"i_vip_expire_tip":1,"i_vip_status":1,"l_vip_endtime":1,"l_vip_starttime":1,"o_vipjy":1}`)
+	if ok && userData != nil && len(*userData) > 0 {
+		userInfo = *userData
+	} else {
+		return map[string]interface{}{
+			"willEffect": false,
+			"userData":   nil,
+			"vipExist":   false,
+		}, nil
+	}
+	if userInfo != nil && len(userInfo) > 0 {
+		userId := mongodb.BsonIdToSId(userInfo["_id"])
+		//查询订单信息获取客户名称
+		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 {
+			return nil, errors.New("查询订单表没有查到订单信息")
+		}
+		vipInfo := qutil.ObjToMap(userInfo["o_vipjy"])
+		buySet := qutil.ObjToMap((*vipInfo)["o_buyset"])
+		areaCount := qutil.IntAll((*buySet)["areacount"])
+		//判断购买区域是否是全国
+		nationwide := false
+		if areaCount == -1 {
+			nationwide = true
+		}
+		if areaCount == -1 {
+			areaCount = 0
+		}
+		//area := qutil.ObjToMap((*vipInfo)["o_area"])
+		userInfo["areaCount"] = areaCount
+		//判断是新版超级订阅还是老版超级订阅
+		newVip := false
+		if qutil.IntAll((*buySet)["upgrade"]) == 1 {
+			newVip = true
+		}
+		t := qutil.Int64All(userInfo["l_vip_endtime"])
+		_t := time.Unix(t, 0)
+		userInfo["vipStartTime"] = (_t.AddDate(0, 0, 1)).Format(qutil.Date_Short_Layout)
+		data := map[string]interface{}{
+			"willEffect": false,
+			"vipExist":   true,
+			"nationwide": nationwide,
+			"userData":   userInfo,
+			"newVip":     newVip,
+		}
+		if len((*orderInfo)) > 0 {
+			data["orderInfo"] = (*orderInfo)[0]
+		}
+		return data, nil
+	}
+	return map[string]interface{}{
+		"willEffect": false,
+		"userData":   nil,
+		"vipExist":   false,
+		"nationwide": false,
+		"new":        false,
+	}, nil
+}

+ 18 - 20
src/order/orderManageController.go

@@ -668,24 +668,23 @@ func ExportOrder(context *admin.Context) (interface{}, error) {
 		str += " e.order_code like " + "'%" + param.OrderCode + "%' and"
 	}
 	if param.OrderType != "" {
-
-		if param.SalesSecondLevel == "" {
-			str += " ("
-			//根据销售渠道一级分类代码查询二级分类
-			class := util.JysqlDB.Find("dict_item", map[string]interface{}{"parent_code": param.OrderType}, "item_code", "", -1, -1)
-			if class != nil && len(*class) > 0 {
-				for k, val := range *class {
-					if k < len(*class)-1 {
-						str += " distribution_channel = '" + qutil.ObjToString(val["item_code"]) + "' or "
-					} else {
-						str += " distribution_channel = '" + qutil.ObjToString(val["item_code"]) + "'"
-					}
-				}
-				str += " ) and"
-			}
-		} else {
-			str += " distribution_channel = '" + param.SalesSecondLevel + "' and"
-		}
+		// if param.SalesSecondLevel == "" {
+		// 	str += " ("
+		// 	//根据销售渠道一级分类代码查询二级分类
+		// 	class := util.JysqlDB.Find("dict_item", map[string]interface{}{"parent_code": param.OrderType}, "item_code", "", -1, -1)
+		// 	if class != nil && len(*class) > 0 {
+		// 		for k, val := range *class {
+		// 			if k < len(*class)-1 {
+		// 				str += " distribution_channel = '" + qutil.ObjToString(val["item_code"]) + "' or "
+		// 			} else {
+		// 				str += " distribution_channel = '" + qutil.ObjToString(val["item_code"]) + "'"
+		// 			}
+		// 		}
+		// 		str += " ) and"
+		// 	}
+		// } else {
+		str += " distribution_channel = '" + param.OrderType + "' and"
+		// }
 	}
 	if param.RefundStatus != "" {
 		str += "  e.refund_status = '" + param.RefundStatus + "' and"
@@ -3667,13 +3666,12 @@ func AutomaticallyCreatingEnt(name, phone, orderCode string, orderStatus int, us
 			positionData := util.BaseDB.FindOne(util.BasePosition, map[string]interface{}{
 				"type":    1,
 				"user_id": baseUserId,
+				"ent_id":  res.Id,
 			}, "id", "")
 			if positionData != nil && len(*positionData) > 0 {
 				userPositionId = fmt.Sprint(qutil.Int64All((*positionData)["id"]))
 			}
-
 		}
-
 	}
 	return res.Id, nil, userPositionId
 }

+ 1 - 0
src/order/router.go

@@ -134,6 +134,7 @@ func init() {
 		"Baiy.Cadmin.Order.vipGives":                          VipGives,
 		"Baiy.Cadmin.Order.copyLink":                          CopyLink,
 		"Baiy.Cadmin.Order.addUpdateRecord":                   AddUpdateRecord,
+		"Baiy.Cadmin.Order.helpVipinfo":                       HelpVipInfo,
 	})
 	RegisterDispatch(OrderDispatcher)
 }