| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace common\models\goods;
- use common\enums\StatusEnum;
- use Exception;
- use RuntimeException;
- use Yii;
- /**
- * This is the model class for table "qimall_goods_description_template".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property string $name 模板名称
- * @property string $frontend_name 前端名称
- * @property int $use_num 使用该模板数量
- * @property string|null $fields 字段
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class GoodsDescriptionTemplate extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_goods_description_template';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'use_num', 'status', 'created_at', 'updated_at'], 'integer'],
- [['fields'], 'safe'],
- [['name'], 'string', 'max' => 8],
- [['frontend_name'], 'string', 'max' => 4],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'name' => 'Name',
- 'frontend_name' => 'Frontend Name',
- 'use_num' => 'Use Num',
- 'fields' => 'Fields',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * @param array $params
- *
- * @return bool|self
- */
- public static function setData(array $params)
- {
- try {
- if (!empty($params['id'])) {
- $model = static::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (!$model) {
- throw new RuntimeException('数据不存在或已删除');
- }
- if ($model->mall_id != $params['mall_id']) {
- throw new RuntimeException('不允许操作此数据');
- }
- } else {
- $model = new static();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '')) {
- throw new RuntimeException($model->getErrorMessage());
- }
- if (!$model->save()) {
- throw new RuntimeException($model->getErrorMessage());
- }
- return $model;
- } catch (Exception $e) {
- static::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|