|
- <?php
-
- namespace backend\modules\api\models;
-
- use Yii;
- use yii\data\ActiveDataProvider;
-
- /**
- * This is the model class for table "base_tailor_station".
- *
- * @property integer $id
- * @property integer $person_num
- * @property string $run_date
- * @property string $run_minutes
- * @property integer $baggage_weight
- * @property string $address
- * @property string $lng
- * @property string $lat
- * @property integer $tailor_type
- * @property string $flight_number
- * @property integer $area_name
- * @property integer $poi_type1
- * @property string $poi_type2
- * @property integer $inout_type
- * @property string $line_id
- * @property string $name
- * @property string $tel
- * @property string $id_card
- * @property string $memo
- * @property string create_time
- * @property string update_time
- * @property string create_user_id
- * @property string update_user_id
- * @property integer main_corp_id
- * @property integer address_res_id
- * @property integer product_res_id
- * @property integer product_id
- * @property integer original_order_id
- * @property integer org_id
- * @property integer org_no
- * @property integer order_id
- */
- class BaseTailorStation extends \yii\db\ActiveRecord
- {
-
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'base_tailor_station';
- }
-
- // public function load($data, $formName = null)
- // {
- // //当前用户所属运营主体
- // $base_user = new BaseUser();
- // $user_main_corp = $base_user->getMainCorp();
- // $user_id = Yii::$app->request->cookies->getValue('user_id');
- // if ($this->isNewRecord) {
- // $this->create_time = date('Y-m-d H:i:s');
- // $this->create_user_id = $user_id;
- // }
- // $this->update_time = date('Y-m-d H:i:s');
- // $this->update_user_id = $user_id;
- // $this->main_corp_id = $user_main_corp;
- // return parent::load($data, $formName); // TODO: Change the autogenerated stub
- // }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['id', 'person_num', 'baggage_weight', 'tailor_type', 'poi_type1', 'inout_type', 'cancel_flag', 'address_res_id', 'product_res_id', 'product_id', 'original_order_id', 'org_id'], 'integer'],
- [['name', 'tel', 'person_num', 'run_date', 'address', 'lng', 'lat', 'tailor_type', 'area_name', 'poi_type1', 'poi_type2', 'inout_type', 'product_id', 'product_res_id', 'org_id'], 'required'],
- [['flight_number', 'id_card', 'memo', 'baggage_weight', 'update_time', 'create_time', 'create_user_id', 'update_user_id', 'line_id', 'main_corp_id', 'original_order_id', 'org_no', 'order_id'], 'safe'],
- [['run_date'], 'string', 'max' => 10],
- [['run_minutes'], 'string', 'max' => 5],
- [['address', 'org_no'], 'string', 'max' => 500],
- [['lng', 'lat', 'flight_number', 'poi_type2'], 'string', 'max' => 50],
- // [['line_id'], 'string', 'max' => 100],
- [['id'], 'unique'],
- //默认值
- [['poi_type1'], 'default', 'value' => '402'],
- [['poi_type2'], 'default', 'value' => '0'],
- [['inout_type'], 'default', 'value' => '0'],
- [['cancel_flag'], 'default', 'value' => '0'],
- //手机限制
- ['tel', 'number'],
- ['tel', 'string', 'min' => 11],
- ['tel', 'filter', 'filter' => 'trim'],
- //身份证限制
- ['id_card', 'string', 'min' => 15],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'id',
- 'person_num' => '人数',
- 'run_date' => '上车日期',
- 'run_minutes' => '上车时间',
- 'baggage_weight' => '行李重量',
- 'address' => '地址',
- 'lng' => '经度',
- 'lat' => '纬度',
- 'tailor_type' => '产品类型',
- 'flight_number' => '航班号',
- 'area_name' => '所属区域 对应base_area.area_name',
- 'poi_type1' => '站点类别 对应base_area.poi_type1 401区域 402站点',
- 'poi_type2' => '站点类型 对应base_area.poi_type2 404 至412',
- 'inout_type' => '上下车属性ID,DICT_TYPE.ID,108上,109上下,110下。非0,必选',
- // 'line_id' => '若未成线路则为 null 成了线路则 线路id以逗号拼接',
- 'dict_type.TYPE_NAME' => '产品类型',
- 'name' => '顾客姓名',
- 'tel' => '顾客电话',
- 'id_card' => '身份证',
- 'memo' => '备注',
- 'product_id' => '产品名称',
- 'product_res_id' => '上下车站点',
- 'original_order_id' => '原订单号',
- 'org_id' => '渠道商',
- 'org_no' => '渠道号',
- 'line_id' => '线路id',
- 'order_id' => '订单号',
- ];
- }
-
- public function getdict_type()
- {
- return $this->hasOne(DictType::className(), ['ID' => 'tailor_type']);
- }
-
- public function getopera_tailor_product()
- {
- return $this->hasOne(OperaTailorProduct::className(), ['id' => 'product_id']);
- }
-
- public function getopera_line()
- {
- return $this->hasOne(OperaLine::className(), ['LINE_ID' => 'line_id']);
- }
-
- /**
- * Function Description:获取站点列表
- * Function Name: getIndex
- *
- *
- * @author LUOCJ
- */
- // public function getIndex($data)
- // {
- // //当前用户所属运营主体
- // $base_user = new BaseUser();
- // $user_main_corp = $base_user->getMainCorp();
- // $query = self::find()->where(['and', ['=', 'cancel_flag', 0]])->orderBy('`create_time` desc');
- // $dataProvider = new ActiveDataProvider([
- // 'query' => $query,
- // ]);
- // $query->andFilterWhere(['=', 'main_corp_id', $user_main_corp]);
- // if (isset($data['address']))
- // $query->andFilterWhere(['like', 'address', $data['address']]);
- // if (isset($data['run_date']))
- // $query->andFilterWhere(['=', 'run_date', $data['run_date']]);
- // if (isset($data['name']))
- // $query->andFilterWhere(['like', 'name', $data['name']]);
- // if (isset($data['tel']))
- // $query->andFilterWhere(['like', 'tel', $data['tel']]);
- // return $dataProvider;
- // }
-
- /**
- * Function Description:获取所有点参数
- * Function Name: getPointInfo
- *
- * @return string
- *
- * @author LUOCJ
- */
- public function getPointInfo($product_id, $run_date)
- {
- $query = self::find()->where(['and', ['=', 'cancel_flag', 0], ['=', 'run_date', $run_date], ['=', 'product_id', $product_id], ['=', 'line_id', '']])->asArray()->all();
- $sql = "select a.inout_type,a.product_id,b.TYPE_ID as type_id,b.PROPERTY as property,a.res_id,c.RES_NAME as res_name,d.area_name from opera_tailor_product_station a inner join base_area d on a.area_id = d.ID inner join base_resource c on a.res_id = c.RES_ID left join base_resource_property b on a.res_id = b.RES_ID and b.TYPE_ID in (212,213) and a.product_id ={$product_id} and a.cancel_flag=0";
- $query_station = Yii::$app->db->createCommand($sql)->queryAll();
- $tp_station = [];
- foreach ($query_station as $k => $v) {
- if ($v['type_id'] == 212)
- $tp_station[$v['res_id']]['lng'] = $v['property'];
- elseif ($v['type_id'] == 213) {
- $tp_station[$v['res_id']]['lat'] = $v['property'];
- $tp_station[$v['res_id']]['res_name'] = $v['res_name'];
- $tp_station[$v['res_id']]['area_name'] = $v['area_name'];
- $tp_station[$v['res_id']]['inout_type'] = $v['inout_type'];
- }
-
- }
- $fin_station = [];
- foreach ($tp_station as $k => $v) {
- $fin_station[$k]['id'] = 0;
- $fin_station[$k]['name'] = '';
- $fin_station[$k]['tel'] = '';
- $fin_station[$k]['person_num'] = '';
- $fin_station[$k]['address'] = $v['res_name'];
- $fin_station[$k]['area_name'] = $v['area_name'];
- $fin_station[$k]['res_id'] = $k;
- $fin_station[$k]['lng'] = $v['lng'];
- $fin_station[$k]['lat'] = $v['lat'];
- $fin_station[$k]['tailor_type'] = $v['inout_type'] == 110 ? 701 : 702;
- }
- $fin_station = array_values($fin_station);
- $res = array_merge($query, $fin_station);
- return json_encode($res);
- }
-
- /**
- * Function Description:根据动态巴士线路id,获取出发日期
- * Function Name: getDynamicRunDate
- * @param $line_id
- *
- * @return string
- *
- * @author 温依莅
- */
- public static function getDynamicRunDate($line_id)
- {
- $res = self::find()->select(
- ['id', 'line_id', 'run_date']
- )->where([
- 'line_id' => $line_id,
- 'cancel_flag' => 0
- ])->limit(1)->asArray()->one();
- return $res['run_date'];
- }
-
- /**
- * Function Description:获取动态巴士线路班次的人数
- * Function Name: getTotalNum
- * @param int $line_id 线路id
- *
- * @return int
- *
- * @author 温依莅
- */
- public static function getTotalNum($line_id)
- {
- $res = self::find()
- ->where([
- 'line_id' => $line_id,
- 'cancel_flag' => 0
- ])->sum('person_num');
- return $res;
- }
-
- /**
- * Function Description:获取某线路的乘客信息
- * Function Name: getCustomerInfo
- * @param int $line_id 线路id
- * @param int $main_corp_id 运营主体id
- * @return array
- *
- * @author 温依莅
- */
- public static function getDynamicCustomerInfo($line_id, $main_corp_id)
- {
- $res = self::find()->select([
- 'address','id', 'name', 'tel', 'id_card', 'memo', 'person_num', 'run_date', 'main_corp_id', 'tailor_type', 'inout_type', 'address_res_id', 'product_res_id', 'product_id', 'org_id', 'org_no', 'original_order_id'
- ])->where([
- 'line_id' => $line_id,
- 'main_corp_id' => $main_corp_id,
- 'cancel_flag' => 0
- ])->asArray()->all();
- return $res;
- }
-
- }
|