| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace addons\ServeBonus\common\models;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_servebonus_commission_item_setting_detail}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $sid 对应qimall_addons_servebonus_commission_item_setting.id
- * @property int $level
- * @property float $prize 出单奖
- * @property float $extra_prize 加权平分奖
- * @property float $is_accumulation 是否开启叠加加权平分:0否,1是
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class ServeBonusCommissionItemSettingDetail extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_servebonus_commission_item_setting_detail}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'sid'], 'required'],
- [['mall_id', 'sid', 'level', 'is_accumulation', 'status', 'created_at', 'updated_at'], 'integer'],
- [['prize', 'extra_prize','cloud_stock_achievement_prize'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'sid' => '对应qimall_addons_servebonus_commission_item_setting.id',
- 'level' => 'Level',
- 'prize' => '出单奖',
- 'extra_prize' => '加权平分奖',
- 'is_accumulation' => '是否开启叠加加权平分:0否,1是',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData($params, $data)
- {
- try{
- foreach ($data as $item) {
- $item['prize'] = empty($item['prize']) ? 0 : $item['prize'];
- $item['extra_prize'] = empty($item['extra_prize']) ? 0 : $item['extra_prize'];
- $model = self::findOne([
- 'mall_id' => $params['mall_id'],
- 'level' => $item['level'],
- 'sid' => $params['sid'],
- 'status' => [StatusEnum::ENABLED]
- ]);
- if (empty($model)) {
- $model = new self();
- $model->mall_id = $params['mall_id'];
- $model->sid = $params['sid'];
- $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;
- }
- }
- }
|