AdoptCat.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\plugins\adopt\models;
  8. use yii\behaviors\TimestampBehavior;
  9. use yii\db\ActiveRecord;
  10. /**
  11. * 土地分类
  12. * Class FoodCat
  13. * @package app\plugins\food\models
  14. * @property integer $id
  15. * @property integer $store_id
  16. * @property string $name
  17. * @property string $pic_url
  18. * @property integer $sort
  19. * @property integer $is_delete
  20. * @property string $is_show
  21. * @property string $created_at
  22. * @property string $updated_at
  23. */
  24. class AdoptCat extends ActiveRecord
  25. {
  26. public function behaviors()
  27. {
  28. return [
  29. [
  30. // 自动更新创建和更新时间
  31. 'class' => TimestampBehavior::class,
  32. 'value' => time()
  33. ]
  34. ];
  35. }
  36. public static function tableName()
  37. {
  38. return '{{%adopt_cat}}';
  39. }
  40. public function rules()
  41. {
  42. return [
  43. [['store_id', 'name',], 'required'],
  44. [['store_id', 'sort', 'created_at', 'updated_at', 'is_delete', 'is_show'], 'integer'],
  45. [['pic_url'], 'string'],
  46. [['name'], 'string', 'max' => 255],
  47. ];
  48. }
  49. public function attributeLabels()
  50. {
  51. return [
  52. 'id' => 'ID',
  53. 'store_id' => '商城id',
  54. 'name' => '分类名称',
  55. 'pic_url' => '分类图片url',
  56. 'sort' => '排序,升序',
  57. 'created_at' => '创建时间',
  58. 'updated_at' => '更新时间',
  59. 'is_delete' => 'Is Delete',
  60. 'is_show' => '是否显示',
  61. ];
  62. }
  63. public static function getCatId($parent_id, &$cat_list = [])
  64. {
  65. $cat_list[] = $parent_id;
  66. $query = self::find()->where([
  67. 'id' => $parent_id,
  68. 'is_delete' => 0,
  69. 'store_id' => get_store_id()
  70. ])->orderBy(['sort'=>SORT_DESC]);
  71. $query->andWhere([
  72. 'is_show' => 1
  73. ]);
  74. $cat = $query->asArray()->all();
  75. if (empty($cat)) {
  76. return $cat_list;
  77. }
  78. foreach ($cat as &$val) {
  79. self::getCatId($val['id'], $cat_list);
  80. }
  81. return $cat_list;
  82. }
  83. }