package app import ( . "code.hoteas.com/golang/hotime" . "code.hoteas.com/golang/hotime/common" "code.hoteas.com/golang/hotime/dri/aliyun" "code.hoteas.com/golang/hotime/dri/tencent" "encoding/base64" "fmt" "io/ioutil" "os" "strings" "time" ) var CompanyCtr = Ctr{ "search": func(that *Context) { if that.Session("user_id").Data == nil { that.Display(2, "没有登录") return } keywords := that.Req.FormValue("keywords") if keywords == "" { keywords = that.Req.FormValue("company_name") } if keywords == "" { keywords = that.Req.FormValue("name") } if len(keywords) < 2 { that.Display(0, Slice{}) return } res, err := aliyun.Company.GetCompanyList(keywords) 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")) }, "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) }, "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 } //统一社会信用代码 code := that.Req.FormValue("social_code") if code == "" { 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 } //营业执照路径 business_license := that.Req.FormValue("business_license") //if business_license == ""{ // that.Display(3, "请求参数异常") // return //} 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}) that.Db.Update("company", Map{"code": code, "name": company_name, "phone": phone, "business_license": business_license, "modify_time[#]": "now()"}, Map{"id": id}) //赠送一张券 data := Map{ "user_id": user_id, "code_no": "SN" + time.Now().Format("20060102150405") + getSn(), "effective_start_time[#]": "NOW()", "effective_end_time": "2022-10-01 23:59:59", "status": 0, "admin_id": user.GetCeilInt("admin_id"), "create_time[#]": "NOW()", } //先判断是否领取过 couponCount := that.Db.Count("coupon_user", Map{"user_id": user_id}) fmt.Println(that.Db.LastQuery) fmt.Println(that.Db.LastData) fmt.Println(that.Db.LastErr) if couponCount == 0 { that.Db.Insert("coupon_user", data) } //不为0但是是10的倍数,说明是vip,也应该给一张 if couponCount != 0 && couponCount%10 == 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 } }, }