Explorar el Código

Merge branch 'dev' of http://git.ycjcjy.com/SpaceOfCheng/services into dev

胡轶钦 hace 6 años
padre
commit
a94df925b8
Se han modificado 3 ficheros con 23 adiciones y 12 borrados
  1. 12
    1
      controllers/bodycheck/bodycheck.go
  2. 11
    0
      controllers/goods/order.go
  3. 0
    11
      service/goods/orders.go

+ 12
- 1
controllers/bodycheck/bodycheck.go Ver fichero

7
 	"spaceofcheng/services/models/model"
7
 	"spaceofcheng/services/models/model"
8
 	"spaceofcheng/services/service/bodycheck"
8
 	"spaceofcheng/services/service/bodycheck"
9
 	"spaceofcheng/services/utils"
9
 	"spaceofcheng/services/utils"
10
+	"sync"
10
 
11
 
11
 	"github.com/astaxie/beego"
12
 	"github.com/astaxie/beego"
12
 )
13
 )
15
 // 临时的解决方案是放到全局单例对象中
16
 // 临时的解决方案是放到全局单例对象中
16
 var qrCodes map[string]string
17
 var qrCodes map[string]string
17
 
18
 
19
+var mtx *sync.Mutex
20
+
18
 // BodyCheckController 商品
21
 // BodyCheckController 商品
19
 type BodyCheckController struct {
22
 type BodyCheckController struct {
20
 	serv *bodycheck.BodyCheckServ
23
 	serv *bodycheck.BodyCheckServ
67
 
70
 
68
 // PostCheckResult 测量结果返回
71
 // PostCheckResult 测量结果返回
69
 func (c *BodyCheckController) PostCheckResult() {
72
 func (c *BodyCheckController) PostCheckResult() {
73
+	// 防止并发
74
+	mtx.Lock()
75
+
70
 	r := c.Ctx.Request
76
 	r := c.Ctx.Request
71
-	defer r.Body.Close()
77
+	defer func() {
78
+		r.Body.Close()
79
+		mtx.Unlock()
80
+	}()
81
+
72
 	con, _ := ioutil.ReadAll(r.Body) //获取post的数据
82
 	con, _ := ioutil.ReadAll(r.Body) //获取post的数据
73
 
83
 
74
 	var formVal map[string]interface{}
84
 	var formVal map[string]interface{}
98
 
108
 
99
 func init() {
109
 func init() {
100
 	qrCodes = make(map[string]string)
110
 	qrCodes = make(map[string]string)
111
+	mtx = new(sync.Mutex)
101
 }
112
 }

+ 11
- 0
controllers/goods/order.go Ver fichero

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 == "" {
283
 	}
290
 	}
284
 	c.ResponseJSON("操作成功!")
291
 	c.ResponseJSON("操作成功!")
285
 }
292
 }
293
+
294
+func init() {
295
+	mtx = new(sync.Mutex)
296
+}

+ 0
- 11
service/goods/orders.go Ver fichero

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
-}