| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?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 "{{%share_level}}".
- *
- * @property integer $id
- * @property string $name
- * @property integer $level
- * @property integer $is_auto_upgrade
- * @property integer $type
- * @property string $value
- * @property string $condition
- * @property integer $profit_type
- * @property string $first_profit
- * @property string $second_profit
- * @property string $third_profit
- * @property string $order_layer
- * @property string $point_reward
- * @property integer $status
- * @property string $desc
- * @property integer $store_id
- * @property integer $is_delete
- * @property integer $created_at
- * @property integer $updated_at
- */
- class ShareLevel extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%share_level}}';
- }
- /**
- * 是否自动升级
- */
- CONST AUTO_UPGRADE = 1; //自动升级
- CONST NO_AUTO_UPGRADE = 0; //不自动升级
- public static $valid_auto_upgrade_arr = [
- self::AUTO_UPGRADE,
- self::NO_AUTO_UPGRADE
- ];
- /**
- * 删除状态
- */
- CONST SHARE_IS_DELETE = 1; //已删除
- CONST SHARE_NOT_DELETE = 0; //未删除
- /**
- * 升级条件
- */
- CONST TYPE_MEMBER = 0; //下级人数
- CONST TYPE_COMMISSION = 1; //累计佣金
- CONST TYPE_SEND_COMMISSION = 2; //已提现佣金
- CONST TYPE_AMOUNT = 3; //累计消费金额
- CONST TYPE_COIN = 4; //累计贡献积分
- CONST TYPE_SHARE_BASE = 5; //累计固定基数
- CONST TYPE_MEMBER_PERFORMANCE = 6; //累计直推用户贡献积分业绩
- public static $valid_type_arr = [
- self::TYPE_MEMBER,
- self::TYPE_COMMISSION,
- self::TYPE_SEND_COMMISSION,
- self::TYPE_AMOUNT,
- self::TYPE_COIN,
- self::TYPE_SHARE_BASE,
- self::TYPE_MEMBER_PERFORMANCE
- ];
- /**
- * 启用状态
- */
- CONST STATUS_ON = 1; //启用
- CONST STATUS_OFF = 0; //禁用
- public static $valid_status_arr = [
- self::STATUS_ON,
- self::STATUS_OFF
- ];
- /**
- * 分销佣金类型
- */
- CONST PROFIT_TYPE_PROGRESS = 0; //百分比
- CONST PROFIT_TYPE_MONEY = 1; //固定金额
- public static $valid_profit_arr = [
- self::PROFIT_TYPE_PROGRESS,
- self::PROFIT_TYPE_MONEY
- ];
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['id', 'level', 'is_auto_upgrade', 'type', 'profit_type', 'status', 'store_id', 'is_delete', 'order_layer'], 'integer'],
- [['value', 'first_profit', 'second_profit', 'third_profit', 'point_reward'], 'number'],
- [['name', 'desc', 'condition'], 'string'],
- [['created_at', 'updated_at'], 'safe']
- ];
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'value' => time()
- ]
- ];
- }
- public function beforeSave($insert)
- {
- if (parent::beforeSave($insert)) {
- $is = self::findOne(['level' => $this->level, 'store_id' => $this->store_id, 'is_delete' => self::SHARE_NOT_DELETE]);
- if ($is) {
- $open = false;
- if ($this->id && $this->id !== $is->id) {
- $open = true;
- }
- if (!$this->id) {
- $open = true;
- }
- if ($open) {
- $this->addError('level', '操作失败,当前等级不可用');
- return false;
- }
- }
- // if ($this->type && !in_array($this->type, self::$valid_type_arr)) {
- // $this->addError('type', '操作失败,升级条件类型信息错误');
- // return false;
- // }
- if ($this->status && !in_array($this->status, self::$valid_status_arr)) {
- $this->addError('status', '操作失败,启用状态错误');
- return false;
- }
- if ($this->profit_type && !in_array($this->profit_type, self::$valid_profit_arr)) {
- $this->addError('profit_type', '操作失败,分销佣金类型错误');
- return false;
- }
- if ($this->is_auto_upgrade && !in_array($this->is_auto_upgrade, self::$valid_auto_upgrade_arr)) {
- $this->addError('is_auto_upgrade', '操作失败,是否自动升级类型错误');
- return false;
- }
- }
- return true;
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- "id" => "ID",
- "name" => "名称",
- "level" => "等级",
- "is_auto_upgrade" => "是否自动升级",
- "type" => "升级条件类型",
- "value" => "升级条件值",
- "condition" => "升级条件值",
- "profit_type" => "分销佣金类型",
- "first_profit" => "一级佣金",
- "second_profit" => "二级佣金",
- "third_profit" => "三级佣金",
- "status" => "启用状态",
- "desc" => "等级说明",
- "store_id" => "Store Id",
- "is_delete" => "is Delete",
- "created_at" => "创建时间",
- "updated_at" => "修改时间",
- ];
- }
- }
|