No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

233 líneas
8.0 KiB

  1. <?php
  2. namespace backend\modules\motorcade\models;
  3. use backend\modules\zzcs\models\BaseResource;
  4. use common\models\zModel;
  5. use Yii;
  6. /**
  7. * This is the model class for table "base_driver".
  8. *
  9. * @property integer $DRIVER_ID
  10. * @property integer $CREATE_USER_ID
  11. * @property string $CREATE_TIME
  12. * @property integer $UPDATE_USER_ID
  13. * @property string $UPDATE_TIME
  14. * @property integer $CANCEL_FLAG
  15. * @property string $DRIVER_NAME
  16. * @property string $DRIVER_NUMBER
  17. * @property integer $SEX
  18. * @property integer $AGE
  19. * @property string $PHONE_NO
  20. * @property integer $ORG_ID
  21. * @property string $ID_NUMBER
  22. * @property string $LICENSE_NO
  23. * @property integer $BELONG
  24. * @property integer $DRIVER_STATUS
  25. * @property string $DRIVER_BIRTHDAY
  26. * @property string $FIRST_LICENSE_DATE
  27. * @property integer $AREA_ID
  28. * @property string $ADDRESS
  29. * @property string $LICENSE_START_DATE
  30. * @property integer $VALID_YEARS
  31. *
  32. * @property BusOrder[] $busOrders
  33. */
  34. class BaseDriver extends zModel
  35. {
  36. const DRIVER_STATUS_NORMAL = 0;
  37. const DRIVER_STATUS_UNNORMAL = 1;
  38. const BELONG_OWN = 523; //自有
  39. const BELONG_ATTACHED = 524; //挂靠
  40. const BELONG_OUTSIDE = 525; //外部
  41. public $province = 791;
  42. public $city;
  43. public $country;
  44. public $outMotorcade = 1;
  45. public function __construct(array $config = [])
  46. {
  47. $this->CANCEL_FLAG = 0;
  48. parent::__construct($config);
  49. }
  50. public function init()
  51. {
  52. $this->DRIVER_BIRTHDAY = date('Y-m-d');
  53. $this->DRIVER_STATUS = 0;
  54. $this->SEX = 1;
  55. $this->DRIVER_STATUS = 0;
  56. $this->ORG_ID = Yii::$app->user->identity->ORG_ID;
  57. $this->MAIN_CORP_ID = Yii::$app->user->identity->MAIN_CORP_ID2;
  58. parent::init();
  59. }
  60. /**
  61. * @inheritdoc
  62. */
  63. public function scenarios()
  64. {
  65. $scenarios = parent::scenarios();
  66. $scenarios['default'] = ['CANCEL_FLAG'];
  67. $scenarios['create'] = ['province', 'city', 'country', 'outMotorcade', 'BELONG', 'CREATE_USER_ID', 'CREATE_TIME', 'DRIVER_NAME', 'ORG_ID', 'DRIVER_STATUS', 'DRIVER_NUMBER', 'SEX', 'ID_NUMBER', 'DRIVER_BIRTHDAY', 'PHONE_NO', 'AREA_ID', 'ADDRESS','MAIN_CORP_ID'];
  68. $scenarios['update'] = ['province', 'city', 'country', 'outMotorcade', 'BELONG', 'UPDATE_USER_ID', 'UPDATE_TIME', 'ORG_ID', 'DRIVER_STATUS', 'DRIVER_NUMBER', 'SEX', 'ID_NUMBER', 'DRIVER_BIRTHDAY', 'PHONE_NO', 'AREA_ID', 'ADDRESS','MAIN_CORP_ID'];
  69. $scenarios['delete'] = ['CANCEL_FLAG'];
  70. return $scenarios;
  71. }
  72. /**
  73. * @inheritdoc
  74. */
  75. public static function tableName()
  76. {
  77. return 'base_driver';
  78. }
  79. /**
  80. * @inheritdoc
  81. */
  82. public function rules()
  83. {
  84. return [
  85. [['CREATE_USER_ID', 'UPDATE_USER_ID', 'CANCEL_FLAG', 'SEX', 'AGE', 'ORG_ID', 'DRIVER_STATUS', 'AREA_ID', 'VALID_YEARS', 'BELONG', ], 'integer'],
  86. [['DRIVER_NAME', 'ID_NUMBER','PHONE_NO','DRIVER_BIRTHDAY', 'ADDRESS', 'SEX'], 'required'],
  87. [['PHONE_NO'], 'required', 'message' => '请填写联系手机号'],
  88. [['DRIVER_NAME', 'ADDRESS'], 'trim'],
  89. [['ORG_ID'], 'integer', 'skipOnEmpty' => true],
  90. [['province', 'city', 'country', 'outMotorcade'], 'safe'],
  91. // [['DRIVER_NAME'], 'unique', 'targetAttribute' => ['DRIVER_NAME', 'CANCEL_FLAG'], 'message' => '司机已经存在'],
  92. [['ID_NUMBER'], 'unique', 'targetAttribute' => ['ID_NUMBER', 'CANCEL_FLAG'], 'message' => '身份证已经存在'],
  93. [['PHONE_NO'], 'unique', 'targetAttribute' => ['PHONE_NO', 'CANCEL_FLAG'], 'message' => '手机号已经存在'],
  94. [['PHONE_NO'], 'match', 'pattern' => '/^\d{11}$/', 'message' => '请正确填写联系手机号'],
  95. [['ID_NUMBER'], 'match', 'pattern' => '/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/', 'message' => '请正确填写身份证号'],
  96. [['DRIVER_BIRTHDAY', 'FIRST_LICENSE_DATE', 'LICENSE_START_DATE'], 'string', 'max' => 20],
  97. [['LICENSE_NO'], 'string', 'max' => 50],
  98. [['ADDRESS', 'DRIVER_NUMBER'], 'string', 'max' => 30],
  99. ];
  100. }
  101. /**
  102. * @inheritdoc
  103. */
  104. public function attributeLabels()
  105. {
  106. return [
  107. 'DRIVER_ID' => '司机',
  108. 'CREATE_USER_ID' => '添加用户',
  109. 'CREATE_TIME' => '添加时间',
  110. 'UPDATE_USER_ID' => '用户',
  111. 'UPDATE_TIME' => '更新时间',
  112. 'CANCEL_FLAG' => '标识',
  113. 'DRIVER_NAME' => '姓名',
  114. 'DRIVER_NUMBER' => '工号',
  115. 'SEX' => '性别',
  116. 'AGE' => '年龄',
  117. 'PHONE_NO' => '手机号',
  118. 'ORG_ID' => '车队',
  119. 'ID_NUMBER' => '身份证',
  120. 'LICENSE_NO' => '驾驶证',
  121. 'DRIVER_STATUS' => '司机状态',
  122. 'DRIVER_BIRTHDAY' => '出生日期',
  123. 'FIRST_LICENSE_DATE' => '初次领证日期',
  124. 'AREA_ID' => '区域',
  125. 'ADDRESS' => '详细地址',
  126. 'LICENSE_START_DATE' => '有效起始日期',
  127. 'VALID_YEARS' => '有效期限',
  128. ];
  129. }
  130. /**
  131. * @return \yii\db\ActiveQuery
  132. */
  133. public function getBusOrders()
  134. {
  135. return $this->hasMany(BusOrder::className(), ['send_bus_driver_res_id' => 'DRIVER_ID']);
  136. }
  137. public function getBaseDocument()
  138. {
  139. return $this->hasMany(BaseDocument::className(), ['DOC_ID' => 'DRIVER_ID']);
  140. }
  141. /**
  142. * @return \yii\db\ActiveQuery
  143. */
  144. public function getOrganization()
  145. {
  146. return $this->hasOne(BaseResource::className(), ['RES_ID' => 'ORG_ID']);
  147. }
  148. /**
  149. * 证件资料
  150. * @return array
  151. */
  152. public function getDocument()
  153. {
  154. $result = [502 => [], 503 => [], 504 => []];
  155. //以502 503 504为数组元素返回
  156. $documents = BaseDocument::findAll(['CANCEL_FLAG' => 0, 'DOC_TYPE' => BaseDocument::DRIVER, 'DOC_ID' => $this->DRIVER_ID]);
  157. if (count($documents) > 0) {
  158. foreach ($documents as $document) {
  159. $document->setScenario('driver');
  160. if ($document->DOC_OPTION == '502') {
  161. $result[502][] = $document;
  162. }
  163. if ($document->DOC_OPTION == '503') {
  164. $result[503][] = $document;
  165. }
  166. if ($document->DOC_OPTION == '504') {
  167. $result[504][] = $document;
  168. }
  169. }
  170. }
  171. while (count($result[502]) < 2) {
  172. $result[502][] = new BaseDocument(['scenario' => 'driver']);
  173. }
  174. while (count($result[503]) < 1) {
  175. $result[503][] = new BaseDocument(['scenario' => 'driver']);
  176. }
  177. while (count($result[504]) < 2) {
  178. $result[504][] = new BaseDocument(['scenario' => 'driver']);
  179. }
  180. // else {
  181. // $result[502] = [new BaseDocument(), new BaseDocument()];
  182. // $result[503] = [new BaseDocument()];
  183. // $result[504] = [new BaseDocument(), new BaseDocument()];
  184. // }
  185. return $result;
  186. // return $this->hasMany(BaseDocument::className(), ['DOC_ID' => 'DRIVER_ID'])->where(['DOC_TYPE' => BaseDocument::DRIVER]);
  187. }
  188. /**
  189. * User: wangxj
  190. *
  191. * 根据form加载数据
  192. *
  193. * @params $data
  194. *
  195. * @return
  196. */
  197. // public function load($data, $formName = null)
  198. // {
  199. // parent::load($data, $formName);
  200. //
  201. // $form = $data['BaseDriver'];
  202. // $this->setAttributes($form);
  203. //// $this->province = $form['pri'];
  204. // }
  205. public function beforeSave($insert)
  206. {
  207. //联系地址的省市
  208. $this->AREA_ID = $this->country ? $this->country : $this->city;
  209. $this->ORG_ID = $this->outMotorcade == 1 ? Yii::$app->user->identity->ORG_ID : $this->ORG_ID;
  210. $this->CREATE_TIME = date('Y-m-d H:i:s', time());
  211. $this->CREATE_USER_ID = Yii::$app->user->id;
  212. $this->UPDATE_USER_ID = Yii::$app->user->id;
  213. return parent::beforeSave($insert);
  214. }
  215. }