Pārlūkot izejas kodu

修改了bug114和124

mainqaq 3 gadus atpakaļ
vecāks
revīzija
3d10a03c76
2 mainītis faili ar 49 papildinājumiem un 21 dzēšanām
  1. 26 19
      controllers/supply_order_api_contorller.go
  2. 23 2
      service/supply_service.go

+ 26 - 19
controllers/supply_order_api_contorller.go Parādīt failu

237
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
237
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
238
 		return
238
 		return
239
 	}
239
 	}
240
-	//supplierid, _ := this.GetInt64("id") //供应商id
241
-	//fmt.Println(dataBody["id"])
242
-	//utils.InfoLog("+++++++++++++前++++++++++++++++++", dataBody["id"])
243
 	supplierid := int64(dataBody["id"].(float64))
240
 	supplierid := int64(dataBody["id"].(float64))
244
-	//utils.InfoLog("+++++++++++++后++++++++++++++++++", supplierid)
245
 	if supplierid == 0 {
241
 	if supplierid == 0 {
246
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
242
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
247
 		return
243
 		return
278
 		dataBody["vatrate"] = 0
274
 		dataBody["vatrate"] = 0
279
 	}
275
 	}
280
 	supplierType := int64(dataBody["suppliertype"].(float64)) //供应商类别
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
 	//number := this.GetString("number")               //纳税人识别号
286
 	//number := this.GetString("number")               //纳税人识别号
284
 	number := dataBody["number"].(string) //纳税人识别号
287
 	number := dataBody["number"].(string) //纳税人识别号
285
 	//bank := this.GetString("bank")                   //开户银行
288
 	//bank := this.GetString("bank")                   //开户银行
286
 	bank := dataBody["bank"].(string) //纳税人识别号
289
 	bank := dataBody["bank"].(string) //纳税人识别号
287
 	//bankAccount := this.GetString("bankAccount")     //银行账号
290
 	//bankAccount := this.GetString("bankAccount")     //银行账号
288
 	bankAccount := dataBody["bankaccount"].(string)
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
 	if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
293
 	if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
299
 		thisStockIn, _ := dataBody["contacts"].([]interface{})
294
 		thisStockIn, _ := dataBody["contacts"].([]interface{})
409
 
404
 
410
 //删除供应商及联系人
405
 //删除供应商及联系人
411
 func (this *SupplyOrderApiController) DelSupply() {
406
 func (this *SupplyOrderApiController) DelSupply() {
407
+	orgId := this.GetAdminUserInfo().CurrentOrgId
412
 	//拿到供应商的id
408
 	//拿到供应商的id
413
 	suid, _ := this.GetInt64("id")
409
 	suid, _ := this.GetInt64("id")
414
 	if suid == 0 {
410
 	if suid == 0 {
418
 	supply := models.SpSupplierName{
414
 	supply := models.SpSupplierName{
419
 		ID: suid,
415
 		ID: suid,
420
 	}
416
 	}
421
-	err := service.DelSupply(supply)
417
+	err := service.DelSupply(supply, orgId)
422
 	if err != nil {
418
 	if err != nil {
423
 		utils.ErrorLog(err.Error())
419
 		utils.ErrorLog(err.Error())
424
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
420
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
434
 func (this *SupplyOrderApiController) DelContactOne() {
430
 func (this *SupplyOrderApiController) DelContactOne() {
435
 	id, _ := this.GetInt64("id")
431
 	id, _ := this.GetInt64("id")
436
 	if id == 0 {
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
 		return
437
 		return
439
 	}
438
 	}
440
 	err := service.DelContactOne(id)
439
 	err := service.DelContactOne(id)
530
 	}
529
 	}
531
 	supplierType := int64(dataBody["suppliertype"].(float64)) //供应商类别
530
 	supplierType := int64(dataBody["suppliertype"].(float64)) //供应商类别
532
 	//vatRate, _ := this.GetFloat("vatrate")
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
 	//bank := this.GetString("bank")
543
 	//bank := this.GetString("bank")
537
 	bank := dataBody["bank"].(string)
544
 	bank := dataBody["bank"].(string)
538
 	//bankAccount := this.GetString("bankAccount")
545
 	//bankAccount := this.GetString("bankAccount")

+ 23 - 2
service/supply_service.go Parādīt failu

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
 	return err
192
 	return err
172
 }
193
 }
173
 
194