Sfoglia il codice sorgente

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

胡轶钦 6 anni fa
parent
commit
e38917f19b
6 ha cambiato i file con 54 aggiunte e 22 eliminazioni
  1. 2
    1
      conf/db.conf
  2. 19
    0
      controllers/flashbuy/flashbuy.go
  3. 1
    1
      models/models.go
  4. 1
    1
      routers/wechat.go
  5. 11
    0
      service/flashbuy/flashbuy.go
  6. 20
    19
      service/user.go

+ 2
- 1
conf/db.conf Vedi File

@@ -6,7 +6,8 @@ con_protocol = tcp
6 6
 
7 7
 ; 数据库地址,可以使用IP
8 8
 ; db_addr      = 47.101.36.130
9
-db_addr        = 192.168.0.122
9
+# db_addr        = 192.168.0.122
10
+db_addr = localhost
10 11
 # db_addr      = rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com
11 12
 
12 13
 ; 端口

+ 19
- 0
controllers/flashbuy/flashbuy.go Vedi File

@@ -69,15 +69,34 @@ func (c *FlashBuyController) GetCustomerFlashBuyList() {
69 69
 
70 70
 }
71 71
 
72
+// GetFlashBuyById 获取抢购详情
72 73
 func (c *FlashBuyController) GetFlashBuyById() {
73 74
 	flashBuyId := c.GetString(":flashBuyId")
74 75
 	flashBuy, err := c.dao.GetFlashBuyById(flashBuyId)
75 76
 	if err != nil {
76 77
 		c.ResponseError(err)
77 78
 	}
79
+
78 80
 	c.ResponseJSON(flashBuy)
79 81
 }
80 82
 
83
+// GetWechatFlashBuyById
84
+func (c *FlashBuyController) GetWechatFlashBuyById() {
85
+	flashBuyId := c.GetString(":flashBuyId")
86
+	flashBuy, err := c.dao.GetFlashBuyById(flashBuyId)
87
+	if err != nil {
88
+		c.ResponseError(err)
89
+	}
90
+	userinfo, err := c.dao.GetFlashByUser(flashBuyId)
91
+	if err != nil {
92
+		c.ResponseError(err)
93
+	}
94
+	c.ResponseJSON(map[string]interface{}{
95
+		"flashBuy": flashBuy,
96
+		"userInfo": userinfo,
97
+	})
98
+}
99
+
81 100
 func (c *FlashBuyController) GetCustomerFlashBuyId() {
82 101
 	flashBuyId := c.GetString(":customerFlashBuyId")
83 102
 	flashBuy, err := c.dao.GetCustomerFlashBuyId(flashBuyId)

+ 1
- 1
models/models.go Vedi File

@@ -22,7 +22,7 @@ func NewDBEngine() *xorm.Engine {
22 22
 	dns := getMySQLDNS()
23 23
 
24 24
 	engine, err := xorm.NewEngine(dbType, dns)
25
-	engine.ShowSQL()
25
+	// engine.ShowSQL()
26 26
 
27 27
 	if err != nil {
28 28
 		panic(err)

+ 1
- 1
routers/wechat.go Vedi File

@@ -97,7 +97,7 @@ func getWechatRoutes(prefix string) beego.LinkNamespace {
97 97
 		beego.NSRouter("/user/luckdraw/record/:id", &luckdraw.LuckDrawController{}, "get:GetRecordByID"),
98 98
 
99 99
 		// 抢购
100
-		beego.NSRouter("/flashbuy/flash/:flashBuyId", &flashbuy.FlashBuyController{}, "get:GetFlashBuyById"),
100
+		beego.NSRouter("/flashbuy/flash/:flashBuyId", &flashbuy.FlashBuyController{}, "get:GetWechatFlashBuyById"),
101 101
 		beego.NSRouter("/flashbuy/customer", &flashbuy.FlashBuyController{}, "get:GetCustomerFlashBuyByCustomerId"),
102 102
 		beego.NSRouter("/flashbuy/customerFlash/:customerFlashBuyId", &flashbuy.FlashBuyController{}, "get:GetCustomerFlashBuyId"),
103 103
 		beego.NSRouter("/flashbuy/:id", &flashbuy.FlashBuyController{}, "post:FlashBuy"),

+ 11
- 0
service/flashbuy/flashbuy.go Vedi File

@@ -62,6 +62,17 @@ func (s *FlashBuyServ) GetFlashBuyById(flashBuyId string) (*model.TaFlashBuy, er
62 62
 	}
63 63
 	return flashbuy, nil
64 64
 }
65
+
66
+// GetFlashByUser 获取用户的抢购信息
67
+func (s *FlashBuyServ) GetFlashByUser(id string) ([]model.TaCustomerFlashBuy, error) {
68
+	cst := s.ctx.Get("customer")
69
+	if cst == nil {
70
+		return nil, errors.New("系统内部错误")
71
+	}
72
+	flashbuys, err := s.dao.GetCustomerFlashBuy(id, cst.(model.TaCustomer).CustomerId)
73
+	return flashbuys, err
74
+}
75
+
65 76
 func (s *FlashBuyServ) SaveFlashBuy(flashbuy model.TaFlashBuy) (*model.TaFlashBuy, error) {
66 77
 	var newFlashBuy *model.TaFlashBuy
67 78
 	var err error

+ 20
- 19
service/user.go Vedi File

@@ -117,28 +117,29 @@ func (s *UserServ) GetUserByID(userid string) (*system.UserInfo, error) {
117 117
 		beego.Error(err)
118 118
 		return nil, err
119 119
 	}
120
-	userinfo.Pwd = ""
121
-	usertype, err := s.dao.GetUserType(userid)
122
-	if err != nil {
123
-		beego.Error(err)
124
-		return nil, err
125
-	}
126
-	userinfo.UserType = usertype
120
+	if userinfo != nil {
121
+		userinfo.Pwd = ""
122
+		usertype, err := s.dao.GetUserType(userid)
123
+		if err != nil {
124
+			beego.Error(err)
125
+			return nil, err
126
+		}
127
+		userinfo.UserType = usertype
127 128
 
128
-	usertag, err := s.dao.GetUserTag(userid)
129
-	if err != nil {
130
-		beego.Error(err)
131
-		return nil, err
132
-	}
133
-	userinfo.UserTag = usertag
129
+		usertag, err := s.dao.GetUserTag(userid)
130
+		if err != nil {
131
+			beego.Error(err)
132
+			return nil, err
133
+		}
134
+		userinfo.UserTag = usertag
134 135
 
135
-	usercase, err := s.dao.GetUserCase(userid)
136
-	if err != nil {
137
-		beego.Error(err)
138
-		return nil, err
136
+		usercase, err := s.dao.GetUserCase(userid)
137
+		if err != nil {
138
+			beego.Error(err)
139
+			return nil, err
140
+		}
141
+		userinfo.UserCase = usercase
139 142
 	}
140
-	userinfo.UserCase = usercase
141
-
142 143
 	// userrole, err := s.dao.GetUserRole(userid)
143 144
 	// if err != nil {
144 145
 	// 	return nil, err