| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%driver}}".
- *
- * @property integer $id
- */
- class Driver extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%driver}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- ]
- ];
- }
- public function beforeSave($insert)
- {
- if (parent::beforeSave($insert)) {
- if($this->saas_user_id > 0){
- if($this->isNewRecord){
- $is = self::find()->where(['saas_user_id' => $this->saas_user_id, 'is_delete' => 0])->one();
- }else{
- $is = self::find()->where(['saas_user_id' => $this->saas_user_id, 'is_delete' => 0])->andWhere(['!=', 'id', $this->id])->one();
- }
- if($is){
- $this->addError('mobile', '操作失败,其他司机[****'. mb_substr($is->name, -1) . $is->id .']已绑定此用户!请更换');
- return false;
- }
- }
- return true;
- }
- return false;
- }
- public function getSaasUser() {
- $saas_user_id = $this->saas_user_id ?? 0;
- $saas_user = SaasUser::findOne($saas_user_id);
- return $saas_user;
- }
- public static function getByAdminId($admin_id, $status = -1) {
- $query = self::find()->where(['admin_id' => $admin_id, 'is_delete' => 0]);
- if($status >= 0){
- $query->andWhere(['status' => $status]);
- }
- return $query->all();
- }
- }
|