| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- namespace addons\OperationCenter\common\models;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_operation_center_commission_item_setting_detail}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $commission_item_setting_id
- * @property int|null $level
- * @property float|null $commission1_value 直推奖
- * @property float|null $commission2_value 间推奖
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $created_at
- * @property int|null $updated_at
- */
- class CommissionItemSettingDetail extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_operation_center_commission_item_setting_detail}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'commission_item_setting_id'], 'required'],
- [['mall_id', 'commission_item_setting_id', 'level', 'status', 'created_at', 'updated_at'], 'integer'],
- [['commission1_value', 'commission2_value'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'commission_item_setting_id' => 'Commission Item Setting ID',
- 'level' => 'Level',
- 'commission1_value' => '直推奖',
- 'commission2_value' => '间推奖',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2023/8/16 0016 16:36
- * @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'],
- 'level' => $item['level'],
- 'commission_item_setting_id' => $params['commission_item_setting_id'],
- 'status' => [StatusEnum::ENABLED]
- ]);
- if (empty($model)) {
- $model = new self();
- $model->mall_id = $params['mall_id'];
- $model->commission_item_setting_id = $params['commission_item_setting_id'];
- $model->loadDefaultValues();
- }
- if(!$model->load($item,'') || !$model->save()){
- throw new \Exception($model->getErrorMessage());
- }
- }
- return true;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getItemSetting()
- {
- return $this->hasOne(CommissionItemSetting::class, [
- 'id' => 'commission_item_setting_id'
- ])->andWhere(['item_type' => 'goods', 'status' => 1])->select([
- 'id', 'mall_id', 'is_partake', 'is_enable', 'item_id', 'item_type', 'settings', 'is_percent'
- ]);
- }
- /**
- * 通过分佣等级(直推 间推)获取分佣类型
- *
- * @param int $level
- * @return int
- */
- public function getCommissionTypeByLevel($level)
- {
- return $this->itemSetting->is_percent == 1
- ? Level::FIXED
- : Level::RATIO;
- }
- /**
- * 通过分佣等级(直推 间推)获取分佣数量
- *
- * @param int $level
- * @return float
- */
- public function getCommissionValueByLevel($level)
- {
- $key = sprintf('commission%s_value', $level);
- return $this->{$key};
- }
- }
|