| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace addons\BossWeight\common\models;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_boss_weight_commission_item_setting}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $is_enable 是否启用股东分红:0:否;1是
- * @property int $is_alone 是否独立设置:0:否;1是
- * @property int $is_extra 是否开启额外分红:0:否;1是
- * @property int $item_id 项目id
- * @property string $item_type 项目类型:商品goods
- * @property string $commission_type 分佣类型:佣金:commission
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class AddonsBossCommissionItemSetting extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_boss_weight_commission_item_setting}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'is_enable', 'is_alone', 'is_extra', 'item_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['item_type', 'commission_type'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'is_enable' => '是否启用股东分红:0:否;1是',
- 'is_alone' => '是否独立设置:0:否;1是',
- 'is_extra' => '是否开启额外分红:0:否;1是',
- 'item_id' => '项目id',
- 'item_type' => '项目类型:商品goods',
- 'commission_type' => '分佣类型:佣金:commission',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public function getDetail()
- {
- return $this->hasMany(AddonsBossCommissionItemSettingDetail::class, ['boss_commission_item_setting_id' => 'id'])->indexBy('level');
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2021/11/2 0002 11:45
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params
- * @param $data
- * @return bool
- */
- public static function setData($params, $data)
- {
- try{
- foreach ($data as $item) {
- $model = self::findOne([
- 'mall_id' => $params['mall_id'],
- 'item_type' => $item['item_type'],
- 'commission_type' => $item['commission_type'],
- 'item_id' => $params['item_id'],
- 'status' => [StatusEnum::ENABLED]
- ]);
- if (empty($model)) {
- $model = new self();
- $model->mall_id = $params['mall_id'];
- $model->item_id = $params['item_id'];
- $model->loadDefaultValues();
- }
- if(!$model->load($item,'') || !$model->save()){
- throw new \Exception($model->getErrorMessage());
- }
- // 插入配置详情
- $detail = ['mall_id' => $params['mall_id'], 'boss_commission_item_setting_id' => $model->id];
- $res = AddonsBossCommissionItemSettingDetail::setData($detail, $item['detail']);
- if ($res == false) throw new \Exception(AddonsBossCommissionItemSettingDetail::getStaticError());
- }
- return true;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|