| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace addons\Store\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_store_notice".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $store_id 门店id
- * @property string $title 标题
- * @property string $content 内容
- * @property int $status 状态[0禁用 1启用 -1删除]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class StoreNotice extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_store_notice}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'store_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['title', 'content'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'store_id' => '门店id',
- 'title' => '标题',
- 'content' => '内容',
- 'status' => '状态[0禁用 1启用 -1删除]',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- ];
- }
- public static function setData(array $params)
- {
- try {
- if (!empty($params['id'])) {
- $where = ['id' => $params['id'], ['status' => StatusEnum::ENABLED]];
- if (isset($params['mall_id'])) $where[] = ['mall_id' => $params['mall_id']];
- if (isset($params['store_id'])) $where[] = ['store_id' => $params['store_id']];
- $model = self::findOne($where);
- if (empty($model)) throw new \Exception('服务不存在或已删除');
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) throw new \PHPUnit\Util\Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|