Driver.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use Yii;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * This is the model class for table "{{%driver}}".
  13. *
  14. * @property integer $id
  15. */
  16. class Driver extends \yii\db\ActiveRecord
  17. {
  18. /**
  19. * @inheritdoc
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%driver}}';
  24. }
  25. public function behaviors()
  26. {
  27. return [
  28. [
  29. 'class' => TimestampBehavior::class,
  30. ]
  31. ];
  32. }
  33. public function beforeSave($insert)
  34. {
  35. if (parent::beforeSave($insert)) {
  36. if($this->saas_user_id > 0){
  37. if($this->isNewRecord){
  38. $is = self::find()->where(['saas_user_id' => $this->saas_user_id, 'is_delete' => 0])->one();
  39. }else{
  40. $is = self::find()->where(['saas_user_id' => $this->saas_user_id, 'is_delete' => 0])->andWhere(['!=', 'id', $this->id])->one();
  41. }
  42. if($is){
  43. $this->addError('mobile', '操作失败,其他司机[****'. mb_substr($is->name, -1) . $is->id .']已绑定此用户!请更换');
  44. return false;
  45. }
  46. }
  47. return true;
  48. }
  49. return false;
  50. }
  51. public function getSaasUser() {
  52. $saas_user_id = $this->saas_user_id ?? 0;
  53. $saas_user = SaasUser::findOne($saas_user_id);
  54. return $saas_user;
  55. }
  56. public static function getByAdminId($admin_id, $status = -1) {
  57. $query = self::find()->where(['admin_id' => $admin_id, 'is_delete' => 0]);
  58. if($status >= 0){
  59. $query->andWhere(['status' => $status]);
  60. }
  61. return $query->all();
  62. }
  63. }