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(); } }