胡轶钦 6 лет назад
Родитель
Сommit
febe80844c

+ 17
- 7
models/customerremark/customerremark.go Просмотреть файл

@@ -20,6 +20,12 @@ type CustomerCardCoupon struct {
20 20
 	VerifyStatus string
21 21
 	ReceiveDate  time.Time
22 22
 }
23
+type customerHistory struct {
24
+	model.TaSaleCustomerRemark `xorm:"extends"`
25
+	Name                       string
26
+	CustomerName               string
27
+	Phone                      string
28
+}
23 29
 
24 30
 // NewCustomerRemarkDAO New Inst
25 31
 func NewCustomerRemarkDAO(ctx *utils.Context) *CustomerRemarkDAO {
@@ -28,16 +34,20 @@ func NewCustomerRemarkDAO(ctx *utils.Context) *CustomerRemarkDAO {
28 34
 		db:  ctx.DB,
29 35
 	}
30 36
 }
31
-func (m *CustomerRemarkDAO) GetRemarkList(salesId, customerId string, page, pageSize int) ([]model.TaSaleCustomerRemark, error) {
32
-	var remark []model.TaSaleCustomerRemark
37
+func (m *CustomerRemarkDAO) GetRemarkList(salesId, customerId string, page, pageSize int) ([]customerHistory, error) {
38
+	var remark []customerHistory
33 39
 	sql := `SELECT
34
-	* 
40
+	a.*,
41
+	b.name,
42
+	b.customer_name,
43
+	b.phone
35 44
 FROM
36
-	ta_sale_customer_remark 
45
+	ta_sale_customer_remark a
46
+	INNER JOIN ta_customer b ON a.customer_id = b.customer_id
37 47
 WHERE
38
-	sales_id = '` + salesId + `'
39
-	and customer_id = '` + customerId + `'
40
-	order by create_date desc limit ` + strconv.Itoa(page-1) + `, ` + strconv.Itoa(pageSize)
48
+	a.sales_id = '` + salesId + `'
49
+	and a.customer_id = '` + customerId + `'
50
+	order by a.create_date desc limit ` + strconv.Itoa(page-1) + `, ` + strconv.Itoa(pageSize)
41 51
 	err := m.db.Sql(sql).Find(&remark)
42 52
 	return remark, err
43 53
 }

+ 2
- 0
models/model/ta_sale_customer_remark.go Просмотреть файл

@@ -7,6 +7,8 @@ import (
7 7
 type TaSaleCustomerRemark struct {
8 8
 	SalesCustomerRemarkId string    `xorm:"not null VARCHAR(64)"`
9 9
 	SaleCustomerId        string    `xorm:"VARCHAR(64)"`
10
+	CustomerId            string    `xorm:"VARCHAR(64)"`
11
+	SalesId               string    `xorm:"VARCHAR(64)"`
10 12
 	RemarkTitle           string    `xorm:"VARCHAR(256)"`
11 13
 	Remark                string    `xorm:"TEXT"`
12 14
 	CreateDate            time.Time `xorm:"DATETIME"`

+ 11
- 6
models/system/user.go Просмотреть файл

@@ -33,6 +33,10 @@ type UserListInfo struct {
33 33
 	model.SysUser `xorm:"extends"`
34 34
 	UserTypeNames string
35 35
 }
36
+type CustomerInfo struct {
37
+	model.TaCustomer `xorm:"extends"`
38
+	Remark           string
39
+}
36 40
 
37 41
 // GetUserList 用户列表
38 42
 func (m *UserDAO) GetUserList(username, typeid, caseids string, page int, pageSize int) ([]UserListInfo, error) {
@@ -404,11 +408,12 @@ func (m *UserDAO) UpdateCustomerHeadImg(customerid, username, imgurl string) err
404 408
 }
405 409
 
406 410
 // GetUserCustomer 获取我的推荐客户
407
-func (m *UserDAO) GetUserCustomer(userid, isrecommend, key string, page int, pageSize int) ([]model.TaCustomer, error) {
408
-	var customers []model.TaCustomer
409
-	sql := `select * from ta_customer where (recommend_id='` + userid + `'`
411
+func (m *UserDAO) GetUserCustomer(userid, isrecommend, key string, page int, pageSize int) ([]CustomerInfo, error) {
412
+	var customers []CustomerInfo
413
+	sql := `select a.*,
414
+	( SELECT remark FROM ta_sale_customer_remark b WHERE a.customer_id = b.customer_id ORDER BY b.create_date DESC LIMIT 1 ) AS remark from ta_customer a where (a.recommend_id='` + userid + `'`
410 415
 	if isrecommend == "" || isrecommend == "false" {
411
-		sql += ` or customer_id in (
416
+		sql += ` or a.customer_id in (
412 417
 			select customer_id from ta_customer_coupon where sales_id='` + userid + `'
413 418
 			union 
414 419
 			select customer_id from ta_customer_card where sales_id='` + userid + `'
@@ -416,10 +421,10 @@ func (m *UserDAO) GetUserCustomer(userid, isrecommend, key string, page int, pag
416 421
 	}
417 422
 	sql += ")"
418 423
 	if key != "" {
419
-		sql += ` and (customer_name like '%` + key + `%' or phone like '%` + key + `%' or name like '%` + key + `%')`
424
+		sql += ` and (a.customer_name like '%` + key + `%' or a.phone like '%` + key + `%' or a.name like '%` + key + `%')`
420 425
 	}
421 426
 	offset := (page - 1) * pageSize
422
-	sql += ` order by create_date desc LIMIT ` + strconv.Itoa(pageSize) + ` OFFSET ` + strconv.Itoa(offset)
427
+	sql += ` order by a.create_date desc LIMIT ` + strconv.Itoa(pageSize) + ` OFFSET ` + strconv.Itoa(offset)
423 428
 	err := m.db.Sql(sql).Find(&customers)
424 429
 	return customers, err
425 430
 }

+ 18
- 1
service/user.go Просмотреть файл

@@ -169,6 +169,23 @@ func (s *UserServ) SaveUser(user system.SysUserForm) (*model.SysUser, error) {
169 169
 	userInfo.Email = user.Email
170 170
 	userInfo.Phone = user.Phone
171 171
 	userInfo.Headimgurl = user.Headimgurl
172
+	var flag bool = true
173
+	for i := 0; i < 4; i++ {
174
+		code := s.dao.GenerateRecommendCode()
175
+		i, err := s.dao.IsCodeExist(code)
176
+		if err != nil {
177
+			return nil, errors.New("生成推荐码失败!请重新点击保存。")
178
+		}
179
+		if i <= 0 {
180
+			userInfo.RecommendCode = code
181
+			flag = false
182
+			break
183
+		}
184
+
185
+	}
186
+	if flag {
187
+		return nil, errors.New("生成推荐码失败!请重新点击保存。")
188
+	}
172 189
 
173 190
 	org := s.ctx.Get("org").(model.SysOrg)
174 191
 	user.OrgId = org.OrgId
@@ -428,7 +445,7 @@ func (s *UserServ) SaveUserRole(userid, roleids string) error {
428 445
 }
429 446
 
430 447
 // GetUserCustomer 获取我的推荐客户
431
-func (s *UserServ) GetUserCustomer(userid, isrecommend, key string, page int, pageSize int) ([]model.TaCustomer, error) {
448
+func (s *UserServ) GetUserCustomer(userid, isrecommend, key string, page int, pageSize int) ([]system.CustomerInfo, error) {
432 449
 	if pageSize == 0 {
433 450
 		pageSize = PAGENUM
434 451
 	}