Quellcode durchsuchen

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

wangfei vor 6 Jahren
Ursprung
Commit
18f07f24b1

+ 2
- 3
conf/db.conf Datei anzeigen

@@ -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 Datei anzeigen

@@ -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"

+ 9
- 0
controllers/customerremark/customerremark.go Datei anzeigen

@@ -55,6 +55,15 @@ func (c *CustomerRemarkController) AddRemark() {
55 55
 	c.ResponseJSON(newRemark)
56 56
 }
57 57
 
58
+func (c *CustomerRemarkController) IsExist() {
59
+	recommendCode := c.GetString(":recommendCode")
60
+	num, err := c.dao.IsExist(recommendCode)
61
+	if err != nil {
62
+		c.ResponseError(err)
63
+	}
64
+	c.ResponseJSON(num)
65
+}
66
+
58 67
 func (c *CustomerRemarkController) SearchCustomer() {
59 68
 	salesId := c.GetString(":salesId")
60 69
 	customerInfo := c.GetString(":customerInfo")

+ 8
- 0
controllers/flashbuy/flashbuy.go Datei anzeigen

@@ -136,3 +136,11 @@ func (c *FlashBuyController) FlashBuy() {
136 136
 	}
137 137
 	c.ResponseJSON("恭喜您!抢购成功!")
138 138
 }
139
+
140
+func (c *FlashBuyController) GetFlashModelList() {
141
+	model, err := c.dao.GetFlashModelList()
142
+	if err != nil {
143
+		c.ResponseError(err)
144
+	}
145
+	c.ResponseJSON(model)
146
+}

+ 1
- 1
models/customer/customer.go Datei anzeigen

@@ -282,7 +282,7 @@ func (m *CustomerDAO) GetSalesByRecommendCode(recommendCode string) (*model.SysU
282 282
 
283 283
 func (m *CustomerDAO) GetSalesCaseById(userId string) (*model.SysUserCase, error) {
284 284
 	userCase := new(model.SysUserCase)
285
-	if _, err := m.db.Where("user_id = ?", userId).Get(&userCase); err != nil {
285
+	if _, err := m.db.Where("user_id = ?", userId).Get(userCase); err != nil {
286 286
 		return nil, err
287 287
 	}
288 288
 	return userCase, nil

+ 5
- 0
models/customer/vip.go Datei anzeigen

@@ -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)

+ 8
- 0
models/customerremark/customerremark.go Datei anzeigen

@@ -128,3 +128,11 @@ FROM
128 128
 	return len(customerReceive), err
129 129
 
130 130
 }
131
+
132
+func (m *CustomerRemarkDAO) IsExist(recommendCode string) (int, error) {
133
+	var user []model.SysUser
134
+	sql := `select * from sys_user where recommend_code = '` + recommendCode + `' 
135
+	and status > ` + strconv.Itoa(models.STATUS_DEL)
136
+	err := m.db.Sql(sql).Find(&user)
137
+	return len(user), err
138
+}

+ 7
- 0
models/flashbuy/flashbuy.go Datei anzeigen

@@ -275,3 +275,10 @@ func (m *FlashbuyDAO) SaveCustomerFlashBuy(cstFlashBuy model.TaCustomerFlashBuy)
275 275
 	_, err := m.db.Insert(cstFlashBuy)
276 276
 	return &cstFlashBuy, err
277 277
 }
278
+
279
+func (m *FlashbuyDAO) GetFlashModelList() ([]model.TdFlashbuyModel, error) {
280
+	var model []model.TdFlashbuyModel
281
+	sql := `select * from td_flashbuy_model`
282
+	err := m.db.Sql(sql).Find(&model)
283
+	return model, err
284
+}

+ 2
- 2
models/goods/types.go Datei anzeigen

@@ -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 Datei anzeigen

@@ -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
routers/common.go Datei anzeigen

@@ -333,5 +333,6 @@ func getCommonRoutes(prefix string) beego.LinkNamespace {
333 333
 		beego.NSRouter("/flashbuy/:flashBuyId/:flashBuyStatus", &flashbuy.FlashBuyController{}, "put:UpdateFlashBuy"),
334 334
 		beego.NSRouter("/flashbuy/:qrcode", &flashbuy.FlashBuyController{}, "get:VerifyCustomerFlashBuyList"),
335 335
 		beego.NSRouter("/flashbuy/:customerFlashBuyId", &flashbuy.FlashBuyController{}, "put:Verify"),
336
+		beego.NSRouter("/flashbuy/model", &flashbuy.FlashBuyController{}, "get:GetFlashModelList"),
336 337
 	)
337 338
 }

+ 3
- 0
routers/guest.go Datei anzeigen

@@ -6,6 +6,7 @@ import (
6 6
 	"spaceofcheng/services/controllers/cases"
7 7
 	"spaceofcheng/services/controllers/course"
8 8
 	"spaceofcheng/services/controllers/customer"
9
+	"spaceofcheng/services/controllers/customerremark"
9 10
 	"spaceofcheng/services/controllers/goods"
10 11
 	"spaceofcheng/services/controllers/message"
11 12
 	"spaceofcheng/services/controllers/user"
@@ -66,5 +67,7 @@ func getGuestRoutes(prefix string) beego.LinkNamespace {
66 67
 		beego.NSRouter("/case/checkin", &cases.SigninController{}, "post:AddSignin"),
67 68
 		beego.NSRouter("/wechat", &controllers.WechatController{}, "get,post:WechatInfo"),
68 69
 		// beego.NSRouter("/wechat", &controllers.WechatController{}, "post:WxReceive"),
70
+
71
+		beego.NSRouter("/customerremark/:recommendCode", &customerremark.CustomerRemarkController{}, "get:IsExist"),
69 72
 	)
70 73
 }

+ 4
- 4
routers/wechat.go Datei anzeigen

@@ -95,15 +95,15 @@ func getWechatRoutes(prefix string) beego.LinkNamespace {
95 95
 		beego.NSRouter("/user/luckdraw/record/:id", &luckdraw.LuckDrawController{}, "get:GetRecordByID"),
96 96
 
97 97
 		// 抢购
98
-		beego.NSRouter("/flashbuy/:flashBuyId", &flashbuy.FlashBuyController{}, "get:GetFlashBuyById"),
99
-		beego.NSRouter("/flashbuy/:customerId", &flashbuy.FlashBuyController{}, "get:GetCustomerFlashBuyByCustomerId"),
100
-		beego.NSRouter("/flashbuy/:customerFlashBuyId", &flashbuy.FlashBuyController{}, "get:GetCustomerFlashBuyId"),
98
+		beego.NSRouter("/flashbuy/flash/:flashBuyId", &flashbuy.FlashBuyController{}, "get:GetFlashBuyById"),
99
+		beego.NSRouter("/flashbuy/customer/:customerId", &flashbuy.FlashBuyController{}, "get:GetCustomerFlashBuyByCustomerId"),
100
+		beego.NSRouter("/flashbuy/customerFlash/:customerFlashBuyId", &flashbuy.FlashBuyController{}, "get:GetCustomerFlashBuyId"),
101 101
 		beego.NSRouter("/flashbuy/:id", &flashbuy.FlashBuyController{}, "post:FlashBuy"),
102 102
 
103 103
 		// 客户备注
104 104
 		beego.NSRouter("/customerremark/record/:salesId/:customerId", &customerremark.CustomerRemarkController{}, "get:GetCustomerReceiveRecord"),
105 105
 		beego.NSRouter("/customerremark/:salesId/:customerId", &customerremark.CustomerRemarkController{}, "get:GetCustomerRemarkList"),
106
-		beego.NSRouter("/customerremark/:salesId/:customerInfo", &customerremark.CustomerRemarkController{}, "get:SearchCustomer"),
106
+		beego.NSRouter("/customerremark/search/:salesId/:customerInfo", &customerremark.CustomerRemarkController{}, "get:SearchCustomer"),
107 107
 		beego.NSRouter("/customerremark", &customerremark.CustomerRemarkController{}, "post:AddRemark"),
108 108
 	)
109 109
 }

+ 8
- 0
service/customerremark/customerremark.go Datei anzeigen

@@ -80,3 +80,11 @@ func (s *CustomerRemarkServ) SearchCustomer(customerInfo, salesId string) (*mode
80 80
 	}
81 81
 	return &customer, nil
82 82
 }
83
+func (s *CustomerRemarkServ) IsExist(recommendCode string) (int, error) {
84
+	num, err := s.dao.IsExist(recommendCode)
85
+	if err != nil {
86
+		utils.LogError("获取推荐人失败: " + err.Error())
87
+		return 0, errors.New("获取推荐人失败")
88
+	}
89
+	return num, nil
90
+}

+ 1
- 1
service/events/giveCard.go Datei anzeigen

@@ -56,7 +56,7 @@ var giveCard = func(e tinyevent.Event) error {
56 56
 		case ActGiveCoupon:
57 57
 			res := make(map[string]interface{})
58 58
 			if err := json.Unmarshal([]byte(act.ResourceDesc), &res); err != nil {
59
-				utils.LogError("解析优惠券赠送规则失败: " + err.Error())
59
+				utils.LogError("解析体验卡赠送规则失败: " + err.Error())
60 60
 				continue
61 61
 			}
62 62
 

+ 9
- 0
service/flashbuy/flashbuy.go Datei anzeigen

@@ -251,3 +251,12 @@ func (s *FlashBuyServ) FlashBuy(id string) error {
251 251
 
252 252
 	return nil
253 253
 }
254
+
255
+func (s *FlashBuyServ) GetFlashModelList() ([]model.TdFlashbuyModel, error) {
256
+	model, err := s.dao.GetFlashModelList()
257
+	if err != nil {
258
+		utils.LogError("获取抢购活动模板失败: " + err.Error())
259
+		return nil, errors.New("获取抢购活动模板失败")
260
+	}
261
+	return model, nil
262
+}

+ 1
- 0
service/goods/goods.go Datei anzeigen

@@ -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 Datei anzeigen

@@ -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)

+ 3
- 11
tests/cases_test.go Datei anzeigen

@@ -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 Datei anzeigen

@@ -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 Datei anzeigen

@@ -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 Datei anzeigen

@@ -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 Datei anzeigen

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