CategoryWatermark.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/25
  6. * Time: 下午8:42
  7. */
  8. namespace common\models;
  9. //use yii\db\ActiveRecord;
  10. //use yii\behaviors\TimestampBehavior;
  11. class CategoryWatermark extends Common
  12. {
  13. // public $setDel = 1;
  14. // public function behaviors()
  15. // {
  16. // return [
  17. // [
  18. // 'class' => TimestampBehavior::className(),
  19. // 'attributes' => [
  20. // # 创建之前
  21. // ActiveRecord::EVENT_BEFORE_INSERT => ['create_at', 'update_at'],
  22. // # 修改之前
  23. // ActiveRecord::EVENT_BEFORE_UPDATE => ['update_at']
  24. // ],
  25. // #设置默认值
  26. // 'value' => $_SERVER['REQUEST_TIME']
  27. // ]
  28. // ];
  29. // }
  30. public function getWatermarkInfo()
  31. {
  32. $query = self::find();
  33. $query->andWhere(['del'=>$this->setDel]);
  34. $query->andWhere(['status'=>1]);
  35. return $query->one();
  36. }
  37. public function rules()
  38. {
  39. return [
  40. [['width','height','position'],'required','message'=>'{attribute}不能为空'],
  41. ['position','in','range'=>[1,2,3,4,5,6,7,8,9]],
  42. [['width','height'],'number','max'=>300],
  43. ['spacing','number','max'=>50],
  44. ['status','in','range'=>[1,2]],
  45. ];
  46. }
  47. public function attributeLabels()
  48. {
  49. return [
  50. 'width'=>'宽度',
  51. 'height'=>'高度',
  52. 'position'=>'水印位置',
  53. 'spacing'=>'间距',
  54. ];
  55. }
  56. public function FindById($id)
  57. {
  58. return self::findOne($id);
  59. }
  60. }