浏览代码

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

胡轶钦 6 年前
父节点
当前提交
d8325632db

+ 2
- 3
conf/db.conf 查看文件

5
 con_protocol = tcp
5
 con_protocol = tcp
6
 
6
 
7
 ; 数据库地址,可以使用IP
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
 # db_addr      = rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com
10
 # db_addr      = rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com
12
 
11
 
13
 ; 端口
12
 ; 端口

+ 1
- 1
conf/log.conf 查看文件

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

+ 2
- 1
controllers/luckdraw/luckdraw.go 查看文件

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

+ 5
- 0
models/customer/vip.go 查看文件

3
 import (
3
 import (
4
 	"spaceofcheng/services/models"
4
 	"spaceofcheng/services/models"
5
 	"spaceofcheng/services/models/model"
5
 	"spaceofcheng/services/models/model"
6
+	"time"
6
 )
7
 )
7
 
8
 
8
 // GetValidVIPCards 依据客户ID 获取 VIP 卡
9
 // GetValidVIPCards 依据客户ID 获取 VIP 卡
9
 // 按照过期时间升序, 即 将到期的在最上面
10
 // 按照过期时间升序, 即 将到期的在最上面
10
 // VIP 卡可以跨案场使用
11
 // VIP 卡可以跨案场使用
11
 func (m *CustomerDAO) GetValidVIPCards(custID string) (vips []model.TaCustomerVip, err error) {
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
 	err = m.db.Where("customer_id=?", custID).
15
 	err = m.db.Where("customer_id=?", custID).
13
 		And("status=?", models.STATUS_NORMAL).
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
 		And("balance>0").
19
 		And("balance>0").
15
 		Asc("end_date").
20
 		Asc("end_date").
16
 		Find(&vips)
21
 		Find(&vips)

+ 2
- 2
models/goods/types.go 查看文件

50
 // OrdersDetail 订单详情
50
 // OrdersDetail 订单详情
51
 type OrdersDetail struct {
51
 type OrdersDetail struct {
52
 	model.TaGoodsOrders `xorm:"extends"`
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 查看文件

214
 	change.ChangeId = utils.GetGUID()
214
 	change.ChangeId = utils.GetGUID()
215
 	change.Status = models.STATUS_NORMAL
215
 	change.Status = models.STATUS_NORMAL
216
 	change.CreateDate = time.Now()
216
 	change.CreateDate = time.Now()
217
+
217
 	_, err := m.db.Insert(change)
218
 	_, err := m.db.Insert(change)
218
 	return err
219
 	return err
219
 }
220
 }

+ 1
- 0
service/goods/goods.go 查看文件

34
 		custDAO:   customer.NewCustomerDAO(ctx),
34
 		custDAO:   customer.NewCustomerDAO(ctx),
35
 		userDAO:   system.NewUserDAO(ctx),
35
 		userDAO:   system.NewUserDAO(ctx),
36
 		couponDAO: coupon.NewCouponDAO(ctx),
36
 		couponDAO: coupon.NewCouponDAO(ctx),
37
+		vipDAO:    vipcard.NewVipcardDAO(ctx),
37
 	}
38
 	}
38
 }
39
 }
39
 
40
 

+ 1
- 0
service/goods/orders.go 查看文件

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

+ 5
- 5
service/luckdraw/luckdraw.go 查看文件

467
 }
467
 }
468
 
468
 
469
 // GetUserLuckDrawByLuckDraw 获取用户抽奖信息
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
 	if err != nil {
473
 	if err != nil {
474
 		utils.LogError("获取用户抽奖设置失败: " + err.Error())
474
 		utils.LogError("获取用户抽奖设置失败: " + err.Error())
475
-		return nil, errors.New("获取用户抽奖设置失败")
475
+		return nil, nil, errors.New("获取用户抽奖设置失败")
476
 	}
476
 	}
477
 	record, err := s.dao.GetUserLuckDrawByLuckDraw(user.CustomerId, luckdrawid)
477
 	record, err := s.dao.GetUserLuckDrawByLuckDraw(user.CustomerId, luckdrawid)
478
 	if err != nil {
478
 	if err != nil {
479
 		utils.LogError("获取用户的抽奖信息失败: " + err.Error())
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
 func (s *LuckdrawServ) GetDetailByRecord(recordid string) (*model.TaPrizeDetail, error) {
485
 func (s *LuckdrawServ) GetDetailByRecord(recordid string) (*model.TaPrizeDetail, error) {

+ 3
- 11
tests/cases_test.go 查看文件

12
 func TestGetCmsCaseList(t *testing.T) {
12
 func TestGetCmsCaseList(t *testing.T) {
13
 
13
 
14
 	Convey("获取案场列表", t, func() {
14
 	Convey("获取案场列表", t, func() {
15
-
16
 		Convey("正常业务", func() {
15
 		Convey("正常业务", func() {
17
 			params := url.Values{}
16
 			params := url.Values{}
18
 			params.Add("orgid", "1")
17
 			params.Add("orgid", "1")
26
 			So(err, ShouldBeNil)
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
 		Convey("机构不传报错", func() {
32
 		Convey("机构不传报错", func() {
45
 			So(err, ShouldBeNil)
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 查看文件

1
 package tests
1
 package tests
2
 
2
 
3
 import (
3
 import (
4
+	"net/http"
4
 	"net/url"
5
 	"net/url"
6
+	"spaceofcheng/services/controllers"
5
 	"spaceofcheng/services/utils"
7
 	"spaceofcheng/services/utils"
6
 	"testing"
8
 	"testing"
9
+	"time"
7
 
10
 
8
 	. "github.com/smartystreets/goconvey/convey"
11
 	. "github.com/smartystreets/goconvey/convey"
9
 )
12
 )
10
 
13
 
11
-func TestGetCmsCaseList(t *testing.T) {
14
+func TestPreGoodsOrder(t *testing.T) {
12
 	Convey("商品下单", t, func() {
15
 	Convey("商品下单", t, func() {
16
+
13
 		Convey("正常下单", func() {
17
 		Convey("正常下单", func() {
14
 			params := url.Values{}
18
 			params := url.Values{}
15
 			params.Add("info", `{"CaseId":"1","AreaId":"12","AreaName":"吧台","TableId":"28","TableNo":"城咖啡水吧台","Amount":"23","OrdersNum":1,"Remark":"","OrgId":"1","UserName":"奥利奥","PayType":"coupon"}`)
19
 			params.Add("info", `{"CaseId":"1","AreaId":"12","AreaName":"吧台","TableId":"28","TableNo":"城咖啡水吧台","Amount":"23","OrdersNum":1,"Remark":"","OrgId":"1","UserName":"奥利奥","PayType":"coupon"}`)
16
 			params.Add("detail", `[{"GoodsId":"61","GoodsName":"美式","SpecId":"40","SpecName":"去冰","Number":1,"Price":"23"}]`)
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 查看文件

11
 	"spaceofcheng/services/utils"
11
 	"spaceofcheng/services/utils"
12
 	"testing"
12
 	"testing"
13
 
13
 
14
-	_ "spaceofcheng/services/routers"
15
-
16
 	"github.com/astaxie/beego"
14
 	"github.com/astaxie/beego"
17
 	. "github.com/smartystreets/goconvey/convey"
15
 	. "github.com/smartystreets/goconvey/convey"
18
 )
16
 )

+ 1
- 1
tests/utils.go 查看文件

131
 	code = w.Code
131
 	code = w.Code
132
 	body, _ = ioutil.ReadAll(w.Result().Body)
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
 	if result != nil {
136
 	if result != nil {
137
 		err = json.Unmarshal(body, result)
137
 		err = json.Unmarshal(body, result)

+ 29
- 1
utils/utils.go 查看文件

6
 	"net/http"
6
 	"net/http"
7
 	"os"
7
 	"os"
8
 	"path/filepath"
8
 	"path/filepath"
9
+	"runtime"
9
 	"strconv"
10
 	"strconv"
10
 	"strings"
11
 	"strings"
11
 	"time"
12
 	"time"
159
 	return str[:strLen-1] + strconv.Itoa(lastNum)
160
 	return str[:strLen-1] + strconv.Itoa(lastNum)
160
 }
161
 }
161
 
162
 
163
+// 当前运行环境
164
+var processEnv string
165
+var appRoot string
166
+
162
 // GetAppRoot 获取系统根目录
167
 // GetAppRoot 获取系统根目录
163
 func GetAppRoot() string {
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
 	return appRoot
193
 	return appRoot
166
 }
194
 }