dataExport.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. package front
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "jfw/config"
  8. "jfw/public"
  9. "log"
  10. "qfw/util"
  11. "qfw/util/jy"
  12. "qfw/util/redis"
  13. "regexp"
  14. "strconv"
  15. "strings"
  16. "time"
  17. "github.com/SKatiyar/qr"
  18. "github.com/go-xweb/xweb"
  19. )
  20. type DataExport struct {
  21. *xweb.Action
  22. toSieve xweb.Mapper `xweb:"/front/dataExport/toSieve"` //数据导出-条件筛选
  23. sieveData xweb.Mapper `xweb:"/front/dataExport/sieveData"` //筛选数据
  24. toMyOrder xweb.Mapper `xweb:"/front/dataExport/toMyOrder"` //我的订单
  25. queryOrder xweb.Mapper `xweb:"/front/dataExport/queryOrder"` //查询我的订单
  26. deleteOrder xweb.Mapper `xweb:"/front/dataExport/deleteOrder"` //删除订单
  27. toOrderDetail xweb.Mapper `xweb:"/front/dataExport/toOrderDetail/(.*)"` //订单详情
  28. getOrderCode xweb.Mapper `xweb:"/front/dataExport/getOrderCode/(\\w+)"` //申请发票获取订单编号
  29. applyInvoice xweb.Mapper `xweb:"/front/dataExport/applyInvoice"` //申请发票
  30. superSearchExport xweb.Mapper `xweb:"/front/dataExport/superSearchExport"` //数据导出-超级搜索
  31. toCreateOrderPage xweb.Mapper `xweb:"/front/dataExport/toCreateOrderPage/(.*)"` //数据导出-订单页面
  32. previewData xweb.Mapper `xweb:"/front/(.*)/previewData/(.*)"` //数据导出-数据预览
  33. sendMailVerify xweb.Mapper `xweb:"/front/dataExport/sendMailVerify"` //发送邮箱验证码
  34. checkMailVerify xweb.Mapper `xweb:"/front/dataExport/checkMailVerify"` //验证邮箱验证码
  35. paysuccess xweb.Mapper `xweb:"/front/dataExport/paysuccess"` //支付成功页面
  36. checkPhoneVerify xweb.Mapper `xweb:"/front/dataExport/checkPhoneVerify"` //验证手机号
  37. fontSet xweb.Mapper `xweb:"/front/dataExport/fontSet/(.*)"`
  38. cancelOrder xweb.Mapper `xweb:"/front/dataExport/cancelOrder"` //取消订单
  39. }
  40. var order_pageSize = 10
  41. func init() {
  42. xweb.AddAction(&DataExport{})
  43. }
  44. var (
  45. layout_date = "2006.01.02"
  46. orderStatus_unPaid = "0" //订单状态-待支付
  47. orderStatus_paid = "1" //订单状态-已完成
  48. orderStatus_deleted = "-1" //订单状态-已删除
  49. orderStatus_cancel = "-2" //订单状态-已取消
  50. tableName_order = "dataexport_order" //订单表
  51. )
  52. func (d *DataExport) ToSieve() error {
  53. industrylist, sortArray = getindustrys()
  54. d.T["industrylist"] = industrylist
  55. d.T["sortArray"] = sortArray
  56. d.T["logid"] = config.Seoconfig["dataexport"].(string)
  57. d.Render("/pc/dataExport_sieve.html", &d.T)
  58. return nil
  59. }
  60. func (d *DataExport) SieveData() error {
  61. publishtime := d.GetString("publishtime")
  62. area := d.GetString("area")
  63. city := d.GetString("city")
  64. region := d.GetString("region")
  65. industry := d.GetString("industry")
  66. keyword := d.GetString("keyword")
  67. minPrice := d.GetString("minprice")
  68. maxPrice := d.GetString("maxprice")
  69. subType := d.GetString("subtype")
  70. buyer := d.GetString("buyer")
  71. winner := d.GetString("winner")
  72. var areaArr []string
  73. var cityArr []string
  74. var regionArr []string
  75. var industryArr []string
  76. var subTypeArr []string
  77. var buyerArr []string
  78. var winnerArr []string
  79. var keywordList []public.KeyWord
  80. log.Println("price", minPrice, maxPrice)
  81. if publishtime != "" {
  82. log.Println("publishtime", publishtime)
  83. }
  84. if area != "" {
  85. areaArr = strings.Split(area, ",")
  86. log.Println("areaArr", areaArr)
  87. }
  88. if city != "" {
  89. cityArr = strings.Split(city, ",")
  90. log.Println("cityArr", cityArr)
  91. }
  92. if region != "" {
  93. regionArr = strings.Split(region, ",")
  94. log.Println("regionArr", regionArr)
  95. }
  96. if industry != "" {
  97. industryArr = strings.Split(industry, ",")
  98. log.Println("industryArr", industryArr)
  99. }
  100. if subType != "" {
  101. subTypeArr = strings.Split(subType, ",")
  102. log.Println("subTypeArr", subTypeArr)
  103. }
  104. log.Println("keywordParam", keyword)
  105. if keyword != "" {
  106. err := json.Unmarshal([]byte(keyword), &keywordList)
  107. if err != nil {
  108. log.Println("keyword param 反序列化异常,查看前后台字段是否对应")
  109. } else {
  110. log.Println("keywordList", len(keywordList), keywordList)
  111. }
  112. }
  113. if buyer != "" {
  114. buyerArr = strings.Split(buyer, ",")
  115. log.Println("buyerArr", buyerArr)
  116. }
  117. if winner != "" {
  118. winnerArr = strings.Split(winner, ",")
  119. log.Println("winnerArr", winnerArr)
  120. }
  121. sieveCondition := map[string]interface{}{
  122. "publishtime": publishtime,
  123. "area": areaArr,
  124. "city": cityArr,
  125. "region": regionArr,
  126. "industry": industryArr,
  127. "keywords": keywordList,
  128. "minprice": minPrice,
  129. "maxprice": maxPrice,
  130. "subtype": subType,
  131. "buyer": buyerArr,
  132. "winner": winnerArr,
  133. "comeintime": time.Now().Unix(),
  134. "comeinfrom": "exportPage",
  135. }
  136. if d.GetSession("s_m_openid") != nil {
  137. sieveCondition["s_openid"] = d.GetSession("s_m_openid").(string)
  138. }
  139. if d.GetSession("userId") != nil {
  140. sieveCondition["s_userid"] = d.GetSession("userId").(string)
  141. }
  142. _id := mongodb.Save(public.ExportTable, sieveCondition)
  143. if _id != "" {
  144. d.T["success"] = true
  145. d.T["redirectUrl"] = "/front/dataExport/toCreateOrderPage/" + util.SE.Encode2Hex(_id)
  146. } else {
  147. d.T["success"] = false
  148. }
  149. d.ServeJson(&d.T)
  150. return nil
  151. }
  152. func (d *DataExport) ToMyOrder() error {
  153. d.T["logid"] = config.Seoconfig["dataexport"].(string)
  154. d.Render("/pc/myOrder.html", &d.T)
  155. return nil
  156. }
  157. func (d *DataExport) QueryOrder() error {
  158. typ := d.GetString("type") //0-全部 1-待支付 2-已支付 3-已取消
  159. query := map[string]interface{}{}
  160. if userId := d.GetSession("userId"); userId != nil {
  161. query["user_id"] = userId.(string)
  162. log.Println("QueryOrder -- userId====================", userId)
  163. } else {
  164. log.Println("QueryOrder -- session userId does not exist")
  165. return nil
  166. }
  167. if typ != "0" && typ != "" {
  168. var status string
  169. if typ == "1" {
  170. status = orderStatus_unPaid
  171. } else if typ == "2" {
  172. status = orderStatus_paid
  173. } else if typ == "3" {
  174. status = orderStatus_cancel
  175. }
  176. query["order_status"] = status
  177. } else {
  178. query["order_status"] = map[string]interface{}{"ne": orderStatus_deleted}
  179. }
  180. //总数
  181. countData := public.Mysql.Find(tableName_order, query, "", "", -1, 0)
  182. count := len(*countData)
  183. //当前页
  184. pageNum, _ := d.GetInteger("pageNum")
  185. //开始下标索引
  186. var start = (pageNum - 1) * order_pageSize
  187. //总页数
  188. //totalPage := (count + int(order_pageSize) - 1) / int(order_pageSize)
  189. list := public.Mysql.Find(tableName_order, query, "", "create_time desc", start, order_pageSize)
  190. if list != nil {
  191. for _, v := range *list {
  192. filter_publishtime := v["filter_publishtime"]
  193. if filter_publishtime != nil || filter_publishtime != "" {
  194. timeArr := strings.Split(filter_publishtime.(string), "_")
  195. if len(timeArr) == 2 {
  196. start, err := strconv.ParseInt(timeArr[0], 10, 64)
  197. end, erro := strconv.ParseInt(timeArr[1], 10, 64)
  198. if err == nil && erro == nil {
  199. v["filter_publishtime"] = util.FormatDateByInt64(&start, layout_date) + "-" + util.FormatDateByInt64(&end, layout_date)
  200. }
  201. }
  202. }
  203. orderMoney := v["order_money"]
  204. if orderMoney != nil {
  205. v["order_money"] = float64(orderMoney.(int64)) / 100
  206. }
  207. if v["id"] != nil && orderMoney != nil && v["order_code"] != nil {
  208. v["token"] = public.GetWaitPayToken(v["id"].(int64), int(orderMoney.(int64)), v["order_code"].(string), util.ObjToString(v["pay_way"]), query["user_id"].(string))
  209. }
  210. }
  211. }
  212. for _, v := range *list {
  213. if v["pay_way"] == "wx_pc" && util.IntAll(v["order_status"]) == 0 {
  214. r, _ := qr.Encode(util.ObjToString(v["code_url"]), qr.M)
  215. pngdat := r.PNG()
  216. v["code_url"] = base64.StdEncoding.EncodeToString(pngdat)
  217. }
  218. }
  219. d.ServeJson(map[string]interface{}{
  220. "list": list,
  221. "count": count,
  222. "pageSize": order_pageSize,
  223. })
  224. return nil
  225. }
  226. /**
  227. 根据 id+openid 取消订单
  228. */
  229. func (d *DataExport) CancelOrder() error {
  230. if userId := d.GetSession("userId"); userId != nil {
  231. // if openid := d.GetSession("s_m_openid"); openid != nil {
  232. queryMap := map[string]interface{}{
  233. "id": d.GetString("id"),
  234. "user_id": userId.(string),
  235. }
  236. boo := public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"order_status": -2})
  237. //取消订单
  238. d.ServeJson(map[string]interface{}{"success": boo})
  239. }
  240. return nil
  241. }
  242. /**
  243. 根据 id+openid 删除
  244. */
  245. func (d *DataExport) DeleteOrder() error {
  246. if userId := d.GetSession("userId"); userId != nil {
  247. // if openid := d.GetSession("s_m_openid"); openid != nil {
  248. queryMap := map[string]interface{}{
  249. "id": d.GetString("id"),
  250. "user_id": userId.(string),
  251. }
  252. boo := public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"order_status": -1})
  253. //撤销订单
  254. d.ServeJson(map[string]interface{}{"success": boo})
  255. }
  256. return nil
  257. }
  258. /**
  259. 根据 订单编号+userId 查询
  260. */
  261. func (d *DataExport) ToOrderDetail(orderCode string) error {
  262. myUserId := ""
  263. if userId := d.GetSession("userId"); userId != nil {
  264. // if openid := d.GetSession("s_m_openid"); openid != nil {
  265. myUserId = userId.(string)
  266. } else {
  267. return nil
  268. }
  269. orderDetail := map[string]interface{}{}
  270. filter := public.SieveCondition{}
  271. queryMap := map[string]interface{}{
  272. "order_code": orderCode,
  273. "user_id": myUserId,
  274. }
  275. if orderCode != "" {
  276. orderDetail = *public.Mysql.FindOne(tableName_order, queryMap, "", "")
  277. }
  278. // log.Println("ToOrderDetail", orderCode, orderDetail)
  279. if orderDetail["pay_money"] != nil {
  280. orderDetail["pay_money"] = float64(orderDetail["pay_money"].(int64)) / 100
  281. }
  282. if orderDetail["order_money"] != nil {
  283. orderDetail["order_money"] = float64(orderDetail["order_money"].(int64)) / 100
  284. }
  285. if orderDetail["filter"] != nil {
  286. err := json.Unmarshal([]byte(orderDetail["filter"].(string)), &filter)
  287. if err == nil {
  288. publishtime := filter.PublishTime
  289. if publishtime != "" {
  290. timeArr := strings.Split(publishtime, "_")
  291. if len(timeArr) == 2 {
  292. start, err := strconv.ParseInt(timeArr[0], 10, 64)
  293. end, erro := strconv.ParseInt(timeArr[1], 10, 64)
  294. if err == nil && erro == nil {
  295. filter.PublishTime = util.FormatDateByInt64(&start, layout_date) + "-" + util.FormatDateByInt64(&end, layout_date)
  296. } else if err == nil && erro != nil {
  297. filter.PublishTime = util.FormatDateByInt64(&start, layout_date) + "-"
  298. } else if err != nil && erro == nil {
  299. filter.PublishTime = "-" + util.FormatDateByInt64(&end, layout_date)
  300. }
  301. }
  302. }
  303. filter.MinPrice = public.GetPriceDes_SieveCondition(filter.MinPrice, filter.MaxPrice)
  304. orderDetail["filter"] = filter
  305. } else {
  306. log.Println("筛选条件-关键词-结构体反序列化-错误", err)
  307. }
  308. }
  309. if orderDetail["applybill_type"] != nil && orderDetail["applybill_type"].(int64) == 0 {
  310. orderDetail["applybill_type"] = "个人"
  311. } else if orderDetail["applybill_type"] != nil && orderDetail["applybill_type"].(int64) == 1 {
  312. orderDetail["applybill_type"] = "单位"
  313. } else {
  314. orderDetail["applybill_type"] = "-"
  315. }
  316. if orderDetail["applybill_status"] != nil && orderDetail["applybill_status"].(int64) == 1 {
  317. orderDetail["applybill_status"] = "T" //已申请
  318. } else {
  319. orderDetail["applybill_status"] = "F" //未申请
  320. }
  321. orderStatus := util.IntAll((orderDetail)["order_status"])
  322. if orderStatus == 1 {
  323. orderDetail["transaction_id"] = func() string {
  324. table := ""
  325. payway := util.ObjToString(orderDetail["pay_way"])
  326. if strings.Contains(payway, "wx") {
  327. payway = "微信"
  328. table = "weixin_pay"
  329. } else if strings.Contains(payway, "ali") {
  330. payway = "支付宝"
  331. table = "ali_pay"
  332. } else {
  333. return ""
  334. }
  335. orderDetail["pay_way"] = payway
  336. wxPayMap := map[string]interface{}{}
  337. wxPayMap["out_trade_no"] = orderDetail["out_trade_no"]
  338. wxpay := public.Mysql.FindOne(table, wxPayMap, "", "")
  339. return util.ObjToString((*wxpay)["transaction_id"])
  340. }()
  341. }
  342. d.T["o"] = orderDetail
  343. d.T["logid"] = config.Seoconfig["dataexport"].(string)
  344. d.Render("/pc/orderDetail.html", &d.T)
  345. return nil
  346. }
  347. //------------------------------申请发票跳转页面-----------------------------
  348. func (d *DataExport) GetOrderCode(order_code string) error {
  349. var status, order_status int64
  350. queryMap := map[string]interface{}{
  351. "order_code": order_code,
  352. }
  353. oDate := public.Mysql.FindOne(tableName_order, queryMap, "", "")
  354. status = (*oDate)["applybill_status"].(int64)
  355. order_status = (*oDate)["order_status"].(int64)
  356. d.T["order_code"] = order_code
  357. d.T["logid"] = config.Seoconfig["dataexport"].(string)
  358. //是否申请发票 支付状态
  359. if status == 1 || order_status == 0 {
  360. d.Redirect("/front/dataExport/toOrderDetail/" + order_code)
  361. } else {
  362. d.Render("/pc/dataExport_invoice.html", &d.T)
  363. }
  364. return nil
  365. }
  366. //----------------------------申请发票------------------------------------
  367. func (d *DataExport) ApplyInvoice() error {
  368. var applyBill_status int
  369. var order_code, applyBill_company, applyBill_taxnum, applyBill_type string
  370. var updateBl bool = false
  371. order_code = d.GetString("order_code")
  372. //获取数据
  373. applyBill_type = d.GetString("demo-radio") //个人 单位
  374. queryMap := map[string]interface{}{
  375. "order_code": order_code,
  376. }
  377. if applyBill_type == "个人" {
  378. applyBill_status = 1
  379. updateBl = public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"applyBill_status": applyBill_status})
  380. } else if applyBill_type == "单位" {
  381. applyBill_status = 1 //状态
  382. applyBill_company = d.GetString("applyBill_company") //公司名
  383. applyBill_taxnum = d.GetString("applyBill_taxnum") //纳税人识别号
  384. updateBl = public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{
  385. "applyBill_company": applyBill_company,
  386. "applyBill_taxnum": applyBill_taxnum,
  387. "applyBill_status": applyBill_status,
  388. "applyBill_type": 1,
  389. }) //修改操作
  390. }
  391. //判断条件
  392. if updateBl {
  393. go func() {
  394. orderdata := public.Mysql.FindOne(tableName_order, map[string]interface{}{
  395. "order_code": order_code,
  396. }, "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", "")
  397. tt := time.Now()
  398. pay_time := util.FormatDate(&tt, util.Date_Full_Layout)
  399. public.SendMailToBJFinance(orderdata, pay_time, "", 2, config.GmailAuth)
  400. }()
  401. }
  402. d.ServeJson(map[string]interface{}{
  403. "flag": updateBl,
  404. })
  405. return nil
  406. }
  407. //---------------------------生成订单预览----------------------------------
  408. func (d *DataExport) SuperSearchExport() error {
  409. openid := util.ObjToString(d.GetSession("s_m_openid"))
  410. userId := util.ObjToString(d.GetSession("userId"))
  411. if userId == "" {
  412. return errors.New("未登录")
  413. }
  414. //接收超级搜索页面参数
  415. keywords := d.GetString("keywords") //搜索词
  416. publishtime := d.GetString("publishtime") //发布时间
  417. area := d.GetString("area") //地区
  418. subtype := d.GetString("subtype") //信息类型
  419. minprice := d.GetString("minprice") //最低价格
  420. maxprice := d.GetString("maxprice") //最高价格
  421. industry := strings.TrimSpace(d.GetString("industry")) //选中的行业
  422. selectType := d.GetString("selectType") //标题 or 全文
  423. //数据回显
  424. d.SetSession("Echo_keywords", keywords)
  425. d.SetSession("Echo_publishtime", publishtime)
  426. d.SetSession("Echo_timeslot", d.GetString("timeslot"))
  427. d.SetSession("Echo_area", area)
  428. d.SetSession("Echo_subtype", subtype)
  429. d.SetSession("Echo_minprice", minprice)
  430. d.SetSession("Echo_maxprice", maxprice)
  431. d.SetSession("Echo_industry", industry)
  432. d.SetSession("Echo_selectType", selectType)
  433. //数据存库转换
  434. areaSave := []string{}
  435. if len(area) > 0 {
  436. areaSave = strings.Split(area, ",")
  437. }
  438. industrySave := []string{}
  439. if len(industry) > 0 {
  440. industrySave = strings.Split(industry, ",")
  441. }
  442. //格式化keywords
  443. KeyWordSave := []public.KeyWord{}
  444. if len(keywords) > 0 {
  445. isIntercept := false
  446. if selectType == "all" {
  447. isIntercept = true
  448. }
  449. _, _, keywords = jy.InterceptSearchKW(keywords, isIntercept, len(industrySave) == 0)
  450. KeyWordSave = append(KeyWordSave, public.KeyWord{Keyword: keywords})
  451. }
  452. //时间
  453. now := time.Now()
  454. if publishtime == "lately-7" { //最近7天
  455. starttime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
  456. publishtime = fmt.Sprintf("%s_%d", starttime, now.Unix())
  457. } else if publishtime == "lately-30" { //最近30天
  458. starttime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
  459. publishtime = fmt.Sprintf("%s_%d", starttime, now.Unix())
  460. } else if publishtime == "thisyear" { //去年
  461. starttime := fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Unix())
  462. endtime := fmt.Sprint(time.Date(now.Year(), 1, 1, 0, 0, 0, 0, time.Local).Unix())
  463. publishtime = fmt.Sprintf("%s_%s", starttime, endtime)
  464. }
  465. data := map[string]interface{}{
  466. "keywords": KeyWordSave,
  467. "publishtime": publishtime,
  468. "area": areaSave,
  469. "subtype": subtype,
  470. "minprice": minprice,
  471. "maxprice": maxprice,
  472. "industry": industrySave,
  473. "selectType": selectType,
  474. "comeintime": now.Unix(),
  475. "s_openid": openid,
  476. "comeinfrom": "supersearchPage",
  477. "s_userid": userId,
  478. }
  479. //存入数据库
  480. _id := mongodb.Save(public.ExportTable, data)
  481. //携带id跳转订单生成页面
  482. d.Redirect("/front/dataExport/toCreateOrderPage/" + util.SE.Encode2Hex(_id))
  483. return nil
  484. }
  485. func (d *DataExport) ToCreateOrderPage(_id string) error {
  486. id := util.SE.Decode4Hex(_id)
  487. openid := util.ObjToString(d.GetSession("s_m_openid"))
  488. userId := util.ObjToString(d.GetSession("userId"))
  489. if userId == "" {
  490. return errors.New("未登录")
  491. }
  492. msgCount := public.GetDataExportSearchCountUseId(id)
  493. if msgCount > public.ExConf.MsgMaxCount {
  494. msgCount = public.ExConf.MsgMaxCount
  495. }
  496. d.T["logid"] = config.Seoconfig["dataexport"].(string)
  497. if msgCount < 1 {
  498. d.Render("/pc/dataExport_noDataErr.html", &d.T)
  499. return nil
  500. }
  501. //订单数据存入session中
  502. d.SetSession("dataexport_waitcreateorder", map[string]interface{}{
  503. "id": id, //用户的筛选条件mongodb中的id string
  504. "data_count": msgCount, //匹配到的数据总数 int
  505. })
  506. //邮箱验证
  507. email := d.GetSession("DataExportVerifyEmail_val")
  508. resPhone := d.GetSession("DataExportVerifyPhone_val")
  509. log.Println(util.Int64All(d.GetSession("CreatEVerifyTime")), "----", time.Now().Unix())
  510. if email != nil {
  511. lastSendDEVerify := util.Int64All(d.GetSession("CreatEVerifyTime"))
  512. timeSpaceing := lastSendDEVerify - time.Now().Unix() + 60*5
  513. d.T["email"] = email
  514. d.T["timeSpaceing"] = timeSpaceing
  515. } else {
  516. mail_phone := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
  517. "user_id": userId,
  518. }, "user_mail,user_phone", "create_time desc")
  519. if mail_phone != nil {
  520. email = (*mail_phone)["user_mail"]
  521. resPhone = (*mail_phone)["user_phone"]
  522. }
  523. if email == nil || email == "" {
  524. userData, _ := mongodb.FindById("user", userId, `{"o_jy":1}`)
  525. o_jy := util.ObjToMap((*userData)["o_jy"])
  526. email = (*o_jy)["s_email"]
  527. }
  528. if email != nil && email != "" {
  529. d.SetSession("EMVerifySucess", true)
  530. d.SetSession("DataExportVerifyEmail_val", email)
  531. }
  532. d.T["email"] = email
  533. }
  534. //手机号
  535. phone := d.GetSession("DataExportVerifyPhone_val")
  536. if phone != nil && phone != "" {
  537. d.T["phone"] = phone
  538. } else {
  539. //剑鱼助手手机号登录
  540. if isPhone(openid) {
  541. phone = openid
  542. } else {
  543. phone = resPhone
  544. }
  545. if phone != nil && phone != "" {
  546. d.SetSession("DataExportVerifyPhone_val", phone)
  547. }
  548. d.T["phone"] = phone
  549. }
  550. d.T["_id"] = _id
  551. d.T["msgCount"] = msgCount
  552. d.T["msgMaxCount"] = public.ExConf.MsgMaxCount
  553. d.T["discount"] = public.ExConf.Discount
  554. d.T["discount10"] = public.ExConf.Discount * 10
  555. d.T["unitPrice_normal"] = public.ExConf.UnitPrice_normal
  556. d.T["unitPrice_senior"] = public.ExConf.UnitPrice_senior
  557. d.T["unitPrice_normal_final"] = (public.ExConf.UnitPrice_normal * 100) * (public.ExConf.Discount * 100) / 10000
  558. d.T["unitPrice_senior_final"] = (public.ExConf.UnitPrice_senior * 100) * (public.ExConf.Discount * 100) / 10000
  559. d.T["orderMinPrice"] = public.ExConf.OrderMinPrice
  560. incurKey := fmt.Sprintf("PreviewData_%s_%d", d.GetSession("userId"), time.Now().Day())
  561. d.T["PreviewData"] = util.IntAll(redis.Get("other", incurKey))
  562. // go func() {
  563. // orderdata := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
  564. // "order_code": "143049462075",
  565. // }, "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", "")
  566. // tt := time.Now()
  567. // pay_time := util.FormatDate(&tt, util.Date_Full_Layout)
  568. // go public.SendMailToBJFinance(orderdata, pay_time, 2, config.GmailAuth)
  569. // }()
  570. d.Render("/pc/createOrderPage.html", &d.T)
  571. return nil
  572. }
  573. func (d *DataExport) PreviewData(source, _id string) error {
  574. if !strings.Contains(source, "app") {
  575. userId := util.ObjToString(d.GetSession("userId"))
  576. // openid := util.ObjToString(d.GetSession("s_m_openid"))
  577. if userId == "" {
  578. return errors.New("未登录")
  579. }
  580. //数据预览每天限制50次
  581. incurKey := fmt.Sprintf("PreviewData_%s_%d", d.GetSession("userId"), time.Now().Day())
  582. times := util.IntAll(redis.Get("other", incurKey))
  583. if times >= 50 {
  584. return errors.New("超出预览次数")
  585. }
  586. if times == 0 {
  587. redis.Put("other", incurKey, 1, 24*60*60)
  588. } else {
  589. redis.Incr("other", incurKey)
  590. }
  591. }
  592. _id = util.SE.Decode4Hex(_id)
  593. dataType := d.GetString("dataType")
  594. //从500条数据中筛选字段最全五条
  595. res := public.GetDataExportSearchResultUseId(_id, dataType, -1)
  596. if res == nil {
  597. d.Render("/pc/dataExport_noDataErr.html", &d.T)
  598. log.Println("PreviewData查询出错")
  599. return nil
  600. }
  601. //格式化字段
  602. res_screen := public.ScreenData(res, dataType, 20)
  603. list := public.FormatExportData(&res_screen, config.Sysconfig["webdomain"].(string), dataType, true)
  604. d.T["data"] = subUrl(list, dataType)
  605. d.T["dataType"] = dataType
  606. d.T["ttf"] = public.GetFontVersion() + "_" + public.PC
  607. d.Render("/pc/previewData.html", &d.T)
  608. return nil
  609. }
  610. /**
  611. 设置ttf版本号
  612. */
  613. func (d *DataExport) FontSet(version string) {
  614. if public.ExConf.Font.Enabled {
  615. if version == "" {
  616. version = public.ExConf.Font.ConvertVersionDefault
  617. }
  618. b := redis.Put(public.ExConf.Font.RedisPool, public.ExConf.Font.RedisKey, version, -1)
  619. if b {
  620. d.RenderString("Congratulations , the font (version " + version + ") set successfully !")
  621. } else {
  622. d.RenderString("Sorry , there is an error , please view the logs !")
  623. }
  624. } else {
  625. d.RenderString("Sorry , permission denied , please contact the administrator !")
  626. }
  627. }
  628. func subUrl(list *[]map[string]interface{}, dataType string) *[]map[string]interface{} {
  629. for _, v := range *list {
  630. //加密截取url
  631. href := util.ObjToString(v["href"])
  632. url := util.ObjToString(v["url"])
  633. if len(url) > 40 { //截取剑鱼标讯地址
  634. v["url"] = url[:40] + "*****" + url[len(url)-10:]
  635. }
  636. if len(href) > 40 { //截取原文地址
  637. v["href"] = href[:40] + "*****" + href[len(href)-10:]
  638. } else if len(href) > 0 {
  639. v["href"] = href[:len(href)*8/10] + "*****"
  640. }
  641. }
  642. var result []map[string]interface{}
  643. bytes, marshalErr := json.Marshal(list)
  644. if marshalErr != nil {
  645. log.Println("数据导出字体混淆errMarshal", marshalErr)
  646. return list
  647. }
  648. //字体混淆
  649. hxb := public.GetFontConvertStr(public.ExConf.Font.ConvertVersionDefault, string(bytes), "pc")
  650. unmarshalErr := json.Unmarshal([]byte(hxb), &result)
  651. if unmarshalErr != nil {
  652. log.Println("数据导出字体混淆unmarshalErr", unmarshalErr)
  653. return list
  654. }
  655. return &result
  656. }
  657. //发送邮件
  658. func (d *DataExport) SendMailVerify() {
  659. email := d.GetString("email")
  660. if isEmail(email) {
  661. var email_used = true
  662. if email != d.GetSession("DataExportVerifyEmail") {
  663. d.DelSession("CreatEVerifyTime")
  664. // openid := util.ObjToString(d.GetSession("s_m_openid"))
  665. userId := util.ObjToString(d.GetSession("userId"))
  666. emails := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
  667. "user_mail": email,
  668. "user_id": userId,
  669. }, "user_mail", "")
  670. if emails != nil && util.ObjToString((*emails)["user_mail"]) != "" {
  671. email_used = false
  672. d.T["success"] = true
  673. d.T["errCode"] = 4
  674. d.T["errMsg"] = "此邮箱已被验证"
  675. d.SetSession("DataExportVerifyEmail_val", email)
  676. d.SetSession("EMVerifySucess", true)
  677. }
  678. }
  679. if email_used {
  680. lastSendDEVerify := util.Int64All(d.GetSession("CreatEVerifyTime"))
  681. log.Println(util.Int64All(d.GetSession("CreatEVerifyTime")), "----", time.Now().Unix())
  682. timeSpaceing := lastSendDEVerify - time.Now().Unix() + 60*5
  683. log.Println("--------:", timeSpaceing)
  684. incurKey := fmt.Sprintf("SendEmail_%s_%d", d.GetSession("userId"), time.Now().Day())
  685. //log.Println(incurKey)
  686. if lastSendDEVerify == 0 || timeSpaceing < 0 {
  687. //每日限制10次
  688. times := util.IntAll(redis.Get("other", incurKey))
  689. if times < 10 {
  690. if times == 0 {
  691. redis.Put("other", incurKey, 1, 24*60*60)
  692. } else {
  693. redis.Incr("other", incurKey)
  694. }
  695. //生成随机数
  696. verifyStr := strings.ToUpper(util.GetComplexRandom(6, 3, 3))
  697. d.SetSession("EMVerifySucess", false)
  698. d.SetSession("DataExportVerifyEmail", email)
  699. d.SetSession("DataExportVerify", verifyStr)
  700. d.SetSession("CreatEVerifyTime", time.Now().Unix())
  701. log.Println("====================", verifyStr, "====================", d.GetSession("CreatEVerifyTime"), "====================")
  702. //发送邮箱验证码
  703. go public.SendMailIdentCode(email, verifyStr, config.GmailAuth)
  704. d.T["success"] = true
  705. } else {
  706. d.T["success"] = false
  707. d.T["errCode"] = 3
  708. d.T["time"] = timeSpaceing
  709. d.T["errMsg"] = "验证码发送次数已达到今日上限"
  710. }
  711. } else {
  712. d.T["success"] = false
  713. d.T["errCode"] = 2
  714. d.T["time"] = timeSpaceing
  715. d.T["errMsg"] = "已发送,5分钟后再尝试"
  716. }
  717. }
  718. } else {
  719. d.T["success"] = false
  720. d.T["errCode"] = 1
  721. d.T["errMsg"] = "邮箱格式不正确"
  722. }
  723. d.ServeJson(&d.T)
  724. }
  725. func isPhone(value string) bool {
  726. var phonePattern = regexp.MustCompile("^[1][3-9][0-9]{9}$")
  727. return phonePattern.MatchString(value)
  728. }
  729. //验证手机号
  730. func (d *DataExport) CheckPhoneVerify() {
  731. phone := d.GetString("phone")
  732. verityResult := false
  733. if isPhone(phone) {
  734. verityResult = true
  735. d.SetSession("DataExportVerifyPhone", phone)
  736. }
  737. d.T["success"] = verityResult
  738. d.ServeJson(&d.T)
  739. }
  740. //验证邮箱
  741. func (d *DataExport) CheckMailVerify() {
  742. email := d.GetString("email")
  743. emailVerity := d.GetString("emailVerity")
  744. DataExportEmail := d.GetSession("DataExportVerifyEmail")
  745. DataExportVerify := d.GetSession("DataExportVerify")
  746. verityResult := false
  747. if emailVerity != "" && emailVerity == DataExportVerify && email != "" && email == DataExportEmail {
  748. verityResult = true
  749. d.DelSession("DataExportVerify")
  750. d.DelSession("CreatEVerifyTime")
  751. d.SetSession("EMVerifySucess", true)
  752. d.SetSession("DataExportVerifyEmail_val", DataExportEmail)
  753. }
  754. d.T["success"] = verityResult
  755. d.ServeJson(&d.T)
  756. }
  757. func isEmail(value string) bool {
  758. 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})(\\]?)$")
  759. return emailPattern.MatchString(value)
  760. }
  761. func (d *DataExport) Paysuccess() error {
  762. code := d.GetString("code")
  763. // openid, _ := d.GetSession("s_m_openid").(string)
  764. userId, _ := d.GetSession("userId").(string)
  765. data := map[string]interface{}{}
  766. if code != "" && userId != "" {
  767. data_ := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
  768. "order_code": code,
  769. "user_id": userId,
  770. "order_status": 1,
  771. }, "pay_way,user_mail,pay_time,pay_money,order_money", "")
  772. if data_ != nil {
  773. data = *data_
  774. if data["pay_money"] != nil {
  775. data["pay_money"] = util.Float64All(data["pay_money"]) / 100
  776. } else {
  777. data["pay_money"] = util.Float64All(data["order_money"]) / 100
  778. }
  779. if data["pay_way"] != nil {
  780. pay_way := util.ObjToString(data["pay_way"])
  781. if strings.Contains(pay_way, "wx") {
  782. pay_way = "微信"
  783. } else if strings.Contains(pay_way, "ali") {
  784. pay_way = "支付宝"
  785. }
  786. data["pay_way"] = pay_way
  787. }
  788. }
  789. }
  790. d.T["data"] = data
  791. d.T["order_code"] = code
  792. return d.Render("/pc/paysuccess.html")
  793. }