You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

165 rivejä
5.2 KiB

  1. <?php
  2. namespace backend\modules\api\models;
  3. use yii\db\ActiveRecord;
  4. use yii\db\Exception;
  5. use yii\db\Expression;
  6. /**
  7. * This is the model class for table "run_station".
  8. *
  9. * @property integer $ID
  10. * @property integer $RUN_ID
  11. * @property integer $PROD_ID
  12. * @property integer $STATION_ORDER_ID
  13. * @property string $START_TIME
  14. * @property integer $START_MINUTES
  15. * @property integer $STATION_RES_ID
  16. * @property integer $STATION_INOUT_TYPE
  17. * @property integer $CREATE_USER_ID
  18. * @property string $CREATE_TIME
  19. * @property string $CHECKPORT_RES_ID
  20. * @property integer $AREA_ID
  21. */
  22. class RunStation extends ActiveRecord
  23. {
  24. /**
  25. * @inheritdoc
  26. */
  27. public static function tableName()
  28. {
  29. return 'run_station';
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['RUN_ID', 'PROD_ID', 'STATION_ORDER_ID', 'START_MINUTES', 'STATION_RES_ID', 'STATION_INOUT_TYPE', 'CREATE_USER_ID', 'CHECKPORT_RES_ID', 'AREA_ID'], 'integer'],
  38. [['START_TIME', 'CREATE_TIME'], 'string', 'max' => 20],
  39. ];
  40. }
  41. /**
  42. * @inheritdoc
  43. */
  44. public function attributeLabels()
  45. {
  46. return [
  47. 'ID' => 'ID',
  48. 'RUN_ID' => 'Run ID',
  49. 'PROD_ID' => 'Prod ID',
  50. 'STATION_ORDER_ID' => 'Station Order ID',
  51. 'START_TIME' => 'Start Time',
  52. 'START_MINUTES' => '场站发车时间至始发日0点的分钟数',
  53. 'STATION_RES_ID' => 'Station Res ID',
  54. 'STATION_INOUT_TYPE' => 'Station Inout Type',
  55. 'CREATE_USER_ID' => 'Create User ID',
  56. 'CREATE_TIME' => 'Create Time',
  57. 'CHECKPORT_RES_ID' => 'Checkport Res ID',
  58. 'AREA_ID' => 'Area ID',
  59. ];
  60. }
  61. /**
  62. * Function Description:获取班次站点详情
  63. * Function Name: getStationInfo
  64. * @param int $run_id 班次id
  65. *
  66. * @return array|bool|\yii\db\ActiveRecord[]
  67. *
  68. * @author 张帅
  69. */
  70. public function getStationInfo($run_id)
  71. {
  72. $result = self::find()
  73. ->select([
  74. 's.run_id',//班次id
  75. 's.station_order_id',//顺序
  76. 's.start_time',//出发时间
  77. 'station_id' => 's.station_res_id',//站点id
  78. 's.station_inout_type',//上下车类型
  79. 'station_name' => BaseResource::find()->select('res_name')->where('res_id = s.station_res_id and cancel_flag = 0')->limit(1),//站点名称
  80. 'station_address' => BaseResourceProperty::find()->select('property')->where('res_id = s.station_res_id and type_id = 279 and cancel_flag = 0')->limit(1),//详细地址
  81. 'latitude' => BaseResourceProperty::find()->select('property')->where('res_id = s.station_res_id and type_id = 212 and cancel_flag = 0')->limit(1),//经度
  82. 'longtitude' => BaseResourceProperty::find()->select('property')->where('res_id = s.station_res_id and type_id = 213 and cancel_flag = 0')->limit(1),//纬度
  83. ])
  84. ->from(self::tableName() . ' as s')
  85. ->where(['and', ['=', 's.run_id', $run_id]])
  86. ->orderBy(['s.station_order_id' => SORT_ASC])
  87. ->asArray()->one();
  88. if (count($result) == 0) {
  89. return false;
  90. } else {
  91. return $result;
  92. }
  93. }
  94. /**
  95. * Function Description:通过run_id获取班次站点
  96. * Function Name: getRunStation
  97. * @param int $run_id 班次id
  98. *
  99. * @return array|bool|ActiveRecord[]
  100. *
  101. * @author 张帅
  102. */
  103. public function getRunStation($run_id)
  104. {
  105. $result = self::find()
  106. ->select([
  107. 'station_order_id',
  108. 'station_res_id',
  109. 'station_inout_type',
  110. 'area_id',
  111. ])
  112. ->where([
  113. 'and',
  114. ['=', 'run_id', $run_id],
  115. ])
  116. ->orderBy(['station_order_id' => SORT_ASC])
  117. ->asArray()->all();
  118. if (count($result) == 0) {
  119. return false;
  120. }
  121. return $result;
  122. }
  123. /**
  124. * Function Description:查询上下车站列表
  125. * Function Name: getStationList
  126. * @param $run_id
  127. *
  128. * @return array|ActiveRecord[]
  129. *
  130. * @author 李健
  131. */
  132. public function getStationList($run_id)
  133. {
  134. $select = [
  135. 'run.start_time',
  136. 'res1.res_name as station_name',
  137. 'res2.type_name',
  138. 'res_name'=> new Expression('if(res3.res_name is null,"--",res3.res_name)')
  139. ];
  140. $where = ['and'];
  141. $where[] = ['=','run.run_id',$run_id];
  142. $res = self::find()
  143. ->select($select)
  144. ->from(self::tableName().' run')
  145. ->leftJoin(BaseResource::tableName().' res1','res1.res_id=run.station_res_id and res1.cancel_flag=0')
  146. ->leftJoin(DictType::tableName().' res2','res2.id=run.station_inout_type')
  147. ->leftJoin(BaseResource::tableName().' res3','res3.res_id=run.checkport_res_id and res3.cancel_flag=0')
  148. ->where($where)
  149. ->orderBy('run.station_order_id asc')
  150. ->asArray()
  151. ->all();
  152. return $res;
  153. }
  154. }