Notice.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace common\models\notice;
  3. use common\models\base\BaseActiveRecord;
  4. use Yii;
  5. use yii\db\Exception;
  6. /**
  7. * This is the model class for table "{{%notice}}".
  8. *
  9. *
  10. * @property int $id
  11. * @property string|null $content 通知内容
  12. * @property int $created_at
  13. * @property int $updated_at
  14. * @property int $status 状态[-1:删除;0:禁用;1启用]
  15. */
  16. class Notice extends BaseActiveRecord
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%notice}}';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['created_at', 'updated_at', 'status'], 'integer'],
  32. [['content'], 'string', 'max' => 255],
  33. ];
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'content' => 'Content',
  43. 'created_at' => 'Created At',
  44. 'updated_at' => 'Updated At',
  45. 'status' => 'Status',
  46. ];
  47. }
  48. /**
  49. * @Author: ltm
  50. * @DateTime: 2022/3/16 0016 17:58
  51. * @Copyright: copyright (c) 2021 广东七件事集团
  52. * @param $data
  53. * @return string
  54. */
  55. public static function setData(array $params){
  56. try{
  57. if (!empty($params['id'])) {
  58. $model = self::findOne(['id'=>$params['id']]);
  59. if (empty($model)) throw new Exception('记录不存在或已删除');
  60. }else{
  61. $model = new self();
  62. $model->loadDefaultValues();
  63. }
  64. if(!$model->load($params,'') || !$model->save()){
  65. throw new Exception($model->getErrorMessage());
  66. }
  67. return $model;
  68. }catch(\Exception $e){
  69. var_dump($e->getMessage());
  70. self::$static_error = $e->getMessage();
  71. return false;
  72. }
  73. }
  74. }