123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- package util
- import (
- "crypto/sha256"
- "fmt"
- "github.com/shopspring/decimal"
- "io"
- "math/big"
- "net/http"
- qu "qfw/util"
- "reflect"
- "regexp"
- "strconv"
- )
- var reg = regexp.MustCompile("[^0-9A-Za-z\u4e00-\u9fa5]+")
- var Filter = regexp.MustCompile("<[^>]*?>|[\\s\u3000\u2003\u00a0]")
- func Sha(con string) string {
- h := sha256.New()
- con = reg.ReplaceAllString(Filter.ReplaceAllString(con, ""), "")
- h.Write([]byte(con))
- return fmt.Sprintf("%x", h.Sum(nil))
- }
- func HexToBigIntMod(href string) int {
- //取哈希值
- t := sha256.New()
- _, _ = io.WriteString(t, href)
- hex := fmt.Sprintf("%x", t.Sum(nil))
- //取模
- n := new(big.Int)
- n, _ = n.SetString(hex[2:], 16)
- return int(n.Mod(n, big.NewInt(16)).Int64())
- }
- func HexText(href string) string {
- h := sha256.New()
- h.Write([]byte(href))
- return fmt.Sprintf("%x", h.Sum(nil))
- }
- //数据类型转换
- func GetPostForm(r *http.Request) map[string]interface{} {
- val := map[string]interface{}{}
- for k, _ := range r.Form {
- // if len(k) < 2 {
- // continue
- // }
- if k != "_id" {
- v := r.FormValue(k)
- switch k[:2] {
- case "s_": //string型
- val[k] = v
- case "l_": //int64位
- val[k], _ = strconv.ParseInt(v, 10, 64)
- case "i_": //int型
- val[k], _ = strconv.Atoi(v)
- default:
- if v == "true" || v == "false" {
- b, _ := strconv.ParseBool(v)
- val[k] = b
- } else {
- val[k] = v
- }
- }
- }
- }
- return val
- }
- //从数组中删除元素
- func deleteSlice(arr []string, v string) []string {
- for k, v1 := range arr {
- if v1 == v {
- return append(arr[:k], arr[k+1:]...)
- }
- }
- return arr
- }
- /**
- * 前端科学计数法处理
- */
- func FormatNumber(tmp map[string]interface{}) {
- for k, v := range tmp {
- if reflect.TypeOf(v).Name() == reflect.Float64.String() {
- num, _ := decimal.NewFromString(strconv.FormatFloat(qu.Float64All(v), 'e', -1, 64))
- tmp[k], _ = num.Float64()
- }
- }
- }
- // 公告信息修改字段,需要修改项目信息的字段
- var ElementsPro = []string{
- "projectname",
- "projectcode",
- "buyer",
- "agency",
- "area",
- "city",
- "publishtime",
- "toptype",
- "subtype",
- "district",
- "title",
- "buyerperson",
- "buyertel",
- "buyerclass",
- "createtime",
- "review_experts",
- "purchasing",
- "href",
- "topscopeclass",
- "budget",
- "bidamount",
- "winner",
- "s_winner",
- }
- func IsModifyPro(tmp map[string]interface{}) bool {
- for _, v := range ElementsPro {
- if tmp[v] != nil {
- return true
- }
- }
- return false
- }
- func GetJyHref(id string) string {
- return `https://www.jianyu360.cn/article/content/` + qu.CommonEncodeArticle("content", id) + `.html`
- }
- func PutHrefRedis(href, shaid, id string) {
- db := HexToBigIntMod(href)
- hashHref := HexText(href)
- PutRedis("title_repeat_fulljudgement", db, hashHref, id, -1)
- PutRedis("shaid", 0, shaid, "", 5184000)
- }
|