暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Diyajax.php 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\api\controller;
  14. use think\Config;
  15. use think\Db;
  16. use PHPExcel_IOFactory;
  17. class Diyajax extends Base
  18. {
  19. /*
  20. * 初始化操作
  21. */
  22. public function _initialize() {
  23. parent::_initialize();
  24. }
  25. /**
  26. * 检验会员登录
  27. */
  28. public function check_userinfo()
  29. {
  30. if (IS_AJAX) {
  31. \think\Session::pause(); // 暂停session,防止session阻塞机制
  32. $ajaxLogic = new \app\api\logic\AjaxLogic;
  33. $result = $ajaxLogic->check_userinfo();
  34. if (!empty($result['data']['ey_is_login'])) {
  35. $assignData = [
  36. 'users' => $result['users'],
  37. ];
  38. $this->assign($assignData);
  39. $filename = './template/'.THEME_STYLE_PATH.'/'.'system/users_info.htm';
  40. if (file_exists($filename)) {
  41. $html = $this->fetch($filename); // 渲染模板标签语法
  42. } else {
  43. $html = '缺少模板文件:'.ltrim($filename, '.');
  44. }
  45. $result['data']['html'] = $html;
  46. }
  47. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$result['data']]);
  48. }
  49. to_index("404");
  50. }
  51. /*
  52. * 下载文件
  53. * https://www.zc10000.com/api/diyajax/downfile
  54. */
  55. public function downFile(){
  56. $id = request()->get('id',0);
  57. //var_dump((int)$id);
  58. //非法
  59. if((int)$id === 0){
  60. respose(['code'=>0, 'msg'=>'请求失败!', 'data'=>[]]);
  61. }
  62. //查找记录
  63. $one = Db::name('users_down')->where(['id'=>$id])->find();
  64. if((int)$one['num'] >= 3){
  65. respose(['code'=>0, 'msg'=>'该链接请求下载次数不能超过3次,链接已失效!', 'data'=>[]]);
  66. }
  67. if((int)$one['expire_time'] < time()){
  68. //已过期
  69. respose(['code'=>0, 'msg'=>'下载链接已失效!', 'data'=>[]]);
  70. }
  71. //查找下载地址
  72. $artData = Db::name('zczygz_content')->where('aid', $one['aid'])
  73. ->find();
  74. if(empty($artData) || empty($artData['down'])){
  75. respose(['code'=>0, 'msg'=>'文档不存在!', 'data'=>[]]);
  76. }
  77. //php
  78. $ext = explode('.',$artData['down']);
  79. $ext = end($ext);
  80. $filename = $one['title'].'.'.$ext;
  81. $file = $artData['down'].'?attname='.$filename;
  82. //$filename = basename($file);
  83. //echo $file;
  84. //记录下载次数
  85. Db::name('users_down')->where(['id'=>$id])->setInc('num');
  86. header('location:'.$file);
  87. //$this->downFileCurl($file,$filename);
  88. }
  89. public function downFileCurl($url, $file_name)
  90. {
  91. header('Content-Description: File Transfer');
  92. header('Content-Type: application/vnd.android.package-archive');
  93. header('Content-Disposition: attachment; filename=' . $file_name);
  94. header('Content-Transfer-Encoding: binary');
  95. header('Expires: 0');
  96. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  97. header('Pragma: public');
  98. $ch = curl_init();
  99. curl_setopt($ch, CURLOPT_URL, $url);
  100. curl_setopt($ch, CURLOPT_HEADER, 0);
  101. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  102. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  103. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
  104. echo $buffer;
  105. return strlen($buffer);
  106. });
  107. curl_exec($ch);
  108. curl_close($ch);
  109. }
  110. /*
  111. * 获取所有申报专业
  112. * /api/Diyajax/getZcList
  113. */
  114. public function getZcList()
  115. {
  116. $param = request()->param();
  117. $param['id'] = (int)$param['id'];
  118. if(!empty($param['id'])){
  119. if($param['id'] === 10001){
  120. //不限制
  121. //查找
  122. $list = Db::name('zc_position')
  123. ->field('id,title')
  124. ->where('is_del', 0)
  125. ->where('status', 1)
  126. ->select();
  127. }else if($param['id'] === 20000) {
  128. //全国
  129. $list = Db::name('zc_position')
  130. ->field('id,title')
  131. ->where('type', 0)
  132. ->where('is_del', 0)
  133. ->where('status', 1)
  134. ->select();
  135. }else {
  136. //具体地区
  137. $ids = Db::name('zc_map')
  138. ->where('map_id',$param['id'])
  139. ->where('is_del', 0)
  140. ->column('zc_id');
  141. $list = Db::name('zc_position')
  142. ->field('id,title')
  143. ->where('type', 1)
  144. ->where('is_del', 0)
  145. ->where('status', 1)
  146. ->whereIn('id', $ids)
  147. ->select();
  148. }
  149. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$list]);
  150. }else{
  151. respose(['code'=>0, 'msg'=>'请求失败', 'data'=>[]]);
  152. }
  153. }
  154. /*
  155. * getZcDjList
  156. * /api/Diyajax/getZcDjList
  157. */
  158. public function getZcDjList(){
  159. $param = request()->param();
  160. $param['id'] = (int)$param['id'];
  161. if(!empty($param['id'])){
  162. $dj_group_id = Db::name('zc_position')->where('id', $param['id'])->value('dj_group_id');
  163. //调用等级
  164. $list = Db::name('zcdj_position')->where('type',$dj_group_id)->select();
  165. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$list]);
  166. }else{
  167. respose(['code'=>0, 'msg'=>'请求失败', 'data'=>[]]);
  168. }
  169. }
  170. /*
  171. * getZcDjList
  172. * /api/Diyajax/getZcSonList
  173. */
  174. public function getZcSonList(){
  175. $param = request()->param();
  176. $param['id'] = (int)$param['id'];
  177. if(!empty($param['id'])){
  178. //调用等级
  179. $list = Db::name('zcson_position')->where('catid',$param['id'])->select();
  180. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$list]);
  181. }else{
  182. respose(['code'=>0, 'msg'=>'请求失败', 'data'=>[]]);
  183. }
  184. }
  185. /*
  186. * //获取毕业专业
  187. * /api/Diyajax/getZcZyList
  188. */
  189. public function getZcZyList()
  190. {
  191. $param = request()->param();
  192. $param['id'] = (int)$param['id'];
  193. if(!empty($param['id'])){
  194. $map_ids = Db::name('zc_zy')
  195. ->where('zc_id', $param['id'])
  196. ->where('is_del', 0)
  197. ->column('map_id');
  198. //调用等级
  199. $list = Db::name('zczy_position')
  200. ->where('id','in',$map_ids)
  201. ->where('is_del', 0)
  202. ->where('status', 1)
  203. ->select();
  204. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$list]);
  205. }else{
  206. respose(['code'=>0, 'msg'=>'请求失败', 'data'=>[]]);
  207. }
  208. }
  209. /*
  210. * id: 1
  211. xl: 4
  212. id: 1
  213. xl: 2
  214. */
  215. public function getZcZsList()
  216. {
  217. $param = request()->param();
  218. $param['id'] = (int)$param['id']; //职称ID
  219. $param['xl'] = (int)$param['xl']; //学历
  220. if(!empty($param['id'])){
  221. $map_ids = Db::name('zc_zs')
  222. ->where('zc_id', $param['id'])
  223. ->where('is_del', 0)
  224. ->column('map_id');
  225. //调用等级
  226. $list = Db::name('zczs_position')
  227. ->where('id','in',$map_ids)
  228. ->where('is_del', 0)
  229. ->where('status', 1)
  230. ->select();
  231. //去掉证书绑定学历
  232. /*$new_list = [];
  233. foreach ($list as $k=>$v){
  234. if((int)$v['bdxl'] >= (int)$param['xl']){
  235. //保留
  236. $new_list[] = $v;
  237. }
  238. }*/
  239. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$list]);
  240. }else{
  241. respose(['code'=>0, 'msg'=>'请求失败', 'data'=>[]]);
  242. }
  243. }
  244. /*
  245. * getZyList
  246. * /api/Diyajax/getZyList
  247. * 丢弃
  248. */
  249. public function getZyList()
  250. {
  251. $param = request()->param();
  252. $param['xlid'] = (int)$param['xlid'];
  253. $param['zcid'] = (int)$param['zcid'];
  254. if(!empty($param['xlid']) && !empty($param['zcid'])){
  255. $map_ids = Db::name('zc_zy')
  256. ->where('zc_id', $param['id'])
  257. ->where('is_del', 0)
  258. ->column('map_id');
  259. //调用等级
  260. $list = Db::name('zczy_position')
  261. ->where('id','in',$map_ids)
  262. ->where('is_del', 0)
  263. ->where('status', 1)
  264. ->select();
  265. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$list]);
  266. }else{
  267. respose(['code'=>0, 'msg'=>'请求失败', 'data'=>[]]);
  268. }
  269. }
  270. /*
  271. * 后期再加令牌
  272. */
  273. public function getCode()
  274. {
  275. $param = request()->param();
  276. $mobile = $param['mobile'];
  277. if (empty($mobile)){
  278. respose(['code'=>0, 'msg'=>'手机号码不能为空', 'data'=>[]]);
  279. }
  280. if (!check_mobile($mobile)) {
  281. respose(['code'=>0, 'msg'=>'手机号码格式不正确', 'data'=>[]]);
  282. }
  283. /*是否允许再次发送*/
  284. $where = [
  285. 'mobile' => $mobile,
  286. 'source' => 6, //$scene
  287. 'status' => 1,
  288. 'is_use' => 0,
  289. 'add_time' => ['>', getTime() - 120]
  290. ];
  291. $Result = Db::name('sms_log')->where($where)->order('id desc')->count();
  292. if (!empty($Result) && false == config('sms_debug')){
  293. respose(['code'=>0, 'msg'=>'120秒内只能发送一次', 'data'=>[]]);
  294. }
  295. $Result = sendSms(1, $mobile, array('content' => mt_rand(1000, 9999)));
  296. if (intval($Result['status']) == 1) {
  297. //@unlink($session_file);
  298. //$this->success('发送成功!');
  299. respose(['code'=>1, 'msg'=>'发送成功', 'data'=>[]]);
  300. } else {
  301. //$this->error($Result['msg']);
  302. respose(['code'=>0, 'msg'=>$Result['msg'], 'data'=>[]]);
  303. }
  304. }
  305. /*
  306. * 处理表单提交数据
  307. */
  308. public function insData()
  309. {
  310. $param = request()->param();
  311. $mobile = $param['sjhm'];
  312. if (empty($mobile)){
  313. respose(['code'=>0, 'msg'=>'手机号码不能为空', 'data'=>[]]);
  314. }
  315. if (!check_mobile($mobile)) {
  316. respose(['code'=>0, 'msg'=>'手机号码格式不正确', 'data'=>[]]);
  317. }
  318. //验证码校验 $param['yzm']
  319. //判断验证码是否存在并且是否可用
  320. if($param['yzm'] == '0000'){
  321. //免验证
  322. }else {
  323. $RecordWhere = [
  324. 'mobile' => trim($param['sjhm']),
  325. 'code' => trim($param['yzm']),
  326. 'lang' => $this->home_lang
  327. ];
  328. $RecordData = Db::name('sms_log')->where($RecordWhere)->field('is_use, add_time')->order('id desc')->find();
  329. if (!empty($RecordData)) {
  330. // 验证码存在
  331. $time = getTime();
  332. $RecordData['add_time'] += Config::get('global.mobile_default_time_out');
  333. if (1 == $RecordData['is_use'] || $RecordData['add_time'] <= $time) {
  334. respose(['code' => 0, 'msg' => '手机验证码已被使用或超时,请重新发送!', 'data' => []]);
  335. } else {
  336. // 处理手机验证码
  337. $RecordWhere = [
  338. 'source' => 1,
  339. 'mobile' => $param['sjhm'],
  340. 'is_use' => 0,
  341. 'lang' => $this->home_lang
  342. ];
  343. // 更新数据
  344. $RecordData = [
  345. 'is_use' => 1,
  346. 'update_time' => $time
  347. ];
  348. Db::name('sms_log')->where($RecordWhere)->update($RecordData);
  349. }
  350. } else {
  351. respose(['code' => 0, 'msg' => '手机验证码不正确,请重新输入!', 'data' => []]);
  352. }
  353. }
  354. $param['zhengshu_val'] = substr($param['zhengshu_val'], 0, -1);
  355. $param['zhengshu'] = explode(',',$param['zhengshu_val']);
  356. //翻译冗余字段
  357. $xl_arr = ['','中专','高技','大专','本科','硕士','博士'];
  358. $xxlx_arr = ['','全日制','非全日制'];
  359. $sbzy_val = Db::name('zc_position')->where('id',$param['sbzy'])->value('title');
  360. $sbdj_val = Db::name('zcdj_position')->where('id',$param['sbdj'])->value('title');
  361. $zs_list = Db::name('zczs_position')->field('id,title')->where('id','in',$param['zhengshu'])->select();
  362. $zs_str = '';
  363. foreach ($zs_list as $k => $v){
  364. $key = array_search($v['id'],$param['zhengshu']);
  365. $zs_str .= $v['title'].'('.$param['zsnx'][$key].'年),';
  366. }
  367. $zy_list = Db::name('zczy_position')->field('id,title')->where('id','in',$param['zy'])->select();
  368. $zy_str = '';
  369. foreach ($zy_list as $k => $v){
  370. $zy_str .= $v['title'].',';
  371. }
  372. $szcs_str = Db::name('citysite')
  373. ->where('id', $param['szcs'])
  374. ->value('name');
  375. $szsf_str = Db::name('citysite')
  376. ->where('id', $param['szsf'])
  377. ->value('name');
  378. $zcson_str = Db::name('zcson_position')
  379. ->where('id', $param['sbzyson'])
  380. ->value('title');
  381. if(empty($zcson_str)){
  382. $zcson_str = '默认';
  383. }
  384. $json = [
  385. 'xl' => $xl_arr[$param['xl']], //学历
  386. 'sbzy' => $sbzy_val, //申报专业
  387. 'sbdj' => $sbdj_val, //申报等级
  388. 'xxlx' => $xxlx_arr[$param['xxlx']], //学校类型
  389. 'zs' => $zs_str, //证书
  390. 'zy' => $zy_str, //专业
  391. 'szsf' => $szsf_str, //省份
  392. 'szcs' => $szcs_str, //城市
  393. 'zcson' => $zcson_str, //申报专业
  394. ];
  395. $json_str = json_encode($json,JSON_UNESCAPED_UNICODE);
  396. //{"xl":"中专","sbzy":"建筑职称","sbdj":"初级","xxlx":"全日制","zs":"建筑一级证书(1年),","zy":"计算机网络技术,","szsf":"广东","szcs":"广州"}
  397. //插入数据
  398. $insertData = [
  399. 'yxdq' => $param['yxdq'], //预选地区
  400. 'sbzy' => $param['sbzy'], //申报专业
  401. 'sbdj' => $param['sbdj'], //申报等级
  402. 'bysj' => $param['bysj2'], //毕业时间
  403. 'nl' => $param['nl'], //年龄
  404. 'xl' => $param['xl'], //学历
  405. 'xxlx' => $param['xxlx'], //学校类型
  406. 'sjhm' => $param['sjhm'], //手机号码
  407. 'ch' => $param['ch'], //称呼
  408. 'zs' => json_encode($param['zhengshu'],JSON_UNESCAPED_UNICODE), //证书 //checkbox $param['zs'] 提交不完全
  409. 'zsnx' => json_encode($param['zsnx'],JSON_UNESCAPED_UNICODE), //证书年限
  410. 'zy' => json_encode($param['zy'],JSON_UNESCAPED_UNICODE), //毕业专业
  411. 'addtime' => getTime(),
  412. 'updatetime' => getTime(),
  413. 'is_del' => 0,
  414. 'status' => 1,
  415. 'szcs' => $param['szcs'], //城市
  416. 'szsf' => $param['szsf'], //省份
  417. 'extend' => $json_str,
  418. 'byzy_is' => $param['byzy-is'],
  419. 'byzy_name' => $param['byzy-name'],
  420. 'sbzyson' => $param['sbzyson'],
  421. ];
  422. $res_id = Db::name('zc_form')->insertGetId($insertData);
  423. if($res_id > 0){
  424. $str = md5($res_id.time());
  425. $run = Db::name('zc_form')->where('id', $res_id)->update(['code' => $str]);
  426. if($run === 1){
  427. respose(['code'=>1, 'msg'=>'提交成功', 'data'=>['code'=>$str,'mobile'=>$param['sjhm']]]);
  428. }
  429. }
  430. respose(['code'=>0, 'msg'=>'提交失败', 'data'=>[]]);
  431. }
  432. /*
  433. * 验证码
  434. * 这里不记录查询记录
  435. */
  436. public function cxCode()
  437. {
  438. $param = request()->param();
  439. $mobile = $param['mobile'];
  440. if (empty($mobile)){
  441. respose(['code'=>0, 'msg'=>'手机号码不能为空', 'data'=>[]]);
  442. }
  443. if (!check_mobile($mobile)) {
  444. respose(['code'=>0, 'msg'=>'手机号码格式不正确', 'data'=>[]]);
  445. }
  446. if (empty($param['code'])){
  447. respose(['code'=>0, 'msg'=>'验证码不能为空', 'data'=>[]]);
  448. }
  449. if($param['code'] == '0000'){
  450. //免验证
  451. }else {
  452. $RecordWhere = [
  453. 'mobile' => trim($param['mobile']),
  454. 'code' => trim($param['code']),
  455. 'lang' => $this->home_lang
  456. ];
  457. $RecordData = Db::name('sms_log')->where($RecordWhere)->field('is_use, add_time')->order('id desc')->find();
  458. if (!empty($RecordData)) {
  459. // 验证码存在
  460. $time = getTime();
  461. $RecordData['add_time'] += Config::get('global.mobile_default_time_out');
  462. if (1 == $RecordData['is_use'] || $RecordData['add_time'] <= $time) {
  463. respose(['code' => 0, 'msg' => '手机验证码已被使用或超时,请重新发送!', 'data' => []]);
  464. } else {
  465. // 处理手机验证码
  466. $RecordWhere = [
  467. 'source' => 1,
  468. 'mobile' => $param['mobile'],
  469. 'is_use' => 0,
  470. 'lang' => $this->home_lang
  471. ];
  472. // 更新数据
  473. $RecordData = [
  474. 'is_use' => 1,
  475. 'update_time' => $time
  476. ];
  477. Db::name('sms_log')->where($RecordWhere)->update($RecordData);
  478. }
  479. } else {
  480. respose(['code' => 0, 'msg' => '手机验证码不正确,请重新输入!', 'data' => []]);
  481. }
  482. }
  483. respose(['code'=>1, 'msg'=>'验证通过,查询中...', 'data'=>[]]);
  484. }
  485. /*
  486. * 获取城市1
  487. */
  488. public function getCsList(){
  489. $param = request()->param();
  490. $param['id'] = (int)$param['id'];
  491. if(!empty($param['id'])){
  492. $list = Db::name('citysite')
  493. ->field('id,name')
  494. ->where('parent_id', $param['id'])
  495. //->where('status',1)
  496. //->where('is_open',1)
  497. ->select();
  498. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$list]);
  499. }else{
  500. respose(['code'=>0, 'msg'=>'请求失败', 'data'=>[]]);
  501. }
  502. }
  503. public function kjForm(){
  504. $param = request()->param();
  505. $param['form_id'] = (int)$param['form_id'];
  506. $one = Db::name('zc_form')->where('id', $param['form_id'])->find();
  507. if((int)$one['pccs'] === 0){
  508. //未更新
  509. if(!empty($param['form_id'])){
  510. $pccs = Db::name('zc_form')->where(['sjhm'=>$one['sjhm'],'is_del'=>0])->count();
  511. $data = [
  512. 'pccs' => (int)$pccs + 1,
  513. 'is_tg' => (int)$param['is_tg'],
  514. 'jjfa' => $param['jjfa'],
  515. 'xy_info' => $param['xy_info'],
  516. ];
  517. //更新表单数据
  518. $list = Db::name('zc_form')
  519. ->where('id', $param['form_id'])
  520. ->update($data);
  521. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>[]]);
  522. }else{
  523. respose(['code'=>0, 'msg'=>'请求失败', 'data'=>[]]);
  524. }
  525. }else{
  526. respose(['code'=>0, 'msg'=>'请求失败', 'data'=>[]]);
  527. }
  528. }
  529. public function getFormList()
  530. {
  531. $list = Db::name('zc_form')
  532. //->where('pccs', 1) //同一号码 只调用一次
  533. ->field('id,ch,sjhm,is_tg,jjfa,extend')
  534. ->where('is_del', 0)
  535. ->where('pccs', '>',0)
  536. ->order('updatetime desc')
  537. //->fetchSql(true)
  538. ->limit(20)
  539. ->select();
  540. //var_dump($list);
  541. $is_tg_str = ['条件不符','符合条件'];
  542. foreach ($list as $key => $item) {
  543. $item['is_tg_n'] = $item['is_tg'];
  544. $extend_info = json_decode($item['extend'],true);
  545. $item['sbxx'] = $extend_info['sbzy'].$extend_info['sbdj'];
  546. $item['sjhm'] = preg_replace('/(\d{3})\d{4}(\d{4})/', '$1****$2', $item['sjhm']);
  547. $item['is_tg'] = $is_tg_str[$item['is_tg']];
  548. $list[$key] = $item;
  549. }
  550. $zrs = $list[0]['id'] + 1000;
  551. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$list,'zrs'=>$zrs]);
  552. }
  553. /*
  554. * 导入数据处理
  555. * /api/Diyajax/exportData
  556. * https://www.zc10000.com/api/Diyajax/exportData
  557. *
  558. * 清除sql命令
  559. *
  560. TRUNCATE TABLE ey_zc_zs;
  561. TRUNCATE TABLE ey_zc_zy;
  562. TRUNCATE TABLE ey_zc_position;
  563. TRUNCATE TABLE ey_zczy_position;
  564. TRUNCATE TABLE ey_zczs_position;
  565. TRUNCATE TABLE ey_zcwf_position;
  566. TRUNCATE TABLE ey_zcwe_position;
  567. TRUNCATE TABLE ey_zcwd_position;
  568. TRUNCATE TABLE ey_zcdj_position;
  569. */
  570. public function exportData(){
  571. $fileTmpPath = './public/006.xlsx';
  572. $expType = PHPExcel_IOFactory::identify($fileTmpPath);
  573. $objReader = PHPExcel_IOFactory::createReader($expType);
  574. $objPHPExcel = $objReader->load($fileTmpPath);
  575. $sheet = $objPHPExcel->getSheet(0); //获取第一张表
  576. $highestRow = $sheet->getHighestRow(); //获取总行数
  577. $highestColumn = $sheet->getHighestColumn(); //XFD
  578. //var_dump($highestRow);die;
  579. //var_dump($highestColumn);die;
  580. //$highestRow = 2; //测试
  581. echo "<pre>";
  582. $rowData_1 = $sheet->rangeToArray('A' . 1 . ':' . $highestColumn . 1, NULL, TRUE, FALSE);
  583. //var_dump($rowData_1);
  584. // 循环读取每个单元格的内容。行数是以第1行为起始
  585. for ($row = 2; $row <= $highestRow; $row++) {
  586. $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
  587. // 处理$rowData,例如保存到数据库等
  588. // ...
  589. //var_dump($rowData);
  590. //判断条件 丢弃
  591. $xlmcc = $rowData[0][4];
  592. if($xlmcc == '研究生' || $xlmcc == '双学位'){
  593. echo '忽略这个记录<br/>';
  594. }else {
  595. if(!empty($rowData[0][0])) {
  596. //处理职称名称 返回职称ID
  597. $aid = model('v1.Zc')->zcPos($rowData[0][0]);
  598. //申报等级
  599. $did = model('v1.Zc')->zcTypeAndDj($aid, $rowData[0][2]);
  600. //添加专业 - 具体专业
  601. $yids = model('v1.Zc')->zczyAdd($aid, $rowData);
  602. //添加专业绑定职称
  603. if (!empty($yids)) {
  604. model('v1.Zc')->bindZcZy($aid, $yids);
  605. }
  606. if (!empty($rowData[0][8])) {
  607. //添加证书 得到证书id
  608. $sid = model('v1.Zc')->ZsZcAdd($aid, $rowData[0][8]);
  609. //添加证书绑定职称
  610. $zids = [$sid];
  611. model('v1.Zc')->bingZs($aid, $zids);
  612. //证书绑定学历
  613. //博士,硕士,研究生,双学位,本科,大专,高技,中专
  614. model('v1.Zc')->zsBindXl($sid, $rowData);
  615. }
  616. //添加主规则 区域/申报等级/职称名称
  617. $gid = model('v1.Zc')->addZcwd($aid, $did, $rowData);
  618. //添加学历规则 学历/学历条件/毕业年限/年龄/专业要求/具体专业
  619. $xid = model('v1.Zc')->addZcXi($gid, $yids, $rowData);
  620. //添加证书规则 且还是或 存在疑问? 前置+具体要求
  621. if (!empty($rowData[0][8])) {
  622. $zid = model('v1.Zc')->addZsGz($gid, $xid, $sid, $rowData);
  623. }
  624. $title = $rowData[0][0] . '-' . $rowData[0][2] . '-' . $rowData[0][1] . '-' . $rowData[0][4];
  625. echo '已处理[' . $title . ']这个记录<br/>';
  626. }else{
  627. echo $row.'为空这个记录<br/>';
  628. }
  629. }
  630. }
  631. echo "</pre>";
  632. }
  633. }