瀏覽代碼

营业执照不能重复添加的判断

yuedefeng 6 年之前
父節點
當前提交
df78d16d01

+ 24 - 28
src/dashoo.cn/backend/api/controllers/oilsupplier/suppliercertsub.go

@@ -342,37 +342,33 @@ func (this *OilSupplierCertSubController) AddGoodsBus() {
 			var list []supplierfile.OilSupplierFile
 			where := "SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
 			svc.GetEntitysByWhere(OilSupplierFileName, where, &list)
-			if len(list) == 0 { //第一次添加准入项,将共有必备资质写入文件表
-				for i := 0; i < len(needList); i++ {
-					var entity supplierfile.OilSupplierFile
-					entity.SupplierId = dataother.SupplierId
-					if i < 4 {
-						entity.SupplierTypeCode = "000"
-					} else {
-						entity.SupplierTypeCode = dataother.SupplierTypeCode
-					}
-					entity.NeedFileType = needList[i].FileName
-					entity.FileType = 1
-					entity.EffectDate = time.Now()
-					entity.CreateBy = this.User.Realname
-					entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
-					svc.InsertEntityBytbl(OilSupplierFileName, &entity)
+			hasField := ""
+			for i := 0; i < len(list); i++ {
+				hasField += list[i].NeedFileType + ","
+			}
+			mustField := "营业执照,组织代码,税务登记,开户许可,银行开户许可证,承诺书,企业信息系统截图,"
+			for i := 0; i < len(needList); i++ {
+				var entity supplierfile.OilSupplierFile
+				entity.SupplierId = dataother.SupplierId
+
+				if strings.Contains(mustField, needList[i].FileName+",") {
+					entity.SupplierTypeCode = "000"
+				} else {
+					entity.SupplierTypeCode = dataother.SupplierTypeCode
 				}
-			} else {
-				if len(needList) > 4 {
-					for i := 4; i < len(needList); i++ {
-						var entity supplierfile.OilSupplierFile
-						entity.SupplierId = dataother.SupplierId
-						entity.SupplierTypeCode = dataother.SupplierTypeCode
-						entity.NeedFileType = needList[i].FileName
-						entity.FileType = 1
-						entity.EffectDate = time.Now()
-						entity.CreateBy = this.User.Realname
-						entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
-						svc.InsertEntityBytbl(OilSupplierFileName, &entity)
-					}
+				entity.NeedFileType = needList[i].FileName
+				entity.FileType = 1
+				entity.EffectDate = time.Now()
+				entity.CreateBy = this.User.Realname
+				entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
+
+				if strings.Contains(hasField, needList[i].FileName+",") {
+					//已存在,不能重复添加
+					continue
 				}
+				svc.InsertEntityBytbl(OilSupplierFileName, &entity)
 			}
+
 		}
 	}
 }

+ 25 - 2
src/dashoo.cn/backend/api/controllers/oilsupplier/supplierfile.go

@@ -2,6 +2,9 @@ package oilsupplier
 
 import (
 	"encoding/json"
+	"strconv"
+	"strings"
+
 	//"strings"
 
 	//"time"
@@ -57,13 +60,33 @@ func (this *SupplierfileController) FileList() {
 // @router /addsubfile [post]
 func (this *SupplierfileController) AddSubfile() {
 	var model supplierfile.OilSupplierFile
+	svc := supplierfile.GetSupplierfileService(utils.DBE)
+
 	var jsonblob = this.Ctx.Input.RequestBody
 	json.Unmarshal(jsonblob, &model)
 	model.CreateBy = this.User.Realname
 	model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
-	svc := supplierfile.GetSupplierfileService(utils.DBE)
-	_, err := svc.InsertEntityBytbl(OilSupplierFileName, &model)
+
+	var list []supplierfile.OilSupplierFile
+	where := "SupplierId = '" + strconv.Itoa(model.SupplierId) + "'"
+	svc.GetEntitysByWhere(OilSupplierFileName, where, &list)
+	hasField := ""
+	for i := 0; i < len(list); i++ {
+		hasField += list[i].NeedFileType + ","
+	}
+
+
 	var errinfo ErrorDataInfo
+	if strings.Contains(hasField, model.NeedFileType+",") {
+		//已存在,不能重复添加
+		errinfo.Message = "操作失败!不能重复添加"
+		errinfo.Code = -1
+		this.Data["json"] = &errinfo
+		this.ServeJSON()
+		return
+	}
+
+	_, err := svc.InsertEntityBytbl(OilSupplierFileName, &model)
 	if err == nil {
 		errinfo.Message = "操作成功!"
 		errinfo.Code = 0