Selaa lähdekoodia

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

胡轶钦 6 vuotta sitten
vanhempi
commit
d8325632db

+ 2
- 3
conf/db.conf Näytä tiedosto

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

+ 1
- 1
conf/log.conf Näytä tiedosto

@@ -1,4 +1,4 @@
1 1
 [common]
2
-filename="E:\\GoProject\\src\\spaceofcheng\\services\\log\\common.log"
2
+filename="E:\\GoProjects\\src\\spaceofcheng\\services\\log\\common.log"
3 3
 # log level "emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"
4 4
 level="debug"

+ 2
- 1
controllers/luckdraw/luckdraw.go Näytä tiedosto

@@ -148,7 +148,7 @@ func (c *LuckDrawController) GetUserByCode() {
148 148
 
149 149
 	user := userRaw.(model.TaCustomer)
150 150
 	luckdrawid := c.GetString(":id")
151
-	record, err := c.serv.GetUserLuckDrawByLuckDraw(user, luckdrawid)
151
+	record, set, err := c.serv.GetUserLuckDrawByLuckDraw(user, luckdrawid)
152 152
 	if err != nil {
153 153
 		utils.LogError("获取用户抽奖信息失败: " + err.Error())
154 154
 		c.ResponseError(errors.New("获取用户抽奖信息失败"))
@@ -166,6 +166,7 @@ func (c *LuckDrawController) GetUserByCode() {
166 166
 		"user":   user,
167 167
 		"record": record,
168 168
 		"detail": detail,
169
+		"set":    set,
169 170
 	})
170 171
 }
171 172
 

+ 5
- 0
models/customer/vip.go Näytä tiedosto

@@ -3,14 +3,19 @@ package customer
3 3
 import (
4 4
 	"spaceofcheng/services/models"
5 5
 	"spaceofcheng/services/models/model"
6
+	"time"
6 7
 )
7 8
 
8 9
 // GetValidVIPCards 依据客户ID 获取 VIP 卡
9 10
 // 按照过期时间升序, 即 将到期的在最上面
10 11
 // VIP 卡可以跨案场使用
11 12
 func (m *CustomerDAO) GetValidVIPCards(custID string) (vips []model.TaCustomerVip, err error) {
13
+	now := time.Now().Local().Format("2006-01-02 15:04:05")
14
+
12 15
 	err = m.db.Where("customer_id=?", custID).
13 16
 		And("status=?", models.STATUS_NORMAL).
17
+		And(`DATE_FORMAT(begin_date, "%Y-%m-%d %T")<=?`, now).
18
+		And(`DATE_FORMAT(end_date, "%Y-%m-%d %T")>=?`, now).
14 19
 		And("balance>0").
15 20
 		Asc("end_date").
16 21
 		Find(&vips)

+ 2
- 2
models/goods/types.go Näytä tiedosto

@@ -50,6 +50,6 @@ type OrdersWithGoods struct {
50 50
 // OrdersDetail 订单详情
51 51
 type OrdersDetail struct {
52 52
 	model.TaGoodsOrders `xorm:"extends"`
53
-	Goods               []DetailWithType
54
-	Coupons             []model.TaGoodsOrdersCoupon
53
+	Goods               []DetailWithType            `xorm:"-"`
54
+	Coupons             []model.TaGoodsOrdersCoupon `xorm:"-"`
55 55
 }

+ 1
- 0
models/vipcard/vipcard.go Näytä tiedosto

@@ -214,6 +214,7 @@ func (m *VipcardDAO) InsertCustomerVipChange(change model.TaCustomerVipChange) e
214 214
 	change.ChangeId = utils.GetGUID()
215 215
 	change.Status = models.STATUS_NORMAL
216 216
 	change.CreateDate = time.Now()
217
+
217 218
 	_, err := m.db.Insert(change)
218 219
 	return err
219 220
 }

+ 1
- 0
service/goods/goods.go Näytä tiedosto

@@ -34,6 +34,7 @@ func NewGoodsServ(ctx *utils.Context) *GoodsServ {
34 34
 		custDAO:   customer.NewCustomerDAO(ctx),
35 35
 		userDAO:   system.NewUserDAO(ctx),
36 36
 		couponDAO: coupon.NewCouponDAO(ctx),
37
+		vipDAO:    vipcard.NewVipcardDAO(ctx),
37 38
 	}
38 39
 }
39 40
 

+ 1
- 0
service/goods/orders.go Näytä tiedosto

@@ -70,6 +70,7 @@ func (s *GoodsServ) PreOrders(
70 70
 		if err != nil {
71 71
 			return nil, utils.LogError("查询用户VIP卡信息出错", err.Error())
72 72
 		}
73
+
73 74
 		if vips != nil && len(vips) > 0 {
74 75
 			for _, vip := range vips {
75 76
 				vipMoney, _ := strconv.ParseFloat(vip.Balance, 64)

+ 5
- 5
service/luckdraw/luckdraw.go Näytä tiedosto

@@ -467,19 +467,19 @@ func (s *LuckdrawServ) GetUserRecordByLuckDraw(userid string, luckdrawid string)
467 467
 }
468 468
 
469 469
 // GetUserLuckDrawByLuckDraw 获取用户抽奖信息
470
-func (s *LuckdrawServ) GetUserLuckDrawByLuckDraw(user model.TaCustomer, luckdrawid string) (*model.TaLuckdrawRecord, error) {
470
+func (s *LuckdrawServ) GetUserLuckDrawByLuckDraw(user model.TaCustomer, luckdrawid string) (*model.TaLuckdrawRecord, *model.TaLuckdrawCustomer, error) {
471 471
 	// 获取用户抽奖设置信息
472
-	_, err := s.dao.GetUserLuckDrawSet(user, luckdrawid)
472
+	customerSet, err := s.dao.GetUserLuckDrawSet(user, luckdrawid)
473 473
 	if err != nil {
474 474
 		utils.LogError("获取用户抽奖设置失败: " + err.Error())
475
-		return nil, errors.New("获取用户抽奖设置失败")
475
+		return nil, nil, errors.New("获取用户抽奖设置失败")
476 476
 	}
477 477
 	record, err := s.dao.GetUserLuckDrawByLuckDraw(user.CustomerId, luckdrawid)
478 478
 	if err != nil {
479 479
 		utils.LogError("获取用户的抽奖信息失败: " + err.Error())
480
-		return nil, errors.New("获取用户的抽奖信息失败")
480
+		return nil, nil, errors.New("获取用户的抽奖信息失败")
481 481
 	}
482
-	return record, nil
482
+	return record, customerSet, nil
483 483
 }
484 484
 
485 485
 func (s *LuckdrawServ) GetDetailByRecord(recordid string) (*model.TaPrizeDetail, error) {

+ 3
- 11
tests/cases_test.go Näytä tiedosto

@@ -12,7 +12,6 @@ import (
12 12
 func TestGetCmsCaseList(t *testing.T) {
13 13
 
14 14
 	Convey("获取案场列表", t, func() {
15
-
16 15
 		Convey("正常业务", func() {
17 16
 			params := url.Values{}
18 17
 			params.Add("orgid", "1")
@@ -26,13 +25,8 @@ func TestGetCmsCaseList(t *testing.T) {
26 25
 			So(err, ShouldBeNil)
27 26
 
28 27
 			// 业务返回判断
29
-			Convey("结果码 200", func() {
30
-				So(result.Code, ShouldEqual, http.StatusOK)
31
-			})
32
-
33
-			Convey("结果不为空", func() {
34
-				So(result.Result, ShouldNotBeEmpty)
35
-			})
28
+			So(result.Code, ShouldEqual, http.StatusOK)
29
+			So(result.Result, ShouldNotBeEmpty)
36 30
 		})
37 31
 
38 32
 		Convey("机构不传报错", func() {
@@ -45,9 +39,7 @@ func TestGetCmsCaseList(t *testing.T) {
45 39
 			So(err, ShouldBeNil)
46 40
 
47 41
 			// 业务返回判断
48
-			Convey("结果码 不是200", func() {
49
-				So(result.Code, ShouldNotEqual, http.StatusOK)
50
-			})
42
+			So(result.Code, ShouldNotEqual, http.StatusOK)
51 43
 		})
52 44
 
53 45
 	})

+ 52
- 3
tests/goodsorder_test.go Näytä tiedosto

@@ -1,24 +1,73 @@
1 1
 package tests
2 2
 
3 3
 import (
4
+	"net/http"
4 5
 	"net/url"
6
+	"spaceofcheng/services/controllers"
5 7
 	"spaceofcheng/services/utils"
6 8
 	"testing"
9
+	"time"
7 10
 
8 11
 	. "github.com/smartystreets/goconvey/convey"
9 12
 )
10 13
 
11
-func TestGetCmsCaseList(t *testing.T) {
14
+func TestPreGoodsOrder(t *testing.T) {
12 15
 	Convey("商品下单", t, func() {
16
+
13 17
 		Convey("正常下单", func() {
14 18
 			params := url.Values{}
15 19
 			params.Add("info", `{"CaseId":"1","AreaId":"12","AreaName":"吧台","TableId":"28","TableNo":"城咖啡水吧台","Amount":"23","OrdersNum":1,"Remark":"","OrgId":"1","UserName":"奥利奥","PayType":"coupon"}`)
16 20
 			params.Add("detail", `[{"GoodsId":"61","GoodsName":"美式","SpecId":"40","SpecName":"去冰","Number":1,"Price":"23"}]`)
17 21
 
18
-			token, _ := utils.CreateToken(map[string]interface{}{})
22
+			result := &controllers.JSONMessage{}
23
+			api := "/api/wechat/MQ/order/goods"
24
+
25
+			token := &utils.JWTToken{
26
+				Guest:   false,
27
+				ID:      "oMOpz0kgTrasoAA3G70R7phomn1g", // openid
28
+				Expire:  time.Now().Local().Add(24 * 30 * time.Hour),
29
+				BatchNo: "",
30
+			}
31
+
32
+			code, _, err := NewRequestMock().
33
+				AddToken(token.ToMap()).
34
+				AddWechatUA().
35
+				Request(http.MethodPost, api, params, result)
19 36
 
20
-			wechatUA := "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12A365 MicroMessenger/5.4.1 NetType/WIFI"
37
+			So(code, ShouldEqual, http.StatusOK)
38
+			So(err, ShouldBeNil)
21 39
 
40
+			// 业务返回判断
41
+			So(result.Code, ShouldEqual, http.StatusOK)
42
+			So(result.Result, ShouldNotBeEmpty)
22 43
 		})
23 44
 	})
24 45
 }
46
+
47
+func TestConfirmOrders(t *testing.T) {
48
+	orderID := "cc84338e-488e-463b-a33e-7dc7f2cd10b6"
49
+
50
+	Convey("下单确认", t, func() {
51
+		result := &controllers.JSONMessage{}
52
+		api := "/api/wechat/MQ/order/goods/" + orderID
53
+
54
+		token := &utils.JWTToken{
55
+			Guest:   false,
56
+			ID:      "oMOpz0kgTrasoAA3G70R7phomn1g", // openid
57
+			Expire:  time.Now().Local().Add(24 * 30 * time.Hour),
58
+			BatchNo: "",
59
+		}
60
+
61
+		code, _, err := NewRequestMock().
62
+			AddToken(token.ToMap()).
63
+			AddWechatUA().
64
+			Request(http.MethodPut, api, nil, result)
65
+
66
+		So(code, ShouldEqual, http.StatusOK)
67
+		So(err, ShouldBeNil)
68
+
69
+		// 业务返回判断
70
+		So(result.Code, ShouldEqual, http.StatusOK)
71
+	})
72
+
73
+}

+ 0
- 2
tests/tests.go Näytä tiedosto

@@ -11,8 +11,6 @@ import (
11 11
 	"spaceofcheng/services/utils"
12 12
 	"testing"
13 13
 
14
-	_ "spaceofcheng/services/routers"
15
-
16 14
 	"github.com/astaxie/beego"
17 15
 	. "github.com/smartystreets/goconvey/convey"
18 16
 )

+ 1
- 1
tests/utils.go Näytä tiedosto

@@ -131,7 +131,7 @@ func (t *RequestMock) Request(meth, addr string, params interface{}, result inte
131 131
 	code = w.Code
132 132
 	body, _ = ioutil.ReadAll(w.Result().Body)
133 133
 
134
-	beego.Trace("testing", meth+" - "+addr, body)
134
+	beego.Trace("testing", meth+" - "+addr)
135 135
 
136 136
 	if result != nil {
137 137
 		err = json.Unmarshal(body, result)

+ 29
- 1
utils/utils.go Näytä tiedosto

@@ -6,6 +6,7 @@ import (
6 6
 	"net/http"
7 7
 	"os"
8 8
 	"path/filepath"
9
+	"runtime"
9 10
 	"strconv"
10 11
 	"strings"
11 12
 	"time"
@@ -159,8 +160,35 @@ func GetFiveSeconds(t time.Time) string {
159 160
 	return str[:strLen-1] + strconv.Itoa(lastNum)
160 161
 }
161 162
 
163
+// 当前运行环境
164
+var processEnv string
165
+var appRoot string
166
+
162 167
 // GetAppRoot 获取系统根目录
163 168
 func GetAppRoot() string {
164
-	appRoot, _ := filepath.Abs(filepath.Dir(os.Args[0]))
169
+	if appRoot != "" {
170
+		return appRoot
171
+	}
172
+
173
+	if processEnv == "" {
174
+		for _, arg := range os.Args {
175
+			if strings.Index(arg, "-test.run") > -1 {
176
+				processEnv = "test"
177
+				break
178
+			}
179
+		}
180
+
181
+		if processEnv == "" {
182
+			processEnv = "production"
183
+		}
184
+	}
185
+
186
+	if processEnv == "test" {
187
+		_, file, _, _ := runtime.Caller(1)
188
+		appRoot, _ = filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator))))
189
+	} else {
190
+		appRoot, _ = filepath.Abs(filepath.Dir(os.Args[0]))
191
+	}
192
+
165 193
 	return appRoot
166 194
 }