|
- <?php
-
- namespace backend\modules\motorcade\models;
-
- use backend\modules\api\models\BaseUser;
- use backend\modules\api\models\DictType;
- use backend\modules\zzcs\models\BaseResource;
- use backend\modules\zzcs\models\BaseSupplier;
- use common\models\zModel;
- use Yii;
- use yii\db\Query;
- use yii\helpers\ArrayHelper;
-
- /**
- * This is the model class for table "base_bus".
- *
- * @property integer $BUS_ID
- * @property integer $CREATE_USER_ID
- * @property string $CREATE_TIME
- * @property integer $UPDATE_USER_ID
- * @property string $UPDATE_TIME
- * @property integer $CANCEL_FLAG
- * @property string $BUS_NO
- * @property integer $BUS_TYPE_RES_ID
- * @property integer $BRAND_ID
- * @property integer $MAIN_CORP_ID
- * @property integer $ORG_ID
- * @property string $SEAT_DESC
- * @property string $BUY_DATE
- * @property string $BUS_LICENSE
- * @property integer $SEAT_COUNT
- * @property string $DRIVER_COUNT
- * @property string $TOUR_COUNT
- * @property string $EXTRA_COUNT
- * @property string $MPG
- * @property string $COST
- * @property integer $BUS_STATE
- * @property integer $SEAT_TYPE
- * @property integer $BUS_COLOR
- * @property string $BUS_IMG_PATH
- * @property string $BUS_IMG_TYPE
- * @property string $REGISTER_TIME
- * @property string $BUS_IMG_PATH_ORI
- * @property string $BUS_BELONG
- *
- * @property BusOrder[] $busOrders
- */
- class BaseBus extends zModel
- {
- public $is_my;
- // 判断是否新车,图片显示判断用,0为新车,1为老车
- public $is_new;
-
- const BUS_STATUS_NORMAL = 336; //正常
- const BUS_STATUS_FIXING = 337; //维修
- const BUS_BELONG_OWN = 523; //自有车辆
- const BUS_BELONG_ATTACHED = 524; //挂靠车辆
- const BUS_BELONG_OUTSIDE = 525; //外部车辆
- // 经营属性
- const BUS_BUSINESS_TYPE = array(
- 1 => '省际',
- 2 => '市际',
- 3 => '其他',
- );
- // 车身属性
- const BUS_SURFACE_TYPE = array(
- 1 => '蜘蛛车身',
- 2 => '恒栋车身',
- 3 => '自在车身',
- 4 => '迪士尼车身',
- 5 => '奕欧来车身',
- 6 => '广告车身',
- 7 => '小黑鱼车身',
- 10 => '其他',
- );
-
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'base_bus';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['CREATE_USER_ID', 'UPDATE_USER_ID', 'CANCEL_FLAG', 'SEAT_MATRIX_ID', 'BUS_TYPE_RES_ID', 'BRAND_ID', 'MAIN_CORP_ID', 'ORG_ID', 'SEAT_COUNT', 'BUS_STATE', 'SEAT_TYPE', 'BUS_COLOR'], 'integer'],
- [['CREATE_TIME', 'BUS_NO', 'REGISTER_TIME', 'MAX_COUNT', 'FUEL_FORM', 'BUY_DATE', 'BRAND_ID'], 'required'],
- [['BUS_NO'], 'unique', 'targetAttribute' => ['BUS_NO', 'CANCEL_FLAG', 'MAIN_CORP_ID', 'ORG_ID'], 'message' => '该车辆已存在'],
- [['UPDATE_TIME', 'BUS_BELONG', 'is_new'], 'safe'],
- [['BUSINESS_TYPE', 'SURFACE_TYPE'], 'string'],
- [['CREATE_TIME', 'BUS_NO', 'BUY_DATE', 'REGISTER_TIME'], 'string', 'max' => 20],
- [['SEAT_DESC', 'BUS_LICENSE'], 'string', 'max' => 50],
- [['DRIVER_COUNT', 'TOUR_COUNT', 'MPG', 'COST'], 'string', 'max' => 10],
- [['EXTRA_COUNT'], 'string', 'max' => 11],
- [['BUS_IMG_PATH', 'BUS_IMG_PATH_ORI'], 'string', 'max' => 1024],
- [['BUS_IMG_TYPE'], 'string', 'max' => 64],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'FUEL_FORM' => '燃料形式',
- 'BUS_BELONG' => '自有或外部',
- 'BUS_ID' => '车辆',
- 'CREATE_USER_ID' => '记录创建用户ID',
- 'CREATE_TIME' => '记录创建时间',
- 'UPDATE_USER_ID' => '记录最后更新用户ID',
- 'UPDATE_TIME' => '记录最后更新时间',
- 'CANCEL_FLAG' => '记录有效性标记,CANCEL_FLAG=0记录有效;CANCEL_FLAG=1,记录已删除',
- 'BUS_NO' => '车牌号',
- 'BUS_TYPE_RES_ID' => '车型',
- 'SEAT_MATRIX_ID' => '座位图ID',
- 'BRAND_ID' => '品牌',
- 'MAIN_CORP_ID' => '运营主体ID',
- 'ORG_ID' => '所属公司ID',
- 'SEAT_DESC' => '座位',
- 'BUY_DATE' => '购车日期',
- 'BUS_LICENSE' => '型号',
- 'SEAT_COUNT' => ' 座位数',
- 'DRIVER_COUNT' => ' 司机座位数',
- 'TOUR_COUNT' => '导游座位数',
- 'EXTRA_COUNT' => '辅座数',
- 'MPG' => '油耗',
- 'COST' => ' 固定成本,单位元/天',
- 'BUS_STATE' => '车辆状态',
- 'SEAT_TYPE' => '座位类型',
- 'BUS_COLOR' => 'Bus Color',
- 'BUS_IMG_PATH' => '图片路径 对应的图片类型为BUS_IMG_TYPE里相应数字',
- 'BUS_IMG_TYPE' => '图片对应的类型,dict_type 360',
- 'REGISTER_TIME' => '注册登记日期',
- 'BUS_IMG_PATH_ORI' => '图片路径 对应的图片类型为BUS_IMG_TYPE里相应数字',
- 'MAX_COUNT' => '核载数',
- 'BUSINESS_TYPE' => '经营属性',
- 'SURFACE_TYPE' => '车身属性',
- ];
- }
-
-
- /**
- * User: wangxj
- *
- * 函数作用
- *
- * @param $post
- * @param $formName
- * @return \yii\db\ActiveQuery
- */
- public function load($post, $formName = null)
- {
- // $this->start_date = date('Y-m-01', time());
- // $this->end_date = date('Y-m-t', time());
- // $this->op = isset($post['op']) ? $post['op'] : $this->op;
- // $this->org_sale_id = isset($post['org_sale_id']) ? $post['org_sale_id'] : $this->org_sale_id;
- // $this->bus_user = isset($post['bus_user']) ? isset($post['bus_user']) :$this ->bus_user;
- // $this->line_name = isset($post['line_name']) ? isset($post['line_name']) :$this ->line_name;
- // $this->line_type = isset($post['line_type']) ? isset($post['line_type']) :$this ->line_type;
- return parent::load($post);
- }
-
- /**
- * @return \yii\db\ActiveQuery 车辆所属公司
- */
- public function getOrg()
- {
- return $this->hasOne(BaseSupplier::className(), ['ID' => 'ORG_ID']);
- }
-
- //所属品牌
- public function getBrand()
- {
- return $this->hasOne(BaseResource::className(), ['RES_ID' => 'BRAND_ID']);
- }
-
- public static function getBrands()
- {
- $data = (new Query())
- ->select(['res_id', 'res_name'])
- ->from('base_resource')
- ->where(['cancel_flag' => '0', 'res_type_id' => '134'])
- ->all();
- return $data;
- }
-
- public static function getFuel()
- {
- $data = (new Query())
- ->select(['id', 'type_name'])
- ->from('dict_type')
- ->where(['parent_id' => '485'])
- ->all();
- return $data;
- }
-
- public function getBusOrders()
- {
- return $this->hasMany(BusOrder::className(), ['send_bus_res_id' => 'BUS_ID']);
- }
-
- public function getBaseDocument()
- {
- return $this->hasMany(BaseDocument::className(), ['DOC_ID' => 'BUS_ID']);
- }
-
- /**
- * User:Steven
- * 获取车辆列表
- * @param $key_word
- * @param $date
- * @param $key
- * @return array
- */
- public function GetBusList($key_word, $key, $date)
- {
- $main_corp_id = Yii::$app->user->identity->MAIN_CORP_ID2; //运营主体
- if (!empty(trim($key_word))) {
- $key_word = ' and a.BUS_NO LIKE \'%' . $key_word . '%\'';
- }
- if (trim($key) != '') {
- $key = ' and a.ORG_ID=' . $key;
- }
- $sql = "select
- a.bus_id,
- a.bus_no,
- a.seat_count,
- a.org_id,
- b.supplier_name res_name,
- a.surface_type,
- count(bo.id) used_time
- from
- base_bus a
- left join base_supplier b on a.org_id = b.id
- left join bus_order bo on bo.send_bus_res_id = a.bus_id and bo.cancel_flag = 0 and bo.run_status <> 439 and bo.run_date = '$date'
- where
- a.cancel_flag = 0
- and a.MAIN_CORP_ID=$main_corp_id $key_word $key
- group by bus_id";
- // $sql = "select a.bus_id,a.bus_no,a.seat_count,a.org_id,b.res_name from base_bus a left join base_resource b on a.org_id=b.res_id where a.cancel_flag=0 and a.MAIN_CORP_ID=$main_corp_id" . $key_word . $key;
- $conn = Yii::$app->db;
- $data = $conn->createCommand($sql)->queryAll();
- return ['model' => $this, 'data' => $data];
- }
-
- /**
- * User:Steven
- * 获取车队列表
- * @return array
- */
- public function getConvoy()
- {
- $main_corp_id = Yii::$app->user->identity->MAIN_CORP_ID2; //运营主体
- $sql = "select distinct a.org_id,b.supplier_name res_name from base_bus a left join base_supplier b on a.org_id=b.id where a.cancel_flag=0 and a.MAIN_CORP_ID=$main_corp_id";
- $conn = Yii::$app->db;
- $data = $conn->createCommand($sql)->queryAll();
- return ['model' => $this, 'data' => $data];
- }
-
- /**
- * User:Steven
- * 获取司机列表
- * @param $key_word
- * @param $date
- * @param $key
- * @return array
- */
- public function getDriver($key_word, $date, $key)
- {
- $main_corp_id = Yii::$app->user->identity->MAIN_CORP_ID2; //运营主体
- if (!empty(trim($key_word))) {
- $key_word = ' and (a.driver_name LIKE \'%' . $key_word . '%\' or a.phone_no LIKE \'%' . $key_word . '%\')';
- }
- if (trim($key) != '') {
- $key = ' and a.ORG_ID=' . $key;
- }
- $sql = "select
- a.driver_id,
- a.driver_name,
- a.phone_no,
- s.supplier_name as res_name,
- count(bo.id) used_time
- from
- base_driver a
- left join base_supplier s on a.org_id = s.id
- left join bus_order bo on bo.send_bus_driver_res_id = a.driver_id and bo.run_date = '$date'
- and bo.cancel_flag = 0
- and bo.run_status <> 439
- where
- a.cancel_flag = 0
- and a.MAIN_CORP_ID=$main_corp_id $key_word $key
- group by driver_id order by convert(a.driver_name using gbk)";
- // $sql = "select a.driver_id,a.driver_name,a.phone_no,b.res_name from base_driver a left join base_resource b on a.org_id=b.res_id where a.cancel_flag=0 and a.MAIN_CORP_ID=$main_corp_id" . $key_word; and a.MAIN_CORP_ID=$main_corp_id" . $key_word;
- $conn = Yii::$app->db;
- $data = $conn->createCommand($sql)->queryAll();
- return ['model' => $this, 'data' => $data];
- }
-
- public function getSeatCount($seat_type = '-1')
- {
- $data = (new Query())
- ->select(['res_id', 'res_name'])
- ->from('base_resource')
- ->where(['parent_id' => $seat_type, 'res_type_id' => '69', 'cancel_flag' => '0'])
- ->all();
- return $data;
- }
-
- public static function is_my()
- {
- $bus_belong = BaseBus::findAll(['CANCEL_FLAG' => 0, 'BUS_ID' => $_REQUEST['bus_id']]);
- return $bus_belong;
- }
-
- public static function getBusBelong()
- {
- $obj = DictType::findAll(['PARENT_ID' => 522]);
- return $obj;
- }
-
- public function baoyanglicheng()
- {
- //当前里程数
- $result[0] = (new Query())->select('max(end_value) as min')->from('run_bus_expenses')->where(['bus_res_id' => $_REQUEST['bus_id']])->one();
- //下次保养里程数
- $result[1] = (new Query())->select('max(last_maintain) as max')->from('base_document')->where(['CANCEL_FLAG' => 0, 'DOC_ID' => $_REQUEST['bus_id'], 'DOC_OPTION' => 515])->one();
- return $result;
- }
-
-
- public function getPicture()
- {
-
- $result = [
- 506 => [new BaseDocument(['scenario' => 'bus']), new BaseDocument(['scenario' => 'bus'])],
- 507 => [new BaseDocument(['scenario' => 'bus']), new BaseDocument(['scenario' => 'bus'])],
- 509 => [new BaseDocument(['scenario' => 'bus']), new BaseDocument(['scenario' => 'bus'])],
- 510 => [new BaseDocument(['scenario' => 'bus']), new BaseDocument(['scenario' => 'bus'])],
- ];
- //以506 507 509 510为数组元素返回 506 507为车辆行驶证 509 510为道路运输证 511为保单 515为保养
- $documents = BaseDocument::findAll(['CANCEL_FLAG' => 0, 'DOC_TYPE' => BaseDocument::BUS, 'DOC_ID' => $this->BUS_ID = $_REQUEST['bus_id'], 'DOC_STATUS' => 0, 'DOC_OPTION' => [506, 507]]);
- if (count($documents) > 0) {
- foreach ($documents as $document) {
- if ($document->DOC_OPTION == '506') {
- if ($document->IMG_OPTION == BaseDocument::IMG_FRONT) {
- $result[506][0] = $document;
- $result[506][0]['is_new'] = 1;
- }
- }
- if ($document->DOC_OPTION == '507') {
- if ($document->IMG_OPTION == BaseDocument::IMG_FRONT) {
- $result[507][0] = $document;
- $result[507][0]['is_new'] = 1;
- }
- }
- }
- }
- $documents1 = BaseDocument::findAll(['CANCEL_FLAG' => 0, 'DOC_TYPE' => BaseDocument::BUS, 'DOC_ID' => $this->BUS_ID = $_REQUEST['bus_id'], 'DOC_STATUS' => 0, 'DOC_OPTION' => [509, 510]]);
- if (count($documents1) > 0) {
- foreach ($documents1 as $document) {
- if ($document->DOC_OPTION == '509') {
- if ($document->IMG_OPTION == BaseDocument::IMG_FRONT) {
- $result[509][0] = $document;
- $result[509][0]['is_new'] = 1;
- }
- }
- if ($document->DOC_OPTION == '510') {
- if ($document->IMG_OPTION == BaseDocument::IMG_FRONT) {
- $result[510][0] = $document;
- $result[510][0]['is_new'] = 1;
- }
- }
- }
- }
- return $result;
- }
-
- /**
- * User: wangxj
- *
- * 函数作用
- *
- * @param $org_id
- * @param $type string 返回类型为数组或对象
- *
- * @return array|BaseBus
- */
- public static function getBusListByOrg($org_id = '', $type = 'array')
- {
- $res = BaseBus::find()->where(['MAIN_CORP_ID' => Yii::$app->user->identity->MAIN_CORP_ID2, 'CANCEL_FLAG' => 0]);
- if ($org_id !== '') {
- $res->andFilterWhere(['ORG_ID' => $org_id]);
- }
- if ($type === 'array') {
- $map = true;
- $res->asArray();
- }
- $data = $res->all();
- if (isset($map)) {
- $data = ArrayHelper::map($data, 'BUS_ID', 'BUS_NO');
- }
- return $data;
- }
-
- public static function getBaseUser($org_id = '', $type = 'array')
- {
- $res = BaseDriver::find()->where(['MAIN_CORP_ID' => Yii::$app->user->identity->MAIN_CORP_ID2, 'CANCEL_FLAG' => 0]);
- if ($org_id !== '') {
- $res->andFilterWhere(['ORG_ID' => $org_id]);
- }
- if ($type === 'array') {
- $map = true;
- $res->asArray();
- }
- $data = $res->all();
- if (isset($map)) {
- $data = ArrayHelper::map($data, 'DRIVER_ID', 'DRIVER_NAME');
- }
- return $data;
- }
-
- public static function getBaseResource($org_id = '', $type = 'array')
- {
- $res = BaseResource::find()->where(['RES_TYPE_ID' => [520, 516]]);
- if ($type === 'array') {
- $map = true;
- $res->asArray();
- }
- $data = $res->all();
- if (isset($map)) {
- $data = ArrayHelper::map($data, 'RES_ID', 'RES_NAME');
- }
- return $data;
- }
- }
|