Browse Source

完善了供应商分页接口的逻辑

mainqaq 3 years ago
parent
commit
e48ed356b4
2 changed files with 80 additions and 11 deletions
  1. 71 8
      controllers/supply_order_api_contorller.go
  2. 9 3
      service/supply_service.go

+ 71 - 8
controllers/supply_order_api_contorller.go View File

@@ -73,17 +73,80 @@ func SupplyOrderApiRegistRouters() {
73 73
 
74 74
 //获取供应商列表GetSupplyList
75 75
 func (this *SupplyOrderApiController) GetSupplyList() {
76
-	ctype, _ := this.GetInt64("ctype")
77
-	page, _ := this.GetInt64("page")
78
-	limit, _ := this.GetInt64("limit")
79
-	code := this.GetString("code")
80
-	sname := this.GetString("sname")
81
-	cname := this.GetString("cname")
82
-	//var tmp map[interface{}]interface{}
76
+	ctype, _ := this.GetInt64("ctype") //供应商类别
77
+	page, _ := this.GetInt64("page")   //页码
78
+	limit, _ := this.GetInt64("limit") //
79
+	code := this.GetString("code")     //供应商编号
80
+	sname := this.GetString("sname")   //供应商名称
81
+	cname := this.GetString("cname")   //联系人名子
82
+	orgId := this.GetAdminUserInfo().CurrentOrgId
83
+	//获取分页的数据
83 84
 	list, total, err := service.GetSupplyList(ctype, page, limit, code, sname, cname)
85
+	//获取供应商类别
86
+	costClassify := "供应商类别"
87
+	drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
88
+	drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
89
+	tmpmap := make(map[int64]string)   //储存供应商类别
90
+	namemap := make(map[string]string) //储存首要联系人
91
+	for i := 0; i < len(drugTypeList); i++ {
92
+		k := int64(drugTypeList[i].Value)
93
+		v := drugTypeList[i].Name
94
+		tmpmap[k] = v
95
+	}
84 96
 	if err == nil {
97
+		for i := 0; i < len(list); i++ {
98
+			code := list[i].SupplierCode
99
+			fistname, errs := service.FindName(code)
100
+			if errs != nil && errs.Error() != "record not found" {
101
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
102
+				return
103
+			}
104
+			namemap[code] = fistname.Name
105
+		}
106
+		type SpSupplierNameList struct { //基于SpSupplierName结构体修改的,为了方便前端取数据整合了一下,删除了几个用不到的字段,添加了联系人名字和供应商类别两个字段
107
+			ID           int64
108
+			SupplierCode string
109
+			SupplierName string
110
+			SupplierType int64
111
+			VatRate      float64
112
+			Number       string
113
+			Bank         string
114
+			BankAccount  string
115
+			UserOrgId    int64
116
+			Status       int64
117
+			ContactsId   int64
118
+			ConName      string //供应商主要联系人名字
119
+			TypeName     string //供应商类别
120
+		}
121
+		//初始化该结构体
122
+		tmplist := []*SpSupplierNameList{}
123
+		for i := 0; i < len(list); i++ {
124
+			var typename string //类别名称
125
+			if list[i].SupplierType == 0 {
126
+				typename = ""
127
+			} else {
128
+				typename = tmpmap[list[i].SupplierType]
129
+			}
130
+			tlist := &SpSupplierNameList{
131
+				list[i].ID,
132
+				list[i].SupplierCode,
133
+				list[i].SupplierName,
134
+				list[i].SupplierType,
135
+				list[i].VatRate,
136
+				list[i].Number,
137
+				list[i].Bank,
138
+				list[i].BankAccount,
139
+				list[i].UserOrgId,
140
+				list[i].Status,
141
+				list[i].ContactsId,
142
+				namemap[list[i].SupplierCode],
143
+				typename,
144
+			}
145
+			tmplist = append(tmplist, tlist)
146
+
147
+		}
85 148
 		this.ServeSuccessJSON(map[string]interface{}{
86
-			"list":  list,
149
+			"list":  tmplist,
87 150
 			"total": total,
88 151
 		})
89 152
 	} else {

+ 9 - 3
service/supply_service.go View File

@@ -7,16 +7,22 @@ import (
7 7
 	"time"
8 8
 )
9 9
 
10
+//根据供应商编号获取首要联系人
11
+func FindName(code string) (fistname models.SpSupplierContacts, err error) {
12
+	err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1", code).First(&fistname).Error
13
+	return fistname, err
14
+}
15
+
10 16
 //供应商分页
11 17
 func GetSupplyList(ctype int64, page int64, limit int64, code string, sname string, cname string) (supplylist []*models.SpSupplierName, total int64, err error) {
12
-	db := XTReadDB().Model(&supplylist).Where("sgj_xt.xt_supplier_name.status = 1")
18
+	db := XTReadDB().Model(&supplylist).Where("sgj_xt.xt_supplier_name.status = 1 ")
13 19
 
14 20
 	offset := (page - 1) * limit
15 21
 
16 22
 	if cname != "" {
17 23
 		cname = "%" + cname + "%" //联系人
18
-		db = db.Joins("join sgj_xt.xt_supplier_contacts on sgj_xt.xt_supplier_contacts.id = sgj_xt.xt_supplier_name.contacts_id")
19
-		db = db.Where("sgj_xt.xt_supplier_contacts.name like ? ", cname).Group("sgj_xt.xt_supplier_name.id")
24
+		db = db.Joins("join sgj_xt.xt_supplier_contacts on sgj_xt.xt_supplier_contacts.supplier_code = sgj_xt.xt_supplier_name.supplier_code")
25
+		db = db.Where("sgj_xt.xt_supplier_contacts.name like ? and sgj_xt.xt_supplier_contacts.status = 1 ", cname).Group("sgj_xt.xt_supplier_name.id")
20 26
 	}
21 27
 	if ctype > 0 {
22 28
 		db = db.Where("sgj_xt.xt_supplier_name.supplier_type = ?", ctype)