From b4201a0054369a8cd89e940947fd6f1a89f357c2 Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期三, 02 八月 2023 13:38:24 +0800
Subject: [PATCH] Merge branch 'master' into fly

---
 service/client.go |   60 ++++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/service/client.go b/service/client.go
index 260ef66..49c8bb7 100644
--- a/service/client.go
+++ b/service/client.go
@@ -15,30 +15,6 @@
 	return ecode.OK
 }
 
-func (ClientService) DeleteClient(id int) int {
-	// check client exist
-	_, err := model.NewClientSearch(nil).SetId(id).First()
-	if err != nil {
-		return ecode.ClientNotExist
-	}
-
-	// delete client
-	err = model.NewClientSearch(nil).SetId(id).Delete()
-	if err != nil {
-		return ecode.ClientDeleteErr
-	}
-	return ecode.OK
-}
-
-func (ClientService) GetClientList() (int, []*model.Client) {
-	// get client list
-	clients, err := model.NewClientSearch(nil).Find()
-	if err != nil {
-		return ecode.ClientListErr, nil
-	}
-
-	return ecode.OK, clients
-}
 
 // CheckClientExist check client exist
 func CheckClientExist(id int) int {
@@ -65,3 +41,39 @@
 
 	return ecode.OK
 }
+
+func (ClientService) GetClientList(page, pageSize int, keyword string) ([]*model.Client, int64, int) {
+	// get contact list
+	contacts, total, err := model.NewClientSearch(nil).SetKeyword(keyword).SetPage(page, pageSize).Find()
+	if err != nil {
+		return nil, 0, ecode.ClientListErr
+	}
+	return contacts, total, ecode.OK
+}
+
+func (ClientService) Assign(id, memberId int) int {
+	// check client exist
+	errCode := CheckClientExist(id)
+	if errCode != ecode.OK {
+		return errCode
+	}
+
+	// assign client
+	err := model.NewClientSearch(nil).SetId(id).UpdateByMap(map[string]interface{}{
+		"member_id": memberId,
+	})
+	if err != nil {
+		return ecode.AssignErr
+	}
+
+	return ecode.OK
+}
+
+func (ClientService) DeleteClient (ids []int) int {
+	// delete client
+	err := model.NewClientSearch(nil).SetIds(ids).Delete()
+	if err != nil {
+		return ecode.ClientDeleteErr
+	}
+	return ecode.OK
+}
\ No newline at end of file

--
Gitblit v1.8.0