iedc-go/example/app/init.go

112 lines
3.1 KiB
Go
Raw Normal View History

2022-03-14 08:48:19 +00:00
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
2022-05-03 00:09:25 +00:00
"errors"
2022-03-14 08:48:19 +00:00
"time"
)
// Project 管理端项目
var Project = Proj{
2022-05-03 14:40:02 +00:00
"article": ArticleCtr,
"company": CompanyCtr,
"declare": DeclareCtr,
"favorite": FavoriteCtr,
"lxcx": Lxcx,
"matters": MattersCtr,
"notify": NotifyCtr,
"order": OrderCtr,
"policy": PolicyCtr,
"provider": ProviderCtr,
"search_record": SearchRecordCtr,
"sms": Sms,
"tag": TagCtr,
"user": UserCtr,
2022-05-04 16:29:30 +00:00
"vip_order": VipOrderCtr,
2022-05-03 14:40:02 +00:00
"websocket": WebsocketCtr,
"wechath5": Wechath5,
"wechatmini": Wechath5,
2022-03-14 08:48:19 +00:00
}
//生成随机码的6位md5
func getSn() string {
x := Rand(8)
return Substr(Md5(ObjToStr(int64(x)+time.Now().UnixNano()+int64(Rand(6)))), 0, 6)
}
2022-04-17 22:28:01 +00:00
//生成随机码的4位随机数
func getCode() string {
//res := ""
//for i := 0; i < 4; i++ {
res := ObjToStr(RandX(1000, 9999))
//}
return res
}
2022-05-03 00:09:25 +00:00
//认证公共方案
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
}