瀏覽代碼

供应商接口

mainqaq 3 年之前
父節點
當前提交
55f4e1c291
共有 1 個文件被更改,包括 40 次插入10 次删除
  1. 40 10
      controllers/supply_order_api_contorller.go

+ 40 - 10
controllers/supply_order_api_contorller.go 查看文件

@@ -90,18 +90,36 @@ func SupplyOrderApiRegistRouters() {
90 90
 	beego.Router("/api/supply/getsupplywarehouseoutbyid", &SupplyOrderApiController{}, "Get:GetSupplyWarehouseById")
91 91
 }
92 92
 
93
+//判断前端参数是否为空
94
+func CheckParams(this *SupplyOrderApiController, m *map[string][]string) (map[string]string, error) {
95
+	tmp := make(map[string]string)
96
+	for k, v := range *m {
97
+		t := this.GetString(k)
98
+		if v[0] == "must" && t == "" {
99
+			return nil, fmt.Errorf(v[2] + "不能为空")
100
+		}
101
+		tmp[k] = t
102
+	}
103
+	return tmp, nil
104
+}
105
+
93 106
 //获取供应商列表GetSupplyList
94 107
 func (this *SupplyOrderApiController) GetSupplyList() {
95 108
 	ctype, _ := this.GetInt64("ctype") //供应商类别
96 109
 	page, _ := this.GetInt64("page")   //页码
97 110
 	limit, _ := this.GetInt64("limit") //每一页查出来的条数
98
-	if page == 0 || limit == 0 {
99
-		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "page或limit参数不能为空")
100
-		return
111
+	check := map[string][]string{
112
+		"page":  {"must", "string", "page"},
113
+		"limit": {"must", "string", "limit"},
101 114
 	}
102
-	//code := this.GetString("code")   //供应商编号
103
-	//sname := this.GetString("sname") //供应商名称
104
-	//cname := this.GetString("cname") //联系人名字
115
+	_, err := CheckParams(this, &check)
116
+	if err != nil {
117
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
118
+	}
119
+	//if page == 0 || limit == 0 {
120
+	//	this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "page或limit参数不能为空")
121
+	//	return
122
+	//}
105 123
 	keyword := this.GetString("keyword") //供应商编号\供应商名称\联系人名字
106 124
 	orgId := this.GetAdminUserInfo().CurrentOrgId
107 125
 	//获取分页的数据
@@ -191,6 +209,7 @@ func (this *SupplyOrderApiController) UpdateSupply() {
191 209
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
192 210
 		return
193 211
 	}
212
+
194 213
 	supplierName := dataBody["suppliername"].(string)
195 214
 	if supplierName == "" {
196 215
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称不能为空")
@@ -290,10 +309,17 @@ func (this *SupplyOrderApiController) UpdateSupply() {
290 309
 //获取单条供应商和涉及到的联系人记录
291 310
 func (this *SupplyOrderApiController) GetSupplyAndContactOne() {
292 311
 	id, _ := this.GetInt64("id")
293
-	if id == 0 {
294
-		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
295
-		return
312
+	check := map[string][]string{
313
+		"id": {"must", "string", "id"},
314
+	}
315
+	_, err := CheckParams(this, &check)
316
+	if err != nil {
317
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
296 318
 	}
319
+	//if id == 0 {
320
+	//	this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
321
+	//	return
322
+	//}
297 323
 	supply, contact, err := service.GetSupplyAndContactOne(id)
298 324
 	//获取供应商类别
299 325
 	orgId := this.GetAdminUserInfo().CurrentOrgId
@@ -481,7 +507,11 @@ func (this *SupplyOrderApiController) SaveSupply() {
481 507
 		dataBody["vatrate"] = 0
482 508
 	}
483 509
 	//supplierType, _ := this.GetInt64("suppliertype")
484
-	supplierType := dataBody["suppliertype"].(int64) //供应商类别
510
+	if dataBody["suppliertype"] == "" || dataBody["suppliertype"] == 0 {
511
+		var tmp float64 = 0
512
+		dataBody["suppliertype"] = tmp
513
+	}
514
+	supplierType := int64(dataBody["suppliertype"].(float64)) //供应商类别
485 515
 	//vatRate, _ := this.GetFloat("vatrate")
486 516
 	vatRate, _ := dataBody["suppliertype"].(float64) //增值税税率
487 517
 	//number := this.GetString("number")