forked from golang/hotime
科服券列表+领券,企业认证,购买vip领券
This commit is contained in:
parent
d656faf915
commit
4e35dfe6ed
@ -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
|
||||
}
|
||||
},
|
||||
}
|
||||
|
56
example/app/coupon.go
Normal file
56
example/app/coupon.go
Normal file
@ -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})
|
||||
},
|
||||
}
|
@ -30,6 +30,7 @@ var Project = Proj{
|
||||
"websocket": WebsocketCtr,
|
||||
"wechath5": Wechath5,
|
||||
"wechatmini": Wechath5,
|
||||
"coupon": CouponCtr,
|
||||
}
|
||||
|
||||
//生成随机码的6位md5
|
||||
|
@ -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
|
||||
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user