Browse Source

bug: fix lock not used

zjxpcyc 6 years ago
parent
commit
53e46db63b
2 changed files with 11 additions and 11 deletions
  1. 11
    0
      controllers/goods/order.go
  2. 0
    11
      service/goods/orders.go

+ 11
- 0
controllers/goods/order.go View File

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

+ 0
- 11
service/goods/orders.go View File

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