|
- <?php
-
- namespace backend\modules\api\models;
-
- use Yii;
- use yii\db\Exception;
- use yii\db\Expression;
-
- /**
- * This is the model class for table "opera_line".
- *
- * @property integer $LINE_ID
- * @property integer $CREATE_USER_ID
- * @property string $CREATE_TIME
- * @property integer $UPDATE_USER_ID
- * @property string $UPDATE_TIME
- * @property integer $CANCEL_FLAG
- * @property integer $IF_DISABLED
- * @property string $LINE_NAME
- * @property string $LINE_CODE
- * @property integer $LINE_TYPE
- * @property integer $LINE_SUB_TYPE
- * @property integer $IS_ONSALE
- * @property integer $SALE_EXPIRED_TYPE
- * @property string $SALE_EXPIRED_TIME
- * @property integer $MAIN_CORP_ID
- * @property integer $TOP_ORG_ID
- * @property integer $ORG_ID
- * @property integer $PRODUCT_TYPE
- * @property string $LINE_DESCRIBE
- * @property integer $DISP_ORDER
- * @property integer $TAILOR_TYPE
- * @property integer $TAILOR_FLAG
- * @property integer $ALLOW_SELECT_SEAT
- */
- class OperaLine extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'opera_line';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['CREATE_USER_ID', 'UPDATE_USER_ID', 'CANCEL_FLAG', 'IF_DISABLED', 'LINE_TYPE', 'LINE_SUB_TYPE', 'IS_ONSALE', 'SALE_EXPIRED_TYPE', 'MAIN_CORP_ID', 'TOP_ORG_ID', 'ORG_ID', 'PRODUCT_TYPE', 'DISP_ORDER', 'TAILOR_TYPE', 'TAILOR_FLAG', 'ALLOW_SELECT_SEAT', 'RUN_DUTY_ID'], 'integer'],
- [['CREATE_TIME', 'LINE_NAME'], 'required'],
- [['UPDATE_TIME'], 'safe'],
- [['LINE_DESCRIBE', 'REMARK'], 'string'],
- [['CREATE_TIME'], 'string', 'max' => 20],
- [['LINE_NAME'], 'string', 'max' => 200],
- [['LINE_CODE'], 'string', 'max' => 30],
- [['SALE_EXPIRED_TIME'], 'string', 'max' => 10],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'LINE_ID' => 'Line ID',
- 'CREATE_USER_ID' => 'Create User ID',
- 'CREATE_TIME' => 'Create Time',
- 'UPDATE_USER_ID' => 'Update User ID',
- 'UPDATE_TIME' => 'Update Time',
- 'CANCEL_FLAG' => 'Cancel Flag',
- 'IF_DISABLED' => 'If Disabled',
- 'LINE_NAME' => 'Line Name',
- 'LINE_CODE' => 'Line Code',
- 'LINE_TYPE' => 'Line Type',
- 'LINE_SUB_TYPE' => 'Line Sub Type',
- 'IS_ONSALE' => 'Is Onsale',
- 'SALE_EXPIRED_TYPE' => 'Sale Expired Type',
- 'SALE_EXPIRED_TIME' => 'Sale Expired Time',
- 'MAIN_CORP_ID' => 'Main Corp ID',
- 'TOP_ORG_ID' => 'Top Org ID',
- 'ORG_ID' => 'Org ID',
- 'PRODUCT_TYPE' => 'Product Type',
- 'LINE_DESCRIBE' => 'Line Describe',
- 'DISP_ORDER' => 'Disp Order',
- 'TAILOR_TYPE' => 'Tailor Type',
- 'TAILOR_FLAG' => 'Tailor Flag',
- 'ALLOW_SELECT_SEAT' => 'Allow Select Seat',
- 'RUN_DUTY_ID' => 'Run Duty Id',
- 'REMARK' => 'Remark',
- ];
- }
-
- /**
- * Function Description:获取动态巴士相关信息
- * Function Name: getDynamicInfo
- * @param $line_id
- *
- * @return array
- *
- * @author 温依莅
- */
- static public function getDynamicInfo($line_id)
- {
- $res = self::find()->select([
- 'ol.line_id', 'ol.product_type', 'ol.line_type', 'ol.main_corp_id', 'otp.cost_price', 'otp.product_price as prod_price', 'otp.product_price as cus_price'
- ])->from('opera_line ol')
- ->leftJoin('opera_tailor_product otp', 'ol.product_type=otp.id')
- ->where([
- 'and',
- ['=', 'ol.line_id', $line_id],
- ['>', 'ol.product_type', 0],
- ['=', 'ol.is_onsale', 1],
- ['=', 'ol.if_disabled', 0],
- ['=', 'otp.is_onsale', 1],
- ['=', 'otp.cancel_flag', 0]
- ])->asArray()->one();
- return $res;
- }
-
- /**
- * Function Description:检查线路编号是否存在
- * Function Name: checkLineExists
- * @param $line_code
- *
- * @return array|null|ActiveRecord
- *
- * @author 李健
- */
- public function checkLineExists($line_code)
- {
- $where = ['and'];
- $where[] = ['=', 'line_code', $line_code];
- $where[] = ['=', 'cancel_flag', 0];
- $res = self::find()
- ->select('line_id')
- ->from(self::tableName())
- ->where($where)
- ->asArray()
- ->one();
- return $res;
-
- }
-
- /**
- * Function Description:插入信息
- * Function Name: insertInfo
- * @param $user_id
- * @param $user_id
- * @param $line_name
- * @param $line_code
- * @param $line_type
- * @param $line_sub_type
- * @param $time_type
- * @param $time_info
- * @param $supply_id
- * @param $main_corp_id
- * @param $allow_select_seat
- *
- * @return bool|string
- *
- * @author 李健
- */
- public function insertInfo($user_id, $user_id, $line_name, $line_code, $line_type, $line_sub_type, $time_type, $time_info, $supply_id, $main_corp_id, $allow_select_seat, $remark, $run_duty_id)
- {
- try {
- $this->CREATE_USER_ID = $user_id;
- $this->CREATE_TIME = date('Y-m-d H:i:s');
- $this->UPDATE_USER_ID = $user_id;
- $this->LINE_NAME = $line_name;
- $this->LINE_CODE = $line_code;
- $this->LINE_TYPE = $line_type;
- $this->LINE_SUB_TYPE = $line_sub_type;
- $this->SALE_EXPIRED_TYPE = $time_type;
- $this->SALE_EXPIRED_TIME = $time_info;
- $this->ORG_ID = $supply_id;
- $this->MAIN_CORP_ID = $main_corp_id;
- $this->ALLOW_SELECT_SEAT = $allow_select_seat;
- $this->REMARK = $remark;
- $this->RUN_DUTY_ID = $run_duty_id;
- $this->save();
- return \Yii::$app->db->lastInsertID;
- } catch (Exception $e) {
- return false;
- }
- }
-
- /**
- * Function Description:获取线路是否可换做
- * Function Name: getLineSeatAllow
- * @param $line_id
- *
- * @return array|null|ActiveRecord
- *
- * @author 娄梦宁
- */
- public function getLineSeatAllow($line_id)
- {
- return self::find()->select('allow_select_seat')->from(self::tableName())
- ->where(['line_id' => $line_id])->asArray()->one();
- }
-
- /**
- * Function Description:得到线路详细信息
- * Function Name: getLineDetail
- * @param $line_id
- *
- * @return array|\yii\db\ActiveRecord[]
- *
- * @author 李健
- */
- public function getLineDetail($line_id)
- {
- $select = [
- 'l.tailor_flag',
- 'l.line_id',
- 'l.line_name',
- 'l.line_code',
- 'l.line_type',
- 'l.org_id',
- 'l.run_duty_id',
- 'l.sale_expired_type',
- 'l.sale_expired_time',
- 's.order_id',
- 's.res_id',
- 's.start_minutes',
- 's.inout_type',
- 's.checkport_res_id',
- 's.area_id',
- 's.distance',
- 'l.allow_select_seat',
- 'l.remark'
- ];
- $where = ['and'];
- $where[] = ['=', 'l.cancel_flag', 0];
- $where[] = ['=', 's.cancel_flag', 0];
- $where[] = ['=', 'l.line_id', $line_id];
-
- $res = self::find()
- ->select($select)
- ->from(self::tableName() . ' l')
- ->innerJoin(OperaStation::tableName() . ' s', 'l.line_id = s.line_id')
- ->where($where)
- ->asArray()
- ->all();
- return $res;
- }
-
- /**
- * Function Description:检查线路
- * Function Name: checkLine
- * @param $line_code
- * @param $line_id
- *
- * @return array|\yii\db\ActiveRecord[]
- *
- * @author 李健
- */
- public function checkLine($line_code, $line_id)
- {
- $select = [
- 'line_id'
- ];
- $where = ['and'];
- $where[] = ['=', 'cancel_flag', 0];
- $where[] = ['=', 'line_code', $line_code];
- $where[] = ['!=', 'line_id', $line_id];
-
- $res = self::find()->select($select)->from(self::tableName())->where($where)->asArray()->all();
- return $res;
- }
-
- public function uptInfo($line_id, $user_id, $user_id, $line_name, $line_code, $line_type, $line_sub_type, $time_type, $time_info, $supply_id, $main_corp_id, $allow_select_seat, $remark = '', $run_duty_id)
- {
- try {
- $obj = self::findOne($line_id);
- $obj->UPDATE_USER_ID = $user_id;
- $obj->LINE_NAME = $line_name;
- $obj->LINE_CODE = $line_code;
- $obj->LINE_TYPE = $line_type;
- $obj->LINE_SUB_TYPE = $line_sub_type;
- $obj->SALE_EXPIRED_TYPE = $time_type;
- $obj->SALE_EXPIRED_TIME = $time_info;
- $obj->ORG_ID = $supply_id;
- $obj->MAIN_CORP_ID = $main_corp_id;
- $obj->ALLOW_SELECT_SEAT = $allow_select_seat;
- $obj->RUN_DUTY_ID = $run_duty_id;
- $obj->REMARK = $remark;
- return $obj->save();
- } catch (Exception $e) {
- return false;
- }
- }
-
- /**
- * Des:获取线路信息
- * Name: getLineInfo
- * @param $line_id
- * @return array|null|\yii\db\ActiveRecord
- * @author 倪宗锋
- */
- public function getLineInfo($line_id){
- $select = [
- 'timeExpendMinutes' => new Expression('(MAX(START_MINUTES) - MIN(START_MINUTES))'),
- 'distance' => new Expression("SUM(DISTANCE)"),
- 'bottomPrice' => new Expression("((SELECT MIN(PROD_PRICE) from opera_tickets where LINE_ID = a.LINE_ID and CANCEL_FLAG=0))"),
- 'desc' => 'a.REMARK',
- 'name' => 'a.line_name'
- ];
- $where = [
- 'and',
- ['=','a.LINE_ID',$line_id],
- ['=','b.LINE_ID',$line_id],
- ['=','a.CANCEL_FLAG',0],
- ['=','b.CANCEL_FLAG',0]
- ];
-
- $getInfo = self::find()->select($select)
- ->from(self::tableName().' a')
- ->innerJoin(OperaStation::tableName().' b','a.LINE_ID = b.LINE_ID ')
- ->where($where)
- ->asArray()
- ->one();
- return $getInfo;
- }
-
- public function getOperaLineTicketsFromLine( $line_id, $fromCityId, $toCityId ) {
- $select = [
- "fromStationCode" => "START_STATION_RES_ID",
- "toStationCode" => "END_STATION_RES_ID",
- "price" => "PROD_PRICE"
- ];
- $where = [
- 'and',
- ['=', 'LINE_ID', $line_id],
- ['=','CANCEL_FLAG',0],
- ['=','IS_ONSALE',1],
- ['=','START_STATION_AREA_ID',$fromCityId],
- ['=','END_STATION_AREA_ID',$toCityId],
- ];
- $getInfo = self::find()->select($select)
- ->from(OperaTickets::tableName())
- ->where($where)
- ->asArray()
- ->all();
- return $getInfo;
- }
-
-
- }
|