胡轶钦 6 년 전
부모
커밋
6d87011f3c
5개의 변경된 파일36개의 추가작업 그리고 11개의 파일을 삭제
  1. 16
    5
      controllers/flashbuy/flashbuy.go
  2. 12
    3
      models/customer/customer.go
  3. 5
    2
      models/flashbuy/flashbuy.go
  4. 1
    1
      routers/common.go
  5. 2
    0
      service/flashbuy/flashbuy.go

+ 16
- 5
controllers/flashbuy/flashbuy.go 파일 보기

@@ -1,9 +1,14 @@
1 1
 package flashbuy
2 2
 
3 3
 import (
4
+	"encoding/json"
5
+	"errors"
4 6
 	"spaceofcheng/services/controllers"
5 7
 	"spaceofcheng/services/models/model"
6 8
 	"spaceofcheng/services/service/flashbuy"
9
+	"spaceofcheng/services/utils"
10
+
11
+	"github.com/astaxie/beego"
7 12
 )
8 13
 
9 14
 // CaseController 信息
@@ -24,8 +29,9 @@ func (c *FlashBuyController) GetFlashBuyList() {
24 29
 		cases := c.Context.Get("cases").([]model.SysUserCase)
25 30
 		caseIDs = c.GetCaseIDs(cases)
26 31
 	}
27
-	flashBuyName := c.GetString("flashBuyName")
28
-	flashBuyStatus := c.GetString("flashBuyStatus")
32
+	flashBuyName := c.GetString("flashbuyname")
33
+	flashBuyStatus := c.GetString("flashbuystatus")
34
+	beego.Error(flashBuyStatus)
29 35
 	page, _ := c.GetInt("page")
30 36
 	pageSize, _ := c.GetInt("pagesize")
31 37
 	list, err := c.dao.GetFlashBuyList(caseIDs, flashBuyName, flashBuyStatus, page, pageSize)
@@ -78,11 +84,16 @@ func (c *FlashBuyController) GetCustomerFlashBuyId() {
78 84
 }
79 85
 
80 86
 func (c *FlashBuyController) SaveFlashBuy() {
81
-	flashbuy := model.TaFlashBuy{}
82
-	if err := c.ParseForm(&flashbuy); err != nil {
87
+	jsnStr := c.GetString("info")
88
+	if jsnStr == "" {
89
+		c.ResponseError(errors.New("未接收到保存内容"))
90
+	}
91
+	info := model.TaFlashBuy{}
92
+	if err := json.Unmarshal([]byte(jsnStr), &info); err != nil {
93
+		utils.LogError("抢购数据转换失败: " + err.Error())
83 94
 		c.ResponseError(err)
84 95
 	}
85
-	newFlashBuy, err := c.dao.SaveFlashBuy(flashbuy)
96
+	newFlashBuy, err := c.dao.SaveFlashBuy(info)
86 97
 	if err != nil {
87 98
 		c.ResponseError(err)
88 99
 	}

+ 12
- 3
models/customer/customer.go 파일 보기

@@ -5,6 +5,7 @@ import (
5 5
 	"spaceofcheng/services/models"
6 6
 	"spaceofcheng/services/models/model"
7 7
 	"spaceofcheng/services/utils"
8
+	"strconv"
8 9
 	"strings"
9 10
 	"time"
10 11
 
@@ -281,9 +282,17 @@ func (m *CustomerDAO) GetSalesByRecommendCode(recommendCode string) (*model.SysU
281 282
 }
282 283
 
283 284
 func (m *CustomerDAO) GetSalesCaseById(userId string) (*model.SysUserCase, error) {
284
-	userCase := new(model.SysUserCase)
285
-	if _, err := m.db.Where("user_id = ?", userId).Get(userCase); err != nil {
285
+	var userCase []model.SysUserCase
286
+	sql := `SELECT
287
+	* 
288
+FROM
289
+	sys_user_case 
290
+WHERE
291
+	is_belong = 1 
292
+	AND user_id = '` + userId + `'and status > ` + strconv.Itoa(models.STATUS_DEL)
293
+	err := m.db.Sql(sql).Find(&userCase)
294
+	if len(userCase) <= 0 {
286 295
 		return nil, err
287 296
 	}
288
-	return userCase, nil
297
+	return &userCase[0], err
289 298
 }

+ 5
- 2
models/flashbuy/flashbuy.go 파일 보기

@@ -8,6 +8,8 @@ import (
8 8
 	"strings"
9 9
 	"time"
10 10
 
11
+	"github.com/astaxie/beego"
12
+
11 13
 	"github.com/go-xorm/xorm"
12 14
 )
13 15
 
@@ -53,7 +55,7 @@ FROM
53 55
 	ta_flash_buy a
54 56
 	INNER JOIN sys_case b ON a.case_id = b.case_id
55 57
 	Where a.status > ` + strconv.Itoa(models.STATUS_DEL) + `
56
-	and a.case_id in(` + strings.Replace(caseid, ",", "','", -1) + `')`
58
+	and a.case_id in('` + strings.Replace(caseid, ",", "','", -1) + `')`
57 59
 	if flashBuyName != "" {
58 60
 		sql += ` and a.flash_buy_name = '` + flashBuyName + `' `
59 61
 	}
@@ -61,6 +63,7 @@ FROM
61 63
 		sql += ` and a.flash_buy_status ='` + flashBuyStatus + `'`
62 64
 	}
63 65
 	sql += ` order by a.start_date desc limit ` + strconv.Itoa(page-1) + `, ` + strconv.Itoa(pageSize)
66
+	beego.Error(sql)
64 67
 	err := m.db.Sql(sql).Find(&flashBuy)
65 68
 	return flashBuy, err
66 69
 }
@@ -72,7 +75,7 @@ func (m *FlashbuyDAO) GetFlashBuyListCount(caseid, flashBuyName, flashBuyStatus
72 75
 FROM
73 76
 	ta_flash_buy a
74 77
 	Where a.status > ` + strconv.Itoa(models.STATUS_DEL) + `
75
-	and a.case_id in(` + strings.Replace(caseid, ",", "','", -1) + `')`
78
+	and a.case_id in('` + strings.Replace(caseid, ",", "','", -1) + `')`
76 79
 	if flashBuyName != "" {
77 80
 		sql += ` and a.flash_buy_name = '` + flashBuyName + `' `
78 81
 	}

+ 1
- 1
routers/common.go 파일 보기

@@ -328,7 +328,7 @@ func getCommonRoutes(prefix string) beego.LinkNamespace {
328 328
 		beego.NSRouter("/flashbuy/customer/:flashBuyId", &flashbuy.FlashBuyController{}, "get:GetCustomerFlashBuyList"),
329 329
 		beego.NSRouter("/flashbuy/:flashBuyId", &flashbuy.FlashBuyController{}, "get:GetFlashBuyById"),
330 330
 		beego.NSRouter("/flashbuy", &flashbuy.FlashBuyController{}, "post:SaveFlashBuy"),
331
-		beego.NSRouter("/flashbuy", &flashbuy.FlashBuyController{}, "put:SaveFlashBuy"),
331
+		beego.NSRouter("/flashbuy/edit", &flashbuy.FlashBuyController{}, "put:SaveFlashBuy"),
332 332
 		beego.NSRouter("/flashbuy/:channelId", &flashbuy.FlashBuyController{}, "delete:DeleteFlashBuy"),
333 333
 		beego.NSRouter("/flashbuy/:flashBuyId/:flashBuyStatus", &flashbuy.FlashBuyController{}, "put:UpdateFlashBuy"),
334 334
 		beego.NSRouter("/flashbuy/:qrcode", &flashbuy.FlashBuyController{}, "get:VerifyCustomerFlashBuyList"),

+ 2
- 0
service/flashbuy/flashbuy.go 파일 보기

@@ -63,6 +63,8 @@ func (s *FlashBuyServ) SaveFlashBuy(flashbuy model.TaFlashBuy) (*model.TaFlashBu
63 63
 	var newFlashBuy *model.TaFlashBuy
64 64
 	var err error
65 65
 	if flashbuy.FlashBuyId == "" {
66
+		org := s.ctx.Get("org").(model.SysOrg)
67
+		flashbuy.OrgId = org.OrgId
66 68
 		newFlashBuy, err = s.dao.AddNewFlashBuy(flashbuy)
67 69
 	} else {
68 70
 		err = s.dao.EditFlashBuy(flashbuy)