| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- <?php
- namespace addons\OperationCenter\common\models;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "{{%addons_operation_center_level}}".
- *
- * @property int $id
- * @property int $mall_id Mall Id
- * @property string $name 等级名称
- * @property int $level 等级权重
- * @property int $commission1_type 1级佣金奖励类型
- * @property float $commission1_value 1级佣金数量
- * @property int $commission2_type 2级佣金奖励类型
- * @property float $commission2_value 2级佣金数量
- * @property int $is_auto_upgrade 是否自动升级
- * @property int $upgrade_type_condition 是否开启条件升级
- * @property string|null $checked_condition_values 升级条件
- * @property string|null $checked_condition_keys 升级条件选中的key集合
- * @property int $upgrade_type_goods 购买升级商品,0关闭,1开启
- * @property int $buy_goods_type 购买升级商品触发升级:0订单完成 1下单完成
- * @property int|null $goods_type 商品升级类型,1- 任意商品 2- 指定商品
- * @property string|null $goods_ids 商品id集合
- * @property string|null $goods_list 商品列表json
- * @property string|null $explain 等级说明
- * @property int $status 等级开启状态
- * @property int|null $deleted_at
- * @property int|null $updated_at
- * @property int|null $created_at
- */
- class Level extends BaseActiveRecord
- {
- /**
- * 比例
- */
- const RATIO = 1;
- /**
- * 固定
- */
- const FIXED = 2;
- /**
- * @var array
- */
- protected $json_keys = [
- 'checked_condition_values', 'checked_condition_keys', 'goods_ids', 'goods_list'
- ];
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_operation_center_level}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'name', 'level'], 'required'],
- [['mall_id', 'level', 'commission1_type', 'commission2_type', 'is_auto_upgrade', 'upgrade_type_condition', 'upgrade_type_goods', 'buy_goods_type', 'goods_type', 'status', 'deleted_at', 'updated_at', 'created_at'], 'integer'],
- [['commission1_value', 'commission2_value'], 'number'],
- [['checked_condition_values', 'checked_condition_keys', 'goods_ids', 'goods_list'], 'string'],
- [['name'], 'string', 'max' => 64],
- [['explain'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'name' => 'Name',
- 'level' => 'Level',
- 'commission1_type' => 'Commission1 Type',
- 'commission1_value' => 'Commission1 Value',
- 'commission2_type' => 'Commission2 Type',
- 'commission2_value' => 'Commission2 Value',
- 'is_auto_upgrade' => 'Is Auto Upgrade',
- 'upgrade_type_condition' => 'Upgrade Type Condition',
- 'checked_condition_values' => 'Checked Condition Values',
- 'checked_condition_keys' => 'Checked Condition Keys',
- 'upgrade_type_goods' => 'Upgrade Type Goods',
- 'buy_goods_type' => 'Buy Goods Type',
- 'goods_type' => 'Goods Type',
- 'goods_ids' => 'Goods Ids',
- 'goods_list' => 'Goods List',
- 'explain' => 'Explain',
- 'status' => 'Status',
- 'deleted_at' => 'Deleted At',
- 'updated_at' => 'Updated At',
- 'created_at' => 'Created At',
- ];
- }
- /**
- * 获取开启的等级列表
- *
- * @param integer $mall_id
- * @return array
- */
- public static function getOpenLevelList(int $mall_id)
- {
- return static::find()
- ->andWhere(['mall_id' => $mall_id, 'status' => 1])
- ->select(['id', 'name', 'level'])
- ->asArray()
- ->all();
- }
- /**
- * 获取权重
- *
- * @param integer $mall_id
- * @return array
- */
- public static function getLevelWeights(int $mall_id)
- {
- $list = self::find()->select('level')->andWhere(['mall_id' => $mall_id])->column();
- $newList = [];
- for ($i = 1; $i <= 10; $i++) {
- $newList[] = [
- 'name' => '等级' . $i,
- 'level' => $i,
- 'disabled' => in_array($i, $list),
- ];
- }
- return $newList;
- }
- /**
- * 设置等级数据
- *
- * @param array $data
- * @return true|static
- */
- public function setLevelData(array $data)
- {
- $data = $this->jsonEncode($data);
- $this->load($data, '');
- return $this->save() ? true : $this;
- }
- /**
- * 获取等级详情
- *
- * @param integer $id
- * @return static|null
- */
- public static function getLevelDetail(int $mall_id, int $id)
- {
- return static::find()
- ->andWhere(['mall_id' => $mall_id, 'id' => $id])
- ->one();
- }
- /**
- * 等级删除
- *
- * @return mixed
- */
- public function delLevel()
- {
- return $this->delete();
- }
- /**
- * 通过分佣等级(直推 间推)获取分佣类型
- *
- * @param int $level
- * @return int
- */
- public function getCommissionTypeByLevel($level)
- {
- $key = sprintf('commission%s_type', $level);
- return $this->{$key};
- }
- /**
- * 通过分佣等级(直推 间推)获取分佣数量
- *
- * @param int $level
- * @return float
- */
- public function getCommissionValueByLevel($level)
- {
- $key = sprintf('commission%s_value', $level);
- return $this->{$key};
- }
- /**
- * @return boolean
- */
- public function hasUpgrade()
- {
- return (boolean) $this->is_auto_upgrade;
- }
- /**
- * @return boolean
- */
- public function openGoodsUpgrade()
- {
- return (boolean) $this->upgrade_type_goods;
- }
- /**
- * @param integer $is_finish
- * @return boolean
- */
- public function buyGoodsType(int $is_finish)
- {
- if ($is_finish == 0 && $this->buy_goods_type == 1) {
- return true;
- }
- if ($is_finish == 1 && $this->buy_goods_type == 0) {
- return true;
- }
- return false;
- // return $this->buy_goods_type == $is_finish;
- }
- /**
- * 是否升级商品
- *
- * @param integer $goods_id
- * @return boolean
- */
- public function isUpgradeGoods(int $goods_id)
- {
- // 任意商品
- if ($this->goods_type == 1) {
- return true;
- }
- // 指定商品
- if (in_array($goods_id, $this->getGoodsIds())) {
- return true;
- }
- return false;
- }
- /**
- * @return array
- */
- public function getGoodsIds()
- {
- if ($this->goods_ids) {
- return Json::decode($this->goods_ids);
- }
- return [];
- }
- /**
- * 查询大于等级的等级
- *
- * @param integer $mall_id
- * @param integer $level
- * @return array
- */
- public static function getLevelByGtLevel(int $mall_id, int $level)
- {
- return static::find()
- ->andWhere(
- ['=', 'mall_id', $mall_id],
- )
- ->andWhere(
- ['>', 'level', $level]
- )
- ->andWhere(['status' => 1])
- ->orderBy('level desc')
- ->all();
- }
- }
|