IndexController.php 8.1 KB

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