您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

144 行
4.5 KiB

  1. <?php
  2. namespace backend\modules\api\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "bus_itinerary".
  6. *
  7. * @property integer $id
  8. * @property integer $itinerary_id
  9. * @property string $create_time
  10. * @property integer $create_user_id
  11. * @property integer $update_user_id
  12. * @property string $update_time
  13. * @property integer $cancel_flag
  14. * @property integer $station_res_id
  15. * @property integer $station_seq_id
  16. * @property string $station_name
  17. * @property string $station_address
  18. * @property double $Longitude
  19. * @property double $Latitude
  20. * @property integer $inout_type
  21. * @property integer $day_seq_id
  22. * @property string $start_time
  23. */
  24. class BusItinerary extends \yii\db\ActiveRecord
  25. {
  26. /**
  27. * @inheritdoc
  28. */
  29. public static function tableName()
  30. {
  31. return 'bus_itinerary';
  32. }
  33. /**
  34. * @inheritdoc
  35. */
  36. public function rules()
  37. {
  38. return [
  39. [['itinerary_id', 'create_time', 'create_user_id'], 'required'],
  40. [['itinerary_id', 'create_user_id', 'update_user_id', 'cancel_flag', 'station_res_id', 'station_seq_id', 'inout_type', 'day_seq_id'], 'integer'],
  41. [['create_time', 'update_time'], 'safe'],
  42. [['Longitude', 'Latitude'], 'number'],
  43. [['station_name'], 'string', 'max' => 100],
  44. [['station_address'], 'string', 'max' => 200],
  45. [['start_time'], 'string', 'max' => 10],
  46. ];
  47. }
  48. /**
  49. * @inheritdoc
  50. */
  51. public function attributeLabels()
  52. {
  53. return [
  54. 'id' => '主键,自增ID',
  55. 'itinerary_id' => '行程ID',
  56. 'create_time' => 'Create Time',
  57. 'create_user_id' => 'Create User ID',
  58. 'update_user_id' => 'Update User ID',
  59. 'update_time' => '记录最后更新时间',
  60. 'cancel_flag' => 'Cancel Flag',
  61. 'station_res_id' => '站点ID',
  62. 'station_seq_id' => '站点顺序',
  63. 'station_name' => '站点名称',
  64. 'station_address' => '站点地址',
  65. 'Longitude' => '经度',
  66. 'Latitude' => '纬度',
  67. 'inout_type' => '上下客类型',
  68. 'day_seq_id' => '行程中的第几天',
  69. 'start_time' => '出发/到达时间',
  70. ];
  71. }
  72. /**
  73. * Function Description:获取行程详情
  74. * Function Name: getStationInfo
  75. * @param $itinerary_id
  76. *
  77. * @return array|bool|\yii\db\ActiveRecord[]
  78. *
  79. * @author 张帅
  80. */
  81. public function getStationInfo($itinerary_id)
  82. {
  83. $result = self::find()
  84. ->select([
  85. 'station_order_id' => 's.station_seq_id',//顺序
  86. 's.day_seq_id',//天数
  87. 's.start_time',//出发时间
  88. 'station_id' => 'station_res_id',//站点id
  89. 'station_inout_type' => 's.inout_type',//上下车类型
  90. 'station_name',//站点名称
  91. 'station_address',//详细地址
  92. 'latitude',//经度
  93. 'longitude',//纬度
  94. ])
  95. ->from(self::tableName() . ' as s')
  96. ->where(['and', ['=', 's.itinerary_id', $itinerary_id]])
  97. ->orderBy(['station_order_id' => SORT_ASC])
  98. ->asArray()->all();
  99. if (count($result) == 0) {
  100. return false;
  101. } else {
  102. $return_result = array();
  103. foreach( $result as $station_info ) {
  104. $new_position = $this->bd_decrypt($station_info["longitude"],$station_info["latitude"]);
  105. $station_info["longitude"] = $new_position["gg_lon"];
  106. $station_info["latitude"] = $new_position["gg_lat"];
  107. if( $station_info["station_inout_type"] == 114 ) {
  108. $station_info["station_name"] = "【不停靠】".$station_info["station_name"];
  109. }
  110. $return_result[] = $station_info;
  111. }
  112. return $return_result;
  113. }
  114. }
  115. /**
  116. * Function Description:百度地图坐标转换成高德地图坐标
  117. * Function Name: bd_decrypt
  118. * @param $itinerary_id
  119. *
  120. * @return array|bool|\yii\db\ActiveRecord[]
  121. *
  122. * @author Redstop
  123. */
  124. function bd_decrypt($bd_lon,$bd_lat)
  125. {
  126. $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  127. $x = $bd_lon - 0.0065;
  128. $y = $bd_lat - 0.006;
  129. $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
  130. $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
  131. $data['gg_lon'] = $z * cos($theta);
  132. $data['gg_lat'] = $z * sin($theta);
  133. return $data;
  134. }
  135. }