| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace addons\BossAchievement\common\models;
- use common\enums\StatusEnum;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "{{%addons_boss_achievement_level_setting}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $level_id 对应qimall_addons_boss_achievement_level.id
- * @property int $level
- * @property string $commission_type 分佣类型:积分score;佣金:commission
- * @property string $from_type 分佣类型:股东;
- * @property float $standard_money 达标业绩,单位:元
- * @property float $prize 业绩分红,单位:百分比
- * @property string|null $achievement_goods_ids 指定商品id集合
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class BossAchievementLevelSetting extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_boss_achievement_level_setting}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'level_id', 'level', 'status', 'created_at', 'updated_at'], 'integer'],
- [['standard_money', 'prize'], 'number'],
- [['commission_type', 'from_type'], 'string', 'max' => 255],
- [['achievement_goods_ids'], 'string', 'max' => 3000],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'level_id' => '对应qimall_addons_boss_achievement_level.id',
- 'level' => '等级',
- 'commission_type' => '分佣类型:积分score;佣金:commission',
- 'from_type' => '分佣类型:股东;',
- 'standard_money' => '达标业绩,单位:元',
- 'prize' => '业绩分红,单位:百分比',
- 'achievement_goods_ids' => '指定商品id集合',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2021/11/4 0004 14:23
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params
- * @return bool
- */
- public static function setData($params)
- {
- try{
- $model = self::findOne(['mall_id' => $params['mall_id'], 'level_id' => $params['level_id']]);
- if (empty($model)) {
- $model = new self();
- $model->mall_id = $params['mall_id'];
- $model->level = $params['level'];
- $model->loadDefaultValues();
- }
- // 检测是否有业绩商品修改
- if ($model->achievement_goods_ids != $params['achievement_goods_ids']) {
- $old_goods = Json::decode($model->achievement_goods_ids, true) ?? [];
- $new_goods = Json::decode($params['achievement_goods_ids'], true) ?? [];
- $diff = array_diff($old_goods, $new_goods);
- if ($diff) {
- // 查询该商品的当月业绩
- $has_achievement = BossAchievementTeam::find()->where(['goods_id' => $diff, 'month' => date('Ym', time()), 'status' => StatusEnum::ENABLED])->asArray()->one();
- if ($has_achievement) throw new \Exception('无法更换商品,因为该商品本月已有业绩产生');
- }
- }
- if(!$model->load($params,'') || !$model->save()){
- throw new \Exception($model->getErrorMessage());
- }
- return true;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 获取所有等级的业绩商品
- * @Author: lun
- * @DateTime: 2022/7/10 0010 16:06
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mall_id
- */
- public static function getAllAchievementGoodsIds($mall_id)
- {
- $goods_ids = [];
- // 获取所有等级
- $list = self::find()->select('level,achievement_goods_ids')->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED])->indexBy('level')->asArray()->all();
- foreach ($list as $item) {
- $goods_ids = array_merge($goods_ids, Json::decode($item['achievement_goods_ids'], true));
- }
- return $goods_ids;
- }
- }
|