250], [['current_score', 'total_score'], 'number'], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => '商城ID', 'name' => '名称', 'level' => '等级(权重)', 'achievement' => '所需一二市场总业绩,单位:元', 'single_market' => '单个市场业绩,单位:元', 'current_money' => '当前池金额,单位:元', 'total_money' => '累计池金额,单位:元', 'bonus_num' => '当前分红人数', 'goods_setting' => '商品设置', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => '创建时间', 'updated_at' => '更新时间', ]; } /** * 获取权重 * @Author: lun * @DateTime: 2022/5/14 0014 10:00 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $mall_id * @return array */ public static function getLevelWeights($mall_id) { $list = self::find()->select('level')->where(['status' => [StatusEnum::DISABLED,StatusEnum::ENABLED], 'mall_id' => $mall_id])->column(); $newList = []; for ($i = 1; $i <= 10; $i++) { $newList[] = [ 'name' => '权重' . $i, 'level' => $i, 'disabled' => in_array($i, $list), ]; } return $newList; } /** * 保存数据 * @Author: lun * @DateTime: 2022/9/16 0016 9:49 * @Copyright: copyright (c) 2021 广东七件事集团 * @param array $params * @return array|bool */ public static function setData(array $params){ try{ if(!empty($params['id'])){ $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $params['mall_id']],['<>','status',StatusEnum::DELETE]]); if(empty($model)) throw new \Exception('等级不存在或已删除'); // 判断等级是否有被修改 if ($model->level != $params['level']) { // 判断该等级下是否有股东存在 $user = DoubleCopyPoolUser::find()->where(['mall_id' => $model->mall_id, 'level' => $model->level, 'status' => StatusEnum::ENABLED])->asArray()->one(); if ($user) throw new Exception('该等级下存在用户,不能被修改'); } }else{ $model = new self(); $model->mall_id = $params['mall_id']; $model->loadDefaultValues(); } if(!$model->load($params,'') || !$model->save()){ throw new Exception($model->getErrorMessage()); } return $model->toArray(); }catch(\Exception $e){ self::$static_error = $e->getMessage(); return false; } } /** * 增加奖金池金额 * @Author: lun * @DateTime: 2022/9/16 0016 15:35 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $mall_id * @param $level * @param array $params * @throws Exception */ public static function savePoolMoney($mall_id, $level, $params = []) { $update_data['updated_at'] = time(); foreach ($params as $key => $value) { $symbol = $value >= 0 ? '+' : '-'; $update_data[$key] = new Expression($key.$symbol.abs($value)); } $res = self::updateAll($update_data, ['mall_id' => $mall_id, 'level' => $level, 'status' => StatusEnum::ENABLED]); if (!$res) throw new Exception('修改能量池基金失败'); } /** * 获取等级map * @Author: lun * @DateTime: 2022/9/16 0016 16:52 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $mall_id * @return array */ public static function getMap($mall_id) { $data = []; $list = self::find()->select('level,name')->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED])->orderBy('level asc')->asArray()->all(); if ($list) { foreach ($list as $item) { $data[$item['level']] = $item['name']; } } return $data; } }