GoodsDecorationTemplateContent.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace common\models\goods\template;
  3. use common\enums\StatusEnum;
  4. /**
  5. * This is the model class for table "{{%goods_decoration_template_content}}".
  6. *
  7. * @property int $id
  8. * @property int $mall_id 商城ID
  9. * @property string $title 标题
  10. * @property string $content 内容
  11. * @property int $status 状态【1启用 0禁用 -1删除】
  12. * @property int $created_at 创建时间
  13. * @property int $updated_at 更新时间
  14. */
  15. class GoodsDecorationTemplateContent extends \common\models\base\BaseActiveRecord
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public static function tableName()
  21. {
  22. return '{{%goods_decoration_template_content}}';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function rules()
  28. {
  29. return [
  30. [['mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
  31. [['content', 'title'], 'string'],
  32. ];
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function attributeLabels()
  38. {
  39. return [
  40. 'id' => 'ID',
  41. 'mall_id' => '商城ID',
  42. 'title' => '标题',
  43. 'content' => '内容',
  44. 'status' => '状态【1启用 0禁用 -1删除】',
  45. 'created_at' => '创建时间',
  46. 'updated_at' => '更新时间',
  47. ];
  48. }
  49. /**
  50. * 保存数据
  51. * @Author bing
  52. * @DateTime 2021-08-26 14:16:24
  53. * @copyright: Copyright (c) 2020 广东七件事集团
  54. * @param array $params
  55. * @return object|boolean
  56. */
  57. public static function setData(array $params)
  58. {
  59. try {
  60. if (!empty($params['id'])) {
  61. $model = self::findOne(['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  62. if (empty($model)) throw new \Exception('商品模板内容已存在或已删除');
  63. } else {
  64. $model = new self();
  65. $model->loadDefaultValues();
  66. }
  67. if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage());
  68. return $model;
  69. } catch (\Exception $e) {
  70. self::$static_error = $e->getMessage();
  71. return false;
  72. }
  73. }
  74. }