Browse Source

no message

xingzai 9 months ago
parent
commit
15f71019b6
3 changed files with 74 additions and 7 deletions
  1. 11 0
      models/order/order.go
  2. 2 2
      models/order/order_user_card.go
  3. 61 5
      services/order.go

+ 11 - 0
models/order/order.go

@@ -287,6 +287,17 @@ func GetCygxOrderList(condition string, pars []interface{}, startSize, pageSize
 	return
 }
 
+func GetCygxOrderDetailList(condition string, pars []interface{}) (items []*CygxOrder, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_order
+			WHERE 1 = 1 ` + condition
+	sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
 // 根据订单编号获取订单详情
 func GetCygxOrderDetailByOrderCode(orderCode string) (item *CygxOrder, err error) {
 	o := orm.NewOrm()

+ 2 - 2
models/order/order_user_card.go

@@ -165,8 +165,8 @@ func GetCygxOrderUserCardDetailByOrderCode(orderCode string) (item *CygxOrderUse
 // 根据手机号获取用户持卡详情
 func GetCygxOrderUserCardDetailByMobile(mobile string) (item *CygxOrderUserCard, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM cygx_order_user_card WHERE mobile = ? `
-	err = o.Raw(sql, mobile).QueryRow(&item)
+	sql := `SELECT * FROM cygx_order_user_card WHERE mobile = ? AND end_date  >= ? `
+	err = o.Raw(sql, mobile, time.Now()).QueryRow(&item)
 	return
 }
 

+ 61 - 5
services/order.go

@@ -227,6 +227,8 @@ func HandleOrderHandle(itemCallback *WechatPayCallback) {
 	if orderDetail.Source == utils.CYGX_OBJ_ACTIVITY {
 		go AddActivitySignupByWechatPay(orderDetail.SourceId, orderDetail.UserId) //微信付款成功自动添加报名
 	}
+
+	go CancelOtherOrder(orderDetail) //付款成功之后自动取消其他相同的订单
 	return
 }
 
@@ -353,9 +355,18 @@ func AddActivitySignupByWechatPay(activityId, userId int) {
 		err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
 		return
 	}
+	var userPointsNum float64
+	if activityInfo.IsResearchPoints {
+		//获取活动对用户要扣的点
+		userPointsNum, e = models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
+		if e != nil {
+			err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
+			return
+		}
+	}
 
-	//专家线下沙龙与买方线下交流自动报名
-	if activityInfo.ActivityTypeId != 5 && activityInfo.ActivityTypeId != 8 {
+	//专家线下沙龙与买方线下交流、扣点的公司调研电话会自动报名
+	if activityInfo.ActivityTypeId != 5 && activityInfo.ActivityTypeId != 8 && userPointsNum == 0 {
 		return
 	}
 	user, e := models.GetWxUserItemByUserId(userId)
@@ -483,9 +494,54 @@ func GetActivityWechatPayMsg(activityId int) (isPublicActivitie, isSignUp bool)
 		isPublicActivitie = true //日卡月卡商品信息
 	}
 
-	//专家线下沙龙与买方线下交流自动报名
-	if activityInfo.ActivityTypeId == 5 || activityInfo.ActivityTypeId == 8 {
-		isSignUp = true
+	var userPointsNum float64
+	if activityInfo.IsResearchPoints {
+		//获取活动对用户要扣的点
+		userPointsNum, e = models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
+		if e != nil {
+			err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
+			return
+		}
+	}
+
+	//专家线下沙龙与买方线下交流、扣点的公司调研电话会自动报名
+	if activityInfo.ActivityTypeId != 5 && activityInfo.ActivityTypeId != 8 && userPointsNum == 0 {
+		return
+	}
+	return
+}
+
+// 付款成功之后自动取消其他相同的订单
+func CancelOtherOrder(item *order.CygxOrder) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("付款成功之后自动取消其他相同的订单失败 CancelOtherOrder, err:", err.Error(), "order_id:", item.OrderId), 2)
+		}
+	}()
+
+	var condition string
+	var pars []interface{}
+	userId := item.UserId
+
+	condition += ` AND user_id  = ?  AND  source_id = ?   AND  source = ?  AND  order_id  != ? AND  order_status = 1  `
+	pars = append(pars, userId, item.SourceId, item.Source, item.OrderId)
+
+	listOrder, e := order.GetCygxOrderDetailList(condition, pars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCygxOrderDetailList, Err: " + e.Error())
+		return
+	}
+	if len(listOrder) == 0 {
+		err = nil
+		return
+	}
+	for _, v := range listOrder {
+		e = order.CancelCygxOrder(v)
+		if e != nil {
+			return
+		}
 	}
 	return
 }