2022-05-03 00:09:25 +00:00
|
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
. "code.hoteas.com/golang/hotime"
|
|
|
|
|
. "code.hoteas.com/golang/hotime/common"
|
|
|
|
|
"code.hoteas.com/golang/hotime/dri/aliyun"
|
2022-05-13 07:34:15 +00:00
|
|
|
|
"code.hoteas.com/golang/hotime/dri/tencent"
|
|
|
|
|
"encoding/base64"
|
2022-05-03 00:09:25 +00:00
|
|
|
|
"fmt"
|
2022-05-13 07:34:15 +00:00
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
2022-05-03 00:09:25 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var CompanyCtr = Ctr{
|
2022-05-03 07:17:27 +00:00
|
|
|
|
|
|
|
|
|
"search": func(that *Context) {
|
2022-05-09 07:07:01 +00:00
|
|
|
|
if that.Session("user_id").Data == nil {
|
|
|
|
|
that.Display(2, "没有登录")
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-05-03 07:17:27 +00:00
|
|
|
|
keywords := that.Req.FormValue("keywords")
|
2022-05-04 16:29:30 +00:00
|
|
|
|
if keywords == "" {
|
|
|
|
|
keywords = that.Req.FormValue("company_name")
|
|
|
|
|
}
|
|
|
|
|
if keywords == "" {
|
|
|
|
|
keywords = that.Req.FormValue("name")
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-03 07:17:27 +00:00
|
|
|
|
if len(keywords) < 2 {
|
2022-05-03 00:09:25 +00:00
|
|
|
|
that.Display(0, Slice{})
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-05-03 07:17:27 +00:00
|
|
|
|
|
|
|
|
|
res, err := aliyun.Company.GetCompanyList(keywords)
|
2022-05-03 00:09:25 +00:00
|
|
|
|
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"))
|
|
|
|
|
},
|
2022-05-09 07:07:01 +00:00
|
|
|
|
"search_info": func(that *Context) {
|
|
|
|
|
if that.Session("user_id").Data == nil {
|
|
|
|
|
that.Display(2, "没有登录")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
name := that.Req.FormValue("name")
|
|
|
|
|
|
|
|
|
|
if len(name) < 2 {
|
|
|
|
|
that.Display(3, "找不到企业")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res, err := aliyun.Company.GetCompanyBaseInfo(name)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
that.Display(4, "查询失败")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if res.GetBool("status") != true {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
that.Display(4, "查询失败")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
that.Display(0, res.GetMap("data"))
|
|
|
|
|
},
|
|
|
|
|
"info": func(that *Context) {
|
|
|
|
|
if that.Session("user_id").Data == nil {
|
|
|
|
|
that.Display(2, "没有登录")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
id := ObjToInt(that.Req.FormValue("id"))
|
|
|
|
|
|
|
|
|
|
if id == 0 {
|
|
|
|
|
that.Display(3, "请求参数异常")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").Data})
|
|
|
|
|
if user == nil {
|
|
|
|
|
that.Display(4, "找不到用户")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res := that.Db.Get("company", "*", Map{"id": user.GetCeilInt("company_id")})
|
|
|
|
|
if res == nil {
|
|
|
|
|
that.Display(4, "找不到企业")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//先不做限制
|
|
|
|
|
//if res.GetCeilInt("salesman_id")!=that.Session("salesman_id").ToCeilInt(){
|
|
|
|
|
// that.Display(4,"不是你的企业")
|
|
|
|
|
// return
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//res["technology_center_flag"] = ObjToSlice(res["technology_center_flag"])
|
|
|
|
|
//res["engineering_center_flag"] = ObjToSlice(res["engineering_center_flag"])
|
|
|
|
|
//res["engineering_laboratory_flag"] = ObjToSlice(res["engineering_laboratory_flag"])
|
|
|
|
|
//res["key_laboratory_flag"] = ObjToSlice(res["key_laboratory_flag"])
|
|
|
|
|
//res["industrial_design_center_flag"] = ObjToSlice(res["industrial_design_center_flag"])
|
|
|
|
|
//
|
|
|
|
|
//res["high_level_talents_flag1"] = ObjToSlice(res["high_level_talents_flag1"])
|
|
|
|
|
//
|
|
|
|
|
//res["tags"] = ObjToSlice(res["tags"])
|
|
|
|
|
|
|
|
|
|
res["technology_center_flag"] = strToArray(res.GetString("technology_center_flag"))
|
|
|
|
|
res["engineering_center_flag"] = strToArray(res.GetString("engineering_center_flag"))
|
|
|
|
|
res["engineering_laboratory_flag"] = strToArray(res.GetString("engineering_laboratory_flag"))
|
|
|
|
|
res["key_laboratory_flag"] = strToArray(res.GetString("key_laboratory_flag"))
|
|
|
|
|
res["industrial_design_center_flag"] = strToArray(res.GetString("industrial_design_center_flag"))
|
|
|
|
|
res["high_level_talents_flag1"] = strToArray(res.GetString("high_level_talents_flag1"))
|
|
|
|
|
res["tags"] = strToArray(res.GetString("tags"))
|
|
|
|
|
|
|
|
|
|
that.Display(0, res)
|
|
|
|
|
},
|
2022-05-13 07:34:15 +00:00
|
|
|
|
"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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//统一社会信用代码
|
2022-05-13 10:43:35 +00:00
|
|
|
|
social_code := that.Req.FormValue("social_code")
|
|
|
|
|
if social_code == "" {
|
2022-05-13 07:34:15 +00:00
|
|
|
|
that.Display(3, "请求参数异常")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//企业名称
|
|
|
|
|
company_name := that.Req.FormValue("company_name")
|
|
|
|
|
if company_name == "" {
|
|
|
|
|
that.Display(3, "请求参数异常")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//手机号
|
|
|
|
|
phone := that.Req.FormValue("phone")
|
|
|
|
|
if phone == "" {
|
|
|
|
|
that.Display(3, "请求参数异常")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//姓名
|
|
|
|
|
name := that.Req.FormValue("user_name")
|
|
|
|
|
if name == "" {
|
|
|
|
|
that.Display(3, "请求参数异常")
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-05-17 04:31:47 +00:00
|
|
|
|
//验证码
|
|
|
|
|
err := auth(that, phone, company_name, name)
|
|
|
|
|
if err != nil {
|
|
|
|
|
that.Display(3, err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-05-13 07:34:15 +00:00
|
|
|
|
//营业执照路径
|
|
|
|
|
business_license := that.Req.FormValue("business_license")
|
2022-05-13 10:43:35 +00:00
|
|
|
|
if business_license == "" {
|
|
|
|
|
that.Display(3, "请求参数异常")
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-05-13 07:34:15 +00:00
|
|
|
|
user_id := that.Session("user_id").Data
|
|
|
|
|
user := that.Db.Get("user", "*", Map{"id": user_id})
|
|
|
|
|
if user == nil {
|
|
|
|
|
that.Display(1, "没有找到该用户")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
company := that.Db.Get("company", "*", Map{"AND": Map{"id": id, "user_id": user_id}})
|
|
|
|
|
if company == nil {
|
|
|
|
|
that.Display(4, "不是属于你的企业")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//认证
|
|
|
|
|
authentication_flag := 1
|
|
|
|
|
//if user.GetCeilInt("authentication_flag") == 0 {
|
|
|
|
|
// authentication_flag = 1
|
|
|
|
|
//}
|
|
|
|
|
//通过base64图片获取信息
|
|
|
|
|
|
|
|
|
|
that.Db.Update("user", Map{"name": name, "phone": phone, "authentication_flag": authentication_flag}, Map{"id": user_id})
|
|
|
|
|
|
2022-05-13 10:43:35 +00:00
|
|
|
|
that.Db.Update("company", Map{"social_code": social_code, "name": company_name, "phone": phone, "business_license": business_license, "modify_time[#]": "now()"}, Map{"id": id})
|
2022-05-13 07:34:15 +00:00
|
|
|
|
|
|
|
|
|
//赠送一张券
|
|
|
|
|
data := Map{
|
|
|
|
|
"user_id": user_id,
|
2022-05-13 07:50:45 +00:00
|
|
|
|
"coupon_id": 1,
|
2022-05-13 07:34:15 +00:00
|
|
|
|
"code_no": "SN" + time.Now().Format("20060102150405") + getSn(),
|
|
|
|
|
"effective_start_time[#]": "NOW()",
|
2022-05-17 04:31:47 +00:00
|
|
|
|
"effective_end_time": time.Now().AddDate(0, 6, 0).Format("2006-01-02 15:04:05"),
|
2022-05-13 10:43:35 +00:00
|
|
|
|
"source_type": 2,
|
2022-05-13 07:34:15 +00:00
|
|
|
|
"status": 0,
|
|
|
|
|
"admin_id": user.GetCeilInt("admin_id"),
|
|
|
|
|
"create_time[#]": "NOW()",
|
|
|
|
|
}
|
2022-05-13 10:43:35 +00:00
|
|
|
|
//先判断是否领取过 source_type=2 是通过认证赠送的券
|
|
|
|
|
couponCount := that.Db.Count("coupon_user", Map{"AND": Map{"user_id": user_id, "source_type": 2}})
|
2022-05-13 07:34:15 +00:00
|
|
|
|
if couponCount == 0 {
|
|
|
|
|
that.Db.Insert("coupon_user", data)
|
|
|
|
|
}
|
|
|
|
|
that.Display(0, "认证成功")
|
|
|
|
|
},
|
|
|
|
|
//上传营业执照
|
|
|
|
|
"upload": func(this *Context) {
|
|
|
|
|
file := this.Req.FormValue("file")
|
|
|
|
|
|
|
|
|
|
if len(file) < 100 {
|
|
|
|
|
this.Display(3, "图片上传错误")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//fmt.Println(uimg)
|
|
|
|
|
btes, e := base64.StdEncoding.DecodeString(file[strings.Index(file, ",")+1:]) //成图片文件并把文件写入到buffer
|
|
|
|
|
//btes, e := base64.StdEncoding.DecodeString(file) //成图片文件并把文件写入到buffer
|
|
|
|
|
if e != nil {
|
|
|
|
|
this.Display(3, "无法解析图片")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//uimgPath:=time.Now().Format(this.Config.GetString("uimgPath"))
|
|
|
|
|
path := time.Now().Format(this.Config.GetString("wxFilePath"))
|
|
|
|
|
os.MkdirAll(this.Config.GetString("tpt")+"/"+path, os.ModeDir)
|
|
|
|
|
filePath := path + Md5(ObjToStr(time.Now().Unix())) + ".jpg"
|
|
|
|
|
|
|
|
|
|
err2 := ioutil.WriteFile(this.Config.GetString("tpt")+"/"+filePath, btes, 0666) //buffer输出到jpg文件中(不做处理,直接写到文件)
|
|
|
|
|
if err2 != nil {
|
|
|
|
|
this.Display(3, "图片保存失败")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
tp := this.Req.FormValue("type")
|
|
|
|
|
|
|
|
|
|
if tp == "company" {
|
|
|
|
|
data := tencent.Tencent.OCRCOMPANY(file)
|
|
|
|
|
c := ObjToMap(data)
|
|
|
|
|
if c != nil {
|
|
|
|
|
c = c.GetMap("Response")
|
|
|
|
|
c["url"] = filePath
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
c = Map{"url": filePath}
|
|
|
|
|
}
|
|
|
|
|
this.Display(0, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-05-03 00:09:25 +00:00
|
|
|
|
}
|