Browse Source

no message

xingzai 1 year ago
parent
commit
32b3a49b6f
6 changed files with 117 additions and 3 deletions
  1. 1 1
      controllers/activity.go
  2. 46 0
      controllers/order.go
  3. 1 0
      models/activity.go
  4. 58 0
      models/order/order.go
  5. 9 0
      routers/commentsRouter.go
  6. 2 2
      services/order.go

+ 1 - 1
controllers/activity.go

@@ -568,7 +568,7 @@ func (this *ActivityCoAntroller) Detail() {
 			} else {
 				resp.GoodsList = services.GetGoodsInfoByActivity(activityInfo) //单场活动信息
 				fmt.Println("activityId", activityId)
-				_, resp.PayTimeCountdown = services.GetHaverEquallyOrderByUser10MinByActivty(uid, activityId) //截止支付时间倒计时
+				resp.OrderCode, resp.PayTimeCountdown = services.GetHaverEquallyOrderByUser10MinByActivty(uid, activityId) //截止支付时间倒计时
 			}
 			for _, v := range resp.GoodsList {
 				resp.PopupPriceMsg += v.PopupPriceMsg //价格弹窗信息

+ 46 - 0
controllers/order.go

@@ -369,3 +369,49 @@ func (this *OrderController) OrderDetail() {
 	br.Success = true
 	br.Msg = "获取成功"
 }
+
+// @Title 通过活动创建订单
+// @Description 通过活动创建订单接口
+// @Param	request	body models.ActivitySingnupRep true "type json string"
+// @Success Ret=200 {object} models.SignupStatus
+// @router /cancel [post]
+func (this *OrderController) Cancel() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	var req order.CygxOrderCancelReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	orderCode := req.OrderCode
+	orderDetail, err := order.GetCygxOrderDetailByOrderCode(orderCode)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败, Err:" + err.Error()
+		return
+	}
+
+	err = order.CancelCygxOrder(orderDetail)
+	if err != nil {
+		br.Msg = "取消订单失败"
+		br.ErrMsg = "获取失败, Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}

+ 1 - 0
models/activity.go

@@ -261,6 +261,7 @@ type CygxActivityResp struct {
 	IsCompanyApply     bool                   `description:"机构是否申请过试用"`
 	IsNeedBusinessCard bool                   `description:"是否需要上传名片"`
 	PayTimeCountdown   int                    `description:"支付时间倒计时"`
+	OrderCode          string                 `comment:"订单编号"`
 	GoodsList          []*order.CygxGoodsResp `description:"商品信息"`
 }
 

+ 58 - 0
models/order/order.go

@@ -29,6 +29,10 @@ type CygxOrderAddReq struct {
 	SourceId int `description:"资源ID"`
 }
 
+type CygxOrderCancelReq struct {
+	OrderCode string `comment:"订单编号"`
+}
+
 type CygxOrder struct {
 	OrderId          int       `orm:"column(order_id);pk";comment:"订单id"`
 	OrderCode        string    `comment:"订单编号"`
@@ -153,6 +157,9 @@ func AddCygxOrder(item *CygxOrder) (err error) {
 			o.Rollback()
 		}
 	}()
+
+	item.OrderStatus = 1 // 初始状态待支付
+
 	itemOrderAction := new(CygxOrderAction)
 
 	itemOrderAction.Action = "创建订单"
@@ -182,6 +189,57 @@ func AddCygxOrder(item *CygxOrder) (err error) {
 	return
 }
 
+// 添加
+func CancelCygxOrder(item *CygxOrder) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+	itemOrderAction := new(CygxOrderAction)
+	itemOrderAction.Action = "取消订单"
+	itemOrderAction.OrderStatus = 0
+	itemOrderAction.OrderStatusText = "已取消"
+	itemOrderAction.OrderCode = item.OrderCode
+	itemOrderAction.UserId = item.UserId
+	itemOrderAction.Mobile = item.Mobile
+	itemOrderAction.Email = item.Email
+	itemOrderAction.CompanyId = item.CompanyId
+	itemOrderAction.CompanyName = item.CompanyName
+	itemOrderAction.RealName = item.RealName
+	itemOrderAction.SellerName = item.SellerName
+	itemOrderAction.CreateTime = time.Now()
+	itemOrderAction.ModifyTime = time.Now()
+	itemOrderAction.RegisterPlatform = item.RegisterPlatform
+
+	_, err = o.Insert(itemOrderAction) // 写入订单操作信息
+	if err != nil {
+		return
+	}
+
+	updateParams := make(map[string]interface{})
+	updateParams["OrderStatus"] = 0
+	updateParams["ModifyTime"] = item.ModifyTime
+	ptrStructOrTableName := "cygx_order"
+	whereParam := map[string]interface{}{"order_code": item.OrderCode}
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range whereParam {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err = qs.Update(updateParams)
+	if err != nil {
+		return
+	}
+	return
+}
+
 // 根据订单编号修改
 func UpdateCygxOrder(item *CygxOrder, oldOrderCode string) (err error) {
 	o := orm.NewOrm()

+ 9 - 0
routers/commentsRouter.go

@@ -322,6 +322,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_mfyx/controllers:OrderController"] = append(beego.GlobalControllerRouter["hongze/hongze_mfyx/controllers:OrderController"],
+        beego.ControllerComments{
+            Method: "Cancel",
+            Router: `/cancel`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_mfyx/controllers:OrderController"] = append(beego.GlobalControllerRouter["hongze/hongze_mfyx/controllers:OrderController"],
         beego.ControllerComments{
             Method: "OrderDetail",

+ 2 - 2
services/order.go

@@ -78,7 +78,7 @@ func GetHaverEquallyOrderByUser10Min(userId, goodsId int) (orderCode string) {
 	var condition string
 	var pars []interface{}
 	endTime := time.Now().Add(-10 * time.Minute)
-	condition = ` AND  user_id = ? AND  goods_id = ? AND create_time > ?  ORDER BY order_id DESC  `
+	condition = ` AND order_status = 1 AND  user_id = ? AND  goods_id = ? AND create_time > ?  ORDER BY order_id DESC  `
 	pars = append(pars, userId, goodsId, endTime)
 	orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
 	if e != nil && e.Error() != utils.ErrNoRow() {
@@ -107,7 +107,7 @@ func GetHaverEquallyOrderByUser10MinByActivty(userId, sourceId int) (orderCode s
 	var condition string
 	var pars []interface{}
 	endTime := time.Now().Add(-10 * time.Minute)
-	condition = ` AND source = 'activity' AND  user_id = ? AND  source_id = ? AND create_time > ?  ORDER BY order_id DESC  `
+	condition = `  AND order_status = 1  AND source = 'activity' AND  user_id = ? AND  source_id = ? AND create_time > ?  ORDER BY order_id DESC  `
 	pars = append(pars, userId, sourceId, endTime)
 	orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
 	if e != nil && e.Error() != utils.ErrNoRow() {