123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- package front
- import (
- "encoding/json"
- "errors"
- "fmt"
- "jy/src/jfw/config"
- "jy/src/jfw/jyutil"
- "strconv"
- "app.yhyue.com/moapp/jybase/encrypt"
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
- "app.yhyue.com/moapp/jypkg/public"
- "app.yhyue.com/moapp/jybase/go-xweb/xweb"
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/dataexport"
- // "jy/src/jfw/modules/app/src/jfw/pay"
- "jy/src/jfw/wx"
- "log"
- "net/url"
- "strings"
- "time"
- util "app.yhyue.com/moapp/jybase/common"
- . "app.yhyue.com/moapp/jybase/date"
- "app.yhyue.com/moapp/jybase/redis"
- "go.mongodb.org/mongo-driver/bson"
- )
- type WsDataExport struct {
- *xweb.Action
- searchExport xweb.Mapper `xweb:"/front/wx_dataExport/searchExport"` //微信数据导出
- toPreview xweb.Mapper `xweb:"/front/wx_dataExport/toPreview/(.*)"` //微信数据导出-预览页面
- getPreview xweb.Mapper `xweb:"/front/wx_dataExport/getPreview"` //微信数据导出-预览数据
- submitOrder xweb.Mapper `xweb:"/front/wx_dataExport/submitOrder"` //微信数据导出-提交订单页面
- wxToOrderDetail xweb.Mapper `xweb:"/front/wx_dataExport/wxToOrderDetail"` //微信数据导出-订单详情
- }
- func init() {
- xweb.AddAction(&WsDataExport{})
- }
- func (w *WsDataExport) WxToOrderDetail() error {
- getsession := w.Session().GetMultiple()
- myOpenid := ""
- if openid := w.GetSession("s_m_openid"); openid != nil {
- myOpenid = openid.(string)
- } else {
- if w.GetString("state") == "wx" {
- //微信跳回来的
- code := w.GetString("code")
- if code != "" {
- openid := jyutil.Getopenid(code)
- if openid != "" {
- FindUserAndCreateSess(openid, w.Session(), "wx", false, true)
- }
- }
- } else {
- if public.CheckWxBrowser(w.Request) {
- //所有参数都不再使用,跳到微信验证用户
- return w.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(w.Site()+w.Url()), "wx"), 302)
- }
- }
- userid := util.ObjToString(w.GetSession("userId"))
- myOpenid, _ = getsession["s_m_openid"].(string)
- if userid == "" {
- return errors.New("未登录")
- }
- }
- myUserId, _ := getsession["userId"].(string)
- orderCode := w.GetString("orderCode")
- //分享
- w.T["signature"] = wx.SignJSSDK(w.Site() + w.Url())
- w.T["openid"] = se.EncodeString(myOpenid)
- mynickname, _ := getsession["s_nickname"].(string)
- myavatar, _ := getsession["s_avatar"].(string)
- w.T["nickname"] = mynickname
- w.T["avatar"] = myavatar
- //-----------------------
- orderDetail := map[string]interface{}{}
- filter := dataexport.SieveCondition{}
- queryMap := map[string]interface{}{
- "order_code": orderCode,
- "user_id": myUserId,
- }
- if orderCode != "" {
- orderDetail = *public.Mysql.FindOne(tableName_order, queryMap, "", "")
- }
- orderDetail["order_code"] = orderCode
- if orderDetail["pay_money"] != nil {
- orderDetail["pay_money"] = float64(orderDetail["pay_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 = FormatDateByInt64(&start, layout_date) + "-" + FormatDateByInt64(&end, layout_date)
- } else if err == nil && erro != nil {
- filter.PublishTime = FormatDateByInt64(&start, layout_date) + "-"
- } else if err != nil && erro == nil {
- filter.PublishTime = "-" + FormatDateByInt64(&end, layout_date)
- }
- }
- }
- filter.MinPrice = public.GetPriceDes_SieveCondition(filter.MinPrice, filter.MaxPrice)
- // 处理行业其他
- tmpIndustry := []string{}
- for i := 0; i < len(filter.Industry); i++ {
- cIndustry := filter.Industry[i]
- if strings.Contains(cIndustry, "其它") {
- continue
- }
- tmpIndustry = append(tmpIndustry, cIndustry)
- }
- filter.Industry = tmpIndustry
- 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" //未申请
- }
- if orderDetail["pay_time"] != nil {
- pay_time := strings.Replace(orderDetail["pay_time"].(string), "-", ".", -1)
- orderDetail["pay_time"] = pay_time
- }
- if orderDetail["create_time"] != nil {
- create_time := strings.Replace(orderDetail["create_time"].(string), "-", ".", -1)
- orderDetail["create_time"] = create_time
- }
- orderMoney := orderDetail["order_money"]
- if orderMoney != nil {
- orderDetail["order_money"] = float64(orderMoney.(int64)) / 100
- }
- //加密
- orderStatus := util.IntAll((orderDetail)["order_status"])
- orderDetail["order_status"] = orderStatus
- 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, "", "")
- if wxpay == nil {
- return ""
- }
- return util.ObjToString((*wxpay)["transaction_id"])
- }()
- }
- w.T["o"] = orderDetail
- w.Render("/weixin/dataExport/dataExport_toOrderDetail.html", &w.T)
- return nil
- }
- func (w *WsDataExport) GetPreview() error {
- userId := util.ObjToString(w.GetSession("userId"))
- if userId == "" {
- return errors.New("未登录")
- }
- _res := make(map[string]interface{})
- //数据预览每天限制50次
- incurKey := fmt.Sprintf("PreviewData_%s_%d", w.GetSession("userId"), time.Now().Day())
- times := util.IntAll(redis.Get("other", incurKey))
- if times >= 50 {
- _res["msg"] = "超出预览次数"
- w.ServeJson(map[string]interface{}{
- "res": _res,
- })
- return nil
- }
- if times == 0 {
- redis.Put("other", incurKey, 1, 24*60*60)
- } else {
- redis.Incr("other", incurKey)
- }
- _id := encrypt.SE.Decode4Hex(w.GetString("_id"))
- dataType := w.GetString("dataType")
- //从500条数据中筛选字段最全五条
- scd := dataexport.GetSqlObjFromId(public.MQFW, _id)
- kws := scd.Keyword
- res, err := dataexport.GetDataExportSearchResult(public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.DbName, public.DbConf.Elasticsearch.Main.Address, scd, dataType, -1)
- if res == nil || err != nil {
- return w.Render("/pc/dataExport_noDataErr.html", &w.T)
- }
- msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.DbName, public.DbConf.Elasticsearch.Main.Address, _id)
- //格式化字段
- res_screen := dataexport.ScreenData(res, dataType, 20, kws)
- list := dataexport.FormatExportData(public.Mgo_Ent, &res_screen, config.Sysconfig["webdomain"].(string), dataType, true)
- //if msgCount > 20000 {
- // msgCount = 20000
- //}
- _res["data"] = subUrl(list, dataType)
- _res["dataType"] = dataType
- _res["total"] = msgCount
- w.ServeJson(map[string]interface{}{
- "res": _res,
- })
- return nil
- }
- // 预览
- func (w *WsDataExport) ToPreview(_id string) error {
- defer util.Catch()
- getsession := w.Session().GetMultiple()
- openid, _ := getsession["s_m_openid"].(string)
- userid, _ := getsession["userId"].(string)
- if userid == "" {
- if w.GetString("state") == "wx" {
- //微信跳回来的
- code := w.GetString("code")
- if code != "" {
- openid = jyutil.Getopenid(code)
- if openid != "" {
- FindUserAndCreateSess(openid, w.Session(), "wx", false, true)
- }
- }
- } else {
- if public.CheckWxBrowser(w.Request) {
- //所有参数都不再使用,跳到微信验证用户
- return w.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(w.Site()+w.Url()), "wx"), 302)
- }
- }
- userid = util.ObjToString(w.GetSession("userId"))
- }
- w.T["id"] = _id
- w.T["dataType"] = w.GetString("dataType")
- w.T["ttf"] = public.GetFontVersion() + "_" + public.PC
- return w.Render("/weixin/dataExport/dataExport_previewData.html")
- }
- // 创建订单页面
- func (w *WsDataExport) SubmitOrder() error {
- defer util.Catch()
- id := encrypt.SE.Decode4Hex(w.GetString("id"))
- openid := util.ObjToString(w.GetSession("s_m_openid"))
- userId := util.ObjToString(w.GetSession("userId"))
- if userId == "" {
- if w.GetString("state") == "wx" {
- //微信跳回来的
- code := w.GetString("code")
- if code != "" {
- openid = jyutil.Getopenid(code)
- if openid != "" {
- FindUserAndCreateSess(openid, w.Session(), "wx", false, true)
- }
- }
- } else {
- if public.CheckWxBrowser(w.Request) {
- //所有参数都不再使用,跳到微信验证用户
- return w.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(w.Site()+w.Url()), "wx"), 302)
- }
- }
- userId = util.ObjToString(w.GetSession("userId"))
- if userId == "" {
- return errors.New("未登录")
- }
- }
- msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.DbName, public.DbConf.Elasticsearch.Main.Address, id)
- if msgCount > public.ExConf.MsgMaxCount || msgCount == -1 {
- msgCount = public.ExConf.MsgMaxCount
- }
- if msgCount < 1 {
- w.Render("/weixin/dataExport/404.html", &w.T)
- return nil
- }
- //订单数据存入session中
- w.SetSession("dataexport_waitcreateorder", map[string]interface{}{
- "id": id, //用户的筛选条件mongodb中的id string
- "data_count": msgCount, //匹配到的数据总数 int
- })
- //邮箱验证
- // w.DelSession("DataExportVerifyEmail_val")
- // w.DelSession("DataExportVerifyPhone_val")
- resEmail, _ := w.GetSession("DataExportVerifyEmail_val").(string)
- resPhone, _ := w.GetSession("DataExportVerifyPhone_val").(string)
- if resEmail != "" {
- lastSendDEVerify := util.Int64All(w.GetSession("CreatEVerifyTime"))
- timeSpaceing := lastSendDEVerify - time.Now().Unix() + 60*5
- w.T["email"] = resEmail
- w.T["timeSpaceing"] = timeSpaceing
- }
- if resPhone != "" {
- w.T["phone"] = resPhone
- }
- if resEmail == "" || resPhone == "" {
- lastEmail, lastPhone := "", ""
- if lastPhone, lastEmail = dataexport.GetLastExportPhoneAndMail(public.Mysql, userId, util.ObjToString(w.GetSession("entUserId"))); lastPhone == "" || lastEmail == "" {
- userData := jyutil.Compatible.Select(userId, `{"s_myemail":1,"s_phone":1,"s_m_phone":1}`)
- if userData != nil && len(*userData) > 0 {
- if lastEmail == "" {
- lastEmail, _ = (*userData)["s_myemail"].(string)
- }
- if lastPhone == "" {
- lastPhone, _ = util.If((*userData)["s_phone"] != nil, (*userData)["s_phone"], (*userData)["s_m_phone"]).(string)
- }
- }
- }
- if resEmail == "" && lastEmail != "" {
- w.T["email"] = lastEmail
- w.SetSession("EMVerifySucess", true)
- w.SetSession("DataExportVerifyEmail_val", lastEmail)
- }
- if resPhone == "" {
- setPhone := lastPhone
- if isPhone(openid) { //剑鱼助手手机号登录
- setPhone = openid
- }
- if setPhone != "" {
- w.SetSession("DataExportVerifyPhone_val", lastPhone)
- }
- w.T["phone"] = lastPhone
- }
- }
- w.T["_id"] = w.GetString("id")
- w.T["msgCount"] = msgCount //信息总量
- incurKey := fmt.Sprintf("PreviewData_%s_%d", w.GetSession("userId"), time.Now().Day()) //每日限制预览次数
- w.T["PreviewData"] = util.IntAll(redis.Get("other", incurKey))
- //字段包
- spec := w.GetString("dataspec")
- if spec != "" {
- w.T["dataspec"] = spec
- }
- w.Render("/weixin/dataExport/dataExport_payOrder.html", &w.T)
- return nil
- }
- // 微信数据导出
- func (wd *WsDataExport) SearchExport() error {
- openid := util.ObjToString(wd.GetSession("s_m_openid"))
- userId := util.ObjToString(wd.GetSession("userId"))
- mgoUserId := util.ObjToString(wd.GetSession("mgoUserId"))
- if userId == "" {
- return errors.New("未登录")
- }
- searchGroup, _ := wd.GetInteger("searchGroup")
- searchMode, _ := wd.GetInteger("searchMode")
- wordsMode, _ := wd.GetInteger("wordsMode")
- //接收超级搜索页面参数
- reqData := public.BidSearchExport{
- Keywords: wd.GetString("searchvalue"), //搜索词
- Publishtime: wd.GetString("publishtime"), //发布时间
- Area: wd.GetString("scope"), //地区
- Buyer: wd.GetString("buyer"), //采购单位
- Agency: wd.GetString("agency"), //招标代理机构
- Winner: wd.GetString("winner"), //中标企业
- Subtype: wd.GetString("subtype"), //信息类型
- Minprice: wd.GetString("minprice"), //最低价格
- Maxprice: wd.GetString("maxprice"), //最高价格
- Industry: strings.TrimSpace(wd.GetString("industry")), //选中的行业
- SelectType: wd.GetString("selectType"), //标题 or 全文
- Buyerclass: wd.GetString("buyerclass"), //采购单位行业
- Hasbuyertel: wd.GetString("buyertel"), //是否有采购电话
- Haswinnertel: wd.GetString("winnertel"), //是否有中标电话
- SelectIds: strings.TrimSpace(wd.GetString("selectIds")), //选择信息id
- Notkey: wd.GetString("notkey"), //排除词
- City: wd.GetString("city"), //城市
- FileExists: wd.GetString("fileExists"), //有无附件
- SearchGroup: searchGroup, //搜索分组:默认0:全部;1:招标采购公告;2:超前项目
- SearchMode: searchMode, //搜索模式:0:精准搜索;1:模糊搜索
- WordsMode: wordsMode, //搜索关键词模式;默认0:包含所有,1:包含任意
- AdditionalWords: wd.GetString("additionalWords"), //关键词:附加关键词(副:五组,每组最多15个字符)
- District: wd.GetString("district"),
- }
- if reqData.Subtype == "" { //移动 数据导出分组
- switch reqData.SearchGroup {
- case 3:
- reqData.Subtype = "招标公告"
- case 4:
- reqData.Subtype = "招标预告"
- case 5:
- reqData.Subtype = "招标结果"
- }
- }
- saveData := reqData.PassBidSearchExport(config.Sysconfig)
- saveData["selectType"] = strings.Join(jy.GetVipState(wd.Session(), *config.Middleground, userId).GetQueryItems(wd.GetString("selectType"), util.Int64All(config.Sysconfig["bidSearchOldUserLimit"])), ",")
- saveData["s_openid"] = openid
- saveData["s_userid"] = userId
- saveData["mgoUserId"] = mgoUserId
- saveData["comeinfrom"] = "supersearchPage"
- region := util.If(reqData.Area == "全国", "", reqData.Area).(string)
- if region != "" && reqData.City != "" {
- region += "," + reqData.City
- } else if region == "" {
- region = reqData.City
- }
- if reqData.District != "" {
- districtArr := []string{}
- for _, v := range strings.Split(reqData.District, ",") {
- if len(strings.Split(v, "_")) > 1 {
- district := strings.Split(v, "_")[1]
- districtArr = append(districtArr, district)
- }
- }
- if region != "" {
- region += "," + strings.Join(districtArr, ",")
- } else {
- region = strings.Join(districtArr, ",")
- }
- }
- region_arr := strings.Split(region, ",")
- if region == "" {
- region_arr = []string{}
- }
- saveData["region"] = region_arr
- //是否开启 正文 标题同时搜索只搜正文的开关
- saveData["searchTypeSwitch"], _ = config.Sysconfig["searchTypeSwitch"].(bool)
- //存入数据库
- _id := mongodb.Save(dataexport.ExportTable, saveData)
- wd.ServeJson(bson.M{"_id": encrypt.SE.Encode2Hex(_id)})
- return nil
- }
|