AjaxController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. <?php
  2. namespace app\controllers;
  3. use app\common\helpers\Identify;
  4. use app\common\widget\LinkmenuWidget;
  5. use app\models\Linkmenu;
  6. use app\modules\admin\models\Sysconfig;
  7. use app\modules\car\models\FCarInfo;
  8. use app\modules\cms\models\Category;
  9. use app\common\components\CacheId;
  10. use app\modules\cms\models\CategoryConfig;
  11. use app\common\components\FormElements;
  12. use app\common\helpers\Cookie;
  13. use app\modules\doc\models\DocDownlog;
  14. use app\modules\doc\models\DocReal;
  15. use app\modules\doc\models\DocRealData;
  16. use app\models\VisitStatisticsByDay;
  17. use app\modules\ucenter\models\UserHistory;
  18. use Yii;
  19. use yii\web\Controller;
  20. class AjaxController extends Controller
  21. {
  22. public $enableCsrfValidation = false;
  23. public $userInfo;
  24. public function init()
  25. {
  26. $this->userInfo = Identify::getUserInfo();
  27. }
  28. //处理文档下载请求
  29. public function actionDowndoc()
  30. {
  31. $docConfigResult = Yii::$app->db->createCommand("select * from {{%config}} where name='doc'")->queryOne();
  32. $docConfig = string2array($docConfigResult['value']);
  33. $mimes = getMimes();
  34. $direct = Yii::$app->request->get('direct');
  35. $downcode = Yii::$app->request->get('downcode');
  36. $downcodeModel = \app\modules\doc\models\DocDowncode::find()->where("downcode='".$downcode."'")->one();
  37. if($downcodeModel&&$downcodeModel->doc_id)
  38. {
  39. $doc = DocReal::findOne($downcodeModel->doc_id);
  40. $docData = DocRealData::findOne($downcodeModel->doc_id);
  41. if($doc&&$docData)
  42. {
  43. $downFlag = false;
  44. //普通下载场景需要校验用户
  45. if((!empty($this->userInfo['user_id'])&&$downcodeModel->user_id == $this->userInfo['user_id'])||$direct==1)
  46. {
  47. $downFlag = true;
  48. }
  49. if($downFlag)
  50. {
  51. //生成下载日志
  52. $downlog = DocDownlog::find()->where("user_id=".intval($this->userInfo['user_id'])." and doc_id=".$doc->id)->one();
  53. if($downlog)
  54. {
  55. $downlog->updateCounters(['count'=>1]);
  56. }
  57. else
  58. {
  59. $downlog = new DocDownlog();
  60. $downlog->user_id = intval($this->userInfo['user_id'])?intval($this->userInfo['user_id']):intval($downcodeModel->user_id);
  61. $downlog->doc_id = $doc->id;
  62. $downlog->cat_id = $doc->cat_id;
  63. $downlog->doc_type = $doc->doc_type;
  64. $downlog->count = 1;
  65. $downlog->create_time = TIMESTAMP;
  66. $downlog->save();
  67. }
  68. //更新文档被下载次数
  69. $doc->updateCounters(['downs'=>1]);
  70. //输出文件下载请求
  71. $file = sys_auth($docData->file,'DECODE',$docData->hash);
  72. //对于大文件,生成种子文件
  73. if($doc->filesize>=$docConfig['bigfilesize']*1024*1024)
  74. {
  75. $tempFile = locateFile(getFileUrl($file),'download');
  76. $file = initBigfileTorent($tempFile,$doc,$docConfig);
  77. $bigFileTip = '【下载说明】';
  78. }
  79. else if($doc->doc_type==3)//网盘资源
  80. {
  81. $file = initPanfile($doc,$docConfig);
  82. $bigFileTip = '【提取说明】';
  83. }
  84. else if($doc->doc_type==2)//合辑文档
  85. {
  86. $allsize = 0;
  87. $docIds = Yii::$app->db->createCommand("SELECT doc_id FROM {{%doc_col}} where col_id=".$doc->id)->queryColumn();
  88. $resultList = DocReal::findAll($docIds);
  89. foreach($resultList as $result)
  90. {
  91. $allsize += $result->filesize;
  92. $contentList[] = array('title'=>$result->title,'ext'=>$result->ext,'file'=>sys_auth($result->data->file,'DECODE',$result->data->hash));
  93. }
  94. $tempFile = locateColFile($doc,$contentList);
  95. $file = initBigfileTorent($tempFile,$doc,$docConfig);
  96. $bigFileTip = '【下载说明】';
  97. }
  98. $ext = fileext($file);
  99. $mime = $mimes[$ext];
  100. if(is_array($mime))$mime = $mime[0];
  101. $fileContents = file_get_contents(getFileUrl($file));
  102. $downcodeModel->used = 1;
  103. $downcodeModel->save();
  104. ob_clean();
  105. header("Content-Type: $mime; charset=UTF-8");
  106. if(preg_match("/Safari/", $_SERVER["HTTP_USER_AGENT"]))
  107. {
  108. $filename = rawurlencode($doc->title.$bigFileTip);
  109. $filename = iconv('utf-8', 'gbk', $filename);
  110. header( 'Content-Disposition: attachment; filename*=UTF-8\'\''. $filename.'.'.$ext);
  111. }
  112. else
  113. {
  114. header("Content-Disposition:attachment;filename=".rawurlencode(rtrim($doc->title.$bigFileTip,".")).'.'.$ext);
  115. }
  116. echo $fileContents;
  117. exit;
  118. }
  119. }
  120. }
  121. }
  122. //判断下载请求处理状态
  123. public function actionCheckdown()
  124. {
  125. $downcode = Yii::$app->request->get('downcode');
  126. $downcodeModel = \app\modules\doc\models\DocDowncode::find()->where("downcode='".$downcode."'")->one();
  127. if($downcodeModel->used==1)
  128. {
  129. $result = [
  130. 'error' => 0,
  131. 'msg' => '处理完毕',
  132. 'data' => [],
  133. 'code'=>200
  134. ];
  135. echo_json($result);
  136. }
  137. }
  138. //联动菜单下级数据获取
  139. public function actionNextlinkmenu()
  140. {
  141. $parent_id = isset($_GET['parent_id'])?intval($_GET['parent_id']):0;
  142. if(empty($parent_id))
  143. {
  144. $result = array('error'=>1,'msg'=>'获取失败');
  145. }
  146. else
  147. {
  148. $parentMenu = Linkmenu::findOne($parent_id);
  149. if(empty($parentMenu))
  150. {
  151. $result = array('error'=>1,'msg'=>'获取失败');
  152. }
  153. else
  154. {
  155. $query = Linkmenu::find();
  156. if($parentMenu->key_id==0){
  157. $params =['key_id'=>$parent_id,'parent_id'=>0,'disabled'=>0];
  158. }
  159. else
  160. {
  161. $params =['parent_id'=>$parent_id,'disabled'=>0];
  162. }
  163. $query = mergeParams($query,$params);
  164. $menuList = $query->orderBy(['list_order'=>SORT_ASC])->all();
  165. if(is_array($menuList))foreach($menuList as $menu)
  166. {
  167. $data[] = array('menu_id'=>$menu->menu_id,'name'=>$menu->name);
  168. }
  169. $result = array('error'=>0,'msg'=>'获取成功','data'=>$data);
  170. echo_json($result);
  171. }
  172. }
  173. }
  174. //获取下级栏目
  175. public function actionNextlinkcat()
  176. {
  177. $parent_id = isset($_GET['parent_id'])?intval($_GET['parent_id']):0;
  178. $content_model_id = isset($_GET['content_model_id'])?intval($_GET['content_model_id']):0;
  179. if(empty($parent_id)&&empty($content_model_id))
  180. {
  181. $result = array('error'=>1,'msg'=>'获取失败');
  182. }
  183. else
  184. {
  185. $catList = json_decode(Yii::$app->cache->get(CacheId::categoryItemsCacheId($content_model_id)),true);
  186. $data = [];
  187. if($content_model_id&&empty($parent_id))
  188. {
  189. if(is_array($catList))foreach($catList as $cat)
  190. {
  191. if($cat['parent_id']==0)
  192. {
  193. $data[] = array('cat_id'=>$cat['cat_id'],'cat_name'=>$cat['cat_name']);
  194. }
  195. }
  196. }
  197. else if($content_model_id&&$parent_id)
  198. {
  199. if(is_array($catList))foreach($catList as $cat)
  200. {
  201. if($cat['parent_id']==$parent_id)
  202. {
  203. $data[] = array('cat_id'=>$cat['cat_id'],'cat_name'=>$cat['cat_name']);
  204. }
  205. }
  206. }
  207. $result = array('error'=>0,'msg'=>'获取成功','data'=>$data);
  208. }
  209. echo_json($result);
  210. }
  211. //获取栏目扩展配置
  212. public function actionGetextconfig()
  213. {
  214. $cat_id = isset($_GET['cat_id'])?intval($_GET['cat_id']):0;
  215. $id = isset($_GET['id'])?intval($_GET['id']):0;
  216. $realStr = !empty($_GET['real'])?'_real':'';
  217. if(empty($cat_id))
  218. {
  219. $result = array('error'=>1,'msg'=>'获取失败');
  220. }
  221. else
  222. {
  223. $category = Category::findOne($cat_id);
  224. //栏目面包屑
  225. $catTitTree = [];
  226. $catBreadInfos = Category::getParentCatRs($cat_id);
  227. if(is_array($catBreadInfos))foreach($catBreadInfos as $catBread)
  228. {
  229. $catTitTree[] = $catBread['cat_name'];
  230. }
  231. $catTitTree = join(" > ",$catTitTree);
  232. $model_list = json_decode(Yii::$app->cache->get(\app\common\components\CacheId::modelListCacheId()),true);
  233. $model = $model_list[$category->content_model_id];
  234. $table_1_name = $model['table_name'].$realStr;
  235. $table_2_name = $model['table_name'].$realStr.'_data';
  236. $model_name = getModelName($table_1_name);
  237. if($category->arr_parent_ids)
  238. {
  239. $extTypeList = CategoryConfig::find()->where("cat_id=".$cat_id." or cat_id in(".trim($category->arr_parent_ids,',').")")->orderBy(['cat_id'=>SORT_ASC,'list_order'=>SORT_ASC])->limit(5)->asArray()->all();
  240. }
  241. else
  242. {
  243. $extTypeList = CategoryConfig::find()->where("cat_id=".$cat_id)->orderBy(['cat_id'=>SORT_ASC,'list_order'=>SORT_ASC])->limit(5)->asArray()->all();
  244. }
  245. if($id)
  246. {
  247. $connection = Yii::$app->db;
  248. $sql = "select * from {{%".$table_1_name."}} a left join {{%".$table_2_name."}} b on a.id=b.id where a.id = ".$id."";
  249. $command=$connection->createCommand($sql);
  250. $row=$command->queryOne();
  251. }
  252. else
  253. {
  254. $row = [];
  255. }
  256. if(is_array($extTypeList))foreach($extTypeList as $k=>$ext_type)
  257. {
  258. $simpleField = 'ext_type_'.($k+1);
  259. $ext_type['var_name'] = $simpleField;
  260. $optionList = [];
  261. $field = $model_name?$model_name.'['.$ext_type['var_name'].']':$ext_type['var_name'];
  262. $fieldId = str_replace(array('[',']'),array('-',''),strtolower($field));
  263. $value = $row[$simpleField];
  264. if($ext_type['type']==1)
  265. {
  266. $optionList = string2array($ext_type['value']);
  267. $formlist[] = array(
  268. 'label'=>$ext_type['bak'],
  269. 'html'=> FormElements::select($optionList,$value,"请选择","name='$field' id='$fieldId' lay-ignore class='form-select ' "),
  270. 'optionList'=>$optionList,
  271. 'type'=>$ext_type['type'],
  272. );
  273. }
  274. else if($ext_type['type']==2)
  275. {
  276. $options = string2array($ext_type['value']);
  277. foreach($options as $v)
  278. {
  279. $optionList[$v] = $v;
  280. }
  281. $formlist[] = array(
  282. 'label'=>$ext_type['bak'],
  283. 'html'=> FormElements::select($optionList,$value,"请选择","name='$field' id='$fieldId' lay-ignore class='form-select '"),
  284. 'optionList'=>$optionList,
  285. 'type'=>$ext_type['type'],
  286. );
  287. }
  288. else if($ext_type['type']==3)
  289. {
  290. $sysconfig = Sysconfig::find()->where("name='".$ext_type['value']."'")->one();
  291. if($sysconfig->type==1) $optionList = json_decode($sysconfig->value,true);
  292. if($sysconfig->type==2)
  293. {
  294. $options = json_decode($sysconfig->value,true);
  295. foreach($options as $v)
  296. {
  297. $optionList[$v] = $v;
  298. }
  299. }
  300. $formlist[] = array(
  301. 'label'=>$ext_type['bak'],
  302. 'html'=> FormElements::select($optionList,$value,"请选择","name='$field' id='$fieldId' lay-ignore class='form-select '"),
  303. 'optionList'=>$optionList,
  304. 'type'=>$ext_type['type'],
  305. );
  306. }
  307. else if($ext_type['type']==4)
  308. {
  309. $array = array();
  310. $array['key_id']= $ext_type['value'];
  311. $array['id']= $fieldId;
  312. $array['name']= $field;
  313. $array['level']= $ext_type['level']?$ext_type['level']:2;
  314. $array['emptyTxts']= ['请选择','请选择','请选择'];
  315. if(isset($value))$array['value']= $value;
  316. $array['selectClass']= 'form-select ';
  317. $array['blockClass']= 'mb-3 row';
  318. $array['unitClass']= 'col-md-'.(12/$ext_type['level']);
  319. $array['unitStyle'] = 'padding-right:10px;';
  320. $html = LinkmenuWidget::widget($array);
  321. $formlist[] = array(
  322. 'label'=>$ext_type['bak'],
  323. 'html'=> $html,
  324. 'optionList'=>[],
  325. 'type'=>$ext_type['type'],
  326. );
  327. }
  328. }
  329. $result = array('error'=>0,'msg'=>'','data'=>['formlist'=>$formlist,'catTitTree'=>$catTitTree]);
  330. }
  331. echo_json($result);
  332. }
  333. //生成二维码
  334. public function actionQrcode()
  335. {
  336. ob_clean();
  337. $url = $_GET['url'];
  338. $qrcode = new \app\components\qrcode\qrcode($url);
  339. $qrcode->create();
  340. }
  341. //生成含入口脚本的URL地址
  342. public function createRealUrl($params)
  343. {
  344. return urldecode(Yii::$app->urlManager->createAbsoluteUrl($params)) ;
  345. }
  346. //记录显示模式
  347. public function actionSetshowmode()
  348. {
  349. $showmode = $_GET['showmode'];
  350. $pageflag = $_GET['pageflag'];
  351. if(!empty($showmode)&&!empty($pageflag))
  352. {
  353. Cookie::setCookie($pageflag,$showmode);
  354. }
  355. }
  356. //处理前台加载文档页面
  357. public function actionLoaddocpage()
  358. {
  359. ini_set('pcre.backtrack_limit', 999999999);
  360. $page = Yii::$app->request->get('page');
  361. $type = Yii::$app->request->get('type');
  362. $id = Yii::$app->request->get('id');
  363. if(!empty($page)&&!empty($type)&&!empty($id))
  364. {
  365. $docData = DocRealData::findOne($id);
  366. //文档内容
  367. $imgcode = string2array($docData->imgcode);
  368. $h5code = string2array($docData->h5code);
  369. if($type=='h5')
  370. {
  371. $result = https_request(getFileUrl($h5code[$page]));
  372. //过滤时段
  373. $badwordConfigResult = Yii::$app->db->createCommand("select * from {{%config}} where name='badword'")->queryOne();
  374. $badwordConfig = string2array($badwordConfigResult['value']);
  375. $filter = true;
  376. $hournow = get_date(TIMESTAMP,'H');
  377. if($badwordConfig['hours'])
  378. {
  379. $hours = explode(",",$badwordConfig['hours']);
  380. if(!in_array($hournow,$hours))
  381. {
  382. $filter = false;
  383. }
  384. }
  385. //爬虫过滤
  386. if(isSpider()&&!$badwordConfig['open_spider'])
  387. {
  388. $filter = false;
  389. }
  390. if($filter)
  391. {
  392. $sesResult = sensitive($result);
  393. if(!empty($sesResult['after']))
  394. {
  395. $result = $sesResult['after'];
  396. }
  397. }
  398. }
  399. else
  400. {
  401. $result = "<img class='imgmode_unit' src='".getFileUrl($imgcode[$page-1])."'>";
  402. }
  403. echo_json(array('error'=>'0','msg'=>'获取成功','data'=>$result));
  404. }
  405. }
  406. //处理前台加载文档页面
  407. public function actionLoaddocpagedirect()
  408. {
  409. ini_set('pcre.backtrack_limit', 999999999);
  410. $page = Yii::$app->request->get('page');
  411. $type = Yii::$app->request->get('type');
  412. $id = Yii::$app->request->get('id');
  413. if(!empty($page)&&!empty($type)&&!empty($id))
  414. {
  415. $docData = DocRealData::findOne($id);
  416. //文档内容
  417. $imgcode = string2array($docData->imgcode);
  418. $h5code = string2array($docData->h5code);
  419. if($type=='h5')
  420. {
  421. $result = https_request(getFileUrl($h5code[$page]));
  422. //过滤时段设置
  423. $badwordConfigResult = Yii::$app->db->createCommand("select * from {{%config}} where name='badword'")->queryOne();
  424. $badwordConfig = string2array($badwordConfigResult['value']);
  425. $filter = true;
  426. $hournow = get_date(TIMESTAMP,'H');
  427. if($badwordConfig['hours'])
  428. {
  429. $hours = explode(",",$badwordConfig['hours']);
  430. if(!in_array($hournow,$hours))
  431. {
  432. $filter = false;
  433. }
  434. }
  435. //爬虫过滤
  436. if(isSpider()&&!$badwordConfig['open_spider'])
  437. {
  438. $filter = false;
  439. }
  440. if($filter)
  441. {
  442. $sesResult = sensitive($result);
  443. if(!empty($sesResult['after']))
  444. {
  445. $result = $sesResult['after'];
  446. }
  447. }
  448. }
  449. else
  450. {
  451. $result = "<img class='imgmode_unit' src='".getFileUrl($imgcode[$page-1])."'>";
  452. }
  453. echo $result;
  454. exit;
  455. }
  456. }
  457. //处理前台加载多媒体文档数据
  458. public function actionLoaddocblob()
  459. {
  460. $id = Yii::$app->request->get('id');
  461. if(!empty($id))
  462. {
  463. $docData = DocRealData::findOne($id);
  464. //文档内容
  465. $h5code = string2array($docData->h5code);
  466. $media_file = getFileUrl($h5code[0]);
  467. ob_clean();
  468. echo https_request($media_file);
  469. }
  470. }
  471. //访问记录
  472. public function actionVisitrecord()
  473. {
  474. $table_name = Yii::$app->request->get('table_name');
  475. $data_id = Yii::$app->request->get('data_id');
  476. $cat_id = Yii::$app->request->get('cat_id');
  477. if(!empty($table_name)&&!empty($data_id))
  478. {
  479. $tableLogDate = Yii::$app->db->tablePrefix."visit_record_".date('Ymd');
  480. $preLogTable = Yii::$app->db->tablePrefix."visit_record_".date('Ymd',TIMESTAMP-24*3600);
  481. $sqlbuf = "show tables like '".$tableLogDate."';";
  482. $result = Yii::$app->db->createCommand($sqlbuf)->queryOne();
  483. if(!$result)
  484. {
  485. $sqlbuf = "create table if not exists $tableLogDate like {{%visit_record_t}};";
  486. Yii::$app->db->createCommand($sqlbuf)->execute();
  487. $sqlbuf = "show tables like '".$preLogTable."';";
  488. $exist = Yii::$app->db->createCommand($sqlbuf)->queryAll();
  489. if($exist)
  490. {
  491. $sqlbuf = "drop table $preLogTable;";
  492. Yii::$app->db->createCommand($sqlbuf)->execute();
  493. }
  494. }
  495. $visit_ip = MYIP;
  496. $visit_time = TIMESTAMP;
  497. $request_from = REQUEST_FROM;
  498. $sqlbuf="insert into $tableLogDate(table_name,data_id,cat_id,request_from,visit_ip,visit_time)values('".$table_name."',$data_id,$cat_id,$request_from,$visit_ip,$visit_time)";
  499. Yii::$app->db->createCommand($sqlbuf)->execute();
  500. $date = str_to_time(get_date(TIMESTAMP,'Y-m-d'));
  501. $stModel = VisitStatisticsByDay::find()->where("table_name='".$table_name."' and data_id = $data_id and date='".$date."'")->one();
  502. if(empty($stModel))
  503. {
  504. $stModel = new VisitStatisticsByDay();
  505. $stModel->table_name = $table_name;
  506. $stModel->data_id = $data_id;
  507. $stModel->cat_id = $cat_id;
  508. $stModel->date = $date;
  509. $stModel->pv=1;
  510. $stModel->uv=1;
  511. $stModel->save();
  512. }
  513. else
  514. {
  515. $sqlbuf = "select count(distinct(visit_ip)) as uv from $tableLogDate where table_name='".$table_name."' and data_id = $data_id";
  516. $result = Yii::$app->db->createCommand($sqlbuf)->queryOne();
  517. $uv = $result['uv'];
  518. $stModel->uv = $uv;
  519. $stModel->pv = $stModel->pv+1;
  520. $stModel->save();
  521. }
  522. //查询数据表主键
  523. $primaryKey = getPrikeyByTableName($table_name);
  524. if($primaryKey)
  525. {
  526. $sqlbuf = "update {{%$table_name}} set views=views+1 where $primaryKey = $data_id";
  527. Yii::$app->db->createCommand($sqlbuf)->execute();
  528. }
  529. //写历史记录
  530. if($table_name&&Identify::hasLogined())
  531. {
  532. $history = new UserHistory();
  533. $history->table_name = $table_name;
  534. $history->data_id = $data_id;
  535. $history->user_id = Identify::getUserInfo(NULL,'user_id');
  536. $history->create_time = TIMESTAMP;
  537. $history->save();
  538. }
  539. }
  540. }
  541. //根据车牌搜索车辆
  542. public function actionSearchcar()
  543. {
  544. $kw = Yii::$app->request->get('kw');
  545. $city1 = Yii::$app->request->get('city1');
  546. $city2 = Yii::$app->request->get('city2');
  547. $city3 = Yii::$app->request->get('city3');
  548. $params = [];
  549. $sql = "select card_num from wz_f_car_info ";
  550. if(!empty($kw)) $params[] = "card_num like '%".$kw."%'";
  551. if(!empty($city1) && $city1!='全省') $params[] = "city = '".$city1."'";
  552. if(!empty($city2) && $city2!='地市') $params[] = "dpt_sec = '".$city2."'";
  553. if(!empty($city3) && $city3!='网格') $params[] = "grid = '".$city3."'";
  554. if($params) $sql .= " where ".implode(' and ',$params);
  555. $sql .= "group by card_num limit 20";
  556. //if(!empty($kw))
  557. //{
  558. $resultList = Yii::$app->db->createCommand($sql)->queryAll();
  559. foreach($resultList as $result)
  560. {
  561. $carList[] = $result['card_num'];
  562. }
  563. $result = [
  564. 'error' => 0,
  565. 'msg' => '搜索成功',
  566. 'data' => ['carList'=>$carList],
  567. 'code'=>200
  568. ];
  569. echo_json($result);
  570. //}
  571. }
  572. //下拉车牌搜索
  573. public function actionSelectcar()
  574. {
  575. $kw = Yii::$app->request->post('card_num');
  576. $city1 = Yii::$app->request->post('city1');
  577. $city2 = Yii::$app->request->post('city2');
  578. $city3 = Yii::$app->request->post('city3');
  579. $page = Yii::$app->request->post('pageNumber')?:1;
  580. $pagesize = Yii::$app->request->post('pageSize')?:10;
  581. $params = [];
  582. if(empty($kw)) $kw = Yii::$app->request->post('searchValue');
  583. //$sql = "select card_num from wz_f_car_info ";
  584. if(!empty($kw)) $params[] = "card_num like '%".strtoupper($kw)."%'";
  585. $ci = ['全省','地市','网格','单位','一级单位','二级单位','三级单位'];
  586. if(!empty($city1) && !in_array($city1,$ci)) $params[] = "city = '".$city1."'";
  587. if(!empty($city2) && !in_array($city2,$ci)) $params[] = "dpt_sec = '".$city2."'";
  588. if(!empty($city3) && !in_array($city3,$ci)) $params[] = "grid = '".$city3."'";
  589. //if($params) $sql .= " where ".implode(' and ',$params);
  590. $query = FCarInfo::find()->select('card_num')->where(join(' and ',$params))->groupBy('card_num');
  591. $countQuery = clone $query;
  592. $resultList = $query->limit(intval($pagesize))->offset(intval(($page-1)*$pagesize))->orderBy(['card_num' => SORT_DESC])->asArray()->all();
  593. $result = [
  594. 'error' => 0,
  595. 'msg' => '搜索成功',
  596. 'totalRow' => $countQuery->count(),
  597. 'list' => $resultList,
  598. 'code'=>200
  599. ];
  600. echo_json($result);
  601. //}
  602. }
  603. }