MdFoodsQrcode.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use yii\db\ActiveRecord;
  9. use yii\behaviors\TimestampBehavior;
  10. use Yii;
  11. /**
  12. * This is the model class for table "{{%md_foods_qrcode}}".
  13. *
  14. * @property integer $id
  15. * @property integer $store_id
  16. * @property integer $md_id
  17. * @property integer $is_disabled
  18. * @property string $url_path
  19. * @property string $qrcode_url
  20. * @property string $mini_path
  21. * @property integer $parent_id
  22. * @property integer $wx_status
  23. * @property integer $ali_status
  24. * @property string $table_num
  25. * @property integer $is_delete
  26. * @property string $created_at
  27. * @property string $updated_at
  28. */
  29. class MdFoodsQrcode extends \yii\db\ActiveRecord
  30. {
  31. /**
  32. * @inheritdoc
  33. */
  34. public static function tableName()
  35. {
  36. return '{{%md_foods_qrcode}}';
  37. }
  38. public function behaviors()
  39. {
  40. return [
  41. [
  42. 'class' => TimestampBehavior::class,
  43. 'attributes' => [
  44. ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
  45. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
  46. ]
  47. ]
  48. ];
  49. }
  50. /**
  51. * @inheritdoc
  52. */
  53. public function rules()
  54. {
  55. return [
  56. [['store_id', 'is_delete', 'id', 'parent_id', 'md_id', 'is_disabled', 'table_num', 'wx_status', 'ali_status'], 'integer'],
  57. [['url_path', 'qrcode_url', 'mini_path'], 'string'],
  58. [['created_at', 'updated_at'], 'safe']
  59. ];
  60. }
  61. public function beforeSave($insert)
  62. {
  63. if (parent::beforeSave($insert)) {
  64. // if ($this->parent_id) {
  65. // $parent_qrcode = MdFoodsQrcode::findOne(['id' => $this->parent_id, 'is_delete' => 0]);
  66. // if ($parent_qrcode && $parent_qrcode->parent_id) {
  67. // $parent_qrcode_ = MdFoodsQrcode::findOne(['id' => $parent_qrcode->parent_id, 'is_delete' => 0]);
  68. // if ($parent_qrcode_) {
  69. // $this->is_disabled = 1;
  70. // }
  71. // }
  72. // }
  73. return true;
  74. }
  75. return false;
  76. }
  77. public function afterSave($insert, $changedAttributes)
  78. {
  79. parent::afterSave($insert, $changedAttributes);
  80. //$this->saveChild($this->id, $insert);
  81. }
  82. public function saveChild($id, $insert) {
  83. if ($insert) {
  84. if ($this->parent_id) {
  85. $parent = self::findOne(['id' => $this->parent_id, 'is_delete' => 0]);
  86. $self = self::findOne(['id' => $id]);
  87. if ($parent) {
  88. $self->store_id = $parent->store_id;
  89. $self->md_id = $parent->md_id;
  90. $self->is_delete = $parent->is_delete;
  91. $self->save();
  92. }
  93. }
  94. } else {
  95. $parent = self::findOne(['id' => $id]);
  96. $qrcode_list = self::findAll(['parent_id' => $id, 'is_delete' => 0]);
  97. foreach ($qrcode_list as $qrcode) {
  98. $qrcode->store_id = $parent->store_id;
  99. $qrcode->md_id = $parent->md_id;
  100. $qrcode->is_delete = $parent->is_delete;
  101. $qrcode->save();
  102. }
  103. }
  104. }
  105. public function getChildren()
  106. {
  107. return $this->hasMany(self::class, ['parent_id' => 'id'])->andWhere(['is_delete' => 0]);
  108. }
  109. /**
  110. * @inheritdoc
  111. */
  112. public function attributeLabels()
  113. {
  114. return [
  115. 'id' => '',
  116. 'store_id' => '店铺id',
  117. 'url_path' => '地址',
  118. 'qrcode_url' => '二维码保存地址',
  119. 'parent_id' => '父级id',
  120. 'table_num' => '桌号',
  121. 'mini_path' => '小程序路径',
  122. 'is_delete' => '',
  123. 'created_at' => '',
  124. 'updated_at' => '',
  125. ];
  126. }
  127. // public function getShopPic()
  128. // {
  129. // return $this->hasMany(ShopPic::className(), ['shop_id'=>'id'])->where(['is_delete'=>0]);
  130. // }
  131. }