|
- <?php
-
- namespace backend\modules\zzcs\models;
-
- use Yii;
- use yii\base\Exception;
- use yii\db\ActiveRecord;
-
- /**
- * This is the model class for table "base_area".
- *
- * @property integer $ID
- * @property integer $PARENT_ID
- * @property integer $CANCEL_FLAG
- * @property integer $CREATE_USER_ID
- * @property string $CREATE_TIME
- * @property integer $UPDATE_USER_ID
- * @property string $UPDATE_TIME
- * @property string $AREA_NAME
- * @property string $POSTCODE
- * @property string $POI_TYPE
- * @property integer $POI_TYPE1
- * @property string $POI_TYPE2
- */
- class BaseArea extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'base_area';
- }
-
- /**
- * @return \yii\db\Connection the database connection used by this AR class.
- */
- public static function getDb()
- {
- return Yii::$app->get('db');
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['ID', 'UPDATE_TIME', 'AREA_NAME'], 'required'],
- [['ID', 'PARENT_ID', 'CANCEL_FLAG', 'CREATE_USER_ID', 'UPDATE_USER_ID', 'POI_TYPE1'], 'integer'],
- [['CREATE_TIME', 'UPDATE_TIME', 'POSTCODE', 'POI_TYPE'], 'string', 'max' => 20],
- [['AREA_NAME'], 'string', 'max' => 100],
- [['POI_TYPE2'], 'string', 'max' => 255],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ID' => 'ID',
- 'PARENT_ID' => 'Parent ID',
- 'CANCEL_FLAG' => 'Cancel Flag',
- 'CREATE_USER_ID' => 'Create User ID',
- 'CREATE_TIME' => 'Create Time',
- 'UPDATE_USER_ID' => 'Update User ID',
- 'UPDATE_TIME' => 'Update Time',
- 'AREA_NAME' => 'Area Name',
- 'POSTCODE' => 'Postcode',
- 'POI_TYPE' => 'Poi Type',
- 'POI_TYPE1' => 'Poi Type1',
- 'POI_TYPE2' => 'Poi Type2',
- ];
- }
-
- /**
- * Function Description:获取区域\站点列表
- * Function Name: getStationList
- *
- * @param int $station_type 类别
- * @param string $station_name 名称
- * @param int $range 区域
- * @param int $poi_type 类型
- * @param int $page_size 每页条数
- * @param int $current_page 当前页
- *
- * @return mixed
- *
- * @author 张帅
- */
- public function getStationList($station_type = -1, $station_name = '', $poi_type = -1, $range = -1,$use_status = -1 , $page_size = 10, $current_page = 1)
- {
-
- #region 1.查询条件
- $sql_having='';
- $sql_where = [];
- $sql_where[] = 'and';
- //筛掉删除后的
- $sql_where[] = ['=', 'a.cancel_flag', 0];
- //poi类别(区域/站点)
- if ($station_type != -1) {
- $sql_where[] = ['=', 'a.poi_type1', $station_type];
- }
-
- //poi名称
- if ($station_name != '') {
- $sql_where[] = ['like', 'a.area_name', $station_name];
- }
-
- //区域
- if ($range != -1) {
- $sql_where[] = ['or', ['=', 'a.id', $range], ['like', 'v.parent_area_id_list', '{' . $range . '}']];
- }
-
- //poi类型
- if ($poi_type != -1) {
- $sql_where[] = ['like', 'a.poi_type2', $poi_type];
- }
-
- //使用状态
- if($use_status==0){
- $sql_having= 'use_count = 0';
- $sql_where[] = ['=', 'a.poi_type1', 402];
- }
- if($use_status ==1){
- $sql_where[]= ['>','c.cnt',0];
- $sql_where[] = ['=', 'a.poi_type1', 402];
- }
-
- $offset = ($current_page - 1) * $page_size;
- #endregion
- $today = date('Y-m-d');
- $select=[
- 'area_id'=>'a.id',
- 'a.area_name',
- 'v.parent_area_id_list',
- 'a.poi_type1',
- 'a.poi_type2',
- 'use_count'=>'ifnull(c.cnt,0)',
- ];
-
- #region 2.查询数据
- $rows = self::find()->select($select)
- ->from('base_area as a')
- ->leftJoin('base_area_view as v', 'a.id = v.area_id')
- ->leftJoin("(SELECT
- count(r.RUN_ID) as cnt,STATION_RES_ID,AREA_ID
- FROM run_station AS s
- INNER JOIN run_main AS r ON s.RUN_ID = r.run_id
- WHERE r.RUN_DATE >= $today
- AND r.RUN_STATUS IN (137, 138, 139, 286)
- GROUP BY STATION_RES_ID) as c",'a.id=c.STATION_RES_ID')
- ->where($sql_where)
- ->orderBy(['a.update_time' => SORT_DESC, 'a.poi_type1' => SORT_ASC, 'v.area_level' => SORT_ASC])
- ->having($sql_having)
- ->offset($offset)
- ->limit($page_size)
- // ->createCommand()->getRawSql();
- ->asArray()
- ->all();
- #endregion
-
- #region 3.获取全部的poi数据并第一次整理数组
- $parent_area_id_arr = [];
- foreach ($rows as $key => $vel) {
- //站点/区域id
- $area_one['station_id'] = $vel['area_id'];
- //站点/区域类别
- $area_one['station_type'] = $vel['poi_type1'];
- //站点是否被使用
- $area_one['use_count'] = $vel['use_count'];
- //区域 、站点
- $parent_area_id_list = substr($vel['parent_area_id_list'], 1, -1);
- if ($vel['poi_type1'] == 401) {
- if ($vel['parent_area_id_list'] == '') {
- $area_one['range'] = [$vel['area_id']];
- } else {
- $area_one['range'] = array_merge(explode('}{', $parent_area_id_list), [$vel['area_id']]);
- }
- $area_one['station'] = [];
- } else {
- $area_one['range'] = explode('}{', $parent_area_id_list);
- $area_one['station']['area_id'] = $vel['area_id'];
- $area_one['station']['area_name'] = $vel['area_name'];
- }
-
- //区域/站点类型
- $poi_type_one = substr($vel['poi_type2'], 1, -1);
- if ($poi_type_one == '') {
- $area_one['poi_type'] = [];
- } else {
- $area_one['poi_type'] = explode('}{', $poi_type_one);
- }
-
- //获取所有的父节点id
- foreach ($area_one['range'] as $range_k => $range_v) {
- if (!isset($parent_area_id_arr[$range_v])) {
- $parent_area_id_arr[$range_v] = $range_v;
- }
- }
-
- $rows[$key] = $area_one;
- }
- #endregion
-
- #region 4.所有父节点的详情
- $parent_area_arr_row = self::find()->select('id as area_id,area_name,poi_type1 as station_type')
- ->where(['in', 'id', $parent_area_id_arr])
- ->asArray()
- ->all();
- foreach ($parent_area_arr_row as $key => $value) {
- $parent_area_arr[$value['area_id']] = $value;
- }
- #endregion
-
- #region 5.获取所有的dict_type
- $poi_type_row = DictType::find()->select('id as station_type_id,type_name as station_type_name')
- ->where(['parent_id' => 403])
- ->asArray()
- ->all();
- foreach ($poi_type_row as $key => $value) {
- $poi_type_all[$value['station_type_id']] = $value;
- }
- #endregion
-
- #region 6.将详情扔回$rows
- foreach ($rows as $area_key => $area_vel) {
- $range_one = [];
- //扔入区域数据
- if (count($area_vel['range']) != 0) {
- foreach ($area_vel['range'] as $range_key => $range_vel) {
- if (isset($parent_area_arr[$range_vel])) {
- $range_one[$range_key] = $parent_area_arr[$range_vel];
- }
- }
- }
-
- //扔入详情
- $poi_type_one = [];
- if (count($area_vel['poi_type']) != 0) {
- foreach ($area_vel['poi_type'] as $poi_type_key => $poi_type_vel) {
- if (isset($poi_type_all[$poi_type_vel])) {
- $poi_type_one[$poi_type_key] = $poi_type_all[$poi_type_vel];
- }
- }
- }
-
- $rows[$area_key]['range'] = $range_one;
- $rows[$area_key]['poi_type'] = $poi_type_one;
- }
- #endregion
-
- #region 7.获取分页
- $total_row = self::find()
- ->select($select)
- ->from('base_area as a')
- ->leftJoin('base_area_view as v', 'a.id = v.area_id')
- ->leftJoin("(SELECT
- count(r.RUN_ID) as cnt,AREA_ID
- FROM run_station AS s
- INNER JOIN run_main AS r ON s.RUN_ID = r.run_id
- WHERE r.RUN_DATE >= $today
- AND r.RUN_STATUS IN (137, 138, 139, 286)
- GROUP BY area_id) as c",'a.id=c.area_id')
- ->where($sql_where)
- ->orderBy(['a.poi_type1' => SORT_ASC, 'v.area_level' => SORT_ASC])
- ->having($sql_having)
- ->count();
-
- $page_arr = $this->getPage($total_row, $page_size, $current_page);
- #endregion
-
- $data['rows'] = $rows;
- $data['page_arr'] = $page_arr;
- $data['page']['page_size'] = $page_size;
- $data['page']['current_page'] = $current_page;
- $data['page']['total_row'] = $total_row;
- $data['page']['total_page'] = ceil($total_row / $page_size);
- return $data;
- }
-
-
- /**
- * Function Description:获取分页数组
- * Function Name: getPage
- *
- * @param int $total_row 总条数
- * @param int $page_size 每页条数
- * @param int $current_page 当前页
- *
- * @return array
- *
- * @author 张帅
- */
- public function getPage($total_row, $page_size, $current_page)
- {
- $total_page = ceil($total_row / $page_size);
- if ($total_page <= 1) {
- $page_arr = [];
- return $page_arr;
- }
- #region 页首
- $page_arr = ['首页', '<上一页', 1];
- #endregion
-
- #region 页前
- if ($current_page <= 5) {
- for ($i = 2; $i <= $current_page; $i++) {
- $page_arr[] = $i;
- }
- } else {
- if ($total_page > 6) {
- $page_arr[] = '...';
- }
- if ($total_page - $current_page <= 2) {
- for ($i = $total_page - 4; $i <= $current_page; $i++) {
- $page_arr[] = $i;
- }
- } else {
- $page_arr[] = $current_page - 2;
- $page_arr[] = $current_page - 1;
- $page_arr[] = $current_page;
- }
- }
- #endregion
-
- #region 页后
- if ($total_page - $current_page <= 4) {
- for ($i = $current_page + 1; $i < $total_page; $i++) {
- $page_arr[] = $i;
- }
- } else {
- if ($current_page >= 3) {
- $page_arr[] = $current_page + 1;
- $page_arr[] = $current_page + 2;
- if ($total_page > 6) {
- $page_arr[] = '...';
- }
- } else {
- for ($i = $current_page + 1; $i <= 5; $i++) {
- $page_arr[] = $i;
- }
- if ($total_page > 6) {
- $page_arr[] = '...';
- }
- }
- }
- #endregion
-
- #region 页尾
- if ($current_page != $total_page) {
- $page_arr[] = $total_page;
- }
- $page_arr[] = '下一页>';
- $page_arr[] = '末页';
- #endregion
-
- return $page_arr;
- }
-
- /**
- * Function Description:添加正式区域
- * Function Name: addRange
- *
- * @param string $station_name 区域名称
- * @param string $range 所属区域
- * @param string $poi_type poi类型
- *
- * @return mixed
- *
- * @author 张帅
- */
- public function addRange($station_name, $range, $poi_type)
- {
- #region 判断权限
- //获取cookies
- $cookies = Yii::$app->request->cookies;
- //账号权限
- $user_id = $cookies->getValue('user_id');
- $user_rule = $cookies->getValue('ht_user_role');
- if ($user_rule != 0) {
- $json['code'] = '1';
- $json['info'] = '无权限';
- return $json;
- }
- #endregion
-
- //1.获取base_area最大的id
- $id = self::find()->max('id');
- $id++;
-
- #region base_area表数据
- $base_area_values = [
- 'ID' => $id,
- 'PARENT_ID' => $range,
- 'CREATE_USER_ID' => $user_id,
- 'CREATE_TIME' => date('Y-m-d H:i:s', time()),
- 'UPDATE_USER_ID' => $user_id,
- 'UPDATE_TIME' => date('Y-m-d H:i:s', time()),
- 'CANCEL_FLAG' => 0,
- 'AREA_NAME' => $station_name,
- 'POI_TYPE1' => 401,
- 'POI_TYPE2' => $poi_type
- ];
- #endregion
-
- $transaction = Yii::$app->db->beginTransaction();
- try {
- //2.将数据存入base_area表
- $this->attributes = $base_area_values;
- $res = $this->insert();
- if (!$res) {
- throw new Exception('base_area插入出错');
- }
- //3.更新base_area_view
- $sql = 'call SP_MAKE_BASE_AREA_VIEW()';
- $res = Yii::$app->db->createCommand($sql)->execute();
- if (false === $res) {
- throw new Exception('更新base_area_view出错');
- }
-
- $transaction->commit();
- $json['code'] = '0';
- $json['info'] = '添加区域成功';
- $json['area_id'] = $id;
-
- } catch (Exception $e) {
- # 回滚事务
- $json['code'] = '1';
- $json['info'] = $e->getMessage();
- }
- return $json;
- }
-
- /**
- * Function Description:修改正式区域
- * Function Name: updateRange
- *
- * @param int $station_id 区域id
- * @param string $station_name 区域名称
- * @param string $range 所属区域
- * @param string $poi_type poi类型
- *
- * @return mixed
- *
- * @author 张帅
- */
- public function updateRange($station_id, $station_name, $range, $poi_type)
- {
- #region 判断权限
- //获取cookies
- $cookies = Yii::$app->request->cookies;
- //账号权限
- $user_id = $cookies->getValue('user_id');
- $user_rule = $cookies->getValue('ht_user_role');
- if ($user_rule != 0) {
- $json['code'] = '1';
- $json['info'] = '无权限';
- return $json;
- }
- #endregion
-
- #region base_area表数据
- $base_area_values = [
- 'PARENT_ID' => $range,
- 'UPDATE_USER_ID' => $user_id,
- 'UPDATE_TIME' => date('Y-m-d H:i:s', time()),
- 'AREA_NAME' => $station_name,
- 'POI_TYPE2' => $poi_type
- ];
- #endregion
-
- $transaction = Yii::$app->db->beginTransaction();
- try {
- //1.修改base_area表
- $base_area_one = self::findOne(['id' => $station_id, 'cancel_flag' => 0]);
- $base_area_one->attributes = $base_area_values;
- $res = $base_area_one->update();
- if (!$res) {
- throw new Exception('输入数据不符合格式');
- }
-
- //2.更新base_area_view
- $sql = 'call SP_MAKE_BASE_AREA_VIEW()';
- $res = Yii::$app->db->createCommand($sql)->execute();
- if (false === $res) {
- throw new Exception('输入数据不符合格式');
- }
-
- $transaction->commit();
- $json['code'] = '0';
- $json['info'] = '修改区域成功';
-
- } catch (Exception $e) {
- # 回滚事务
- $json['code'] = '1';
- $json['info'] = $e->getMessage();
- }
- return $json;
- }
-
- /**
- * Function Description:获取区域详情及配置包
- * Function Name: getStationInfo
- *
- * @param int $station_id 区域id
- *
- * @return array
- *
- * @author 张帅
- */
- public function getStationInfo($station_id)
- {
- #region 1.数据库获取详情
- $station_info_db = self::find()
- ->select('a.area_name,a.poi_type2,v.parent_area_id_list')
- ->from('base_area as a')
- ->leftJoin('base_area_view as v', 'a.id = v.area_id')
- ->where([
- 'and',
- ['=', 'a.id', $station_id],
- ['=', 'a.cancel_flag', 0]
- ])
- ->asArray()
- ->one();
- #endregion
-
- #region 2.整理数据
- $station_info = [];
- $station_info['station_id'] = $station_id;//站点id
- $station_info['station_name'] = $station_info_db['area_name'];//站点名称
- //poi类型
- if ($station_info_db['poi_type2'] != '0') {
- $poi_type_arr = substr($station_info_db['poi_type2'], 1, -1);
- $poi_type_arr = explode('}{', $poi_type_arr);
- } else {
- $poi_type_arr = [];
- }
- $station_info['poi_type_arr'] = $poi_type_arr;
- //父节点数组
- if (!empty($station_info_db['parent_area_id_list'])) {
- $station_parent_list_arr = substr($station_info_db['parent_area_id_list'], 1, -1);
- $station_parent_list_arr = explode('}{', $station_parent_list_arr);
- $station_info['range_arr'] = $station_parent_list_arr;
- #region 查询下拉列表
- $rang_list = BaseArea::find()
- ->select('id as area_id,area_name,parent_id')
- ->where([
- 'and',
- ['in', 'parent_id', $station_parent_list_arr],
- ['=', 'cancel_flag', 0],
- ['=', 'poi_type1', 401]
- ])
- ->asArray()
- ->all();
-
- $rang_list_arr = [];
- foreach ($rang_list as $rang_key => $range_vel) {
- $rang_list_arr[$range_vel['parent_id']][$range_vel['area_id']]['area_id'] = $range_vel['area_id'];
- $rang_list_arr[$range_vel['parent_id']][$range_vel['area_id']]['area_name'] = $range_vel['area_name'];
- }
- $station_info['rang_list_arr'] = $rang_list_arr;
- #endregion
- } else {
- $station_info['range_arr'] = [];
- $station_info['rang_list_arr'] = [];
- }
- #endregion
-
- #endregion
- return $station_info;
- //echo '<pre>';print_r($station_info);die;
- }
-
- /**
- * Function Description:获取展示区域的数据
- * Function Name: getShowStationInfo
- *
- * @param int $station_id 区域id
- *
- * @return array
- *
- * @author 张帅
- */
- public function getShowStationInfo($station_id)
- {
- #region 1.数据库获取详情
- $station_info_db = self::find()
- ->select('a.area_name,a.poi_type2,v.parent_area_id_list,v.parent_area_name_list')
- ->from('base_area as a')
- ->leftJoin('base_area_view as v', 'a.id = v.area_id')
- ->where([
- 'and',
- ['=', 'a.id', $station_id],
- ['=', 'a.cancel_flag', 0]
- ])
- ->asArray()
- ->one();
- #endregion
-
- #region 2.整理数据
- $station_info = [];
- $station_info['station_id'] = $station_id;//站点id
- $station_info['station_name'] = $station_info_db['area_name'];//站点名称
-
-
- //poi类型
- if ($station_info_db['poi_type2'] != '0') {
-
- $poi_type_arr = substr($station_info_db['poi_type2'], 1, -1);
- $poi_type_arr = explode('}{', $poi_type_arr);
-
- #region 获取poi类型的名称
- $poi_type_arr = DictType::find()
- ->select('id as station_type_id,type_name as station_type_name')
- ->where([
- 'and',
- ['in', 'id', $poi_type_arr]
- ])->asArray()->all();
- #endregion
- } else {
- $poi_type_arr = [];
- }
- $station_info['poi_type_arr'] = $poi_type_arr;
-
- //父节点数组
- $rang_list_arr = [];
- if (!empty($station_info_db['parent_area_id_list'])) {
- $station_parent_id_list_arr = substr($station_info_db['parent_area_id_list'], 1, -1);
- $station_parent_id_list_arr = explode('}{', $station_parent_id_list_arr);
-
- $station_parent_name_list_arr = substr($station_info_db['parent_area_name_list'], 1, -1);
- $station_parent_name_list_arr = explode('}{', $station_parent_name_list_arr);
-
- foreach ($station_parent_id_list_arr as $key => $value) {
- $rang_list_arr[$key]['area_id'] = $value;
- $rang_list_arr[$key]['area_name'] = $station_parent_name_list_arr[$key];
- }
- }
-
- $station_info['range_arr'] = $rang_list_arr;
-
- return $station_info;
- }
-
- /**
- * Function Description:删除区域或站点
- * Function Name: deleteStation
- *
- * @param int $station_id 区域id
- *
- * @return mixed
- *
- * @author 张帅
- */
- public function deleteStation($station_id)
- {
- #region 判断权限
- //获取cookies
- $cookies = Yii::$app->request->cookies;
- //账号权限
- $user_id = $cookies->getValue('user_id');
- $user_rule = $cookies->getValue('ht_user_role');
- if ($user_rule != 0) {
- $json['code'] = '1';
- $json['info'] = '无权限';
- return $json;
- }
- #endregion
-
-
- #region 1.查询区域或站点是否为其他区域或站点的父节点
- $count = BaseAreaView::find()
- ->where([
- 'and',
- ['like', 'parent_area_id_list', '{' . $station_id . '}']
- ])
- ->count();
- if ($count > 0) {
- $json['code'] = '1';
- $json['info'] = '该区域或站点有子站点或区域,请删除子站点或区域后再试';
- return $json;
- }
- #endregion
-
- #region 2.删除站点
- $transaction = Yii::$app->db->beginTransaction();
- try {
- //3.修改base_area表
- $base_area_one = self::findOne(['id' => $station_id, 'cancel_flag' => 0]);
- $base_area_one->attributes = ['CANCEL_FLAG' => '1', 'UPDATE_USER_ID' => $user_id, 'UPDATE_TIME' => date('Y-m-d H:i:s', time())];
- $res = $base_area_one->update();
- if (!$res) {
- throw new Exception('因数据原因,删除站点失败');
- }
-
- //4.更新base_area_view
- $sql = 'call SP_MAKE_BASE_AREA_VIEW()';
- $res = Yii::$app->db->createCommand($sql)->execute();
- if (false === $res) {
- throw new Exception('因数据原因,删除站点失败');
- }
-
- $transaction->commit();
- $json['code'] = '0';
- $json['info'] = '删除站点成功';
-
- } catch (Exception $e) {
- # 回滚事务
- $json['code'] = '1';
- $json['info'] = $e->getMessage();
- }
- #endregion
-
- return $json;
- }
-
- /**
- * Function Description:导出excel
- * Function Name: exportExcel
- *
- * @param string $file_name 文件名
- * @param array $data_title 表名
- * @param array $data_list 数据
- *
- * @return string
- *
- * @author 张帅
- */
- public function exportExcel($file_name, $data_title, $data_list)
- {
- ini_set('memory_limit', '1024M');
- set_time_limit(60 * 60);
- require Yii::getAlias('@backend') . "/common/PHPExcel/PHPExcel.php";
- $objPHPExcel = new \PHPExcel(); //实例化PHPExcel类
- $objSheet = $objPHPExcel->getActiveSheet(); //获取当前活动sheet的操作对象
- $objSheet->setTitle($file_name); //给当前活动sheet的操作对象
-
- $objSheet->mergeCells('A1:O1'); //合并单元格
- $objSheet->setCellValue('A1', $file_name);
- $objSheet->getStyle('A1:O1')->getFont()->setName('微软雅黑')->setSize(15)->setBold(True);
- $objSheet->getStyle('A1:O1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER)->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);;
- $objSheet->getStyle('A1:O1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('A6A6A6');
- $objSheet->getStyle('A2:O2')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('CCCCCC');
-
- $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'];
- foreach ($data_title as $k => $v) {
- $objSheet->setCellValue($directory[$k] . '2', $v);
- }
-
- for ($j = 0; $j < count($data_list); $j++) {
- $list = array_values($data_list[$j]);
- foreach ($list as $k => $v) {
- $objSheet->setCellValue($directory[$k] . ($j + 3), $v);
- }
- }
-
- $objWrite = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); //按照指定格式生成excel文件
-
- ob_start();
- $objWrite->save('php://output');
- $xlsData = ob_get_contents();
- ob_end_clean();
- $json["code"] = '0';
- $json["file"] = "data:application/vnd.ms-excel;base64," . base64_encode($xlsData);
- $json["file_name"] = $file_name;
- return json_encode($json);
- }
-
- public function getAreaList($area_id)
- {
- $query = self::find()
- ->select(['id as area_id', 'area_name'])
- ->where(['and', ['=', 'cancel_flag', 0], ['=', 'parent_id', $area_id], ['in', 'poi_type2', ['0','{630}']], ['=', 'poi_type1', 401]])
- ->asArray()
- ->all();
- return $query;
- }
-
- /**
- * Function Description:获取地区的名字
- * Function Name: getAreaName
- * @param $area_id_array
- *
- * @return array
- *
- * @author 李健
- */
- public function getAreaName($area_id_array)
- {
- $select = [
- 'id',
- 'area_name'
- ];
- $where = ['in','id',$area_id_array];
- $res = self::find()
- ->select($select)
- ->from(self::tableName())
- ->where($where);
- $sql = $res->createCommand()->rawSql;
- $data = $res->asArray()->all();
- return [
- 'sql'=>$sql,
- 'data'=>$data
- ];
- }
-
- /**
- * Function Description:获取地区的名字
- * Function Name: getArea
- * @param $area_id_array
- *
- * @return array
- *
- * @author 李健
- */
- public function getArea($area_id)
- {
- $select = [
- 'id',
- 'area_name'
- ];
- $where = ['=','parent_id',$area_id];
- $res = self::find()
- ->select($select)
- ->from(self::tableName())
- ->where($where);
- $sql = $res->createCommand()->rawSql;
- $data = $res->asArray()->all();
- return [
- 'sql'=>$sql,
- 'data'=>$data
- ];
- }
-
-
- /**
- * Function Description:获取指定地区信息
- * Function Name: getAreaInfo
- * @param $area_id
- *
- * @return array|ActiveRecord[]
- *
- * @author 李健
- */
- public function getAreaInfo($area_id)
- {
- $select = [
- 'id',
- 'area_name',
- 'parent_id'
- ];
- $where = ['and'];
- $where[] = ['=','cancel_flag',0];
- $where[] = ['=','id',$area_id];
-
- $res = self::find()->select($select)->from(self::tableName())->where($where)->asArray()->all();
- return $res;
- }
- }
-
|