| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace addons\Seed\common\models;
- use addons\Store\common\models\Store;
- use common\enums\StatusEnum;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_seed_store_setting}}".
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property int $store_id 店铺ID
- * @property float|null $percent 设置比例,单位:百分比
- * @property int $status 状态【-1删除 0发放中,1正常】
- * @property int $created_at 创建时间
- * @property int $updated_at 更新数据时间
- */
- class SeedStoreSetting extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_seed_store_setting}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'store_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['percent'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'store_id' => '店铺ID',
- 'percent' => '设置比例,单位:百分比',
- 'status' => '状态【-1删除 0发放中,1正常】',
- 'created_at' => '创建时间',
- 'updated_at' => '更新数据时间',
- ];
- }
- /**
- * 关联店铺表
- * @Author: lun
- * @DateTime: 2022/8/23 0023 18:30
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getStore()
- {
- return $this->hasOne(Store::class, ['id' => 'store_id'])->select('id,store_name,logo_img,user_id');
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2022/8/23 0023 17:29
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params
- * @return array|bool
- */
- public static function setData($params)
- {
- try {
- $model = self::findOne(['store_id' => $params['store_id'], 'status' => StatusEnum::ENABLED]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model->toArray();
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|