Syncrecord.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/7/12
  6. * Time: 下午2:43
  7. */
  8. namespace common\models;
  9. use yii\db\ActiveRecord;
  10. use yii\behaviors\TimestampBehavior;
  11. use Yii;
  12. class Syncrecord extends Common{
  13. public function behaviors()
  14. {
  15. return [
  16. [
  17. 'class' => TimestampBehavior::className(),
  18. 'attributes' => [
  19. # 创建之前
  20. ActiveRecord::EVENT_BEFORE_INSERT => ['create_at'],
  21. # 修改之前
  22. // ActiveRecord::EVENT_BEFORE_UPDATE => ['update_at']
  23. ],
  24. #设置默认值
  25. 'value' => $_SERVER['REQUEST_TIME']
  26. ]
  27. ];
  28. }
  29. protected function QueryFind()
  30. {
  31. return self::find();
  32. }
  33. public function FindByUnid($id)
  34. {
  35. return $this->QueryFind()->andWhere(['unid'=>$id])->orderBy(['create_at'=>SORT_DESC])->one();
  36. }
  37. public function Record($input)
  38. {
  39. $this->uid = $input['uid'];
  40. $this->hid = $input['hid'];
  41. $this->operation_type = $input['operation_type'];
  42. $this->content = $input['content'];
  43. $this->create_at = $_SERVER['REQUEST_TIME'];
  44. $this->unid = $input['unid'];
  45. return $this->save(false);
  46. }
  47. }