dataExport.go 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. package front
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "jy/src/jfw/config"
  7. "jy/src/jfw/jyutil"
  8. "log"
  9. "regexp"
  10. "strconv"
  11. "strings"
  12. "sync"
  13. "time"
  14. . "app.yhyue.com/moapp/jybase/date"
  15. "app.yhyue.com/moapp/jybase/encrypt"
  16. "app.yhyue.com/moapp/jypkg/common/src/qfw/util/dataexport"
  17. "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
  18. "app.yhyue.com/moapp/jypkg/public"
  19. util "app.yhyue.com/moapp/jybase/common"
  20. "app.yhyue.com/moapp/jybase/redis"
  21. "app.yhyue.com/moapp/jybase/go-xweb/xweb"
  22. )
  23. type DataExport struct {
  24. *xweb.Action
  25. toSieve xweb.Mapper `xweb:"/front/dataExport/toSieve"` //数据导出-条件筛选
  26. sieveData xweb.Mapper `xweb:"/front/dataExport/sieveData"` //筛选数据
  27. toOrderDetail xweb.Mapper `xweb:"/front/dataExport/toOrderDetail/(.*)"` //订单详情
  28. getOrderCode xweb.Mapper `xweb:"/front/dataExport/getOrderCode/(\\w+)"` //申请发票获取订单编号
  29. superSearchExport xweb.Mapper `xweb:"/front/dataExport/superSearchExport"` //数据导出-超级搜索
  30. toCreateOrderPage xweb.Mapper `xweb:"/front/dataExport/toCreateOrderPage/(.*)"` //数据导出-订单页面
  31. previewData xweb.Mapper `xweb:"/front/(.*)/previewData/(.*)"` //数据导出-数据预览
  32. sendMailVerify xweb.Mapper `xweb:"/front/dataExport/sendMailVerify"` //发送邮箱验证码
  33. checkMailVerify xweb.Mapper `xweb:"/front/dataExport/checkMailVerify"` //验证邮箱验证码
  34. paysuccess xweb.Mapper `xweb:"/front/dataExport/paysuccess"` //支付成功页面
  35. checkPhoneVerify xweb.Mapper `xweb:"/front/dataExport/checkPhoneVerify"` //验证手机号
  36. fontSet xweb.Mapper `xweb:"/front/dataExport/fontSet/(.*)"`
  37. setDontPromptAgain xweb.Mapper `xweb:"/front/dataExport/setDontPromptAgain"` //数据导出-超出2w条,不再提示
  38. getDontPromptAgain xweb.Mapper `xweb:"/front/dataExport/getDontPromptAgain"` //数据导出-超出2w条,不再提示
  39. cancelOrder xweb.Mapper `xweb:"/front/dataExport/cancelOrder"` //取消订单
  40. vipOrderDetail xweb.Mapper `xweb:"/front/vipOrder/vipOrderDetail"` //vip订单详情
  41. entOrderDetail xweb.Mapper `xweb:"/front/entniche/entnicheOrderDetail"` //商机管理订单详情
  42. invoice xweb.Mapper `xweb:"/front/order/invoice/(\\w+)"` //电子发票-开发票
  43. check_invoice xweb.Mapper `xweb:"/front/order/check_invoice/(\\w+)"` //电子发票-开发票-流程
  44. invoicetimeOut xweb.Mapper `xweb:"/front/order/invoicetimeOut"` //申请超时
  45. valuationList xweb.Mapper `xweb:"/front/order/valuationList/(\\w+)"` //计费清单
  46. memberDetail xweb.Mapper `xweb:"/front/member/memberDetail"` //大会员订单详情
  47. aiForecastPackDetail xweb.Mapper `xweb:"/front/aiForecastPack/aiForecastPackDetail"` //AI中标预测包订单详情
  48. subAccountDetail xweb.Mapper `xweb:"/front/subAccount/subAccountDetail"` //子账号订单详情
  49. bidfileDetail xweb.Mapper `xweb:"/front/bidfile/bidfileDetail"` //招标文件解读详情
  50. integralDetail xweb.Mapper `xweb:"/front/integral/integralDetail"` //剑鱼币订单详情
  51. getPcEntAuth xweb.Mapper `xweb:"/front/entExportAuth/getAuth"` //获取企业权限
  52. //gettest xweb.Mapper `xweb:"/front/order/gettest"` //模拟
  53. //entDataExport xweb.Mapper `xweb:"/front/entDataExport/(.*)"` //企业数据导出
  54. //isEntExportSuccess xweb.Mapper `xweb:"/front/entExportAuth/isEntExportSuccess"` //企业导出是否成功
  55. }
  56. var order_pageSize = 10
  57. type Filters struct {
  58. FilterId string
  59. }
  60. func init() {
  61. xweb.AddAction(&DataExport{})
  62. }
  63. var (
  64. layout_date = "2006.01.02"
  65. orderStatus_unPaid = "0" //订单状态-待支付
  66. orderStatus_paid = "1" //订单状态-已完成
  67. orderStatus_deleted = "-1" //订单状态-已删除
  68. orderStatus_cancel = "-2" //订单状态-已取消
  69. tableName_order = "dataexport_order" //订单表
  70. SEX = encrypt.SimpleEncrypt{Key: "topJYBX2019"}
  71. exportLock = sync.Mutex{}
  72. exportLockMap = map[int]sync.Mutex{}
  73. )
  74. func (d *DataExport) ToSieve() error {
  75. industrylist, sortArray = jy.Getindustrys(util.ObjToString(config.Sysconfig["industry"]), public.MQFW)
  76. d.T["industrylist"] = industrylist
  77. d.T["sortArray"] = sortArray
  78. d.T["logid"] = config.Seoconfig["dataexport"].(string)
  79. d.T["ttf"] = public.GetFontVersion() + "_" + public.PC
  80. d.Render("/pc/dataExport_sieve.html", &d.T)
  81. return nil
  82. }
  83. func (d *DataExport) SieveData() {
  84. dataType := d.GetString("dataType")
  85. publishtime := d.GetString("publishtime")
  86. area := d.GetString("area")
  87. city := d.GetString("city")
  88. region := d.GetString("region")
  89. industry := d.GetString("industry")
  90. keyword := d.GetString("keyword")
  91. minPrice := d.GetString("minprice")
  92. maxPrice := d.GetString("maxprice")
  93. subType := d.GetString("subtype")
  94. buyer := d.GetString("buyer")
  95. buyerclass := d.GetString("buyerclass")
  96. winner := d.GetString("winner")
  97. selectType := d.GetString("selectType")
  98. var areaArr []string
  99. var cityArr []string
  100. var regionArr []string
  101. var industryArr []string
  102. var subTypeArr []string
  103. var buyerArr []string
  104. var buyerclassArr []string
  105. var winnerArr []string
  106. var keywordList []dataexport.KeyWord
  107. log.Println("price", minPrice, maxPrice)
  108. if publishtime != "" {
  109. log.Println("publishtime", publishtime)
  110. }
  111. if area != "" {
  112. areaArr = strings.Split(area, ",")
  113. log.Println("areaArr", areaArr)
  114. }
  115. if city != "" {
  116. cityArr = strings.Split(city, ",")
  117. log.Println("cityArr", cityArr)
  118. }
  119. if region != "" {
  120. regionArr = strings.Split(region, ",")
  121. log.Println("regionArr", regionArr)
  122. }
  123. if industry != "" {
  124. industryArr = strings.Split(industry, ",")
  125. log.Println("industryArr", industryArr)
  126. }
  127. if subType != "" {
  128. subTypeArr = strings.Split(subType, ",")
  129. log.Println("subTypeArr", subTypeArr)
  130. }
  131. if keyword != "" {
  132. err := json.Unmarshal([]byte(keyword), &keywordList)
  133. if err != nil {
  134. log.Println("keyword param 反序列化异常,查看前后台字段是否对应")
  135. } else {
  136. log.Println("keywordList", len(keywordList), keywordList)
  137. }
  138. }
  139. log.Println("selectType", selectType)
  140. if buyer != "" {
  141. buyerArr = strings.Split(buyer, ",")
  142. log.Println("buyerArr", buyerArr)
  143. }
  144. if buyerclass != "" {
  145. buyerclassArr = strings.Split(buyerclass, ",")
  146. log.Println("buyerclassArr", buyerclassArr)
  147. }
  148. if winner != "" {
  149. winnerArr = strings.Split(winner, ",")
  150. log.Println("winnerArr", winnerArr)
  151. }
  152. var isTitle int
  153. if selectType != "" {
  154. if strings.Count(selectType, "title") > 1 {
  155. isTitle = 3 //包含标题及正文
  156. } else if strings.Contains(selectType, "detail") {
  157. isTitle = 2 //只包含正文
  158. } else if strings.Contains(selectType, "title") {
  159. isTitle = 1 //只包含标题
  160. }
  161. //去重 如果选取了标题及正文 引起的有2个title问题
  162. if strings.Count(selectType, "title") > 1 {
  163. var detail []string
  164. for _, v := range strings.Split(selectType, ",") {
  165. if v == "title" {
  166. continue
  167. }
  168. detail = append(detail, v)
  169. }
  170. //维持原逻辑 正文表示标题及正文
  171. selectType = strings.Replace(strings.Join(detail, ","), "detail", "title,detail", -1)
  172. }
  173. }
  174. exportLimit := util.StructToMapMore(config.ExportConfig["exportLimit"])
  175. wordsLimit := util.IntAllDef(exportLimit["wordsLimit"], 100)
  176. countLimit := util.IntAllDef(exportLimit["countLimit"], 300)
  177. buyerLimit := util.IntAllDef(exportLimit["buyerLimit"], 100)
  178. winnerLimit := util.IntAllDef(exportLimit["winnerLimit"], 100)
  179. var count int
  180. for k, kw := range keywordList {
  181. if kw.Keyword != "" {
  182. count++
  183. }
  184. count += len(kw.Appended)
  185. count += len(kw.Exclude)
  186. if len([]rune(kw.Keyword)) > wordsLimit {
  187. keywordList[k].Keyword = util.SubString(kw.Keyword, 0, wordsLimit)
  188. }
  189. for k1, ad := range kw.Appended {
  190. if len([]rune(ad)) > wordsLimit {
  191. keywordList[k].Appended[k1] = util.SubString(ad, 0, wordsLimit)
  192. }
  193. }
  194. for k1, el := range kw.Exclude {
  195. if len([]rune(el)) > wordsLimit {
  196. keywordList[k].Exclude[k1] = util.SubString(el, 0, wordsLimit)
  197. }
  198. }
  199. }
  200. if count > countLimit {
  201. d.ServeJson(map[string]interface{}{
  202. "error_code": -1,
  203. "error_msg": fmt.Sprintf("关键词信息超过上限%d", countLimit),
  204. })
  205. return
  206. }
  207. if len(buyerArr) > buyerLimit {
  208. d.ServeJson(map[string]interface{}{
  209. "error_code": -1,
  210. "error_msg": fmt.Sprintf("采购单位超过上限%d", buyerLimit),
  211. })
  212. return
  213. }
  214. if len(winnerArr) > winnerLimit {
  215. d.ServeJson(map[string]interface{}{
  216. "error_code": -1,
  217. "error_msg": fmt.Sprintf("中标单位超过上限%d", winnerLimit),
  218. })
  219. return
  220. }
  221. sieveCondition := map[string]interface{}{
  222. "publishtime": publishtime,
  223. "area": areaArr,
  224. "city": cityArr,
  225. "region": regionArr,
  226. "industry": industryArr,
  227. "keywords": keywordList,
  228. "selectType": selectType,
  229. "minprice": minPrice,
  230. "maxprice": maxPrice,
  231. "subtype": subType,
  232. "buyer": buyerArr,
  233. "buyerclass": buyerclassArr,
  234. "isTitle": isTitle,
  235. "winner": winnerArr,
  236. "comeintime": time.Now().Unix(),
  237. "comeinfrom": "exportPage",
  238. }
  239. sessVal := d.Session().GetMultiple()
  240. if sessVal["s_m_openid"] != nil {
  241. sieveCondition["s_openid"] = util.ObjToString(sessVal["s_m_openid"])
  242. }
  243. if sessVal["userId"] != nil {
  244. sieveCondition["s_userid"] = util.ObjToString(sessVal["userId"])
  245. }
  246. _id := mongodb.Save(dataexport.ExportTable, sieveCondition)
  247. _res := map[string]interface{}{
  248. "error_code": 0,
  249. "error_msg": "",
  250. }
  251. if _id != "" {
  252. msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.DbName, public.DbConf.Elasticsearch.Main.Address, _id)
  253. //从500条数据中筛选字段最全五条
  254. scd := dataexport.GetSqlObjFromId(public.MQFW, _id)
  255. kws := scd.Keyword
  256. res, err := dataexport.GetDataExportSearchResult(public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.DbName, public.DbConf.Elasticsearch.Main.Address, scd, dataType, -1)
  257. if res == nil || err != nil {
  258. _res["error_msg"] = "无数据"
  259. d.ServeJson(_res)
  260. return
  261. }
  262. //格式化字段
  263. res_screen := dataexport.ScreenData(res, dataType, 20, kws)
  264. var EntArr = []string{}
  265. if dataType == "2" {
  266. for _, v := range res_screen {
  267. //高级字段查询且winner不为空
  268. if v["s_winner"] != nil && v["s_winner"] != "" {
  269. EntArr = append(EntArr, v["s_winner"].(string))
  270. }
  271. }
  272. }
  273. list := dataexport.FormatExportData(public.Mgo_Ent, &res_screen, config.Sysconfig["webdomain"].(string), dataType, true)
  274. /*if msgCount > 20000 {
  275. msgCount = 20000
  276. }*/
  277. _res["data"] = map[string]interface{}{
  278. "list": subUrl(list, dataType),
  279. "_id": encrypt.SE.Encode2Hex(_id),
  280. "total": msgCount,
  281. }
  282. d.ServeJson(_res)
  283. //_res["dataType"] = dataType
  284. //d.T["success"] = true
  285. //d.T["redirectUrl"] = "/front/dataExport/toCreateOrderPage/" + util.se.Encode2Hex(_id)
  286. } else {
  287. _res["error_code"] = -1
  288. _res["error_msg"] = "保存筛选条件失败"
  289. d.ServeJson(_res)
  290. }
  291. }
  292. /*
  293. *
  294. 根据 id+openid 取消订单
  295. */
  296. func (d *DataExport) CancelOrder() error {
  297. if userId := d.GetSession("userId"); userId != nil {
  298. // if openid := d.GetSession("s_m_openid"); openid != nil {
  299. queryMap := map[string]interface{}{
  300. "id": d.GetString("id"),
  301. "user_id": userId.(string),
  302. }
  303. boo := public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"order_status": -2})
  304. //取消订单
  305. d.ServeJson(map[string]interface{}{"success": boo})
  306. }
  307. return nil
  308. }
  309. /*
  310. *
  311. 根据 订单编号+userId 查询
  312. */
  313. func (d *DataExport) ToOrderDetail(orderCode string) error {
  314. myUserId := ""
  315. if userId := d.GetSession("userId"); userId != nil {
  316. // if openid := d.GetSession("s_m_openid"); openid != nil {
  317. myUserId = userId.(string)
  318. } else {
  319. return nil
  320. }
  321. orderDetail := map[string]interface{}{}
  322. filter := dataexport.SieveCondition{}
  323. queryMap := map[string]interface{}{
  324. "order_code": orderCode,
  325. "user_id": myUserId,
  326. }
  327. if orderCode != "" {
  328. orderDetail = *public.Mysql.FindOne(tableName_order, queryMap, "", "")
  329. //最后一次开票查询
  330. orderDetail["source"] = LastInvoiceSource(orderCode)
  331. }
  332. // log.Println("ToOrderDetail", orderCode, orderDetail)
  333. if orderDetail["pay_money"] != nil {
  334. orderDetail["pay_money"] = float64(orderDetail["pay_money"].(int64))
  335. }
  336. if orderDetail["order_money"] != nil {
  337. orderDetail["order_money"] = float64(orderDetail["order_money"].(int64))
  338. }
  339. if orderDetail["discount_price"] != nil {
  340. orderDetail["discount_price"] = float64(orderDetail["discount_price"].(int64))
  341. }
  342. //卡卷id加密
  343. if orderDetail["d_relation_id"] != "" {
  344. orderDetail["userLotteryId"] = encrypt.SE.Encode2Hex(util.ObjToString(orderDetail["d_relation_id"]))
  345. }
  346. delete(orderDetail, "d_relation_id")
  347. if orderDetail["filter"] != nil {
  348. err := json.Unmarshal([]byte(orderDetail["filter"].(string)), &filter)
  349. if err == nil {
  350. publishtime := filter.PublishTime
  351. if publishtime != "" {
  352. timeArr := strings.Split(publishtime, "_")
  353. if len(timeArr) == 2 {
  354. start, err := strconv.ParseInt(timeArr[0], 10, 64)
  355. end, erro := strconv.ParseInt(timeArr[1], 10, 64)
  356. if err == nil && erro == nil {
  357. filter.PublishTime = FormatDateByInt64(&start, layout_date) + "-" + FormatDateByInt64(&end, layout_date)
  358. } else if err == nil && erro != nil {
  359. filter.PublishTime = FormatDateByInt64(&start, layout_date) + "-"
  360. } else if err != nil && erro == nil {
  361. filter.PublishTime = "-" + FormatDateByInt64(&end, layout_date)
  362. }
  363. }
  364. }
  365. filter.MinPrice = public.GetPriceDes_SieveCondition(filter.MinPrice, filter.MaxPrice)
  366. orderDetail["filter"] = filter
  367. } else {
  368. log.Println("筛选条件-关键词-结构体反序列化-错误", err)
  369. }
  370. }
  371. if orderDetail["applybill_type"] != nil && orderDetail["applybill_type"].(int64) == 0 {
  372. orderDetail["applybill_type"] = "个人"
  373. } else if orderDetail["applybill_type"] != nil && orderDetail["applybill_type"].(int64) == 1 {
  374. orderDetail["applybill_type"] = "单位"
  375. } else {
  376. orderDetail["applybill_type"] = "-"
  377. }
  378. orderStatus := util.IntAll((orderDetail)["order_status"])
  379. if orderStatus == 1 {
  380. orderDetail["transaction_id"] = func() string {
  381. table := ""
  382. payway := util.ObjToString(orderDetail["pay_way"])
  383. if strings.Contains(payway, "wx") {
  384. payway = "微信"
  385. table = "weixin_pay"
  386. } else if strings.Contains(payway, "ali") {
  387. payway = "支付宝"
  388. table = "ali_pay"
  389. } else {
  390. return ""
  391. }
  392. orderDetail["pay_way"] = payway
  393. wxPayMap := map[string]interface{}{}
  394. wxPayMap["out_trade_no"] = orderDetail["out_trade_no"]
  395. payDetail := public.Mysql.FindOne(table, wxPayMap, "", "")
  396. if payDetail == nil || len(*payDetail) == 0 {
  397. return ""
  398. }
  399. return util.ObjToString((*payDetail)["transaction_id"])
  400. }()
  401. }
  402. d.T["o"] = orderDetail
  403. d.T["logid"] = config.Seoconfig["dataexport"].(string)
  404. return d.Render("/pc/orderDetail.html", &d.T)
  405. }
  406. // 查询订单最后开票状态
  407. func LastInvoiceSource(orderCode string) int64 {
  408. orderData := public.Mysql.SelectBySql("select source from invoice where order_code =? ORDER BY create_time desc ", orderCode)
  409. if orderData != nil && len(*orderData) > 0 {
  410. return util.Int64All((*orderData)[0]["source"])
  411. }
  412. return 0
  413. }
  414. // ------------------------------申请发票跳转页面-----------------------------
  415. func (d *DataExport) GetOrderCode(order_code string) error {
  416. var status, order_status int64
  417. queryMap := map[string]interface{}{
  418. "order_code": order_code,
  419. }
  420. oDate := public.Mysql.FindOne(tableName_order, queryMap, "", "")
  421. status = (*oDate)["applybill_status"].(int64)
  422. order_status = (*oDate)["order_status"].(int64)
  423. d.T["order_code"] = order_code
  424. d.T["logid"] = config.Seoconfig["dataexport"].(string)
  425. //是否申请发票 支付状态
  426. if status == 1 || order_status == 0 {
  427. d.Redirect("/front/dataExport/toOrderDetail/" + order_code)
  428. } else {
  429. d.Render("/pc/dataExport_invoice.html", &d.T)
  430. }
  431. return nil
  432. }
  433. // ---------------------------生成订单预览----------------------------------
  434. func (d *DataExport) SuperSearchExport() error {
  435. sessVal := d.Session().GetMultiple()
  436. openid := util.ObjToString(sessVal["s_m_openid"])
  437. userId := util.ObjToString(sessVal["userId"])
  438. searchGroup, _ := d.GetInteger("searchGroup")
  439. searchMode, _ := d.GetInteger("searchMode")
  440. wordsMode, _ := d.GetInteger("wordsMode")
  441. if userId == "" {
  442. return errors.New("未登录")
  443. }
  444. //接收超级搜索页面参数
  445. reqData := public.BidSearchExport{
  446. Keywords: d.GetString("keywords"), //搜索词
  447. Publishtime: d.GetString("publishtime"), //发布时间
  448. Area: d.GetString("area"), //地区
  449. Subtype: d.GetString("subtype"), //信息类型
  450. Minprice: d.GetString("minprice"), //最低价格
  451. Maxprice: d.GetString("maxprice"), //最高价格
  452. Industry: strings.TrimSpace(d.GetString("industry")), //选中的行业
  453. SelectType: d.GetString("selectType"), //标题 or 全文
  454. Buyerclass: d.GetString("buyerclass"), //采购单位行业
  455. Hasbuyertel: d.GetString("buyertel"), //是否有采购电话
  456. Haswinnertel: d.GetString("winnertel"), //是否有中标电话
  457. SelectIds: strings.TrimSpace(d.GetString("selectIds")), //选择信息id
  458. Notkey: d.GetString("notkey"), //排除词
  459. FileExists: d.GetString("fileExists"), //是否有附件
  460. City: d.GetString("city"), //城市
  461. BidField: d.GetString("bid_field"), // 领域数据类型 0101- 医疗行业
  462. SearchGroup: searchGroup, //搜索分组:默认0:全部;1:招标采购公告;2:超前项目
  463. SearchMode: searchMode, //搜索模式:0:精准搜索;1:模糊搜索
  464. WordsMode: wordsMode, //搜索关键词模式;默认0:包含所有,1:包含任意
  465. AdditionalWords: d.GetString("additionalWords"), //关键词:附加关键词(副:五组,每组最多15个字符)
  466. }
  467. selectType := strings.Join(jy.GetVipState(d.Session(), *config.Middleground, userId).GetQueryItems(d.GetString("selectType"), util.Int64All(config.Sysconfig["bidSearchOldUserLimit"])), ",")
  468. //数据回显
  469. d.SetSession("Echo_timeslot", d.GetString("timeslot"))
  470. d.SetSession("Echo_keywords", reqData.Keywords)
  471. d.SetSession("Echo_publishtime", reqData.Publishtime)
  472. d.SetSession("Echo_area", reqData.Area)
  473. d.SetSession("Echo_subtype", reqData.Subtype)
  474. d.SetSession("Echo_minprice", reqData.Minprice)
  475. d.SetSession("Echo_maxprice", reqData.Maxprice)
  476. d.SetSession("Echo_industry", reqData.Industry)
  477. d.SetSession("Echo_selectType", reqData.SelectType)
  478. d.SetSession("Echo_buyerclass", reqData.Buyerclass)
  479. d.SetSession("Echo_hasBuyertel", reqData.Hasbuyertel)
  480. d.SetSession("Echo_hasWinnertel", reqData.Haswinnertel)
  481. d.SetSession("Echo_notkey", reqData.Notkey)
  482. d.SetSession("Echo_fileExists", reqData.FileExists)
  483. d.SetSession("Echo_city", reqData.City)
  484. d.SetSession("Echo_bid_field", reqData.BidField) // 领域类型 0101-医疗行业
  485. d.SetSession("Echo_searchGroup", reqData.SearchGroup)
  486. d.SetSession("Echo_searchMode", reqData.SearchMode)
  487. d.SetSession("Echo_wordsMode", reqData.WordsMode)
  488. d.SetSession("Echo_additionalWords", reqData.AdditionalWords)
  489. saveData := reqData.PassBidSearchExport(config.Sysconfig)
  490. saveData["selectType"] = selectType
  491. saveData["s_openid"] = openid
  492. saveData["s_userid"] = userId
  493. saveData["comeinfrom"] = "supersearchPage"
  494. //是否开启 正文 标题同时搜索只搜正文的开关
  495. saveData["searchTypeSwitch"], _ = config.Sysconfig["searchTypeSwitch"].(bool)
  496. region := util.If(reqData.Area == "全国", "", reqData.Area).(string)
  497. if region != "" && reqData.City != "" {
  498. region += "," + reqData.City
  499. } else {
  500. region = reqData.City
  501. }
  502. saveData["region"] = util.If(region != "", strings.Split(region, ","), []string{}).([]string)
  503. //存入数据库
  504. _id := mongodb.Save(dataexport.ExportTable, saveData)
  505. log.Println(_id, "saveData:", saveData)
  506. return d.Redirect("/front/dataExport/toCreateOrderPage/" + encrypt.SE.Encode2Hex(_id))
  507. }
  508. func (d *DataExport) ToCreateOrderPage(_id string) error {
  509. id := encrypt.SE.Decode4Hex(_id)
  510. sessVal := d.Session().GetMultiple()
  511. openid := util.ObjToString(sessVal["s_m_openid"])
  512. userId := util.ObjToString(sessVal["userId"])
  513. if userId == "" {
  514. return errors.New("未登录")
  515. }
  516. // }
  517. // 企业数据导出结束
  518. //是否是从结构化数据推广页过来的
  519. if d.GetString("from") == "structed" {
  520. d.SetSession("Structed", true)
  521. } else {
  522. d.DelSession("Structed")
  523. }
  524. msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.DbName, public.DbConf.Elasticsearch.Main.Address, id)
  525. if msgCount > public.ExConf.MsgMaxCount || msgCount == -1 {
  526. msgCount = public.ExConf.MsgMaxCount
  527. }
  528. d.T["logid"] = config.Seoconfig["dataexport"].(string)
  529. if msgCount < 1 {
  530. d.Render("/pc/dataExport_noDataErr.html", &d.T)
  531. return nil
  532. }
  533. //订单数据存入session中
  534. d.SetSession("dataexport_waitcreateorder", map[string]interface{}{
  535. "id": id, //用户的筛选条件mongodb中的id string
  536. "data_count": msgCount, //匹配到的数据总数 int
  537. })
  538. resEmail := util.ObjToString(sessVal["DataExportVerifyEmail_val"])
  539. resPhone := util.ObjToString(sessVal["DataExportVerifyPhone_val"])
  540. if resEmail != "" {
  541. lastSendDEVerify := util.Int64All(sessVal["CreatEVerifyTime"])
  542. timeSpaceing := lastSendDEVerify - time.Now().Unix() + 60*5
  543. d.T["email"] = resEmail
  544. d.T["timeSpaceing"] = timeSpaceing
  545. }
  546. if resPhone != "" {
  547. d.T["phone"] = resPhone
  548. }
  549. if resEmail == "" || resPhone == "" {
  550. lastEmail, lastPhone := "", ""
  551. if lastPhone, lastEmail = dataexport.GetLastExportPhoneAndMail(public.Mysql, userId, util.ObjToString(sessVal["entUserId"])); lastPhone == "" || lastEmail == "" {
  552. userData := jyutil.Compatible.Select(userId, `{"s_myemail":1,"s_phone":1,"s_m_phone":1}`)
  553. if userData != nil && len(*userData) > 0 {
  554. if lastEmail == "" {
  555. lastEmail, _ = (*userData)["s_myemail"].(string)
  556. }
  557. if lastPhone == "" {
  558. lastPhone, _ = util.If((*userData)["s_phone"] != nil, (*userData)["s_phone"], (*userData)["s_m_phone"]).(string)
  559. }
  560. }
  561. }
  562. if resEmail == "" && lastEmail != "" {
  563. d.T["email"] = lastEmail
  564. d.SetSession("EMVerifySucess", true)
  565. d.SetSession("DataExportVerifyEmail_val", lastEmail)
  566. }
  567. if resPhone == "" {
  568. setPhone := lastPhone
  569. if isPhone(openid) { //剑鱼助手手机号登录
  570. setPhone = openid
  571. }
  572. if setPhone != "" {
  573. d.SetSession("DataExportVerifyPhone_val", lastPhone)
  574. }
  575. d.T["phone"] = lastPhone
  576. }
  577. }
  578. d.T["_id"] = _id
  579. d.T["msgCount"] = msgCount
  580. incurKey := fmt.Sprintf("PreviewData_%s_%d", util.ObjToString(sessVal["userId"]), time.Now().Day())
  581. d.T["PreviewData"] = util.IntAll(redis.Get("other", incurKey))
  582. d.Render("/pc/createOrderPage.html", &d.T)
  583. return nil
  584. }
  585. func (d *DataExport) PreviewData(source, _id string) error {
  586. if !strings.Contains(source, "app") {
  587. sessVal := d.Session().GetMultiple()
  588. userId := util.ObjToString(sessVal["userId"])
  589. // openid := util.ObjToString(d.GetSession("s_m_openid"))
  590. if userId == "" {
  591. return errors.New("未登录")
  592. }
  593. //数据预览每天限制50次
  594. incurKey := fmt.Sprintf("PreviewData_%s_%d", util.ObjToString(sessVal["userId"]), time.Now().Day())
  595. times := util.IntAll(redis.Get("other", incurKey))
  596. if times >= 50 {
  597. return errors.New("超出预览次数")
  598. }
  599. if times == 0 {
  600. redis.Put("other", incurKey, 1, 24*60*60)
  601. } else {
  602. redis.Incr("other", incurKey)
  603. }
  604. }
  605. _id = encrypt.SE.Decode4Hex(_id)
  606. dataType := d.GetString("dataType")
  607. //从500条数据中筛选字段最全五条
  608. scd := dataexport.GetSqlObjFromId(public.MQFW, _id)
  609. kws := scd.Keyword
  610. res, err := dataexport.GetDataExportSearchResult(public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.DbName, public.DbConf.Elasticsearch.Main.Address, scd, dataType, -1)
  611. if res == nil || err != nil {
  612. log.Println("PreviewData查询出错", res)
  613. return d.Render("/pc/dataExport_noDataErr.html", &d.T)
  614. }
  615. //格式化字段
  616. res_screen := dataexport.ScreenData(res, dataType, 20, kws)
  617. list := dataexport.FormatExportData(public.Mgo_Ent, &res_screen, config.Sysconfig["webdomain"].(string), dataType, true)
  618. d.T["data"] = subUrl(list, dataType)
  619. d.T["dataType"] = dataType
  620. d.T["ttf"] = public.GetFontVersion() + "_" + public.PC
  621. d.Render("/pc/previewData.html", &d.T)
  622. return nil
  623. }
  624. /*
  625. *
  626. 设置ttf版本号
  627. */
  628. func (d *DataExport) FontSet(version string) {
  629. if public.ExConf.Font.Enabled {
  630. if version == "" {
  631. version = public.ExConf.Font.ConvertVersionDefault
  632. }
  633. b := redis.Put(public.ExConf.Font.RedisPool, public.ExConf.Font.RedisKey, version, -1)
  634. if b {
  635. d.RenderString("Congratulations , the font (version " + version + ") set successfully !")
  636. } else {
  637. d.RenderString("Sorry , there is an error , please view the logs !")
  638. }
  639. } else {
  640. d.RenderString("Sorry , permission denied , please contact the administrator !")
  641. }
  642. }
  643. func subUrl(list *[]map[string]interface{}, dataType string) *[]map[string]interface{} {
  644. for _, v := range *list {
  645. //加密截取url
  646. href := util.ObjToString(v["href"])
  647. url := util.ObjToString(v["url"])
  648. if len(url) > 40 { //截取剑鱼标讯地址
  649. v["url"] = url[:40] + "*****" + url[len(url)-10:]
  650. }
  651. re := regexp.MustCompile(`\/\/([^\/]+)`)
  652. // 使用正则表达式查找匹配的结果
  653. match := re.FindStringSubmatch(href)
  654. if len(match) > 1 {
  655. data := match[1]
  656. ds := strings.Split(data, ".")
  657. if len(ds) > 2 {
  658. href = strings.Replace(href, ds[1], "****", 1)
  659. }
  660. }
  661. if len(href) > 40 { //截取原文地址
  662. v["href"] = href[:40] + "*****" + href[len(href)-10:]
  663. } else if len(href) > 0 {
  664. v["href"] = href[:len(href)*8/10] + "*****"
  665. }
  666. }
  667. var result []map[string]interface{}
  668. bytes, marshalErr := json.Marshal(list)
  669. if marshalErr != nil {
  670. log.Println("数据导出字体混淆errMarshal", marshalErr)
  671. return list
  672. }
  673. //字体混淆
  674. hxb := public.GetFontConvertStr(public.ExConf.Font.ConvertVersionDefault, string(bytes), "pc")
  675. unmarshalErr := json.Unmarshal([]byte(hxb), &result)
  676. if unmarshalErr != nil {
  677. log.Println("数据导出字体混淆unmarshalErr", unmarshalErr)
  678. return list
  679. }
  680. return &result
  681. }
  682. // 发送邮件
  683. func (d *DataExport) SendMailVerify() {
  684. email := d.GetString("email")
  685. if isEmail(email) {
  686. var email_used = true
  687. sessVal := d.Session().GetMultiple()
  688. if email != util.ObjToString(sessVal["DataExportVerifyEmail"]) {
  689. d.DelSession("CreatEVerifyTime")
  690. // openid := util.ObjToString(d.GetSession("s_m_openid"))
  691. userId := util.ObjToString(sessVal["userId"])
  692. emails := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
  693. "user_mail": email,
  694. "user_id": userId,
  695. }, "user_mail", "")
  696. if emails != nil && util.ObjToString((*emails)["user_mail"]) != "" {
  697. email_used = false
  698. d.T["success"] = true
  699. d.T["errCode"] = 4
  700. d.T["errMsg"] = "此邮箱已被验证"
  701. d.SetSession("DataExportVerifyEmail_val", email)
  702. d.SetSession("EMVerifySucess", true)
  703. }
  704. }
  705. if email_used {
  706. lastSendDEVerify := util.Int64All(sessVal["CreatEVerifyTime"])
  707. timeSpaceing := lastSendDEVerify - time.Now().Unix() + 60*5
  708. incurKey := fmt.Sprintf("SendEmail_%s_%d", util.ObjToString(sessVal["userId"]), time.Now().Day())
  709. //log.Println(incurKey)
  710. if lastSendDEVerify == 0 || timeSpaceing < 0 {
  711. //每日限制10次
  712. times := util.IntAll(redis.Get("other", incurKey))
  713. if times < 10 {
  714. if times == 0 {
  715. redis.Put("other", incurKey, 1, 24*60*60)
  716. } else {
  717. redis.Incr("other", incurKey)
  718. }
  719. //生成随机数
  720. verifyStr := strings.ToUpper(util.GetComplexRandom(6, 3, 3))
  721. d.SetSession("EMVerifySucess", false)
  722. d.SetSession("DataExportVerifyEmail", email)
  723. d.SetSession("DataExportVerify", verifyStr)
  724. d.SetSession("CreatEVerifyTime", time.Now().Unix())
  725. log.Println("====================", verifyStr, "====================", sessVal["CreatEVerifyTime"], "====================")
  726. //发送邮箱验证码
  727. go public.SendMailIdentCode(email, verifyStr, config.GmailAuth)
  728. d.T["success"] = true
  729. } else {
  730. d.T["success"] = false
  731. d.T["errCode"] = 3
  732. d.T["time"] = timeSpaceing
  733. d.T["errMsg"] = "验证码发送次数已达到今日上限"
  734. }
  735. } else {
  736. d.T["success"] = false
  737. d.T["errCode"] = 2
  738. d.T["time"] = timeSpaceing
  739. d.T["errMsg"] = "已发送,5分钟后再尝试"
  740. }
  741. }
  742. } else {
  743. d.T["success"] = false
  744. d.T["errCode"] = 1
  745. d.T["errMsg"] = "邮箱格式不正确"
  746. }
  747. d.ServeJson(&d.T)
  748. }
  749. func isPhone(value string) bool {
  750. var phonePattern = regexp.MustCompile("^[1][3-9][0-9]{9}$")
  751. return phonePattern.MatchString(value)
  752. }
  753. // 验证手机号
  754. func (d *DataExport) CheckPhoneVerify() {
  755. phone := d.GetString("phone")
  756. verityResult := false
  757. if isPhone(phone) {
  758. verityResult = true
  759. d.SetSession("DataExportVerifyPhone", phone)
  760. }
  761. d.T["success"] = verityResult
  762. d.ServeJson(&d.T)
  763. }
  764. // 验证邮箱
  765. func (d *DataExport) CheckMailVerify() {
  766. email := d.GetString("email")
  767. emailVerity := d.GetString("emailVerity")
  768. DataExportEmail := d.GetSession("DataExportVerifyEmail")
  769. DataExportVerify := d.GetSession("DataExportVerify")
  770. verityResult := false
  771. if emailVerity != "" && emailVerity == DataExportVerify && email != "" && email == DataExportEmail {
  772. verityResult = true
  773. d.DelSession("DataExportVerify")
  774. d.DelSession("CreatEVerifyTime")
  775. d.SetSession("EMVerifySucess", true)
  776. d.SetSession("DataExportVerifyEmail_val", DataExportEmail)
  777. }
  778. d.T["success"] = verityResult
  779. d.ServeJson(&d.T)
  780. }
  781. func isEmail(value string) bool {
  782. 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})(\\]?)$")
  783. return emailPattern.MatchString(value)
  784. }
  785. func (d *DataExport) Paysuccess() error {
  786. code := d.GetString("code")
  787. // openid, _ := d.GetSession("s_m_openid").(string)
  788. userId, _ := d.GetSession("userId").(string)
  789. data := map[string]interface{}{}
  790. if code != "" && userId != "" {
  791. data_ := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
  792. "order_code": code,
  793. "user_id": userId,
  794. "order_status": 1,
  795. }, "pay_way,user_mail,pay_time,pay_money,order_money", "")
  796. if data_ != nil {
  797. data = *data_
  798. if data["pay_money"] != nil {
  799. data["pay_money"] = util.Float64All(data["pay_money"]) / 100
  800. } else {
  801. data["pay_money"] = util.Float64All(data["order_money"]) / 100
  802. }
  803. if data["pay_way"] != nil {
  804. pay_way := util.ObjToString(data["pay_way"])
  805. if strings.Contains(pay_way, "wx") {
  806. pay_way = "微信"
  807. } else if strings.Contains(pay_way, "ali") {
  808. pay_way = "支付宝"
  809. }
  810. data["pay_way"] = pay_way
  811. }
  812. }
  813. }
  814. d.T["data"] = data
  815. d.T["order_code"] = code
  816. return d.Render("/pc/paysuccess.html")
  817. }
  818. func (d *DataExport) VipOrderDetail() {
  819. d.Render("/pc/vip_orderDetail.html")
  820. }
  821. func (d *DataExport) EntOrderDetail() {
  822. d.Render("/pc/entniche_orderDetail.html")
  823. }
  824. func (d *DataExport) Invoice(order_code string) error {
  825. userid := d.GetSession("userId").(string)
  826. d.T["order_code"] = order_code
  827. res := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
  828. "user_id": userid,
  829. "order_code": order_code,
  830. }, "user_mail,user_phone", "create_time desc")
  831. if *res != nil {
  832. d.T["mail"] = (*res)["user_mail"]
  833. d.T["phone"] = (*res)["user_phone"]
  834. }
  835. if public.Mysql.CountBySql("select count(1) as count from dataexport_order where user_id = ? and order_code = ? and order_status = ?", userid, order_code, 1) > 0 {
  836. return d.Render("/pc/invoice.html", &d.T)
  837. }
  838. return d.Render("/_error.html")
  839. }
  840. func (d *DataExport) Check_invoice(order_code string) error {
  841. userid := d.GetSession("userId").(string)
  842. d.T["order_code"] = order_code
  843. if public.Mysql.CountBySql("select count(1) as count from dataexport_order where user_id = ? and order_code = ? and order_status = ?", userid, order_code, 1) > 0 {
  844. return d.Render("/pc/check_invoice.html", &d.T)
  845. }
  846. return d.Render("/_error.html")
  847. }
  848. //func (d *DataExport) Gettest() {
  849. // order_code := d.GetString("order_code")
  850. // info := public.Mysql.FindOne("invoice", map[string]interface{}{"order_code": order_code}, "", "")
  851. // d.ServeJson(map[string]interface{}{
  852. // "data": info,
  853. // })
  854. // return
  855. //}
  856. func (d *DataExport) InvoicetimeOut() {
  857. d.Render("/pc/invoice_error.html")
  858. }
  859. func (d *DataExport) ValuationList(order_code string) error {
  860. userid := d.GetSession("userId").(string)
  861. d.T["order_code"] = order_code
  862. if public.Mysql.CountBySql("select count(1) as count from dataexport_order where user_id = ? and order_code = ?", userid, order_code) > 0 {
  863. return d.Render("/pc/billing_list.html")
  864. }
  865. return d.Render("/_error.html")
  866. }
  867. func (d *DataExport) SetDontPromptAgain() {
  868. status := d.GetString("status") //0 提示 1 不再提示
  869. userId := d.GetSession("mgoUserId").(string)
  870. boo := public.MQFW.UpdateById("user", userId, map[string]interface{}{
  871. "$set": map[string]interface{}{
  872. "i_export_promptAgain": status,
  873. },
  874. })
  875. d.ServeJson(map[string]interface{}{
  876. "error_code": 0,
  877. "error_msg": "",
  878. "success": boo,
  879. })
  880. return
  881. }
  882. func (d *DataExport) GetDontPromptAgain() {
  883. isPrompt := true
  884. userId := d.GetSession("mgoUserId").(string)
  885. user, ok := public.MQFW.FindById("user", userId, `{"i_export_promptAgain":1}`)
  886. if ok && user != nil && len(*user) > 0 {
  887. if util.IntAll((*user)["i_export_promptAgain"]) == 1 {
  888. isPrompt = false
  889. }
  890. }
  891. d.ServeJson(map[string]interface{}{
  892. "error_code": 0,
  893. "error_msg": "",
  894. "isPrompt": isPrompt,
  895. })
  896. return
  897. }
  898. //
  899. //func (d *DataExport) EntDataExport(_id string) error {
  900. // id := util.se.Decode4Hex(_id)
  901. // userId := util.ObjToString(d.GetSession("userId"))
  902. // entId := util.IntAll(d.GetSession("entId"))
  903. // entUserId := util.IntAll(d.GetSession("entUserId"))
  904. // isFirst, err := d.GetBool("isFirst")
  905. // if err != nil {
  906. // isFirst = true
  907. // }
  908. // if userId == "" {
  909. // return errors.New("未登录")
  910. // }
  911. // exportLock.Lock()
  912. // exportLockMap[entId] = sync.Mutex{}
  913. // entLock := exportLockMap[entId]
  914. // exportLock.Unlock()
  915. // entLock.Lock()
  916. // query := map[string]interface{}{"ent_id": entId, "user_id": entUserId}
  917. // data_limit, remain_nums, export_nums := 0, 0, 0
  918. // limit := public.Mysql.FindOne("entniche_export_limit", query, "data_limit,remain_nums,export_nums", "")
  919. // if limit != nil {
  920. // data_limit = util.IntAll((*limit)["data_limit"])
  921. // remain_nums = util.IntAll((*limit)["remain_nums"])
  922. // export_nums = util.IntAll((*limit)["export_nums"])
  923. // }
  924. // count := 0
  925. // newCount := 0
  926. // data := &[]map[string]interface{}{}
  927. // current := GetCurrentCount(entId)
  928. // log.Println("企业总条数", current)
  929. // url := config.Sysconfig["dedupUrl"].(string)
  930. // count, newCount, data = public.GetEntDataExportCount(id, entId, entUserId, remain_nums, current, isFirst, util.ObjToString(config.Sysconfig["webdomain"]), url)
  931. // isExport := true
  932. // isEntExport := true
  933. // if newCount > current {
  934. // isEntExport = false
  935. // }
  936. // if newCount > remain_nums {
  937. // isExport = false
  938. // }
  939. // //current 企业总条数 count 筛选条数 newCount 去重后条数 exportNum 今日已导出 limit 今日剩余 limitDay 今日限额
  940. // result := map[string]interface{}{
  941. // "newCount": newCount,
  942. // "count": count,
  943. // "limit": remain_nums,
  944. // "limitDay": data_limit,
  945. // "exportNum": export_nums,
  946. // "current": current,
  947. // "isExport": isExport,
  948. // "isEntExport": isEntExport,
  949. // }
  950. // if isFirst || !isExport || !isEntExport {
  951. // entLock.Unlock()
  952. // d.ServeJson(result)
  953. // } else {
  954. // go func() {
  955. // data = public.FormatExportDatas(data, config.Sysconfig["webdomain"].(string), "2", entId)
  956. // xlsxUrl := GetXlsx(*data, entId, entUserId)
  957. // if xlsxUrl != "" {
  958. // filter := Filters{
  959. // FilterId: id,
  960. // }
  961. // filterStr, _ := json.Marshal(filter)
  962. // SaveExportLog(entId, entUserId, count, newCount, remain_nums, export_nums, xlsxUrl, "2", string(filterStr))
  963. // DeductNum(entId, newCount)
  964. // go func() {
  965. // for _, v := range *data {
  966. // mongodb.Save("entdataexport", v)
  967. // }
  968. // }()
  969. // redis.Put("other", "entexportdata_"+fmt.Sprintln(entId), xlsxUrl, 60)
  970. // entLock.Unlock()
  971. // }
  972. // }()
  973. // d.ServeJson(result)
  974. // }
  975. // return nil
  976. //}
  977. // 剑鱼pc判断登录用户是否有我的企业、商机管理菜单
  978. func (this *DataExport) GetPcEntAuth() {
  979. userId, _ := this.GetSession("userId").(string)
  980. //userId := "1212"
  981. if userId == "" {
  982. data := map[string]interface{}{
  983. "error_code": 1001,
  984. "myEntMenu": true,
  985. "entnicheMenu": true,
  986. }
  987. this.ServeJson(data)
  988. return
  989. }
  990. phone, _ := GetPhone(userId)
  991. //phone = "15136225931"
  992. myEntMenu := false
  993. entnicheMenu := false
  994. privatedata := false
  995. pcUsers := map[int]bool{}
  996. hideUsers := map[int]bool{}
  997. for _, v := range config.EntnichePcConf.EntnichePcUser {
  998. pcUsers[v] = true
  999. }
  1000. for _, v := range config.EntnichePcConf.HideEntnicheMenu {
  1001. hideUsers[v] = true
  1002. }
  1003. isNew := false
  1004. if phone != "" {
  1005. ent := public.Mysql.SelectBySql("select id,isNew,phone,createtime from entniche_info where phone=? and status=1 ", phone)
  1006. if ent != nil && len(*ent) != 0 {
  1007. for _, val := range *ent {
  1008. if pcUsers[util.IntAll(val["id"])] {
  1009. myEntMenu = true
  1010. if hideUsers[util.IntAll(val["id"])] {
  1011. entnicheMenu = false
  1012. } else {
  1013. if util.IntAll(val["isNew"]) == 1 {
  1014. isNew = true
  1015. }
  1016. entnicheMenu = true
  1017. }
  1018. break
  1019. }
  1020. }
  1021. }
  1022. if !myEntMenu {
  1023. user := public.Mysql.SelectBySql("select id,ent_id,power,export_power from entniche_user where phone=? ORDER BY power desc", phone)
  1024. if user != nil && len(*user) > 0 {
  1025. for _, v := range *user {
  1026. if pcUsers[util.IntAll(v["ent_id"])] {
  1027. ents := public.Mysql.SelectBySql("select status,id,createtime,isNew from entniche_info where id=? ", util.IntAll(v["ent_id"]))
  1028. if ents != nil && len(*ents) != 0 {
  1029. for _, vv := range *ents {
  1030. if util.IntAll(vv["status"]) == 1 {
  1031. myEntMenu = true
  1032. }
  1033. if util.IntAll(v["power"]) == 1 {
  1034. if hideUsers[util.IntAll(vv["id"])] {
  1035. entnicheMenu = false
  1036. } else {
  1037. if util.IntAll(vv["isNew"]) == 1 {
  1038. isNew = true
  1039. }
  1040. entnicheMenu = true
  1041. }
  1042. }
  1043. }
  1044. }
  1045. break
  1046. }
  1047. }
  1048. }
  1049. }
  1050. userCount := public.Mysql.CountBySql("select count(1) from privatedata where phone=?", phone)
  1051. if userCount > 0 {
  1052. privatedata = true
  1053. }
  1054. }
  1055. data := map[string]interface{}{
  1056. "myEntMenu": true,
  1057. "entnicheMenu": entnicheMenu,
  1058. "isNew": isNew,
  1059. "privatedata": privatedata,
  1060. }
  1061. this.ServeJson(data)
  1062. }
  1063. //
  1064. ////判断是否导出成功
  1065. //func (this *DataExport) IsEntExportSuccess() {
  1066. // entId := util.IntAll(this.GetSession("entId"))
  1067. // res := map[string]interface{}{
  1068. // "state": false,
  1069. // }
  1070. // if entId != 0 {
  1071. // key := "entexportdata_" + fmt.Sprintln(entId)
  1072. // log.Println(key)
  1073. // xlsxUrl := redis.Get("other", key)
  1074. // log.Println(xlsxUrl)
  1075. // if xlsxUrl != nil {
  1076. // res["state"] = true
  1077. // res["xlsxUrl"] = xlsxUrl
  1078. // redis.Del("other", key)
  1079. // }
  1080. // }
  1081. // this.ServeJson(res)
  1082. //}
  1083. //
  1084. ////生成xlsx
  1085. //func GetXlsx(mMap []map[string]interface{}, entId, entUserId int) string {
  1086. // xf, err := xlsx.OpenFile("./web/staticres/fields.xlsx")
  1087. // if err != nil {
  1088. // log.Println("fields file not foud", err.Error())
  1089. // }
  1090. // sh := xf.Sheets[1]
  1091. // for _, v := range mMap {
  1092. // row := sh.AddRow()
  1093. // row.AddCell().SetValue(v["area"])
  1094. // row.AddCell().SetValue(v["city"])
  1095. // row.AddCell().SetValue(v["title"])
  1096. // row.AddCell().SetValue(v["subtype"])
  1097. // row.AddCell().SetValue(v["detail"])
  1098. // if v["publishtime"] != nil {
  1099. // row.AddCell().SetValue(v["publishtime"])
  1100. // } else {
  1101. // row.AddCell()
  1102. // }
  1103. // row.AddCell().SetValue(v["href"])
  1104. // row.AddCell().SetValue(v["url"])
  1105. // row.AddCell().SetValue(v["projectname"])
  1106. // row.AddCell().SetValue(v["projectcode"])
  1107. // row.AddCell().SetValue(v["projectscope"])
  1108. // if v["budget"] != nil {
  1109. // row.AddCell().SetFloat(util.Float64All(v["budget"]))
  1110. // } else {
  1111. // row.AddCell()
  1112. // }
  1113. // if v["bidamount"] != nil {
  1114. // row.AddCell().SetFloat(util.Float64All(v["bidamount"]))
  1115. // } else {
  1116. // row.AddCell()
  1117. // }
  1118. // if v["bidopentime"] != nil {
  1119. // row.AddCell().SetValue(v["bidopentime"])
  1120. // } else {
  1121. // row.AddCell()
  1122. // }
  1123. // row.AddCell().SetValue(v["buyer"])
  1124. // row.AddCell().SetValue(v["buyerperson"])
  1125. // row.AddCell().SetValue(v["buyertel"])
  1126. // row.AddCell().SetValue(v["agency"])
  1127. // row.AddCell().SetValue(v["s_winner"])
  1128. // row.AddCell().SetValue(v["winnerperson"])
  1129. // row.AddCell().SetValue(v["winnertel"])
  1130. // row.AddCell().SetValue(v["legal_person"])
  1131. // row.AddCell().SetValue(v["company_phone"])
  1132. // row.AddCell().SetValue(v["company_email"])
  1133. // }
  1134. // xf.Sheets = xf.Sheets[1:2]
  1135. // xf.Sheets[0].Name = "数据导出"
  1136. // //生文件
  1137. // t := strconv.FormatInt(time.Now().Unix(), 10)
  1138. // entIds := strconv.Itoa(entId)
  1139. // entUserIds := strconv.Itoa(entUserId)
  1140. // dir := "./web/staticres/xlsx/entsearchexport/" + entIds + "_" + entUserIds + "_" + t + "/"
  1141. // if b, _ := PathExists(dir); !b {
  1142. // err1 := os.MkdirAll(dir, os.ModePerm)
  1143. // if err1 != nil {
  1144. // log.Println("mkdir err", dir)
  1145. // }
  1146. // }
  1147. // fname := entIds + "_" + entUserIds + "_" + "entdataexport.xlsx"
  1148. // xlsxUrl := dir + fname
  1149. // xlsxUrls := "/xlsx/entsearchexport/" + entIds + "_" + entUserIds + "_" + t + "/" + fname
  1150. // err = xf.Save(xlsxUrl)
  1151. // if err != nil {
  1152. // log.Println("xls error", fname)
  1153. // xlsxUrls = ""
  1154. // }
  1155. // return xlsxUrls
  1156. //}
  1157. //
  1158. //func PathExists(path string) (bool, error) {
  1159. // _, err := os.Stat(path)
  1160. // if err == nil {
  1161. // return true, nil
  1162. // }
  1163. // if os.IsNotExist(err) {
  1164. // return false, nil
  1165. // }
  1166. // return false, err
  1167. //}
  1168. //
  1169. //func SaveExportLog(entId, entUserId, count, newCount, remain_nums, export_nums int, xlsxUrl, types, filterStr string) {
  1170. // query := map[string]interface{}{
  1171. // "id": entUserId,
  1172. // "ent_id": entId,
  1173. // }
  1174. // set := map[string]interface{}{
  1175. // "remain_nums": remain_nums - newCount,
  1176. // "export_nums": export_nums + newCount,
  1177. // }
  1178. // ok := public.Mysql.Update("entniche_export_limit", map[string]interface{}{"ent_id": entId, "user_id": entUserId}, set)
  1179. // if !ok {
  1180. // log.Println("修改导出条数失败", query, remain_nums, newCount)
  1181. // }
  1182. // userData := public.Mysql.FindOne("entniche_user", query, "name,phone", "")
  1183. // if userData != nil {
  1184. // name := util.ObjToString((*userData)["name"])
  1185. // phone := util.ObjToString((*userData)["phone"])
  1186. // now := time.Now()
  1187. // public.Mysql.Insert("entniche_export_log", map[string]interface{}{
  1188. // "user_name": name,
  1189. // "export_time": FormatDate(&now, util.Date_Full_Layout),
  1190. // "data_source": "2",
  1191. // "export_num": count,
  1192. // "deduct_num": newCount,
  1193. // "download_url": xlsxUrl,
  1194. // "ent_id": entId,
  1195. // "phone": phone,
  1196. // "user_id": entUserId,
  1197. // "filter": filterStr,
  1198. // })
  1199. // }
  1200. //}
  1201. //
  1202. //func DeductNum(entId, newCount int) {
  1203. // query := map[string]interface{}{
  1204. // "id": entId,
  1205. // }
  1206. // userData := public.Mysql.FindOne("entniche_info", query, "name,phone", "")
  1207. // if userData != nil {
  1208. // name := util.ObjToString((*userData)["name"])
  1209. // phone := util.ObjToString((*userData)["phone"])
  1210. // public.Mgo_Qyfw.Update("user", map[string]interface{}{"phone": phone, "username": name}, map[string]interface{}{
  1211. // "$inc": map[string]interface{}{
  1212. // "plan.current": -newCount,
  1213. // },
  1214. // }, false, false)
  1215. // }
  1216. //}
  1217. //
  1218. //func GetCurrentCount(entId int) int {
  1219. // count := 0
  1220. // userData := public.Mysql.FindOne("entniche_info", map[string]interface{}{"id": entId}, "name,phone", "")
  1221. // if userData == nil {
  1222. // return count
  1223. // }
  1224. // current, ok := public.Mgo_Qyfw.FindOne("user", map[string]interface{}{"phone": util.ObjToString((*userData)["phone"]), "username": util.ObjToString((*userData)["name"])})
  1225. // if current == nil || !ok {
  1226. // return count
  1227. // }
  1228. // plan, _ := (*current)["plan"].(map[string]interface{})
  1229. // count = util.IntAll(plan["current"])
  1230. // return count
  1231. //}
  1232. // 获取当前登录用户的手机号
  1233. func GetPhone(userId string) (string, string) {
  1234. u := jyutil.Compatible.Select(userId, `{"s_phone":1,"s_m_phone":1}`)
  1235. if u != nil {
  1236. if s_phone, _ := (*u)["s_phone"].(string); s_phone != "" {
  1237. return s_phone, "s_phone"
  1238. } else if s_m_phone, _ := (*u)["s_m_phone"].(string); s_m_phone != "" {
  1239. return s_m_phone, "s_m_phone"
  1240. }
  1241. }
  1242. return "", ""
  1243. }
  1244. func (d *DataExport) MemberDetail() {
  1245. d.Render("/pc/member_orderDetail.html")
  1246. }
  1247. func (d *DataExport) AiForecastPackDetail() {
  1248. d.Render("/pc/aiPack_orderDetail.html")
  1249. }
  1250. func (d *DataExport) SubAccountDetail() {
  1251. d.Render("/pc/subAccount_orderDetail.html")
  1252. }
  1253. func (d *DataExport) BidfileDetail() {
  1254. d.Render("/order/pc/bidfile/bidfileDetail.html")
  1255. }
  1256. func (d *DataExport) IntegralDetail() {
  1257. d.Render("/order/pc/integral/integralDetail.html")
  1258. }