| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%activity_rebate_order_self_level}}".
- *
- * @property integer $id
- */
- class ActivityOrderRebateSelfLevel extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%activity_rebate_order_self_level}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- ]
- ];
- }
-
- public function beforeSave($insert) {
- if(parent::beforeSave($insert)){
-
- $query = self::find()->where(['level' => $this->level, 'status' => 1, 'store_id' => $this->store_id,'is_delete' => 0]);
- $has = $query->andWhere([
- '!=', 'id', (int)$this->id
- ])->one();
- if($has){
- $this->addError('level', '操作失败,等级已存在,等级id:' . $has->id);
- return false;
- }
- $al1 = self::find()->where(['store_id' => $this->store_id, 'status' => 1,'is_delete' => 0])->andWhere(['<', 'level', $this->level])->andWhere(['!=', 'level', $this->getOldAttribute('level')])->orderBy('level DESC')->limit(1)->one();
- if($al1 && $this->money <= $al1->money && $this->child_num <= $al1->child_num && $this->child_level <= $al1->child_level){
- $this->addError('level', '操作失败,等级升级规则错误(金额、下级数量,下级等级,不能低于上一个等级),对比等级:' . $al1->level);
- return false;
- }
- $al2 = self::find()->where(['store_id' => $this->store_id, 'status' => 1,'is_delete' => 0])->andWhere(['>', 'level', $this->level])->andWhere(['!=', 'level', $this->getOldAttribute('level')])->orderBy('level ASC')->limit(1)->one();
- if($al2 && $this->money >= $al2->money && $this->child_num >= $al2->child_num && $this->child_level >= $al2->child_level){
- $this->addError('level', '操作失败,等级升级规则错误(金额、下级数量,下级等级,不能高于下一个等级),对比等级:' . $al2->level);
- return false;
- }
-
- if(!$insert && (
- ($this->getOldAttribute('level') != $this->level)
- || ($this->getOldAttribute('status') != $this->status && $this->status == 0)
- || ($this->getOldAttribute('is_delete') != $this->is_delete && $this->is_delete == 1)
- )){
- $count = ActivityOrderRebateSelfUser::find()->where(['store_id' => $this->store_id, 'level' => $this->getOldAttribute('level')])->count();
- if($count > 0) {
- $this->addError('level', '操作失败,当前等级下有会员,禁止修改等级,会员数量' . $count);
- return false;
- }
- }
- return true;
- }
- return false;
- }
- }
|