| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use yii\db\ActiveRecord;
- use yii\behaviors\TimestampBehavior;
- use Yii;
- /**
- * This is the model class for table "{{%md_foods_qrcode}}".
- *
- * @property integer $id
- * @property integer $store_id
- * @property integer $md_id
- * @property integer $is_disabled
- * @property string $url_path
- * @property string $qrcode_url
- * @property string $mini_path
- * @property integer $parent_id
- * @property integer $wx_status
- * @property integer $ali_status
- * @property string $table_num
- * @property integer $is_delete
- * @property string $created_at
- * @property string $updated_at
- */
- class MdFoodsQrcode extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%md_foods_qrcode}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
- ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
- ]
- ]
- ];
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['store_id', 'is_delete', 'id', 'parent_id', 'md_id', 'is_disabled', 'table_num', 'wx_status', 'ali_status'], 'integer'],
- [['url_path', 'qrcode_url', 'mini_path'], 'string'],
- [['created_at', 'updated_at'], 'safe']
- ];
- }
- public function beforeSave($insert)
- {
- if (parent::beforeSave($insert)) {
- // if ($this->parent_id) {
- // $parent_qrcode = MdFoodsQrcode::findOne(['id' => $this->parent_id, 'is_delete' => 0]);
- // if ($parent_qrcode && $parent_qrcode->parent_id) {
- // $parent_qrcode_ = MdFoodsQrcode::findOne(['id' => $parent_qrcode->parent_id, 'is_delete' => 0]);
- // if ($parent_qrcode_) {
- // $this->is_disabled = 1;
- // }
- // }
- // }
- return true;
- }
- return false;
- }
- public function afterSave($insert, $changedAttributes)
- {
- parent::afterSave($insert, $changedAttributes);
- //$this->saveChild($this->id, $insert);
- }
- public function saveChild($id, $insert) {
- if ($insert) {
- if ($this->parent_id) {
- $parent = self::findOne(['id' => $this->parent_id, 'is_delete' => 0]);
- $self = self::findOne(['id' => $id]);
- if ($parent) {
- $self->store_id = $parent->store_id;
- $self->md_id = $parent->md_id;
- $self->is_delete = $parent->is_delete;
- $self->save();
- }
- }
- } else {
- $parent = self::findOne(['id' => $id]);
- $qrcode_list = self::findAll(['parent_id' => $id, 'is_delete' => 0]);
- foreach ($qrcode_list as $qrcode) {
- $qrcode->store_id = $parent->store_id;
- $qrcode->md_id = $parent->md_id;
- $qrcode->is_delete = $parent->is_delete;
- $qrcode->save();
- }
- }
- }
- public function getChildren()
- {
- return $this->hasMany(self::class, ['parent_id' => 'id'])->andWhere(['is_delete' => 0]);
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => '',
- 'store_id' => '店铺id',
- 'url_path' => '地址',
- 'qrcode_url' => '二维码保存地址',
- 'parent_id' => '父级id',
- 'table_num' => '桌号',
- 'mini_path' => '小程序路径',
- 'is_delete' => '',
- 'created_at' => '',
- 'updated_at' => '',
- ];
- }
- // public function getShopPic()
- // {
- // return $this->hasMany(ShopPic::className(), ['shop_id'=>'id'])->where(['is_delete'=>0]);
- // }
- }
|