| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace common\models\goods\template;
- use common\enums\StatusEnum;
- /**
- * This is the model class for table "{{%goods_template_relation}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $goods_id Goods ID
- * @property int $template_id 模板ID[qimall_goods_decoration_template主键]
- * @property int $status 状态【1启用 0禁用 -1删除】
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- * @property GoodsDecorationTemplate $template
- */
- class GoodsTemplateRelation extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%goods_template_relation}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'goods_id', 'template_id', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'goods_id' => 'Goods ID',
- 'template_id' => '模板ID[qimall_goods_decoration_template主键]',
- 'status' => '状态【1启用 0禁用 -1删除】',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- public function getTemplate()
- {
- return $this->hasOne(GoodsDecorationTemplate::class, ['id' => 'template_id']);
- }
- /**
- * 保存数据
- * @Author bing
- * @DateTime 2021-08-26 14:16:24
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param array $params
- * @return object|boolean
- */
- public static function setData(array $params)
- {
- try {
- $model = self::findOne(['goods_id' => $params['goods_id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if(empty($model)){
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|