基础整理

This commit is contained in:
hoteas 2022-05-03 09:41:18 +08:00
parent 76b220aa5d
commit b709b58fef
7 changed files with 430 additions and 8 deletions

View File

@ -3,8 +3,21 @@ package app
import ( import (
. "code.hoteas.com/golang/hotime" . "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common" . "code.hoteas.com/golang/hotime/common"
"sort"
) )
type paixuArr []Map
func (x paixuArr) Len() int {
return len(x)
}
func (x paixuArr) Less(i, j int) bool {
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{ var DeclareCtr = Ctr{
"info": func(that *Context) { "info": func(that *Context) {
@ -54,6 +67,304 @@ var DeclareCtr = Ctr{
//政策匹配 //政策匹配
"match": func(that *Context) { "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
}
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 that.Req.Form[k] != nil {
if 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", company, 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", company, 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", "id,declare_id", Map{"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{"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{"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{"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 {
flagslice = append(flagslice, v)
}
}
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"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 {
flagslice = append(flagslice, v)
}
}
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"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 {
flagslice = append(flagslice, v)
}
}
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"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 {
flagslice = append(flagslice, v)
}
}
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"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{"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{"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{"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{"del_flag": 0, "high_level_talents_flag": ObjToInt(that.Req.FormValue("high_level_talents_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")]["high_level_talents_flag_count"] = 1
}
//企业股东或成员是否有国内外高校或科研院在编、全职人员:0-否,1-是
if ObjToInt(that.Req.FormValue("shareholders_flag")) > 0 {
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"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{"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{"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)
res := Slice{}
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,tag,status", Map{"id": id})
res = append(res, article)
}
that.Display(0, res)
}, },
//用户微信公众号或者小程序登录 //用户微信公众号或者小程序登录
"search": func(that *Context) { "search": func(that *Context) {

View File

@ -13,7 +13,7 @@ var Sms = Ctr{
that.Display(2, "没有授权") that.Display(2, "没有授权")
return return
} }
if that.Session("wechat_id").Data == nil && that.Session("salesman_id").Data == nil { if that.Session("wechat_id").Data == nil && that.Session("user_id").Data == nil {
that.Display(2, "没有登录不可发送短信") that.Display(2, "没有登录不可发送短信")
return return
} }

83
example/app/tag.go Normal file
View File

@ -0,0 +1,83 @@
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})
},
}

View File

@ -6,6 +6,11 @@ import (
) )
var UserCtr = Ctr{ 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) { "info": func(that *Context) {
if that.Session("user_id").Data != nil { if that.Session("user_id").Data != nil {
@ -34,13 +39,6 @@ var UserCtr = Ctr{
that.Display(0, user) that.Display(0, user)
}, },
"auth": func(that *Context) {
if that.Session("user_id").Data != nil {
that.Display(2, "没有登录")
return
}
},
"edit": func(that *Context) { "edit": func(that *Context) {
if that.Session("user_id").Data != nil { if that.Session("user_id").Data != nil {
that.Display(2, "没有登录") that.Display(2, "没有登录")

View File

@ -137,6 +137,14 @@ var Wechath5 = Ctr{
"del_flag": 0, "del_flag": 0,
} }
user["id"] = that.Db.Insert("user", user) 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["user_id"] = user.GetCeilInt("id")
@ -158,6 +166,14 @@ var Wechath5 = Ctr{
"del_flag": 0, "del_flag": 0,
} }
user["id"] = that.Db.Insert("user", user) 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["user_id"] = user.GetCeilInt("id")

View File

@ -140,6 +140,15 @@ var WechatMini = Ctr{
} }
user["id"] = that.Db.Insert("user", user) 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["user_id"] = user.GetCeilInt("id")
wchat["create_time[#]"] = "now()" wchat["create_time[#]"] = "now()"

View File

@ -6,6 +6,11 @@ import (
) )
var Salesman = Ctr{ 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) { "info": func(that *Context) {
if that.Session("salesman_id").Data != nil { if that.Session("salesman_id").Data != nil {
that.Display(2, "没有登录") that.Display(2, "没有登录")