255], [['explain'], 'string', 'max' => 5000], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => '商城id', 'level' => '等级权重id', 'name' => '等级名称', 'checked_condition_values' => '升级条件', 'checked_condition_keys' => '升级条件选中的key集合', 'condition_type' => '0 未选择、1满足其一 2、满足所有', 'upgrade_type_condition' => '是否开启条件升级', 'is_over' => '超越奖励', 'is_equal' => '平级', 'is_fill' => '补货', 'give_quota' => 'json;赠送等级配置', 'explain' => '等级说明', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => 'Created At', 'updated_at' => 'Updated At', 'is_open_fill_min' => '代理进货数量限制', 'fill_min' => '最低补货数量', 'commission' => '团队佣金奖励', 'score' => '团队积分奖励', 'is_open_equal_settle_type' => '平级奖独立设置', 'equal_settle_type' => '平级奖结算方式', 'is_recommender_reward' => '直推下级代理奖励设置', 'agent_setting_info' => '直推下级代理奖励设置', 'is_recommender_condition' => '直推下级代理奖条件', 'recommender_condition_prize' => '直推下级代理奖条件', 'recommender_settle_prize' => '结算比例', 'recommender_settle_rate' => '结算比例', ]; } public static function setData(array $params) { try { if(!empty($params['id'])){ $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]]); if (empty($model)) throw new \Exception('服务不存在或已删除'); if($params['status']==StatusEnum::DELETE){ $res = CloudStockTwoAgent::findOne(['mall_id'=> $params['mall_id'],'level'=>$model->level,'status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]]); if($res) throw new \Exception('该等级关联了代理商'); } }else{ $model = new self(); $model->loadDefaultValues(); } if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage()); if (!$model->save()) throw new \Exception($model->getErrorMessage()); return $model; } catch (\Exception $e) { self::$static_error = $e->getMessage(); return false; } } /** * @name: * @msg: 获取云库存代理商等级列表 * @param {int} $mall_id 商城id * @param {int} $level 等级 * @return array */ public static function getLevelList(int $mall_id, int $level = null) : array { if (!empty(self::$levels)) return self::$levels; $levels = self::find() ->select('id,mall_id,level,name as level_name,give_quota,created_at') ->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED]) ->orderBy('level asc') ->asArray() ->indexBy('level') ->all(); if (empty($levels)) return []; self::$levels = $levels; if ($level !== null) { $levels = $levels[$level] ?? []; } return $levels; } /** * @name: * @msg: 获取特定等级设置代理商的名额配置 * @param {int} $mall_id 商城 id * @param {int} $level 等级 * @return int */ public static function getGiveQuota(int $mall_id, int $level, int $user_id) : int { $give_quota = CloudStockTwoAgentQuota::find() ->select('id,mall_id,user_id,level,num,status') ->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'level' => $level, 'user_id' => $user_id]) ->asArray() ->one(); if (empty($give_quota)) { $number = 0; } else { $number = $give_quota['num']; } return $number; } }