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-05-09 07:07:01 +00:00
|
|
|
"strings"
|
2022-03-14 08:48:19 +00:00
|
|
|
"time"
|
2022-05-05 08:07:01 +00:00
|
|
|
"unicode/utf8"
|
2022-03-14 08:48:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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,
|
2022-05-05 08:07:01 +00:00
|
|
|
"upan": UpanCtr,
|
2022-05-03 14:40:02 +00:00
|
|
|
"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
|
|
|
|
2022-05-09 07:07:01 +00:00
|
|
|
func strToArray(str string) Slice {
|
|
|
|
s := Slice{}
|
|
|
|
|
|
|
|
olds := strings.Split(str, ",")
|
|
|
|
for _, v := range olds {
|
|
|
|
if v != "" {
|
|
|
|
s = append(s, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func arrayToStr(ars Slice) string {
|
|
|
|
s := ","
|
|
|
|
if ars == nil {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
for k, _ := range ars {
|
|
|
|
s = s + ars.GetString(k) + ","
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2022-05-03 00:09:25 +00:00
|
|
|
//认证公共方案
|
2022-05-06 03:35:40 +00:00
|
|
|
func auth(that *Context, phone, companyName, userName string) error {
|
2022-05-03 00:09:25 +00:00
|
|
|
|
2022-05-06 03:35:40 +00:00
|
|
|
user := that.Db.Get("user", "id,phone,salesman_id,company_id,provider_id,name", Map{"id": that.Session("user_id").ToCeilInt()})
|
2022-05-03 00:09:25 +00:00
|
|
|
if user == nil {
|
|
|
|
return errors.New("找不到用户")
|
|
|
|
}
|
2022-05-06 03:35:40 +00:00
|
|
|
company := that.Db.Get("company", "name,id", Map{"id": user.GetCeilInt("company_id")})
|
2022-05-07 03:02:12 +00:00
|
|
|
|
2022-05-06 03:35:40 +00:00
|
|
|
if company == nil {
|
|
|
|
return errors.New("找不到企业")
|
|
|
|
}
|
2022-05-03 00:09:25 +00:00
|
|
|
//手机号与原来的不同则进行绑定
|
2022-05-06 03:35:40 +00:00
|
|
|
if phone != user.GetString("phone") || companyName != company.GetString("name") || user.GetString("name") != userName {
|
2022-05-03 00:09:25 +00:00
|
|
|
//微信验证成功
|
|
|
|
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 {
|
2022-05-06 03:35:40 +00:00
|
|
|
that.Db.Update("user", Map{"phone": phone, "name": userName}, Map{"id": user.GetCeilInt("id")})
|
2022-05-03 00:09:25 +00:00
|
|
|
if user.GetCeilInt("company_id") != 0 {
|
|
|
|
that.Db.Update("company", Map{"phone": phone}, Map{"id": user.GetCeilInt("company_id")})
|
|
|
|
}
|
|
|
|
user["phone"] = phone
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
//
|
2022-05-06 03:35:40 +00:00
|
|
|
//company := that.Db.Get("company", "name,id", Map{"id": user.GetCeilInt("company_id")})
|
2022-05-03 00:09:25 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
}
|
2022-05-05 08:07:01 +00:00
|
|
|
|
|
|
|
// FilterEmoji 过滤 emoji 表情
|
|
|
|
func FilterEmoji(content string) string {
|
|
|
|
new_content := ""
|
|
|
|
for _, value := range content {
|
|
|
|
_, size := utf8.DecodeRuneInString(string(value))
|
|
|
|
if size <= 3 {
|
|
|
|
new_content += string(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new_content
|
|
|
|
}
|