| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- namespace addons\LuckyGroup\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_lucky_group_level".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $level 等级权重
- * @property string $name 等级名称
- * @property float $team_commission 渠道奖佣金
- * @property int $is_percent_team 渠道奖类型 0百分比 1 固定金额
- * @property float $equal_commission 平级奖佣金
- * @property int $is_percent_equal 平级奖类型 0百分比 1 固定金额
- * @property float $over_commission 越级奖佣金
- * @property int $is_percent_over 越级奖类型 0百分比 1 固定金额
- * @property int $is_auto_upgrade 是否开启升级设置【1是 0否】
- * @property int $upgrade_type_goods 开启商品升级【1是 0否】
- * @property int $upgrade_type_condition 开启条件升级【1是 0否】
- * @property string|null $checked_condition_values 升级条件设置值列表
- * @property string|null $checked_condition_keys 选中条件的key值集合
- * @property int $condition_type 条件升级选项【0未选择 1满足其一 2满足所有】
- * @property int $goods_type 商品升级类型,1- 任意商品 2- 指定商品
- * @property string|null $goods_ids 指定升级商品的ID集合
- * @property int $buy_goods_type 购买商品升级时间场景【1订单完成 2支付】
- * @property int $init_attend_times 每日参团次数
- * @property string|null $desc 等级权益描述
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- */
- class LuckyGroupLevel extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_lucky_group_level}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'level', 'is_percent_team', 'is_percent_equal', 'is_percent_over', 'is_auto_upgrade', 'upgrade_type_goods', 'upgrade_type_condition', 'condition_type', 'goods_type', 'buy_goods_type', 'init_attend_times', 'status', 'created_at', 'updated_at'], 'integer'],
- [['team_commission', 'equal_commission', 'over_commission'], 'number'],
- [['checked_condition_values', 'checked_condition_keys', 'goods_ids', 'desc'], 'string'],
- [['name'], 'string', 'max' => 32],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'level' => '等级权重',
- 'name' => '等级名称',
- 'team_commission' => '渠道奖佣金',
- 'is_percent_team' => '渠道奖类型 0百分比 1 固定金额',
- 'equal_commission' => '平级奖佣金',
- 'is_percent_equal' => '平级奖类型 0百分比 1 固定金额',
- 'over_commission' => '越级奖佣金',
- 'is_percent_over' => '越级奖类型 0百分比 1 固定金额',
- 'is_auto_upgrade' => '是否开启升级设置【1是 0否】',
- 'upgrade_type_goods' => '开启商品升级【1是 0否】',
- 'upgrade_type_condition' => '开启条件升级【1是 0否】',
- 'checked_condition_values' => '升级条件设置值列表',
- 'checked_condition_keys' => '选中条件的key值集合',
- 'condition_type' => '条件升级选项【0未选择 1满足其一 2满足所有】',
- 'goods_type' => '商品升级类型,1- 任意商品 2- 指定商品',
- 'goods_ids' => '指定升级商品的ID集合',
- 'buy_goods_type' => '购买商品升级时间场景【1订单完成 2支付】',
- 'init_attend_times' => '每日参团次数',
- 'desc' => '等级权益描述',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- public static function setData(int $mall_id, array $data)
- {
- if (!empty($data['id'])) {
- $model = self::findOne(['mall_id' => $mall_id, 'status' => [StatusEnum::ENABLED], 'id' => $data['id']]);
- if (empty($model)) {
- self::$static_error = '分类数据异常';
- return false;
- }
- } else {
- $model = new self();
- $model->loadDefaultValues();
- $model->status = StatusEnum::ENABLED;
- $model->mall_id = $mall_id;
- unset($data['id']);
- }
- foreach ($data as $key => $val) {
- if (
- ('checked_condition_values' === $key || 'checked_condition_keys' == $key || 'goods_ids' == $key) &&
- !empty($val) &&
- is_array($val)
- ) {
- $val = json_encode($val);
- }
- $model->$key = $val;
- }
- if (!$model->save()) {
- self::$static_error = '保存数据失败:' . $model->getErrorMessage();
- return false;
- }
- return $model;
- }
- public static function getListByUpgrade($params = null)
- {
- if (!empty($params['mall_id'])) {
- $lists = self::find()
- ->select('id,level,name')
- ->where(['mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED])
- ->orderBy('level asc')
- ->asArray()
- ->all();
- // 不要权重为 0 的等级
- // if (!in_array(0, array_column($lists, 'level'))) {
- // array_unshift($lists, [
- // 'name' => "默认等级",
- // 'level' => 0,
- // 'id' => 0,
- // ]);
- // }
- } else {
- $lists = [];
- // array_unshift($lists, [
- // 'name' => "默认等级",
- // 'level' => 0,
- // 'id' => 0,
- // ]);
- }
- return $lists;
- }
- public static function getLevelWeights(int $mall_id)
- {
- $lists = self::find()
- ->select('level')
- ->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED])
- ->orderBy('level asc')
- ->asArray()
- ->column();
- // dd($lists);
- if (!empty($lists)) {
- for ($i = 1; $i <= 10; $i++) {
- $levels[] = [
- 'name' => '权重' . $i,
- 'level' => $i,
- 'disabled' => in_array($i, $lists),
- ];
- }
- } else {
- for ($i = 1; $i <= 10; $i++) {
- $levels[] = [
- 'name' => '权重' . $i,
- 'level' => $i,
- 'disabled' => false,
- ];
- }
- }
- return $levels;
- }
- }
|