diff --git a/example/app/AES.go b/example/app/AES.go deleted file mode 100644 index a90b7eb..0000000 --- a/example/app/AES.go +++ /dev/null @@ -1,118 +0,0 @@ -package app - -import ( - "bytes" - "code.hoteas.com/golang/hotime/common" - "crypto/aes" - "crypto/cipher" - "encoding/base64" - "errors" - "fmt" -) - -//高级加密标准(Adevanced Encryption Standard ,AES) - -//16,24,32位字符串的话,分别对应AES-128,AES-192,AES-256 加密方法 -//key不能泄露 -var PwdKey = []byte("mif022h3g9geAHUHY432,:da1adag389") - -//PKCS7 填充模式 -func pKCS7Padding(ciphertext []byte, blockSize int) []byte { - padding := blockSize - len(ciphertext)%blockSize - //Repeat()函数的功能是把切片[]byte{byte(padding)}复制padding个,然后合并成新的字节切片返回 - padtext := bytes.Repeat([]byte{byte(padding)}, padding) - return append(ciphertext, padtext...) -} - -//填充的反向操作,删除填充字符串 -func pKCS7UnPadding(origData []byte) ([]byte, error) { - //获取数据长度 - length := len(origData) - if length == 0 { - return nil, errors.New("加密字符串错误!") - } else { - //获取填充字符串长度 - unpadding := int(origData[length-1]) - //截取切片,删除填充字节,并且返回明文 - return origData[:(length - unpadding)], nil - } -} - -//实现加密 -func AesEcrypt(origData []byte, key []byte) ([]byte, error) { - //创建加密算法实例 - block, err := aes.NewCipher(key) - if err != nil { - return nil, err - } - //获取块的大小 - blockSize := block.BlockSize() - //对数据进行填充,让数据长度满足需求 - origData = pKCS7Padding(origData, blockSize) - //采用AES加密方法中CBC加密模式 - blocMode := cipher.NewCBCEncrypter(block, key[:blockSize]) - crypted := make([]byte, len(origData)) - //执行加密 - blocMode.CryptBlocks(crypted, origData) - return crypted, nil -} - -//实现解密 -func AesDeCrypt(cypted []byte, key []byte) (bytes []byte, err error) { - //异常处理 - defer func() { - if e := recover(); e != nil { - //that.SetError(errors.New(fmt.Sprint(err)), LOG_FMT) - fmt.Println(err) - err = errors.New(common.ObjToStr(e)) - } - }() - //创建加密算法实例 - block, err := aes.NewCipher(key) - if err != nil { - return nil, err - } - - //获取块大小 - blockSize := block.BlockSize() - //创建加密客户端实例 - blockMode := cipher.NewCBCDecrypter(block, key[:blockSize]) - origData := make([]byte, len(cypted)) - //这个函数也可以用来解密 - blockMode.CryptBlocks(origData, cypted) - //去除填充字符串 - origData, err = pKCS7UnPadding(origData) - if err != nil { - return nil, err - } - return origData, err -} - -//加密base64 -func EnPwdCode(pwd []byte) (string, error) { - result, err := AesEcrypt(pwd, PwdKey) - if err != nil { - return "", err - } - return base64.StdEncoding.EncodeToString(result), err -} - -//解密 -func DePwdCode(pwd string) ([]byte, error) { - //解密base64字符串 - pwdByte, err := base64.StdEncoding.DecodeString(pwd) - if err != nil { - fmt.Println(err) - return nil, err - } - //执行AES解密 - return AesDeCrypt(pwdByte, PwdKey) - -} - -//func main() { -// str := []byte("12fff我是ww.topgoer.com的站长枯藤") -// pwd, _ := EnPwdCode(str) -// bytes, _ := DePwdCode(pwd) -// fmt.Println(string(bytes)) -//} diff --git a/example/app/article.go b/example/app/article.go deleted file mode 100644 index 3819d76..0000000 --- a/example/app/article.go +++ /dev/null @@ -1,110 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var ArticleCtr = Ctr{ - - "getdispatchs": func(that *Context) { - - //判断类型 - tp := that.Req.FormValue("type") - //判断类型 - data := Map{"del_flag": 0} - if tp == "notify" { - data["notify_id[!]"] = nil - } - - if tp == "policy" { - data["policy_id[!]"] = nil - } - - if tp == "declare" { - data["declare_id[!]"] = nil - } - - if len(data) > 1 { - data = Map{"AND": data, "GROUP": "dispatch_name"} - } else { - data["GROUP"] = "dispatch_name" - } - - res := that.Db.Select("article", "dispatch_name", data) - that.Display(0, res) - - }, - //用户微信公众号或者小程序登录 - "search": func(that *Context) { - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - data := Map{"del_flag": 0} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords} - } - - startTime := that.Req.FormValue("starttime") - finishTime := that.Req.FormValue("finishtime") - - if startTime != "" { - data["release_time[>=]"] = startTime - } - if finishTime != "" { - data["release_time[<=]"] = finishTime - } - - dispatchName := that.Req.FormValue("dispatch_name") - if dispatchName != "" { - data["dispatch_name"] = dispatchName - } - - //判断类型 - tp := that.Req.FormValue("type") - if tp == "notify" { - data["notify_id[!]"] = nil - } - - if tp == "policy" { - data["policy_id[!]"] = nil - } - - if tp == "declare" { - data["declare_id[!]"] = nil - } - - if len(data) > 1 { - data = Map{"AND": data, "ORDER": "release_time DESC"} - } - - count := that.Db.Count("article", data) - - res := that.Db.Page(page, pageSize).PageSelect("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+ - "favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,policy_id,declare_id,notify_id,dispatch_name,policy_level", data) - for _, v := range res { - - if v.GetCeilInt("notify_id") > 0 { - v["notify"] = that.Db.Get("notify", "tag", Map{"id": v.GetCeilInt("notify_id")}) - } - if v.GetCeilInt("policy_id") > 0 { - v["policy"] = that.Db.Get("policy", "tag", Map{"id": v.GetCeilInt("policy_id")}) - } - if v.GetCeilInt("declare_id") > 0 { - v["declare"] = that.Db.Get("declare", "money_scope_min,money_scope_max,status", Map{"id": v.GetCeilInt("declare_id")}) - } - } - - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/app/company.go b/example/app/company.go deleted file mode 100644 index a4f47c0..0000000 --- a/example/app/company.go +++ /dev/null @@ -1,259 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "code.hoteas.com/golang/hotime/dri/aliyun" - "code.hoteas.com/golang/hotime/dri/tencent" - "encoding/base64" - "fmt" - "io/ioutil" - "os" - "strings" - "time" -) - -var CompanyCtr = Ctr{ - - "search": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - keywords := that.Req.FormValue("keywords") - if keywords == "" { - keywords = that.Req.FormValue("company_name") - } - if keywords == "" { - keywords = that.Req.FormValue("name") - } - - if len(keywords) < 2 { - that.Display(0, Slice{}) - return - } - - res, err := aliyun.Company.GetCompanyList(keywords) - if err != nil { - fmt.Println(err) - that.Display(0, Slice{}) - return - } - if res.GetCeilInt64("status") != 200 { - fmt.Println(err) - that.Display(0, Slice{}) - return - } - - that.Display(0, res.GetMap("data").GetSlice("list")) - }, - "search_info": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - name := that.Req.FormValue("name") - - if len(name) < 2 { - that.Display(3, "找不到企业") - return - } - - res, err := aliyun.Company.GetCompanyBaseInfo(name) - if err != nil { - fmt.Println(err) - that.Display(4, "查询失败") - return - } - if res.GetBool("status") != true { - fmt.Println(err) - that.Display(4, "查询失败") - return - } - - that.Display(0, res.GetMap("data")) - }, - "info": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").Data}) - if user == nil { - that.Display(4, "找不到用户") - return - } - - res := that.Db.Get("company", "*", Map{"id": user.GetCeilInt("company_id")}) - if res == nil { - that.Display(4, "找不到企业") - return - } - //先不做限制 - //if res.GetCeilInt("salesman_id")!=that.Session("salesman_id").ToCeilInt(){ - // that.Display(4,"不是你的企业") - // return - //} - - //res["technology_center_flag"] = ObjToSlice(res["technology_center_flag"]) - //res["engineering_center_flag"] = ObjToSlice(res["engineering_center_flag"]) - //res["engineering_laboratory_flag"] = ObjToSlice(res["engineering_laboratory_flag"]) - //res["key_laboratory_flag"] = ObjToSlice(res["key_laboratory_flag"]) - //res["industrial_design_center_flag"] = ObjToSlice(res["industrial_design_center_flag"]) - // - //res["high_level_talents_flag1"] = ObjToSlice(res["high_level_talents_flag1"]) - // - //res["tags"] = ObjToSlice(res["tags"]) - - res["technology_center_flag"] = strToArray(res.GetString("technology_center_flag")) - res["engineering_center_flag"] = strToArray(res.GetString("engineering_center_flag")) - res["engineering_laboratory_flag"] = strToArray(res.GetString("engineering_laboratory_flag")) - res["key_laboratory_flag"] = strToArray(res.GetString("key_laboratory_flag")) - res["industrial_design_center_flag"] = strToArray(res.GetString("industrial_design_center_flag")) - res["high_level_talents_flag1"] = strToArray(res.GetString("high_level_talents_flag1")) - res["tags"] = strToArray(res.GetString("tags")) - - that.Display(0, res) - }, - "edit": func(that *Context) { - - //if that.Session("user_id").Data == nil { - // that.Display(2, "没有登录") - // return - //} - - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - //统一社会信用代码 - social_code := that.Req.FormValue("social_code") - if social_code == "" { - that.Display(3, "请求参数异常") - return - } - //企业名称 - company_name := that.Req.FormValue("company_name") - if company_name == "" { - that.Display(3, "请求参数异常") - return - } - //手机号 - phone := that.Req.FormValue("phone") - if phone == "" { - that.Display(3, "请求参数异常") - return - } - //姓名 - name := that.Req.FormValue("user_name") - if name == "" { - that.Display(3, "请求参数异常") - return - } - //验证码 - err := auth(that, phone, company_name, name) - if err != nil { - that.Display(3, err.Error()) - return - } - //营业执照路径 - business_license := that.Req.FormValue("business_license") - if business_license == "" { - that.Display(3, "请求参数异常") - return - } - user_id := that.Session("user_id").Data - user := that.Db.Get("user", "*", Map{"id": user_id}) - if user == nil { - that.Display(1, "没有找到该用户") - return - } - company := that.Db.Get("company", "*", Map{"AND": Map{"id": id, "user_id": user_id}}) - if company == nil { - that.Display(4, "不是属于你的企业") - return - } - //认证 - authentication_flag := 1 - //if user.GetCeilInt("authentication_flag") == 0 { - // authentication_flag = 1 - //} - //通过base64图片获取信息 - - that.Db.Update("user", Map{"name": name, "phone": phone, "authentication_flag": authentication_flag}, Map{"id": user_id}) - - that.Db.Update("company", Map{"social_code": social_code, "name": company_name, "phone": phone, "business_license": business_license, "modify_time[#]": "now()"}, Map{"id": id}) - - //赠送一张券 - data := Map{ - "user_id": user_id, - "coupon_id": 1, - "code_no": "SN" + time.Now().Format("20060102150405") + getSn(), - "effective_start_time[#]": "NOW()", - "effective_end_time": time.Now().AddDate(0, 6, 0).Format("2006-01-02 15:04:05"), - "source_type": 2, - "status": 0, - "admin_id": user.GetCeilInt("admin_id"), - "create_time[#]": "NOW()", - } - //先判断是否领取过 source_type=2 是通过认证赠送的券 - couponCount := that.Db.Count("coupon_user", Map{"AND": Map{"user_id": user_id, "source_type": 2}}) - if couponCount == 0 { - that.Db.Insert("coupon_user", data) - } - that.Display(0, "认证成功") - }, - //上传营业执照 - "upload": func(this *Context) { - file := this.Req.FormValue("file") - - if len(file) < 100 { - this.Display(3, "图片上传错误") - return - } - - //fmt.Println(uimg) - btes, e := base64.StdEncoding.DecodeString(file[strings.Index(file, ",")+1:]) //成图片文件并把文件写入到buffer - //btes, e := base64.StdEncoding.DecodeString(file) //成图片文件并把文件写入到buffer - if e != nil { - this.Display(3, "无法解析图片") - return - } - - //uimgPath:=time.Now().Format(this.Config.GetString("uimgPath")) - path := time.Now().Format(this.Config.GetString("wxFilePath")) - os.MkdirAll(this.Config.GetString("tpt")+"/"+path, os.ModeDir) - filePath := path + Md5(ObjToStr(time.Now().Unix())) + ".jpg" - - err2 := ioutil.WriteFile(this.Config.GetString("tpt")+"/"+filePath, btes, 0666) //buffer输出到jpg文件中(不做处理,直接写到文件) - if err2 != nil { - this.Display(3, "图片保存失败") - return - } - tp := this.Req.FormValue("type") - - if tp == "company" { - data := tencent.Tencent.OCRCOMPANY(file) - c := ObjToMap(data) - if c != nil { - c = c.GetMap("Response") - c["url"] = filePath - - } else { - c = Map{"url": filePath} - } - this.Display(0, c) - return - } - }, -} diff --git a/example/app/coupon.go b/example/app/coupon.go deleted file mode 100644 index ab7ffff..0000000 --- a/example/app/coupon.go +++ /dev/null @@ -1,67 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var CouponCtr = Ctr{ - - "search": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - user_id := that.Session("user_id").Data - user := that.Db.Get("user", "*", Map{"id": user_id}) - if user == nil { - that.Display(1, "没有找到该用户") - return - } - - //0-待使用,1-已使用,2-已过期 - - status := ObjToInt(that.Req.FormValue("status")) - var data = Map{ - "coupon_user.user_id": user_id, - "coupon_user.state": 0, - } - if that.Req.FormValue("status") != "" { - data.Put("coupon_user.status", status) - } - - specMap := Map{"AND": data} - if status == 0 { - specMap.Put("ORDER", "coupon_user.status ASC,coupon_user.effective_end_time ASC,coupon_user.create_time DESC") - } - if status == 1 { - specMap.Put("ORDER", "coupon_user.use_time DESC") - } - if status == 2 { - specMap.Put("ORDER", "coupon_user.effective_end_time DESC") - } - - count := that.Db.Count("coupon_user", Map{"AND": data}) - - res := that.Db.Page(page, pageSize).PageSelect("coupon_user", - Map{"[>]coupon": "coupon_user.coupon_id = coupon.id"}, - "coupon_user.code_no,coupon_user.effective_start_time,coupon_user.effective_end_time,coupon_user.status,"+ - "coupon.coupon_amount,coupon.coupon_type,coupon.name,"+ - "coupon.description", - specMap, - ) - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/app/declare.go b/example/app/declare.go deleted file mode 100644 index cd8e90d..0000000 --- a/example/app/declare.go +++ /dev/null @@ -1,1015 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "sort" - "strings" -) - -type paixuArr []Map - -func (x paixuArr) Len() int { - return len(x) -} -func (x paixuArr) Less(i, j int) bool { - if x[i].GetMap("declare") != nil { - return x[i].GetMap("declare").GetFloat64("matching_degree") > x[j].GetMap("declare").GetFloat64("matching_degree") - } - return x[i].GetCeilInt64("count") > x[j].GetCeilInt64("count") -} -func (x paixuArr) Swap(i, j int) { - x[i], x[j] = x[j], x[i] -} - -var DeclareCtr = Ctr{ - - "info": func(that *Context) { - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - res := that.Db.Get("declare", "*", Map{"id": id}) - - if res == nil { - that.Display(4, "找不到通知公告") - return - } - res["click_num"] = res.GetCeilInt64("click_num") + res.GetCeilInt64("click_num_base") + 1 - delete(res, "click_num_base") - - res["favorite_num"] = res.GetCeilInt64("favorite_num") + res.GetCeilInt64("favorite_num_base") - delete(res, "favorite_num_base") - - article := that.Db.Get("article", "*", Map{"id": res.GetCeilInt64("article_id")}) - if article != nil { - article["click_num"] = article.GetCeilInt64("click_num") + article.GetCeilInt64("click_num_base") + 1 - delete(article, "click_num_base") - - article["favorite_num"] = article.GetCeilInt64("favorite_num") + article.GetCeilInt64("favorite_num_base") - delete(article, "favorite_num_base") - } - - res["article"] = article - - //浏览量加1 - that.Db.Update("declare", Map{"click_num[#]": "click_num+1"}, Map{"id": id}) - //浏览量加1 - that.Db.Update("article", Map{"click_num[#]": "click_num+1"}, Map{"id": res.GetCeilInt64("article_id")}) - - //查询是否已关注 - if that.Session("user_id").Data != nil { - favorite := that.Db.Get("favorite", "user_id,declare_id", Map{"AND": Map{"declare_id": id, "user_id": that.Session("user_id").ToCeilInt(), "del_flag": 0}}) - res["favorite"] = favorite - } - - that.Display(0, res) - }, - //政策匹配 - "match": func(that *Context) { - - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").Data}) - if user == nil { - that.Display(4, "找不到用户") - return - } - - companyName := that.Req.FormValue("company_name") - if companyName == "" { - that.Display(3, "参数错误") - return - } - qu := that.Req.FormValue("register_address") - qus := strings.Split(qu, "/") - - for _, v := range qus { - if v != "" { - qu = v - } - } - - if !strings.Contains(qu, "区") && !strings.Contains(qu, "县") { - qu = "没有此项数据随意填充的" - } - - company := that.Db.Get("company", "*", Map{"user_id": that.Session("user_id").Data}) - - delete(company, "id") - delete(company, "salesman_id") - delete(company, "provider_id") - delete(company, "user_id") - delete(company, "del_flag") - delete(company, "state") - delete(company, "create_time") - delete(company, "modify_time") - data := Map{} - - for k, _ := range company { - if k == "high_level_talents_flag1" && that.Req.FormValue("highLevel_talents_flag") != "" { - that.Req.Form[k] = that.Req.Form["highLevel_talents_flag"] - } - if that.Req.Form[k] != nil { - if k == "tags" || k == "high_level_talents_flag1" || k == "technology_center_flag" || k == "engineering_center_flag" || k == "engineering_laboratory_flag" || k == "key_laboratory_flag" || k == "industrial_design_center_flag" { - data[k] = ObjToStr(that.Req.Form[k]) - } else { - data[k] = that.Req.FormValue(k) - } - } - } - - //如果企业名称相同则允许变更企业信息 - if companyName == company.GetString("name") { - that.Db.Update("company", data, Map{"user_id": that.Session("user_id").Data}) - } - if companyName != company.GetString("name") { - //扫码绑定后,第一次使用匹配功能,自动进行认证,并更新企业信息 - if user.GetCeilInt("certification_flag") == 0 && user.GetCeilInt64("salesman_id") != 0 { - that.Db.Update("user", Map{"certification_flag": 1}, Map{"id": user.GetCeilInt("id")}) - company["name"] = companyName - that.Db.Update("company", data, Map{"user_id": that.Session("user_id").Data}) - } - //其余情况,不存储数据 - } - - tags := that.Req.Form["tags"] - declares := map[int64]Map{} - - //标签分析 - if tags != nil { - for _, v := range tags { - dtag := that.Db.Select("declare_tag", Map{"[><]declare": "declare_tag.declare_id=declare.id"}, "declare_tag.declare_id", Map{"AND": Map{"OR": Map{"declare.policy_level": Slice{"省", "市"}, "declare.dispatch_department[~]": qu}, "declare_tag.tag_id": v}}) - for _, v1 := range dtag { - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["tag_count"] = 1 - } - } - } - - //企业规模分析 - dtag := that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "company_scale[<=]": ObjToInt(that.Req.FormValue("company_scale"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["company_scale_count"] = 1 - } - - //是否是有效期内的科技型中小企业称号:0-否,1-是 - if ObjToInt(that.Req.FormValue("smes_flag")) > 0 { - - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "smes_flag": ObjToInt(that.Req.FormValue("smes_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["smes_flag_count"] = 1 - } - - } - //是否是有效期内的高新区技术企业称号:0-否,1-是 - if ObjToInt(that.Req.FormValue("htzte_flag")) > 0 { - - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "htzte_flag": ObjToInt(that.Req.FormValue("htzte_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["htzte_flag_count"] = 1 - } - } - //是否是有效期内的工程中心称号:0-否,1-市级,2-省级,3-国家级 - flags := that.Req.Form["engineering_center_flag"] - flagslice := Slice{} - if flags != nil { - for _, v := range flags { - if v == "0" { - continue - } - flagslice = append(flagslice, v) - } - - } - if len(flagslice) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "engineering_center_flag": flagslice}}) - - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["engineering_center_flag_count"] = 1 - } - } - - //是否是有效期内的工程实验室称号:0-否,1-市级,2-省级,3-国家级 - flags = that.Req.Form["engineering_laboratory_flag"] - flagslice = Slice{} - if flags != nil { - for _, v := range flags { - if v == "0" { - continue - } - flagslice = append(flagslice, v) - } - - } - if len(flagslice) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "engineering_laboratory_flag": flagslice}}) - - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["engineering_laboratory_flag_count"] = 1 - } - } - //是否是有效期内的重点实验室称号:0-否,1-市级,2-省级,3-国家级 - flags = that.Req.Form["key_laboratory_flag"] - flagslice = Slice{} - if flags != nil { - for _, v := range flags { - if v == "0" { - continue - } - flagslice = append(flagslice, v) - } - - } - if len(flagslice) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "key_laboratory_flag": flagslice}}) - for _, v1 := range dtag { - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["key_laboratory_flag_count"] = 1 - } - } - - //是否是有效期内的工业设计中心称号:0-否,1-市级,2-省级,3-国家级 - flags = that.Req.Form["industrial_design_center_flag"] - flagslice = Slice{} - if flags != nil { - for _, v := range flags { - if v == "0" { - continue - } - flagslice = append(flagslice, v) - } - - } - if len(flagslice) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "industrial_design_center_flag": flagslice}}) - for _, v1 := range dtag { - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["industrial_design_center_flag_count"] = 1 - } - } - - //上年度有无研发投入:0-否,1-是 - if ObjToInt(that.Req.FormValue("research_input_flag")) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "research_input_flag": ObjToInt(that.Req.FormValue("research_input_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["research_input_flag_count"] = 1 - } - } - - //有无授权发明专利:0-否,1-是 - if ObjToInt(that.Req.FormValue("invention_patent_flag")) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "invention_patent_flag": ObjToInt(that.Req.FormValue("invention_patent_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["invention_patent_flag_count"] = 1 - } - } - - //有无国际科技合作:0-否,1-是 - if ObjToInt(that.Req.FormValue("international_cooperation_flag")) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "international_cooperation_flag": ObjToInt(that.Req.FormValue("international_cooperation_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["international_cooperation_flag_count"] = 1 - } - } - //上年度有无固定资产投入:0-否,1-是 - if ObjToInt(that.Req.FormValue("investment_fixed_assets_flag")) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "investment_fixed_assets_flag": ObjToInt(that.Req.FormValue("investment_fixed_assets_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["investment_fixed_assets_flag_count"] = 1 - } - } - //高层次人才情况:0-否,1-3个及以上博士-1,2-1个及以上博士-2,3-知名企业中高管1个及以上 - //dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "high_level_talents_flag1": ObjToInt(that.Req.FormValue("high_level_talents_flag1"))}}) - //for _, v1 := range dtag { - // - // if declares[v1.GetCeilInt64("declare_id")] == nil { - // declares[v1.GetCeilInt64("declare_id")] = v1 - // } - // declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - // declares[v1.GetCeilInt64("declare_id")]["high_level_talents_flag1_count"] = 1 - //} - // - // - //flags := that.Req.Form["engineering_center_flag"] - //flagslice := Slice{} - //if flags != nil { - // for _, v := range flags { - // if v == "0" { - // continue - // } - // flagslice = append(flagslice, v) - // } - // - //} - //高层次人才情况:0-否,1-3个及以上博士-1,2-1个及以上博士-2,3-知名企业中高管1个及以上 - flags = that.Req.Form["high_level_talents_flag1"] - flagslice = Slice{} - if flags != nil { - for _, v := range flags { - if v == "0" { - continue - } - flagslice = append(flagslice, v) - } - - } - if len(flagslice) > 0 { - - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "high_level_talents_flag1": flagslice}}) - - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["high_level_talents_flag1"] = 1 - } - - } - - //企业股东或成员是否有国内外高校或科研院在编、全职人员:0-否,1-是 - if ObjToInt(that.Req.FormValue("shareholders_flag")) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "shareholders_flag": ObjToInt(that.Req.FormValue("shareholders_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["shareholders_flag_count"] = 1 - } - } - //企业有无从外地引进博士学历人才:0-否,1-是 - if ObjToInt(that.Req.FormValue("nonlocal_dr_flag")) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "nonlocal_dr_flag": ObjToInt(that.Req.FormValue("nonlocal_dr_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["nonlocal_dr_flag"] = 1 - } - } - //上年度是否有贷款/融资或未来有贷款/融资计划:0-否,1-是 - if ObjToInt(that.Req.FormValue("loan_flag")) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "loan_flag": ObjToInt(that.Req.FormValue("loan_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["loan_flag"] = 1 - } - } - - px := paixuArr{} - for _, v := range declares { - px = append(px, v) - } - //获取到排序后的数据 - sort.Sort(px) - var res []Map - for _, v := range px { - id := v.GetCeilInt("declare_id") - article := that.Db.Get("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+ - "favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,declare_id,declare_id,declare_id", Map{"declare_id": id}) - article["declare"] = that.Db.Get("declare", "money_scope_min,money_scope_max,status", Map{"id": id}) - - res = append(res, article) - } - minMoney := float64(0) - maxMoney := float64(0) - for _, v := range res { - if v.GetMap("declare") != nil { - if v.GetMap("declare").GetFloat64("money_scope_min") < minMoney { - minMoney = v.GetMap("declare").GetFloat64("money_scope_min") - } - if v.GetMap("declare").GetFloat64("money_scope_max") > maxMoney { - maxMoney = v.GetMap("declare").GetFloat64("money_scope_max") - } - } - } - seData := Map{ - "user_id": that.Session("user_id").Data, - "search_company_name": companyName, - "policy_match_count": len(res), - "json_data": ObjToStr(company), - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - } - if maxMoney != minMoney { - seData["money_scope"] = ObjToStr(ObjToInt(minMoney)) + "-" + ObjToStr(ObjToInt(maxMoney)) + "" - } else if maxMoney == 0 { - seData["money_scope"] = "" - } else { - seData["money_scope"] = ObjToStr(ObjToInt(maxMoney)) + "" - } - - //匹配记录存储 - that.Db.Insert("search_record", seData) - - that.Display(0, res) - - }, - - //政策匹配 - "match_v2": func(that *Context) { - - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").Data}) - if user == nil { - that.Display(4, "找不到用户") - return - } - companyName := that.Req.FormValue("company_name") - if companyName == "" { - that.Display(3, "参数错误") - return - } - qu := that.Req.FormValue("register_address") - qus := strings.Split(qu, "/") - - for _, v := range qus { - if v != "" { - qu = v - } - } - - if !strings.Contains(qu, "区") && !strings.Contains(qu, "县") { - qu = "没有此项数据随意填充的" - } - - company := that.Db.Get("company", "*", Map{"id": user.GetCeilInt("company_id")}) - - //消除company没有创建的影响 - if company == nil { - companyId := that.Db.Insert("company", Map{ - "user_id": user["id"], - "create_time[#]": "now()", - "modify_time[#]": "now()", - "provider_id": user["provider_id"], - "salesman_id": user["salesman_id"], - "del_flag": 0, - }) - user["company_id"] = companyId - that.Db.Update("user", Map{"company_id": companyId}, Map{"id": user.GetCeilInt("id")}) - company = that.Db.Get("company", "*", Map{"id": user.GetCeilInt("company_id")}) - } - - delete(company, "id") - delete(company, "salesman_id") - delete(company, "provider_id") - delete(company, "user_id") - delete(company, "del_flag") - delete(company, "state") - delete(company, "create_time") - delete(company, "modify_time") - data := Map{} - - for k, _ := range company { - if k == "high_level_talents_flag1" && that.Req.FormValue("highLevel_talents_flag") != "" { - that.Req.Form[k] = that.Req.Form["highLevel_talents_flag"] - } - if that.Req.Form[k] != nil { - if k == "tags" || k == "high_level_talents_flag1" || k == "technology_center_flag" || k == "engineering_center_flag" || k == "engineering_laboratory_flag" || k == "key_laboratory_flag" || k == "industrial_design_center_flag" { - //data[k] = ObjToStr(that.Req.Form[k]) - data[k] = arrayToStr(ObjToSlice(that.Req.Form[k])) - } else { - data[k] = that.Req.FormValue(k) - } - } - } - - //如果企业名称相同则允许变更企业信息 - if companyName == company.GetString("name") || company.GetString("name") == "" { - that.Db.Update("company", data, Map{"user_id": that.Session("user_id").Data}) - } - if companyName != company.GetString("name") || user.GetCeilInt("certification_flag") == 0 { - //扫码绑定后,第一次使用匹配功能,自动进行认证,并更新企业信息 - if (user.GetCeilInt("certification_flag") == 0 || company.GetString("name") == "") && user.GetCeilInt64("salesman_id") != 0 { - that.Db.Update("user", Map{"certification_flag": 1}, Map{"id": user.GetCeilInt("id")}) - company["name"] = companyName - that.Db.Update("company", data, Map{"user_id": that.Session("user_id").Data}) - } - //其余情况,不存储数据 - } - - tags := that.Req.Form["tags"] - declares := map[int64]Map{} - - //标签分析 - if tags != nil { - for _, v := range tags { - dtag := that.Db.Select("declare_tag", Map{"[><]declare": "declare_tag.declare_id=declare.id"}, "declare_tag.declare_id", Map{"AND": Map{"OR": Map{"declare.policy_level": Slice{"省", "市"}, "declare.dispatch_department[~]": qu}, "declare_tag.tag_id": v}}) - for _, v1 := range dtag { - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["tag_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("tag_count") + 1 - } - } - } - - //企业规模分析 - dtag := that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "company_scale[<=]": ObjToInt(that.Req.FormValue("company_scale"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["company_scale_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("company_scale_count") + 1 - } - - //是否是有效期内的科技型中小企业称号:0-否,1-是 - if ObjToInt(that.Req.FormValue("smes_flag")) > 0 { - - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "smes_flag": ObjToInt(that.Req.FormValue("smes_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["smes_flag_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("smes_flag_count") + 1 - } - - } - //是否是有效期内的高新区技术企业称号:0-否,1-是 - if ObjToInt(that.Req.FormValue("htzte_flag")) > 0 { - - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "htzte_flag": ObjToInt(that.Req.FormValue("htzte_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["htzte_flag_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("htzte_flag_count") + 1 - } - } - //是否是有效期内的工程中心称号:0-否,1-市级,2-省级,3-国家级 - flags := that.Req.Form["engineering_center_flag"] - flagslice := Slice{} - if flags != nil { - for _, v := range flags { - if v == "0" { - continue - } - flagslice = append(flagslice, v) - } - - } - if len(flagslice) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "engineering_center_flag": flagslice}}) - - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["engineering_center_flag_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("engineering_center_flag_count") + 1 - } - } - - //是否是有效期内的工程实验室称号:0-否,1-市级,2-省级,3-国家级 - flags = that.Req.Form["engineering_laboratory_flag"] - flagslice = Slice{} - if flags != nil { - for _, v := range flags { - if v == "0" { - continue - } - flagslice = append(flagslice, v) - } - - } - if len(flagslice) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "engineering_laboratory_flag": flagslice}}) - - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["engineering_laboratory_flag_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("engineering_laboratory_flag_count") + 1 - } - } - //是否是有效期内的重点实验室称号:0-否,1-市级,2-省级,3-国家级 - flags = that.Req.Form["key_laboratory_flag"] - flagslice = Slice{} - if flags != nil { - for _, v := range flags { - if v == "0" { - continue - } - flagslice = append(flagslice, v) - } - - } - if len(flagslice) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "key_laboratory_flag": flagslice}}) - for _, v1 := range dtag { - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["key_laboratory_flag_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("key_laboratory_flag_count") + 1 - } - } - - //是否是有效期内的工业设计中心称号:0-否,1-市级,2-省级,3-国家级 - flags = that.Req.Form["industrial_design_center_flag"] - flagslice = Slice{} - if flags != nil { - for _, v := range flags { - if v == "0" { - continue - } - flagslice = append(flagslice, v) - } - - } - if len(flagslice) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "industrial_design_center_flag": flagslice}}) - for _, v1 := range dtag { - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["industrial_design_center_flag_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("industrial_design_center_flag_count") + 1 - } - } - - //上年度有无研发投入:0-否,1-是 - if ObjToInt(that.Req.FormValue("research_input_flag")) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "research_input_flag": ObjToInt(that.Req.FormValue("research_input_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["research_input_flag_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("research_input_flag_count") + 1 - } - } - - //有无授权发明专利:0-否,1-是 - if ObjToInt(that.Req.FormValue("invention_patent_flag")) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "invention_patent_flag": ObjToInt(that.Req.FormValue("invention_patent_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["invention_patent_flag_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("invention_patent_flag_count") + 1 - } - } - - //有无国际科技合作:0-否,1-是 - if ObjToInt(that.Req.FormValue("international_cooperation_flag")) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "international_cooperation_flag": ObjToInt(that.Req.FormValue("international_cooperation_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["international_cooperation_flag_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("international_cooperation_flag_count") + 1 - } - } - //上年度有无固定资产投入:0-否,1-是 - if ObjToInt(that.Req.FormValue("investment_fixed_assets_flag")) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "investment_fixed_assets_flag": ObjToInt(that.Req.FormValue("investment_fixed_assets_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["investment_fixed_assets_flag_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("investment_fixed_assets_flag_count") + 1 - } - } - //高层次人才情况:0-否,1-3个及以上博士-1,2-1个及以上博士-2,3-知名企业中高管1个及以上 - //dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "high_level_talents_flag1": ObjToInt(that.Req.FormValue("high_level_talents_flag1"))}}) - //for _, v1 := range dtag { - // - // if declares[v1.GetCeilInt64("declare_id")] == nil { - // declares[v1.GetCeilInt64("declare_id")] = v1 - // } - // declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - // declares[v1.GetCeilInt64("declare_id")]["high_level_talents_flag1_count"] = 1 - //} - // - // - //flags := that.Req.Form["engineering_center_flag"] - //flagslice := Slice{} - //if flags != nil { - // for _, v := range flags { - // if v == "0" { - // continue - // } - // flagslice = append(flagslice, v) - // } - // - //} - //高层次人才情况:0-否,1-3个及以上博士-1,2-1个及以上博士-2,3-知名企业中高管1个及以上 - flags = that.Req.Form["high_level_talents_flag1"] - flagslice = Slice{} - if flags != nil { - for _, v := range flags { - if v == "0" { - continue - } - flagslice = append(flagslice, v) - } - - } - if len(flagslice) > 0 { - - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "high_level_talents_flag1": flagslice}}) - - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["high_level_talents_flag1_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("high_level_talents_flag1_count") + 1 - } - - } - - //企业股东或成员是否有国内外高校或科研院在编、全职人员:0-否,1-是 - if ObjToInt(that.Req.FormValue("shareholders_flag")) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "shareholders_flag": ObjToInt(that.Req.FormValue("shareholders_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["shareholders_flag_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("shareholders_flag_count") + 1 - } - } - //企业有无从外地引进博士学历人才:0-否,1-是 - if ObjToInt(that.Req.FormValue("nonlocal_dr_flag")) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "nonlocal_dr_flag": ObjToInt(that.Req.FormValue("nonlocal_dr_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["nonlocal_dr_flag_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("nonlocal_dr_flag_count") + 1 - } - } - //上年度是否有贷款/融资或未来有贷款/融资计划:0-否,1-是 - if ObjToInt(that.Req.FormValue("loan_flag")) > 0 { - dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "loan_flag": ObjToInt(that.Req.FormValue("loan_flag"))}}) - for _, v1 := range dtag { - - if declares[v1.GetCeilInt64("declare_id")] == nil { - declares[v1.GetCeilInt64("declare_id")] = v1 - } - declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1 - declares[v1.GetCeilInt64("declare_id")]["loan_flag_count"] = declares[v1.GetCeilInt64("declare_id")].GetInt64("loan_flag_count") + 1 - } - } - - px := paixuArr{} - for _, v := range declares { - px = append(px, v) - } - //获取到排序后的数据 - sort.Sort(px) - res := paixuArr{} - //总参数量,除了tag标签 - columns := []string{ - "loan_flag", "nonlocal_dr_flag", "shareholders_flag", "high_level_talents_flag1", - "investment_fixed_assets_flag", "international_cooperation_flag", "invention_patent_flag", - "research_input_flag", "industrial_design_center_flag", "key_laboratory_flag", - "engineering_laboratory_flag", "engineering_center_flag", "htzte_flag", - "smes_flag", "company_scale"} - RecommendValue := 0 - RecommendDeclare := Map{} - for _, v := range px { - id := v.GetCeilInt("declare_id") - article := that.Db.Get("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+ - "favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,declare_id,declare_id,declare_id", Map{"declare_id": id}) - if article == nil { - that.Display(4, "没有查到article数据") - return - } - declare := that.Db.Get("declare", "*", Map{"id": id}) - - //查询是否已关注 - if that.Session("user_id").Data != nil { - favorite := that.Db.Get("favorite", "user_id,declare_id", Map{"AND": Map{"declare_id": id, "user_id": that.Session("user_id").ToCeilInt(), "del_flag": 0}}) - declare["favorite"] = favorite - } - matchingDegree := 0 - matchingDegreeCount := 0 - for _, v1 := range columns { - if declare.GetCeilInt(v1) != 0 { - matchingDegreeCount = matchingDegreeCount + 1 - } - if declare.GetCeilInt(v1) != 0 && v.GetCeilInt(v1+"_count") != 0 { - matchingDegree++ - } - } - - if RecommendValue < matchingDegree { - RecommendValue = matchingDegree - RecommendDeclare = declare - } - - matchingDegreePercent := ObjToFloat64(ObjToFloat64(matchingDegree) / ObjToFloat64(matchingDegreeCount)) - - if matchingDegreePercent < 0.5 { - matchingDegreePercent = 0.5 + matchingDegreePercent - } - if matchingDegreePercent == 1 { - matchingDegreePercent = 0.95 - } - declare["matching_degree"] = matchingDegreePercent - - article["declare"] = declare - res = append(res, article) - } - - sort.Sort(res) - minMoney := float64(0) - maxMoney := float64(0) - for _, v := range res { - if v.GetMap("declare") != nil { - if v.GetMap("declare").GetFloat64("money_scope_min") < minMoney { - minMoney = v.GetMap("declare").GetFloat64("money_scope_min") - } - if v.GetMap("declare").GetFloat64("money_scope_max") > maxMoney { - maxMoney = v.GetMap("declare").GetFloat64("money_scope_max") - } - } - } - seData := Map{ - "user_id": that.Session("user_id").Data, - "search_company_name": companyName, - "policy_match_count": len(res), - "json_data": ObjToStr(company), - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - } - if maxMoney != minMoney { - seData["money_scope"] = ObjToStr(ObjToInt(minMoney)) + "-" + ObjToStr(ObjToInt(maxMoney)) + "" - } else if maxMoney == 0 { - seData["money_scope"] = "" - } else { - seData["money_scope"] = ObjToStr(ObjToInt(maxMoney)) + "" - } - - //匹配记录存储 - that.Db.Insert("search_record", seData) - re := Map{"recomend": RecommendDeclare, "count": len(res), "data": res} - - //company,e:=aliyun.Company.GetCompanyBaseInfo(companyName) - //if e==nil{ - // re["company"]= - //} - - that.Display(0, re) - - }, - - //用户微信公众号或者小程序登录 - "search": func(that *Context) { - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - data := Map{"del_flag": 0, "declare_id[!]": nil} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords} - } - - startTime := that.Req.FormValue("starttime") - finishTime := that.Req.FormValue("finishtime") - - if startTime != "" { - data["release_date[>=]"] = startTime - } - if finishTime != "" { - data["release_date[<=]"] = finishTime - } - - dispatchName := that.Req.FormValue("dispatch_name") - if dispatchName != "" { - data["dispatch_name"] = dispatchName - } - - if len(data) > 1 { - data = Map{"AND": data, "ORDER": "release_time DESC"} - } - - count := that.Db.Count("article", data) - - res := that.Db.Page(page, pageSize).PageSelect("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+ - "favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,declare_id,declare_id,declare_id,dispatch_name,policy_level", data) - for _, v := range res { - - //if v.GetCeilInt("declare_id")>0{ - // v["declare"]=that.Db.Get("declare","id,tag",Map{"id":v.GetCeilInt("declare_id")}) - //} - //if v.GetCeilInt("declare_id")>0{ - // v["declare"]=that.Db.Get("declare","tag",Map{"id":v.GetCeilInt("declare_id")}) - //} - if v.GetCeilInt("declare_id") > 0 { - v["declare"] = that.Db.Get("declare", "money_scope_min,money_scope_max,status", Map{"id": v.GetCeilInt("declare_id")}) - } - } - - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/app/favorite.go b/example/app/favorite.go deleted file mode 100644 index 974b214..0000000 --- a/example/app/favorite.go +++ /dev/null @@ -1,241 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var FavoriteCtr = Ctr{ - //关注 - "follow": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - policyId := ObjToInt(that.Req.FormValue("policy_id")) - notifyId := ObjToInt(that.Req.FormValue("notify_id")) - declareId := ObjToInt(that.Req.FormValue("declare_id")) - providerId := ObjToInt(that.Req.FormValue("provider_id")) - - favorite := Map{} - data := Map{} - if providerId != 0 { - data = Map{"provider_id": providerId, "user_id": that.Session("user_id").Data} - favorite = that.Db.Get("favorite", "*", Map{"AND": data}) - data["modify_time[#]"] = "now()" - data["del_flag"] = 0 - data["type"] = 1 - - } else if notifyId != 0 { - article := that.Db.Get("article", "id", Map{"notify_id": notifyId}) - if article != nil { - data = Map{"notify_id": notifyId, "article_id": article.GetCeilInt("id"), "user_id": that.Session("user_id").Data} - favorite = that.Db.Get("favorite", "*", Map{"AND": data}) - data["modify_time[#]"] = "now()" - data["del_flag"] = 0 - data["type"] = 2 - } - - } else if policyId != 0 { - article := that.Db.Get("article", "id", Map{"policy_id": policyId}) - if article != nil { - data = Map{"policy_id": policyId, "article_id": article.GetCeilInt("id"), "user_id": that.Session("user_id").Data} - favorite = that.Db.Get("favorite", "*", Map{"AND": data}) - data["modify_time[#]"] = "now()" - data["del_flag"] = 0 - data["type"] = 3 - } - - } else if declareId != 0 { - article := that.Db.Get("article", "id", Map{"declare_id": declareId}) - if article != nil { - data = Map{"declare_id": declareId, "article_id": article.GetCeilInt("id"), "user_id": that.Session("user_id").Data} - favorite = that.Db.Get("favorite", "*", Map{"AND": data}) - data["modify_time[#]"] = "now()" - data["del_flag"] = 0 - data["type"] = 4 - } - } - - if len(data) != 0 { - isFavorite := int64(0) - if favorite != nil { - isFavorite = that.Db.Update("favorite", data, Map{"id": favorite.GetCeilInt("id")}) - } else { - data["create_time[#]"] = "now()" - isFavorite = that.Db.Insert("favorite", data) - } - - if isFavorite != 0 { - if data.GetCeilInt("article_id") != 0 { - that.Db.Update("article", Map{"favorite_num[#]": "favorite_num+1"}, Map{"id": data.GetCeilInt("article_id")}) - } - if data.GetCeilInt("notify_id") != 0 { - that.Db.Update("notify", Map{"favorite_num[#]": "favorite_num+1"}, Map{"id": data.GetCeilInt("notify_id")}) - } - if data.GetCeilInt("policy_id") != 0 { - that.Db.Update("policy", Map{"favorite_num[#]": "favorite_num+1"}, Map{"id": data.GetCeilInt("policy_id")}) - } - - if data.GetCeilInt("declare_id") != 0 { - that.Db.Update("declare", Map{"favorite_num[#]": "favorite_num+1"}, Map{"id": data.GetCeilInt("declare_id")}) - } - - if data.GetCeilInt("provider_id") != 0 { - that.Db.Update("provider", Map{"favorite_num[#]": "favorite_num+1"}, Map{"id": data.GetCeilInt("provider_id")}) - } - } - - that.Display(0, "关注成功") - return - } - - that.Display(4, "找不到关注对象") - return - - }, - - //关注 - "unfollow": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - policyId := ObjToInt(that.Req.FormValue("policy_id")) - notifyId := ObjToInt(that.Req.FormValue("notify_id")) - declareId := ObjToInt(that.Req.FormValue("declare_id")) - providerId := ObjToInt(that.Req.FormValue("provider_id")) - - favorite := Map{} - data := Map{} - if providerId != 0 { - data = Map{"provider_id": providerId, "user_id": that.Session("user_id").Data} - favorite = that.Db.Get("favorite", "*", Map{"AND": data}) - data["modify_time[#]"] = "now()" - data["del_flag"] = 1 - data["type"] = 1 - - } else if notifyId != 0 { - article := that.Db.Get("article", "id", Map{"notify_id": notifyId}) - if article != nil { - data = Map{"notify_id": notifyId, "article_id": article.GetCeilInt("id"), "user_id": that.Session("user_id").Data} - favorite = that.Db.Get("favorite", "*", Map{"AND": data}) - data["modify_time[#]"] = "now()" - data["del_flag"] = 1 - data["type"] = 2 - } - } else if policyId != 0 { - - article := that.Db.Get("article", "id", Map{"policy_id": policyId}) - if article != nil { - data = Map{"policy_id": policyId, "article_id": article.GetCeilInt("id"), "user_id": that.Session("user_id").Data} - favorite = that.Db.Get("favorite", "*", Map{"AND": data}) - data["modify_time[#]"] = "now()" - data["del_flag"] = 1 - data["type"] = 3 - } - - } else if declareId != 0 { - article := that.Db.Get("article", "id", Map{"declare_id": declareId}) - if article != nil { - data = Map{"declare_id": declareId, "article_id": article.GetCeilInt("id"), "user_id": that.Session("user_id").Data} - favorite = that.Db.Get("favorite", "*", Map{"AND": data}) - data["modify_time[#]"] = "now()" - data["del_flag"] = 1 - data["type"] = 4 - } - } - - if len(data) != 0 && favorite != nil { - - isFavorite := that.Db.Update("favorite", data, Map{"id": favorite.GetCeilInt("id")}) - - if isFavorite != 0 { - if data.GetCeilInt("article_id") != 0 { - that.Db.Update("article", Map{"favorite_num[#]": "favorite_num-1"}, Map{"id": data.GetCeilInt("article_id")}) - } - if data.GetCeilInt("notify_id") != 0 { - that.Db.Update("notify", Map{"favorite_num[#]": "favorite_num-1"}, Map{"id": data.GetCeilInt("notify_id")}) - } - if data.GetCeilInt("policy_id") != 0 { - that.Db.Update("policy", Map{"favorite_num[#]": "favorite_num-1"}, Map{"id": data.GetCeilInt("policy_id")}) - } - - if data.GetCeilInt("declare_id") != 0 { - that.Db.Update("declare", Map{"favorite_num[#]": "favorite_num-1"}, Map{"id": data.GetCeilInt("declare_id")}) - } - - if data.GetCeilInt("provider_id") != 0 { - that.Db.Update("provider", Map{"favorite_num[#]": "favorite_num-1"}, Map{"id": data.GetCeilInt("provider_id")}) - } - } - - that.Display(0, "取消关注成功") - return - } - - that.Display(0, "没有关注") - return - }, - - "search": func(that *Context) { - - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - tp := ObjToInt(that.Req.FormValue("type")) - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - data := Map{"del_flag": 0, "user_id": that.Session("user_id").Data} - - if tp != 0 { - data["type"] = tp - } - - if len(data) > 1 { - data = Map{"AND": data, "ORDER": "modify_time DESC"} - } - - count := that.Db.Count("favorite", data) - - res := that.Db.Page(page, pageSize).PageSelect("favorite", "*", data) - - for _, v := range res { - if v.GetCeilInt64("policy_id") != 0 { - v["policy"] = that.Db.Get("policy", "id,tag", Map{"id": v.GetCeilInt64("policy_id")}) - } - if v.GetCeilInt64("declare_id") != 0 { - v["declare"] = that.Db.Get("declare", "id,money_scope_min,money_scope_max,status", Map{"id": v.GetCeilInt64("declare_id")}) - } - - if v.GetCeilInt64("notify_id") != 0 { - v["notify"] = that.Db.Get("notify", "id,tag", Map{"id": v.GetCeilInt64("notify_id")}) - } - - if v.GetCeilInt64("article_id") != 0 { - v["article"] = that.Db.Get("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+ - "favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status", Map{"id": v.GetCeilInt64("article_id")}) - } - - if v.GetCeilInt64("provider_id") != 0 { - v["provider"] = that.Db.Get("provider", "id,name,level,discount,avatar,title,description,"+ - "click_num_base+click_num AS click_num,handle_num_base+handle_num AS handle_num,favorite_num_base+favorite_num AS favorite_num,modify_time", Map{"id": v.GetCeilInt64("provider_id")}) - } - - } - - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/app/func.go b/example/app/func.go deleted file mode 100644 index cb257f5..0000000 --- a/example/app/func.go +++ /dev/null @@ -1,44 +0,0 @@ -package app - -import ( - "bytes" - "code.hoteas.com/golang/hotime/common" - "fmt" - "github.com/tealeg/xlsx" - "net/http" - "time" -) - -func DataToExcel(w http.ResponseWriter, r *http.Request, titleList []string, dataList []common.Map, fileName string) { - // 生成一个新的文件 - file := xlsx.NewFile() - // 添加sheet页 - sheet, _ := file.AddSheet("Sheet1") - // 插入表头 - titleRow := sheet.AddRow() - for _, v := range titleList { - cell := titleRow.AddCell() - cell.Value = v - cell.GetStyle().Font.Color = "00FF0000" - } - for _, v1 := range dataList { - row := sheet.AddRow() - // 插入内容 - for _, v := range titleList { - cell := row.AddCell() - cell.SetValue(v1.Get(v)) - } - - } - //file.Save("D:\\temp\\vip_excel"+fileName) - - fileName = fmt.Sprintf("%s.xlsx", fileName) - //_ = file.Save(fileName) - w.Header().Add("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, fileName)) - w.Header().Add("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") - - var buffer bytes.Buffer - _ = file.Write(&buffer) - content := bytes.NewReader(buffer.Bytes()) - http.ServeContent(w, r, fileName, time.Now(), content) -} diff --git a/example/app/init.go b/example/app/init.go deleted file mode 100644 index 7f9d411..0000000 --- a/example/app/init.go +++ /dev/null @@ -1,154 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "errors" - "strings" - "time" - "unicode/utf8" -) - -// Project 管理端项目 -var Project = Proj{ - "article": ArticleCtr, - "company": CompanyCtr, - "declare": DeclareCtr, - "favorite": FavoriteCtr, - "lxcx": Lxcx, - "matters": MattersCtr, - "notify": NotifyCtr, - "order": OrderCtr, - "policy": PolicyCtr, - "provider": ProviderCtr, - "search_record": SearchRecordCtr, - "sms": Sms, - "tag": TagCtr, - "upan": UpanCtr, - "user": UserCtr, - "vip_order": VipOrderCtr, - "websocket": WebsocketCtr, - "wechath5": Wechath5, - "wechatmini": Wechath5, - "coupon": CouponCtr, -} - -//生成随机码的6位md5 -func getSn() string { - x := Rand(8) - return Substr(Md5(ObjToStr(int64(x)+time.Now().UnixNano()+int64(Rand(6)))), 0, 6) -} - -//生成随机码的4位随机数 -func getCode() string { - //res := "" - //for i := 0; i < 4; i++ { - res := ObjToStr(RandX(1000, 9999)) - //} - return res -} - -func strToArray(str string) Slice { - s := Slice{} - - olds := strings.Split(str, ",") - for _, v := range olds { - if v != "" { - s = append(s, v) - } - } - return s -} - -func arrayToStr(ars Slice) string { - s := "," - if ars == nil { - return s - } - for k, _ := range ars { - s = s + ars.GetString(k) + "," - } - return s -} - -//认证公共方案 -func auth(that *Context, phone, companyName, userName string) error { - - user := that.Db.Get("user", "id,phone,salesman_id,company_id,provider_id,name", Map{"id": that.Session("user_id").ToCeilInt()}) - if user == nil { - return errors.New("找不到用户") - } - company := that.Db.Get("company", "name,id", Map{"id": user.GetCeilInt("company_id")}) - - if company == nil { - return errors.New("找不到企业") - } - //手机号与原来的不同则进行绑定 - if phone != user.GetString("phone") || companyName != company.GetString("name") || user.GetString("name") != userName { - //微信验证成功 - if that.Session("wechat_phone").ToStr() == phone { - that.Db.Update("user", Map{"phone": phone}, Map{"id": user.GetCeilInt("id")}) - if user.GetCeilInt("company_id") != 0 { - that.Db.Update("company", Map{"phone": phone}, Map{"id": user.GetCeilInt("company_id")}) - } - user["phone"] = phone - } else if that.Req.FormValue("code") == "" || that.Session("phone").ToStr() != phone || that.Session("code").ToStr() != that.Req.FormValue("code") { - - return errors.New("验证码错误") - } else { - that.Db.Update("user", Map{"phone": phone, "name": userName}, Map{"id": user.GetCeilInt("id")}) - if user.GetCeilInt("company_id") != 0 { - that.Db.Update("company", Map{"phone": phone}, Map{"id": user.GetCeilInt("company_id")}) - } - user["phone"] = phone - } - - } - // - //company := that.Db.Get("company", "name,id", Map{"id": user.GetCeilInt("company_id")}) - if company != nil { - that.Db.Update("company", Map{"name": companyName}, Map{"id": company.GetCeilInt64("id")}) - if user.GetCeilInt64("salesman_id") != 0 { - that.Db.Update("user", Map{"certification_flag": 1}, Map{"id": user.GetCeilInt("id")}) - } - return nil - } - - company = Map{"name": companyName, - "user_id": user.GetCeilInt("id"), - } - if user.GetCeilInt("salesman_id") != 0 { - company["salesman_id"] = user.GetCeilInt("salesman_id") - } - if user.GetCeilInt("provider_id") != 0 { - company["provider_id"] = user.GetCeilInt("provider_id") - } - if user.GetString("phone") != "" { - company["phone"] = user.GetString("phone") - } - company["id"] = that.Db.Insert("company", company) - if company.GetCeilInt64("id") == 0 { - return errors.New("新建企业失败") - } - upUser := Map{"company_id": company.GetCeilInt64("id")} - if user.GetCeilInt64("salesman_id") != 0 { - upUser["certification_flag"] = 1 - - } - that.Db.Update("user", upUser, Map{"id": that.Session("user_id").Data}) - - return nil - -} - -// FilterEmoji 过滤 emoji 表情 -func FilterEmoji(content string) string { - new_content := "" - for _, value := range content { - _, size := utf8.DecodeRuneInString(string(value)) - if size <= 3 { - new_content += string(value) - } - } - return new_content -} diff --git a/example/app/lxcx.go b/example/app/lxcx.go deleted file mode 100644 index eaf8995..0000000 --- a/example/app/lxcx.go +++ /dev/null @@ -1,29 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - "code.hoteas.com/golang/hotime/common" - "io/ioutil" - "log" - "net/http" - "net/url" -) - -var Lxcx = Ctr{ - "lists": func(that *Context) { - urlStr := "https://www.ruichuangshe.com/Resources/Services/sAppInterface.ashx?type=policyprojectbycompanyname&page=1&pagesize=10&code=8eb68adf79d660e57ccd69ea4bf340162e29e43ec344df62b364bd65b886da7fca9fb995ad93a5b485d66fd268f946f34cf0&CompanyName=" - companyName := that.Req.FormValue("company") - companyName = url.QueryEscape(url.QueryEscape(companyName)) - - resp, err := http.Get(urlStr + companyName) - if err != nil { - log.Println("err") - } - defer resp.Body.Close() - b, err := ioutil.ReadAll(resp.Body) - if err != nil { - log.Println("err") - } - that.Display(0, common.ObjToMap(string(b))) - }, -} diff --git a/example/app/matters.go b/example/app/matters.go deleted file mode 100644 index cb27ed1..0000000 --- a/example/app/matters.go +++ /dev/null @@ -1,168 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var MattersCtr = Ctr{ - "create": func(that *Context) { - - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - sn := that.Req.FormValue("sn") - if sn == "" { - that.Display(3, "没有SN码") - return - } - serviceContent := that.Req.FormValue("service_content") - if serviceContent == "" { - that.Display(3, "没有服务内容") - return - } - - salesman := that.Db.Get("salesman", "id,provider_id,name,nickname", Map{"AND": Map{"sn": sn, "del_flag": 0}}) - if salesman == nil { - that.Display(4, "找不到服务商") - return - } - - re := that.Db.Insert("matters", Map{ - "user_id": that.Session("user_id").Data, - "salesman_id": salesman.GetCeilInt64("id"), - "provider_id": salesman.GetCeilInt64("provider_id"), - "type": 1, - "service_content": serviceContent, - "complete_flag": 0, - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - }) - res := that.Db.Get("matters", "*", Map{"id": re}) - if res == nil { - that.Display(4, "找不到事项") - return - } - - res["salesman"] = that.Db.Get("salesman", "name,id", Map{"id": res.GetCeilInt64("salesman_id")}) - - res["provider"] = that.Db.Get("provider", "name,id", Map{"id": res.GetCeilInt64("provider_id")}) - - that.Display(0, res) - }, - "info": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - res := that.Db.Get("matters", "*", Map{"id": id}) - if res == nil { - that.Display(4, "找不到事项") - return - } - - res["salesman"] = that.Db.Get("salesman", "name,id", Map{"id": res.GetCeilInt64("salesman_id")}) - - res["provider"] = that.Db.Get("provider", "name,id", Map{"id": res.GetCeilInt64("provider_id")}) - - that.Display(0, res) - }, - "edit": func(that *Context) { - - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - serviceEvaluation := ObjToInt(that.Req.FormValue("service_evaluation")) - evaluationRemark := that.Req.FormValue("evaluation_remark") - - if serviceEvaluation == 0 { - that.Display(3, "请求参数异常") - return - } - - matters := that.Db.Get("matters", "*", Map{"AND": Map{"id": id, "user_id": that.Session("user_id").Data}}) - if matters == nil { - that.Display(4, "不是属于你的评价") - return - } - - if matters.GetCeilInt("complete_flag") == 1 { - that.Display(4, "已完成评价,不可重复评价") - return - } - - that.Db.Update("matters", Map{"service_evaluation": serviceEvaluation, "evaluation_remark": evaluationRemark, "complete_flag": 1, "modify_time[#]": "now()"}, Map{"id": id}) - - that.Display(0, "评价成功") - }, - //用户微信公众号或者小程序登录 - "search": func(that *Context) { - - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - tp := that.Req.FormValue("type") - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - data := Map{"del_flag": 0, "user_id": that.Session("user_id").Data} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords} - } - - if tp != "" { - data["type"] = ObjToInt(tp) - } - - startTime := that.Req.FormValue("starttime") - finishTime := that.Req.FormValue("finishtime") - - if startTime != "" { - data["modify_time[>=]"] = startTime - } - if finishTime != "" { - data["modify_time[<=]"] = finishTime - } - - if len(data) > 1 { - data = Map{"AND": data, "ORDER": "modify_time DESC"} - } - - count := that.Db.Count("matters", data) - - res := that.Db.Page(page, pageSize).PageSelect("matters", "*", data) - - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/app/notify.go b/example/app/notify.go deleted file mode 100644 index 2137b4a..0000000 --- a/example/app/notify.go +++ /dev/null @@ -1,111 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var NotifyCtr = Ctr{ - - "info": func(that *Context) { - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - res := that.Db.Get("notify", "*", Map{"id": id}) - - if res == nil { - that.Display(4, "找不到通知公告") - return - } - res["click_num"] = res.GetCeilInt64("click_num") + res.GetCeilInt64("click_num_base") + 1 - delete(res, "click_num_base") - - res["favorite_num"] = res.GetCeilInt64("favorite_num") + res.GetCeilInt64("favorite_num_base") - delete(res, "favorite_num_base") - - article := that.Db.Get("article", "*", Map{"id": res.GetCeilInt64("article_id")}) - if article != nil { - article["click_num"] = article.GetCeilInt64("click_num") + article.GetCeilInt64("click_num_base") + 1 - delete(article, "click_num_base") - - article["favorite_num"] = article.GetCeilInt64("favorite_num") + article.GetCeilInt64("favorite_num_base") - delete(article, "favorite_num_base") - } - - res["article"] = article - //浏览量加1 - that.Db.Update("notify", Map{"click_num[#]": "click_num+1"}, Map{"id": id}) - //浏览量加1 - that.Db.Update("article", Map{"click_num[#]": "click_num+1"}, Map{"id": res.GetCeilInt64("article_id")}) - - //查询是否已关注 - if that.Session("user_id").Data != nil { - favorite := that.Db.Get("favorite", "user_id,notify_id", Map{"AND": Map{"notify_id": id, "user_id": that.Session("user_id").ToCeilInt(), "del_flag": 0}}) - res["favorite"] = favorite - } - - that.Display(0, res) - }, - //用户微信公众号或者小程序登录 - "search": func(that *Context) { - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - data := Map{"del_flag": 0, "notify_id[!]": nil} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords} - } - - startTime := that.Req.FormValue("starttime") - finishTime := that.Req.FormValue("finishtime") - - if startTime != "" { - data["release_date[>=]"] = startTime - } - if finishTime != "" { - data["release_date[<=]"] = finishTime - } - - dispatchName := that.Req.FormValue("dispatch_name") - if dispatchName != "" { - data["dispatch_name"] = dispatchName - } - - if len(data) > 1 { - data = Map{"AND": data, "ORDER": "release_time DESC"} - } - - count := that.Db.Count("article", data) - - res := that.Db.Page(page, pageSize).PageSelect("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+ - "favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,policy_id,declare_id,notify_id,dispatch_name,policy_level", data) - for _, v := range res { - - if v.GetCeilInt("notify_id") > 0 { - v["notify"] = that.Db.Get("notify", "id,tag", Map{"id": v.GetCeilInt("notify_id")}) - } - //if v.GetCeilInt("policy_id")>0{ - // v["policy"]=that.Db.Get("policy","tag",Map{"id":v.GetCeilInt("policy_id")}) - //} - //if v.GetCeilInt("declare_id")>0{ - // v["declare"]=that.Db.Get("declare","money_scope_min,money_scope_max,tag,status",Map{"id":v.GetCeilInt("declare_id")}) - //} - } - - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/app/order.go b/example/app/order.go deleted file mode 100644 index 1a05c74..0000000 --- a/example/app/order.go +++ /dev/null @@ -1,208 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "time" -) - -var OrderCtr = Ctr{ - //创建订单 - "create": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - providerId := ObjToInt(that.Req.FormValue("provider_id")) - phone := that.Req.FormValue("phone") - companyName := that.Req.FormValue("company_name") - userName := that.Req.FormValue("user_name") - if providerId == 0 || len(phone) != 11 || len(companyName) < 4 || len(userName) < 2 { - that.Display(3, "请求参数异常") - return - } - - err := auth(that, phone, companyName, userName) - if err != nil { - that.Display(3, err.Error()) - return - } - - declareId := ObjToInt(that.Req.FormValue("declare_id")) - - tp := that.Req.FormValue("type") - - //新建流程 - user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").Data}) - - if user == nil { - that.Display(4, "找不到用户") - return - } - company := that.Db.Get("company", "name", Map{"id": user.GetCeilInt("company_id")}) - if company == nil { - that.Display(4, "找不到企业") - return - } - - provider := that.Db.Get("provider", "*", Map{"id": providerId}) - - if provider == nil { - that.Display(4, "找不到该服务商") - return - } - - //是否以前已经创建了该服务商的订单,如果创建了则直接跳转到订单详情中去 - oldOrder := that.Db.Get("order", "id", Map{"AND": Map{"provider_id": providerId, "user_id": that.Session("user_id").Data, "del_flag": 0, "status": 0}}) - if oldOrder != nil { - orderRecord := Map{ - "order_id": oldOrder.GetCeilInt64("id"), - "user_id": user.GetCeilInt64("id"), - "remarks": user.GetString("nickname") + "向“" + provider.GetString("name") + "”服务商再次发起了订单请求", - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - } - - orderRecord["id"] = that.Db.Insert("order_record", orderRecord) - that.Db.Update("order", Map{"order_record_id": orderRecord.GetCeilInt64("id"), "modify_time[#]": "now()"}, Map{"id": oldOrder.GetCeilInt64("id")}) - - that.Display(0, oldOrder.GetCeilInt64("id")) - return - } - - data := Map{ - "name": "购买“" + provider.GetString("title") + "”服务", - "sn": "SN" + time.Now().Format("20060102150405") + getSn(), - "user_id": user.GetCeilInt64("id"), - "salesman_id": provider.GetCeilInt64("salesman_id"), - "provider_id": provider.GetCeilInt64("id"), - "company_id": company.GetCeilInt64("id"), - "company_name": company.GetString("name"), - "phone": user.GetString("phone"), - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - } - - if declareId != 0 { - data["policy_declare_flag"] = 1 - data["declare_id"] = declareId - } - - if tp == "policy_declare_flag" { - data["policy_declare_flag"] = 1 - } - - data["id"] = that.Db.Insert("order", data) - if data.GetCeilInt64("id") == 0 { - that.Display(4, "无法生成订单!") - return - } - - orderRecord := Map{ - "order_id": data["id"], - "user_id": user.GetCeilInt64("id"), - "remarks": user.GetString("nickname") + "向“" + provider.GetString("name") + "”服务商发起了订单请求", - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - } - - orderRecord["id"] = that.Db.Insert("order_record", orderRecord) - - if orderRecord.GetCeilInt64("id") == 0 { - that.Display(4, "无法生成订单记录!") - return - } - - that.Db.Update("order", Map{"order_record_id": orderRecord.GetCeilInt64("id")}, Map{"id": data.GetCeilInt64("id")}) - - that.Display(0, data.GetCeilInt64("id")) - }, - - "info": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - res := that.Db.Get("order", "*", Map{"AND": Map{"id": id, "user_id": that.Session("user_id").Data}}) - - if res == nil { - that.Display(4, "找不到对应订单") - return - } - if res.GetCeilInt("provider_id") > 0 { - res["provider"] = that.Db.Get("provider", "name,title,phone", Map{"id": res.GetCeilInt("provider_id")}) - } - - res["order_record"] = that.Db.Select("order_record", "remarks,modify_time", Map{"order_id": res.GetCeilInt("id"), "ORDER": "modify_time DESC"}) - - that.Display(0, res) - }, - //用户微信公众号或者小程序登录 - "search": func(that *Context) { - - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - data := Map{"del_flag": 0, "user_id": that.Session("user_id").Data} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["OR"] = Map{"sn[~]": keywords, "company_name[~]": keywords, "name[~]": keywords} - } - - startTime := that.Req.FormValue("starttime") - finishTime := that.Req.FormValue("finishtime") - - if startTime != "" { - data["modify_time[>=]"] = startTime - } - if finishTime != "" { - data["modify_time[<=]"] = finishTime - } - - if len(data) > 1 { - data = Map{"AND": data, "ORDER": "modify_time DESC"} - } - - count := that.Db.Count("order", data) - - res := that.Db.Page(page, pageSize).PageSelect("order", "*", data) - for _, v := range res { - - //if v.GetCeilInt("policy_id")>0{ - // v["policy"]=that.Db.Get("policy","id,tag",Map{"id":v.GetCeilInt("policy_id")}) - //} - if v.GetCeilInt("provider_id") > 0 { - v["provider"] = that.Db.Get("provider", "name,title", Map{"id": v.GetCeilInt("provider_id")}) - } - if v.GetCeilInt("order_record_id") > 0 { - v["order_record"] = that.Db.Get("order_record", "remarks,modify_time", Map{"id": v.GetCeilInt("order_record_id")}) - } - } - - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/app/policy.go b/example/app/policy.go deleted file mode 100644 index 73b9b1e..0000000 --- a/example/app/policy.go +++ /dev/null @@ -1,112 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var PolicyCtr = Ctr{ - - "info": func(that *Context) { - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - res := that.Db.Get("policy", "*", Map{"id": id}) - - if res == nil { - that.Display(4, "找不到通知公告") - return - } - res["click_num"] = res.GetCeilInt64("click_num") + res.GetCeilInt64("click_num_base") + 1 - delete(res, "click_num_base") - - res["favorite_num"] = res.GetCeilInt64("favorite_num") + res.GetCeilInt64("favorite_num_base") - delete(res, "favorite_num_base") - - article := that.Db.Get("article", "*", Map{"id": res.GetCeilInt64("article_id")}) - if article != nil { - article["click_num"] = article.GetCeilInt64("click_num") + article.GetCeilInt64("click_num_base") + 1 - delete(article, "click_num_base") - - article["favorite_num"] = article.GetCeilInt64("favorite_num") + article.GetCeilInt64("favorite_num_base") - delete(article, "favorite_num_base") - } - - res["article"] = article - - //浏览量加1 - that.Db.Update("policy", Map{"click_num[#]": "click_num+1"}, Map{"id": id}) - //浏览量加1 - that.Db.Update("article", Map{"click_num[#]": "click_num+1"}, Map{"id": res.GetCeilInt64("article_id")}) - - //查询是否已关注 - if that.Session("user_id").Data != nil { - favorite := that.Db.Get("favorite", "user_id,policy_id", Map{"AND": Map{"policy_id": id, "user_id": that.Session("user_id").ToCeilInt(), "del_flag": 0}}) - res["favorite"] = favorite - } - - that.Display(0, res) - }, - //用户微信公众号或者小程序登录 - "search": func(that *Context) { - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - data := Map{"del_flag": 0, "policy_id[!]": nil} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords} - } - - startTime := that.Req.FormValue("starttime") - finishTime := that.Req.FormValue("finishtime") - - if startTime != "" { - data["release_date[>=]"] = startTime - } - if finishTime != "" { - data["release_date[<=]"] = finishTime - } - - dispatchName := that.Req.FormValue("dispatch_name") - if dispatchName != "" { - data["dispatch_name"] = dispatchName - } - - if len(data) > 1 { - data = Map{"AND": data, "ORDER": "release_time DESC"} - } - - count := that.Db.Count("article", data) - - res := that.Db.Page(page, pageSize).PageSelect("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+ - "favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,policy_id,declare_id,policy_id,dispatch_name,policy_level", data) - for _, v := range res { - - //if v.GetCeilInt("policy_id")>0{ - // v["policy"]=that.Db.Get("policy","id,tag",Map{"id":v.GetCeilInt("policy_id")}) - //} - if v.GetCeilInt("policy_id") > 0 { - v["policy"] = that.Db.Get("policy", "tag", Map{"id": v.GetCeilInt("policy_id")}) - } - //if v.GetCeilInt("declare_id")>0{ - // v["declare"]=that.Db.Get("declare","money_scope_min,money_scope_max,tag,status",Map{"id":v.GetCeilInt("declare_id")}) - //} - } - - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/app/provider.go b/example/app/provider.go deleted file mode 100644 index 85e8abb..0000000 --- a/example/app/provider.go +++ /dev/null @@ -1,92 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var ProviderCtr = Ctr{ - //用户微信公众号或者小程序登录 - "info": func(that *Context) { - - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - res := that.Db.Get("provider", "*", Map{"id": id}) - - if res == nil { - that.Display(4, "找不到服务商") - return - } - - //浏览量加1 - that.Db.Update("provider", Map{"click_num[#]": "click_num+1"}, Map{"id": id}) - - //查询是否已关注 - if that.Session("user_id").Data != nil { - favorite := that.Db.Get("favorite", "user_id,provider_id", Map{"AND": Map{"provider_id": id, "user_id": that.Session("user_id").ToCeilInt(), "del_flag": 0}}) - res["favorite"] = favorite - } - - that.Display(0, res) - }, - "search": func(that *Context) { - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - data := Map{"del_flag": 0, "state": 0} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["OR"] = Map{"name[~]": keywords, "title[~]": keywords} - } - - tp := that.Req.FormValue("type") - if tp != "" { - data[tp] = 1 - } - - policyDeclareFlag := that.Req.FormValue("policy_declare_flag") - if policyDeclareFlag != "" { - data["policy_declare_flag"] = ObjToInt(policyDeclareFlag) - } - - intellectualPropertyFlag := that.Req.FormValue("intellectual_property_flag") - if intellectualPropertyFlag != "" { - data["intellectual_property_flag"] = ObjToInt(intellectualPropertyFlag) - } - - taxOnsultingFlag := that.Req.FormValue("tax_onsulting_flag") - if taxOnsultingFlag != "" { - data["tax_onsulting_flag"] = ObjToInt(taxOnsultingFlag) - } - - lawFlag := that.Req.FormValue("law_flag") - if lawFlag != "" { - data["law_flag"] = ObjToInt(lawFlag) - } - - if len(data) > 1 { - data = Map{"AND": data, "ORDER": "id DESC"} - } - - count := that.Db.Count("provider", data) - - res := that.Db.Page(page, pageSize).PageSelect("provider", "id,name,level,discount,avatar,title,description,"+ - "click_num_base+click_num AS click_num,handle_num_base+handle_num AS handle_num,favorite_num_base+favorite_num AS favorite_num,modify_time,policy_declare_flag,intellectual_property_flag,tax_onsulting_flag,law_flag", data) - - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/app/search_record.go b/example/app/search_record.go deleted file mode 100644 index 9ea13a5..0000000 --- a/example/app/search_record.go +++ /dev/null @@ -1,51 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var SearchRecordCtr = Ctr{ - - "search": func(that *Context) { - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - //if pageSize <= 0 { - pageSize = 50 - //} - - data := Map{"del_flag": 0} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["search_company_name[~]"] = keywords - } - - startTime := that.Req.FormValue("starttime") - finishTime := that.Req.FormValue("finishtime") - - if startTime != "" { - data["create_time[>=]"] = startTime - } - if finishTime != "" { - data["create_time[<=]"] = finishTime - } - - if len(data) > 1 { - data = Map{"AND": data} - } else { - data["ORDER"] = "create_time DESC" - } - - count := that.Db.Count("search_record", data) - - res := that.Db.Page(page, pageSize).PageSelect("search_record", "id,search_company_name,policy_match_count,money_scope,create_time", data) - - that.Display(0, Map{"total": count, "data": res}) - - }, -} diff --git a/example/app/sms.go b/example/app/sms.go deleted file mode 100644 index 77e7c2f..0000000 --- a/example/app/sms.go +++ /dev/null @@ -1,30 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - "code.hoteas.com/golang/hotime/dri/ddsms" -) - -var Sms = Ctr{ - //只允许微信验证过的或者登录成功的发送短信 - "send": func(that *Context) { - - if that.Session("wechat_id").Data == nil && that.Session("user_id").Data == nil { - that.Display(2, "没有登录不可发送短信") - return - } - - phone := that.Req.FormValue("phone") - if len(phone) < 11 { - that.Display(3, "手机号格式错误") - return - } - code := getCode() - that.Session("phone", phone) - that.Session("code", code) - - ddsms.DDY.SendYZM(phone, that.Config.GetString("smsLogin"), map[string]string{"code": code}) - - that.Display(0, "发送成功") - }, -} diff --git a/example/app/tag.go b/example/app/tag.go deleted file mode 100644 index ba1d4fb..0000000 --- a/example/app/tag.go +++ /dev/null @@ -1,83 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var TagCtr = Ctr{ - - "create": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - name := that.Req.FormValue("name") - - oldTag := that.Db.Get("tag", "id", Map{"name": name}) - if oldTag != nil { - that.Display(4, "此标签已存在") - return - } - - re := that.Db.Insert("tag", Map{ - "user_id": that.Session("user_id").Data, - "name": name, - "remark": "用户上传", - "create_time[#]": "now()", - "modify_time[#]": "now()", - "state": 1, //先置为异常状态,等待审核通过 - "del_flag": 0, - }) - - if re == 0 { - that.Display(4, "添加失败") - return - } - - that.Display(0, "添加成功") - return - - }, - //用户微信公众号或者小程序登录 - "search": func(that *Context) { - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 40 - } - - data := Map{"del_flag": 0, "state": 0} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["OR"] = Map{"name[~]": keywords, "remark[~]": keywords} - } - - startTime := that.Req.FormValue("starttime") - finishTime := that.Req.FormValue("finishtime") - - if startTime != "" { - data["modify_time[>=]"] = startTime - } - if finishTime != "" { - data["modify_time[<=]"] = finishTime - } - - if len(data) > 1 { - data = Map{"AND": data} - } - - count := that.Db.Count("tag", data) - - res := that.Db.Page(page, pageSize).PageSelect("tag", "id,name,remark", data) - - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/app/upan.go b/example/app/upan.go deleted file mode 100644 index beb1d93..0000000 --- a/example/app/upan.go +++ /dev/null @@ -1,91 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - "code.hoteas.com/golang/hotime/common" - "fmt" - "strings" -) - -var UpanCtr = Ctr{ - "login": func(that *Context) { - timestamp := that.Req.FormValue("timestamp") - sn := that.Req.FormValue("sn") - - //str,_:=EnPwdCode([]byte(lus[len(lus)-1]+":"+ObjToStr(t)))// - re, e := DePwdCode(sn) - - if e != nil { - that.Display(3, "数据异常") - return - } - reStr := string(re) - realSn := strings.Replace(reStr, ":"+timestamp, "", -1) - if len(realSn)+len(timestamp)+1 != len(reStr) { - that.Display(4, "数据验证失败") - return - } - fmt.Println("U盘校验", realSn) - user := that.Db.Get("user", "*", common.Map{"upankey": realSn}) - if user == nil { - that.Display(5, "还没有绑定用户") - return - } - - that.Session("user_id", user.GetCeilInt("id")) - that.Display(0, "登录成功") - }, - - "create": func(that *Context) { - timestamp := that.Req.FormValue("timestamp") - sn := that.Req.FormValue("sn") - - //str,_:=EnPwdCode([]byte(lus[len(lus)-1]+":"+ObjToStr(t)))// - re, e := DePwdCode(sn) - - if e != nil { - fmt.Println(e) - that.Display(3, "数据异常") - return - } - reStr := string(re) - realSn := strings.Replace(reStr, ":"+timestamp, "", -1) - if len(realSn)+len(timestamp)+1 != len(reStr) { - that.Display(4, "数据验证失败") - return - } - - fmt.Println("U盘校验", realSn) - - uuser := that.Db.Get("user", "id", common.Map{"upankey": realSn}) - - if uuser != nil { - that.Display(4, "已经绑定了其他企业") - return - } - - phone := that.Req.FormValue("phone") - companyName := that.Req.FormValue("company_name") - userName := that.Req.FormValue("user_name") - - if len(phone) != 11 || len(companyName) < 4 || len(userName) < 2 { - that.Display(3, "请求参数异常") - return - } - //验证不成功则反馈 - err := auth(that, phone, companyName, userName) - if err != nil { - fmt.Println(err) - that.Display(3, err.Error()) - return - } - - num := that.Db.Update("user", common.Map{"upankey": realSn}, common.Map{"id": that.Session("user_id").Data}) - if num == 0 { - that.Display(4, "更新失败") - return - } - that.Display(0, "绑定成功") - - }, -} diff --git a/example/app/user.go b/example/app/user.go deleted file mode 100644 index 4c695ab..0000000 --- a/example/app/user.go +++ /dev/null @@ -1,107 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var UserCtr = Ctr{ - "test": func(that *Context) { - that.Session("user_id", 1) - that.Session("wechat_id", 1) - that.Display(0, 1) - }, - //用户微信公众号或者小程序登录 - "info": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").ToCeilInt()}) - if user == nil { - that.Display(2, "获取个人信息失败") - return - } - - if user.GetCeilInt("company_id") == 0 { - companyId := that.Db.Insert("company", Map{ - "user_id": user["id"], - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - }) - user["company_id"] = companyId - that.Db.Update("user", Map{"company_id": companyId}, Map{"id": user.GetCeilInt("id")}) - } - - delete(user, "password") - - company := that.Db.Get("company", "id,name,social_code,business_license", Map{"id": user.GetCeilInt("company_id")}) - salesman := that.Db.Get("salesman", "id,name", Map{"id": user.GetCeilInt("salesman_id")}) - provider := that.Db.Get("provider", "id,name", Map{"id": user.GetCeilInt("provider_id")}) - - if user != nil { - user["company"] = company - user["salesman"] = salesman - user["provider"] = provider - } - - that.Display(0, user) - }, - - "edit": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - name := that.Req.FormValue("name") - nickname := that.Req.FormValue("nickname") - sex := that.Req.FormValue("sex") - email := that.Req.FormValue("email") - avatar := that.Req.FormValue("avatar") - address := that.Req.FormValue("address") - phone := that.Req.FormValue("phone") //如果更换手机号则要有新的短信验证码 - code := that.Req.FormValue("code") - - data := Map{"modify_time[#]": "now()"} - if name != "" { - data["name"] = name - } - if nickname != "" { - data["nickname"] = nickname - } - if sex != "" { - data["sex"] = sex - } - if email != "" { - data["email"] = email - } - if avatar != "" { - data["avatar"] = avatar - } - if address != "" { - data["address"] = address - } - if phone != "" { - - //微信验证成功 - if that.Session("wechat_phone").ToStr() == phone { - data["phone"] = phone - } else if code == "" || that.Session("phone").ToStr() != phone || that.Session("code").ToStr() != code { - that.Display(3, "手机短信验证失败") - return - } - data["phone"] = phone - } - - re := that.Db.Update("user", data, Map{"id": that.Session("user_id").Data}) - if re == 0 { - that.Display(4, "更新失败") - return - } - - that.Display(0, "修改成功") - }, -} diff --git a/example/app/vip_order.go b/example/app/vip_order.go deleted file mode 100644 index a0d02fa..0000000 --- a/example/app/vip_order.go +++ /dev/null @@ -1,235 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "code.hoteas.com/golang/hotime/dri/wechat" - "fmt" - "time" -) - -var VipOrderCtr = Ctr{ - //创建V订单 - "create": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - phone := that.Req.FormValue("phone") - companyName := that.Req.FormValue("company_name") - userName := that.Req.FormValue("user_name") - if len(phone) != 11 || len(companyName) < 4 || len(userName) < 2 { - that.Display(3, "请求参数异常") - return - } - - that.Db.Delete("vip_order", Map{"AND": Map{"user_id": that.Session("user_id").Data, "status": 0}}) - - user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").Data}) - if user == nil { - that.Display(2, "找不到此用户") - return - } - - wc := that.Db.Get("wechat", "openid", Map{"AND": Map{"appid": that.Config.GetString("wechatAppID"), "user_id": that.Session("user_id").Data}}) - if wc == nil { - that.Display(2, "没有获取微信个人信息") - return - } - - err := auth(that, phone, companyName, userName) - - if err != nil { - that.Display(3, err.Error()) - return - } - - data := Map{ - "sn": "SN" + time.Now().Format("20060102150405") + getSn(), - //"name":"1年VIP会员", - "amount": 36000, //720元 - "user_id": user.GetCeilInt64("id"), - "company_id": user.GetCeilInt("company_id"), - "expiration_time": time.Now().Add(365 * 24 * time.Hour).Format("2006-01-02 15:04:05"), - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - "status": 0, - } - tp := "购买" - if user.GetString("expiration_time") != "" { - data["old_expiration_time"] = user.GetString("expiration_time") - - t, e := time.Parse("2006-01-02 15:04:05", user.GetString("expiration_time")) - fmt.Println(e, "时间创建失败") - if t.Unix() >= time.Now().Unix() { - tp = "续订" - data["expiration_time"] = t.Add(365 * 24 * time.Hour).Format("2006-01-02 15:04:05") - } - - } - - if user.GetCeilInt("provider_id") != 0 { - data["provider_id"] = user.GetCeilInt("provider_id") - data["amount"] = 36000 - //tp=tp - } - //data["amount"] = 1 - - if user.GetCeilInt("salesman_id") != 0 { - data["salesman_id"] = user.GetCeilInt("salesman_id") - } - data["name"] = companyName + tp + "1年VIP会员" - - jsParams, e := wechat.WxPay.GetJsOrder(data.GetCeilInt64("amount"), that.Config.GetString("wechatAppID"), wc.GetString("openid"), data.GetString("name"), data.GetString("sn"), that.Config.GetString("wechatAppNotifyUrl")) - if e != nil { - fmt.Println(e) - that.Display(4, e) - return - } - re := that.Db.Insert("vip_order", data) - fmt.Println(re) - that.Display(0, jsParams) - }, - "callback": func(that *Context) { - data, e := wechat.WxPay.CallbackJsOrder(that.Req) - if e != nil { - fmt.Println(e) - //that.Display(4,e) - - fmt.Println("返回数据错误", e) - return - } - - sn := data.OutTradeNo - amount := int64(data.Amount.Total) - state := data.TradeState - //state:="SUCCESS" - //data := Map{"ces": "das"} - //sn := that.Req.FormValue("sn") - //amount := ObjToCeilInt64(that.Req.FormValue("amount")) - - if state != "SUCCESS" { - - fmt.Println("购买返回失败", data) - return - } - - vipOrder := that.Db.Get("vip_order", "*", Map{"sn": sn}) - - if vipOrder == nil { - - fmt.Println("找不到订单", vipOrder, data) - return - } - user := that.Db.Get("user", "*", Map{"id": vipOrder.GetCeilInt("user_id")}) - if user == nil { - - fmt.Println("找不到用户", vipOrder, data) - return - } - if vipOrder.GetCeilInt64("amount") != amount { - - fmt.Println("金额不符", user, vipOrder, amount, data) - return - } - - that.Db.Update("vip_order", Map{"status": 1}, Map{"id": vipOrder.GetCeilInt("id")}) - - idata := Map{"expiration_time": time.Now().Add(365 * 24 * time.Hour).Format("2006-01-02 15:04:05")} - if user.GetString("expiration_time") != "" { - - t, e := time.Parse("2006-01-02 15:04:05", user.GetString("expiration_time")) - fmt.Println(e, "时间创建失败") - if t.Unix() >= time.Now().Unix() { - idata["expiration_time"] = t.Add(365 * 24 * time.Hour).Format("2006-01-02 15:04:05") - } - } - - re := that.Db.Update("user", idata, Map{"id": user.GetCeilInt("id")}) - if re == 0 { - fmt.Println("购买失败", user, vipOrder, re, data) - - return - } - fmt.Println("成功购买", user, vipOrder, re, data) - - //购买成功后赠送10张券 - //user_id := that.Session("user_id").Data - data2 := Map{ - "user_id": that.Session("user_id").Data, - "coupon_id": 1, - "code_no": "SN" + time.Now().Format("20060102150405") + getSn(), - "effective_start_time[#]": "NOW()", - "effective_end_time": time.Now().AddDate(0, 6, 0).Format("2006-01-02 15:04:05"), - "source_type": 1, - "status": 0, - "admin_id": user.GetCeilInt("admin_id"), - "create_time[#]": "NOW()", - } - for n := 0; n < 5; n++ { - that.Db.Insert("coupon_user", data2) - } - data2["effective_end_time"] = time.Now().AddDate(1, 0, 0).Format("2006-01-02 15:04:05") - for n := 0; n < 5; n++ { - that.Db.Insert("coupon_user", data2) - } - return - - }, - "export": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - buy_date := ObjToStr(that.Req.FormValue("buy_date")) - if buy_date == "" { - that.Display(3, "请求参数异常") - return - } - - //data := that.Db.Query("SELECT vo.sn 订单号, vo.`name` 订单名, vo.user_id 购买用户ID,usr.`name` 购买用户名, usr.phone 购买用户电话, cp.id 企业ID, cp.`name` 企业名,\nvo.expiration_time 过期时间, vo.old_expiration_time 订购前到期时间, vo.amount `订单金额_单位(分)`,\nvo.salesman_id 业务员ID,sm.`name` 业务员名, sm.phone 业务员电话, pv.`name` 服务商名 \nFROM vip_order vo\nLEFT JOIN salesman sm ON sm.id = vo.salesman_id\nLEFT JOIN provider pv ON pv.id = vo.provider_id\nLEFT JOIN `user` usr ON usr.id = vo.user_id\nLEFT JOIN company cp ON cp.id = vo.company_id\nWHERE vo.`status` = 1 AND vo.create_time >= '" + buy_date + "' \nORDER BY vo.create_time") - //data := that.Db.Query("SELECT vo.sn 订单号, vo.`name` 订单名, vo.user_id 购买用户ID,usr.`name` 购买用户名, usr.phone 购买用户电话, cp.id 企业ID, cp.`name` 企业名,\nvo.expiration_time 过期时间, vo.old_expiration_time 订购前到期时间, vo.amount `订单金额_单位(分)`,\nvo.salesman_id 业务员ID,sm.`name` 业务员名, sm.phone 业务员电话, pv.`name` 服务商名 \nFROM vip_order vo\n" + - // "LEFT JOIN salesman sm ON sm.id = vo.salesman_id\nLEFT JOIN provider pv ON pv.id = vo.provider_id\nLEFT JOIN `user` usr" + - // " ON usr.id = vo.user_id\nLEFT JOIN company cp ON cp.id = vo.company_id\nWHERE" + - // " vo.`status` = 1 AND vo.create_time >= ? \nORDER BY vo.create_time",buy_date) - - data := that.Db.Select("vip_order", Map{"[>]salesman": "salesman.id=vip_order.salesman_id", - "[>]provider": "provider.id = vip_order.provider_id", - "[>]user": "user.id = vip_order.user_id", - "[>]company": "company.id = vip_order.company_id", - }, "vip_order.sn 订单号, vip_order.`name` 订单名, vip_order.user_id 购买用户ID,user.`name` 购买用户名, user.phone 购买用户电话, company.id 企业ID, company.`name` 企业名,\nvip_order.expiration_time 过期时间, vip_order.amount `订单金额_单位(分)`,\nvip_order.salesman_id 业务员ID,salesman.`name` 业务员名, salesman.phone 业务员电话, provider.`name` 服务商名", - Map{"AND": Map{"vip_order.status": 1, "vip_order.create_time[>=]": buy_date}, "ORDER": "vip_order.create_time DESC"}) - - if len(data) == 0 { - that.Display(0, "今日没有vip购买信息数据") - return - } - - var titleList []string - if data != nil { - m := data[0] - for k, _ := range m { - titleList = append(titleList, k) - } - } - - var dataList []Map - for _, v := range data { - dataList = append(dataList, v) - } - - //打印最后一次sql语句 - //that.Db.LastQuery - //请求的数据 - //that.Db.LastData - //that.Db.LastErr - //appIns.Db.Select("company",common.Map{"[<>]user":"company.id=user.company_id"},"company.id as id",common.Map{"AND":common.Map{"id[!]":nil},"ORDER":"id DESC"}) - //appIns.Db.Query("select * from user where id = ? and name = ?",common.Slice{1,"nn"}) - - //titleList:= []string{"aaaa", "vvvvv", "dddd", "eeeee", "gfgggg"} - DataToExcel(that.Resp, that.Req, titleList, dataList, buy_date+"vip购买信息分析数据") - }, -} diff --git a/example/app/websocket.go b/example/app/websocket.go deleted file mode 100644 index 0c9250e..0000000 --- a/example/app/websocket.go +++ /dev/null @@ -1,72 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "golang.org/x/net/websocket" - "time" -) - -type WSClient struct { - ID string - *websocket.Conn - time.Time - DeadTime time.Time - IsDead bool -} - -//websocket链接池 -var WsUserMap = map[string][]*WSClient{} -var WSMasterID = "" - -func WsSendMsg(ws *WSClient, data Map) bool { - if WsUserMap[ws.ID] == nil { - return false - } - - for _, v := range WsUserMap[ws.ID] { - if v.IsDead || v == ws { - //WsUserMap[ws.ID]=WsUserMap[ws.ID][:k] - continue - } - - str := data.ToJsonString() - v.Conn.Write([]byte(str)) - - } - - return true -} - -var WebsocketCtr = Ctr{ - "conn": func(this *Context) { - id := this.SessionId - if WsUserMap[id] == nil { - WsUserMap[id] = []*WSClient{} - } - hdler := websocket.Handler(func(ws *websocket.Conn) { - - client := &WSClient{ID: id, Conn: ws, Time: time.Now(), DeadTime: time.Now(), IsDead: false} - - WsUserMap[id] = append(WsUserMap[id], client) - var message string - for true { - err := websocket.Message.Receive(ws, &message) - if err != nil { - client.DeadTime = time.Now() - client.IsDead = true - return - } - - data := Map{} - data.JsonToMap(message) - WsSendMsg(client, data) - //switch data.GetString("type") { - // - //} - - } - }) - hdler.ServeHTTP(this.Resp, this.Req) - }, -} diff --git a/example/app/wechath5.go b/example/app/wechath5.go deleted file mode 100644 index d0dd58d..0000000 --- a/example/app/wechath5.go +++ /dev/null @@ -1,287 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "code.hoteas.com/golang/hotime/dri/wechat" - "time" -) - -var Wechath5 = Ctr{ - - //微信注册,0已经完整的注册了,1还没有注册 - "code": func(that *Context) { - - if that.Req.FormValue("code") == "" { - that.Display(3, "参数不足") - return - } - - appid, resToken, userInfo, err := wechat.H5Program.GetUserInfo(that.Req.FormValue("code")) - - if err != nil { - that.Display(4, err) - return - } - //此次获取的微信信息 - wechatInfo := Map{ - "openid": userInfo.OpenID, - "acttoken": resToken.AccessToken, - "retoken": resToken.RefreshToken, - "appid": appid, - "unionid": userInfo.Unionid, - "nickname": FilterEmoji(userInfo.Nickname), - "avatar": userInfo.HeadImgURL, - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - "type": 1, - } - - userId := 0 - - //这个defer放到上面,防止出现用户第一次登陆的时候出现不返回company和salesman的情况 - //如果有则直接返回用户信息到微信小程序里 - defer func() { - if userId != 0 { - user := that.Db.Get("user", "*", Map{"id": userId}) - if user == nil { - that.Display(4, "获取个人信息失败") - return - } - delete(user, "password") - company := that.Db.Get("company", "id,name", Map{"id": user.GetCeilInt("company_id")}) - - //消除company没有创建的影响 - if company == nil { - companyId := that.Db.Insert("company", Map{ - "user_id": user["id"], - "provider_id": user["provider_id"], - "salesman_id": user["salesman_id"], - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - }) - user["company_id"] = companyId - that.Db.Update("user", Map{"company_id": companyId}, Map{"id": user.GetCeilInt("id")}) - company = that.Db.Get("company", "*", Map{"id": user.GetCeilInt("company_id")}) - } - salesman := that.Db.Get("salesman", "id,name", Map{"id": user.GetCeilInt("salesman_id")}) - provider := that.Db.Get("provider", "id,name", Map{"id": user.GetCeilInt("provider_id")}) - - user["company"] = company - user["salesman"] = salesman - user["provider"] = provider - - that.Display(0, user) - } - }() - - defer func() { - - //有sn就关联业务员 - parentId := ObjToInt(that.Req.FormValue("parent_id")) - if parentId == 0 { - return - } - if userId == 0 || userId == parentId { - return - } - puser := that.Db.Get("user", "`index`,id", Map{"id": parentId}) - if puser == nil { - return - } - user := that.Db.Get("user", "parent_id", Map{"id": userId}) - if user.GetCeilInt("parent_id") != 0 { - return - } - index1 := puser.GetString("index") - if index1 == "," { - index1 = index1 + ObjToStr(parentId) + "," - } - - //2022/5/11 zpw 添加字段:用户关联parenid的时间 (join_parent_time) - that.Db.Update("user", Map{"parent_id": parentId, "index": index1 + ObjToStr(userId) + ",", "join_parent_time[#]": "NOW()"}, Map{"id": userId}) - //在这里做判断 能否通过分享领券 - //如果通过邀请获得的券超过了三张则不再赠送 - //赠送一张券 - data := Map{ - "user_id": parentId, - "coupon_id": 1, - "code_no": "SN" + time.Now().Format("20060102150405") + getSn(), - "effective_start_time[#]": "NOW()", - "effective_end_time": time.Now().AddDate(0, 6, 0).Format("2006-01-02 15:04:05"), - "source_type": 3, - "status": 0, - "admin_id": user.GetCeilInt("admin_id"), - "create_time[#]": "NOW()", - } - //先判断是否领取过 source_type=3 是通过拉新赠送的券 - couponCount := that.Db.Count("coupon_user", Map{"AND": Map{"user_id": parentId, "source_type": 3}}) - if couponCount < 3 { - that.Db.Insert("coupon_user", data) - } - - }() - //最后验证服务商是否绑定 - defer func() { - //有sn就关联业务员 - sn := that.Req.FormValue("sn") - if sn == "" { - return - } - if userId == 0 { - return - } - - salesman := that.Db.Get("salesman", "*", Map{"sn": sn}) - if salesman.GetCeilInt("id") == 0 { - return - } - - user := that.Db.Get("user", "*", Map{"id": userId}) - if user == nil { - return - } - - //用户都有企服人员关联 - if user.GetCeilInt("salesman_id") != 0 { - - return - } - //用户没有企服商id - //2022/5/11 zpw 添加字段:用户关联企服商业务人员的时间 (join_salesman_time) - that.Db.Update("user", Map{"salesman_id": salesman.GetCeilInt64("id"), "provider_id": salesman.GetCeilInt64("provider_id"), "join_salesman_time[#]": "NOW()"}, Map{"id": user.GetCeilInt64("id")}) - if user.GetCeilInt("company_id") == 0 { - return - } - //绑定企业 - that.Db.Update("company", Map{"salesman_id": salesman.GetCeilInt64("id"), "provider_id": salesman.GetCeilInt64("provider_id")}, Map{"id": user.GetCeilInt64("company_id")}) - - }() - - wechat := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": userInfo.OpenID, "del_flag": 0}}) - - if wechat != nil { - //有用户直接返回 - if wechat.GetCeilInt("user_id") != 0 { - - that.Db.Update("user", Map{"login_time[#]": "now()"}, Map{"id": wechat.GetCeilInt("user_id")}) - that.Session("wechat_id", wechat.GetCeilInt("id")) - that.Session("user_id", wechat.GetCeilInt("user_id")) - - userId = wechat.GetCeilInt("user_id") - //that.Display(0, "登录成功") - return - } - //没有用户继续查询数据库看是否有其他unionid - wechat1 := that.Db.Get("wechat", "*", Map{"AND": Map{"unionid": userInfo.Unionid, "openid[!]": userInfo.OpenID, "user_id[>]": 0, "del_flag": 0}}) - - //其他表有该数据,则更新当前表数据信息 - if wechat1 != nil { - - wechatInfo["user_id"] = wechat1.GetCeilInt("user_id") - that.Db.Update("wechat", wechatInfo, Map{"id": wechat.GetCeilInt("id")}) - - that.Db.Update("user", Map{"login_time[#]": "now()"}, Map{"id": wechat1.GetCeilInt("user_id")}) - that.Session("wechat_id", wechat.GetCeilInt("id")) - that.Session("user_id", wechatInfo.GetCeilInt("user_id")) - - userId = wechatInfo.GetCeilInt("user_id") - //that.Display(0, "登录成功") - return - } - - //其他表也没有当前信息,则生成user表,并更新当前用户,一般不会走到这里来 - user := Map{ - "nickname": wechatInfo.GetString("nickname"), - "avatar": wechatInfo.GetString("avatar"), - "index": ",", - "create_time[#]": "now()", - "modify_time[#]": "now()", - "login_time[#]": "now()", - "del_flag": 0, - } - user["id"] = that.Db.Insert("user", user) - //创建企业 - user["company_id"] = that.Db.Insert("company", Map{ - "user_id": user["id"], - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - }) - that.Db.Update("user", Map{"company_id": user["company_id"]}, Map{"id": user["id"]}) - - wechatInfo["user_id"] = user.GetCeilInt("id") - - that.Db.Update("wechat", wechatInfo, Map{"id": wechat.GetCeilInt("id")}) - - that.Session("wechat_id", wechat.GetCeilInt("id")) - that.Session("user_id", wechatInfo.GetCeilInt("user_id")) - - userId = wechatInfo.GetCeilInt("user_id") - //that.Display(0, "登录成功") - return - } - user := Map{ - "nickname": wechatInfo.GetString("nickname"), - "avatar": wechatInfo.GetString("avatar"), - "index": ",", - "create_time[#]": "now()", - "modify_time[#]": "now()", - "login_time[#]": "now()", - "del_flag": 0, - } - user["id"] = that.Db.Insert("user", user) - user["company_id"] = that.Db.Insert("company", Map{ - "user_id": user["id"], - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - }) - - that.Db.Update("user", Map{"company_id": user["company_id"]}, Map{"id": user["id"]}) - - wechatInfo["user_id"] = user.GetCeilInt("id") - - wechatInfo["id"] = that.Db.Insert("wechat", wechatInfo) - - if wechatInfo.GetCeilInt("id") == 0 { - that.Display(4, "创建用户失败") - return - } - - that.Session("wechat_id", wechatInfo.GetCeilInt("id")) - that.Session("user_id", wechatInfo.GetCeilInt("user_id")) - - userId = wechatInfo.GetCeilInt("user_id") - //that.Display(0, "登录成功") - - }, - //网页签名 - "sign": func(that *Context) { - - signUrl := that.Req.FormValue("url") - if signUrl == "" { - that.Display(3, "参数不足") - return - } - - cfg1, e := wechat.H5Program.GetSignUrl(signUrl) - - if e != nil { - that.Display(4, e) - return - } - - sign := Map{ - "appId": cfg1.AppID, - "timestamp": cfg1.Timestamp, - "nonceStr": cfg1.NonceStr, - "signature": cfg1.Signature, - } - - that.Display(0, sign) - - }, -} diff --git a/example/app/wechatmini.go b/example/app/wechatmini.go deleted file mode 100644 index 402f661..0000000 --- a/example/app/wechatmini.go +++ /dev/null @@ -1,167 +0,0 @@ -package app - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "code.hoteas.com/golang/hotime/dri/wechat" - "fmt" -) - -var WechatMini = Ctr{ - "getphone": func(that *Context) { - - //sessionKey := that.Req.FormValue("sessionkey") - - if that.Session("wechat_id").Data == nil { - that.Display(2, "请先登录") - return - } - - encryptedData := that.Req.FormValue("encryptedData") - iv := that.Req.FormValue("iv") - - if encryptedData == "" || iv == "" { - that.Display(3, "参数不足") - return - } - - wechatIns := that.Db.Get("wechat", "sessionkey", Map{"id": that.Session("wechat_id").ToCeilInt()}) - _, re, e := wechat.MiniProgram.GetPhoneNumber(wechatIns.GetString("sessionkey"), encryptedData, iv) - - if e != nil { - that.Display(4, e) - return - } - //临时存储用于校验 - that.Session("wechat_phone", re.PhoneNumber) - that.Display(0, re.PhoneNumber) - - }, - //检查是否已经有用户登录了,如果有直接登录,如果没有则查询unionid,有则直接返回用户信息,没有则返回null - "code": func(that *Context) { - - code := that.Req.FormValue("code") - if code == "" { - that.Display(3, "缺少code") - return - } - - appid, re, e := wechat.MiniProgram.GetBaseUserInfo(code) - fmt.Println(re) - if e != nil { - that.Display(4, e) - return - } - - wchat := Map{"openid": re.OpenID, - "appid": appid, - "sessionkey": re.SessionKey, - "unionid": re.UnionID, - "modify_time[#]": "now()", - "del_flag": 0, - "type": 2, - } - - userId := 0 - - //如果有则直接返回用户信息到微信小程序里 - defer func() { - if userId != 0 { - user := that.Db.Get("user", "*", Map{"id": userId}) - company := that.Db.Get("company", "id,name", Map{"id": user.GetCeilInt("company_id")}) - salesman := that.Db.Get("salesman", "id,name", Map{"id": user.GetCeilInt("salesman_id")}) - provider := that.Db.Get("provider", "id,name", Map{"id": user.GetCeilInt("provider_id")}) - if user == nil { - that.Display(4, "获取个人信息失败") - return - } - delete(user, "password") - user["company"] = company - user["salesman"] = salesman - user["provider"] = provider - that.Display(0, user) - } - }() - - wechat := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": re.OpenID, "user_id[!]": nil, "del_flag": 0}}) - //有该用户,则登录成功 - if wechat != nil { - - that.Session("wechat_id", wechat.GetCeilInt("id")) - that.Session("user_id", wechat.GetCeilInt("user_id")) - //更新用户信息 - that.Db.Update("wechat", wchat, Map{"id": wechat.GetCeilInt("id")}) - //that.Display(0, "登录成功") - userId = wechat.GetCeilInt("user_id") - return - } - - //如果其他人有相关信息,则直接取用 - wechat = that.Db.Get("wechat", "*", Map{"AND": Map{"unionid": re.UnionID, "user_id[!]": nil, "del_flag": 0}}) - if wechat != nil { - wechat1 := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": re.OpenID, "del_flag": 0}}) - //有该信息,但没有相关的用户信息,则直接绑定其他的信息上来 - if wechat1 != nil { - - //更新用户信息 - that.Db.Update("wechat", wchat, Map{"id": wechat1.GetCeilInt("id")}) - - that.Session("wechat_id", wechat1.GetCeilInt("id")) - that.Session("user_id", wechat.GetCeilInt("user_id")) - //that.Display(0, "登录成功") - userId = wechat.GetCeilInt("user_id") - return - } - //没有相关用户信息,则新建wechat并完成登录 - wchat["user_id"] = wechat["user_id"] - wchat["create_time[#]"] = "now()" - - wchat["id"] = that.Db.Insert("wechat", wchat) - if wchat.GetCeilInt("id") == 0 { - - that.Display(5, "创建wechat失败") - return - } - - that.Session("wechat_id", wchat.GetCeilInt("id")) - that.Session("user_id", wchat.GetCeilInt("user_id")) - - userId = wchat.GetCeilInt("user_id") - //that.Display(0, "登录成功") - return - } - - user := Map{ - - "create_time[#]": "now()", - "modify_time[#]": "now()", - "login_time[#]": "now()", - "del_flag": 0, - } - user["id"] = that.Db.Insert("user", user) - - user["company_id"] = that.Db.Insert("company", Map{ - "user_id": user["id"], - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - }) - - that.Db.Update("user", Map{"company_id": user["company_id"]}, Map{"id": user["id"]}) - - wchat["user_id"] = user.GetCeilInt("id") - wchat["create_time[#]"] = "now()" - - wchat["id"] = that.Db.Insert("wechat", wchat) - if wchat.GetCeilInt("id") == 0 { - that.Display(5, "登录失败") - return - } - - that.Session("wechat_id", wchat.GetCeilInt("id")) - that.Session("user_id", wchat.GetCeilInt("user_id")) - - userId = wchat.GetCeilInt("user_id") - //that.Display(0, nil) - }, -} diff --git a/example/config/config.json b/example/config/config.json deleted file mode 100644 index eb3e762..0000000 --- a/example/config/config.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "aliyunCode": "06c6a07e89dd45c88de040ee1489eef7", - "avatarPath": "avatar/2006/01/02/", - "cache": { - "db": { - "db": false, - "session": true - }, - "memory": { - "db": true, - "session": true, - "timeout": 7200 - } - }, - "codeConfig": [ - { - "config": "config/admin.json", - "mode": 0, - "name": "", - "rule": "config/adminRule.json", - "table": "admin" - } - ], - "crossDomain": "", - "db": { - "mysql": { - "host": "192.168.2.50", - "name": "zct_v2_v2", - "password": "kct@2021", - "port": "3306", - "prefix": "", - "user": "root" - } - }, - "defFile": [ - "index.html", - "index.htm" - ], - "error": { - "1": "内部系统异常", - "2": "访问权限异常", - "3": "请求参数异常", - "4": "数据处理异常", - "5": "数据结果异常", - "6": "需要进一步获取个人信息" - }, - "imgPath": "img/2006/01/02/", - "mode": 2, - "port": "8081", - "sessionName": "HOTIME", - "smsKey": "b0eb4bf0198b9983cffcb85b69fdf4fa", - "smsLogin": "【政策通】您的验证码为:{code},请在5分钟内使用,切勿将验证码泄露于他人,如非本人操作请忽略。", - "tencentId": "AKIDOgT8cKCQksnY7yKATaYO7j9ORJzSYohP", - "tencentKey": "GNXgjdN4czA9ya0FNMApVJzTmsmU0KSN", - "tpt": "tpt", - "wechatAppID": "wxdcc8d6360661a179", - "wechatAppNotifyUrl": "https://zcth5.kct.cn/app/vip_order/callback", - "wechatAppSecret": "4d793683ca915264663a9c9a33530c3c", - "wechatMiniAppID": "wx1c795e883b5b54c4", - "wechatMiniAppSecret": "d2bec12d1fa4d8b5714ccbed1c0671e4", - "wechatPayMApiV3Key": "dh33tyagd1623623GDYGGDhe1d9dh171", - "wechatPayMCHID": "1624888906", - "wechatPayPrivateKey": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC1vs3i/4sozxsK\noiS2S95rl+csLXQDugg23bcAVzXr7ZeTM/h81sCwraQDMnAJ/V3n7LxFAZeaFwLb\nyrkQ3lv4IEtWVgjVUkjkhvKGWcAp16Q/grOpxWmmn+VlW5ZGwQQ4DL4sC6BeEyxu\nUdtZ7UVc9lqsQX01R0oiegItJGPMMXNgeLFDEeoAwyIQcL0VG2bND7qrEVeQkLTj\nFm9ZkSb0LySPkSgqxMlSpiX1MS+wWWIHpq91CvdVHNowaGFA7ajU3RztbFAuxdpl\ng9RIocbrY1QwGXouQTEOUI2KZaES9rAa2lD6oWom4mRYiQ1oNO12XlUTcKsr84P5\nTq50dOYFAgMBAAECggEAQUns/mncnOlhhn1fANnaaf5kvlsJvTj8MHGPhyDNLxbo\nB6p4zqf7Cr0mGTvqQbxyGpnRvFxpEKLJlRmLSAMJOOapCbfYboGjy+yqfRcK0D02\nNNaIIinX3VK9fp7bKkm2cUgqnPoEPydWI79mNDTnYRDi29Se3R/iAuafl4XmD/js\nOKWG5tlXEatZ+gDbhnug4hp3xEGm4pbTS1HedV7HgYiKpxAT9uc/YmiHelZUUqlG\nwa1Nda2J88pzCSZX6TsRyY9UF/sjorxSNZGfj+5waeYMccj0Cx4uEQYgBv5tm+I+\nFTRgo/riM5gT9oRTnuNuzUrNwUNLyUsldvdQdlheNQKBgQDqwhrW52q3xClFLXR4\nHu9cTPt/p96MYE+xBllO/M9VFcG/hT++9R9l26+o26Lu+iIF5euDQiYSyURniGim\nWfV0I2q8HufhPLJBamvxRPI0V8LHwbY7c6HKnRR3eDAWAVYIcmsV4RLS67bsgtnr\nCgaFUDHXnpPKjxp1b4M5K3GqxwKBgQDGMLgAQn0a3nZwquPD4D+6tjy5xTxDX4Op\nULHBQheX0lBAR9Kcurzy4ca+T5xsyHd6SPwQxobRPei/3TBmc18J1T3nxJkTbEEP\nqy8k7MOWW2es3ou4CRL5lVKPx4YDWb5iT7X3Ue55JjPFAoj6FBOHxdvRQnDYsLFy\nSuSHPc280wKBgQCqfvCZNZcnAbtrd3jIKMd0hKB/dP7HesdF7TN9j1RRGi0NmIvU\ndxgnlOa9v05VO6rsF7D1MlyOdkhM3SAL+PewMmy5VcTYq4lWwyDEKGuzoi1fgIuG\nIBPYID8WCV77DFtcZSTqzf0q3HCM0vfLoQtdVQHt9Ein60ivE579LVUvTwKBgFid\nefgrwnJcG8serb5sKzKZvyc1CE/7igwPl5sYqSHqGJXVR1dqq4dR6iI3yHJfZASa\nU5JQogE21DXNeZGlbk4gOZDCt8sWcTTHTsoMzxsQfZeu3fwImqJb4NGG3eXrn5On\nnm4aBS3IJgelrYdbqKvhjPrQ4VISFxVKZUoPGUmfAoGARZbtbyl3s8cAExWe9dK6\nyWdkA3M2wR4n623W13rTQDc3D7p/hmlgB2x8it88m+580326G4qgwdUbG93EW1WQ\nahbkkcmdxzHgPVJdsyx22fR0TkeT1gjMpoSh4k3HOsbZE4EvlI459yE9fTSLBq2A\nFzGjYRpBTlRyrsSEhyVg4G0=\n-----END PRIVATE KEY-----", - "wechatPaySerialNo": "7A92D2D26D212D6BF934BDB10D547274807C3DDB", - "wxFilePath": "wxfile/2006/01/02/" -} \ No newline at end of file diff --git a/example/config/configNote.json b/example/config/configNote.json deleted file mode 100644 index 8c83367..0000000 --- a/example/config/configNote.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "cache": { - "db": { - "db": "默认false,非必须,缓存数据库,启用后能减少数据库的读写压力", - "session": "默认true,非必须,缓存web session,同时缓存session保持的用户缓存", - "timeout": "默认60 * 60 * 24 * 30,非必须,过期时间,超时自动删除" - }, - "memory": { - "db": "默认true,非必须,缓存数据库,启用后能减少数据库的读写压力", - "session": "默认true,非必须,缓存web session,同时缓存session保持的用户缓存", - "timeout": "默认60 * 60 * 2,非必须,过期时间,超时自动删除" - }, - "redis": { - "db": "默认true,非必须,缓存数据库,启用后能减少数据库的读写压力", - "host": "默认服务ip:127.0.0.1,必须,如果需要使用redis服务时配置,", - "password": "默认密码空,必须,如果需要使用redis服务时配置,默认密码空", - "port": "默认服务端口:6379,必须,如果需要使用redis服务时配置,", - "session": "默认true,非必须,缓存web session,同时缓存session保持的用户缓存", - "timeout": "默认60 * 60 * 24 * 15,非必须,过期时间,超时自动删除" - }, - "注释": "可配置memory,db,redis,默认启用memory,默认优先级为memory\u003eredis\u003edb,memory与数据库缓存设置项一致,缓存数据填充会自动反方向反哺,加入memory缓存过期将自动从redis更新,但memory永远不会更新redis,如果是集群建议不要开启memory,配置即启用" - }, - "codeConfig": [ - "注释:配置即启用,非必须,默认无", - { - "config": "默认config/app.json,必须,接口描述配置文件", - "mode": "默认0,非必须,0为内嵌代码模式,1为生成代码模式", - "name": "默认无,非必须,有则生成代码到此目录,无则采用缺省模式使用表名,如设置为:admin,将在admin目录生成包名为admin的代码", - "rule": "默认config/rule.json,非必须,有则按改规则生成接口,无则按系统内嵌方式生成", - "table": "默认admin,必须,根据数据库内当前表名做为用户生成数据" - } - ], - "crossDomain": "默认空 非必须,空字符串为不开启,如果需要跨域设置,auto为智能开启所有网站允许跨域,http://www.baidu.com为指定域允许跨域", - "db": { - "mysql": { - "host": "默认127.0.0.1,必须,数据库ip地址", - "name": "默认test,必须,数据库名称", - "password": "默认root,必须,数据库密码", - "port": "默认3306,必须,数据库端口", - "prefix": "默认空,非必须,数据表前缀", - "slave": { - "host": "默认127.0.0.1,必须,数据库ip地址", - "name": "默认test,必须,数据库名称", - "password": "默认root,必须,数据库密码", - "port": "默认3306,必须,数据库端口", - "user": "默认root,必须,数据库用户名", - "注释": "从数据库配置,mysql里配置slave项即启用主从读写,减少数据库压力" - }, - "user": "默认root,必须,数据库用户名", - "注释": "除prefix及主从数据库slave项,其他全部必须" - }, - "sqlite": { - "path": "默认config/data.db,必须,数据库位置" - }, - "注释": "配置即启用,非必须,默认使用sqlite数据库" - }, - "defFile": "默认访问index.html或者index.htm文件,必须,默认访问文件类型", - "error": { - "1": "内部系统异常,在环境配置,文件访问权限等基础运行环境条件不足造成严重错误时使用", - "2": "访问权限异常,没有登录或者登录异常等时候使用", - "3": "请求参数异常,request参数不满足要求,比如参数不足,参数类型错误,参数不满足要求等时候使用", - "4": "数据处理异常,数据库操作或者三方请求返回的结果非正常结果,比如数据库突然中断等时候使用", - "5": "数据结果异常,一般用于无法给出response要求的格式要求下使用,比如response需要的是string格式但你只能提供int数据时", - "注释": "web服务内置错误提示,自定义异常建议10开始" - }, - "logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置", - "logLevel": "默认0,必须,0关闭,1打印,日志等级", - "mode": "默认0,非必须,0生产模式,1,测试模式,2开发模式,3内嵌代码模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存", - "modeRouterStrict": "默认false,必须,路由严格模式false,为大小写忽略必须匹配,true必须大小写匹配", - "port": "默认80,必须,web服务开启Http端口,0为不启用http服务,默认80", - "sessionName": "默认HOTIME,必须,设置session的cookie名", - "tlsCert": "默认空,非必须,https证书", - "tlsKey": "默认空,非必须,https密钥", - "tlsPort": "默认空,非必须,web服务https端口,0为不启用https服务", - "tpt": "默认tpt,必须,web静态文件目录,默认为程序目录下tpt目录", - "webConnectLogFile": "无默认,非必须,webConnectLogShow开启之后才能使用,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置", - "webConnectLogShow": "默认true,非必须,访问日志如果需要web访问链接、访问ip、访问时间打印,false为关闭true开启此功能" -} \ No newline at end of file diff --git a/example/config/data.db b/example/config/data.db deleted file mode 100644 index b33f3b4..0000000 Binary files a/example/config/data.db and /dev/null differ diff --git a/example/main.go b/example/main.go deleted file mode 100644 index 89a2ece..0000000 --- a/example/main.go +++ /dev/null @@ -1,89 +0,0 @@ -package main - -import ( - . "code.hoteas.com/golang/hotime" - "code.hoteas.com/golang/hotime/dri/aliyun" - "code.hoteas.com/golang/hotime/dri/ddsms" - "code.hoteas.com/golang/hotime/dri/tencent" - "code.hoteas.com/golang/hotime/dri/wechat" - "code.hoteas.com/golang/hotime/example/app" - "code.hoteas.com/golang/hotime/example/provider" - //. "code.hoteas.com/golang/hotime/common" - "fmt" - "time" -) - -// -func main() { - date, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00") - fmt.Println(date, date.Unix()) - //fmt.Println("开始测试") - //t:=common.Map{"t":1652425167} - //fmt.Println(t.GetTime("t")) - //t["t"]=1652425167123 - //fmt.Println(t.GetTime("t")) - //t["t"]=1652425167123456 - //fmt.Println(t.GetTime("t")) - //t["t"]=1652425167123456789 - //fmt.Println(t.GetTime("t")) - //fmt.Println("开始测试2") - //t["t"]="2006-01-02 15:04:05" - //fmt.Println(t.GetTime("t")) - //t["t"]="2006-01-02 15" - //fmt.Println(t.GetTime("t")) - //t["t"]="2006-01-02" - //fmt.Println(t.GetTime("t")) - //t["t"]="2006-01" - //fmt.Println(t.GetTime("t")) - //t["t"]="2006-01" - //fmt.Println(t.GetTime("t")) - //t["t"]="2006" - //fmt.Println(t.GetTime("t")) - // - //t["t"]="06" - //fmt.Println(t.GetTime("t")) - - //fmt.Println("0123456"[1:7]) - appIns := Init("config/config.json") - - aliyun.Company.Init(appIns.Config.GetString("aliyunCode")) - - //初始化短信配置 - ddsms.DDY.Init(appIns.Config.GetString("smsKey")) - //初始化公众号配置 - wechat.H5Program.Init(appIns.Config.GetString("wechatAppID"), appIns.Config.GetString("wechatAppSecret")) - //初始化小程序配置 - wechat.MiniProgram.Init(appIns.Config.GetString("wechatMiniAppID"), appIns.Config.GetString("wechatMiniAppSecret")) - //初始化小程序及公众号支付配置 - wechat.WxPay.Init(appIns.Config.GetString("wechatPayMCHID"), - appIns.Config.GetString("wechatPaySerialNo"), - appIns.Config.GetString("wechatPayMApiV3Key"), - appIns.Config.GetString("wechatPayPrivateKey")) - tencent.Tencent.Init(appIns.Config.GetString("tencentId"), appIns.Config.GetString("tencentKey")) - - //用户侧访问前设置 - appIns.SetConnectListener(func(that *Context) (isFinished bool) { - //发送短信校验 - //that.RespFunc = func() { - // go func(Form url.Values, RespData common.Map) { - // fmt.Println(Form) - // fmt.Println(RespData) - // }(that.Req.Form, that.RespData) - // - //} - - return isFinished - }) - - //appIns.SetConnectListener(func(that *Context) (isFinished bool) { - // - // return isFinished - //}) - //appIns.Db.Action(func(db db.HoTimeDB) (isSuccess bool) { - // return isSuccess - //}) - appIns.Run(Router{ - "provider": provider.Project, - "app": app.Project, - }) -} diff --git a/example/provider/company.go b/example/provider/company.go deleted file mode 100644 index fc00461..0000000 --- a/example/provider/company.go +++ /dev/null @@ -1,144 +0,0 @@ -package provider - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "code.hoteas.com/golang/hotime/dri/aliyun" - "fmt" -) - -var CompanyCtr = Ctr{ - - "search": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - keywords := that.Req.FormValue("keywords") - if keywords == "" { - keywords = that.Req.FormValue("company_name") - } - if keywords == "" { - keywords = that.Req.FormValue("name") - } - - if len(keywords) < 2 { - that.Display(0, Slice{}) - return - } - - res, err := aliyun.Company.GetCompanyList(keywords) - if err != nil { - fmt.Println(err) - that.Display(0, Slice{}) - return - } - if res.GetCeilInt64("status") != 200 { - fmt.Println(err) - that.Display(0, Slice{}) - return - } - - that.Display(0, res.GetMap("data").GetSlice("list")) - }, - "search_info": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - name := that.Req.FormValue("name") - - if len(name) < 2 { - that.Display(3, "找不到企业") - return - } - - res, err := aliyun.Company.GetCompanyBaseInfo(name) - if err != nil { - fmt.Println(err) - that.Display(4, "查询失败") - return - } - if res.GetBool("status") != true { - fmt.Println(err) - that.Display(4, "查询失败") - return - } - - that.Display(0, res.GetMap("data")) - }, - - "info": func(that *Context) { - if that.Session("salesman_id").Data == nil { - that.Display(2, "没有登录") - return - } - - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - res := that.Db.Get("company", "*", Map{"id": id}) - if res == nil { - that.Display(4, "找不到企业") - return - } - //先不做限制 - //if res.GetCeilInt("salesman_id")!=that.Session("salesman_id").ToCeilInt(){ - // that.Display(4,"不是你的企业") - // return - //} - - res["technology_center_flag"] = strToArray(res.GetString("technology_center_flag")) - res["engineering_center_flag"] = strToArray(res.GetString("engineering_center_flag")) - res["engineering_laboratory_flag"] = strToArray(res.GetString("engineering_laboratory_flag")) - res["key_laboratory_flag"] = strToArray(res.GetString("key_laboratory_flag")) - res["industrial_design_center_flag"] = strToArray(res.GetString("industrial_design_center_flag")) - res["high_level_talents_flag1"] = strToArray(res.GetString("high_level_talents_flag1")) - res["tags"] = strToArray(res.GetString("tags")) - - that.Display(0, res) - }, - "edit": func(that *Context) { - if that.Session("salesman_id").Data == nil { - that.Display(2, "没有登录") - return - } - - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - company := that.Db.Get("company", "*", Map{"id": id}) - delete(company, "id") - delete(company, "salesman_id") - delete(company, "provider_id") - delete(company, "user_id") - delete(company, "del_flag") - delete(company, "state") - delete(company, "create_time") - delete(company, "modify_time") - data := Map{} - for k, _ := range company { - if that.Req.Form[k] != nil { - if k == "tags" || k == "high_level_talents_flag1" || k == "technology_center_flag" || k == "engineering_center_flag" || k == "engineering_laboratory_flag" || k == "key_laboratory_flag" || k == "industrial_design_center_flag" { - data[k] = arrayToStr(ObjToSlice(that.Req.Form[k])) - } else { - data[k] = that.Req.FormValue(k) - } - - } - } - - that.Db.Update("company", data, Map{"id": id}) - - that.Display(0, "更新成功") - - }, -} diff --git a/example/provider/declare.go b/example/provider/declare.go deleted file mode 100644 index e5cd5a7..0000000 --- a/example/provider/declare.go +++ /dev/null @@ -1,113 +0,0 @@ -package provider - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var DeclareCtr = Ctr{ - - "info": func(that *Context) { - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - res := that.Db.Get("declare", "*", Map{"id": id}) - - if res == nil { - that.Display(4, "找不到通知公告") - return - } - res["click_num"] = res.GetCeilInt64("click_num") + res.GetCeilInt64("click_num_base") + 1 - delete(res, "click_num_base") - - res["favorite_num"] = res.GetCeilInt64("favorite_num") + res.GetCeilInt64("favorite_num_base") - delete(res, "favorite_num_base") - - article := that.Db.Get("article", "*", Map{"id": res.GetCeilInt64("article_id")}) - if article != nil { - article["click_num"] = article.GetCeilInt64("click_num") + article.GetCeilInt64("click_num_base") + 1 - delete(article, "click_num_base") - - article["favorite_num"] = article.GetCeilInt64("favorite_num") + article.GetCeilInt64("favorite_num_base") - delete(article, "favorite_num_base") - } - - res["article"] = article - - //浏览量加1 - that.Db.Update("declare", Map{"click_num[#]": "click_num+1"}, Map{"id": id}) - //浏览量加1 - that.Db.Update("article", Map{"click_num[#]": "click_num+1"}, Map{"id": res.GetCeilInt64("article_id")}) - - //查询是否已关注 - if that.Session("user_id").Data != nil { - favorite := that.Db.Get("favorite", "user_id,declare_id", Map{"AND": Map{"declare_id": id, "user_id": that.Session("user_id").ToCeilInt(), "del_flag": 0}}) - res["favorite"] = favorite - } - - that.Display(0, res) - }, - - //用户微信公众号或者小程序登录 - "search": func(that *Context) { - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - data := Map{"del_flag": 0, "declare_id[!]": nil} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords} - } - - startTime := that.Req.FormValue("starttime") - finishTime := that.Req.FormValue("finishtime") - - if startTime != "" { - data["release_date[>=]"] = startTime - } - if finishTime != "" { - data["release_date[<=]"] = finishTime - } - - dispatchName := that.Req.FormValue("dispatch_name") - if dispatchName != "" { - data["dispatch_name"] = dispatchName - } - - if len(data) > 1 { - data = Map{"AND": data, "ORDER": "release_time DESC"} - } - - count := that.Db.Count("article", data) - - res := that.Db.Page(page, pageSize).PageSelect("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+ - "favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,declare_id,declare_id,declare_id,dispatch_name,policy_level", data) - for _, v := range res { - - //if v.GetCeilInt("declare_id")>0{ - // v["declare"]=that.Db.Get("declare","id,tag",Map{"id":v.GetCeilInt("declare_id")}) - //} - //if v.GetCeilInt("declare_id")>0{ - // v["declare"]=that.Db.Get("declare","tag",Map{"id":v.GetCeilInt("declare_id")}) - //} - if v.GetCeilInt("declare_id") > 0 { - v["declare"] = that.Db.Get("declare", "money_scope_min,money_scope_max,status", Map{"id": v.GetCeilInt("declare_id")}) - } - } - - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/provider/init.go b/example/provider/init.go deleted file mode 100644 index 67bc9ea..0000000 --- a/example/provider/init.go +++ /dev/null @@ -1,72 +0,0 @@ -package provider - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "strings" - "time" - "unicode/utf8" -) - -// Project 管理端项目 -var Project = Proj{ - "company": CompanyCtr, - "declare": DeclareCtr, - "matters": MattersCtr, - "order": OrderCtr, - "salesman": Salesman, - "sms": Sms, - "tag": TagCtr, - "user": UserCtr, - "wechat": Wechat, -} - -func strToArray(str string) Slice { - s := Slice{} - - olds := strings.Split(str, ",") - for _, v := range olds { - if v != "" { - s = append(s, v) - } - } - return s -} - -func arrayToStr(ars Slice) string { - s := "," - if ars == nil { - return s - } - for k, _ := range ars { - s = s + ars.GetString(k) + "," - } - return s -} - -//生成随机码的6位md5 -func getSn() string { - x := Rand(8) - return Substr(Md5(ObjToStr(int64(x)+time.Now().UnixNano()+int64(Rand(6)))), 0, 6) -} - -//生成随机码的4位随机数 -func getCode() string { - //res := "" - //for i := 0; i < 4; i++ { - res := ObjToStr(RandX(1000, 9999)) - //} - return res -} - -// 过滤 emoji 表情 -func FilterEmoji(content string) string { - new_content := "" - for _, value := range content { - _, size := utf8.DecodeRuneInString(string(value)) - if size <= 3 { - new_content += string(value) - } - } - return new_content -} diff --git a/example/provider/matters.go b/example/provider/matters.go deleted file mode 100644 index d6df3d4..0000000 --- a/example/provider/matters.go +++ /dev/null @@ -1,108 +0,0 @@ -package provider - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var MattersCtr = Ctr{ - - "info": func(that *Context) { - if that.Session("salesman_id").Data == nil { - that.Display(2, "没有登录") - return - } - - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - res := that.Db.Get("matters", "*", Map{"id": id}) - if res == nil { - that.Display(4, "找不到事项") - return - } - if res.GetCeilInt("salesman_id") != that.Session("salesman_id").ToCeilInt() { - that.Display(4, "不是你的事项") - return - } - - res["user"] = that.Db.Get("user", "id,name,nickname,company_id", Map{"id": res.GetCeilInt64("user_id")}) - if res.GetMap("user") != nil && res.GetMap("user").GetCeilInt64("company_id") != 0 { - res["company"] = that.Db.Get("company", "id,name", Map{"id": res.GetMap("user").GetCeilInt64("company_id")}) - } - that.Display(0, res) - }, - - //用户微信公众号或者小程序登录 - "search": func(that *Context) { - if that.Session("salesman_id").Data == nil { - that.Display(2, "没有登录") - return - } - userId := ObjToInt(that.Req.FormValue("id")) - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - tp := that.Req.FormValue("type") - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - data := Map{"del_flag": 0, "salesman_id": that.Session("salesman_id").Data} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords} - } - - if userId != 0 { - - user := that.Db.Get("user", "id", Map{"AND": Map{"id": userId, "salesman_id": that.Session("salesman_id").Data}}) - if user != nil { - data["user_id"] = userId - } - } - - if tp != "" { - data["type"] = ObjToInt("tp") - } - - startTime := that.Req.FormValue("starttime") - finishTime := that.Req.FormValue("finishtime") - - if startTime != "" { - data["modify_time[>=]"] = startTime - } - if finishTime != "" { - data["modify_time[<=]"] = finishTime - } - - if len(data) > 1 { - data = Map{"AND": data} - } - - count := that.Db.Count("matters", data) - - res := that.Db.Page(page, pageSize).PageSelect("matters", "*", data) - - for _, v := range res { - if v.GetCeilInt64("user_id") != 0 { - v["user"] = that.Db.Get("user", "id,avatar,name,nickname,company_id", Map{"id": v.GetCeilInt64("user_id")}) - if v.GetMap("user") != nil && v.GetMap("user").GetCeilInt64("company_id") != 0 { - v["company"] = that.Db.Get("company", "id,name", Map{"id": v.GetMap("user").GetCeilInt64("company_id")}) - } - } - } - - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/provider/order.go b/example/provider/order.go deleted file mode 100644 index 3df5a5d..0000000 --- a/example/provider/order.go +++ /dev/null @@ -1,239 +0,0 @@ -package provider - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var OrderCtr = Ctr{ - "info": func(that *Context) { - if that.Session("salesman_id").Data == nil { - that.Display(2, "没有登录") - return - } - - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data}) - if salesman == nil { - that.Display(2, "登录错误") - return - } - - res := that.Db.Get("order", "*", Map{"AND": Map{"id": id, "provider_id": salesman.GetCeilInt64("provider_id")}}) - - if res == nil { - that.Display(4, "找不到对应订单") - return - } - - //if res.GetCeilInt("salesman_id") != that.Session("salesman_id").ToCeilInt() { - // that.Display(4, "不是你的订单") - // return - //} - - if res.GetCeilInt("user_id") > 0 { - res["user"] = that.Db.Get("user", "name,nickname,avatar", Map{"id": res.GetCeilInt("user_id")}) - } - - res["order_record"] = that.Db.Select("order_record", "remarks,modify_time", Map{"order_id": res.GetCeilInt("id"), "ORDER": "modify_time DESC"}) - - that.Display(0, res) - }, - "create_order_record": func(that *Context) { - if that.Session("salesman_id").Data == nil { - that.Display(2, "没有登录") - return - } - - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - remarks := that.Req.FormValue("remarks") - - salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data}) - if salesman == nil { - that.Display(2, "登录错误") - return - } - - order := that.Db.Get("order", "*", Map{"AND": Map{"id": id, "provider_id": salesman.GetCeilInt64("provider_id")}}) - if order == nil { - that.Display(4, "不是属于你的订单") - return - } - - if order.GetCeilInt("status") != 0 { - that.Display(4, "已完结订单,不可操作") - return - } - - orderRecordId := that.Db.Insert("order_record", Map{ - "order_id": id, - "user_id": order.GetCeilInt64("user_id"), - "remarks": salesman.GetString("name") + ":" + remarks, - "salesman_id": order.GetCeilInt64("salesman_id"), - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - }) - - that.Db.Update("order", Map{"order_record_id": orderRecordId}, Map{"id": id}) - - that.Display(0, "新增订单记录成功") - - }, - "edit": func(that *Context) { - - if that.Session("salesman_id").Data == nil { - that.Display(2, "没有登录") - return - } - - id := ObjToInt(that.Req.FormValue("id")) - - if id == 0 { - that.Display(3, "请求参数异常") - return - } - - salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data}) - if salesman == nil { - that.Display(2, "登录错误") - return - } - - policyDeclareFlag := ObjToInt(that.Req.FormValue("policy_declare_flag")) - declareId := ObjToInt(that.Req.FormValue("declare_id")) - - intellectualPropertyFlag := ObjToInt(that.Req.FormValue("intellectual_property_flag")) - intellectualPropertyCount := ObjToInt(that.Req.FormValue("intellectual_property_count")) - taxOnsultingFlag := ObjToInt(that.Req.FormValue("tax_onsulting_flag")) - - lawFlag := ObjToInt(that.Req.FormValue("law_flag")) - status := ObjToInt(that.Req.FormValue("status")) - - data := Map{ - "policy_declare_flag": policyDeclareFlag, - "intellectual_property_flag": intellectualPropertyFlag, - "intellectual_property_count": intellectualPropertyCount, - "tax_onsulting_flag": taxOnsultingFlag, - "law_flag": lawFlag, - "status": status, - "modify_time[#]": "now()", - } - - if declareId != 0 { - data["declare_id"] = declareId - } - - order := that.Db.Get("order", "*", Map{"AND": Map{"id": id, "provider_id": salesman.GetCeilInt64("provider_id")}}) - if order == nil { - that.Display(4, "不是属于你的订单") - return - } - - if order.GetCeilInt("status") != 0 { - that.Display(4, "已完结订单,不可操作") - return - } - - data["order_record_id"] = that.Db.Insert("order_record", Map{ - "order_id": id, - "user_id": order.GetCeilInt64("user_id"), - "remarks": salesman.GetString("name") + "变更了订单服务内容", - "salesman_id": order.GetCeilInt64("salesman_id"), - "create_time[#]": "now()", - "modify_time[#]": "now()", - "del_flag": 0, - }) - re := that.Db.Update("order", data, Map{"id": id}) - if re == 0 { - that.Display(4, "变更订单内容失败") - return - } - - that.Display(0, "变更订单内容成功") - }, - //用户微信公众号或者小程序登录 - "search": func(that *Context) { - - if that.Session("salesman_id").Data == nil { - that.Display(2, "没有登录") - return - } - - userId := ObjToInt(that.Req.FormValue("id")) - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data}) - if salesman == nil { - that.Display(2, "登录错误") - return - } - - data := Map{"del_flag": 0, "provider_id": salesman.GetCeilInt64("provider_id")} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["OR"] = Map{"sn[~]": keywords, "name[~]": keywords} - } - - if userId != 0 { - - user := that.Db.Get("user", "id", Map{"AND": Map{"id": userId, "salesman_id": that.Session("salesman_id").Data}}) - if user != nil { - data["user_id"] = userId - } - } - - startTime := that.Req.FormValue("starttime") - finishTime := that.Req.FormValue("finishtime") - - if startTime != "" { - data["modify_time[>=]"] = startTime - } - if finishTime != "" { - data["modify_time[<=]"] = finishTime - } - - if len(data) > 1 { - data = Map{"AND": data} - } - - count := that.Db.Count("order", data) - - res := that.Db.Page(page, pageSize).PageSelect("order", "*", data) - for _, v := range res { - - //if v.GetCeilInt("policy_id")>0{ - // v["policy"]=that.Db.Get("policy","id,tag",Map{"id":v.GetCeilInt("policy_id")}) - //} - if v.GetCeilInt("user_id") > 0 { - v["user"] = that.Db.Get("user", "name,nickname,avatar", Map{"id": v.GetCeilInt("user_id")}) - } - if v.GetCeilInt("order_record_id") > 0 { - v["order_record"] = that.Db.Get("order_record", "remarks,modify_time", Map{"id": v.GetCeilInt("order_record_id")}) - } - } - - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/provider/salesman.go b/example/provider/salesman.go deleted file mode 100644 index 1cc4ec6..0000000 --- a/example/provider/salesman.go +++ /dev/null @@ -1,143 +0,0 @@ -package provider - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var Salesman = Ctr{ - "test": func(that *Context) { - that.Session("salesman_id", 1) - that.Session("wechat_id", 1) - that.Display(0, 1) - }, - "info": func(that *Context) { - if that.Session("salesman_id").Data == nil { - that.Display(2, "没有登录") - return - } - - salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data}) - if salesman == nil { - that.Display(4, "找不到该业务员") - return - } - - if salesman.GetString("nickname") == "" { - wechat := that.Db.Get("wechat", "*", Map{"salesman_id": salesman.GetCeilInt64("id")}) - if wechat != nil { - salesman["nickname"] = wechat.GetString("nickname") - salesman["avatar"] = wechat.GetString("avatar") - that.Db.Update("salesman", Map{"nickname": wechat.GetString("nickname"), "avatar": wechat.GetString("avatar")}, Map{"id": salesman.GetCeilInt64("id")}) - } - } - salesman["user"] = that.Db.Count("user", Map{"AND": Map{"salesman_id": that.Session("salesman_id").Data, "del_flag": 0}}) - salesman["matters"] = that.Db.Count("matters", Map{"AND": Map{"salesman_id": that.Session("salesman_id").Data, "del_flag": 0}}) - - salesman["admin"] = that.Db.Get("admin", "id,name,avatar", Map{"id": salesman.GetCeilInt64("admin_id")}) - salesman["provider"] = that.Db.Get("provider", "*", Map{"id": salesman.GetCeilInt64("provider_id")}) - if salesman["provider"] != nil { - salesman["provider_salesman"] = that.Db.Get("salesman", "id,nickname,name,avatar", Map{"id": salesman.GetMap("provider").GetCeilInt64("salesman_id")}) - } - - that.Display(0, salesman) - }, - - "search": func(that *Context) { - if that.Session("salesman_id").Data == nil { - that.Display(2, "没有登录") - return - } - - salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data}) - if salesman == nil { - that.Display(4, "找不到该业务员") - return - } - - provider := that.Db.Get("provider", "*", Map{"id": salesman.GetCeilInt64("provider_id")}) - - if provider.GetCeilInt("salesman_id") != salesman.GetCeilInt("id") { - that.Display(0, Slice{}) - return - } - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - data := Map{"del_flag": 0, "provider_id": salesman.GetCeilInt64("provider_id")} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["OR"] = Map{"name[~]": keywords, "nickname[~]": keywords, "phone[~]": keywords} - } - - startTime := that.Req.FormValue("starttime") - finishTime := that.Req.FormValue("finishtime") - - if startTime != "" { - data["modifye_time[>=]"] = startTime - } - if finishTime != "" { - data["modifye_time[<=]"] = finishTime - } - - count := that.Db.Count("salesman", data) - - res := that.Db.Page(page, pageSize).PageSelect("salesman", "id,name,nickname,avatar", data) - - that.Display(0, Map{"total": count, "data": res}) - }, - //用户微信公众号或者小程序登录 - "login": func(that *Context) { - - code := that.Req.FormValue("code") - phone := that.Req.FormValue("phone") - - if phone != that.Session("phone").ToStr() && code == that.Session("code").ToStr() { - that.Display(3, "手机号或者验证码错误") - return - } - - if that.Session("wechat_id").Data == nil { - that.Display(2, "还未登录") - return - } - - wechat := that.Db.Get("wechat", "*", Map{"id": that.Session("wechat_id").ToCeilInt()}) - - salesman := that.Db.Get("salesman", "*", Map{"phone": phone}) - - if salesman == nil { - that.Display(3, "找不到企服商") - return - } - - if wechat == nil { - that.Display(2, "还未绑定微信") - return - } - - //有用户直接返回 - if wechat.GetCeilInt("salesman_id") != 0 && wechat.GetCeilInt64("salesman_id") != salesman.GetCeilInt64("id") { - that.Display(5, "你已经绑定了其他商户") - return - } - - that.Db.Update("wechat", Map{"salesman_id": salesman.GetCeilInt64("id")}, Map{"id": wechat.GetCeilInt64("id")}) - that.Db.Update("salesman", Map{"login_time[#]": "now()", "modify_time[#]": "now()"}, - Map{"id": salesman.GetCeilInt("id")}) - - wechat["salesman_id"] = salesman.GetCeilInt64("id") - that.Session("salesman_id", salesman.GetCeilInt64("id")) - that.Display(0, "登录成功!") - - }, -} diff --git a/example/provider/sms.go b/example/provider/sms.go deleted file mode 100644 index 233d055..0000000 --- a/example/provider/sms.go +++ /dev/null @@ -1,38 +0,0 @@ -package provider - -import ( - . "code.hoteas.com/golang/hotime" - "code.hoteas.com/golang/hotime/common" - "code.hoteas.com/golang/hotime/dri/ddsms" -) - -var Sms = Ctr{ - //只允许微信验证过的或者登录成功的发送短信 - "send": func(that *Context) { - - phone := that.Req.FormValue("phone") - if len(phone) < 11 { - that.Display(3, "手机号格式错误") - return - } - - if that.Session("wechat_id").Data == nil && that.Session("salesman_id").Data == nil { - that.Display(2, "没有登录不可发送短信") - return - } - - salesman := that.Db.Get("salesman", "id", common.Map{"phone": phone}) - if salesman == nil { - that.Display(3, "你还不是企服人员,请联系管理员") - return - } - - code := getCode() - that.Session("phone", phone) - that.Session("code", code) - - ddsms.DDY.SendYZM(phone, that.Config.GetString("smsLogin"), map[string]string{"code": code}) - - that.Display(0, "发送成功") - }, -} diff --git a/example/provider/tag.go b/example/provider/tag.go deleted file mode 100644 index 20ec539..0000000 --- a/example/provider/tag.go +++ /dev/null @@ -1,83 +0,0 @@ -package provider - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" -) - -var TagCtr = Ctr{ - - "create": func(that *Context) { - if that.Session("user_id").Data == nil { - that.Display(2, "没有登录") - return - } - - name := that.Req.FormValue("name") - - oldTag := that.Db.Get("tag", "id", Map{"name": name}) - if oldTag != nil { - that.Display(4, "此标签已存在") - return - } - - re := that.Db.Insert("tag", Map{ - "user_id": that.Session("user_id").Data, - "name": name, - "remark": "用户上传", - "create_time[#]": "now()", - "modify_time[#]": "now()", - "state": 1, //先置为异常状态,等待审核通过 - "del_flag": 0, - }) - - if re == 0 { - that.Display(4, "添加失败") - return - } - - that.Display(0, "添加成功") - return - - }, - //用户微信公众号或者小程序登录 - "search": func(that *Context) { - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 40 - } - - data := Map{"del_flag": 0, "state": 0} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["OR"] = Map{"name[~]": keywords, "remark[~]": keywords} - } - - startTime := that.Req.FormValue("starttime") - finishTime := that.Req.FormValue("finishtime") - - if startTime != "" { - data["modify_time[>=]"] = startTime - } - if finishTime != "" { - data["modify_time[<=]"] = finishTime - } - - if len(data) > 1 { - data = Map{"AND": data} - } - - count := that.Db.Count("tag", data) - - res := that.Db.Page(page, pageSize).PageSelect("tag", "id,name,remark", data) - - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/provider/user.go b/example/provider/user.go deleted file mode 100644 index f35a550..0000000 --- a/example/provider/user.go +++ /dev/null @@ -1,150 +0,0 @@ -package provider - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "time" -) - -var UserCtr = Ctr{ - //用户微信公众号或者小程序登录 - "info": func(that *Context) { - if that.Session("salesman_id").Data == nil { - that.Display(2, "没有登录") - return - } - userId := ObjToInt(that.Req.FormValue("id")) - - if userId == 0 { - that.Display(3, "参数错误") - return - } - - user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").ToCeilInt()}) - if user == nil { - that.Display(4, "获取个人信息失败") - return - } - - delete(user, "password") - - that.Display(0, user) - }, - - "edit": func(that *Context) { - - if that.Session("salesman_id").Data == nil { - that.Display(2, "没有登录") - return - } - userId := ObjToInt(that.Req.FormValue("id")) - - if userId == 0 { - that.Display(3, "参数错误") - return - } - - name := that.Req.FormValue("name") - nickname := that.Req.FormValue("nickname") - sex := that.Req.FormValue("sex") - email := that.Req.FormValue("email") - avatar := that.Req.FormValue("avatar") - address := that.Req.FormValue("address") - phone := that.Req.FormValue("phone") //如果更换手机号则要有新的短信验证码 - - data := Map{"modify_time[#]": "now()"} - if name != "" { - data["name"] = name - } - if nickname != "" { - data["nickname"] = nickname - } - if sex != "" { - data["sex"] = sex - } - if email != "" { - data["email"] = email - } - if avatar != "" { - data["avatar"] = avatar - } - if address != "" { - data["address"] = address - } - if phone != "" { - - data["phone"] = phone - } - - re := that.Db.Update("user", data, Map{"id": userId}) - if re == 0 { - that.Display(4, "更新失败") - return - } - - that.Display(4, "修改成功") - }, - - "search": func(that *Context) { - if that.Session("salesman_id").Data == nil { - that.Display(2, "没有登录") - return - } - - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - tp := ObjToInt(that.Req.FormValue("type")) //0,无操作,1,已扫码未认证,2,已认证,3,VIP会员 - - data := Map{"del_flag": 0, "salesman_id": that.Session("salesman_id").Data} - keywords := that.Req.FormValue("keywords") - if keywords != "" { - data["OR"] = Map{"name[~]": keywords, "nickname[~]": keywords, "phone[~]": keywords} - } - - startTime := that.Req.FormValue("starttime") - finishTime := that.Req.FormValue("finishtime") - - if startTime != "" { - data["modifye_time[>=]"] = startTime - } - if finishTime != "" { - data["modifye_time[<=]"] = finishTime - } - if tp == 1 { - data["certification_flag"] = 0 - } - - if tp == 2 { - data["certification_flag"] = 1 - data["OR"] = Map{"expiration_time": nil, "expiration_time[#]": "now()"} - } - - if tp == 3 { - data["certification_flag"] = 1 - data["expiration_time[>]"] = time.Now().Format("2006-01-02 15:04:05") - } - - if len(data) > 1 { - data = Map{"AND": data, "ORDER": "modify_time DESC"} - } - - count := that.Db.Count("user", data) - - res := that.Db.Page(page, pageSize).PageSelect("user", "*", data) - - for _, v := range res { - delete(v, "password") - } - - that.Display(0, Map{"total": count, "data": res}) - }, -} diff --git a/example/provider/wechat.go b/example/provider/wechat.go deleted file mode 100644 index 3a7c222..0000000 --- a/example/provider/wechat.go +++ /dev/null @@ -1,97 +0,0 @@ -package provider - -import ( - . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "code.hoteas.com/golang/hotime/dri/wechat" -) - -var Wechat = Ctr{ - - ////微信注册 - "code": func(that *Context) { - - if that.Req.FormValue("code") == "" { - that.Display(3, "参数不足") - return - } - - appid, resToken, userInfo, err := wechat.H5Program.GetUserInfo(that.Req.FormValue("code")) - - if err != nil { - that.Display(4, err) - return - } - //此次获取的微信信息 - wechatInfo := Map{ - "openid": userInfo.OpenID, - "acttoken": resToken.AccessToken, - "retoken": resToken.RefreshToken, - "appid": appid, - "unionid": userInfo.Unionid, - "nickname": FilterEmoji(userInfo.Nickname), - "avatar": userInfo.HeadImgURL, - //"create_time[#]":"now()", - "modify_time[#]": "now()", - "del_flag": 0, - "type": 1, - } - - wechat := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": userInfo.OpenID, "del_flag": 0}}) - - if wechat != nil { - //有用户直接返回 - if wechat.GetCeilInt("salesman_id") != 0 { - - that.Db.Update("salesman", Map{"login_time[#]": "now()"}, - Map{"id": wechat.GetCeilInt("salesman_id")}) - that.Session("salesman_id", wechat.GetCeilInt("salesman_id")) - - that.Display(0, "登录成功") - return - } - that.Session("wechat_id", wechat.GetCeilInt("id")) - that.Display(2, "暂未绑定") - return - - } - - wechatInfo["create_time[#]"] = "now()" - - wechatInfo["id"] = that.Db.Insert("wechat", wechatInfo) - if wechatInfo.GetCeilInt("id") == 0 { - that.Display(4, "创建用户失败") - return - } - - that.Session("wechat_id", wechatInfo.GetCeilInt("id")) - that.Display(2, "暂未绑定") - }, - - //网页签名 - "sign": func(that *Context) { - - signUrl := that.Req.FormValue("url") - if signUrl == "" { - that.Display(3, "参数不足") - return - } - - cfg1, e := wechat.H5Program.GetSignUrl(signUrl) - - if e != nil { - that.Display(4, e) - return - } - - sign := Map{ - "appId": cfg1.AppID, - "timestamp": cfg1.Timestamp, - "nonceStr": cfg1.NonceStr, - "signature": cfg1.Signature, - } - - that.Display(0, sign) - - }, -} diff --git a/example/tpt/pc.html b/example/tpt/pc.html deleted file mode 100644 index ea60dfc..0000000 --- a/example/tpt/pc.html +++ /dev/null @@ -1,80 +0,0 @@ - - - - - 微信登录 - - - - - - - - -
- - -
-
- 欢迎使用政策狩猎精灵 -
-
-
初次使用需要绑定您的信息
-
请打开微信扫描下方二维码
-
-
-
- -
- - -