|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
-
- namespace backend\modules\api\models;
-
- use Yii;
-
- /**
- * This is the model class for table "bus_itinerary".
- *
- * @property integer $id
- * @property integer $itinerary_id
- * @property string $create_time
- * @property integer $create_user_id
- * @property integer $update_user_id
- * @property string $update_time
- * @property integer $cancel_flag
- * @property integer $station_res_id
- * @property integer $station_seq_id
- * @property string $station_name
- * @property string $station_address
- * @property double $Longitude
- * @property double $Latitude
- * @property integer $inout_type
- * @property integer $day_seq_id
- * @property string $start_time
- */
- class BusItinerary extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'bus_itinerary';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['itinerary_id', 'create_time', 'create_user_id'], 'required'],
- [['itinerary_id', 'create_user_id', 'update_user_id', 'cancel_flag', 'station_res_id', 'station_seq_id', 'inout_type', 'day_seq_id'], 'integer'],
- [['create_time', 'update_time'], 'safe'],
- [['Longitude', 'Latitude'], 'number'],
- [['station_name'], 'string', 'max' => 100],
- [['station_address'], 'string', 'max' => 200],
- [['start_time'], 'string', 'max' => 10],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => '主键,自增ID',
- 'itinerary_id' => '行程ID',
- 'create_time' => 'Create Time',
- 'create_user_id' => 'Create User ID',
- 'update_user_id' => 'Update User ID',
- 'update_time' => '记录最后更新时间',
- 'cancel_flag' => 'Cancel Flag',
- 'station_res_id' => '站点ID',
- 'station_seq_id' => '站点顺序',
- 'station_name' => '站点名称',
- 'station_address' => '站点地址',
- 'Longitude' => '经度',
- 'Latitude' => '纬度',
- 'inout_type' => '上下客类型',
- 'day_seq_id' => '行程中的第几天',
- 'start_time' => '出发/到达时间',
- ];
- }
-
- /**
- * Function Description:获取行程详情
- * Function Name: getStationInfo
- * @param $itinerary_id
- *
- * @return array|bool|\yii\db\ActiveRecord[]
- *
- * @author 张帅
- */
- public function getStationInfo($itinerary_id)
- {
- $result = self::find()
- ->select([
- 'station_order_id' => 's.station_seq_id',//顺序
- 's.day_seq_id',//天数
- 's.start_time',//出发时间
- 'station_id' => 'station_res_id',//站点id
- 'station_inout_type' => 's.inout_type',//上下车类型
- 'station_name',//站点名称
- 'station_address',//详细地址
- 'latitude',//经度
- 'longitude',//纬度
- ])
- ->from(self::tableName() . ' as s')
- ->where(['and', ['=', 's.itinerary_id', $itinerary_id]])
- ->orderBy(['station_order_id' => SORT_ASC])
- ->asArray()->all();
- if (count($result) == 0) {
- return false;
- } else {
- $return_result = array();
- foreach( $result as $station_info ) {
- $new_position = $this->bd_decrypt($station_info["longitude"],$station_info["latitude"]);
- $station_info["longitude"] = $new_position["gg_lon"];
- $station_info["latitude"] = $new_position["gg_lat"];
- if( $station_info["station_inout_type"] == 114 ) {
- $station_info["station_name"] = "【不停靠】".$station_info["station_name"];
- }
- $return_result[] = $station_info;
- }
-
- return $return_result;
- }
- }
-
- /**
- * Function Description:百度地图坐标转换成高德地图坐标
- * Function Name: bd_decrypt
- * @param $itinerary_id
- *
- * @return array|bool|\yii\db\ActiveRecord[]
- *
- * @author Redstop
- */
- function bd_decrypt($bd_lon,$bd_lat)
- {
- $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
- $x = $bd_lon - 0.0065;
- $y = $bd_lat - 0.006;
- $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
- $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
- $data['gg_lon'] = $z * cos($theta);
- $data['gg_lat'] = $z * sin($theta);
- return $data;
- }
- }
|