|
@@ -15,10 +15,7 @@ import (
|
|
|
func Order(r *GinRouter) {
|
|
|
r.POSTJWT("/order/createBatch", OrderAddBatch)
|
|
|
r.GETJWT("/order/list", OrderList)
|
|
|
-
|
|
|
- r.POSTJWT("/order/complete", OrderComplete)
|
|
|
- r.POSTJWT("/order/cancel", OrderCancel)
|
|
|
- r.POSTJWT("/order/update", OrderUpdate)
|
|
|
+ r.POSTJWT("/order/cancelOrComplete/:id", OrderCancelOrComplete)
|
|
|
r.GETJWT("/order/detail/:id", OrderDetail)
|
|
|
r.GETJWT("/order/count", OrderCount)
|
|
|
}
|
|
@@ -127,9 +124,9 @@ func OrderCount(_ *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
return resMap, nil
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-func OrderComplete(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
-
|
|
|
+
|
|
|
+func OrderCancelOrComplete(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
+
|
|
|
_id := c.Param("id")
|
|
|
if len(_id) < 1 {
|
|
|
return nil, errors.New("id不能为空")
|
|
@@ -149,99 +146,33 @@ func OrderComplete(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
if len(order.Products) < 1 {
|
|
|
return nil, errors.New("该订单为空")
|
|
|
}
|
|
|
+
|
|
|
+ if order.UserId.Hex() != apictx.User.ID {
|
|
|
+ return nil, errors.New("非法操作")
|
|
|
+ }
|
|
|
+
|
|
|
statusMap := map[int]struct{}{}
|
|
|
for _, v := range order.Products {
|
|
|
statusMap[v.Status] = struct{}{}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
if len(statusMap) == 1 {
|
|
|
- if _, ok := statusMap[1]; ok {
|
|
|
- return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionOrder, _id, &model.Order{Status: 2, IsCancel: -1})
|
|
|
+
|
|
|
+
|
|
|
+ if _, ok := statusMap[-1]; ok && order.Status == -1 {
|
|
|
+ return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionOrder, _id, &model.Order{Status: 3, IsCancel: -1})
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- return nil, errors.New("该订单商品未全部发货")
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-func OrderCancel(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
-
|
|
|
-
|
|
|
- return nil, nil
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-func OrderUpdate(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
- var form model.Order
|
|
|
- err := c.ShouldBindJSON(&form)
|
|
|
- if err != nil {
|
|
|
- return nil, errors.New("参数错误")
|
|
|
- }
|
|
|
- if form.Id.Hex() == "" {
|
|
|
- return nil, errors.New("更新的产品id不能为空")
|
|
|
- }
|
|
|
- form.UpdateTime = time.Now()
|
|
|
-
|
|
|
- result, err := repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionOrder, form.Id.Hex(), &form)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- if result.ModifiedCount > 0 {
|
|
|
-
|
|
|
- curOder := model.Order{}
|
|
|
- found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
- CollectName: repo.CollectionOrder,
|
|
|
- Query: repo.Map{"_id": form.Id},
|
|
|
- Project: []string{"products"},
|
|
|
- }, &curOder)
|
|
|
+
|
|
|
+
|
|
|
+ if _, ok := statusMap[1]; ok && order.Status == 1 {
|
|
|
|
|
|
- if found {
|
|
|
- if len(curOder.Products) > 0 {
|
|
|
- statusMap := make(map[int]struct{})
|
|
|
- for _, v := range curOder.Products {
|
|
|
- statusMap[v.Status] = struct{}{}
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- status := curOder.Status
|
|
|
- if len(statusMap) == 1 {
|
|
|
- if _, ok := statusMap[-1]; ok {
|
|
|
- status = -1
|
|
|
- }
|
|
|
- if _, ok := statusMap[1]; ok {
|
|
|
- status = 1
|
|
|
- }
|
|
|
- if _, ok := statusMap[2]; ok {
|
|
|
- status = 2
|
|
|
- }
|
|
|
- }
|
|
|
- if len(statusMap) == 2 {
|
|
|
- if _, ok := statusMap[-1]; ok {
|
|
|
- status = -1
|
|
|
- } else if _, ok := statusMap[1]; ok {
|
|
|
- status = 1
|
|
|
- }
|
|
|
- }
|
|
|
- if len(statusMap) == 3 {
|
|
|
- status = -1
|
|
|
- }
|
|
|
- var statusOrder model.Order
|
|
|
- statusOrder.Status = status
|
|
|
- repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionOrder, form.Id.Hex(), &statusOrder)
|
|
|
-
|
|
|
- }
|
|
|
+ return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionOrder, _id, &model.Order{Status: 2, IsCancel: -1})
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- return result, err
|
|
|
|
|
|
+ return nil, errors.New("该订单不满足取消或完成操作")
|
|
|
}
|
|
|
|
|
|
|