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.
 
 
 
 
 
 

282 lines
8.8 KiB

  1. <?php
  2. namespace backend\modules\api\models;
  3. use Yii;
  4. use yii\db\Exception;
  5. use yii\db\Expression;
  6. /**
  7. * This is the model class for table "opera_station".
  8. *
  9. * @property integer $ID
  10. * @property integer $CREATE_USER_ID
  11. * @property string $CREATE_TIME
  12. * @property integer $UPDATE_USER_ID
  13. * @property string $UPDATE_TIME
  14. * @property integer $CANCEL_FLAG
  15. * @property integer $LINE_ID
  16. * @property integer $ORDER_ID
  17. * @property integer $START_MINUTES
  18. * @property integer $RES_ID
  19. * @property integer $CHECKPORT_RES_ID
  20. * @property integer $INOUT_TYPE
  21. * @property integer $AREA_ID
  22. * @property double $DISTANCE
  23. */
  24. class OperaStation extends \yii\db\ActiveRecord
  25. {
  26. /**
  27. * @inheritdoc
  28. */
  29. public static function tableName()
  30. {
  31. return 'opera_station';
  32. }
  33. /**
  34. * @inheritdoc
  35. */
  36. public function rules()
  37. {
  38. return [
  39. [['CREATE_USER_ID', 'UPDATE_USER_ID', 'CANCEL_FLAG', 'LINE_ID', 'ORDER_ID', 'START_MINUTES', 'RES_ID', 'CHECKPORT_RES_ID', 'INOUT_TYPE', 'AREA_ID'], 'integer'],
  40. [['CREATE_TIME'], 'required'],
  41. [['UPDATE_TIME'], 'safe'],
  42. [['DISTANCE'], 'number'],
  43. [['CREATE_TIME'], 'string', 'max' => 20],
  44. ];
  45. }
  46. /**
  47. * @inheritdoc
  48. */
  49. public function attributeLabels()
  50. {
  51. return [
  52. 'ID' => 'ID',
  53. 'CREATE_USER_ID' => '记录创建用户ID',
  54. 'CREATE_TIME' => '记录创建时间',
  55. 'UPDATE_USER_ID' => '记录最后更新用户ID',
  56. 'UPDATE_TIME' => '记录最后更新时间',
  57. 'CANCEL_FLAG' => '记录有效性标记,CANCEL_FLAG=0记录有效;CANCEL_FLAG=1,记录已删除',
  58. 'LINE_ID' => '线路ID',
  59. 'ORDER_ID' => '场站停靠顺序ID,从1开始,非0',
  60. 'START_MINUTES' => '场站发车时间至始发日0点的分钟数',
  61. 'RES_ID' => '资源ID,BASE_RESOURCE.RES_ID,如普通座、贵宾座等。还缺少站点相关资源',
  62. 'CHECKPORT_RES_ID' => '检票口资源ID,BASE_RESOURCE.RES_ID,可为0,非必选',
  63. 'INOUT_TYPE' => '上下车属性ID,DICT_TYPE.ID,108上,109上下,110下。非0,必选',
  64. 'AREA_ID' => '应用POI,BASE_AREA.ID',
  65. 'DISTANCE' => '距离',
  66. ];
  67. }
  68. /**
  69. * Function Description:根据line_id,获取可生成票种的站点信息
  70. * Function Name: getTicketsInfo
  71. * @param int $line_id 线路id
  72. *
  73. * @return array
  74. *
  75. * @author 温依莅
  76. */
  77. static public function getTicketsInfo($line_id)
  78. {
  79. $res = self::find()->select([
  80. 'a.id', 'a.line_id', 'a.order_id', 'a.start_minutes', 'a.res_id', 'b.res_name', 'a.inout_type', 'a.area_id'
  81. ])->from('opera_station a')
  82. ->leftJoin('base_resource b', 'a.res_id=b.res_id')->where([
  83. 'a.line_id' => $line_id,
  84. 'a.cancel_flag' => 0
  85. ])
  86. ->orderBy('a.order_id asc')
  87. ->asArray()
  88. ->indexBy('order_id')->all();
  89. return $res;
  90. }
  91. /**
  92. * Function Description:获取线路总里程
  93. * Function Name: getSumDistance
  94. * @param $lined
  95. *
  96. * @return array|null|\yii\db\ActiveRecord
  97. *
  98. * @author 李健
  99. */
  100. public function getSumDistance($lined)
  101. {
  102. $res = self::find()
  103. ->select('sum(distance) as line_distance')
  104. ->from(self::tableName())
  105. ->where('line_id=' . $lined)
  106. ->asArray()
  107. ->one();
  108. return $res;
  109. }
  110. //{108,1,0,0,230,2,791}{110,2,180,60,0,9817,809}
  111. /**modify nzf 参数顺序错误修正 未执行save修改 循环添加,外层用clone修正*/
  112. public function addStation($user_id, $line_id, $inout_type, $order_id, $start_minutes, $distance, $checkport_res_id, $res_id, $area_id)
  113. {
  114. try {
  115. $this->CREATE_USER_ID = $user_id;
  116. $this->CREATE_TIME = date('Y-m-d H:i:s');
  117. $this->UPDATE_USER_ID = $user_id;
  118. $this->LINE_ID = $line_id;
  119. $this->ORDER_ID = $order_id;
  120. $this->START_MINUTES = $start_minutes;
  121. $this->RES_ID = $res_id;
  122. $this->CHECKPORT_RES_ID = $checkport_res_id;
  123. $this->INOUT_TYPE = $inout_type;
  124. $this->AREA_ID = $area_id;
  125. $this->DISTANCE = $distance;
  126. return $this->save();
  127. } catch (Exception $e) {
  128. return false;
  129. }
  130. }
  131. /**
  132. * Function Description:更新站点
  133. * Function Name: uptStation
  134. * @param $user_id
  135. * @param $line_id
  136. * @param $inout_type
  137. * @param $order_id
  138. * @param $start_minutes
  139. * @param $distance
  140. * @param $checkport_res_id
  141. * @param $res_id
  142. * @param $area_id
  143. *
  144. * @return bool
  145. *
  146. * @author 李健
  147. */
  148. public function uptStation($user_id, $line_id, $inout_type, $order_id, $start_minutes, $distance, $checkport_res_id, $res_id, $area_id)
  149. {
  150. try {
  151. $obj = $this->getStationObj($order_id, $line_id);
  152. $obj->UPDATE_USER_ID = $user_id;
  153. $obj->START_MINUTES = $start_minutes;
  154. $obj->RES_ID = $res_id;
  155. $obj->CHECKPORT_RES_ID = $checkport_res_id;
  156. $obj->INOUT_TYPE = $inout_type;
  157. $obj->AREA_ID = $area_id;
  158. $obj->DISTANCE = $distance;
  159. $obj->CANCEL_FLAG = 0;
  160. return $obj->save();
  161. } catch (Exception $e) {
  162. return false;
  163. }
  164. }
  165. /**
  166. * Function Description:获取线路对象
  167. * Function Name: getStationObj
  168. * @param $order_id
  169. * @param $line_id
  170. *
  171. * @return array|null|\yii\db\ActiveRecord
  172. *
  173. * @author 李健
  174. */
  175. public function getStationObj($order_id, $line_id)
  176. {
  177. $where = ['and'];
  178. $where[] = ['=', 'order_id', $order_id];
  179. $where[] = ['=', 'line_id', $line_id];
  180. //$where[] = ['=','cancel_flag',0];
  181. $res = self::find()->from(self::tableName())->where($where)->one();
  182. return $res;
  183. }
  184. /**
  185. * Function Description:删除所有站点
  186. * Function Name: delAllStation
  187. * @param $line_id
  188. *
  189. * @return int
  190. *
  191. * @author 李健
  192. */
  193. public function delAllStation($line_id)
  194. {
  195. $res = self::updateAll(['cancel_flag' => 1], ['line_id' => $line_id]);
  196. return $res;
  197. }
  198. /**
  199. * Des:携程对接使用站点列表
  200. * Name: getStationList
  201. * @param $line_id
  202. * @param $fromCityId
  203. * @return array
  204. * @author 倪宗锋
  205. */
  206. public function getStationList($line_id, $fromCityId,$toCityId)
  207. {
  208. $select = [
  209. 'code' => 'a.res_id',
  210. 'name' => 'b.res_name',
  211. 'address' => new Expression("(SELECT PROPERTY from base_resource_property WHERE RES_ID = a.res_id and TYPE_ID = 279 and CANCEL_FLAG = 0)"),
  212. 'cityName' => new Expression("(SELECT AREA_NAME from base_area where ID = a.AREA_ID)"),
  213. 'latitude' => new Expression("(SELECT PROPERTY from base_resource_property WHERE RES_ID = a.res_id and TYPE_ID = 213)"),
  214. 'longitude' => new Expression("(SELECT PROPERTY from base_resource_property WHERE RES_ID = a.res_id and TYPE_ID = 212)"),
  215. 'boardingType' => new Expression("(CASE a.INOUT_TYPE
  216. WHEN 108 THEN 1
  217. WHEN 110 THEN 2
  218. WHEN 109 THEN if(c.parent_id = $fromCityId or c.ID= $fromCityId,1,2)
  219. ELSE 2
  220. end)"),
  221. 'offsetMinutes' => 'a.START_MINUTES',
  222. 'sequence' => 'a.order_id',
  223. 'waitMinutes' => new Expression("'5'")
  224. ];
  225. $where = [
  226. 'and',
  227. ['=', 'a.LINE_ID', $line_id],
  228. ['=', 'a.CANCEL_FLAG', 0],
  229. ['=', 'a.CANCEL_FLAG', 0],
  230. [
  231. 'or',
  232. [
  233. 'and',
  234. [
  235. 'or',
  236. ['=','c.parent_id',$fromCityId],
  237. ['=','c.ID',$fromCityId],
  238. ],
  239. ['in','a.INOUT_TYPE',[108,109]],
  240. ],
  241. [
  242. 'and',
  243. [
  244. 'or',
  245. ['=','c.parent_id',$toCityId],
  246. ['=','c.ID',$toCityId]
  247. ],
  248. ['in','a.INOUT_TYPE',[109,110]],
  249. ],
  250. ]
  251. ];
  252. $list = self::find()->select($select)
  253. ->from(self::tableName() . ' a')
  254. ->innerJoin(BaseResource::tableName() . ' b', 'a.RES_ID = b.RES_ID')
  255. ->innerJoin(BaseArea::tableName().' c', 'a.AREA_ID = c.ID')
  256. ->where($where)
  257. ->asArray()
  258. ->all();
  259. if (empty($list[0])) {
  260. return [];
  261. }
  262. return $list;
  263. }
  264. }