From 4e35dfe6ed558f3a81d282f509316cad2a571373 Mon Sep 17 00:00:00 2001 From: zhoupengwei Date: Fri, 13 May 2022 15:34:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=91=E6=9C=8D=E5=88=B8=E5=88=97=E8=A1=A8+?= =?UTF-8?q?=E9=A2=86=E5=88=B8=EF=BC=8C=E4=BC=81=E4=B8=9A=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=EF=BC=8C=E8=B4=AD=E4=B9=B0vip=E9=A2=86=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/app/company.go | 140 +++++++++++++++++++++++++++++++++++++++ example/app/coupon.go | 56 ++++++++++++++++ example/app/init.go | 1 + example/app/vip_order.go | 15 +++++ 4 files changed, 212 insertions(+) create mode 100644 example/app/coupon.go diff --git a/example/app/company.go b/example/app/company.go index a1014c1..26fe08b 100644 --- a/example/app/company.go +++ b/example/app/company.go @@ -4,7 +4,13 @@ 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{ @@ -116,4 +122,138 @@ var CompanyCtr = Ctr{ 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 + } + }, } diff --git a/example/app/coupon.go b/example/app/coupon.go new file mode 100644 index 0000000..c8cb2c3 --- /dev/null +++ b/example/app/coupon.go @@ -0,0 +1,56 @@ +package app + +import ( + . "code.hoteas.com/golang/hotime" + . "code.hoteas.com/golang/hotime/common" +) + +var CouponCtr = Ctr{ + + "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 + } + + user_id := that.Session("user_id").Data + user := that.Db.Get("user", "*", Map{"id": user_id}) + if user == nil { + that.Display(1, "没有找到该用户") + return + } + + //0-待使用,1-已使用,2-已过期 + + status := ObjToInt(that.Req.FormValue("status")) + var data = Map{ + "coupon_user.user_id": user_id, + "coupon_user.state": 0, + } + if that.Req.FormValue("status") != "" { + data.Put("coupon_user.status", status) + } + + count := that.Db.Count("coupon_user", Map{"AND": data}) + + res := that.Db.Page(page, pageSize).PageSelect("coupon_user", + Map{"[>]coupon": "coupon_user.coupon_id = coupon.id"}, + "coupon_user.code_no,coupon_user.effective_start_time,coupon_user.effective_end_time,coupon_user.status,"+ + "coupon.coupon_amount,coupon.coupon_type,coupon.name,"+ + "coupon.description", + Map{"AND": data, + "ORDER": "coupon_user.create_time DESC"}) + that.Display(0, Map{"total": count, "data": res}) + }, +} diff --git a/example/app/init.go b/example/app/init.go index 5be176e..7f9d411 100644 --- a/example/app/init.go +++ b/example/app/init.go @@ -30,6 +30,7 @@ var Project = Proj{ "websocket": WebsocketCtr, "wechath5": Wechath5, "wechatmini": Wechath5, + "coupon": CouponCtr, } //生成随机码的6位md5 diff --git a/example/app/vip_order.go b/example/app/vip_order.go index 3e313e7..53bab79 100644 --- a/example/app/vip_order.go +++ b/example/app/vip_order.go @@ -154,6 +154,21 @@ var VipOrderCtr = Ctr{ return } fmt.Println("成功购买", user, vipOrder, re, data) + + //购买成功后赠送10张券 + //user_id := that.Session("user_id").Data + data2 := Map{ + "user_id": that.Session("user_id").Data, + "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()", + } + for n := 0; n < 10; n++ { + that.Db.Insert("coupon_user", data2) + } return },