Banner.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. /**
  10. * This is the model class for table "{{%banner}}".
  11. *
  12. * @property integer $id
  13. * @property integer $store_id
  14. * @property string $pic_url
  15. * @property string $title
  16. * @property string $page_url
  17. * @property integer $sort
  18. * @property integer $created_at
  19. * @property integer $is_delete
  20. * @property integer $type
  21. * @property string $open_type
  22. * @property integer $md_id
  23. */
  24. class Banner extends \yii\db\ActiveRecord
  25. {
  26. /**
  27. * 商城
  28. */
  29. const TYPE_STORE = 1;
  30. /**
  31. * 点餐
  32. */
  33. const TYPE_FOOD = 2;
  34. /**
  35. * SAAS
  36. */
  37. const TYPE_SAAS = 3;
  38. /**
  39. * @inheritdoc
  40. */
  41. public static function tableName()
  42. {
  43. return '{{%banner}}';
  44. }
  45. /**
  46. * @inheritdoc
  47. */
  48. public function rules()
  49. {
  50. return [
  51. [['store_id', 'pic_url', 'title'], 'required'],
  52. [['store_id', 'sort', 'created_at', 'is_delete', 'type', 'md_id'], 'integer'],
  53. [['pic_url', 'page_url'], 'string'],
  54. [['title', 'open_type'], 'string', 'max' => 255],
  55. ['type', 'default', 'value' => 1,],
  56. ];
  57. }
  58. /**
  59. * @inheritdoc
  60. */
  61. public function attributeLabels()
  62. {
  63. return [
  64. 'id' => 'ID',
  65. 'store_id' => '商城id',
  66. 'pic_url' => '图片url',
  67. 'title' => '标题',
  68. 'page_url' => '页面路径',
  69. 'sort' => '排序,升序',
  70. 'created_at' => '添加时间',
  71. 'is_delete' => '是否删除:0=未删除,1=已删除',
  72. 'type' => '类型1 => 商城,2 => 点餐',
  73. 'open_type' => 'Open Type',
  74. ];
  75. }
  76. /**
  77. * @return array
  78. */
  79. public function saveBanner()
  80. {
  81. if ($this->validate()) {
  82. if ($this->save()) {
  83. return [
  84. 'code' => 0,
  85. 'msg' => '成功'
  86. ];
  87. } else {
  88. return [
  89. 'code' => 1,
  90. 'msg' => '失败'
  91. ];
  92. }
  93. } else {
  94. return $this->errors[0];
  95. }
  96. }
  97. }