| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace addons\CloudStockTwo\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "{{%addons_cloud_stock_level".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $level 等级权重id
- * @property string $name 等级名称
- * @property string|null $checked_condition_values 升级条件
- * @property string|null $checked_condition_keys 升级条件选中的key集合
- * @property int $condition_type 0 未选择、1满足其一 2、满足所有
- * @property int $upgrade_type_condition 是否开启条件升级
- * @property int $is_over 超越奖励
- * @property int $is_equal 平级
- * @property int $is_fill 补货
- * @property string|null $give_quota json;赠送等级配置
- * @property string $explain 等级说明
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- * @property int $is_open_fill_min
- * @property int $fill_min
- */
- class CloudStockTwoLevel extends BaseActiveRecord
- {
- private static $levels = [];
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_cloud_stock_two_level}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'name'], 'required'],
- [['mall_id', 'level', 'condition_type', 'upgrade_type_condition', 'is_over', 'is_equal', 'is_fill', 'status', 'created_at', 'updated_at','is_open_fill_min','fill_min','is_open_equal_settle_type','equal_settle_type','is_recommender_reward','is_recommender_condition','recommender_condition_prize','recommender_settle_prize','recommender_settle_rate'], 'integer'],
- [['checked_condition_values', 'checked_condition_keys', 'give_quota','commission','score','agent_setting_info'], 'string'],
- [['name'], 'string', 'max' => 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;
- }
- }
|