|
- <?php
- /**
- * 数据库表类 bus_ticket
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 倪宗锋
- * PhpStorm LoginController.php
- * Create By 2017/06/15 14:22 $
- */
-
- namespace common\models;
-
- use yii\db\ActiveRecord;
- use yii\db\Expression;
-
- /**
- * 数据库表类 bus_ticket.
- * @property integer $ticket_id
- * @property integer $start_area_id
- * @property string $start_area_name
- * @property integer $end_area_id
- * @property string $end_area_name
- * @property integer $start_res_id
- * @property string $start_res_name
- * @property integer $end_res_id
- * @property string $end_res_name
- * @property integer $line_id
- * @property integer $line_type
- * @property string $prod_price
- * @property string $line_name
- * @property double $start_res_longitude
- * @property double $start_res_latitude
- * @property double $end_res_longitude
- * @property double $end_res_latitude
- */
- class BusTicket extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'bus_ticket';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['ticket_id'], 'required'],
- [['ticket_id', 'start_area_id', 'end_area_id', 'start_res_id', 'end_res_id', 'line_id', 'line_type'], 'integer'],
- [['prod_price', 'start_res_longitude', 'start_res_latitude', 'end_res_longitude', 'end_res_latitude'], 'number'],
- [['start_area_name', 'end_area_name', 'start_res_name', 'end_res_name'], 'string', 'max' => 50],
- [['line_name'], 'string', 'max' => 255],
- [['ticket_id'], 'unique'],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ticket_id' => 'Ticket ID',
- 'start_area_id' => 'Start Area ID',
- 'start_area_name' => 'Start Area Name',
- 'end_area_id' => 'End Area ID',
- 'end_area_name' => 'End Area Name',
- 'start_res_id' => 'Start Res ID',
- 'start_res_name' => 'Start Res Name',
- 'end_res_id' => 'End Res ID',
- 'end_res_name' => 'End Res Name',
- 'line_id' => 'Line ID',
- 'line_type' => 'Line Type',
- 'prod_price' => 'Prod Price',
- 'line_name' => 'Line Name',
- 'start_res_longitude' => 'Start Res Longitude',
- 'start_res_latitude' => 'Start Res Latitude',
- 'end_res_longitude' => 'End Res Longitude',
- 'end_res_latitude' => 'End Res Latitude',
- ];
- }
-
- /**
- * Function Description:查返程票种id对应的产品id
- * Function Name: getBackTicketId
- * @param $ticket_id
- *
- * @return mixed
- *
- * @author 娄梦宁
- */
- public function getBackTicketId($ticket_id)
- {
- $result = self::find()->select(['c.pro_cate_id'])
- ->from(self::tableName() . ' as a')
- ->innerJoin('bus_ticket b', 'a.end_res_name=b.start_res_name and a.start_res_name=b.end_res_name')
- ->leftJoin('prod_category c', 'a.ticket_id=c.bus_ticket_id')
- ->where(['b.ticket_id' => $ticket_id])
- ->groupBy('a.ticket_id')
- ->asArray()
- ->one();
- return $result['pro_cate_id'];
- }
-
- /*
- * 获取当前数据库所存票种信息
- */
- public function getBusArr()
- {
- $result = self::find()
- ->from(self::tableName())
- ->indexBy('ticket_id')
- ->asArray()
- ->all();
- return $result;
- }
-
- /**
- * Des:根据票种ID获取所有票种的上下车站点信息
- * 如果用户选择了上下车poi则进行过滤 只获取这些poi对应的票种
- * Name: getTicketAndLineByIDs
- * @param $ticketIds array
- * @param $params array
- * @return array
- * @author 倪宗锋
- */
- public function getTicketAndLineByIDs($ticketIds, $params)
- {
- $where = [
- 'and',
- ['in', 'ticket_id', $ticketIds],
- ['=', 'b.delete_flag', 0]
- ];
- if (empty($params['start_poi']) == false && empty($params['end_poi']) == false) {
- if ($params['if_back']) {
- $where[] = ['=', 'a.start_area_id', $params['end_poi']];
- $where[] = ['=', 'a.end_area_id', $params['start_poi']];
- } else{
- $where[] = ['=', 'a.start_area_id', $params['start_poi']];
- $where[] = ['=', 'a.end_area_id', $params['end_poi']];
- }
- }
- $result = self::find()->select(['a.start_res_name', 'a.start_res_id', new Expression("GROUP_CONCAT(CONCAT(ticket_id,'|',a.end_res_id,'|',a.end_res_name,'|',b.pro_cate_id) separator '||') FxTicket")])
- ->from(self::tableName() . ' as a')
- ->innerJoin(ProdCategory::tableName() . ' b', 'a.ticket_id = b.bus_ticket_id and b.sign is null')
- ->where($where)
- ->groupBy('a.start_res_id')
- ->indexBy('start_res_id')
- ->asArray()
- ->all();
- if (empty($result)) {
- return [];
- }
- foreach ($result as $key => $val) {//拼接成以起始站为中心的数组
- $result[$key]['end_station_list'] = [];
- $ticketArr = explode('||', $val['FxTicket']);
- foreach ($ticketArr as $val1) {
- $theArr = explode('|', $val1);
- if (count($theArr) == 4) {
- $theArr1['ticket_id'] = $theArr[0];
- $theArr1['end_res_id'] = $theArr[1];
- $theArr1['end_res_name'] = $theArr[2];
- $theArr1['pro_cate_id'] = $theArr[3];
- $result[$key]['end_station_list'][$theArr[0]] = $theArr1;
- }
- }
- unset($result[$key]['FxTicket']);
- }
- return $result;
- }
-
- /**
- * Des: 获取出发站点
- * Name: getStartStation
- * @param $param
- * @return array
- * @author 倪宗锋
- */
- public function getStartStation($param)
- {
- //where条件
- $where = ['and'];
- $where[] = ['=', 'c.system', $param['system']];
- if (empty($param['station_id']) == false) {
- $where[] = ['=', 'a.end_area_id', $param['station_id']];
- }
- if (empty($param['poi_type']) == false) {
- $where[] = ['like', 'y.POI_TYPE2', "{{$param['poi_type']}}"];
- }
- if (empty($param['poi_name']) == false) {
- $where[] = ['like', 'a.start_area_name', "{$param['poi_name']}"];
- }
- if (empty($param['category_id']) == false) {
- $where[] = ['=', 'c.cms_cate_id', $param['category_id']];
- }
- if (empty($param['limit'])) {
- $param['limit'] = 999;
- }
- //select 条件
- $select = [
- 'id' => 'a.start_area_id',
- 'name' => 'a.start_area_name'
- ];
- $result = self::find()->select($select)
- ->from(self::tableName() . ' a')
- ->distinct()
- ->innerJoin(ProdCategory::tableName() . ' b', 'a.line_id = b.sign')
- ->innerJoin(CmsCategoryProd::tableName() . ' c', 'b.pro_cate_id = c.prod_cate_id')
- ->innerJoin(BaseArea::tableName() . ' y', 'a.start_area_id = y.ID')
- ->orderBy('b.sales_count desc ')
- ->limit($param['limit'])
- ->where($where)
- ->asArray()
- ->all();
- return $result;
- }
-
- /**
- * Des:获取目的地的station
- * Name: getEndStation
- * @param $param
- * @return array
- * @author 倪宗锋
- */
- public function getEndStation($param)
- {
- //where条件
- $where = ['and'];
- $where[] = ['=', 'c.system', $param['system']];
- if (empty($param['station_id']) == false) {
- $where[] = ['=', 'a.start_area_id', $param['station_id']];
- }
- if (empty($param['poi_type']) == false) {
- $where[] = ['like', 'y.POI_TYPE2', "{{$param['poi_type']}}"];
- }
- if (empty($param['poi_name']) == false) {
- $where[] = ['like', 'a.end_area_name', "{$param['poi_name']}"];
- }
- if (empty($param['category_id']) == false) {
- $where[] = ['=', 'c.cms_cate_id', $param['category_id']];
- }
- if (empty($param['limit'])) {
- $param['limit'] = 999;
- }
- //select 条件
- $select = [
- 'id' => 'a.end_area_id',
- 'name' => 'a.end_area_name'
- ];
- $result = self::find()->select($select)
- ->distinct()
- ->from(self::tableName() . ' a')
- ->innerJoin(ProdCategory::tableName() . ' b', 'a.line_id = b.sign')
- ->innerJoin(CmsCategoryProd::tableName() . ' c', 'b.pro_cate_id = c.prod_cate_id')
- ->innerJoin(BaseArea::tableName() . ' y', 'a.end_area_id = y.ID')
- ->orderBy('b.sales_count desc ')
- ->limit($param['limit'])
- ->where($where)
- ->asArray()
- ->all();
- return $result;
- }
-
- /**
- * Function Description:获取所有目的地poi数组
- * Function Name: getAllArea
- *
- * @return array|ActiveRecord[]
- *
- * @author 娄梦宁
- */
- public function getAllArea(){
- $result=self::find()->select('end_area_id as area_id,end_area_name as area_name')
- ->from(self::tableName())
- ->distinct()
- ->asArray()
- ->all();
- return $result;
- }
- }
|