SettingLog.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace addons\OperationCenter\common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%addons_operation_center_setting_log}}".
  6. *
  7. * @property int $id
  8. * @property int $mall_id
  9. * @property string|null $after_setting
  10. * @property string|null $before_setting
  11. * @property int|null $deleted_at
  12. * @property int|null $updated_at
  13. * @property int|null $created_at
  14. */
  15. class SettingLog extends BaseActiveRecord
  16. {
  17. /**
  18. * @var array
  19. */
  20. protected $json_keys = [
  21. 'after_setting', 'before_setting'
  22. ];
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public static function tableName()
  27. {
  28. return '{{%addons_operation_center_setting_log}}';
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function rules()
  34. {
  35. return [
  36. [['mall_id'], 'required'],
  37. [['mall_id', 'deleted_at', 'updated_at', 'created_at'], 'integer'],
  38. [['after_setting', 'before_setting'], 'string'],
  39. ];
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function attributeLabels()
  45. {
  46. return [
  47. 'id' => 'ID',
  48. 'mall_id' => 'Mall ID',
  49. 'after_setting' => 'After Setting',
  50. 'before_setting' => 'Before Setting',
  51. 'deleted_at' => 'Deleted At',
  52. 'updated_at' => 'Updated At',
  53. 'created_at' => 'Created At',
  54. ];
  55. }
  56. /**
  57. * 添加设置日志
  58. *
  59. * @param integer $mall_id
  60. * @param array $before_setting
  61. * @param array $after_setting
  62. * @return boolean
  63. */
  64. public static function addSettingLog(
  65. int $mall_id, array $before_setting, array $after_setting
  66. )
  67. {
  68. $data = compact('mall_id', 'before_setting', 'after_setting');
  69. $model = new static();
  70. $data = $model->jsonEncode($data);
  71. $model->load($data, '');
  72. return $model->save();
  73. }
  74. /**
  75. * 获取最后设置的ID
  76. *
  77. * @param integer $mall_id
  78. * @return int
  79. */
  80. public static function getLastSettingId(int $mall_id)
  81. {
  82. return static::find()
  83. ->select('id')
  84. ->andWhere(['mall_id' => $mall_id])
  85. ->orderBy('id desc')
  86. ->scalar();
  87. }
  88. }