second_push.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. package service
  2. import (
  3. "encoding/json"
  4. "history"
  5. "log"
  6. "os"
  7. mongoutil "qfw/mongodb"
  8. qu "qfw/util"
  9. "qfw/util/mail"
  10. "strconv"
  11. "strings"
  12. "time"
  13. . "util"
  14. "github.com/tealeg/xlsx"
  15. "github.com/go-xweb/xweb"
  16. "gopkg.in/mgo.v2/bson"
  17. )
  18. var (
  19. xlsxArr []map[string]interface{}
  20. SE = qu.SimpleEncrypt{Key: "topJYBX2019"}
  21. )
  22. type SecondPush struct {
  23. *xweb.Action
  24. secondPush xweb.Mapper `xweb:"/service/secondpush/create"`
  25. getUserRule xweb.Mapper `xweb:"/service/secondpush/getrules"`
  26. saveSpushRule xweb.Mapper `xweb:"/service/secondpush/saverule"`
  27. secondPushTask xweb.Mapper `xweb:"/service/secondpush/dotask"`
  28. addSecondPushRule xweb.Mapper `xweb:"/service/secondpush/add"` //保存二次推送规则
  29. secondPushList xweb.Mapper `xweb:"/service/secondpush/list"`
  30. secondPushClone xweb.Mapper `xweb:"/service/secondPushClone/(.*)"`
  31. delSecondPushRule xweb.Mapper `xweb:"/service/customer/secondpush/delrule"` //删除历史任务规则
  32. }
  33. func (s *SecondPush) SecondPush() {
  34. defer qu.Catch()
  35. id := s.GetString("id")
  36. user := s.GetSession("user").(map[string]interface{})
  37. query := bson.M{}
  38. query["_id"] = mongoutil.StringTOBsonId(id)
  39. s_pushid := s.GetString("s_pushid")
  40. secondpush_id := ""
  41. if s_pushid != "" {
  42. secondpush_id = s_pushid
  43. hData, ok := Mgo.FindOne("second_push", bson.M{"_id": mongoutil.StringTOBsonId(secondpush_id)})
  44. if ok && hData != nil && len(*hData) > 0 {
  45. s.T["spush_rule"] = (*hData)["dep_rules"]
  46. (*hData)["_id"] = id
  47. s.T["data"] = *hData
  48. }
  49. } else {
  50. var user_name, user_customername, appid = "", "", ""
  51. userInfo, ok := Mgo.FindOne("euser", query)
  52. if ok && userInfo != nil && *userInfo != nil {
  53. user_name = qu.ObjToString((*userInfo)["s_name"])
  54. user_customername = qu.ObjToString((*userInfo)["s_customername"])
  55. appid = qu.ObjToString((*userInfo)["s_appid"])
  56. }
  57. secondpush_id = Mgo.Save("second_push", map[string]interface{}{
  58. "createtime": time.Now().Unix(),
  59. "updatetime": time.Now().Unix(),
  60. "user_id": id,
  61. "create_user": user["name"],
  62. "state": 0,
  63. "s_name": user_name,
  64. "s_customername": user_customername,
  65. "s_appid": appid,
  66. })
  67. s.Redirect("/service/secondpush/create?id=" + id + "&s_pushid=" + secondpush_id)
  68. return
  69. }
  70. s.T["spush_id"] = secondpush_id
  71. s.Render("private/second_push_create.html", &s.T)
  72. }
  73. func (s *SecondPush) GetUserRule() {
  74. customerId := s.GetString("c_id")
  75. query := bson.M{
  76. "s_userid": customerId,
  77. "b_delete": false,
  78. }
  79. data, _ := Mgo.Find("euserdepart", query, `{"i_createtime":-1}`, nil, false, 0, 0)
  80. if data != nil && len(*data) != 0 {
  81. res := []map[string]interface{}{}
  82. for _, m := range *data {
  83. history_rule_data := make(map[string]interface{})
  84. q := bson.M{
  85. "s_departid": mongoutil.BsonIdToSId(m["_id"]),
  86. "b_delete": false,
  87. }
  88. history_rule_data["department_isuse"] = m["i_isuse"]
  89. history_rule_data["depart_name"] = m["s_name"]
  90. depart_rule_data, _ := Mgo.Find("euserdepartrule", q, `{"i_createtime":-1}`, `{"s_name":1,"i_updatetime":1,"i_isuse":1,"_id":1}`, false, 0, 0)
  91. if depart_rule_data != nil && len(*depart_rule_data) != 0 {
  92. for _, j := range *depart_rule_data {
  93. j["_id"] = mongoutil.BsonIdToSId(j["_id"])
  94. }
  95. history_rule_data["department_rule"] = depart_rule_data
  96. history_rule_data["is_slected"] = true
  97. }
  98. res = append(res, history_rule_data)
  99. }
  100. s.ServeJson(map[string]interface{}{
  101. "status": "success",
  102. "data": res,
  103. })
  104. } else {
  105. s.ServeJson(map[string]interface{}{
  106. "status": "fail",
  107. "data": "",
  108. })
  109. }
  110. }
  111. //保存二次推送规则
  112. func (s *SecondPush) SaveSpushRule() {
  113. rules_id := s.GetString("rulesid")
  114. s_pushid := s.GetString("s_pushid")
  115. // userid := s.GetString("userid")
  116. if s_pushid != "" {
  117. user_history, _ := Mgo.FindOne("second_push", map[string]interface{}{
  118. "_id": mongoutil.StringTOBsonId(s_pushid),
  119. })
  120. if *user_history != nil && user_history != nil {
  121. if (*user_history)["dep_rules"] != nil {
  122. dep_rules := qu.ObjArrToMapArr((*user_history)["dep_rules"].([]interface{}))
  123. dep_new_rules := []map[string]interface{}{}
  124. ruleMap := map[string]bool{}
  125. if len(dep_rules) > 0 {
  126. for _, r := range dep_rules {
  127. dep_new_rules = append(dep_new_rules, r)
  128. ruleMap[mongoutil.BsonIdToSId(r["_id"])] = true
  129. }
  130. }
  131. rules_id_list := strings.Split(rules_id, ",")
  132. for _, rule := range rules_id_list {
  133. if !ruleMap[rule] {
  134. query := bson.M{
  135. "_id": mongoutil.StringTOBsonId(rule),
  136. "b_delete": false,
  137. }
  138. res, _ := Mgo.FindOne("euserdepartrule", query)
  139. if res != nil && len(*res) != 0 {
  140. //获取规则所属部门信息
  141. department_info, _ := Mgo.FindOne("euserdepart", map[string]interface{}{
  142. "_id": mongoutil.StringTOBsonId((*res)["s_departid"].(string)),
  143. "b_delete": false,
  144. })
  145. (*res)["is_new"] = false
  146. (*res)["s_depart_name"] = (*department_info)["s_name"]
  147. dep_new_rules = append(dep_new_rules, *res)
  148. }
  149. }
  150. }
  151. set := bson.M{
  152. "$set": bson.M{
  153. "dep_rules": dep_new_rules,
  154. // "tag_rules": usertags,
  155. "updatetime": time.Now().Unix(),
  156. },
  157. }
  158. ok := Mgo.Update("second_push", map[string]interface{}{
  159. "_id": mongoutil.StringTOBsonId(s_pushid),
  160. }, set, false, false)
  161. s.ServeJson(map[string]interface{}{
  162. "status": ok,
  163. })
  164. return
  165. } else {
  166. rules_id_list := strings.Split(rules_id, ",")
  167. dep_rules := []map[string]interface{}{}
  168. for _, rule := range rules_id_list {
  169. query := bson.M{
  170. "_id": mongoutil.StringTOBsonId(rule),
  171. "b_delete": false,
  172. }
  173. res, _ := Mgo.FindOne("euserdepartrule", query)
  174. if res != nil && *res != nil {
  175. //获取规则所属部门信息
  176. department_info, _ := Mgo.FindOne("euserdepart", map[string]interface{}{
  177. "_id": mongoutil.StringTOBsonId((*res)["s_departid"].(string)),
  178. "b_delete": false,
  179. })
  180. (*res)["is_new"] = false
  181. (*res)["s_depart_name"] = (*department_info)["s_name"]
  182. dep_rules = append(dep_rules, *res)
  183. }
  184. }
  185. set := bson.M{
  186. "$set": bson.M{
  187. "dep_rules": dep_rules,
  188. // "tag_rules": usertags,
  189. "updatetime": time.Now().Unix(),
  190. },
  191. }
  192. isupdata := Mgo.Update("second_push", map[string]interface{}{
  193. "_id": mongoutil.StringTOBsonId(s_pushid),
  194. }, set, false, false)
  195. s.ServeJson(map[string]interface{}{
  196. "status": isupdata,
  197. })
  198. return
  199. }
  200. }
  201. s.ServeJson(map[string]interface{}{
  202. "status": "fail",
  203. })
  204. }
  205. }
  206. func (s *SecondPush) SecondPushTask() {
  207. log.Println("开始二次推送任务...")
  208. s_pushid := s.GetString("s_pushid")
  209. if s_pushid != "" {
  210. customer, _ := Mgo.Find("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(s_pushid)}, nil, nil, false, -1, -1)
  211. if len(*customer) == 1 {
  212. c := (*customer)[0]
  213. customer_name := qu.ObjToString(c["s_name"]) //客户名称
  214. email := qu.ObjToString(c["sendMail"])
  215. starttime := qu.Int64All(c["starttime"])
  216. endtime := qu.Int64All(c["endtime"])
  217. if len(c) != 0 && c != nil {
  218. if c["dep_rules"] != nil && len(c["dep_rules"].([]interface{})) != 0 {
  219. for _, m := range c["dep_rules"].([]interface{}) {
  220. log.Println("ruleid", mongoutil.BsonIdToSId(m.(map[string]interface{})["_id"]))
  221. q := bson.M{
  222. "ruleid": mongoutil.BsonIdToSId(m.(map[string]interface{})["_id"]),
  223. "bget": 1,
  224. "createtime": bson.M{
  225. "$gte": starttime,
  226. "$lte": endtime,
  227. },
  228. }
  229. d, _ := MgoCus.Find("usermail", q, nil, nil, false, 0, 0)
  230. if len(*d) > 0 && d != nil {
  231. for _, l := range *d {
  232. xlsxArr = append(xlsxArr, l)
  233. }
  234. }
  235. }
  236. } else {
  237. q := bson.M{
  238. "appid": c["s_appid"],
  239. "bget": 1,
  240. "createtime": bson.M{
  241. "$gte": starttime,
  242. "$lte": endtime,
  243. },
  244. }
  245. d, _ := MgoCus.Find("usermail", q, nil, nil, false, 0, 0)
  246. for _, l := range *d {
  247. xlsxArr = append(xlsxArr, l)
  248. }
  249. }
  250. if len(xlsxArr) == 0 {
  251. log.Println("查询数据为空")
  252. } else {
  253. log.Println(len(xlsxArr))
  254. GetXlsxs(xlsxArr, customer_name, email, s_pushid)
  255. go UpdateHistoryState(2, s_pushid, len(xlsxArr))
  256. s.ServeJson(map[string]interface{}{
  257. "status": true,
  258. })
  259. xlsxArr = []map[string]interface{}{}
  260. }
  261. }
  262. } else {
  263. log.Println("初始化客户信息失败")
  264. }
  265. }
  266. }
  267. //func (s *SecondPush) HistoryList() {
  268. // id := s.GetString("id")
  269. // if s.Method() == "POST" {
  270. // data, _ := Mgo.Find("second_push", map[string]interface{}{"user_id": id}, `{"updatetime":-1}`, nil, false, -1, -1)
  271. // s.ServeJson(map[string]interface{}{
  272. // "data": data,
  273. // })
  274. // } else {
  275. // s.T["id"] = id
  276. // s.Render("private/historylog_list.html", &s.T)
  277. // }
  278. //}
  279. func UpdateHistoryState(state int, s_pushid string, count int) {
  280. if state == 2 {
  281. Mgo.Update("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(s_pushid)}, map[string]interface{}{
  282. "$set": map[string]interface{}{
  283. "state": state,
  284. "result_count": count,
  285. "finishtime": time.Now().Unix(),
  286. },
  287. }, false, false)
  288. return
  289. }
  290. Mgo.Update("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(s_pushid)}, map[string]interface{}{
  291. "$set": map[string]interface{}{
  292. "state": state,
  293. },
  294. }, false, false)
  295. }
  296. func (s *SecondPush) HistoryClone(hid string) {
  297. data, ok := Mgo.FindOne("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(hid)})
  298. if ok && data != nil && *data != nil {
  299. (*data)["state"] = 0
  300. (*data)["result_count"] = nil
  301. (*data)["createtime"] = time.Now().Unix()
  302. (*data)["updatetime"] = time.Now().Unix()
  303. Mgo.Save("second_push", *data)
  304. }
  305. }
  306. func (s *SecondPush) HistoryRuleEdit() {
  307. hid := s.GetString("hid")
  308. rid := s.GetString("rid")
  309. if s.Method() == "POST" {
  310. data := GetPostForm(s.Request)
  311. o_rules := []map[string]interface{}{}
  312. o_rulesStr := data["o_rules"].(string)
  313. json.Unmarshal([]byte(o_rulesStr), &o_rules)
  314. data["o_rules"] = o_rules
  315. data["_id"] = mongoutil.StringTOBsonId(rid)
  316. if qu.IntAll(data["i_esquerytype"]) == 1 { //自动生成es
  317. data["s_esquery"] = Utiltags(data)
  318. }
  319. datas, ok := Mgo.FindOne("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(hid)})
  320. if ok && datas != nil && *datas != nil {
  321. dep_rules := qu.ObjArrToMapArr((*datas)["dep_rules"].([]interface{}))
  322. for k, v := range dep_rules {
  323. if rid == mongoutil.BsonIdToSId(v["_id"]) {
  324. dep_rules[k] = data
  325. }
  326. }
  327. rep := Mgo.Update("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(hid)}, map[string]interface{}{"$set": map[string]interface{}{"dep_rules": dep_rules}}, false, false)
  328. s.ServeJson(map[string]interface{}{
  329. "rep": rep,
  330. "s_esquery": data["s_esquery"],
  331. })
  332. }
  333. } else {
  334. id := s.GetString("id")
  335. data, ok := Mgo.FindOne("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(hid)})
  336. if ok && data != nil && *data != nil {
  337. dep_rules := qu.ObjArrToMapArr((*data)["dep_rules"].([]interface{}))
  338. for _, v := range dep_rules {
  339. if rid == mongoutil.BsonIdToSId(v["_id"]) {
  340. s.T["data"] = v
  341. }
  342. }
  343. }
  344. s.T["did"] = id //部门id
  345. s.T["cid"] = id //客户id
  346. s.T["ids"] = id
  347. s.T["history_id"] = hid
  348. s.T["rid"] = rid
  349. s.T["province"] = Province
  350. s.T["city"] = ProvinceCitys
  351. s.T["district"] = CityDistricts
  352. s.T["topTypeArr"] = TopTypeArr
  353. s.T["subTypeArr"] = SubTypeArr
  354. s.T["matchTypeMap"] = MatchTypeMap
  355. s.T["matchTypeMap2"] = MatchTypeMap2
  356. s.T["existField"] = ExistFiled
  357. s.T["buyerClass"] = BuyerClass
  358. s.T["scopeClass"] = ScopeClassMap
  359. s.Render("private/history_rule_edit.html", &s.T)
  360. }
  361. }
  362. func GetXlsxs(mMap []map[string]interface{}, fn, email, id string) {
  363. if id != "" {
  364. query := bson.M{
  365. "_id": bson.ObjectIdHex(id),
  366. }
  367. data, ok := Mgo.FindOne("second_push", query)
  368. if ok && (*data) != nil && len(*data) > 0 {
  369. dataType := qu.IntAll((*data)["i_extfieldstype"])
  370. xf, err := xlsx.OpenFile("web/res/fields.xlsx")
  371. if err != nil {
  372. log.Println("fields file not foud", err.Error())
  373. }
  374. if dataType == 1 {
  375. sh := xf.Sheets[0]
  376. for i, v := range mMap {
  377. row := sh.AddRow()
  378. row.AddCell().SetInt(i + 1)
  379. row.AddCell().SetValue(v["matchkey"])
  380. row.AddCell().SetValue(v["area"])
  381. row.AddCell().SetValue(v["city"])
  382. row.AddCell().SetValue(v["title"])
  383. row.AddCell().SetValue(v["subtype"])
  384. if v["publishtime"] != nil {
  385. row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02"))
  386. } else {
  387. row.AddCell()
  388. }
  389. row.AddCell().SetValue(v["buyer"])
  390. row.AddCell().SetValue(v["s_winner"])
  391. if v["bidamount"] != nil {
  392. row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
  393. } else {
  394. row.AddCell()
  395. }
  396. row.AddCell().SetValue(v["projectname"])
  397. row.AddCell().SetValue(v["detail"])
  398. row.AddCell().SetValue(v["jybxhref"])
  399. ids := SE.EncodeString(qu.ObjToString(v["id"]))
  400. row.AddCell().SetValue(ids)
  401. }
  402. xf.Sheets = xf.Sheets[0:1]
  403. } else if dataType == 2 {
  404. sh := xf.Sheets[1]
  405. for _, v := range mMap {
  406. row := sh.AddRow()
  407. // row.AddCell().SetInt(i + 1)
  408. row.AddCell().SetValue(v["matchkey"])
  409. row.AddCell().SetValue(v["area"])
  410. row.AddCell().SetValue(v["city"])
  411. row.AddCell().SetValue(v["title"])
  412. row.AddCell().SetValue(v["subtype"])
  413. row.AddCell().SetValue(v["detail"])
  414. if v["publishtime"] != nil {
  415. row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02"))
  416. } else {
  417. row.AddCell()
  418. }
  419. row.AddCell().SetValue(v["href"])
  420. row.AddCell().SetValue(v["jybxhref"])
  421. row.AddCell().SetValue(v["projectname"])
  422. row.AddCell().SetValue(v["projectcode"])
  423. row.AddCell().SetValue(v["projectscope"])
  424. if v["budget"] != nil {
  425. row.AddCell().SetFloat(qu.Float64All(v["budget"]))
  426. } else {
  427. row.AddCell()
  428. }
  429. if v["bidamount"] != nil {
  430. row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
  431. } else {
  432. row.AddCell()
  433. }
  434. if v["bidopentime"] != nil {
  435. row.AddCell().SetValue(time.Unix(qu.Int64All(v["bidopentime"]), 0).Format("2006-01-02"))
  436. } else {
  437. row.AddCell()
  438. }
  439. row.AddCell().SetValue(v["buyer"])
  440. row.AddCell().SetValue(v["buyerperson"])
  441. row.AddCell().SetValue(v["buyertel"])
  442. row.AddCell().SetValue(v["agency"])
  443. row.AddCell().SetValue(v["s_winner"])
  444. row.AddCell().SetValue(v["winnerperson"])
  445. row.AddCell().SetValue(v["winnertel"])
  446. row.AddCell().SetValue(v["legal_person"])
  447. row.AddCell().SetValue(v["company_phone"])
  448. row.AddCell().SetValue(v["company_email"])
  449. ids := SE.EncodeString(qu.ObjToString(v["id"]))
  450. row.AddCell().SetValue(ids)
  451. }
  452. xf.Sheets = xf.Sheets[1:2]
  453. } else if dataType == 3 {
  454. sh := xf.Sheets[2]
  455. for _, v := range mMap {
  456. row := sh.AddRow()
  457. // row.AddCell().SetInt(i + 1)
  458. row.AddCell().SetValue(v["departname"])
  459. row.AddCell().SetValue(v["rulename"])
  460. row.AddCell().SetValue(v["matchkey"])
  461. row.AddCell().SetValue(v["area"])
  462. row.AddCell().SetValue(v["city"])
  463. row.AddCell().SetValue(v["district"])
  464. row.AddCell().SetValue(v["title"])
  465. row.AddCell().SetValue(v["detail"])
  466. if v["publishtime"] != nil {
  467. row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02"))
  468. } else {
  469. row.AddCell()
  470. }
  471. row.AddCell().SetValue(v["href"])
  472. if v["bidamount"] != nil {
  473. row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
  474. } else {
  475. row.AddCell()
  476. }
  477. row.AddCell().SetValue(v["buyer"])
  478. row.AddCell().SetValue(v["buyerclass"])
  479. row.AddCell().SetValue(v["buyerperson"])
  480. row.AddCell().SetValue(v["buyertel"])
  481. row.AddCell().SetValue(v["s_winner"])
  482. row.AddCell().SetValue(v["legal_person"])
  483. row.AddCell().SetValue(v["company_phone"])
  484. row.AddCell().SetValue(v["company_address"])
  485. row.AddCell().SetValue(v["rank"])
  486. row.AddCell().SetValue(v["purchasing"])
  487. row.AddCell().SetValue(v["capital"])
  488. row.AddCell().SetValue(v["establish_date"])
  489. row.AddCell().SetValue(v["business_scope"])
  490. row.AddCell().SetValue(v["stock_name"])
  491. row.AddCell().SetValue(v["buyer_credit_no"])
  492. row.AddCell().SetValue(v["winner_credit_no"])
  493. ids := SE.EncodeString(qu.ObjToString(v["id"]))
  494. row.AddCell().SetValue(ids)
  495. }
  496. xf.Sheets = xf.Sheets[2:3]
  497. } else if dataType == 4 {
  498. sh := xf.Sheets[3]
  499. for _, v := range mMap {
  500. row := sh.AddRow()
  501. // row.AddCell().SetInt(i + 1)
  502. row.AddCell().SetValue(v["departname"])
  503. row.AddCell().SetValue(v["rulename"])
  504. row.AddCell().SetValue(v["matchkey"])
  505. row.AddCell().SetValue(v["area"])
  506. row.AddCell().SetValue(v["city"])
  507. row.AddCell().SetValue(v["title"])
  508. row.AddCell().SetValue(v["subtype"])
  509. row.AddCell().SetValue(v["detail"])
  510. if v["publishtime"] != nil {
  511. row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02"))
  512. } else {
  513. row.AddCell()
  514. }
  515. row.AddCell().SetValue(v["href"])
  516. row.AddCell().SetValue(v["jybxhref"])
  517. row.AddCell().SetValue(v["projectname"])
  518. row.AddCell().SetValue(v["projectcode"])
  519. row.AddCell().SetValue(v["projectscope"])
  520. if v["budget"] != nil {
  521. row.AddCell().SetFloat(qu.Float64All(v["budget"]))
  522. } else {
  523. row.AddCell()
  524. }
  525. if v["bidamount"] != nil {
  526. row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
  527. } else {
  528. row.AddCell()
  529. }
  530. if v["bidopentime"] != nil {
  531. row.AddCell().SetValue(time.Unix(qu.Int64All(v["bidopentime"]), 0).Format("2006-01-02"))
  532. } else {
  533. row.AddCell()
  534. }
  535. row.AddCell().SetValue(v["buyer"])
  536. row.AddCell().SetValue(v["buyerperson"])
  537. row.AddCell().SetValue(v["buyertel"])
  538. row.AddCell().SetValue(v["agency"])
  539. row.AddCell().SetValue(v["s_winner"])
  540. row.AddCell().SetValue(v["winnerperson"])
  541. row.AddCell().SetValue(v["winnertel"])
  542. row.AddCell().SetValue(v["legal_person"])
  543. row.AddCell().SetValue(v["company_phone"])
  544. row.AddCell().SetValue(v["company_email"])
  545. ids := SE.EncodeString(qu.ObjToString(v["id"]))
  546. row.AddCell().SetValue(ids)
  547. }
  548. xf.Sheets = xf.Sheets[3:4]
  549. }
  550. xf.Sheets[0].Name = "详细数据"
  551. //生文件
  552. t := strconv.FormatInt(time.Now().Unix(), 10)
  553. dir := "./web/res/xlsx/" + t + "/"
  554. if b, _ := history.PathExists(dir); !b {
  555. err1 := os.MkdirAll(dir, os.ModePerm)
  556. if err1 != nil {
  557. log.Println("mkdir err", dir)
  558. }
  559. }
  560. fname := t + ".xlsx"
  561. err = xf.Save(dir + fname)
  562. if err != nil {
  563. log.Println("xls error", fname)
  564. } else {
  565. for i := 0; i < len(history.Gmails); i++ {
  566. gmail := history.Gmails[i]
  567. status := mail.GSendMail_q("剑鱼标讯", email, "", "", fn, "", dir+fname, fname, gmail)
  568. if status {
  569. log.Println("send mail success", fname, email)
  570. break
  571. }
  572. }
  573. }
  574. }
  575. }
  576. }
  577. func (s *SecondPush) AddSecondPushRule() {
  578. defer qu.Catch()
  579. if s.Method() == "POST" {
  580. his_id := s.GetString("s_pushid")
  581. if his_id != "" {
  582. i_updatetime, _ := strconv.ParseInt(s.GetString("i_updatetime"), 10, 64)
  583. i_extfieldstype, _ := strconv.Atoi(s.GetString("i_extfieldstype"))
  584. set := bson.M{
  585. "$set": bson.M{
  586. "i_updatetime": i_updatetime,
  587. "sendMail": s.GetString("sendMail"),
  588. "i_extfieldstype": i_extfieldstype,
  589. "starttime": s.GetString("starttime"),
  590. "endtime": s.GetString("endtime"),
  591. },
  592. }
  593. isupdata := Mgo.UpdateById("second_push", mongoutil.StringTOBsonId(his_id), set)
  594. if isupdata {
  595. s.ServeJson(map[string]interface{}{
  596. "history_id": his_id,
  597. "rep": true,
  598. })
  599. } else {
  600. s.ServeJson(map[string]interface{}{
  601. "history_id": "",
  602. "rep": false,
  603. })
  604. }
  605. }
  606. }
  607. }
  608. func (s *SecondPush) SecondPushList() {
  609. id := s.GetString("id")
  610. if s.Method() == "POST" {
  611. data, _ := Mgo.Find("second_push", map[string]interface{}{"user_id": id}, `{"updatetime":-1}`, nil, false, -1, -1)
  612. s.ServeJson(map[string]interface{}{
  613. "data": data,
  614. })
  615. }
  616. }
  617. func (s *SecondPush) SecondPushClone(hid string) {
  618. data, ok := Mgo.FindOne("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(hid)})
  619. user := s.GetSession("user").(map[string]interface{})
  620. if ok && data != nil && *data != nil {
  621. (*data)["state"] = 0
  622. (*data)["result_count"] = nil
  623. (*data)["createtime"] = time.Now().Unix()
  624. (*data)["updatetime"] = time.Now().Unix()
  625. (*data)["create_user"] = user["name"]
  626. delete((*data), "finishtime")
  627. Mgo.Save("second_push", *data)
  628. }
  629. }
  630. func (s *SecondPush) DelSecondPushRule() {
  631. id := s.GetString("id")
  632. hid := s.GetString("s_pushid")
  633. if hid != "" {
  634. data, ok := Mgo.FindOne("second_push", bson.M{"_id": mongoutil.StringTOBsonId(hid)})
  635. if ok && data != nil && *data != nil {
  636. if (*data)["dep_rules"] != nil {
  637. dep_rules := qu.ObjArrToMapArr((*data)["dep_rules"].([]interface{}))
  638. ruleMap := map[string]bool{id: true}
  639. ruleArr := []map[string]interface{}{}
  640. for _, m := range dep_rules {
  641. if !ruleMap[mongoutil.BsonIdToSId(m["_id"])] {
  642. ruleArr = append(ruleArr, m)
  643. }
  644. }
  645. ok := Mgo.Update("second_push", bson.M{"_id": mongoutil.StringTOBsonId(hid)}, bson.M{"$set": bson.M{"dep_rules": ruleArr}}, false, false)
  646. s.ServeJson(map[string]interface{}{
  647. "success": ok,
  648. })
  649. }
  650. }
  651. }
  652. }