|
- <?php
-
- namespace backend\modules\api\models;
-
- use Yii;
- use yii\db\Expression;
-
- /**
- * This is the model class for table "outside_run".
- *
- * @property integer $id
- * @property integer $org_id
- * @property string $run_code
- * @property string $prod_code
- * @property string $prod_name
- * @property string $line_code
- * @property string $line_name
- * @property string $start_date
- * @property string $start_time
- * @property string $start_area
- * @property string $end_area
- * @property string $start_res
- * @property string $end_res
- * @property string $cus_price
- * @property string $mid_price
- * @property integer $remain_count
- * @property integer $cancel_flag
- * @property string $update_time
- */
- class OutsideRun extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'outside_run';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['org_id', 'remain_count', 'cancel_flag'], 'integer'],
- [['cus_price', 'mid_price'], 'number'],
- [['run_code', 'prod_code', 'prod_name', 'line_name', 'start_area', 'end_area', 'start_res', 'end_res'], 'string', 'max' => 50],
- [['line_code'], 'string', 'max' => 30],
- [['start_date', 'start_time'], 'string', 'max' => 10],
- [['update_time'], 'string', 'max' => 20],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'org_id' => 'Org ID',
- 'run_code' => 'Run Code',
- 'prod_code' => 'Prod Code',
- 'prod_name' => 'Prod Name',
- 'line_code' => 'Line Code',
- 'line_name' => 'Line Name',
- 'start_date' => 'Start Date',
- 'start_time' => 'Start Time',
- 'start_area' => 'Start Area',
- 'end_area' => 'End Area',
- 'start_res' => 'Start Res',
- 'end_res' => 'End Res',
- 'cus_price' => 'Cus Price',
- 'mid_price' => 'Mid Price',
- 'remain_count' => 'Remain Count',
- 'cancel_flag' => 'Cancel Flag',
- 'update_time' => 'Update Time',
- ];
- }
-
- /**
- * Des:获取出发站点数组
- * Name: getStartCity
- * @return array
- * @author 倪宗锋
- */
- public function getStartCity()
- {
- $where = [
- 'and',
- ['=', 'cancel_flag', 0],
- ['>=', 'start_date', new Expression("DATE(NOW())")]
- ];
- $list = self::find()->select(['start_area'])
- ->distinct('start_area')
- ->where($where)
- ->asArray()
- ->all();
- if (!is_array($list)) {
- $list = [];
- }
- return $list;
- }
-
- /**
- * Des:获取结束站点
- * Name: getEndArea
- * @param $startArea
- * @return array
- * @author 倪宗锋
- */
- public function getEndAreaByStartArea($startArea)
- {
- $select = [
- 'preSaleStart' => new Expression("MIN(start_date)"),
- 'preSaleEnd' => new Expression("MAX(start_date)"),
- 'area_name' => new Expression("end_area")
- ];
- $where = [
- 'and',
- ['=', 'cancel_flag', 0],
- ['=', 'start_area', str_replace('市', '', $startArea)],
- ['>=', 'start_date', new Expression("DATE(NOW())")]
- ];
- $getList = self::find()->select($select)
- ->where($where)
- ->groupBy('end_area')
- ->asArray()
- ->all();
- if (is_array($getList) == false) {
- $getList = [];
- }
- return $getList;
- }
-
- /***
- * Des:携程对接获取线路列表
- * Name: getLineList
- * @param $date
- * @param $fromCity
- * @param $toCity
- * @return array
- * @author 倪宗锋
- */
- public function getLineList($date, $fromCity, $toCity)
- {
- $select = [
- 'run_code',
- 'prod_code',
- 'line_code',
- 'line_name' => new Expression("CONCAT(start_res,'-',end_res)"),
- 'start_time',
- 'start_area',
- 'end_area',
- 'line_id' => new Expression("concat(SUBSTR(prod_code FROM locate('T',prod_code,locate('T',prod_code)+1)+1),line_code)"),
- 'price' => new Expression("MIN(cus_price)"),
- 'start_res',
- 'end_res',
- 'start_res_long',
- 'end_res_long',
- 'start_res_lat',
- 'end_res_lat',
- 'start_res_address',
- 'end_res_address',
- 'start_time' => new Expression("GROUP_CONCAT(CONCAT(start_time,'-',remain_count))")
- ];
- $where = [
- 'and',
- ['=', 'start_area', $fromCity],
- ['=', 'end_area', $toCity],
- ['=', 'start_date', $date],
- ['=', 'cancel_flag', 0]
- ];
- $list = self::find()->select($select)
- ->where($where)
- ->groupBy('line_id')
- ->asArray()
- ->all();
- if (is_array($list) == false) {
- return [];
- }
- return $list;
- }
-
- /**
- * Des:携程 汽车票对接 获取 run_id
- * Name: getRunId
- * @param $params
- * @return array
- * @author 倪宗锋
- */
- public function getInfo($params)
- {
- $lineIDEx = explode('NJYYT', $params['lineId']);
- $lineId = $lineIDEx['1'];//线路ID
- $ticketId = $lineIDEx['0'];//票种ID
- $select = [
- 'run_id' => new Expression("SUBSTR(run_code FROM locate('NJYYT',run_code)+5)"),
- 'remain_count'
- ];
- $where = [
- 'and',
- ['=', 'cancel_flag', 0],
- ['=', 'line_code', 'NJYYT' . $lineId],
- ['like', 'prod_code', '%T' . $ticketId, false],
- ['=', 'start_time', $params['fromTime']],
- ['=', 'start_date', $params['fromDate']]
- ];
- $info = self::find()->select($select)
- ->where($where)
- ->asArray()
- ->one();
- if (empty($info['run_id'])) {
- $run_id = 0;
- } else {
- $run_id = $info['run_id'];
- }
- return [
- 'run_id' => $run_id,
- 'line_id' => $lineIDEx['1'],
- 'ticket_id' => $ticketId,
- 'count' => $info['remain_count'] ? $info['remain_count'] : 0
- ];
- }
- }
|