forked from golang/hotime
基础整理
This commit is contained in:
parent
dbf8f91696
commit
76b220aa5d
@ -58,6 +58,14 @@ func (that *company) GetCompanyOtherAll(name string) Map {
|
||||
return res
|
||||
}
|
||||
|
||||
// GetCompanyBaseInfo 获取企业基础信息
|
||||
func (that *company) GetCompanyList(name string) (Map, error) {
|
||||
url := "/fuzzyQueryCompanyInfo/"
|
||||
|
||||
body, err := that.basePost(url, name)
|
||||
return ObjToMap(body), err
|
||||
}
|
||||
|
||||
// GetCompanyBaseInfo 获取企业基础信息
|
||||
func (that *company) GetCompanyBaseInfo(name string) (Map, error) {
|
||||
url := "/getCompanyBaseInfo/"
|
||||
|
88
example/app/article.go
Normal file
88
example/app/article.go
Normal file
@ -0,0 +1,88 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
)
|
||||
|
||||
var ArticleCtr = Ctr{
|
||||
|
||||
"getdispatchs": func(that *Context) {
|
||||
|
||||
res := that.Db.Select("article", "dispatch_name", Map{"del_flag": 0, "GROUP": "dispatch_name"})
|
||||
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_date[>=]"] = startTime
|
||||
}
|
||||
if finishTime != "" {
|
||||
data["release_date[<=]"] = 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}
|
||||
}
|
||||
|
||||
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", 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,tag,status", Map{"id": v.GetCeilInt("declare_id")})
|
||||
}
|
||||
}
|
||||
|
||||
that.Display(0, Map{"total": count, "data": res})
|
||||
},
|
||||
}
|
31
example/app/company.go
Normal file
31
example/app/company.go
Normal file
@ -0,0 +1,31 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"code.hoteas.com/golang/hotime/dri/aliyun"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var CompanyCtr = Ctr{
|
||||
"lists": func(that *Context) {
|
||||
companyName := that.Req.FormValue("company_name")
|
||||
if len(companyName) < 2 {
|
||||
that.Display(0, Slice{})
|
||||
return
|
||||
}
|
||||
res, err := aliyun.Company.GetCompanyList(companyName)
|
||||
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"))
|
||||
},
|
||||
}
|
116
example/app/declare.go
Normal file
116
example/app/declare.go
Normal file
@ -0,0 +1,116 @@
|
||||
package app
|
||||
|
||||
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)
|
||||
},
|
||||
//政策匹配
|
||||
"match": func(that *Context) {
|
||||
|
||||
},
|
||||
//用户微信公众号或者小程序登录
|
||||
"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}
|
||||
}
|
||||
|
||||
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", 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,tag,status", Map{"id": v.GetCeilInt("declare_id")})
|
||||
}
|
||||
}
|
||||
|
||||
that.Display(0, Map{"total": count, "data": res})
|
||||
},
|
||||
}
|
241
example/app/favorite.go
Normal file
241
example/app/favorite.go
Normal file
@ -0,0 +1,241 @@
|
||||
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 {
|
||||
notify := that.Db.Get("notify", "article_id", Map{"id": notifyId})
|
||||
if notify != nil {
|
||||
data = Map{"notify_id": notifyId, "article_id": notify.GetCeilInt("article_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 {
|
||||
policy := that.Db.Get("policy", "article_id", Map{"id": policyId})
|
||||
if policy != nil {
|
||||
data = Map{"policy_id": policyId, "article_id": policy.GetCeilInt("article_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 {
|
||||
declare := that.Db.Get("declare", "article_id", Map{"id": declareId})
|
||||
if declare != nil {
|
||||
data = Map{"declare_id": declareId, "article_id": declare.GetCeilInt("article_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 {
|
||||
notify := that.Db.Get("notify", "article_id", Map{"id": notifyId})
|
||||
if notify != nil {
|
||||
data = Map{"notify_id": notifyId, "article_id": notify.GetCeilInt("article_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 {
|
||||
|
||||
policy := that.Db.Get("policy", "article_id", Map{"id": policyId})
|
||||
if policy != nil {
|
||||
data = Map{"policy_id": policyId, "article_id": policy.GetCeilInt("article_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 {
|
||||
declare := that.Db.Get("declare", "article_id", Map{"id": declareId})
|
||||
if declare != nil {
|
||||
data = Map{"declare_id": declareId, "article_id": declare.GetCeilInt("article_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(4, "没有关注")
|
||||
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}
|
||||
}
|
||||
|
||||
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,tag,status", Map{"id": v.GetCeilInt64("policy_id")})
|
||||
}
|
||||
|
||||
if v.GetCeilInt64("notify_id") != 0 {
|
||||
v["notify"] = that.Db.Get("notify", "id,tag", Map{"id": v.GetCeilInt64("policy_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("policy_id")})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
that.Display(0, Map{"total": count, "data": res})
|
||||
},
|
||||
}
|
@ -3,50 +3,17 @@ package app
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"code.hoteas.com/golang/hotime/dri/ddsms"
|
||||
"github.com/silenceper/wechat/v2"
|
||||
"github.com/silenceper/wechat/v2/cache"
|
||||
"github.com/silenceper/wechat/v2/miniprogram"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/config"
|
||||
"github.com/silenceper/wechat/v2/officialaccount"
|
||||
h5config "github.com/silenceper/wechat/v2/officialaccount/config"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Project 管理端项目
|
||||
var Project = Proj{
|
||||
"salesman": Salesman,
|
||||
"lxcx": Lxcx,
|
||||
"wechat": Wechat,
|
||||
"websocket": WebsocketCtr,
|
||||
}
|
||||
var weixin *wechat.Wechat //微信登录实例
|
||||
var miniProgram *miniprogram.MiniProgram
|
||||
var h5Program *officialaccount.OfficialAccount
|
||||
|
||||
func InitApp(app *Application) {
|
||||
weixin = wechat.NewWechat()
|
||||
memory := cache.NewMemory()
|
||||
memoryMini := cache.NewMemory()
|
||||
cfg := &config.Config{
|
||||
AppID: app.Config.GetString("wechatMiniAppID"),
|
||||
AppSecret: app.Config.GetString("wechatMiniAppSecret"),
|
||||
//Token: "xxx",
|
||||
//EncodingAESKey: "xxxx",
|
||||
Cache: memoryMini,
|
||||
}
|
||||
h5cfg := &h5config.Config{
|
||||
AppID: app.Config.GetString("wechatAppID"),
|
||||
AppSecret: app.Config.GetString("wechatAppSecret"),
|
||||
//Token: "xxx",
|
||||
//EncodingAESKey: "xxxx",
|
||||
Cache: memory,
|
||||
}
|
||||
|
||||
miniProgram = weixin.GetMiniProgram(cfg)
|
||||
h5Program = weixin.GetOfficialAccount(h5cfg)
|
||||
|
||||
ddsms.DDY.Init(app.Config.GetString("smsKey"))
|
||||
"wechath5": Wechath5,
|
||||
"wechatmini": Wechath5,
|
||||
"provider": ProviderCtr,
|
||||
}
|
||||
|
||||
//生成随机码的6位md5
|
||||
@ -63,3 +30,69 @@ func getCode() string {
|
||||
//}
|
||||
return res
|
||||
}
|
||||
|
||||
//认证公共方案
|
||||
func auth(that *Context, phone, companyName string) error {
|
||||
|
||||
user := that.Db.Get("user", "id,phone,salesman_id,company_id,provider_id", Map{"id": that.Session("user_id").ToCeilInt()})
|
||||
if user == nil {
|
||||
return errors.New("找不到用户")
|
||||
}
|
||||
|
||||
//手机号与原来的不同则进行绑定
|
||||
if phone != user.GetString("phone") {
|
||||
//微信验证成功
|
||||
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}, 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
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,5 @@ var Lxcx = Ctr{
|
||||
log.Println("err")
|
||||
}
|
||||
that.Display(0, common.ObjToMap(string(b)))
|
||||
|
||||
},
|
||||
}
|
||||
|
159
example/app/matters.go
Normal file
159
example/app/matters.go
Normal file
@ -0,0 +1,159 @@
|
||||
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", "*", 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,
|
||||
})
|
||||
|
||||
that.Display(0, re)
|
||||
},
|
||||
"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}
|
||||
}
|
||||
|
||||
count := that.Db.Count("matters", data)
|
||||
|
||||
res := that.Db.Page(page, pageSize).PageSelect("matters", "*", data)
|
||||
|
||||
that.Display(0, Map{"total": count, "data": res})
|
||||
},
|
||||
}
|
111
example/app/notify.go
Normal file
111
example/app/notify.go
Normal file
@ -0,0 +1,111 @@
|
||||
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}
|
||||
}
|
||||
|
||||
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", 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})
|
||||
},
|
||||
}
|
195
example/app/order.go
Normal file
195
example/app/order.go
Normal file
@ -0,0 +1,195 @@
|
||||
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")
|
||||
if providerId == 0 || len(phone) != 11 || len(companyName) < 4 {
|
||||
that.Display(3, "请求参数异常")
|
||||
return
|
||||
}
|
||||
|
||||
err := auth(that, phone, companyName)
|
||||
if err != nil {
|
||||
that.Display(3, err)
|
||||
return
|
||||
}
|
||||
|
||||
declareId := ObjToInt(that.Req.FormValue("declare_id"))
|
||||
|
||||
tp := that.Req.FormValue("type")
|
||||
|
||||
//是否以前已经创建了该服务商的订单,如果创建了则直接跳转到订单详情中去
|
||||
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 {
|
||||
that.Display(0, oldOrder.GetCeilInt64("id"))
|
||||
return
|
||||
}
|
||||
|
||||
//新建流程
|
||||
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
|
||||
}
|
||||
|
||||
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", data)
|
||||
|
||||
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{"id": id})
|
||||
|
||||
if res == nil {
|
||||
that.Display(4, "找不到对应订单")
|
||||
return
|
||||
}
|
||||
if res.GetCeilInt("provider_id") > 0 {
|
||||
res["provider"] = that.Db.Get("provider", "name,title", 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}
|
||||
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}
|
||||
}
|
||||
|
||||
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})
|
||||
},
|
||||
}
|
112
example/app/policy.go
Normal file
112
example/app/policy.go
Normal file
@ -0,0 +1,112 @@
|
||||
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}
|
||||
}
|
||||
|
||||
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", 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})
|
||||
},
|
||||
}
|
87
example/app/provider.go
Normal file
87
example/app/provider.go
Normal file
@ -0,0 +1,87 @@
|
||||
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}
|
||||
keywords := that.Req.FormValue("keywords")
|
||||
if keywords != "" {
|
||||
data["OR"] = Map{"name[~]": keywords, "title[~]": keywords}
|
||||
}
|
||||
|
||||
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}
|
||||
}
|
||||
|
||||
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", data)
|
||||
|
||||
that.Display(0, Map{"total": count, "data": res})
|
||||
},
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
)
|
||||
|
||||
var Salesman = Ctr{
|
||||
//用户微信公众号或者小程序登录
|
||||
"login": func(that *Context) {
|
||||
acttoken := that.Req.FormValue("acttoken")
|
||||
retoken := that.Req.FormValue("retoken")
|
||||
appid := that.Req.FormValue("appid")
|
||||
unionid := that.Req.FormValue("unionid")
|
||||
openid := that.Req.FormValue("openid")
|
||||
nickname := that.Req.FormValue("nickname")
|
||||
avatar := that.Req.FormValue("avatar")
|
||||
phone := that.Req.FormValue("phone")
|
||||
Type := ObjToInt(that.Req.FormValue("type"))
|
||||
|
||||
if acttoken == "" || retoken == "" || appid == "" || unionid == "" || openid == "" || nickname == "" || avatar == "" || that.Req.FormValue("type") == "" || phone == "" {
|
||||
that.Display(3, "请求参数异常,请校验参数")
|
||||
return
|
||||
}
|
||||
|
||||
wechat := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": openid, "del_flag": 0}})
|
||||
salesman := that.Db.Get("salesman", "*", Map{"phone": phone})
|
||||
|
||||
if salesman == nil {
|
||||
that.Display(3, "找不到企服商")
|
||||
return
|
||||
}
|
||||
|
||||
if wechat != nil {
|
||||
//有用户直接返回
|
||||
if wechat.GetCeilInt("salesman_id") != 0 && wechat.GetCeilInt64("salesman_id") == salesman.GetInt64("id") {
|
||||
that.Display(0, wechat)
|
||||
return
|
||||
}
|
||||
|
||||
that.Db.Update("wechat", Map{"salesman_id": salesman.GetCeilInt64("id")}, Map{"id": wechat.GetInt64("id")})
|
||||
|
||||
wechat["salesman_id"] = salesman.GetCeilInt64("id")
|
||||
that.Display(0, wechat)
|
||||
return
|
||||
}
|
||||
|
||||
wechat = Map{}
|
||||
wechat["salesman_id"] = salesman.GetCeilInt("id")
|
||||
wechat["acttoken"] = acttoken
|
||||
wechat["retoken"] = retoken
|
||||
wechat["appid"] = appid
|
||||
wechat["unionid"] = unionid
|
||||
wechat["openid"] = openid
|
||||
wechat["nickname"] = nickname
|
||||
wechat["avatar"] = avatar
|
||||
wechat["type"] = Type
|
||||
wechat["id"] = that.Db.Insert("wechat", wechat)
|
||||
if wechat.GetCeilInt("id") == 0 {
|
||||
that.Display(4, "创建用户失败")
|
||||
return
|
||||
}
|
||||
that.Display(0, wechat)
|
||||
|
||||
},
|
||||
}
|
@ -2,28 +2,33 @@ package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
"code.hoteas.com/golang/hotime/dri/ddsms"
|
||||
)
|
||||
|
||||
var Sms = Ctr{
|
||||
//只允许微信验证过的或者登录成功的发送短信
|
||||
//"send": func(this *Context) {
|
||||
//
|
||||
// if len(this.Req.FormValue("token")) != 32 {
|
||||
// this.Display(2, "没有授权")
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// phone := this.Req.FormValue("phone")
|
||||
// if len(phone) < 11 {
|
||||
// this.Display(3, "手机号格式错误")
|
||||
// return
|
||||
// }
|
||||
// code := getCode()
|
||||
// this.Session("phone", phone)
|
||||
// this.Session("code", code)
|
||||
//
|
||||
// ddsms.DDY.SendYZM(phone, this.Config.GetString("smsLogin"), map[string]string{"code": code})
|
||||
//
|
||||
// this.Display(0, "发送成功")
|
||||
//},
|
||||
"send": func(that *Context) {
|
||||
|
||||
if len(that.Req.FormValue("token")) != 32 {
|
||||
that.Display(2, "没有授权")
|
||||
return
|
||||
}
|
||||
if that.Session("wechat_id").Data == nil && that.Session("salesman_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, "发送成功")
|
||||
},
|
||||
}
|
||||
|
@ -5,144 +5,94 @@ import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
)
|
||||
|
||||
var User = Ctr{
|
||||
var UserCtr = Ctr{
|
||||
//用户微信公众号或者小程序登录
|
||||
"login": func(that *Context) {
|
||||
|
||||
acttoken := that.Req.FormValue("acttoken")
|
||||
retoken := that.Req.FormValue("retoken")
|
||||
appid := that.Req.FormValue("appid")
|
||||
unionid := that.Req.FormValue("unionid")
|
||||
openid := that.Req.FormValue("openid")
|
||||
nickname := that.Req.FormValue("nickname")
|
||||
avatar := that.Req.FormValue("avatar")
|
||||
Type := ObjToInt(that.Req.FormValue("type"))
|
||||
|
||||
sn := that.Req.FormValue("sn")
|
||||
|
||||
if acttoken == "" || retoken == "" || appid == "" || unionid == "" || openid == "" || nickname == "" || avatar == "" || that.Req.FormValue("type") == "" {
|
||||
that.Display(3, "请求参数异常,请校验参数")
|
||||
"info": func(that *Context) {
|
||||
if that.Session("user_id").Data != nil {
|
||||
that.Display(2, "没有登录")
|
||||
return
|
||||
}
|
||||
|
||||
wechat := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": openid, "del_flag": 0}})
|
||||
|
||||
defer func() {
|
||||
if sn == "" {
|
||||
return
|
||||
}
|
||||
if wechat.GetCeilInt("user_id") == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
salesman := that.Db.Get("salesman", "*", Map{"sn": sn})
|
||||
if salesman.GetCeilInt("id") == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
user := that.Db.Get("user", "*", Map{"id": wechat.GetCeilInt("user_id")})
|
||||
user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").ToCeilInt()})
|
||||
if user == nil {
|
||||
return
|
||||
}
|
||||
//用户都有企服人员关联
|
||||
if user.GetCeilInt("salesman_id") != 0 {
|
||||
|
||||
return
|
||||
}
|
||||
//用户没有企服商id
|
||||
that.Db.Update("user", Map{"salesman_id": salesman.GetCeilInt64("id")}, Map{"id": user.GetCeilInt64("id")})
|
||||
|
||||
}()
|
||||
|
||||
if wechat != nil {
|
||||
//有用户直接返回
|
||||
if wechat.GetCeilInt("user_id") != 0 {
|
||||
that.Display(0, wechat)
|
||||
return
|
||||
}
|
||||
//没有用户继续查询数据库看是否有其他unionid
|
||||
wechat1 := that.Db.Get("wechat", "*", Map{"AND": Map{"unionid": unionid, "openid[!]": openid, "user_id[>]": 0, "del_flag": 0}})
|
||||
|
||||
//其他表有该数据,则更新当前表数据信息
|
||||
if wechat1 != nil {
|
||||
|
||||
wechat["user_id"] = wechat1.GetCeilInt("user_id")
|
||||
wechat["acttoken"] = acttoken
|
||||
wechat["retoken"] = retoken
|
||||
wechat["appid"] = appid
|
||||
wechat["unionid"] = unionid
|
||||
wechat["openid"] = openid
|
||||
wechat["nickname"] = nickname
|
||||
wechat["avatar"] = avatar
|
||||
wechat["type"] = Type
|
||||
|
||||
that.Db.Update("wechat", wechat, Map{"id": wechat.GetCeilInt("id")})
|
||||
that.Display(0, wechat)
|
||||
that.Display(4, "获取个人信息失败")
|
||||
return
|
||||
}
|
||||
|
||||
//其他表也没有当前信息,则生成user表,并更新当前用户
|
||||
user := Map{
|
||||
"nick_name": nickname,
|
||||
"avatar_name": avatar,
|
||||
"del_flag": 0,
|
||||
}
|
||||
user["id"] = that.Db.Insert("user", user)
|
||||
delete(user, "password")
|
||||
|
||||
wechat["user_id"] = user.GetCeilInt("id")
|
||||
wechat["acttoken"] = acttoken
|
||||
wechat["retoken"] = retoken
|
||||
wechat["appid"] = appid
|
||||
wechat["unionid"] = unionid
|
||||
wechat["openid"] = openid
|
||||
wechat["nickname"] = nickname
|
||||
wechat["avatar"] = avatar
|
||||
wechat["type"] = Type
|
||||
that.Db.Update("wechat", wechat, Map{"id": wechat.GetCeilInt("id")})
|
||||
that.Display(0, wechat)
|
||||
return
|
||||
}
|
||||
user := Map{
|
||||
"nick_name": nickname,
|
||||
"avatar_name": avatar,
|
||||
"del_flag": 0,
|
||||
}
|
||||
user["id"] = that.Db.Insert("user", user)
|
||||
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")})
|
||||
|
||||
wechat = Map{}
|
||||
wechat["user_id"] = user.GetCeilInt("id")
|
||||
wechat["acttoken"] = acttoken
|
||||
wechat["retoken"] = retoken
|
||||
wechat["appid"] = appid
|
||||
wechat["unionid"] = unionid
|
||||
wechat["openid"] = openid
|
||||
wechat["nickname"] = nickname
|
||||
wechat["avatar"] = avatar
|
||||
wechat["type"] = Type
|
||||
wechat["id"] = that.Db.Insert("wechat", wechat)
|
||||
if wechat.GetCeilInt("id") == 0 {
|
||||
that.Display(4, "创建用户失败")
|
||||
return
|
||||
if user != nil {
|
||||
user["company"] = company
|
||||
user["salesman"] = salesman
|
||||
user["provider"] = provider
|
||||
}
|
||||
that.Display(0, wechat)
|
||||
|
||||
that.Display(0, user)
|
||||
},
|
||||
"check": func(that *Context) {
|
||||
openid := that.Req.FormValue("openid")
|
||||
if openid == "" {
|
||||
that.Display(3, "请求参数异常,请校验参数")
|
||||
|
||||
"auth": func(that *Context) {
|
||||
if that.Session("user_id").Data != nil {
|
||||
that.Display(2, "没有登录")
|
||||
return
|
||||
}
|
||||
},
|
||||
|
||||
"edit": func(that *Context) {
|
||||
if that.Session("user_id").Data != nil {
|
||||
that.Display(2, "没有登录")
|
||||
return
|
||||
}
|
||||
|
||||
wechat := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": openid, "user_id[!]": nil, "del_flag": 0}})
|
||||
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")
|
||||
|
||||
if wechat == nil {
|
||||
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 != "" {
|
||||
|
||||
that.Display(3, "找不到该用户")
|
||||
//微信验证成功
|
||||
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, wechat)
|
||||
|
||||
that.Display(4, "修改成功")
|
||||
},
|
||||
}
|
||||
|
@ -1,115 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var Wechat = Ctr{
|
||||
"login": func(that *Context) {
|
||||
|
||||
sessionKey := that.Req.FormValue("sessionkey")
|
||||
encryptedData := that.Req.FormValue("encryptedData")
|
||||
iv := that.Req.FormValue("iv")
|
||||
|
||||
if sessionKey == "" || encryptedData == "" || iv == "" {
|
||||
that.Display(3, "参数不足")
|
||||
return
|
||||
}
|
||||
|
||||
eny := miniProgram.GetEncryptor()
|
||||
re, e := eny.Decrypt(sessionKey, encryptedData, iv)
|
||||
|
||||
if e != nil {
|
||||
that.Display(4, e)
|
||||
return
|
||||
}
|
||||
that.Display(0, re.PhoneNumber)
|
||||
|
||||
},
|
||||
"code": func(that *Context) {
|
||||
|
||||
code := that.Req.FormValue("code")
|
||||
if code == "" {
|
||||
that.Display(3, "缺少code")
|
||||
return
|
||||
}
|
||||
|
||||
a := miniProgram.GetAuth()
|
||||
re, e := a.Code2Session(code)
|
||||
fmt.Println(re)
|
||||
if e != nil {
|
||||
that.Display(4, e)
|
||||
return
|
||||
}
|
||||
wchat := Map{"openid": re.OpenID,
|
||||
"appid": a.AppID,
|
||||
"state": 0,
|
||||
"sessionkey": re.SessionKey,
|
||||
"unionid": re.UnionID,
|
||||
}
|
||||
//wchat["id"] = that.Db.Insert("wechat", wchat)
|
||||
|
||||
that.Display(0, wchat)
|
||||
return
|
||||
|
||||
},
|
||||
|
||||
////微信注册,0已经完整的注册了,1还没有注册
|
||||
"codeh5": func(that *Context) {
|
||||
|
||||
auth := h5Program.GetOauth()
|
||||
//weixin.GetOpenPlatform()
|
||||
resToken, err := auth.GetUserAccessToken(that.Req.FormValue("code"))
|
||||
if err != nil {
|
||||
that.Display(5, "code错误")
|
||||
return
|
||||
}
|
||||
|
||||
//getUserInfo
|
||||
userInfo, err := auth.GetUserInfo(resToken.AccessToken, resToken.OpenID, "")
|
||||
if err != nil {
|
||||
that.Display(6, "微信个人信息无法获取")
|
||||
return
|
||||
}
|
||||
|
||||
//wechatInfo := ObjToMap(userInfo)
|
||||
wechatInfo := Map{
|
||||
"openid": userInfo.OpenID,
|
||||
"acttoken": resToken.AccessToken,
|
||||
"retoken": resToken.RefreshToken,
|
||||
"appid": that.Config.GetString("wechatAppID"),
|
||||
"unionid": userInfo.Unionid,
|
||||
"nickname": userInfo.Nickname,
|
||||
"avatar": userInfo.HeadImgURL,
|
||||
}
|
||||
|
||||
that.Display(0, wechatInfo)
|
||||
},
|
||||
//网页签名
|
||||
"sign": func(that *Context) {
|
||||
|
||||
if that.Req.FormValue("sign_url") == "" {
|
||||
that.Display(2, "参数不足")
|
||||
return
|
||||
}
|
||||
signUrl := that.Req.FormValue("sign_url")
|
||||
js := h5Program.GetJs()
|
||||
cfg1, e := js.GetConfig(signUrl)
|
||||
if e != nil {
|
||||
that.Display(7, e)
|
||||
return
|
||||
}
|
||||
|
||||
sign := Map{
|
||||
"appId": cfg1.AppID,
|
||||
"timestamp": cfg1.Timestamp,
|
||||
"nonceStr": cfg1.NonceStr,
|
||||
"signature": cfg1.Signature,
|
||||
}
|
||||
|
||||
that.Display(0, sign)
|
||||
|
||||
},
|
||||
}
|
204
example/app/wechath5.go
Normal file
204
example/app/wechath5.go
Normal file
@ -0,0 +1,204 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"code.hoteas.com/golang/hotime/dri/wechat"
|
||||
)
|
||||
|
||||
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": userInfo.Nickname,
|
||||
"avatar": userInfo.HeadImgURL,
|
||||
"create_time[#]": "now()",
|
||||
"modify_time[#]": "now()",
|
||||
"del_flag": 0,
|
||||
"type": 1,
|
||||
}
|
||||
|
||||
userId := 0
|
||||
|
||||
//最后验证服务商是否绑定
|
||||
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
|
||||
that.Db.Update("user", Map{"salesman_id": salesman.GetCeilInt64("id"), "provider_id": salesman.GetCeilInt64("provider_id")}, 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")})
|
||||
|
||||
}()
|
||||
|
||||
//如果有则直接返回用户信息到微信小程序里
|
||||
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")})
|
||||
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)
|
||||
}
|
||||
}()
|
||||
|
||||
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"),
|
||||
"create_time[#]": "now()",
|
||||
"modify_time[#]": "now()",
|
||||
"login_time[#]": "now()",
|
||||
"del_flag": 0,
|
||||
}
|
||||
user["id"] = that.Db.Insert("user", user)
|
||||
|
||||
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"),
|
||||
"create_time[#]": "now()",
|
||||
"modify_time[#]": "now()",
|
||||
"login_time[#]": "now()",
|
||||
"del_flag": 0,
|
||||
}
|
||||
user["id"] = that.Db.Insert("user", user)
|
||||
|
||||
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)
|
||||
|
||||
},
|
||||
}
|
158
example/app/wechatmini.go
Normal file
158
example/app/wechatmini.go
Normal file
@ -0,0 +1,158 @@
|
||||
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)
|
||||
|
||||
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)
|
||||
},
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"aliyunCode": "06c6a07e89dd45c88de040ee1489eef7",
|
||||
"avatarPath": "avatar/2006/01/02/",
|
||||
"cache": {
|
||||
"db": {
|
||||
@ -23,9 +24,9 @@
|
||||
"crossDomain": "",
|
||||
"db": {
|
||||
"mysql": {
|
||||
"host": "192.168.2.50",
|
||||
"host": "192.168.6.253",
|
||||
"name": "zct_v2",
|
||||
"password": "kct@2021",
|
||||
"password": "dasda8454456",
|
||||
"port": "3306",
|
||||
"prefix": "",
|
||||
"user": "root"
|
||||
@ -40,7 +41,8 @@
|
||||
"2": "访问权限异常",
|
||||
"3": "请求参数异常",
|
||||
"4": "数据处理异常",
|
||||
"5": "数据结果异常"
|
||||
"5": "数据结果异常",
|
||||
"6": "需要进一步获取个人信息"
|
||||
},
|
||||
"imgPath": "img/2006/01/02/",
|
||||
"mode": 2,
|
||||
|
@ -2,11 +2,11 @@ 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/wechat"
|
||||
"code.hoteas.com/golang/hotime/example/app"
|
||||
"code.hoteas.com/golang/hotime/example/salesman"
|
||||
|
||||
"code.hoteas.com/golang/hotime/example/provider"
|
||||
//. "code.hoteas.com/golang/hotime/common"
|
||||
"fmt"
|
||||
"time"
|
||||
@ -17,16 +17,19 @@ func main() {
|
||||
fmt.Println(date, date.Unix())
|
||||
//fmt.Println("0123456"[1:7])
|
||||
appIns := Init("config/config.json")
|
||||
app.InitApp(appIns)
|
||||
//初始化短信
|
||||
|
||||
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"))
|
||||
|
||||
//用户侧访问前设置
|
||||
appIns.SetConnectListener(func(that *Context) (isFinished bool) {
|
||||
//that.Session("admin_id", 1)
|
||||
//发送短信校验
|
||||
|
||||
return isFinished
|
||||
})
|
||||
@ -39,7 +42,7 @@ func main() {
|
||||
// return isSuccess
|
||||
//})
|
||||
appIns.Run(Router{
|
||||
"salesman": salesman.Project,
|
||||
"provider": provider.Project,
|
||||
"app": app.Project,
|
||||
})
|
||||
}
|
||||
|
80
example/provider/company.go
Normal file
80
example/provider/company.go
Normal file
@ -0,0 +1,80 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
)
|
||||
|
||||
var CompanyCtr = 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("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"] = 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"])
|
||||
|
||||
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 == "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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
that.Db.Update("company", company, Map{"id": id})
|
||||
|
||||
that.Display(0, "更新成功")
|
||||
|
||||
},
|
||||
}
|
28
example/provider/init.go
Normal file
28
example/provider/init.go
Normal file
@ -0,0 +1,28 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Project 管理端项目
|
||||
var Project = Proj{
|
||||
"salesman": Salesman,
|
||||
"wechat": Wechat,
|
||||
}
|
||||
|
||||
//生成随机码的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
|
||||
}
|
99
example/provider/matters.go
Normal file
99
example/provider/matters.go
Normal file
@ -0,0 +1,99 @@
|
||||
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["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)
|
||||
},
|
||||
|
||||
//用户微信公众号或者小程序登录
|
||||
"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)
|
||||
|
||||
that.Display(0, Map{"total": count, "data": res})
|
||||
},
|
||||
}
|
227
example/provider/order.go
Normal file
227
example/provider/order.go
Normal file
@ -0,0 +1,227 @@
|
||||
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
|
||||
}
|
||||
|
||||
res := that.Db.Get("order", "*", Map{"id": 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, "salesman_id": that.Session("salesman_id").Data}})
|
||||
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, "salesman_id": that.Session("salesman_id").Data}})
|
||||
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
|
||||
}
|
||||
|
||||
data := Map{"del_flag": 0}
|
||||
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})
|
||||
},
|
||||
}
|
127
example/provider/salesman.go
Normal file
127
example/provider/salesman.go
Normal file
@ -0,0 +1,127 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
)
|
||||
|
||||
var Salesman = Ctr{
|
||||
"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
|
||||
}
|
||||
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.GetInt64("id") {
|
||||
that.Display(5, "你已经绑定了其他商户")
|
||||
return
|
||||
}
|
||||
|
||||
that.Db.Update("wechat", Map{"salesman_id": salesman.GetCeilInt64("id")}, Map{"id": wechat.GetInt64("id")})
|
||||
|
||||
wechat["salesman_id"] = salesman.GetCeilInt64("id")
|
||||
that.Session("salesman_id", salesman.GetCeilInt64("id"))
|
||||
that.Display(0, "登录成功!")
|
||||
|
||||
},
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package salesman
|
||||
package provider
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
@ -15,6 +15,11 @@ var Sms = Ctr{
|
||||
return
|
||||
}
|
||||
|
||||
if that.Session("wechat_id").Data == nil && that.Session("salesman_id").Data == nil {
|
||||
that.Display(2, "没有登录不可发送短信")
|
||||
return
|
||||
}
|
||||
|
||||
code := getCode()
|
||||
that.Session("phone", phone)
|
||||
that.Session("code", code)
|
145
example/provider/user.go
Normal file
145
example/provider/user.go
Normal file
@ -0,0 +1,145 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
)
|
||||
|
||||
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["expiration_time[<]"] = "now()"
|
||||
}
|
||||
|
||||
if tp == 3 {
|
||||
data["certification_flag"] = 1
|
||||
data["expiration_time[>]"] = "now()"
|
||||
}
|
||||
|
||||
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})
|
||||
},
|
||||
}
|
95
example/provider/wechat.go
Normal file
95
example/provider/wechat.go
Normal file
@ -0,0 +1,95 @@
|
||||
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": 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.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)
|
||||
|
||||
},
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package salesman
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"code.hoteas.com/golang/hotime/dri/ddsms"
|
||||
"github.com/silenceper/wechat/v2"
|
||||
"github.com/silenceper/wechat/v2/cache"
|
||||
"github.com/silenceper/wechat/v2/miniprogram"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/config"
|
||||
"github.com/silenceper/wechat/v2/officialaccount"
|
||||
h5config "github.com/silenceper/wechat/v2/officialaccount/config"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Project 管理端项目
|
||||
var Project = Proj{
|
||||
"salesman": Salesman,
|
||||
"wechat": Wechat,
|
||||
}
|
||||
var weixin *wechat.Wechat //微信登录实例
|
||||
var miniProgram *miniprogram.MiniProgram
|
||||
var h5Program *officialaccount.OfficialAccount
|
||||
|
||||
func InitApp(app *Application) {
|
||||
weixin = wechat.NewWechat()
|
||||
memory := cache.NewMemory()
|
||||
memoryMini := cache.NewMemory()
|
||||
cfg := &config.Config{
|
||||
AppID: app.Config.GetString("wechatMiniAppID"),
|
||||
AppSecret: app.Config.GetString("wechatMiniAppSecret"),
|
||||
//Token: "xxx",
|
||||
//EncodingAESKey: "xxxx",
|
||||
Cache: memoryMini,
|
||||
}
|
||||
h5cfg := &h5config.Config{
|
||||
AppID: app.Config.GetString("wechatAppID"),
|
||||
AppSecret: app.Config.GetString("wechatAppSecret"),
|
||||
//Token: "xxx",
|
||||
//EncodingAESKey: "xxxx",
|
||||
Cache: memory,
|
||||
}
|
||||
|
||||
miniProgram = weixin.GetMiniProgram(cfg)
|
||||
h5Program = weixin.GetOfficialAccount(h5cfg)
|
||||
|
||||
ddsms.DDY.Init(app.Config.GetString("smsKey"))
|
||||
}
|
||||
|
||||
//生成随机码的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
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package salesman
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
)
|
||||
|
||||
var Salesman = Ctr{
|
||||
//用户微信公众号或者小程序登录
|
||||
"login": func(that *Context) {
|
||||
acttoken := that.Req.FormValue("acttoken")
|
||||
retoken := that.Req.FormValue("retoken")
|
||||
appid := that.Req.FormValue("appid")
|
||||
unionid := that.Req.FormValue("unionid")
|
||||
openid := that.Req.FormValue("openid")
|
||||
nickname := that.Req.FormValue("nickname")
|
||||
avatar := that.Req.FormValue("avatar")
|
||||
phone := that.Req.FormValue("phone")
|
||||
Type := ObjToInt(that.Req.FormValue("type"))
|
||||
|
||||
if acttoken == "" || retoken == "" || appid == "" || unionid == "" || openid == "" || nickname == "" || avatar == "" || that.Req.FormValue("type") == "" || phone == "" {
|
||||
that.Display(3, "请求参数异常,请校验参数")
|
||||
return
|
||||
}
|
||||
|
||||
wechat := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": openid, "del_flag": 0}})
|
||||
salesman := that.Db.Get("salesman", "*", Map{"phone": phone})
|
||||
|
||||
if salesman == nil {
|
||||
that.Display(3, "找不到企服商")
|
||||
return
|
||||
}
|
||||
|
||||
if wechat != nil {
|
||||
//有用户直接返回
|
||||
if wechat.GetCeilInt("salesman_id") != 0 && wechat.GetCeilInt64("salesman_id") == salesman.GetInt64("id") {
|
||||
that.Display(0, wechat)
|
||||
return
|
||||
}
|
||||
|
||||
that.Db.Update("wechat", Map{"salesman_id": salesman.GetCeilInt64("id")}, Map{"id": wechat.GetInt64("id")})
|
||||
|
||||
wechat["salesman_id"] = salesman.GetCeilInt64("id")
|
||||
that.Display(0, wechat)
|
||||
return
|
||||
}
|
||||
|
||||
wechat = Map{}
|
||||
wechat["salesman_id"] = salesman.GetCeilInt("id")
|
||||
wechat["acttoken"] = acttoken
|
||||
wechat["retoken"] = retoken
|
||||
wechat["appid"] = appid
|
||||
wechat["unionid"] = unionid
|
||||
wechat["openid"] = openid
|
||||
wechat["nickname"] = nickname
|
||||
wechat["avatar"] = avatar
|
||||
wechat["type"] = Type
|
||||
wechat["id"] = that.Db.Insert("wechat", wechat)
|
||||
if wechat.GetCeilInt("id") == 0 {
|
||||
that.Display(4, "创建用户失败")
|
||||
return
|
||||
}
|
||||
that.Display(0, wechat)
|
||||
|
||||
},
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
package salesman
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var Wechat = Ctr{
|
||||
"login": func(that *Context) {
|
||||
|
||||
sessionKey := that.Req.FormValue("sessionkey")
|
||||
encryptedData := that.Req.FormValue("encryptedData")
|
||||
iv := that.Req.FormValue("iv")
|
||||
|
||||
if sessionKey == "" || encryptedData == "" || iv == "" {
|
||||
that.Display(3, "参数不足")
|
||||
return
|
||||
}
|
||||
|
||||
eny := miniProgram.GetEncryptor()
|
||||
re, e := eny.Decrypt(sessionKey, encryptedData, iv)
|
||||
|
||||
if e != nil {
|
||||
that.Display(4, e)
|
||||
return
|
||||
}
|
||||
|
||||
that.Display(0, re.PhoneNumber)
|
||||
|
||||
},
|
||||
"code": func(that *Context) {
|
||||
code := that.Req.FormValue("code")
|
||||
if code == "" {
|
||||
that.Display(3, "缺少code")
|
||||
return
|
||||
}
|
||||
|
||||
a := miniProgram.GetAuth()
|
||||
re, e := a.Code2Session(code)
|
||||
fmt.Println(re)
|
||||
if e != nil {
|
||||
that.Display(4, e)
|
||||
return
|
||||
}
|
||||
wchat := Map{"openid": re.OpenID,
|
||||
"appid": a.AppID,
|
||||
"state": 0,
|
||||
"sessionkey": re.SessionKey,
|
||||
"unionid": re.UnionID,
|
||||
}
|
||||
//wchat["id"] = that.Db.Insert("wechat", wchat)
|
||||
|
||||
that.Display(0, wchat)
|
||||
return
|
||||
|
||||
},
|
||||
|
||||
////微信注册,0已经完整的注册了,1还没有注册
|
||||
"codeh5": func(that *Context) {
|
||||
|
||||
auth := h5Program.GetOauth()
|
||||
//weixin.GetOpenPlatform()
|
||||
resToken, err := auth.GetUserAccessToken(that.Req.FormValue("code"))
|
||||
if err != nil {
|
||||
that.Display(5, "code错误")
|
||||
return
|
||||
}
|
||||
|
||||
//getUserInfo
|
||||
userInfo, err := auth.GetUserInfo(resToken.AccessToken, resToken.OpenID, "")
|
||||
if err != nil {
|
||||
that.Display(6, "微信个人信息无法获取")
|
||||
return
|
||||
}
|
||||
|
||||
//wechatInfo := ObjToMap(userInfo)
|
||||
wechatInfo := Map{
|
||||
"openid": userInfo.OpenID,
|
||||
"acttoken": resToken.AccessToken,
|
||||
"retoken": resToken.RefreshToken,
|
||||
"appid": that.Config.GetString("wechatAppID"),
|
||||
"unionid": userInfo.Unionid,
|
||||
"nickname": userInfo.Nickname,
|
||||
"avatar": userInfo.HeadImgURL,
|
||||
}
|
||||
|
||||
that.Display(0, wechatInfo)
|
||||
},
|
||||
//网页签名
|
||||
"sign": func(that *Context) {
|
||||
|
||||
if that.Req.FormValue("sign_url") == "" {
|
||||
that.Display(2, "参数不足")
|
||||
return
|
||||
}
|
||||
signUrl := that.Req.FormValue("sign_url")
|
||||
js := h5Program.GetJs()
|
||||
cfg1, e := js.GetConfig(signUrl)
|
||||
if e != nil {
|
||||
that.Display(7, e)
|
||||
return
|
||||
}
|
||||
|
||||
sign := Map{
|
||||
"appId": cfg1.AppID,
|
||||
"timestamp": cfg1.Timestamp,
|
||||
"nonceStr": cfg1.NonceStr,
|
||||
"signature": cfg1.Signature,
|
||||
}
|
||||
|
||||
that.Display(0, sign)
|
||||
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue
Block a user