|
- <?php
-
- namespace backend\modules\api\models;
-
- use Yii;
- use yii\db\Exception;
- use yii\db\Expression;
-
- /**
- * This is the model class for table "opera_station".
- *
- * @property integer $ID
- * @property integer $CREATE_USER_ID
- * @property string $CREATE_TIME
- * @property integer $UPDATE_USER_ID
- * @property string $UPDATE_TIME
- * @property integer $CANCEL_FLAG
- * @property integer $LINE_ID
- * @property integer $ORDER_ID
- * @property integer $START_MINUTES
- * @property integer $RES_ID
- * @property integer $CHECKPORT_RES_ID
- * @property integer $INOUT_TYPE
- * @property integer $AREA_ID
- * @property double $DISTANCE
- */
- class OperaStation extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'opera_station';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['CREATE_USER_ID', 'UPDATE_USER_ID', 'CANCEL_FLAG', 'LINE_ID', 'ORDER_ID', 'START_MINUTES', 'RES_ID', 'CHECKPORT_RES_ID', 'INOUT_TYPE', 'AREA_ID'], 'integer'],
- [['CREATE_TIME'], 'required'],
- [['UPDATE_TIME'], 'safe'],
- [['DISTANCE'], 'number'],
- [['CREATE_TIME'], 'string', 'max' => 20],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ID' => 'ID',
- 'CREATE_USER_ID' => '记录创建用户ID',
- 'CREATE_TIME' => '记录创建时间',
- 'UPDATE_USER_ID' => '记录最后更新用户ID',
- 'UPDATE_TIME' => '记录最后更新时间',
- 'CANCEL_FLAG' => '记录有效性标记,CANCEL_FLAG=0记录有效;CANCEL_FLAG=1,记录已删除',
- 'LINE_ID' => '线路ID',
- 'ORDER_ID' => '场站停靠顺序ID,从1开始,非0',
- 'START_MINUTES' => '场站发车时间至始发日0点的分钟数',
- 'RES_ID' => '资源ID,BASE_RESOURCE.RES_ID,如普通座、贵宾座等。还缺少站点相关资源',
- 'CHECKPORT_RES_ID' => '检票口资源ID,BASE_RESOURCE.RES_ID,可为0,非必选',
- 'INOUT_TYPE' => '上下车属性ID,DICT_TYPE.ID,108上,109上下,110下。非0,必选',
- 'AREA_ID' => '应用POI,BASE_AREA.ID',
- 'DISTANCE' => '距离',
- ];
- }
-
- /**
- * Function Description:根据line_id,获取可生成票种的站点信息
- * Function Name: getTicketsInfo
- * @param int $line_id 线路id
- *
- * @return array
- *
- * @author 温依莅
- */
- static public function getTicketsInfo($line_id)
- {
- $res = self::find()->select([
- 'a.id', 'a.line_id', 'a.order_id', 'a.start_minutes', 'a.res_id', 'b.res_name', 'a.inout_type', 'a.area_id'
- ])->from('opera_station a')
- ->leftJoin('base_resource b', 'a.res_id=b.res_id')->where([
- 'a.line_id' => $line_id,
- 'a.cancel_flag' => 0
- ])
- ->orderBy('a.order_id asc')
- ->asArray()
- ->indexBy('order_id')->all();
- return $res;
- }
-
- /**
- * Function Description:获取线路总里程
- * Function Name: getSumDistance
- * @param $lined
- *
- * @return array|null|\yii\db\ActiveRecord
- *
- * @author 李健
- */
- public function getSumDistance($lined)
- {
- $res = self::find()
- ->select('sum(distance) as line_distance')
- ->from(self::tableName())
- ->where('line_id=' . $lined)
- ->asArray()
- ->one();
- return $res;
- }
-
- //{108,1,0,0,230,2,791}{110,2,180,60,0,9817,809}
-
- /**modify nzf 参数顺序错误修正 未执行save修改 循环添加,外层用clone修正*/
- public function addStation($user_id, $line_id, $inout_type, $order_id, $start_minutes, $distance, $checkport_res_id, $res_id, $area_id)
- {
- try {
- $this->CREATE_USER_ID = $user_id;
- $this->CREATE_TIME = date('Y-m-d H:i:s');
- $this->UPDATE_USER_ID = $user_id;
- $this->LINE_ID = $line_id;
- $this->ORDER_ID = $order_id;
- $this->START_MINUTES = $start_minutes;
- $this->RES_ID = $res_id;
- $this->CHECKPORT_RES_ID = $checkport_res_id;
- $this->INOUT_TYPE = $inout_type;
- $this->AREA_ID = $area_id;
- $this->DISTANCE = $distance;
- return $this->save();
- } catch (Exception $e) {
- return false;
- }
- }
-
- /**
- * Function Description:更新站点
- * Function Name: uptStation
- * @param $user_id
- * @param $line_id
- * @param $inout_type
- * @param $order_id
- * @param $start_minutes
- * @param $distance
- * @param $checkport_res_id
- * @param $res_id
- * @param $area_id
- *
- * @return bool
- *
- * @author 李健
- */
- public function uptStation($user_id, $line_id, $inout_type, $order_id, $start_minutes, $distance, $checkport_res_id, $res_id, $area_id)
- {
- try {
- $obj = $this->getStationObj($order_id, $line_id);
- $obj->UPDATE_USER_ID = $user_id;
- $obj->START_MINUTES = $start_minutes;
- $obj->RES_ID = $res_id;
- $obj->CHECKPORT_RES_ID = $checkport_res_id;
- $obj->INOUT_TYPE = $inout_type;
- $obj->AREA_ID = $area_id;
- $obj->DISTANCE = $distance;
- $obj->CANCEL_FLAG = 0;
- return $obj->save();
- } catch (Exception $e) {
- return false;
- }
- }
-
- /**
- * Function Description:获取线路对象
- * Function Name: getStationObj
- * @param $order_id
- * @param $line_id
- *
- * @return array|null|\yii\db\ActiveRecord
- *
- * @author 李健
- */
- public function getStationObj($order_id, $line_id)
- {
- $where = ['and'];
- $where[] = ['=', 'order_id', $order_id];
- $where[] = ['=', 'line_id', $line_id];
- //$where[] = ['=','cancel_flag',0];
- $res = self::find()->from(self::tableName())->where($where)->one();
- return $res;
- }
-
- /**
- * Function Description:删除所有站点
- * Function Name: delAllStation
- * @param $line_id
- *
- * @return int
- *
- * @author 李健
- */
- public function delAllStation($line_id)
- {
- $res = self::updateAll(['cancel_flag' => 1], ['line_id' => $line_id]);
- return $res;
- }
-
- /**
- * Des:携程对接使用站点列表
- * Name: getStationList
- * @param $line_id
- * @param $fromCityId
- * @return array
- * @author 倪宗锋
- */
- public function getStationList($line_id, $fromCityId,$toCityId)
- {
- $select = [
- 'code' => 'a.res_id',
- 'name' => 'b.res_name',
- 'address' => new Expression("(SELECT PROPERTY from base_resource_property WHERE RES_ID = a.res_id and TYPE_ID = 279 and CANCEL_FLAG = 0)"),
- 'cityName' => new Expression("(SELECT AREA_NAME from base_area where ID = a.AREA_ID)"),
- 'latitude' => new Expression("(SELECT PROPERTY from base_resource_property WHERE RES_ID = a.res_id and TYPE_ID = 213)"),
- 'longitude' => new Expression("(SELECT PROPERTY from base_resource_property WHERE RES_ID = a.res_id and TYPE_ID = 212)"),
- 'boardingType' => new Expression("(CASE a.INOUT_TYPE
- WHEN 108 THEN 1
- WHEN 110 THEN 2
- WHEN 109 THEN if(c.parent_id = $fromCityId or c.ID= $fromCityId,1,2)
- ELSE 2
- end)"),
- 'offsetMinutes' => 'a.START_MINUTES',
- 'sequence' => 'a.order_id',
- 'waitMinutes' => new Expression("'5'")
- ];
- $where = [
- 'and',
- ['=', 'a.LINE_ID', $line_id],
- ['=', 'a.CANCEL_FLAG', 0],
- ['=', 'a.CANCEL_FLAG', 0],
- [
- 'or',
- [
- 'and',
- [
- 'or',
- ['=','c.parent_id',$fromCityId],
- ['=','c.ID',$fromCityId],
- ],
- ['in','a.INOUT_TYPE',[108,109]],
- ],
- [
- 'and',
- [
- 'or',
- ['=','c.parent_id',$toCityId],
- ['=','c.ID',$toCityId]
- ],
- ['in','a.INOUT_TYPE',[109,110]],
- ],
-
- ]
- ];
- $list = self::find()->select($select)
- ->from(self::tableName() . ' a')
- ->innerJoin(BaseResource::tableName() . ' b', 'a.RES_ID = b.RES_ID')
- ->innerJoin(BaseArea::tableName().' c', 'a.AREA_ID = c.ID')
- ->where($where)
- ->asArray()
- ->all();
- if (empty($list[0])) {
- return [];
- }
- return $list;
-
- }
-
-
- }
|