Selaa lähdekoodia

修改了bug114和124

mainqaq 3 vuotta sitten
vanhempi
commit
3d10a03c76
2 muutettua tiedostoa jossa 49 lisäystä ja 21 poistoa
  1. 26 19
      controllers/supply_order_api_contorller.go
  2. 23 2
      service/supply_service.go

+ 26 - 19
controllers/supply_order_api_contorller.go Näytä tiedosto

@@ -237,11 +237,7 @@ func (this *SupplyOrderApiController) UpdateSupply() {
237 237
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
238 238
 		return
239 239
 	}
240
-	//supplierid, _ := this.GetInt64("id") //供应商id
241
-	//fmt.Println(dataBody["id"])
242
-	//utils.InfoLog("+++++++++++++前++++++++++++++++++", dataBody["id"])
243 240
 	supplierid := int64(dataBody["id"].(float64))
244
-	//utils.InfoLog("+++++++++++++后++++++++++++++++++", supplierid)
245 241
 	if supplierid == 0 {
246 242
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
247 243
 		return
@@ -278,22 +274,21 @@ func (this *SupplyOrderApiController) UpdateSupply() {
278 274
 		dataBody["vatrate"] = 0
279 275
 	}
280 276
 	supplierType := int64(dataBody["suppliertype"].(float64)) //供应商类别
281
-	//vatRate, _ := this.GetFloat("vatrate")           //增值税税率
282
-	vatRate, _ := dataBody["suppliertype"].(float64) //增值税税率
277
+	var tmpvarrate float64
278
+	datavarrate := dataBody["vatrate"]
279
+	switch datavarrate.(type) {
280
+	case float64:
281
+		tmpvarrate = datavarrate.(float64)
282
+	case string:
283
+		tmpvarrate, _ = strconv.ParseFloat(dataBody["vatrate"].(string), 64)
284
+	}
285
+	vatRate := tmpvarrate //增值税税率
283 286
 	//number := this.GetString("number")               //纳税人识别号
284 287
 	number := dataBody["number"].(string) //纳税人识别号
285 288
 	//bank := this.GetString("bank")                   //开户银行
286 289
 	bank := dataBody["bank"].(string) //纳税人识别号
287 290
 	//bankAccount := this.GetString("bankAccount")     //银行账号
288 291
 	bankAccount := dataBody["bankaccount"].(string)
289
-	//contacts := this.Get("contacts")//联系人
290
-	//dataBody := make(map[string]interface{}, 0)
291
-	//err = json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
292
-	//if err != nil {
293
-	//	utils.ErrorLog(err.Error())
294
-	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
295
-	//	return
296
-	//}
297 292
 	//保存联系人
298 293
 	if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
299 294
 		thisStockIn, _ := dataBody["contacts"].([]interface{})
@@ -409,6 +404,7 @@ func (this *SupplyOrderApiController) GetSupplyType() {
409 404
 
410 405
 //删除供应商及联系人
411 406
 func (this *SupplyOrderApiController) DelSupply() {
407
+	orgId := this.GetAdminUserInfo().CurrentOrgId
412 408
 	//拿到供应商的id
413 409
 	suid, _ := this.GetInt64("id")
414 410
 	if suid == 0 {
@@ -418,7 +414,7 @@ func (this *SupplyOrderApiController) DelSupply() {
418 414
 	supply := models.SpSupplierName{
419 415
 		ID: suid,
420 416
 	}
421
-	err := service.DelSupply(supply)
417
+	err := service.DelSupply(supply, orgId)
422 418
 	if err != nil {
423 419
 		utils.ErrorLog(err.Error())
424 420
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -434,7 +430,10 @@ func (this *SupplyOrderApiController) DelSupply() {
434 430
 func (this *SupplyOrderApiController) DelContactOne() {
435 431
 	id, _ := this.GetInt64("id")
436 432
 	if id == 0 {
437
-		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人id不能为空")
433
+		//this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人id不能为空")
434
+		this.ServeSuccessJSON(map[string]interface{}{
435
+			"list": "删除成功,没有走数据库",
436
+		})
438 437
 		return
439 438
 	}
440 439
 	err := service.DelContactOne(id)
@@ -530,9 +529,17 @@ func (this *SupplyOrderApiController) SaveSupply() {
530 529
 	}
531 530
 	supplierType := int64(dataBody["suppliertype"].(float64)) //供应商类别
532 531
 	//vatRate, _ := this.GetFloat("vatrate")
533
-	vatRate, _ := dataBody["vatrate"].(float64) //增值税税率
534
-	//number := this.GetString("number")
535
-	number := dataBody["number"].(string)
532
+	var tmpvarrate float64
533
+	datavarrate := dataBody["vatrate"]
534
+	switch datavarrate.(type) {
535
+	case float64:
536
+		tmpvarrate = datavarrate.(float64)
537
+	case string:
538
+		tmpvarrate, _ = strconv.ParseFloat(dataBody["vatrate"].(string), 64)
539
+	}
540
+	vatRate := tmpvarrate //增值税税率
541
+	//number := dataBody["number"].(string)
542
+	number, _ := dataBody["number"].(string)
536 543
 	//bank := this.GetString("bank")
537 544
 	bank := dataBody["bank"].(string)
538 545
 	//bankAccount := this.GetString("bankAccount")

+ 23 - 2
service/supply_service.go Näytä tiedosto

@@ -166,8 +166,29 @@ func GetSupplyAndContactOne(id, orgId int64) (supply models.SpSupplierName, cont
166 166
 }
167 167
 
168 168
 //删除供应商及联系人
169
-func DelSupply(supply models.SpSupplierName) error {
170
-	err := XTWriteDB().Model(&supply).Update("status", 0).Error
169
+func DelSupply(supply models.SpSupplierName, orgId int64) error {
170
+	tx := XTWriteDB().Begin()
171
+	defer func() {
172
+		if err != nil {
173
+			tx.Rollback()
174
+		} else {
175
+			tx.Commit()
176
+		}
177
+	}()
178
+	//删除供应商
179
+	err := tx.Model(&supply).Update("status", 0).Error
180
+	if err != nil {
181
+		return err
182
+	}
183
+	var spcode models.SpSupplierName
184
+	//获取供应商编号
185
+	err = tx.Model(&models.SpSupplierName{}).Select("supplier_code").Where("user_org_id = ? and id = ?", orgId, supply.ID).First(&spcode).Error
186
+	if err != nil {
187
+		return err
188
+	}
189
+	//删除联系人
190
+	err = tx.Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and user_org_id = ?", spcode.SupplierCode, orgId).Update("status", 0).Error
191
+
171 192
 	return err
172 193
 }
173 194