| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- namespace addons\DoubleCopy\common\models;
- use common\enums\StatusEnum;
- use Yii;
- use yii\db\Exception;
- use yii\db\Expression;
- /**
- * This is the model class for table "{{%addons_double_copy_pool_level}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property string $name 名称
- * @property int $level 等级(权重)
- * @property float $achievement 所需一二市场业绩,单位:元
- * @property float $single_market 单个市场业绩,单位:元
- * @property float $current_money 当前池金额,单位:元
- * @property float $total_money 累计池金额,单位:元
- * @property int $bonus_num 当前分红人数
- * @property string|null $goods_setting 商品设置
- * @property array|null $extra_pool_level 商品设置
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- * @property int $is_enable_extra_pool 更新时间
- * @property float $current_score 当前池积分
- * @property float $total_score 累计池积分
- */
- class DoubleCopyPoolLevel extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_double_copy_pool_level}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'level', 'bonus_num', 'status', 'created_at', 'updated_at', 'is_enable_extra_pool'], 'integer'],
- [['achievement', 'single_market', 'current_money', 'total_money'], 'number'],
- [['goods_setting'], 'string'],
- [['extra_pool_level'], 'safe'],
- [['name'], 'string', 'max' => 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;
- }
- }
|