Browse Source

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

keyman1995 6 years ago
parent
commit
f486f9edbd

+ 1
- 1
.gitignore View File

@@ -2,4 +2,4 @@
2 2
 *.exe~
3 3
 *.test
4 4
 *.log
5
-common.log
5
+log

+ 1
- 1
conf/db.conf View File

@@ -6,7 +6,7 @@ con_protocol = tcp
6 6
 
7 7
 ; 数据库地址,可以使用IP
8 8
 # db_addr      = 192.168.0.122
9
-db_addr      = 192.168.0.122
9
+db_addr      = localhost
10 10
 
11 11
 ; 端口
12 12
 db_port      = 3306

+ 12
- 0
controllers/card/card.go View File

@@ -198,3 +198,15 @@ func (c *CardController) GetCustomerCardByID() {
198 198
 
199 199
 	c.ResponseJSON(card)
200 200
 }
201
+
202
+// GetCaseUsableCard 获取案场可用券
203
+func (c *CardController) GetCaseUsableCard() {
204
+	page, _ := c.GetInt("page")
205
+	pageSize, _ := c.GetInt("pagesize")
206
+	cards, err := c.serv.GetCaseUsableCard(page, pageSize)
207
+	if err != nil {
208
+		c.ResponseError(err)
209
+	}
210
+
211
+	c.ResponseJSON(cards)
212
+}

+ 12
- 0
controllers/coupon/coupon.go View File

@@ -210,3 +210,15 @@ func (c *CouponController) GetCustomerCouponByID() {
210 210
 
211 211
 	c.ResponseJSON(coupon)
212 212
 }
213
+
214
+// GetCaseUsableCoupon 获取案场可用券
215
+func (c *CouponController) GetCaseUsableCoupon() {
216
+	page, _ := c.GetInt("page")
217
+	pageSize, _ := c.GetInt("pagesize")
218
+	coupons, err := c.serv.GetCaseUsableCoupon(page, pageSize)
219
+	if err != nil {
220
+		c.ResponseError(err)
221
+	}
222
+
223
+	c.ResponseJSON(coupons)
224
+}

+ 55
- 78
controllers/goods/order.go View File

@@ -9,9 +9,6 @@ import (
9 9
 	"spaceofcheng/services/utils"
10 10
 	"strconv"
11 11
 	"time"
12
-
13
-	"github.com/astaxie/beego"
14
-	"github.com/tealeg/xlsx"
15 12
 )
16 13
 
17 14
 // GetOrderList 获取商品订单
@@ -154,94 +151,74 @@ func (c *GoodsController) GetOrdersByRecord() {
154 151
 		c.ResponseError(err)
155 152
 	}
156 153
 
157
-	file := xlsx.NewFile()
158
-	sheet, _ := file.AddSheet("Sheet1")
159
-	row := sheet.AddRow()
160
-	row.SetHeightCM(0.8) //设置每行的高度
161
-	cell := row.AddCell()
162
-	cell.Value = "归属案场"
163
-	cell = row.AddCell()
164
-	cell.Value = "商品分类"
165
-	cell = row.AddCell()
166
-	cell.Value = "商品名称"
167
-	cell = row.AddCell()
168
-	cell.Value = "商品规格"
169
-	cell = row.AddCell()
170
-	cell.Value = "下单人"
171
-	cell = row.AddCell()
172
-	cell.Value = "销售数量"
173
-	cell = row.AddCell()
174
-	cell.Value = "商品单价"
175
-	cell = row.AddCell()
176
-	cell.Value = "商品总价"
177
-	cell = row.AddCell()
178
-	cell.Value = "订单状态"
179
-	cell = row.AddCell()
180
-	cell.Value = "下单时间"
181
-	cell = row.AddCell()
182
-	cell.Value = "订单号"
154
+	excel, err := utils.NewTinyXLSXEngine()
155
+	if err != nil {
156
+		utils.LogError("初始化Excel服务失败: " + err.Error())
157
+		c.ResponseError(errors.New("初始化Excel服务失败"))
158
+	}
159
+
160
+	excel.SetCell(excel.InsertRow(), []string{
161
+		"归属案场",
162
+		"商品分类",
163
+		"商品名称",
164
+		"商品规格",
165
+		"下单人",
166
+		"销售数量",
167
+		"商品单价",
168
+		"商品总价",
169
+		"订单状态",
170
+		"下单时间",
171
+		"订单号",
172
+	})
173
+
183 174
 	var amount float64
184
-	amount = 0
185 175
 	for _, order := range orders {
186 176
 		for _, good := range order.Goods {
187
-			row := sheet.AddRow()
188
-			row.SetHeightCM(0.8) //设置每行的高度
189
-			cell := row.AddCell()
190
-			cell.Value = order.CaseName
191
-			cell = row.AddCell()
192
-			cell.Value = good.TypeName
193
-			cell = row.AddCell()
194
-			cell.Value = good.GoodsName
195
-			cell = row.AddCell()
196
-			cell.Value = good.SpecName
197
-			cell = row.AddCell()
198
-			cell.Value = order.UserName
199
-			cell = row.AddCell()
200
-			cell.Value = strconv.Itoa(good.Number)
201
-			cell = row.AddCell()
202
-			cell.Value = good.Price
203
-			cell = row.AddCell()
177
+			row := excel.InsertRow()
178
+			excel.SetCell(row, []string{
179
+				order.CaseName,
180
+				good.TypeName,
181
+				good.GoodsName,
182
+				good.SpecName,
183
+				order.UserName,
184
+				strconv.Itoa(good.Number),
185
+				good.Price,
186
+				strconv.Itoa(good.Number),
187
+			})
188
+
204 189
 			price, err := strconv.ParseFloat(good.Price, 64)
205 190
 			if err != nil {
206 191
 				c.ResponseError(errors.New("金额类型不正确!"))
207 192
 			}
208
-			num, err := strconv.ParseFloat(strconv.Itoa(good.Number), 64)
209
-			if err != nil {
210
-				c.ResponseError(errors.New("金额类型不正确!"))
211
-			}
212
-			amount = amount + price*num
213
-			cell.Value = strconv.FormatFloat(price*num, 'f', -1, 64)
214
-			cell = row.AddCell()
215
-			var status = "未完成"
193
+			// num, err := strconv.ParseFloat(strconv.Itoa(good.Number), 64)
194
+			// if err != nil {
195
+			// 	c.ResponseError(errors.New("金额类型不正确!"))
196
+			// }
197
+			charge := price * float64(good.Number)
198
+			amount = amount + charge
199
+
200
+			excel.SetCell(row, strconv.FormatFloat(charge, 'f', -1, 64))
201
+
202
+			status := "未完成"
216 203
 			if order.Status == models.STATUS_NORMAL {
217 204
 				status = "已完成"
218 205
 			}
219
-			cell.Value = status
220
-			cell = row.AddCell()
221
-			cell.Value = order.CreateDate.Format("2006-01-02 15:04:05")
222
-			cell = row.AddCell()
223
-			cell.Value = order.OrdersNo
206
+			excel.SetCell(row, status)
207
+			excel.SetCell(row, order.CreateDate.Format("2006-01-02 15:04:05"))
208
+			excel.SetCell(row, order.OrdersNo)
224 209
 		}
225 210
 	}
226
-	row = sheet.AddRow()
227
-	row.SetHeightCM(0.8)
228
-	cell = row.AddCell()
229
-	cell.Value = "总规定次数"
230
-	cell = row.AddCell()
231
-	cell.Value = strconv.Itoa(record.Num)
232
-	cell = row.AddCell()
233
-	cell.Value = "实际使用总数"
234
-	cell = row.AddCell()
235
-	cell.Value = strconv.Itoa(record.ActrualNum)
236
-	cell = row.AddCell()
237
-	cell.Value = "总价"
238
-	cell = row.AddCell()
239
-	cell.Value = strconv.FormatFloat(amount, 'f', -1, 64)
240
-
241
-	excelpath := beego.AppConfig.String("excelpath") + utils.GetGUID() + ".xlsx"
242
-	err = file.Save(excelpath)
243 211
 
244
-	c.ResponseJSON(orders)
212
+	excel.SetCell(excel.InsertRow(), []string{
213
+		"总规定次数",
214
+		strconv.Itoa(record.Num),
215
+		"实际使用总数",
216
+		strconv.Itoa(record.ActrualNum),
217
+		"总价",
218
+		strconv.FormatFloat(amount, 'f', -1, 64),
219
+	})
220
+
221
+	c.SaveToExcel("订单月记录.xlsx", excel)
245 222
 }
246 223
 
247 224
 // GetCustomerOrders 获取用户订单

+ 11
- 0
log/common.log View File

@@ -0,0 +1,11 @@
1
+2018/09/14 16:15:08 [E] 获取发送卡信息失败: Error 1054: Unknown column 'serial_code' in 'field list'
2
+2018/09/14 16:15:08 [E] 获取人员信息失败: 获取人员信息失败
3
+2018/09/14 16:20:29 [E] 获取发送卡信息失败: Error 1054: Unknown column 'serial_code' in 'field list'
4
+2018/09/14 16:20:29 [E] 获取人员信息失败: 获取人员信息失败
5
+2018/09/14 16:21:28 [E] 获取发送卡信息失败: Error 1054: Unknown column 'serial_code' in 'field list'
6
+2018/09/14 16:21:28 [E] 获取人员信息失败: 获取人员信息失败
7
+2018/09/14 17:38:13 [E] 获取用户信息失败: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM
8
+			sys_user t
9
+		JOIN sys_user_type s ON t.user_id = s.user_id
10
+		JOIN td_use' at line 4
11
+2018/09/14 18:49:55 [E] 解析 Token 失败: token contains an invalid number of segments

+ 15
- 4
models/card/card.go View File

@@ -10,6 +10,8 @@ import (
10 10
 	"strings"
11 11
 	"time"
12 12
 
13
+	"github.com/astaxie/beego"
14
+
13 15
 	"github.com/go-xorm/xorm"
14 16
 	"github.com/yl10/kit/guid"
15 17
 )
@@ -108,7 +110,7 @@ func (m *CardDAO) AddCard(card *model.TaCouponCard) error {
108 110
 	return nil
109 111
 }
110 112
 
111
-// UpdateCard 更新优惠券
113
+// UpdateCard 更新体验卡
112 114
 func (m *CardDAO) UpdateCard(card *model.TaCouponCard, cols []string) error {
113 115
 	if card.CardId == "" {
114 116
 		return errors.New("无卡信息")
@@ -222,6 +224,7 @@ type CaseUsableCard struct {
222 224
 func (m *CardDAO) GetCaseUsableCard(caseid, userid string, page, pageSize int) ([]CaseUsableCard, error) {
223 225
 	var cards []CaseUsableCard
224 226
 	sql := `select * from ta_coupon_card where case_id=? and status=? and end_date>now() order by create_date limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
227
+	beego.Error(sql)
225 228
 	err := m.db.Sql(sql, caseid, models.STATUS_NORMAL).Find(&cards)
226 229
 	if userid != "" {
227 230
 		for inx, card := range cards {
@@ -235,6 +238,14 @@ func (m *CardDAO) GetCaseUsableCard(caseid, userid string, page, pageSize int) (
235 238
 	return cards, err
236 239
 }
237 240
 
241
+// GetCaseUsableCardCount 获取案场可用卡数量
242
+func (m *CardDAO) GetCaseUsableCardCount(caseid, userid string) (int, error) {
243
+	var Coupons []CaseUsableCard
244
+	sql := `select * from ta_coupon_card where case_id=? and status=? and end_date>now()`
245
+	err := m.db.Sql(sql, caseid, models.STATUS_NORMAL).Find(&Coupons)
246
+	return len(Coupons), err
247
+}
248
+
238 249
 // GetCustomerCardByCardAndUser 根据卡与用户获取领取的用户信息
239 250
 func (m *CardDAO) GetCustomerCardByCardAndUser(cardid, userid string) ([]model.TaCustomerCard, error) {
240 251
 	var customerCards []model.TaCustomerCard
@@ -275,7 +286,7 @@ func (m *CardDAO) GetCustomerCardByUser(caseid, userid string) ([]model.TaCustom
275 286
 	return customerCards, err
276 287
 }
277 288
 
278
-// GetCardWithCustomer 获取优惠券明细
289
+// GetCardWithCustomer 获取体验卡明细
279 290
 func (m *CardDAO) GetCardWithCustomer(cardid string) (*CaseUsableCard, error) {
280 291
 	var card = new(CaseUsableCard)
281 292
 	sql := `select * from ta_card where coupin_id=?`
@@ -284,7 +295,7 @@ func (m *CardDAO) GetCardWithCustomer(cardid string) (*CaseUsableCard, error) {
284 295
 		return nil, err
285 296
 	}
286 297
 	if card == nil || card.CardId == "" {
287
-		return nil, errors.New("无优惠券信息")
298
+		return nil, errors.New("无体验卡信息")
288 299
 	}
289 300
 	var customerCopons []model.TaCustomerCard
290 301
 	sql = `select * from ta_customer_card where card_id = ? and status>?`
@@ -324,7 +335,7 @@ func (m *CardDAO) GetCardByCustomer(orgid, customerid string) ([]CustomerCardWit
324 335
 // GetCustomerCardByID 获取我的体验卡详情
325 336
 func (m *CardDAO) GetCustomerCardByID(id string) (*CustomerCardWithShare, error) {
326 337
 	if id == "" {
327
-		return nil, errors.New("无优惠券信息")
338
+		return nil, errors.New("无体验卡信息")
328 339
 	}
329 340
 	var customerCard = new(CustomerCardWithShare)
330 341
 	sql := `select * from ta_customer_card where status>? and customer_card_id=?`

+ 14
- 0
models/coupon/coupon.go View File

@@ -305,6 +305,15 @@ func (m *CouponDAO) GetCaseUsableCoupon(caseid, userid string, page, pageSize in
305 305
 	return Coupons, err
306 306
 }
307 307
 
308
+// GetCaseUsableCouponCount 获取案场可用优惠券数量
309
+func (m *CouponDAO) GetCaseUsableCouponCount(caseid, userid string) (int, error) {
310
+	var Coupons []CaseCouponDetail
311
+	sql := `select * from ta_coupon where case_id=? and status=? and end_date>now()`
312
+	err := m.db.Sql(sql, caseid, models.STATUS_NORMAL).Find(&Coupons)
313
+
314
+	return len(Coupons), err
315
+}
316
+
308 317
 // GetCustomerCouponByCouponAndUser 根据优惠券与用户获取领取的用户信息
309 318
 func (m *CouponDAO) GetCustomerCouponByCouponAndUser(couponid, userid string) ([]model.TaCustomerCoupon, error) {
310 319
 	var customerCoupons []model.TaCustomerCoupon
@@ -450,3 +459,8 @@ func (m *CouponDAO) VerifyCustomerCoupon(id string) error {
450 459
 	_, err := m.db.Cols(cols...).Where("customer_coupon_id=?", id).Update(customerCoupon)
451 460
 	return err
452 461
 }
462
+
463
+// ReceiveCoupon 领取优惠券
464
+func (m *CouponDAO) ReceiveCoupon(couponid string) {
465
+
466
+}

+ 1
- 0
models/model/ta_customer_card.go View File

@@ -19,4 +19,5 @@ type TaCustomerCard struct {
19 19
 	CaseId           string    `xorm:"VARCHAR(64)"`
20 20
 	OrgId            string    `xorm:"VARCHAR(64)"`
21 21
 	VerifyStatus     string    `xorm:"VARCHAR(32)"`
22
+	SerialCode       string    `xorm:"VARCHAR(64)"`
22 23
 }

+ 1
- 0
models/model/ta_customer_coupon.go View File

@@ -18,4 +18,5 @@ type TaCustomerCoupon struct {
18 18
 	UseDate            time.Time `xorm:"DATETIME"`
19 19
 	CaseId             string    `xorm:"VARCHAR(64)"`
20 20
 	OrgId              string    `xorm:"VARCHAR(64)"`
21
+	SerialCode         string    `xorm:"VARCHAR(64)"`
21 22
 }

+ 1
- 3
models/system/user.go View File

@@ -405,7 +405,6 @@ type UserWithType struct {
405 405
 	model.SysUser `xorm:"extends"`
406 406
 	TypeId        string
407 407
 	TypeName      string
408
-	CaseId        string
409 408
 }
410 409
 
411 410
 // GetUserWithTypeByID 获取用户类型
@@ -413,8 +412,7 @@ func (m *UserDAO) GetUserWithTypeByID(userID string) ([]UserWithType, error) {
413 412
 	query := `
414 413
 		SELECT
415 414
 			t.*, m.type_id,
416
-			m.type_name,
417
-			m.case_id
415
+			m.type_name
418 416
 		FROM
419 417
 			sys_user t
420 418
 		JOIN sys_user_type s ON t.user_id = s.user_id

+ 2
- 0
routers/wechat.go View File

@@ -53,10 +53,12 @@ func getWechatRoutes() beego.LinkNamespace {
53 53
 		beego.NSRouter("/user/detail/:id", &user.UserController{}, "get:GetCaseUserByID"),
54 54
 
55 55
 		// 优惠券
56
+		beego.NSRouter("/coupon", &coupon.CouponController{}, "get:GetCaseUsableCoupon"),
56 57
 		beego.NSRouter("/coupon/:id", &coupon.CouponController{}, "get:GetCouponByID"),
57 58
 		beego.NSRouter("/coupon/detail/:id", &coupon.CouponController{}, "get:GetCouponWithCustomer"),
58 59
 
59 60
 		// 卡
61
+		beego.NSRouter("/card", &card.CardController{}, "get:GetCaseUsableCard"),
60 62
 		beego.NSRouter("/card/:id", &card.CardController{}, "get:GetCardByID"),
61 63
 		beego.NSRouter("/card/detail/:id", &card.CardController{}, "get:GetCardWithCustomer"),
62 64
 	)

+ 58
- 8
service/card/card.go View File

@@ -6,6 +6,8 @@ import (
6 6
 	"spaceofcheng/services/models/card"
7 7
 	"spaceofcheng/services/models/customer"
8 8
 	"spaceofcheng/services/models/model"
9
+	"spaceofcheng/services/models/system"
10
+	"spaceofcheng/services/service"
9 11
 	"spaceofcheng/services/utils"
10 12
 	"strings"
11 13
 	"time"
@@ -18,6 +20,7 @@ type CardServ struct {
18 20
 	ctx     *utils.Context
19 21
 	dao     *card.CardDAO
20 22
 	custDao *customer.CustomerDAO
23
+	userDao *system.UserDAO
21 24
 }
22 25
 
23 26
 // NewCardServ 初始化
@@ -26,6 +29,7 @@ func NewCardServ(ctx *utils.Context) *CardServ {
26 29
 		ctx:     ctx,
27 30
 		dao:     card.NewCardDAO(ctx),
28 31
 		custDao: customer.NewCustomerDAO(ctx),
32
+		userDao: system.NewUserDAO(ctx),
29 33
 	}
30 34
 }
31 35
 
@@ -214,15 +218,15 @@ func (s *CardServ) GiveCardTo(from *model.SysUser, to *model.TaCustomer, card *c
214 218
 	endDate := card.EndDate
215 219
 
216 220
 	// 检查用户是否已经有了该券
217
-	custcardS, err := s.dao.CheckCustCard(to.CustomerId, card.CardId, startDate, endDate)
218
-	if err != nil {
219
-		utils.LogError("校验客户卡失败: " + err.Error())
220
-		return errors.New("校验客户卡失败")
221
-	}
221
+	// custcardS, err := s.dao.CheckCustCard(to.CustomerId, card.CardId, startDate, endDate)
222
+	// if err != nil {
223
+	// 	utils.LogError("校验客户卡失败: " + err.Error())
224
+	// 	return errors.New("校验客户卡失败")
225
+	// }
222 226
 
223
-	if custcardS != nil && len(custcardS) > 0 {
224
-		return errors.New("客户 " + to.CustomerName + " 已经拥有该券")
225
-	}
227
+	// if custcardS != nil && len(custcardS) > 0 {
228
+	// 	return errors.New("客户 " + to.CustomerName + " 已经拥有该券")
229
+	// }
226 230
 
227 231
 	// 放入我的卡券
228 232
 	custcard := model.TaCustomerCard{
@@ -309,3 +313,49 @@ func (s *CardServ) GetCustomerCardByID(id string) (*card.CustomerCardWithShare,
309 313
 	}
310 314
 	return card, nil
311 315
 }
316
+
317
+// GetCaseUsableCard 获取案场可用卡
318
+func (s *CardServ) GetCaseUsableCard(page, pageSize int) (map[string]interface{}, error) {
319
+
320
+	if pageSize == 0 {
321
+		pageSize = service.PAGENUM
322
+	}
323
+	if page == 0 {
324
+		page = 1
325
+	}
326
+	customer := s.ctx.Get("customer").(model.TaCustomer)
327
+	if customer.UserId == "" {
328
+		return nil, errors.New("您没有权限查看数据")
329
+	}
330
+	userTypes, err := s.userDao.GetUserWithTypeByID(customer.UserId)
331
+	if err != nil {
332
+		utils.LogError("获取用户信息失败: " + err.Error())
333
+		return nil, errors.New("获取用户信息失败")
334
+	}
335
+	if len(userTypes) == 0 {
336
+		return nil, errors.New("您没有权限查看数据")
337
+	}
338
+	caseinfo, err := s.userDao.GetUserBelongCase(customer.UserId)
339
+	if err != nil {
340
+		return nil, errors.New("您没有案场信息!")
341
+	}
342
+	var userid = ""
343
+	if userTypes[0].TypeId != models.USERTYPE_MANAGER {
344
+		userid = customer.UserId
345
+	}
346
+	coupons, err := s.dao.GetCaseUsableCard(caseinfo.CaseId, userid, page, pageSize)
347
+	if err != nil {
348
+		return nil, errors.New("获取数据失败!")
349
+	}
350
+	total, err := s.dao.GetCaseUsableCardCount(caseinfo.CaseId, userid)
351
+	if err != nil {
352
+		utils.LogError("获取商品规格失败: " + err.Error())
353
+		return nil, errors.New("获取商品规格失败")
354
+	}
355
+	return map[string]interface{}{
356
+		"list":     coupons,
357
+		"pagesize": pageSize,
358
+		"pagenum":  total,
359
+		"page":     page,
360
+	}, nil
361
+}

+ 58
- 12
service/coupon/coupon.go View File

@@ -6,12 +6,12 @@ import (
6 6
 	"spaceofcheng/services/models/coupon"
7 7
 	"spaceofcheng/services/models/customer"
8 8
 	"spaceofcheng/services/models/model"
9
+	"spaceofcheng/services/models/system"
10
+	"spaceofcheng/services/service"
9 11
 	"spaceofcheng/services/utils"
10 12
 	"strings"
11 13
 	"time"
12 14
 
13
-	"github.com/astaxie/beego"
14
-
15 15
 	"github.com/yl10/kit/guid"
16 16
 )
17 17
 
@@ -20,6 +20,7 @@ type CouponServ struct {
20 20
 	ctx     *utils.Context
21 21
 	dao     *coupon.CouponDAO
22 22
 	custDao *customer.CustomerDAO
23
+	userDao *system.UserDAO
23 24
 }
24 25
 
25 26
 // NewCouponServ 初始化
@@ -28,6 +29,7 @@ func NewCouponServ(ctx *utils.Context) *CouponServ {
28 29
 		ctx:     ctx,
29 30
 		dao:     coupon.NewCouponDAO(ctx),
30 31
 		custDao: customer.NewCustomerDAO(ctx),
32
+		userDao: system.NewUserDAO(ctx),
31 33
 	}
32 34
 }
33 35
 
@@ -269,15 +271,15 @@ func (s *CouponServ) GiveCouponTo(from *model.SysUser, to *model.TaCustomer, cp
269 271
 	}
270 272
 
271 273
 	// 检查用户是否已经有了该券
272
-	custCPS, err := s.dao.CheckCustCoupon(to.CustomerId, cp.CouponId, startDate, endDate)
273
-	if err != nil {
274
-		utils.LogError("校验客户优惠券失败: " + err.Error())
275
-		return errors.New("校验客户优惠券失败")
276
-	}
277
-	beego.Error(custCPS)
278
-	if custCPS != nil && len(custCPS) > 0 {
279
-		return errors.New("客户 " + to.CustomerName + " 已经拥有该券")
280
-	}
274
+	// custCPS, err := s.dao.CheckCustCoupon(to.CustomerId, cp.CouponId, startDate, endDate)
275
+	// if err != nil {
276
+	// 	utils.LogError("校验客户优惠券失败: " + err.Error())
277
+	// 	return errors.New("校验客户优惠券失败")
278
+	// }
279
+	// beego.Error(custCPS)
280
+	// if custCPS != nil && len(custCPS) > 0 {
281
+	// 	return errors.New("客户 " + to.CustomerName + " 已经拥有该券")
282
+	// }
281 283
 
282 284
 	// 放入我的卡券
283 285
 	custCP := model.TaCustomerCoupon{
@@ -404,4 +406,48 @@ func (s *CouponServ) GetCustomerCouponByID(id string) (*coupon.CustomerCouponWit
404 406
 	return coupon, nil
405 407
 }
406 408
 
407
-//
409
+// GetCaseUsableCoupon 获取案场可用券
410
+func (s *CouponServ) GetCaseUsableCoupon(page, pageSize int) (map[string]interface{}, error) {
411
+
412
+	if pageSize == 0 {
413
+		pageSize = service.PAGENUM
414
+	}
415
+	if page == 0 {
416
+		page = 1
417
+	}
418
+	customer := s.ctx.Get("customer").(model.TaCustomer)
419
+	if customer.UserId == "" {
420
+		return nil, errors.New("您没有权限查看数据")
421
+	}
422
+	userTypes, err := s.userDao.GetUserWithTypeByID(customer.UserId)
423
+	if err != nil {
424
+		utils.LogError("获取用户信息失败: " + err.Error())
425
+		return nil, errors.New("获取用户信息失败")
426
+	}
427
+	if len(userTypes) > 0 {
428
+		return nil, errors.New("您没有权限查看数据")
429
+	}
430
+	caseinfo, err := s.userDao.GetUserBelongCase(customer.UserId)
431
+	if err != nil {
432
+		return nil, errors.New("您没有案场信息!")
433
+	}
434
+	var userid = ""
435
+	if userTypes[0].TypeId != models.USERTYPE_MANAGER {
436
+		userid = customer.UserId
437
+	}
438
+	coupons, err := s.dao.GetCaseUsableCoupon(caseinfo.CaseId, userid, page, pageSize)
439
+	if err != nil {
440
+		return nil, errors.New("获取数据失败!")
441
+	}
442
+	total, err := s.dao.GetCaseUsableCouponCount(caseinfo.CaseId, userid)
443
+	if err != nil {
444
+		utils.LogError("获取商品规格失败: " + err.Error())
445
+		return nil, errors.New("获取商品规格失败")
446
+	}
447
+	return map[string]interface{}{
448
+		"list":     coupons,
449
+		"pagesize": pageSize,
450
+		"pagenum":  total,
451
+		"page":     page,
452
+	}, nil
453
+}

+ 8
- 7
service/goods/orders.go View File

@@ -284,15 +284,16 @@ func (s *GoodsServ) validOrdersInfo(info *model.TaGoodsOrders) error {
284 284
 					return errors.New("下单人状态不正确, 不能下单")
285 285
 				}
286 286
 
287
-				if ut.CaseId == caseID {
288
-					info.UserType = ut.TypeId
287
+				info.UserType = ut.TypeId
289 288
 
290
-					// 下单人姓名 - 姓名不存在则用昵称
291
-					info.UserName = ut.RealName
292
-					if info.UserName == "" {
293
-						info.UserName = cust.CustomerName
294
-					}
289
+				// 下单人姓名 - 姓名不存在则用昵称
290
+				info.UserName = ut.RealName
291
+				if info.UserName == "" {
292
+					info.UserName = cust.CustomerName
295 293
 				}
294
+				// if ut.CaseId == caseID {
295
+
296
+				// }
296 297
 			}
297 298
 		}
298 299