IndexController.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace app\test\controller;
  3. use QL\QueryList;
  4. use think\Db;
  5. use cmf\controller\HomeBaseController;
  6. class IndexController extends HomeBaseController
  7. {
  8. public function index()
  9. {
  10. header("Content-type: application/vnd.ms-excel");
  11. header("Content-Disposition: attachment;Filename=报表.xls");
  12. $data = Db::table('recruit_entry')->where('rid', 6)->select()->toArray();
  13. $posts = Db::table('recruit_post')->column('code,name', 'id');
  14. $recruits = Db::table('recruit')->column('name', 'id');
  15. $families_data = Db::table('recruit_family')->select()->toArray();
  16. $families = [];
  17. foreach ($families_data as $v) {
  18. if (empty($families[$v['eid']])) {
  19. $families[$v['eid']] = '';
  20. }
  21. if (!empty($v['appellation'])) {
  22. $families[$v['eid']] .= $v['appellation'] . '-' . $v['realname'] . '-' . date('Y-m-d', $v['birthday']) . '-' . $v['political_attitudes'] . '-' . $v['work'] . ';';
  23. }
  24. }
  25. foreach ($data as &$v) {
  26. $v['post_code'] = $posts[$v['post_id']]['code'];
  27. $v['post_name'] = $posts[$v['post_id']]['name'];
  28. $v['recruits_name'] = $recruits[$v['rid']];
  29. $v['family'] = empty($families[$v['id']]) ? '' : $families[$v['id']];
  30. $v['birthday'] = empty($v['birthday']) ? '' : date('Y-m-d', $v['birthday']);
  31. $v['status_text'] = $v['status'] == 1 ? '审核中或报名成功' : '暂存或审核失败';
  32. $v['word_url'] = empty($v['word_url']) ? '' : 'http://www.jucai.gov.cn' . $v['word_url'];
  33. $v['front_card'] = $this->_dealImage($v['front_card']);
  34. $v['back_card'] = $this->_dealImage($v['back_card']);
  35. $v['diploma_img'] = $this->_dealImage($v['diploma_img']);
  36. $v['degree_img'] = $this->_dealImage($v['degree_img']);
  37. $v['xuexin_img'] = $this->_dealImage($v['xuexin_img']);
  38. $v['work_pro_img'] = $this->_dealImage($v['work_pro_img']);
  39. $v['work_approve'] = $this->_dealImage($v['work_approve']);
  40. unset($v);
  41. }
  42. $this->assign('data', $data);
  43. return $this->fetch();
  44. }
  45. private function _dealImage($image)
  46. {
  47. $arr = explode(',', $image);
  48. $res = [];
  49. foreach ($arr as $v) {
  50. if (strpos($v, 'blob:') === false) {
  51. $res[] = $v;
  52. }
  53. }
  54. if (empty($res)) {
  55. return '';
  56. } else {
  57. return implode('<br/><br/>', $res);
  58. }
  59. }
  60. public function t1()
  61. {
  62. $table = QueryList::get('http://rcyz.qxrc.com/index.php?g=portal&m=index&a=site_list')->find('table');
  63. // 采集表的每行内容
  64. $tableRows = $table->find('tr:gt(0)')->map(function ($row) {
  65. $arr = [];
  66. $arr['title'] = $row->find('td:eq(2) a')->text();
  67. $arr['href'] = 'http://rcyz.qxrc.com' . $row->find('td:eq(2) a')->attr('href');
  68. $arr['id'] = str_replace('http://rcyz.qxrc.com/index.php?g=activity&m=activity&a=site_portal&id=', '', $arr['href']);
  69. return $arr;
  70. });
  71. $res = $tableRows->all();
  72. foreach ($res as $v) {
  73. Db::table('psite')->insert([
  74. 'id' => $v['id'],
  75. 'href' => $v['href'],
  76. ]);
  77. }
  78. return 'ok';
  79. }
  80. public function t2()
  81. {
  82. $site = Db::table('psite')->select();
  83. foreach ($site as $v) {
  84. $ql = QueryList::get($v['href']);
  85. $rt['town'] = str_replace('所在乡镇:', '', $ql->find('.head h4')->text());
  86. $rt['content'] = $ql->find('.intro-content')->text();
  87. $rt['contact'] = $ql->find('.comment-ranking p:eq(0) strong')->text();
  88. $rt['mobile'] = $ql->find('.comment-ranking p:eq(1) strong')->text();
  89. $rt['email'] = $ql->find('.comment-ranking p:eq(2) strong')->text();
  90. $rt['address'] = $ql->find('.comment-ranking p:eq(5) strong')->text();
  91. Db::name('activity_site')->where('id', $v['id'])->update($rt);
  92. }
  93. }
  94. public function t3()
  95. {
  96. set_time_limit(0);
  97. $site = Db::table('psite')->select();
  98. foreach ($site as $v) {
  99. $this->_getActivity($v['href'], $v['id']);
  100. }
  101. }
  102. private function _getActivity($url, $id, $page = 1)
  103. {
  104. $rt = QueryList::get($url . '&p=' . $page)->rules([
  105. 'href' => ['.item-image a', 'href'],
  106. 'image' => ['.item-image img', 'src'],
  107. ])->range('.row .span9 .span3')->query()->getData();
  108. $flag = QueryList::get($url . '&p=' . $page)->find('.pagination li:last')->text();
  109. $list = $rt->all();
  110. if (!empty($list)) {
  111. foreach ($list as $v) {
  112. Db::table('pactivity')->insert([
  113. 'site_id' => $id,
  114. 'href' => 'http://rcyz.qxrc.com' . $v['href'],
  115. 'image' => $v['image'],
  116. ]);
  117. }
  118. }
  119. if ($flag == '尾页') {
  120. $this->_getActivity($url, $id, $page + 1);
  121. }
  122. }
  123. public function t4()
  124. {
  125. set_time_limit(0);
  126. $list = Db::table('pactivity')->select();
  127. foreach ($list as $v) {
  128. $ql = QueryList::get($v['href']);
  129. $arr = [];
  130. $arr['id'] = (int)str_replace('http://rcyz.qxrc.com/index.php?g=activity&m=activity&a=detail&id=', '', $v['href']);
  131. $arr['title'] = $ql->find('.article-box h2')->text();
  132. $arr['main_image'] = (string)$v['image'];
  133. $arr['start_time'] = strtotime($ql->find('.tc-box:eq(3)>div:eq(1)>div:eq(0) strong')->text());
  134. $end_time = strtotime($ql->find('.tc-box:eq(3)>div:eq(1)>div:eq(1) strong')->text());
  135. $arr['end_time'] = $end_time > 0 ? $end_time : 0;
  136. $arr['address'] = $ql->find('.tc-box:eq(4)>div:eq(1) strong')->text();
  137. $arr['user_id'] = $v['site_id'];
  138. $arr['content'] = $ql->find('#article_content')->html();
  139. $info = $ql->find('.article-infobox span:eq(0)')->text();
  140. $info = explode('|', $info);
  141. $arr['create_time'] = strtotime(trim(str_replace('创建于:', '', $info[0])));
  142. $arr['author'] = trim(str_replace('作者:', '', $info[1]));
  143. $arr['status'] = 2;
  144. Db::name('activity')->insert($arr);
  145. }
  146. return 'ok';
  147. }
  148. public function t5()
  149. {
  150. $ql = QueryList::get('http://rcyz.qxrc.com/index.php?g=portal&m=index&a=review_list&p=1');
  151. $this->_getReviewList($ql);
  152. $ql = QueryList::get('http://rcyz.qxrc.com/index.php?g=portal&m=index&a=review_list&p=2');
  153. $this->_getReviewList($ql);
  154. }
  155. private function _getReviewList(QueryList $ql)
  156. {
  157. $rt = $ql->rules([
  158. 'href' => ['.item-image a', 'href'],
  159. 'image' => ['.item-image img', 'src'],
  160. ])->range('.tc-gridbox')->query()->getData();
  161. $list = $rt->all();
  162. foreach ($list as $v) {
  163. Db::table('preview')->insert([
  164. 'href' => 'http://rcyz.qxrc.com' . $v['href'],
  165. 'image' => $v['image'],
  166. ]);
  167. }
  168. }
  169. public function t6()
  170. {
  171. $list = Db::table('preview')->select();
  172. foreach ($list as $v) {
  173. $ql = QueryList::get($v['href']);
  174. $arr = [];
  175. $arr['title'] = $ql->find('.article-box>h2')->text();
  176. $arr['content'] = $ql->find('#article_content')->html();
  177. $arr['main_image'] = $v['image'];
  178. $href = $ql->find('.row>.span3>div:eq(0)>div:eq(1)>div:eq(0) a')->attr('href');
  179. $arr['activity_id'] = (int)str_replace('/index.php?g=activity&m=activity&a=detail&id=','',$href);
  180. $arr['user_id'] = (int)Db::name('activity')->where('id',$arr['activity_id'])->value('user_id');
  181. $arr['create_time'] = time();
  182. Db::name('activity_review')->insert($arr);
  183. }
  184. }
  185. }