MpwxPlugins.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace common\models\common;
  3. use common\enums\StatusEnum;
  4. use RuntimeException;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_mpwx_plugins".
  8. *
  9. * @property int $id 主键
  10. * @property string $addons_name 插件标识
  11. * @property string $name 插件名称
  12. * @property string|null $plugins 插件安装配置
  13. * @property int $status 状态【1启用 0禁用 -1删除】
  14. * @property int|null $created_at 创建时间
  15. * @property int|null $updated_at 修改时间
  16. */
  17. class MpwxPlugins extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return 'qimall_mpwx_plugins';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['status', 'created_at', 'updated_at'], 'integer'],
  33. [['addons_name', 'name'], 'string', 'max' => 100],
  34. [['plugins'], 'string', 'max' => 255],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'addons_name' => 'Addons Name',
  45. 'name' => 'Name',
  46. 'plugins' => 'Plugins',
  47. 'status' => 'Status',
  48. 'created_at' => 'Created At',
  49. 'updated_at' => 'Updated At',
  50. ];
  51. }
  52. /**
  53. * 保存数据,如果存在则更新
  54. *
  55. * @param array $params
  56. *
  57. * @return object|boolean
  58. */
  59. public static function setData(array $params)
  60. {
  61. try {
  62. $model = self::findOne(['addons_name' => $params['addons_name'], 'name' => $params['name'], 'status' => StatusEnum::ENABLED]);
  63. if (empty($model)) {
  64. $model = new self();
  65. $model->loadDefaultValues();
  66. }
  67. if (!$model->load($params, '') || !$model->save()) {
  68. throw new RuntimeException($model->getErrorMessage());
  69. }
  70. return $model;
  71. } catch (\Exception $e) {
  72. self::$static_error = $e->getMessage();
  73. return false;
  74. }
  75. }
  76. }