您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

865 行
28 KiB

  1. <?php
  2. namespace backend\modules\zzcs\models;
  3. use Yii;
  4. use yii\base\Exception;
  5. use yii\db\ActiveRecord;
  6. /**
  7. * This is the model class for table "base_area".
  8. *
  9. * @property integer $ID
  10. * @property integer $PARENT_ID
  11. * @property integer $CANCEL_FLAG
  12. * @property integer $CREATE_USER_ID
  13. * @property string $CREATE_TIME
  14. * @property integer $UPDATE_USER_ID
  15. * @property string $UPDATE_TIME
  16. * @property string $AREA_NAME
  17. * @property string $POSTCODE
  18. * @property string $POI_TYPE
  19. * @property integer $POI_TYPE1
  20. * @property string $POI_TYPE2
  21. */
  22. class BaseArea extends ActiveRecord
  23. {
  24. /**
  25. * @inheritdoc
  26. */
  27. public static function tableName()
  28. {
  29. return 'base_area';
  30. }
  31. /**
  32. * @return \yii\db\Connection the database connection used by this AR class.
  33. */
  34. public static function getDb()
  35. {
  36. return Yii::$app->get('db');
  37. }
  38. /**
  39. * @inheritdoc
  40. */
  41. public function rules()
  42. {
  43. return [
  44. [['ID', 'UPDATE_TIME', 'AREA_NAME'], 'required'],
  45. [['ID', 'PARENT_ID', 'CANCEL_FLAG', 'CREATE_USER_ID', 'UPDATE_USER_ID', 'POI_TYPE1'], 'integer'],
  46. [['CREATE_TIME', 'UPDATE_TIME', 'POSTCODE', 'POI_TYPE'], 'string', 'max' => 20],
  47. [['AREA_NAME'], 'string', 'max' => 100],
  48. [['POI_TYPE2'], 'string', 'max' => 255],
  49. ];
  50. }
  51. /**
  52. * @inheritdoc
  53. */
  54. public function attributeLabels()
  55. {
  56. return [
  57. 'ID' => 'ID',
  58. 'PARENT_ID' => 'Parent ID',
  59. 'CANCEL_FLAG' => 'Cancel Flag',
  60. 'CREATE_USER_ID' => 'Create User ID',
  61. 'CREATE_TIME' => 'Create Time',
  62. 'UPDATE_USER_ID' => 'Update User ID',
  63. 'UPDATE_TIME' => 'Update Time',
  64. 'AREA_NAME' => 'Area Name',
  65. 'POSTCODE' => 'Postcode',
  66. 'POI_TYPE' => 'Poi Type',
  67. 'POI_TYPE1' => 'Poi Type1',
  68. 'POI_TYPE2' => 'Poi Type2',
  69. ];
  70. }
  71. /**
  72. * Function Description:获取区域\站点列表
  73. * Function Name: getStationList
  74. *
  75. * @param int $station_type 类别
  76. * @param string $station_name 名称
  77. * @param int $range 区域
  78. * @param int $poi_type 类型
  79. * @param int $page_size 每页条数
  80. * @param int $current_page 当前页
  81. *
  82. * @return mixed
  83. *
  84. * @author 张帅
  85. */
  86. public function getStationList($station_type = -1, $station_name = '', $poi_type = -1, $range = -1,$use_status = -1 , $page_size = 10, $current_page = 1)
  87. {
  88. #region 1.查询条件
  89. $sql_having='';
  90. $sql_where = [];
  91. $sql_where[] = 'and';
  92. //筛掉删除后的
  93. $sql_where[] = ['=', 'a.cancel_flag', 0];
  94. //poi类别(区域/站点)
  95. if ($station_type != -1) {
  96. $sql_where[] = ['=', 'a.poi_type1', $station_type];
  97. }
  98. //poi名称
  99. if ($station_name != '') {
  100. $sql_where[] = ['like', 'a.area_name', $station_name];
  101. }
  102. //区域
  103. if ($range != -1) {
  104. $sql_where[] = ['or', ['=', 'a.id', $range], ['like', 'v.parent_area_id_list', '{' . $range . '}']];
  105. }
  106. //poi类型
  107. if ($poi_type != -1) {
  108. $sql_where[] = ['like', 'a.poi_type2', $poi_type];
  109. }
  110. //使用状态
  111. if($use_status==0){
  112. $sql_having= 'use_count = 0';
  113. $sql_where[] = ['=', 'a.poi_type1', 402];
  114. }
  115. if($use_status ==1){
  116. $sql_where[]= ['>','c.cnt',0];
  117. $sql_where[] = ['=', 'a.poi_type1', 402];
  118. }
  119. $offset = ($current_page - 1) * $page_size;
  120. #endregion
  121. $today = date('Y-m-d');
  122. $select=[
  123. 'area_id'=>'a.id',
  124. 'a.area_name',
  125. 'v.parent_area_id_list',
  126. 'a.poi_type1',
  127. 'a.poi_type2',
  128. 'use_count'=>'ifnull(c.cnt,0)',
  129. ];
  130. #region 2.查询数据
  131. $rows = self::find()->select($select)
  132. ->from('base_area as a')
  133. ->leftJoin('base_area_view as v', 'a.id = v.area_id')
  134. ->leftJoin("(SELECT
  135. count(r.RUN_ID) as cnt,STATION_RES_ID,AREA_ID
  136. FROM run_station AS s
  137. INNER JOIN run_main AS r ON s.RUN_ID = r.run_id
  138. WHERE r.RUN_DATE >= $today
  139. AND r.RUN_STATUS IN (137, 138, 139, 286)
  140. GROUP BY STATION_RES_ID) as c",'a.id=c.STATION_RES_ID')
  141. ->where($sql_where)
  142. ->orderBy(['a.update_time' => SORT_DESC, 'a.poi_type1' => SORT_ASC, 'v.area_level' => SORT_ASC])
  143. ->having($sql_having)
  144. ->offset($offset)
  145. ->limit($page_size)
  146. // ->createCommand()->getRawSql();
  147. ->asArray()
  148. ->all();
  149. #endregion
  150. #region 3.获取全部的poi数据并第一次整理数组
  151. $parent_area_id_arr = [];
  152. foreach ($rows as $key => $vel) {
  153. //站点/区域id
  154. $area_one['station_id'] = $vel['area_id'];
  155. //站点/区域类别
  156. $area_one['station_type'] = $vel['poi_type1'];
  157. //站点是否被使用
  158. $area_one['use_count'] = $vel['use_count'];
  159. //区域 、站点
  160. $parent_area_id_list = substr($vel['parent_area_id_list'], 1, -1);
  161. if ($vel['poi_type1'] == 401) {
  162. if ($vel['parent_area_id_list'] == '') {
  163. $area_one['range'] = [$vel['area_id']];
  164. } else {
  165. $area_one['range'] = array_merge(explode('}{', $parent_area_id_list), [$vel['area_id']]);
  166. }
  167. $area_one['station'] = [];
  168. } else {
  169. $area_one['range'] = explode('}{', $parent_area_id_list);
  170. $area_one['station']['area_id'] = $vel['area_id'];
  171. $area_one['station']['area_name'] = $vel['area_name'];
  172. }
  173. //区域/站点类型
  174. $poi_type_one = substr($vel['poi_type2'], 1, -1);
  175. if ($poi_type_one == '') {
  176. $area_one['poi_type'] = [];
  177. } else {
  178. $area_one['poi_type'] = explode('}{', $poi_type_one);
  179. }
  180. //获取所有的父节点id
  181. foreach ($area_one['range'] as $range_k => $range_v) {
  182. if (!isset($parent_area_id_arr[$range_v])) {
  183. $parent_area_id_arr[$range_v] = $range_v;
  184. }
  185. }
  186. $rows[$key] = $area_one;
  187. }
  188. #endregion
  189. #region 4.所有父节点的详情
  190. $parent_area_arr_row = self::find()->select('id as area_id,area_name,poi_type1 as station_type')
  191. ->where(['in', 'id', $parent_area_id_arr])
  192. ->asArray()
  193. ->all();
  194. foreach ($parent_area_arr_row as $key => $value) {
  195. $parent_area_arr[$value['area_id']] = $value;
  196. }
  197. #endregion
  198. #region 5.获取所有的dict_type
  199. $poi_type_row = DictType::find()->select('id as station_type_id,type_name as station_type_name')
  200. ->where(['parent_id' => 403])
  201. ->asArray()
  202. ->all();
  203. foreach ($poi_type_row as $key => $value) {
  204. $poi_type_all[$value['station_type_id']] = $value;
  205. }
  206. #endregion
  207. #region 6.将详情扔回$rows
  208. foreach ($rows as $area_key => $area_vel) {
  209. $range_one = [];
  210. //扔入区域数据
  211. if (count($area_vel['range']) != 0) {
  212. foreach ($area_vel['range'] as $range_key => $range_vel) {
  213. if (isset($parent_area_arr[$range_vel])) {
  214. $range_one[$range_key] = $parent_area_arr[$range_vel];
  215. }
  216. }
  217. }
  218. //扔入详情
  219. $poi_type_one = [];
  220. if (count($area_vel['poi_type']) != 0) {
  221. foreach ($area_vel['poi_type'] as $poi_type_key => $poi_type_vel) {
  222. if (isset($poi_type_all[$poi_type_vel])) {
  223. $poi_type_one[$poi_type_key] = $poi_type_all[$poi_type_vel];
  224. }
  225. }
  226. }
  227. $rows[$area_key]['range'] = $range_one;
  228. $rows[$area_key]['poi_type'] = $poi_type_one;
  229. }
  230. #endregion
  231. #region 7.获取分页
  232. $total_row = self::find()
  233. ->select($select)
  234. ->from('base_area as a')
  235. ->leftJoin('base_area_view as v', 'a.id = v.area_id')
  236. ->leftJoin("(SELECT
  237. count(r.RUN_ID) as cnt,AREA_ID
  238. FROM run_station AS s
  239. INNER JOIN run_main AS r ON s.RUN_ID = r.run_id
  240. WHERE r.RUN_DATE >= $today
  241. AND r.RUN_STATUS IN (137, 138, 139, 286)
  242. GROUP BY area_id) as c",'a.id=c.area_id')
  243. ->where($sql_where)
  244. ->orderBy(['a.poi_type1' => SORT_ASC, 'v.area_level' => SORT_ASC])
  245. ->having($sql_having)
  246. ->count();
  247. $page_arr = $this->getPage($total_row, $page_size, $current_page);
  248. #endregion
  249. $data['rows'] = $rows;
  250. $data['page_arr'] = $page_arr;
  251. $data['page']['page_size'] = $page_size;
  252. $data['page']['current_page'] = $current_page;
  253. $data['page']['total_row'] = $total_row;
  254. $data['page']['total_page'] = ceil($total_row / $page_size);
  255. return $data;
  256. }
  257. /**
  258. * Function Description:获取分页数组
  259. * Function Name: getPage
  260. *
  261. * @param int $total_row 总条数
  262. * @param int $page_size 每页条数
  263. * @param int $current_page 当前页
  264. *
  265. * @return array
  266. *
  267. * @author 张帅
  268. */
  269. public function getPage($total_row, $page_size, $current_page)
  270. {
  271. $total_page = ceil($total_row / $page_size);
  272. if ($total_page <= 1) {
  273. $page_arr = [];
  274. return $page_arr;
  275. }
  276. #region 页首
  277. $page_arr = ['首页', '<上一页', 1];
  278. #endregion
  279. #region 页前
  280. if ($current_page <= 5) {
  281. for ($i = 2; $i <= $current_page; $i++) {
  282. $page_arr[] = $i;
  283. }
  284. } else {
  285. if ($total_page > 6) {
  286. $page_arr[] = '...';
  287. }
  288. if ($total_page - $current_page <= 2) {
  289. for ($i = $total_page - 4; $i <= $current_page; $i++) {
  290. $page_arr[] = $i;
  291. }
  292. } else {
  293. $page_arr[] = $current_page - 2;
  294. $page_arr[] = $current_page - 1;
  295. $page_arr[] = $current_page;
  296. }
  297. }
  298. #endregion
  299. #region 页后
  300. if ($total_page - $current_page <= 4) {
  301. for ($i = $current_page + 1; $i < $total_page; $i++) {
  302. $page_arr[] = $i;
  303. }
  304. } else {
  305. if ($current_page >= 3) {
  306. $page_arr[] = $current_page + 1;
  307. $page_arr[] = $current_page + 2;
  308. if ($total_page > 6) {
  309. $page_arr[] = '...';
  310. }
  311. } else {
  312. for ($i = $current_page + 1; $i <= 5; $i++) {
  313. $page_arr[] = $i;
  314. }
  315. if ($total_page > 6) {
  316. $page_arr[] = '...';
  317. }
  318. }
  319. }
  320. #endregion
  321. #region 页尾
  322. if ($current_page != $total_page) {
  323. $page_arr[] = $total_page;
  324. }
  325. $page_arr[] = '下一页>';
  326. $page_arr[] = '末页';
  327. #endregion
  328. return $page_arr;
  329. }
  330. /**
  331. * Function Description:添加正式区域
  332. * Function Name: addRange
  333. *
  334. * @param string $station_name 区域名称
  335. * @param string $range 所属区域
  336. * @param string $poi_type poi类型
  337. *
  338. * @return mixed
  339. *
  340. * @author 张帅
  341. */
  342. public function addRange($station_name, $range, $poi_type)
  343. {
  344. #region 判断权限
  345. //获取cookies
  346. $cookies = Yii::$app->request->cookies;
  347. //账号权限
  348. $user_id = $cookies->getValue('user_id');
  349. $user_rule = $cookies->getValue('ht_user_role');
  350. if ($user_rule != 0) {
  351. $json['code'] = '1';
  352. $json['info'] = '无权限';
  353. return $json;
  354. }
  355. #endregion
  356. //1.获取base_area最大的id
  357. $id = self::find()->max('id');
  358. $id++;
  359. #region base_area表数据
  360. $base_area_values = [
  361. 'ID' => $id,
  362. 'PARENT_ID' => $range,
  363. 'CREATE_USER_ID' => $user_id,
  364. 'CREATE_TIME' => date('Y-m-d H:i:s', time()),
  365. 'UPDATE_USER_ID' => $user_id,
  366. 'UPDATE_TIME' => date('Y-m-d H:i:s', time()),
  367. 'CANCEL_FLAG' => 0,
  368. 'AREA_NAME' => $station_name,
  369. 'POI_TYPE1' => 401,
  370. 'POI_TYPE2' => $poi_type
  371. ];
  372. #endregion
  373. $transaction = Yii::$app->db->beginTransaction();
  374. try {
  375. //2.将数据存入base_area表
  376. $this->attributes = $base_area_values;
  377. $res = $this->insert();
  378. if (!$res) {
  379. throw new Exception('base_area插入出错');
  380. }
  381. //3.更新base_area_view
  382. $sql = 'call SP_MAKE_BASE_AREA_VIEW()';
  383. $res = Yii::$app->db->createCommand($sql)->execute();
  384. if (false === $res) {
  385. throw new Exception('更新base_area_view出错');
  386. }
  387. $transaction->commit();
  388. $json['code'] = '0';
  389. $json['info'] = '添加区域成功';
  390. $json['area_id'] = $id;
  391. } catch (Exception $e) {
  392. # 回滚事务
  393. $json['code'] = '1';
  394. $json['info'] = $e->getMessage();
  395. }
  396. return $json;
  397. }
  398. /**
  399. * Function Description:修改正式区域
  400. * Function Name: updateRange
  401. *
  402. * @param int $station_id 区域id
  403. * @param string $station_name 区域名称
  404. * @param string $range 所属区域
  405. * @param string $poi_type poi类型
  406. *
  407. * @return mixed
  408. *
  409. * @author 张帅
  410. */
  411. public function updateRange($station_id, $station_name, $range, $poi_type)
  412. {
  413. #region 判断权限
  414. //获取cookies
  415. $cookies = Yii::$app->request->cookies;
  416. //账号权限
  417. $user_id = $cookies->getValue('user_id');
  418. $user_rule = $cookies->getValue('ht_user_role');
  419. if ($user_rule != 0) {
  420. $json['code'] = '1';
  421. $json['info'] = '无权限';
  422. return $json;
  423. }
  424. #endregion
  425. #region base_area表数据
  426. $base_area_values = [
  427. 'PARENT_ID' => $range,
  428. 'UPDATE_USER_ID' => $user_id,
  429. 'UPDATE_TIME' => date('Y-m-d H:i:s', time()),
  430. 'AREA_NAME' => $station_name,
  431. 'POI_TYPE2' => $poi_type
  432. ];
  433. #endregion
  434. $transaction = Yii::$app->db->beginTransaction();
  435. try {
  436. //1.修改base_area表
  437. $base_area_one = self::findOne(['id' => $station_id, 'cancel_flag' => 0]);
  438. $base_area_one->attributes = $base_area_values;
  439. $res = $base_area_one->update();
  440. if (!$res) {
  441. throw new Exception('输入数据不符合格式');
  442. }
  443. //2.更新base_area_view
  444. $sql = 'call SP_MAKE_BASE_AREA_VIEW()';
  445. $res = Yii::$app->db->createCommand($sql)->execute();
  446. if (false === $res) {
  447. throw new Exception('输入数据不符合格式');
  448. }
  449. $transaction->commit();
  450. $json['code'] = '0';
  451. $json['info'] = '修改区域成功';
  452. } catch (Exception $e) {
  453. # 回滚事务
  454. $json['code'] = '1';
  455. $json['info'] = $e->getMessage();
  456. }
  457. return $json;
  458. }
  459. /**
  460. * Function Description:获取区域详情及配置包
  461. * Function Name: getStationInfo
  462. *
  463. * @param int $station_id 区域id
  464. *
  465. * @return array
  466. *
  467. * @author 张帅
  468. */
  469. public function getStationInfo($station_id)
  470. {
  471. #region 1.数据库获取详情
  472. $station_info_db = self::find()
  473. ->select('a.area_name,a.poi_type2,v.parent_area_id_list')
  474. ->from('base_area as a')
  475. ->leftJoin('base_area_view as v', 'a.id = v.area_id')
  476. ->where([
  477. 'and',
  478. ['=', 'a.id', $station_id],
  479. ['=', 'a.cancel_flag', 0]
  480. ])
  481. ->asArray()
  482. ->one();
  483. #endregion
  484. #region 2.整理数据
  485. $station_info = [];
  486. $station_info['station_id'] = $station_id;//站点id
  487. $station_info['station_name'] = $station_info_db['area_name'];//站点名称
  488. //poi类型
  489. if ($station_info_db['poi_type2'] != '0') {
  490. $poi_type_arr = substr($station_info_db['poi_type2'], 1, -1);
  491. $poi_type_arr = explode('}{', $poi_type_arr);
  492. } else {
  493. $poi_type_arr = [];
  494. }
  495. $station_info['poi_type_arr'] = $poi_type_arr;
  496. //父节点数组
  497. if (!empty($station_info_db['parent_area_id_list'])) {
  498. $station_parent_list_arr = substr($station_info_db['parent_area_id_list'], 1, -1);
  499. $station_parent_list_arr = explode('}{', $station_parent_list_arr);
  500. $station_info['range_arr'] = $station_parent_list_arr;
  501. #region 查询下拉列表
  502. $rang_list = BaseArea::find()
  503. ->select('id as area_id,area_name,parent_id')
  504. ->where([
  505. 'and',
  506. ['in', 'parent_id', $station_parent_list_arr],
  507. ['=', 'cancel_flag', 0],
  508. ['=', 'poi_type1', 401]
  509. ])
  510. ->asArray()
  511. ->all();
  512. $rang_list_arr = [];
  513. foreach ($rang_list as $rang_key => $range_vel) {
  514. $rang_list_arr[$range_vel['parent_id']][$range_vel['area_id']]['area_id'] = $range_vel['area_id'];
  515. $rang_list_arr[$range_vel['parent_id']][$range_vel['area_id']]['area_name'] = $range_vel['area_name'];
  516. }
  517. $station_info['rang_list_arr'] = $rang_list_arr;
  518. #endregion
  519. } else {
  520. $station_info['range_arr'] = [];
  521. $station_info['rang_list_arr'] = [];
  522. }
  523. #endregion
  524. #endregion
  525. return $station_info;
  526. //echo '<pre>';print_r($station_info);die;
  527. }
  528. /**
  529. * Function Description:获取展示区域的数据
  530. * Function Name: getShowStationInfo
  531. *
  532. * @param int $station_id 区域id
  533. *
  534. * @return array
  535. *
  536. * @author 张帅
  537. */
  538. public function getShowStationInfo($station_id)
  539. {
  540. #region 1.数据库获取详情
  541. $station_info_db = self::find()
  542. ->select('a.area_name,a.poi_type2,v.parent_area_id_list,v.parent_area_name_list')
  543. ->from('base_area as a')
  544. ->leftJoin('base_area_view as v', 'a.id = v.area_id')
  545. ->where([
  546. 'and',
  547. ['=', 'a.id', $station_id],
  548. ['=', 'a.cancel_flag', 0]
  549. ])
  550. ->asArray()
  551. ->one();
  552. #endregion
  553. #region 2.整理数据
  554. $station_info = [];
  555. $station_info['station_id'] = $station_id;//站点id
  556. $station_info['station_name'] = $station_info_db['area_name'];//站点名称
  557. //poi类型
  558. if ($station_info_db['poi_type2'] != '0') {
  559. $poi_type_arr = substr($station_info_db['poi_type2'], 1, -1);
  560. $poi_type_arr = explode('}{', $poi_type_arr);
  561. #region 获取poi类型的名称
  562. $poi_type_arr = DictType::find()
  563. ->select('id as station_type_id,type_name as station_type_name')
  564. ->where([
  565. 'and',
  566. ['in', 'id', $poi_type_arr]
  567. ])->asArray()->all();
  568. #endregion
  569. } else {
  570. $poi_type_arr = [];
  571. }
  572. $station_info['poi_type_arr'] = $poi_type_arr;
  573. //父节点数组
  574. $rang_list_arr = [];
  575. if (!empty($station_info_db['parent_area_id_list'])) {
  576. $station_parent_id_list_arr = substr($station_info_db['parent_area_id_list'], 1, -1);
  577. $station_parent_id_list_arr = explode('}{', $station_parent_id_list_arr);
  578. $station_parent_name_list_arr = substr($station_info_db['parent_area_name_list'], 1, -1);
  579. $station_parent_name_list_arr = explode('}{', $station_parent_name_list_arr);
  580. foreach ($station_parent_id_list_arr as $key => $value) {
  581. $rang_list_arr[$key]['area_id'] = $value;
  582. $rang_list_arr[$key]['area_name'] = $station_parent_name_list_arr[$key];
  583. }
  584. }
  585. $station_info['range_arr'] = $rang_list_arr;
  586. return $station_info;
  587. }
  588. /**
  589. * Function Description:删除区域或站点
  590. * Function Name: deleteStation
  591. *
  592. * @param int $station_id 区域id
  593. *
  594. * @return mixed
  595. *
  596. * @author 张帅
  597. */
  598. public function deleteStation($station_id)
  599. {
  600. #region 判断权限
  601. //获取cookies
  602. $cookies = Yii::$app->request->cookies;
  603. //账号权限
  604. $user_id = $cookies->getValue('user_id');
  605. $user_rule = $cookies->getValue('ht_user_role');
  606. if ($user_rule != 0) {
  607. $json['code'] = '1';
  608. $json['info'] = '无权限';
  609. return $json;
  610. }
  611. #endregion
  612. #region 1.查询区域或站点是否为其他区域或站点的父节点
  613. $count = BaseAreaView::find()
  614. ->where([
  615. 'and',
  616. ['like', 'parent_area_id_list', '{' . $station_id . '}']
  617. ])
  618. ->count();
  619. if ($count > 0) {
  620. $json['code'] = '1';
  621. $json['info'] = '该区域或站点有子站点或区域,请删除子站点或区域后再试';
  622. return $json;
  623. }
  624. #endregion
  625. #region 2.删除站点
  626. $transaction = Yii::$app->db->beginTransaction();
  627. try {
  628. //3.修改base_area表
  629. $base_area_one = self::findOne(['id' => $station_id, 'cancel_flag' => 0]);
  630. $base_area_one->attributes = ['CANCEL_FLAG' => '1', 'UPDATE_USER_ID' => $user_id, 'UPDATE_TIME' => date('Y-m-d H:i:s', time())];
  631. $res = $base_area_one->update();
  632. if (!$res) {
  633. throw new Exception('因数据原因,删除站点失败');
  634. }
  635. //4.更新base_area_view
  636. $sql = 'call SP_MAKE_BASE_AREA_VIEW()';
  637. $res = Yii::$app->db->createCommand($sql)->execute();
  638. if (false === $res) {
  639. throw new Exception('因数据原因,删除站点失败');
  640. }
  641. $transaction->commit();
  642. $json['code'] = '0';
  643. $json['info'] = '删除站点成功';
  644. } catch (Exception $e) {
  645. # 回滚事务
  646. $json['code'] = '1';
  647. $json['info'] = $e->getMessage();
  648. }
  649. #endregion
  650. return $json;
  651. }
  652. /**
  653. * Function Description:导出excel
  654. * Function Name: exportExcel
  655. *
  656. * @param string $file_name 文件名
  657. * @param array $data_title 表名
  658. * @param array $data_list 数据
  659. *
  660. * @return string
  661. *
  662. * @author 张帅
  663. */
  664. public function exportExcel($file_name, $data_title, $data_list)
  665. {
  666. ini_set('memory_limit', '1024M');
  667. set_time_limit(60 * 60);
  668. require Yii::getAlias('@backend') . "/common/PHPExcel/PHPExcel.php";
  669. $objPHPExcel = new \PHPExcel(); //实例化PHPExcel类
  670. $objSheet = $objPHPExcel->getActiveSheet(); //获取当前活动sheet的操作对象
  671. $objSheet->setTitle($file_name); //给当前活动sheet的操作对象
  672. $objSheet->mergeCells('A1:O1'); //合并单元格
  673. $objSheet->setCellValue('A1', $file_name);
  674. $objSheet->getStyle('A1:O1')->getFont()->setName('微软雅黑')->setSize(15)->setBold(True);
  675. $objSheet->getStyle('A1:O1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER)->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);;
  676. $objSheet->getStyle('A1:O1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('A6A6A6');
  677. $objSheet->getStyle('A2:O2')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('CCCCCC');
  678. $directory = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
  679. foreach ($data_title as $k => $v) {
  680. $objSheet->setCellValue($directory[$k] . '2', $v);
  681. }
  682. for ($j = 0; $j < count($data_list); $j++) {
  683. $list = array_values($data_list[$j]);
  684. foreach ($list as $k => $v) {
  685. $objSheet->setCellValue($directory[$k] . ($j + 3), $v);
  686. }
  687. }
  688. $objWrite = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); //按照指定格式生成excel文件
  689. ob_start();
  690. $objWrite->save('php://output');
  691. $xlsData = ob_get_contents();
  692. ob_end_clean();
  693. $json["code"] = '0';
  694. $json["file"] = "data:application/vnd.ms-excel;base64," . base64_encode($xlsData);
  695. $json["file_name"] = $file_name;
  696. return json_encode($json);
  697. }
  698. public function getAreaList($area_id)
  699. {
  700. $query = self::find()
  701. ->select(['id as area_id', 'area_name'])
  702. ->where(['and', ['=', 'cancel_flag', 0], ['=', 'parent_id', $area_id], ['in', 'poi_type2', ['0','{630}']], ['=', 'poi_type1', 401]])
  703. ->asArray()
  704. ->all();
  705. return $query;
  706. }
  707. /**
  708. * Function Description:获取地区的名字
  709. * Function Name: getAreaName
  710. * @param $area_id_array
  711. *
  712. * @return array
  713. *
  714. * @author 李健
  715. */
  716. public function getAreaName($area_id_array)
  717. {
  718. $select = [
  719. 'id',
  720. 'area_name'
  721. ];
  722. $where = ['in','id',$area_id_array];
  723. $res = self::find()
  724. ->select($select)
  725. ->from(self::tableName())
  726. ->where($where);
  727. $sql = $res->createCommand()->rawSql;
  728. $data = $res->asArray()->all();
  729. return [
  730. 'sql'=>$sql,
  731. 'data'=>$data
  732. ];
  733. }
  734. /**
  735. * Function Description:获取地区的名字
  736. * Function Name: getArea
  737. * @param $area_id_array
  738. *
  739. * @return array
  740. *
  741. * @author 李健
  742. */
  743. public function getArea($area_id)
  744. {
  745. $select = [
  746. 'id',
  747. 'area_name'
  748. ];
  749. $where = ['=','parent_id',$area_id];
  750. $res = self::find()
  751. ->select($select)
  752. ->from(self::tableName())
  753. ->where($where);
  754. $sql = $res->createCommand()->rawSql;
  755. $data = $res->asArray()->all();
  756. return [
  757. 'sql'=>$sql,
  758. 'data'=>$data
  759. ];
  760. }
  761. /**
  762. * Function Description:获取指定地区信息
  763. * Function Name: getAreaInfo
  764. * @param $area_id
  765. *
  766. * @return array|ActiveRecord[]
  767. *
  768. * @author 李健
  769. */
  770. public function getAreaInfo($area_id)
  771. {
  772. $select = [
  773. 'id',
  774. 'area_name',
  775. 'parent_id'
  776. ];
  777. $where = ['and'];
  778. $where[] = ['=','cancel_flag',0];
  779. $where[] = ['=','id',$area_id];
  780. $res = self::find()->select($select)->from(self::tableName())->where($where)->asArray()->all();
  781. return $res;
  782. }
  783. }