AllclickRecord.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. class AllclickRecord extends Common{
  12. public function behaviors()
  13. {
  14. return [
  15. [
  16. 'class' => TimestampBehavior::className(),
  17. 'attributes' => [
  18. # 创建之前
  19. ActiveRecord::EVENT_BEFORE_INSERT => ['create_at'],
  20. # 修改之前
  21. // ActiveRecord::EVENT_BEFORE_UPDATE => ['update_at']
  22. ],
  23. #设置默认值
  24. 'value' => $_SERVER['REQUEST_TIME']
  25. ]
  26. ];
  27. }
  28. public function RecordQuery($arr = [])
  29. {
  30. $query = self::find();
  31. $query->andWhere(['id'=>$arr['id']]);
  32. $query->andWhere(['ip'=>$arr['ip']]);
  33. $query->andWhere(['type'=>$arr['type']]);
  34. return $query->one();
  35. }
  36. public function addRecord($arr)
  37. {
  38. $this->id = $arr['id'];
  39. $this->ip = $arr['ip'];
  40. $this->type = $arr['type'];
  41. return $this->save();
  42. }
  43. }