123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837 |
- package front
- import (
- "encoding/base64"
- "encoding/json"
- "errors"
- "fmt"
- "jfw/config"
- "jfw/public"
- "log"
- "qfw/util"
- "qfw/util/jy"
- "qfw/util/redis"
- "regexp"
- "strconv"
- "strings"
- "time"
- "github.com/SKatiyar/qr"
- "github.com/go-xweb/xweb"
- )
- type DataExport struct {
- *xweb.Action
- toSieve xweb.Mapper `xweb:"/front/dataExport/toSieve"` //数据导出-条件筛选
- sieveData xweb.Mapper `xweb:"/front/dataExport/sieveData"` //筛选数据
- toMyOrder xweb.Mapper `xweb:"/front/dataExport/toMyOrder"` //我的订单
- queryOrder xweb.Mapper `xweb:"/front/dataExport/queryOrder"` //查询我的订单
- deleteOrder xweb.Mapper `xweb:"/front/dataExport/deleteOrder"` //删除订单
- toOrderDetail xweb.Mapper `xweb:"/front/dataExport/toOrderDetail/(.*)"` //订单详情
- getOrderCode xweb.Mapper `xweb:"/front/dataExport/getOrderCode/(\\w+)"` //申请发票获取订单编号
- applyInvoice xweb.Mapper `xweb:"/front/dataExport/applyInvoice"` //申请发票
- superSearchExport xweb.Mapper `xweb:"/front/dataExport/superSearchExport"` //数据导出-超级搜索
- toCreateOrderPage xweb.Mapper `xweb:"/front/dataExport/toCreateOrderPage/(.*)"` //数据导出-订单页面
- previewData xweb.Mapper `xweb:"/front/(.*)/previewData/(.*)"` //数据导出-数据预览
- sendMailVerify xweb.Mapper `xweb:"/front/dataExport/sendMailVerify"` //发送邮箱验证码
- checkMailVerify xweb.Mapper `xweb:"/front/dataExport/checkMailVerify"` //验证邮箱验证码
- paysuccess xweb.Mapper `xweb:"/front/dataExport/paysuccess"` //支付成功页面
- checkPhoneVerify xweb.Mapper `xweb:"/front/dataExport/checkPhoneVerify"` //验证手机号
- fontSet xweb.Mapper `xweb:"/front/dataExport/fontSet/(.*)"`
- cancelOrder xweb.Mapper `xweb:"/front/dataExport/cancelOrder"` //取消订单
- }
- var order_pageSize = 10
- func init() {
- xweb.AddAction(&DataExport{})
- }
- var (
- layout_date = "2006.01.02"
- orderStatus_unPaid = "0" //订单状态-待支付
- orderStatus_paid = "1" //订单状态-已完成
- orderStatus_deleted = "-1" //订单状态-已删除
- orderStatus_cancel = "-2" //订单状态-已取消
- tableName_order = "dataexport_order" //订单表
- )
- func (d *DataExport) ToSieve() error {
- industrylist, sortArray = getindustrys()
- d.T["industrylist"] = industrylist
- d.T["sortArray"] = sortArray
- d.T["logid"] = config.Seoconfig["dataexport"].(string)
- d.Render("/pc/dataExport_sieve.html", &d.T)
- return nil
- }
- func (d *DataExport) SieveData() error {
- publishtime := d.GetString("publishtime")
- area := d.GetString("area")
- city := d.GetString("city")
- region := d.GetString("region")
- industry := d.GetString("industry")
- keyword := d.GetString("keyword")
- minPrice := d.GetString("minprice")
- maxPrice := d.GetString("maxprice")
- subType := d.GetString("subtype")
- buyer := d.GetString("buyer")
- winner := d.GetString("winner")
- var areaArr []string
- var cityArr []string
- var regionArr []string
- var industryArr []string
- var subTypeArr []string
- var buyerArr []string
- var winnerArr []string
- var keywordList []public.KeyWord
- log.Println("price", minPrice, maxPrice)
- if publishtime != "" {
- log.Println("publishtime", publishtime)
- }
- if area != "" {
- areaArr = strings.Split(area, ",")
- log.Println("areaArr", areaArr)
- }
- if city != "" {
- cityArr = strings.Split(city, ",")
- log.Println("cityArr", cityArr)
- }
- if region != "" {
- regionArr = strings.Split(region, ",")
- log.Println("regionArr", regionArr)
- }
- if industry != "" {
- industryArr = strings.Split(industry, ",")
- log.Println("industryArr", industryArr)
- }
- if subType != "" {
- subTypeArr = strings.Split(subType, ",")
- log.Println("subTypeArr", subTypeArr)
- }
- log.Println("keywordParam", keyword)
- if keyword != "" {
- err := json.Unmarshal([]byte(keyword), &keywordList)
- if err != nil {
- log.Println("keyword param 反序列化异常,查看前后台字段是否对应")
- } else {
- log.Println("keywordList", len(keywordList), keywordList)
- }
- }
- if buyer != "" {
- buyerArr = strings.Split(buyer, ",")
- log.Println("buyerArr", buyerArr)
- }
- if winner != "" {
- winnerArr = strings.Split(winner, ",")
- log.Println("winnerArr", winnerArr)
- }
- sieveCondition := map[string]interface{}{
- "publishtime": publishtime,
- "area": areaArr,
- "city": cityArr,
- "region": regionArr,
- "industry": industryArr,
- "keywords": keywordList,
- "minprice": minPrice,
- "maxprice": maxPrice,
- "subtype": subType,
- "buyer": buyerArr,
- "winner": winnerArr,
- "comeintime": time.Now().Unix(),
- "comeinfrom": "exportPage",
- }
- if d.GetSession("s_m_openid") != nil {
- sieveCondition["s_openid"] = d.GetSession("s_m_openid").(string)
- }
- if d.GetSession("userId") != nil {
- sieveCondition["s_userid"] = d.GetSession("userId").(string)
- }
- _id := mongodb.Save(public.ExportTable, sieveCondition)
- if _id != "" {
- d.T["success"] = true
- d.T["redirectUrl"] = "/front/dataExport/toCreateOrderPage/" + util.SE.Encode2Hex(_id)
- } else {
- d.T["success"] = false
- }
- d.ServeJson(&d.T)
- return nil
- }
- func (d *DataExport) ToMyOrder() error {
- d.T["logid"] = config.Seoconfig["dataexport"].(string)
- d.Render("/pc/myOrder.html", &d.T)
- return nil
- }
- func (d *DataExport) QueryOrder() error {
- typ := d.GetString("type") //0-全部 1-待支付 2-已支付 3-已取消
- query := map[string]interface{}{}
- if userId := d.GetSession("userId"); userId != nil {
- query["user_id"] = userId.(string)
- log.Println("QueryOrder -- userId====================", userId)
- } else {
- log.Println("QueryOrder -- session userId does not exist")
- return nil
- }
- if typ != "0" && typ != "" {
- var status string
- if typ == "1" {
- status = orderStatus_unPaid
- } else if typ == "2" {
- status = orderStatus_paid
- } else if typ == "3" {
- status = orderStatus_cancel
- }
- query["order_status"] = status
- } else {
- query["order_status"] = map[string]interface{}{"ne": orderStatus_deleted}
- }
- //总数
- countData := public.Mysql.Find(tableName_order, query, "", "", -1, 0)
- count := len(*countData)
- //当前页
- pageNum, _ := d.GetInteger("pageNum")
- //开始下标索引
- var start = (pageNum - 1) * order_pageSize
- //总页数
- //totalPage := (count + int(order_pageSize) - 1) / int(order_pageSize)
- list := public.Mysql.Find(tableName_order, query, "", "create_time desc", start, order_pageSize)
- if list != nil {
- for _, v := range *list {
- filter_publishtime := v["filter_publishtime"]
- if filter_publishtime != nil || filter_publishtime != "" {
- timeArr := strings.Split(filter_publishtime.(string), "_")
- if len(timeArr) == 2 {
- start, err := strconv.ParseInt(timeArr[0], 10, 64)
- end, erro := strconv.ParseInt(timeArr[1], 10, 64)
- if err == nil && erro == nil {
- v["filter_publishtime"] = util.FormatDateByInt64(&start, layout_date) + "-" + util.FormatDateByInt64(&end, layout_date)
- }
- }
- }
- orderMoney := v["order_money"]
- if orderMoney != nil {
- v["order_money"] = float64(orderMoney.(int64)) / 100
- }
- if v["id"] != nil && orderMoney != nil && v["order_code"] != nil {
- v["token"] = public.GetWaitPayToken(v["id"].(int64), int(orderMoney.(int64)), v["order_code"].(string), util.ObjToString(v["pay_way"]), query["user_id"].(string))
- }
- }
- }
- for _, v := range *list {
- if v["pay_way"] == "wx_pc" && util.IntAll(v["order_status"]) == 0 {
- r, _ := qr.Encode(util.ObjToString(v["code_url"]), qr.M)
- pngdat := r.PNG()
- v["code_url"] = base64.StdEncoding.EncodeToString(pngdat)
- }
- }
- d.ServeJson(map[string]interface{}{
- "list": list,
- "count": count,
- "pageSize": order_pageSize,
- })
- return nil
- }
- /**
- 根据 id+openid 取消订单
- */
- func (d *DataExport) CancelOrder() error {
- if userId := d.GetSession("userId"); userId != nil {
- // if openid := d.GetSession("s_m_openid"); openid != nil {
- queryMap := map[string]interface{}{
- "id": d.GetString("id"),
- "user_id": userId.(string),
- }
- boo := public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"order_status": -2})
- //取消订单
- d.ServeJson(map[string]interface{}{"success": boo})
- }
- return nil
- }
- /**
- 根据 id+openid 删除
- */
- func (d *DataExport) DeleteOrder() error {
- if userId := d.GetSession("userId"); userId != nil {
- // if openid := d.GetSession("s_m_openid"); openid != nil {
- queryMap := map[string]interface{}{
- "id": d.GetString("id"),
- "user_id": userId.(string),
- }
- boo := public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"order_status": -1})
- //撤销订单
- d.ServeJson(map[string]interface{}{"success": boo})
- }
- return nil
- }
- /**
- 根据 订单编号+userId 查询
- */
- func (d *DataExport) ToOrderDetail(orderCode string) error {
- myUserId := ""
- if userId := d.GetSession("userId"); userId != nil {
- // if openid := d.GetSession("s_m_openid"); openid != nil {
- myUserId = userId.(string)
- } else {
- return nil
- }
- orderDetail := map[string]interface{}{}
- filter := public.SieveCondition{}
- queryMap := map[string]interface{}{
- "order_code": orderCode,
- "user_id": myUserId,
- }
- if orderCode != "" {
- orderDetail = *public.Mysql.FindOne(tableName_order, queryMap, "", "")
- }
- // log.Println("ToOrderDetail", orderCode, orderDetail)
- if orderDetail["pay_money"] != nil {
- orderDetail["pay_money"] = float64(orderDetail["pay_money"].(int64)) / 100
- }
- if orderDetail["order_money"] != nil {
- orderDetail["order_money"] = float64(orderDetail["order_money"].(int64)) / 100
- }
- if orderDetail["filter"] != nil {
- err := json.Unmarshal([]byte(orderDetail["filter"].(string)), &filter)
- if err == nil {
- publishtime := filter.PublishTime
- if publishtime != "" {
- timeArr := strings.Split(publishtime, "_")
- if len(timeArr) == 2 {
- start, err := strconv.ParseInt(timeArr[0], 10, 64)
- end, erro := strconv.ParseInt(timeArr[1], 10, 64)
- if err == nil && erro == nil {
- filter.PublishTime = util.FormatDateByInt64(&start, layout_date) + "-" + util.FormatDateByInt64(&end, layout_date)
- } else if err == nil && erro != nil {
- filter.PublishTime = util.FormatDateByInt64(&start, layout_date) + "-"
- } else if err != nil && erro == nil {
- filter.PublishTime = "-" + util.FormatDateByInt64(&end, layout_date)
- }
- }
- }
- filter.MinPrice = public.GetPriceDes_SieveCondition(filter.MinPrice, filter.MaxPrice)
- orderDetail["filter"] = filter
- } else {
- log.Println("筛选条件-关键词-结构体反序列化-错误", err)
- }
- }
- if orderDetail["applybill_type"] != nil && orderDetail["applybill_type"].(int64) == 0 {
- orderDetail["applybill_type"] = "个人"
- } else if orderDetail["applybill_type"] != nil && orderDetail["applybill_type"].(int64) == 1 {
- orderDetail["applybill_type"] = "单位"
- } else {
- orderDetail["applybill_type"] = "-"
- }
- if orderDetail["applybill_status"] != nil && orderDetail["applybill_status"].(int64) == 1 {
- orderDetail["applybill_status"] = "T" //已申请
- } else {
- orderDetail["applybill_status"] = "F" //未申请
- }
- orderStatus := util.IntAll((orderDetail)["order_status"])
- if orderStatus == 1 {
- orderDetail["transaction_id"] = func() string {
- table := ""
- payway := util.ObjToString(orderDetail["pay_way"])
- if strings.Contains(payway, "wx") {
- payway = "微信"
- table = "weixin_pay"
- } else if strings.Contains(payway, "ali") {
- payway = "支付宝"
- table = "ali_pay"
- } else {
- return ""
- }
- orderDetail["pay_way"] = payway
- wxPayMap := map[string]interface{}{}
- wxPayMap["out_trade_no"] = orderDetail["out_trade_no"]
- wxpay := public.Mysql.FindOne(table, wxPayMap, "", "")
- return util.ObjToString((*wxpay)["transaction_id"])
- }()
- }
- d.T["o"] = orderDetail
- d.T["logid"] = config.Seoconfig["dataexport"].(string)
- d.Render("/pc/orderDetail.html", &d.T)
- return nil
- }
- //------------------------------申请发票跳转页面-----------------------------
- func (d *DataExport) GetOrderCode(order_code string) error {
- var status, order_status int64
- queryMap := map[string]interface{}{
- "order_code": order_code,
- }
- oDate := public.Mysql.FindOne(tableName_order, queryMap, "", "")
- status = (*oDate)["applybill_status"].(int64)
- order_status = (*oDate)["order_status"].(int64)
- d.T["order_code"] = order_code
- d.T["logid"] = config.Seoconfig["dataexport"].(string)
- //是否申请发票 支付状态
- if status == 1 || order_status == 0 {
- d.Redirect("/front/dataExport/toOrderDetail/" + order_code)
- } else {
- d.Render("/pc/dataExport_invoice.html", &d.T)
- }
- return nil
- }
- //----------------------------申请发票------------------------------------
- func (d *DataExport) ApplyInvoice() error {
- var applyBill_status int
- var order_code, applyBill_company, applyBill_taxnum, applyBill_type string
- var updateBl bool = false
- order_code = d.GetString("order_code")
- //获取数据
- applyBill_type = d.GetString("demo-radio") //个人 单位
- queryMap := map[string]interface{}{
- "order_code": order_code,
- }
- if applyBill_type == "个人" {
- applyBill_status = 1
- updateBl = public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"applyBill_status": applyBill_status})
- } else if applyBill_type == "单位" {
- applyBill_status = 1 //状态
- applyBill_company = d.GetString("applyBill_company") //公司名
- applyBill_taxnum = d.GetString("applyBill_taxnum") //纳税人识别号
- updateBl = public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{
- "applyBill_company": applyBill_company,
- "applyBill_taxnum": applyBill_taxnum,
- "applyBill_status": applyBill_status,
- "applyBill_type": 1,
- }) //修改操作
- }
- //判断条件
- if updateBl {
- go func() {
- orderdata := public.Mysql.FindOne(tableName_order, map[string]interface{}{
- "order_code": order_code,
- }, "id,filter,user_mail,user_phone,product_type,data_spec,filter_id,order_code,data_count,order_status,order_money,out_trade_no,applybill_type,applybill_company,applybill_taxnum,user_openid,create_time,pay_time,pay_way", "")
- tt := time.Now()
- pay_time := util.FormatDate(&tt, util.Date_Full_Layout)
- public.SendMailToBJFinance(orderdata, pay_time, "", 2, config.GmailAuth)
- }()
- }
- d.ServeJson(map[string]interface{}{
- "flag": updateBl,
- })
- return nil
- }
- //---------------------------生成订单预览----------------------------------
- func (d *DataExport) SuperSearchExport() error {
- openid := util.ObjToString(d.GetSession("s_m_openid"))
- userId := util.ObjToString(d.GetSession("userId"))
- if userId == "" {
- return errors.New("未登录")
- }
- //接收超级搜索页面参数
- keywords := d.GetString("keywords") //搜索词
- publishtime := d.GetString("publishtime") //发布时间
- area := d.GetString("area") //地区
- subtype := d.GetString("subtype") //信息类型
- minprice := d.GetString("minprice") //最低价格
- maxprice := d.GetString("maxprice") //最高价格
- industry := strings.TrimSpace(d.GetString("industry")) //选中的行业
- selectType := d.GetString("selectType") //标题 or 全文
- //数据回显
- d.SetSession("Echo_keywords", keywords)
- d.SetSession("Echo_publishtime", publishtime)
- d.SetSession("Echo_timeslot", d.GetString("timeslot"))
- d.SetSession("Echo_area", area)
- d.SetSession("Echo_subtype", subtype)
- d.SetSession("Echo_minprice", minprice)
- d.SetSession("Echo_maxprice", maxprice)
- d.SetSession("Echo_industry", industry)
- d.SetSession("Echo_selectType", selectType)
- //数据存库转换
- areaSave := []string{}
- if len(area) > 0 {
- areaSave = strings.Split(area, ",")
- }
- industrySave := []string{}
- if len(industry) > 0 {
- industrySave = strings.Split(industry, ",")
- }
- //格式化keywords
- KeyWordSave := []public.KeyWord{}
- if len(keywords) > 0 {
- isIntercept := false
- if selectType == "all" {
- isIntercept = true
- }
- _, _, keywords = jy.InterceptSearchKW(keywords, isIntercept, len(industrySave) == 0)
- KeyWordSave = append(KeyWordSave, public.KeyWord{Keyword: keywords})
- }
- //时间
- now := time.Now()
- if publishtime == "lately-7" { //最近7天
- starttime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
- publishtime = fmt.Sprintf("%s_%d", starttime, now.Unix())
- } else if publishtime == "lately-30" { //最近30天
- starttime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
- publishtime = fmt.Sprintf("%s_%d", starttime, now.Unix())
- } else if publishtime == "thisyear" { //去年
- starttime := fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Unix())
- endtime := fmt.Sprint(time.Date(now.Year(), 1, 1, 0, 0, 0, 0, time.Local).Unix())
- publishtime = fmt.Sprintf("%s_%s", starttime, endtime)
- }
- data := map[string]interface{}{
- "keywords": KeyWordSave,
- "publishtime": publishtime,
- "area": areaSave,
- "subtype": subtype,
- "minprice": minprice,
- "maxprice": maxprice,
- "industry": industrySave,
- "selectType": selectType,
- "comeintime": now.Unix(),
- "s_openid": openid,
- "comeinfrom": "supersearchPage",
- "s_userid": userId,
- }
- //存入数据库
- _id := mongodb.Save(public.ExportTable, data)
- //携带id跳转订单生成页面
- d.Redirect("/front/dataExport/toCreateOrderPage/" + util.SE.Encode2Hex(_id))
- return nil
- }
- func (d *DataExport) ToCreateOrderPage(_id string) error {
- id := util.SE.Decode4Hex(_id)
- openid := util.ObjToString(d.GetSession("s_m_openid"))
- userId := util.ObjToString(d.GetSession("userId"))
- if userId == "" {
- return errors.New("未登录")
- }
- msgCount := public.GetDataExportSearchCountUseId(id)
- if msgCount > public.ExConf.MsgMaxCount {
- msgCount = public.ExConf.MsgMaxCount
- }
- d.T["logid"] = config.Seoconfig["dataexport"].(string)
- if msgCount < 1 {
- d.Render("/pc/dataExport_noDataErr.html", &d.T)
- return nil
- }
- //订单数据存入session中
- d.SetSession("dataexport_waitcreateorder", map[string]interface{}{
- "id": id, //用户的筛选条件mongodb中的id string
- "data_count": msgCount, //匹配到的数据总数 int
- })
- //邮箱验证
- email := d.GetSession("DataExportVerifyEmail_val")
- resPhone := d.GetSession("DataExportVerifyPhone_val")
- log.Println(util.Int64All(d.GetSession("CreatEVerifyTime")), "----", time.Now().Unix())
- if email != nil {
- lastSendDEVerify := util.Int64All(d.GetSession("CreatEVerifyTime"))
- timeSpaceing := lastSendDEVerify - time.Now().Unix() + 60*5
- d.T["email"] = email
- d.T["timeSpaceing"] = timeSpaceing
- } else {
- mail_phone := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
- "user_id": userId,
- }, "user_mail,user_phone", "create_time desc")
- if mail_phone != nil {
- email = (*mail_phone)["user_mail"]
- resPhone = (*mail_phone)["user_phone"]
- }
- if email == nil || email == "" {
- userData, _ := mongodb.FindById("user", userId, `{"o_jy":1}`)
- o_jy := util.ObjToMap((*userData)["o_jy"])
- email = (*o_jy)["s_email"]
- }
- if email != nil && email != "" {
- d.SetSession("EMVerifySucess", true)
- d.SetSession("DataExportVerifyEmail_val", email)
- }
- d.T["email"] = email
- }
- //手机号
- phone := d.GetSession("DataExportVerifyPhone_val")
- if phone != nil && phone != "" {
- d.T["phone"] = phone
- } else {
- //剑鱼助手手机号登录
- if isPhone(openid) {
- phone = openid
- } else {
- phone = resPhone
- }
- if phone != nil && phone != "" {
- d.SetSession("DataExportVerifyPhone_val", phone)
- }
- d.T["phone"] = phone
- }
- d.T["_id"] = _id
- d.T["msgCount"] = msgCount
- d.T["msgMaxCount"] = public.ExConf.MsgMaxCount
- d.T["discount"] = public.ExConf.Discount
- d.T["discount10"] = public.ExConf.Discount * 10
- d.T["unitPrice_normal"] = public.ExConf.UnitPrice_normal
- d.T["unitPrice_senior"] = public.ExConf.UnitPrice_senior
- d.T["unitPrice_normal_final"] = (public.ExConf.UnitPrice_normal * 100) * (public.ExConf.Discount * 100) / 10000
- d.T["unitPrice_senior_final"] = (public.ExConf.UnitPrice_senior * 100) * (public.ExConf.Discount * 100) / 10000
- d.T["orderMinPrice"] = public.ExConf.OrderMinPrice
- incurKey := fmt.Sprintf("PreviewData_%s_%d", d.GetSession("userId"), time.Now().Day())
- d.T["PreviewData"] = util.IntAll(redis.Get("other", incurKey))
- // go func() {
- // orderdata := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
- // "order_code": "143049462075",
- // }, "id,filter,user_mail,user_phone,product_type,data_spec,filter_id,order_code,data_count,order_status,order_money,prepay_id,applybill_type,applybill_company,applybill_taxnum", "")
- // tt := time.Now()
- // pay_time := util.FormatDate(&tt, util.Date_Full_Layout)
- // go public.SendMailToBJFinance(orderdata, pay_time, 2, config.GmailAuth)
- // }()
- d.Render("/pc/createOrderPage.html", &d.T)
- return nil
- }
- func (d *DataExport) PreviewData(source, _id string) error {
- if !strings.Contains(source, "app") {
- userId := util.ObjToString(d.GetSession("userId"))
- // openid := util.ObjToString(d.GetSession("s_m_openid"))
- if userId == "" {
- return errors.New("未登录")
- }
- //数据预览每天限制50次
- incurKey := fmt.Sprintf("PreviewData_%s_%d", d.GetSession("userId"), time.Now().Day())
- times := util.IntAll(redis.Get("other", incurKey))
- if times >= 50 {
- return errors.New("超出预览次数")
- }
- if times == 0 {
- redis.Put("other", incurKey, 1, 24*60*60)
- } else {
- redis.Incr("other", incurKey)
- }
- }
- _id = util.SE.Decode4Hex(_id)
- dataType := d.GetString("dataType")
- //从500条数据中筛选字段最全五条
- res := public.GetDataExportSearchResultUseId(_id, dataType, -1)
- if res == nil {
- d.Render("/pc/dataExport_noDataErr.html", &d.T)
- log.Println("PreviewData查询出错")
- return nil
- }
- //格式化字段
- res_screen := public.ScreenData(res, dataType, 20)
- list := public.FormatExportData(&res_screen, config.Sysconfig["webdomain"].(string), dataType, true)
- d.T["data"] = subUrl(list, dataType)
- d.T["dataType"] = dataType
- d.T["ttf"] = public.GetFontVersion() + "_" + public.PC
- d.Render("/pc/previewData.html", &d.T)
- return nil
- }
- /**
- 设置ttf版本号
- */
- func (d *DataExport) FontSet(version string) {
- if public.ExConf.Font.Enabled {
- if version == "" {
- version = public.ExConf.Font.ConvertVersionDefault
- }
- b := redis.Put(public.ExConf.Font.RedisPool, public.ExConf.Font.RedisKey, version, -1)
- if b {
- d.RenderString("Congratulations , the font (version " + version + ") set successfully !")
- } else {
- d.RenderString("Sorry , there is an error , please view the logs !")
- }
- } else {
- d.RenderString("Sorry , permission denied , please contact the administrator !")
- }
- }
- func subUrl(list *[]map[string]interface{}, dataType string) *[]map[string]interface{} {
- for _, v := range *list {
- //加密截取url
- href := util.ObjToString(v["href"])
- url := util.ObjToString(v["url"])
- if len(url) > 40 { //截取剑鱼标讯地址
- v["url"] = url[:40] + "*****" + url[len(url)-10:]
- }
- if len(href) > 40 { //截取原文地址
- v["href"] = href[:40] + "*****" + href[len(href)-10:]
- } else if len(href) > 0 {
- v["href"] = href[:len(href)*8/10] + "*****"
- }
- }
- var result []map[string]interface{}
- bytes, marshalErr := json.Marshal(list)
- if marshalErr != nil {
- log.Println("数据导出字体混淆errMarshal", marshalErr)
- return list
- }
- //字体混淆
- hxb := public.GetFontConvertStr(public.ExConf.Font.ConvertVersionDefault, string(bytes), "pc")
- unmarshalErr := json.Unmarshal([]byte(hxb), &result)
- if unmarshalErr != nil {
- log.Println("数据导出字体混淆unmarshalErr", unmarshalErr)
- return list
- }
- return &result
- }
- //发送邮件
- func (d *DataExport) SendMailVerify() {
- email := d.GetString("email")
- if isEmail(email) {
- var email_used = true
- if email != d.GetSession("DataExportVerifyEmail") {
- d.DelSession("CreatEVerifyTime")
- // openid := util.ObjToString(d.GetSession("s_m_openid"))
- userId := util.ObjToString(d.GetSession("userId"))
- emails := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
- "user_mail": email,
- "user_id": userId,
- }, "user_mail", "")
- if emails != nil && util.ObjToString((*emails)["user_mail"]) != "" {
- email_used = false
- d.T["success"] = true
- d.T["errCode"] = 4
- d.T["errMsg"] = "此邮箱已被验证"
- d.SetSession("DataExportVerifyEmail_val", email)
- d.SetSession("EMVerifySucess", true)
- }
- }
- if email_used {
- lastSendDEVerify := util.Int64All(d.GetSession("CreatEVerifyTime"))
- log.Println(util.Int64All(d.GetSession("CreatEVerifyTime")), "----", time.Now().Unix())
- timeSpaceing := lastSendDEVerify - time.Now().Unix() + 60*5
- log.Println("--------:", timeSpaceing)
- incurKey := fmt.Sprintf("SendEmail_%s_%d", d.GetSession("userId"), time.Now().Day())
- //log.Println(incurKey)
- if lastSendDEVerify == 0 || timeSpaceing < 0 {
- //每日限制10次
- times := util.IntAll(redis.Get("other", incurKey))
- if times < 10 {
- if times == 0 {
- redis.Put("other", incurKey, 1, 24*60*60)
- } else {
- redis.Incr("other", incurKey)
- }
- //生成随机数
- verifyStr := strings.ToUpper(util.GetComplexRandom(6, 3, 3))
- d.SetSession("EMVerifySucess", false)
- d.SetSession("DataExportVerifyEmail", email)
- d.SetSession("DataExportVerify", verifyStr)
- d.SetSession("CreatEVerifyTime", time.Now().Unix())
- log.Println("====================", verifyStr, "====================", d.GetSession("CreatEVerifyTime"), "====================")
- //发送邮箱验证码
- go public.SendMailIdentCode(email, verifyStr, config.GmailAuth)
- d.T["success"] = true
- } else {
- d.T["success"] = false
- d.T["errCode"] = 3
- d.T["time"] = timeSpaceing
- d.T["errMsg"] = "验证码发送次数已达到今日上限"
- }
- } else {
- d.T["success"] = false
- d.T["errCode"] = 2
- d.T["time"] = timeSpaceing
- d.T["errMsg"] = "已发送,5分钟后再尝试"
- }
- }
- } else {
- d.T["success"] = false
- d.T["errCode"] = 1
- d.T["errMsg"] = "邮箱格式不正确"
- }
- d.ServeJson(&d.T)
- }
- func isPhone(value string) bool {
- var phonePattern = regexp.MustCompile("^[1][3-9][0-9]{9}$")
- return phonePattern.MatchString(value)
- }
- //验证手机号
- func (d *DataExport) CheckPhoneVerify() {
- phone := d.GetString("phone")
- verityResult := false
- if isPhone(phone) {
- verityResult = true
- d.SetSession("DataExportVerifyPhone", phone)
- }
- d.T["success"] = verityResult
- d.ServeJson(&d.T)
- }
- //验证邮箱
- func (d *DataExport) CheckMailVerify() {
- email := d.GetString("email")
- emailVerity := d.GetString("emailVerity")
- DataExportEmail := d.GetSession("DataExportVerifyEmail")
- DataExportVerify := d.GetSession("DataExportVerify")
- verityResult := false
- if emailVerity != "" && emailVerity == DataExportVerify && email != "" && email == DataExportEmail {
- verityResult = true
- d.DelSession("DataExportVerify")
- d.DelSession("CreatEVerifyTime")
- d.SetSession("EMVerifySucess", true)
- d.SetSession("DataExportVerifyEmail_val", DataExportEmail)
- }
- d.T["success"] = verityResult
- d.ServeJson(&d.T)
- }
- func isEmail(value string) bool {
- var emailPattern = regexp.MustCompile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$")
- return emailPattern.MatchString(value)
- }
- func (d *DataExport) Paysuccess() error {
- code := d.GetString("code")
- // openid, _ := d.GetSession("s_m_openid").(string)
- userId, _ := d.GetSession("userId").(string)
- data := map[string]interface{}{}
- if code != "" && userId != "" {
- data_ := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
- "order_code": code,
- "user_id": userId,
- "order_status": 1,
- }, "pay_way,user_mail,pay_time,pay_money,order_money", "")
- if data_ != nil {
- data = *data_
- if data["pay_money"] != nil {
- data["pay_money"] = util.Float64All(data["pay_money"]) / 100
- } else {
- data["pay_money"] = util.Float64All(data["order_money"]) / 100
- }
- if data["pay_way"] != nil {
- pay_way := util.ObjToString(data["pay_way"])
- if strings.Contains(pay_way, "wx") {
- pay_way = "微信"
- } else if strings.Contains(pay_way, "ali") {
- pay_way = "支付宝"
- }
- data["pay_way"] = pay_way
- }
- }
- }
- d.T["data"] = data
- d.T["order_code"] = code
- return d.Render("/pc/paysuccess.html")
- }
|