Brak opisu

Diyajax.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. class Diyajax extends Base
  17. {
  18. /*
  19. * 初始化操作
  20. */
  21. public function _initialize() {
  22. parent::_initialize();
  23. }
  24. /**
  25. * 检验会员登录
  26. */
  27. public function check_userinfo()
  28. {
  29. if (IS_AJAX) {
  30. \think\Session::pause(); // 暂停session,防止session阻塞机制
  31. $ajaxLogic = new \app\api\logic\AjaxLogic;
  32. $result = $ajaxLogic->check_userinfo();
  33. if (!empty($result['data']['ey_is_login'])) {
  34. $assignData = [
  35. 'users' => $result['users'],
  36. ];
  37. $this->assign($assignData);
  38. $filename = './template/'.THEME_STYLE_PATH.'/'.'system/users_info.htm';
  39. if (file_exists($filename)) {
  40. $html = $this->fetch($filename); // 渲染模板标签语法
  41. } else {
  42. $html = '缺少模板文件:'.ltrim($filename, '.');
  43. }
  44. $result['data']['html'] = $html;
  45. }
  46. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$result['data']]);
  47. }
  48. to_index("404");
  49. }
  50. /*
  51. * 下载文件
  52. * https://www.zc10000.com/api/diyajax/downfile
  53. */
  54. public function downFile(){
  55. $id = request()->get('id',0);
  56. //var_dump((int)$id);
  57. //非法
  58. if((int)$id === 0){
  59. respose(['code'=>0, 'msg'=>'请求失败!', 'data'=>[]]);
  60. }
  61. //查找记录
  62. $one = Db::name('users_down')->where(['id'=>$id])->find();
  63. if((int)$one['num'] >= 3){
  64. respose(['code'=>0, 'msg'=>'该链接请求下载次数不能超过3次,链接已失效!', 'data'=>[]]);
  65. }
  66. if((int)$one['expire_time'] < time()){
  67. //已过期
  68. respose(['code'=>0, 'msg'=>'下载链接已失效!', 'data'=>[]]);
  69. }
  70. //查找下载地址
  71. $artData = Db::name('zczygz_content')->where('aid', $one['aid'])
  72. ->find();
  73. if(empty($artData) || empty($artData['down'])){
  74. respose(['code'=>0, 'msg'=>'文档不存在!', 'data'=>[]]);
  75. }
  76. //php
  77. $ext = explode('.',$artData['down']);
  78. $ext = end($ext);
  79. $filename = $one['title'].'.'.$ext;
  80. $file = $artData['down'].'?attname='.$filename;
  81. //$filename = basename($file);
  82. //echo $file;
  83. //记录下载次数
  84. Db::name('users_down')->where(['id'=>$id])->setInc('num');
  85. header('location:'.$file);
  86. //$this->downFileCurl($file,$filename);
  87. }
  88. public function downFileCurl($url, $file_name)
  89. {
  90. header('Content-Description: File Transfer');
  91. header('Content-Type: application/vnd.android.package-archive');
  92. header('Content-Disposition: attachment; filename=' . $file_name);
  93. header('Content-Transfer-Encoding: binary');
  94. header('Expires: 0');
  95. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  96. header('Pragma: public');
  97. $ch = curl_init();
  98. curl_setopt($ch, CURLOPT_URL, $url);
  99. curl_setopt($ch, CURLOPT_HEADER, 0);
  100. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  101. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  102. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
  103. echo $buffer;
  104. return strlen($buffer);
  105. });
  106. curl_exec($ch);
  107. curl_close($ch);
  108. }
  109. /*
  110. * 获取所有申报专业
  111. * /api/Diyajax/getZcList
  112. */
  113. public function getZcList()
  114. {
  115. $param = request()->param();
  116. $param['id'] = (int)$param['id'];
  117. if(!empty($param['id'])){
  118. if($param['id'] === 10001){
  119. //不限制
  120. //查找
  121. $list = Db::name('zc_position')
  122. ->field('id,title')
  123. ->where('is_del', 0)
  124. ->where('status', 1)
  125. ->select();
  126. }else if($param['id'] === 20000) {
  127. //全国
  128. $list = Db::name('zc_position')
  129. ->field('id,title')
  130. ->where('type', 0)
  131. ->where('is_del', 0)
  132. ->where('status', 1)
  133. ->select();
  134. }else {
  135. //具体地区
  136. $ids = Db::name('zc_map')
  137. ->where('map_id',$param['id'])
  138. ->where('is_del', 0)
  139. ->column('zc_id');
  140. $list = Db::name('zc_position')
  141. ->field('id,title')
  142. ->where('type', 1)
  143. ->where('is_del', 0)
  144. ->where('status', 1)
  145. ->whereIn('id', $ids)
  146. ->select();
  147. }
  148. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$list]);
  149. }else{
  150. respose(['code'=>0, 'msg'=>'请求失败', 'data'=>[]]);
  151. }
  152. }
  153. /*
  154. * getZcDjList
  155. * /api/Diyajax/getZcDjList
  156. */
  157. public function getZcDjList(){
  158. $param = request()->param();
  159. $param['id'] = (int)$param['id'];
  160. if(!empty($param['id'])){
  161. $dj_group_id = Db::name('zc_position')->where('id', $param['id'])->value('dj_group_id');
  162. //调用等级
  163. $list = Db::name('zcdj_position')->where('type',$dj_group_id)->select();
  164. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$list]);
  165. }else{
  166. respose(['code'=>0, 'msg'=>'请求失败', 'data'=>[]]);
  167. }
  168. }
  169. /*
  170. * //获取毕业专业
  171. * /api/Diyajax/getZcZyList
  172. */
  173. public function getZcZyList()
  174. {
  175. $param = request()->param();
  176. $param['id'] = (int)$param['id'];
  177. if(!empty($param['id'])){
  178. $map_ids = Db::name('zc_zy')
  179. ->where('zc_id', $param['id'])
  180. ->where('is_del', 0)
  181. ->column('map_id');
  182. //调用等级
  183. $list = Db::name('zczy_position')
  184. ->where('id','in',$map_ids)
  185. ->where('is_del', 0)
  186. ->where('status', 1)
  187. ->select();
  188. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$list]);
  189. }else{
  190. respose(['code'=>0, 'msg'=>'请求失败', 'data'=>[]]);
  191. }
  192. }
  193. public function getZcZsList()
  194. {
  195. $param = request()->param();
  196. $param['id'] = (int)$param['id'];
  197. if(!empty($param['id'])){
  198. $map_ids = Db::name('zc_zs')
  199. ->where('zc_id', $param['id'])
  200. ->where('is_del', 0)
  201. ->column('map_id');
  202. //调用等级
  203. $list = Db::name('zczs_position')
  204. ->where('id','in',$map_ids)
  205. ->where('is_del', 0)
  206. ->where('status', 1)
  207. ->select();
  208. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$list]);
  209. }else{
  210. respose(['code'=>0, 'msg'=>'请求失败', 'data'=>[]]);
  211. }
  212. }
  213. /*
  214. * getZyList
  215. * /api/Diyajax/getZyList
  216. * 丢弃
  217. */
  218. public function getZyList()
  219. {
  220. $param = request()->param();
  221. $param['xlid'] = (int)$param['xlid'];
  222. $param['zcid'] = (int)$param['zcid'];
  223. if(!empty($param['xlid']) && !empty($param['zcid'])){
  224. $map_ids = Db::name('zc_zy')
  225. ->where('zc_id', $param['id'])
  226. ->where('is_del', 0)
  227. ->column('map_id');
  228. //调用等级
  229. $list = Db::name('zczy_position')
  230. ->where('id','in',$map_ids)
  231. ->where('is_del', 0)
  232. ->where('status', 1)
  233. ->select();
  234. respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$list]);
  235. }else{
  236. respose(['code'=>0, 'msg'=>'请求失败', 'data'=>[]]);
  237. }
  238. }
  239. /*
  240. * 后期再加令牌
  241. */
  242. public function getCode()
  243. {
  244. $param = request()->param();
  245. $mobile = $param['mobile'];
  246. if (empty($mobile)){
  247. respose(['code'=>0, 'msg'=>'手机号码不能为空', 'data'=>[]]);
  248. }
  249. if (!check_mobile($mobile)) {
  250. respose(['code'=>0, 'msg'=>'手机号码格式不正确', 'data'=>[]]);
  251. }
  252. /*是否允许再次发送*/
  253. $where = [
  254. 'mobile' => $mobile,
  255. 'source' => 6, //$scene
  256. 'status' => 1,
  257. 'is_use' => 0,
  258. 'add_time' => ['>', getTime() - 120]
  259. ];
  260. $Result = Db::name('sms_log')->where($where)->order('id desc')->count();
  261. if (!empty($Result) && false == config('sms_debug')){
  262. respose(['code'=>0, 'msg'=>'120秒内只能发送一次', 'data'=>[]]);
  263. }
  264. $Result = sendSms(1, $mobile, array('content' => mt_rand(1000, 9999)));
  265. if (intval($Result['status']) == 1) {
  266. //@unlink($session_file);
  267. //$this->success('发送成功!');
  268. respose(['code'=>1, 'msg'=>'发送成功', 'data'=>[]]);
  269. } else {
  270. //$this->error($Result['msg']);
  271. respose(['code'=>0, 'msg'=>$Result['msg'], 'data'=>[]]);
  272. }
  273. }
  274. /*
  275. * 处理表单提交数据
  276. */
  277. public function insData()
  278. {
  279. $param = request()->param();
  280. $mobile = $param['sjhm'];
  281. if (empty($mobile)){
  282. respose(['code'=>0, 'msg'=>'手机号码不能为空', 'data'=>[]]);
  283. }
  284. if (!check_mobile($mobile)) {
  285. respose(['code'=>0, 'msg'=>'手机号码格式不正确', 'data'=>[]]);
  286. }
  287. //验证码校验 $param['yzm']
  288. //判断验证码是否存在并且是否可用
  289. if($param['yzm'] == '0000'){
  290. //免验证
  291. }else {
  292. $RecordWhere = [
  293. 'mobile' => trim($param['sjhm']),
  294. 'code' => trim($param['yzm']),
  295. 'lang' => $this->home_lang
  296. ];
  297. $RecordData = Db::name('sms_log')->where($RecordWhere)->field('is_use, add_time')->order('id desc')->find();
  298. if (!empty($RecordData)) {
  299. // 验证码存在
  300. $time = getTime();
  301. $RecordData['add_time'] += Config::get('global.mobile_default_time_out');
  302. if (1 == $RecordData['is_use'] || $RecordData['add_time'] <= $time) {
  303. respose(['code' => 0, 'msg' => '手机验证码已被使用或超时,请重新发送!', 'data' => []]);
  304. } else {
  305. // 处理手机验证码
  306. $RecordWhere = [
  307. 'source' => 1,
  308. 'mobile' => $param['sjhm'],
  309. 'is_use' => 0,
  310. 'lang' => $this->home_lang
  311. ];
  312. // 更新数据
  313. $RecordData = [
  314. 'is_use' => 1,
  315. 'update_time' => $time
  316. ];
  317. Db::name('sms_log')->where($RecordWhere)->update($RecordData);
  318. }
  319. } else {
  320. respose(['code' => 0, 'msg' => '手机验证码不正确,请重新输入!', 'data' => []]);
  321. }
  322. }
  323. //插入数据
  324. $insertData = [
  325. 'yxdq' => $param['yxdq'], //预选地区
  326. 'sbzy' => $param['sbzy'], //申报专业
  327. 'sbdj' => $param['sbdj'], //申报等级
  328. 'bysj' => $param['bysj'], //毕业时间
  329. 'nl' => $param['nl'], //年龄
  330. 'xl' => $param['xl'], //学历
  331. 'xxlx' => $param['xxlx'], //学校类型
  332. 'sjhm' => $param['sjhm'], //手机号码
  333. 'ch' => $param['ch'], //称呼
  334. 'zs' => json_encode($param['zs'],JSON_UNESCAPED_UNICODE), //证书
  335. 'zsnx' => json_encode($param['zsnx'],JSON_UNESCAPED_UNICODE), //证书年限
  336. 'zy' => json_encode($param['zy'],JSON_UNESCAPED_UNICODE), //毕业专业
  337. 'addtime' => getTime(),
  338. 'updatetime' => getTime(),
  339. 'is_del' => 0,
  340. 'status' => 1,
  341. ];
  342. $res_id = Db::name('zc_form')->insertGetId($insertData);
  343. if($res_id > 0){
  344. $str = md5($res_id.time());
  345. $run = Db::name('zc_form')->where('id', $res_id)->update(['code' => $str]);
  346. if($run === 1){
  347. respose(['code'=>1, 'msg'=>'提交成功', 'data'=>['code'=>$str,'mobile'=>$param['sjhm']]]);
  348. }
  349. }
  350. respose(['code'=>0, 'msg'=>'提交失败', 'data'=>[]]);
  351. }
  352. }