You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.5 KiB

  1. <?php
  2. namespace goods\models\ars;
  3. use Yii;
  4. use yii\behaviors\TimestampBehavior;
  5. /**
  6. * This is the model class for table "atg_supplier".
  7. *
  8. * @property int $id
  9. * @property string $name 供应商名称
  10. * @property string $full_name 供应商全称
  11. * @property string $phone 手机号码
  12. * @property string $address 地址
  13. * @property int $is_delete 是否删除,1为已删除
  14. * @property int $created_at 创建时间
  15. * @property int $updated_at 更新时间
  16. */
  17. class Supplier extends \yii\db\ActiveRecord
  18. {
  19. //是否删除is_delete
  20. const IS_DELETE_NO = 0;//未删除
  21. const IS_DELETE_YES = 1;//已删除
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return 'atg_supplier';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['name', 'full_name', 'phone', 'address'], 'required'],
  36. [['is_delete'], 'integer'],
  37. [['name', 'full_name', 'address'], 'string', 'max' => 50],
  38. [['phone'], 'string', 'max' => 20],
  39. ['phone', 'filter', 'filter' => 'trim'],
  40. ['phone','match','pattern'=>'/^[1][34578][0-9]{9}$/'],
  41. ['phone', 'unique', 'targetClass' => '\goods\models\ars\Supplier', 'message' => '手机号已被使用'],
  42. ];
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function attributeLabels()
  48. {
  49. return [
  50. 'id' => 'id',
  51. 'name' => '供应商名称',
  52. 'full_name' => '供应商全称',
  53. 'phone' => '手机号码',
  54. 'address' => '地址',
  55. 'is_delete' => '是否删除,1为已删除',
  56. 'created_at' => '创建时间',
  57. 'updated_at' => '更新时间',
  58. ];
  59. }
  60. /**
  61. * @author linyao
  62. * @email 602604991@qq.com
  63. * @created Nov 8, 2019
  64. *
  65. * 行为存储创建时间和更新时间
  66. */
  67. public function behaviors()
  68. {
  69. return [
  70. [
  71. 'class' => TimestampBehavior::className(),
  72. 'createdAtAttribute' => 'created_at',
  73. 'updatedAtAttribute' => 'updated_at',
  74. 'value' => function() {
  75. return time();
  76. },
  77. ],
  78. ];
  79. }
  80. /**
  81. * @return array
  82. * 数据键值对
  83. */
  84. public static function modelColumn()
  85. {
  86. return $column = self::find()->select(['name'])->where(['is_delete' => self::IS_DELETE_NO])->indexBy('id')->column();
  87. }
  88. }