package qua

import (
	"fmt"
	"go.mongodb.org/mongo-driver/bson/primitive"
	qu "qfw/util"
	u "util"
)

func BudgetFieldScore(tmp map[string]interface{},score int64) (map[string]interface{}) {

	budget := qu.Float64All(tmp["budget"])
	bidamount := qu.Float64All(tmp["bidamount"])
	reason,desc:=fmt.Sprintf("%d初始分",score),""

	/*错误项*/
	if (budget<10.0||budget>20000000000.0)  {
		return map[string]interface{}{
			"score":int64(0),
			"reason":"错误：大小",
		}
	}

	/*减分项
		"行业范围": 1,
	    "间隔异常": 2
	*/

	if bidamount > 0.0 && budget >0.0 {
		proportion := bidamount/budget
		if (proportion>=0.1&&proportion<=0.3)||(proportion>=3&&proportion<=5){
			desc = "间隔异常"
			reason+="~"+desc + fmt.Sprintf("-%d",qu.Int64All(u.Budget_Score[desc]))
			score -= qu.Int64All(u.Budget_Score[desc])
		}
		if proportion>=0.001&&proportion<0.1{
			return map[string]interface{}{
				"score":int64(0),
				"reason":"错误：比例",
			}
		}
	}

	class := make(map[string]interface{},0)
	if topscopeclass, ok := tmp["topscopeclass"].(primitive.A); budget>0.0&&ok&&len(topscopeclass)>0 {
		for _,v := range topscopeclass{
			value := qu.ObjToString(v)
			new_value := value[:len(value)-1]
			if class[new_value]==nil {//校验行业
				if !checkingClassMoney(budget,new_value) {
					desc = "行业范围"
					reason+="~"+desc + fmt.Sprintf("-%d",qu.Int64All(u.Budget_Score[desc]))
					score -= qu.Int64All(u.Budget_Score[desc])
				}
				class[new_value]=1
			}
		}
	}



	return map[string]interface{}{
		"score":score,
		"reason":reason,
	}
}