|
- <?php
-
- namespace backend\modules\api\models;
-
- use yii\db\ActiveRecord;
- use yii\db\Exception;
- use yii\db\Expression;
-
- /**
- * This is the model class for table "run_station".
- *
- * @property integer $ID
- * @property integer $RUN_ID
- * @property integer $PROD_ID
- * @property integer $STATION_ORDER_ID
- * @property string $START_TIME
- * @property integer $START_MINUTES
- * @property integer $STATION_RES_ID
- * @property integer $STATION_INOUT_TYPE
- * @property integer $CREATE_USER_ID
- * @property string $CREATE_TIME
- * @property string $CHECKPORT_RES_ID
- * @property integer $AREA_ID
- */
- class RunStation extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'run_station';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['RUN_ID', 'PROD_ID', 'STATION_ORDER_ID', 'START_MINUTES', 'STATION_RES_ID', 'STATION_INOUT_TYPE', 'CREATE_USER_ID', 'CHECKPORT_RES_ID', 'AREA_ID'], 'integer'],
- [['START_TIME', 'CREATE_TIME'], 'string', 'max' => 20],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ID' => 'ID',
- 'RUN_ID' => 'Run ID',
- 'PROD_ID' => 'Prod ID',
- 'STATION_ORDER_ID' => 'Station Order ID',
- 'START_TIME' => 'Start Time',
- 'START_MINUTES' => '场站发车时间至始发日0点的分钟数',
- 'STATION_RES_ID' => 'Station Res ID',
- 'STATION_INOUT_TYPE' => 'Station Inout Type',
- 'CREATE_USER_ID' => 'Create User ID',
- 'CREATE_TIME' => 'Create Time',
- 'CHECKPORT_RES_ID' => 'Checkport Res ID',
- 'AREA_ID' => 'Area ID',
- ];
- }
-
- /**
- * Function Description:获取班次站点详情
- * Function Name: getStationInfo
- * @param int $run_id 班次id
- *
- * @return array|bool|\yii\db\ActiveRecord[]
- *
- * @author 张帅
- */
- public function getStationInfo($run_id)
- {
- $result = self::find()
- ->select([
- 's.run_id',//班次id
- 's.station_order_id',//顺序
- 's.start_time',//出发时间
- 'station_id' => 's.station_res_id',//站点id
- 's.station_inout_type',//上下车类型
- 'station_name' => BaseResource::find()->select('res_name')->where('res_id = s.station_res_id and cancel_flag = 0')->limit(1),//站点名称
- 'station_address' => BaseResourceProperty::find()->select('property')->where('res_id = s.station_res_id and type_id = 279 and cancel_flag = 0')->limit(1),//详细地址
- 'latitude' => BaseResourceProperty::find()->select('property')->where('res_id = s.station_res_id and type_id = 212 and cancel_flag = 0')->limit(1),//经度
- 'longtitude' => BaseResourceProperty::find()->select('property')->where('res_id = s.station_res_id and type_id = 213 and cancel_flag = 0')->limit(1),//纬度
- ])
- ->from(self::tableName() . ' as s')
- ->where(['and', ['=', 's.run_id', $run_id]])
- ->orderBy(['s.station_order_id' => SORT_ASC])
- ->asArray()->one();
- if (count($result) == 0) {
- return false;
- } else {
- return $result;
- }
- }
-
- /**
- * Function Description:通过run_id获取班次站点
- * Function Name: getRunStation
- * @param int $run_id 班次id
- *
- * @return array|bool|ActiveRecord[]
- *
- * @author 张帅
- */
- public function getRunStation($run_id)
- {
- $result = self::find()
- ->select([
- 'station_order_id',
- 'station_res_id',
- 'station_inout_type',
- 'area_id',
- ])
- ->where([
- 'and',
- ['=', 'run_id', $run_id],
- ])
- ->orderBy(['station_order_id' => SORT_ASC])
- ->asArray()->all();
-
- if (count($result) == 0) {
- return false;
- }
- return $result;
- }
-
- /**
- * Function Description:查询上下车站列表
- * Function Name: getStationList
- * @param $run_id
- *
- * @return array|ActiveRecord[]
- *
- * @author 李健
- */
- public function getStationList($run_id)
- {
- $select = [
- 'run.start_time',
- 'res1.res_name as station_name',
- 'res2.type_name',
- 'res_name'=> new Expression('if(res3.res_name is null,"--",res3.res_name)')
- ];
- $where = ['and'];
- $where[] = ['=','run.run_id',$run_id];
- $res = self::find()
- ->select($select)
- ->from(self::tableName().' run')
- ->leftJoin(BaseResource::tableName().' res1','res1.res_id=run.station_res_id and res1.cancel_flag=0')
- ->leftJoin(DictType::tableName().' res2','res2.id=run.station_inout_type')
- ->leftJoin(BaseResource::tableName().' res3','res3.res_id=run.checkport_res_id and res3.cancel_flag=0')
- ->where($where)
- ->orderBy('run.station_order_id asc')
- ->asArray()
- ->all();
- return $res;
- }
-
- }
|