ws_dataExport.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. package front
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "jy/src/jfw/config"
  7. "jy/src/jfw/jyutil"
  8. "strconv"
  9. "app.yhyue.com/moapp/jybase/encrypt"
  10. "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
  11. "app.yhyue.com/moapp/jypkg/public"
  12. "app.yhyue.com/moapp/jybase/go-xweb/xweb"
  13. "app.yhyue.com/moapp/jypkg/common/src/qfw/util/dataexport"
  14. // "jy/src/jfw/modules/app/src/jfw/pay"
  15. "jy/src/jfw/wx"
  16. "log"
  17. "net/url"
  18. "strings"
  19. "time"
  20. util "app.yhyue.com/moapp/jybase/common"
  21. . "app.yhyue.com/moapp/jybase/date"
  22. "app.yhyue.com/moapp/jybase/redis"
  23. "go.mongodb.org/mongo-driver/bson"
  24. )
  25. type WsDataExport struct {
  26. *xweb.Action
  27. searchExport xweb.Mapper `xweb:"/front/wx_dataExport/searchExport"` //微信数据导出
  28. toPreview xweb.Mapper `xweb:"/front/wx_dataExport/toPreview/(.*)"` //微信数据导出-预览页面
  29. getPreview xweb.Mapper `xweb:"/front/wx_dataExport/getPreview"` //微信数据导出-预览数据
  30. submitOrder xweb.Mapper `xweb:"/front/wx_dataExport/submitOrder"` //微信数据导出-提交订单页面
  31. wxToOrderDetail xweb.Mapper `xweb:"/front/wx_dataExport/wxToOrderDetail"` //微信数据导出-订单详情
  32. }
  33. func init() {
  34. xweb.AddAction(&WsDataExport{})
  35. }
  36. func (w *WsDataExport) WxToOrderDetail() error {
  37. getsession := w.Session().GetMultiple()
  38. myOpenid := ""
  39. if openid := w.GetSession("s_m_openid"); openid != nil {
  40. myOpenid = openid.(string)
  41. } else {
  42. if w.GetString("state") == "wx" {
  43. //微信跳回来的
  44. code := w.GetString("code")
  45. if code != "" {
  46. openid := jyutil.Getopenid(code)
  47. if openid != "" {
  48. FindUserAndCreateSess(openid, w.Session(), "wx", false, true)
  49. }
  50. }
  51. } else {
  52. if public.CheckWxBrowser(w.Request) {
  53. //所有参数都不再使用,跳到微信验证用户
  54. return w.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(w.Site()+w.Url()), "wx"), 302)
  55. }
  56. }
  57. userid := util.ObjToString(w.GetSession("userId"))
  58. myOpenid, _ = getsession["s_m_openid"].(string)
  59. if userid == "" {
  60. return errors.New("未登录")
  61. }
  62. }
  63. myUserId, _ := getsession["userId"].(string)
  64. orderCode := w.GetString("orderCode")
  65. //分享
  66. w.T["signature"] = wx.SignJSSDK(w.Site() + w.Url())
  67. w.T["openid"] = se.EncodeString(myOpenid)
  68. mynickname, _ := getsession["s_nickname"].(string)
  69. myavatar, _ := getsession["s_avatar"].(string)
  70. w.T["nickname"] = mynickname
  71. w.T["avatar"] = myavatar
  72. //-----------------------
  73. orderDetail := map[string]interface{}{}
  74. filter := dataexport.SieveCondition{}
  75. queryMap := map[string]interface{}{
  76. "order_code": orderCode,
  77. "user_id": myUserId,
  78. }
  79. if orderCode != "" {
  80. orderDetail = *public.Mysql.FindOne(tableName_order, queryMap, "", "")
  81. }
  82. orderDetail["order_code"] = orderCode
  83. if orderDetail["pay_money"] != nil {
  84. orderDetail["pay_money"] = float64(orderDetail["pay_money"].(int64)) / 100
  85. }
  86. if orderDetail["filter"] != nil {
  87. err := json.Unmarshal([]byte(orderDetail["filter"].(string)), &filter)
  88. if err == nil {
  89. publishtime := filter.PublishTime
  90. if publishtime != "" {
  91. timeArr := strings.Split(publishtime, "_")
  92. if len(timeArr) == 2 {
  93. start, err := strconv.ParseInt(timeArr[0], 10, 64)
  94. end, erro := strconv.ParseInt(timeArr[1], 10, 64)
  95. if err == nil && erro == nil {
  96. filter.PublishTime = FormatDateByInt64(&start, layout_date) + "-" + FormatDateByInt64(&end, layout_date)
  97. } else if err == nil && erro != nil {
  98. filter.PublishTime = FormatDateByInt64(&start, layout_date) + "-"
  99. } else if err != nil && erro == nil {
  100. filter.PublishTime = "-" + FormatDateByInt64(&end, layout_date)
  101. }
  102. }
  103. }
  104. filter.MinPrice = public.GetPriceDes_SieveCondition(filter.MinPrice, filter.MaxPrice)
  105. // 处理行业其他
  106. tmpIndustry := []string{}
  107. for i := 0; i < len(filter.Industry); i++ {
  108. cIndustry := filter.Industry[i]
  109. if strings.Contains(cIndustry, "其它") {
  110. continue
  111. }
  112. tmpIndustry = append(tmpIndustry, cIndustry)
  113. }
  114. filter.Industry = tmpIndustry
  115. orderDetail["filter"] = filter
  116. } else {
  117. log.Println("筛选条件-关键词-结构体反序列化-错误", err)
  118. }
  119. }
  120. if orderDetail["applybill_type"] != nil && orderDetail["applybill_type"].(int64) == 0 {
  121. orderDetail["applybill_type"] = "个人"
  122. } else if orderDetail["applybill_type"] != nil && orderDetail["applybill_type"].(int64) == 1 {
  123. orderDetail["applybill_type"] = "单位"
  124. } else {
  125. orderDetail["applybill_type"] = "-"
  126. }
  127. if orderDetail["applybill_status"] != nil && orderDetail["applybill_status"].(int64) == 1 {
  128. orderDetail["applybill_status"] = "T" //已申请
  129. } else {
  130. orderDetail["applybill_status"] = "F" //未申请
  131. }
  132. if orderDetail["pay_time"] != nil {
  133. pay_time := strings.Replace(orderDetail["pay_time"].(string), "-", ".", -1)
  134. orderDetail["pay_time"] = pay_time
  135. }
  136. if orderDetail["create_time"] != nil {
  137. create_time := strings.Replace(orderDetail["create_time"].(string), "-", ".", -1)
  138. orderDetail["create_time"] = create_time
  139. }
  140. orderMoney := orderDetail["order_money"]
  141. if orderMoney != nil {
  142. orderDetail["order_money"] = float64(orderMoney.(int64)) / 100
  143. }
  144. //加密
  145. orderStatus := util.IntAll((orderDetail)["order_status"])
  146. orderDetail["order_status"] = orderStatus
  147. if orderStatus == 1 {
  148. orderDetail["transaction_id"] = func() string {
  149. table := ""
  150. payway := util.ObjToString(orderDetail["pay_way"])
  151. if strings.Contains(payway, "wx") {
  152. payway = "微信"
  153. table = "weixin_pay"
  154. } else if strings.Contains(payway, "ali") {
  155. payway = "支付宝"
  156. table = "ali_pay"
  157. } else {
  158. return ""
  159. }
  160. orderDetail["pay_way"] = payway
  161. wxPayMap := map[string]interface{}{}
  162. wxPayMap["out_trade_no"] = orderDetail["out_trade_no"]
  163. wxpay := public.Mysql.FindOne(table, wxPayMap, "", "")
  164. if wxpay == nil {
  165. return ""
  166. }
  167. return util.ObjToString((*wxpay)["transaction_id"])
  168. }()
  169. }
  170. w.T["o"] = orderDetail
  171. w.Render("/weixin/dataExport/dataExport_toOrderDetail.html", &w.T)
  172. return nil
  173. }
  174. func (w *WsDataExport) GetPreview() error {
  175. userId := util.ObjToString(w.GetSession("userId"))
  176. if userId == "" {
  177. return errors.New("未登录")
  178. }
  179. _res := make(map[string]interface{})
  180. //数据预览每天限制50次
  181. incurKey := fmt.Sprintf("PreviewData_%s_%d", w.GetSession("userId"), time.Now().Day())
  182. times := util.IntAll(redis.Get("other", incurKey))
  183. if times >= 50 {
  184. _res["msg"] = "超出预览次数"
  185. w.ServeJson(map[string]interface{}{
  186. "res": _res,
  187. })
  188. return nil
  189. }
  190. if times == 0 {
  191. redis.Put("other", incurKey, 1, 24*60*60)
  192. } else {
  193. redis.Incr("other", incurKey)
  194. }
  195. _id := encrypt.SE.Decode4Hex(w.GetString("_id"))
  196. dataType := w.GetString("dataType")
  197. //从500条数据中筛选字段最全五条
  198. scd := dataexport.GetSqlObjFromId(public.MQFW, _id)
  199. kws := scd.Keyword
  200. res, err := dataexport.GetDataExportSearchResult(public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.DbName, public.DbConf.Elasticsearch.Main.Address, scd, dataType, -1)
  201. if res == nil || err != nil {
  202. return w.Render("/pc/dataExport_noDataErr.html", &w.T)
  203. }
  204. msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.DbName, public.DbConf.Elasticsearch.Main.Address, _id)
  205. //格式化字段
  206. res_screen := dataexport.ScreenData(res, dataType, 20, kws)
  207. list := dataexport.FormatExportData(public.Mgo_Ent, &res_screen, config.Sysconfig["webdomain"].(string), dataType, true)
  208. //if msgCount > 20000 {
  209. // msgCount = 20000
  210. //}
  211. _res["data"] = subUrl(list, dataType)
  212. _res["dataType"] = dataType
  213. _res["total"] = msgCount
  214. w.ServeJson(map[string]interface{}{
  215. "res": _res,
  216. })
  217. return nil
  218. }
  219. // 预览
  220. func (w *WsDataExport) ToPreview(_id string) error {
  221. defer util.Catch()
  222. getsession := w.Session().GetMultiple()
  223. openid, _ := getsession["s_m_openid"].(string)
  224. userid, _ := getsession["userId"].(string)
  225. if userid == "" {
  226. if w.GetString("state") == "wx" {
  227. //微信跳回来的
  228. code := w.GetString("code")
  229. if code != "" {
  230. openid = jyutil.Getopenid(code)
  231. if openid != "" {
  232. FindUserAndCreateSess(openid, w.Session(), "wx", false, true)
  233. }
  234. }
  235. } else {
  236. if public.CheckWxBrowser(w.Request) {
  237. //所有参数都不再使用,跳到微信验证用户
  238. return w.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(w.Site()+w.Url()), "wx"), 302)
  239. }
  240. }
  241. userid = util.ObjToString(w.GetSession("userId"))
  242. }
  243. w.T["id"] = _id
  244. w.T["dataType"] = w.GetString("dataType")
  245. w.T["ttf"] = public.GetFontVersion() + "_" + public.PC
  246. return w.Render("/weixin/dataExport/dataExport_previewData.html")
  247. }
  248. // 创建订单页面
  249. func (w *WsDataExport) SubmitOrder() error {
  250. defer util.Catch()
  251. id := encrypt.SE.Decode4Hex(w.GetString("id"))
  252. openid := util.ObjToString(w.GetSession("s_m_openid"))
  253. userId := util.ObjToString(w.GetSession("userId"))
  254. if userId == "" {
  255. if w.GetString("state") == "wx" {
  256. //微信跳回来的
  257. code := w.GetString("code")
  258. if code != "" {
  259. openid = jyutil.Getopenid(code)
  260. if openid != "" {
  261. FindUserAndCreateSess(openid, w.Session(), "wx", false, true)
  262. }
  263. }
  264. } else {
  265. if public.CheckWxBrowser(w.Request) {
  266. //所有参数都不再使用,跳到微信验证用户
  267. return w.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(w.Site()+w.Url()), "wx"), 302)
  268. }
  269. }
  270. userId = util.ObjToString(w.GetSession("userId"))
  271. if userId == "" {
  272. return errors.New("未登录")
  273. }
  274. }
  275. msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.DbName, public.DbConf.Elasticsearch.Main.Address, id)
  276. if msgCount > public.ExConf.MsgMaxCount || msgCount == -1 {
  277. msgCount = public.ExConf.MsgMaxCount
  278. }
  279. if msgCount < 1 {
  280. w.Render("/weixin/dataExport/404.html", &w.T)
  281. return nil
  282. }
  283. //订单数据存入session中
  284. w.SetSession("dataexport_waitcreateorder", map[string]interface{}{
  285. "id": id, //用户的筛选条件mongodb中的id string
  286. "data_count": msgCount, //匹配到的数据总数 int
  287. })
  288. //邮箱验证
  289. // w.DelSession("DataExportVerifyEmail_val")
  290. // w.DelSession("DataExportVerifyPhone_val")
  291. resEmail, _ := w.GetSession("DataExportVerifyEmail_val").(string)
  292. resPhone, _ := w.GetSession("DataExportVerifyPhone_val").(string)
  293. if resEmail != "" {
  294. lastSendDEVerify := util.Int64All(w.GetSession("CreatEVerifyTime"))
  295. timeSpaceing := lastSendDEVerify - time.Now().Unix() + 60*5
  296. w.T["email"] = resEmail
  297. w.T["timeSpaceing"] = timeSpaceing
  298. }
  299. if resPhone != "" {
  300. w.T["phone"] = resPhone
  301. }
  302. if resEmail == "" || resPhone == "" {
  303. lastEmail, lastPhone := "", ""
  304. if lastPhone, lastEmail = dataexport.GetLastExportPhoneAndMail(public.Mysql, userId, util.ObjToString(w.GetSession("entUserId"))); lastPhone == "" || lastEmail == "" {
  305. userData := jyutil.Compatible.Select(userId, `{"s_myemail":1,"s_phone":1,"s_m_phone":1}`)
  306. if userData != nil && len(*userData) > 0 {
  307. if lastEmail == "" {
  308. lastEmail, _ = (*userData)["s_myemail"].(string)
  309. }
  310. if lastPhone == "" {
  311. lastPhone, _ = util.If((*userData)["s_phone"] != nil, (*userData)["s_phone"], (*userData)["s_m_phone"]).(string)
  312. }
  313. }
  314. }
  315. if resEmail == "" && lastEmail != "" {
  316. w.T["email"] = lastEmail
  317. w.SetSession("EMVerifySucess", true)
  318. w.SetSession("DataExportVerifyEmail_val", lastEmail)
  319. }
  320. if resPhone == "" {
  321. setPhone := lastPhone
  322. if isPhone(openid) { //剑鱼助手手机号登录
  323. setPhone = openid
  324. }
  325. if setPhone != "" {
  326. w.SetSession("DataExportVerifyPhone_val", lastPhone)
  327. }
  328. w.T["phone"] = lastPhone
  329. }
  330. }
  331. w.T["_id"] = w.GetString("id")
  332. w.T["msgCount"] = msgCount //信息总量
  333. incurKey := fmt.Sprintf("PreviewData_%s_%d", w.GetSession("userId"), time.Now().Day()) //每日限制预览次数
  334. w.T["PreviewData"] = util.IntAll(redis.Get("other", incurKey))
  335. //字段包
  336. spec := w.GetString("dataspec")
  337. if spec != "" {
  338. w.T["dataspec"] = spec
  339. }
  340. w.Render("/weixin/dataExport/dataExport_payOrder.html", &w.T)
  341. return nil
  342. }
  343. // 微信数据导出
  344. func (wd *WsDataExport) SearchExport() error {
  345. openid := util.ObjToString(wd.GetSession("s_m_openid"))
  346. userId := util.ObjToString(wd.GetSession("userId"))
  347. mgoUserId := util.ObjToString(wd.GetSession("mgoUserId"))
  348. if userId == "" {
  349. return errors.New("未登录")
  350. }
  351. searchGroup, _ := wd.GetInteger("searchGroup")
  352. searchMode, _ := wd.GetInteger("searchMode")
  353. wordsMode, _ := wd.GetInteger("wordsMode")
  354. //接收超级搜索页面参数
  355. reqData := public.BidSearchExport{
  356. Keywords: wd.GetString("searchvalue"), //搜索词
  357. Publishtime: wd.GetString("publishtime"), //发布时间
  358. Area: wd.GetString("scope"), //地区
  359. Buyer: wd.GetString("buyer"), //采购单位
  360. Agency: wd.GetString("agency"), //招标代理机构
  361. Winner: wd.GetString("winner"), //中标企业
  362. Subtype: wd.GetString("subtype"), //信息类型
  363. Minprice: wd.GetString("minprice"), //最低价格
  364. Maxprice: wd.GetString("maxprice"), //最高价格
  365. Industry: strings.TrimSpace(wd.GetString("industry")), //选中的行业
  366. SelectType: wd.GetString("selectType"), //标题 or 全文
  367. Buyerclass: wd.GetString("buyerclass"), //采购单位行业
  368. Hasbuyertel: wd.GetString("buyertel"), //是否有采购电话
  369. Haswinnertel: wd.GetString("winnertel"), //是否有中标电话
  370. SelectIds: strings.TrimSpace(wd.GetString("selectIds")), //选择信息id
  371. Notkey: wd.GetString("notkey"), //排除词
  372. City: wd.GetString("city"), //城市
  373. FileExists: wd.GetString("fileExists"), //有无附件
  374. SearchGroup: searchGroup, //搜索分组:默认0:全部;1:招标采购公告;2:超前项目
  375. SearchMode: searchMode, //搜索模式:0:精准搜索;1:模糊搜索
  376. WordsMode: wordsMode, //搜索关键词模式;默认0:包含所有,1:包含任意
  377. AdditionalWords: wd.GetString("additionalWords"), //关键词:附加关键词(副:五组,每组最多15个字符)
  378. District: wd.GetString("district"),
  379. }
  380. if reqData.Subtype == "" { //移动 数据导出分组
  381. switch reqData.SearchGroup {
  382. case 3:
  383. reqData.Subtype = "招标公告"
  384. case 4:
  385. reqData.Subtype = "招标预告"
  386. case 5:
  387. reqData.Subtype = "招标结果"
  388. }
  389. }
  390. saveData := reqData.PassBidSearchExport(config.Sysconfig)
  391. saveData["selectType"] = strings.Join(jy.GetVipState(wd.Session(), *config.Middleground, userId).GetQueryItems(wd.GetString("selectType"), util.Int64All(config.Sysconfig["bidSearchOldUserLimit"])), ",")
  392. saveData["s_openid"] = openid
  393. saveData["s_userid"] = userId
  394. saveData["mgoUserId"] = mgoUserId
  395. saveData["comeinfrom"] = "supersearchPage"
  396. region := util.If(reqData.Area == "全国", "", reqData.Area).(string)
  397. if region != "" && reqData.City != "" {
  398. region += "," + reqData.City
  399. } else if region == "" {
  400. region = reqData.City
  401. }
  402. if reqData.District != "" {
  403. districtArr := []string{}
  404. for _, v := range strings.Split(reqData.District, ",") {
  405. if len(strings.Split(v, "_")) > 1 {
  406. district := strings.Split(v, "_")[1]
  407. districtArr = append(districtArr, district)
  408. }
  409. }
  410. if region != "" {
  411. region += "," + strings.Join(districtArr, ",")
  412. } else {
  413. region = strings.Join(districtArr, ",")
  414. }
  415. }
  416. region_arr := strings.Split(region, ",")
  417. if region == "" {
  418. region_arr = []string{}
  419. }
  420. saveData["region"] = region_arr
  421. //是否开启 正文 标题同时搜索只搜正文的开关
  422. saveData["searchTypeSwitch"], _ = config.Sysconfig["searchTypeSwitch"].(bool)
  423. //存入数据库
  424. _id := mongodb.Save(dataexport.ExportTable, saveData)
  425. wd.ServeJson(bson.M{"_id": encrypt.SE.Encode2Hex(_id)})
  426. return nil
  427. }