Kaynağa Gözat

bug: fix lock not used

zjxpcyc 6 yıl önce
ebeveyn
işleme
53e46db63b
2 değiştirilmiş dosya ile 11 ekleme ve 11 silme
  1. 11
    0
      controllers/goods/order.go
  2. 0
    11
      service/goods/orders.go

+ 11
- 0
controllers/goods/order.go Dosyayı Görüntüle

@@ -8,9 +8,12 @@ import (
8 8
 	"spaceofcheng/services/models/model"
9 9
 	"spaceofcheng/services/utils"
10 10
 	"strconv"
11
+	"sync"
11 12
 	"time"
12 13
 )
13 14
 
15
+var mtx *sync.Mutex
16
+
14 17
 // GetOrderList 获取商品订单
15 18
 // 管理端 - 统计查询
16 19
 func (c *GoodsController) GetOrderList() {
@@ -86,6 +89,10 @@ func (c *GoodsController) GetOnlineOrder() {
86 89
 // PostOrder 下单
87 90
 // 微信端
88 91
 func (c *GoodsController) PostOrder() {
92
+	// 防止并发
93
+	mtx.Lock()
94
+	defer mtx.Unlock()
95
+
89 96
 	// 订单主信息
90 97
 	info := c.GetString("info")
91 98
 	if info == "" {
@@ -280,3 +287,7 @@ func (c *GoodsController) UpdateOrdersIntimidate() {
280 287
 	}
281 288
 	c.ResponseJSON("操作成功!")
282 289
 }
290
+
291
+func init() {
292
+	mtx = new(sync.Mutex)
293
+}

+ 0
- 11
service/goods/orders.go Dosyayı Görüntüle

@@ -11,23 +11,16 @@ import (
11 11
 	"spaceofcheng/services/service/cases"
12 12
 	"spaceofcheng/services/utils"
13 13
 	"strconv"
14
-	"sync"
15 14
 	"time"
16 15
 
17 16
 	"github.com/yl10/kit/guid"
18 17
 )
19 18
 
20
-var mtx *sync.Mutex
21
-
22 19
 // Orders 下单
23 20
 func (s *GoodsServ) Orders(
24 21
 	info *model.TaGoodsOrders,
25 22
 	details []model.TaGoodsOrdersDetail,
26 23
 	customercouponid string) error {
27
-	// 防止并发
28
-	mtx.Lock()
29
-	defer mtx.Unlock()
30
-
31 24
 	// org := s.ctx.Get("org").(model.SysOrg)
32 25
 	cust := s.ctx.Get("customer").(model.TaCustomer)
33 26
 
@@ -595,7 +588,3 @@ func (s *GoodsServ) GetNewGoods(ordersID string) (*goods.OrdersWithGoods, error)
595 588
 
596 589
 	return order, nil
597 590
 }
598
-
599
-func init() {
600
-	mtx = new(sync.Mutex)
601
-}