| 
					
				 | 
			
			
				@@ -45,7 +45,7 @@ func NewRuleService() RuleService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 func (s *ruleService) Get(pid int, id int) viewmodels.ViewRule {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	data := s.daoRule.FindByPidWithBid(pid, id)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	viewData := viewmodels.ViewRule{SafeRule: data.SafeRule, QualityRule: data.QualityRule, ContractRule: data.ContractRule}
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	viewData := viewmodels.ViewRule{SafeRule: data.SafeRule, QualityRule: data.QualityRule, ContractPaidRule: data.ContractPaidRule, ContractReturnRule: data.ContractReturnRule}
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	return viewData
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -54,15 +54,9 @@ func (s *ruleService) Post(pid int, id int, key string, value string) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	return err
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// type Code struct {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// 	Date string `from:"date" json:"date"`
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// 	Text string `from:"text" json:"text"`
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// 	Name string `from:"name" json:"name"`
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// 	Code string `from:"code" json:"code"`
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 // 生成code
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 func (s *ruleService) AutoCode(bid int, pid int, codeType string) (string, error) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	fmt.Println("codeType---------------------------------------", codeType)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 获取该标段的规则
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	rule := s.daoRule.FindByPidWithBid(pid, bid)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if codeType == "safeRule" {
 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -88,14 +82,40 @@ func (s *ruleService) AutoCode(bid int, pid int, codeType string) (string, error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			}
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			return string(e), err
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		}
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} else if codeType == "contractRule" {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		if rule.ContractRule == "" {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} else if codeType == "contractReturnRule" {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if rule.ContractReturnRule == "" {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return "", errors.New("该标段未设置编号规则!")
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		}
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		var code viewmodels.RuleCode
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		err := json.Unmarshal([]byte(rule.ContractReturnRule), &code)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if err == nil {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			total, err := s.daoContract.CountRuleCode(bid, 0)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if err != nil {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				return "", err
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			}
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			value := reflect.ValueOf(code)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			for i := 0; i < value.NumField(); i++ {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				b := fmt.Sprint(value.Field(i))
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if b == code.Code {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					k, _ := strconv.Atoi(b)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					code.Code = utils.CreateRuleCode(int64(k), total, len(code.Code))
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				}
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			}
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			e, err := json.Marshal(code)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if err != nil {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				return "", err
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			}
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return string(e), err
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		}
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} else if codeType == "contractPaidRule" {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if rule.ContractReturnRule == "" {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			return "", errors.New("该标段未设置编号规则!")
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		}
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		var code viewmodels.RuleCode
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		err := json.Unmarshal([]byte(rule.ContractRule), &code)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		err := json.Unmarshal([]byte(rule.ContractPaidRule), &code)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		if err == nil {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			total, err := s.daoContract.CountRuleCode(bid)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			total, err := s.daoContract.CountRuleCode(bid, 1)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			if err != nil {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 				return "", err
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			}
 
			 |