RuleKeywordStat.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace addons\Wechat\common\models;
  3. use Yii;
  4. use yii\db\ActiveRecord;
  5. use yii\behaviors\BlameableBehavior;
  6. use yii\behaviors\TimestampBehavior;
  7. /**
  8. * This is the model class for table "{{%addon_wechat_rule_keyword_stat}}".
  9. *
  10. * @property string $id
  11. * @property int $rule_id 规则id
  12. * @property string $keyword_id 关键字id
  13. * @property string $rule_name 规则名称
  14. * @property int $keyword_type 类别
  15. * @property string $keyword_content 触发的关键字内容
  16. * @property string $hit 关键字id
  17. * @property int $status 状态(-1:已删除,0:禁用,1:正常)
  18. * @property int $created_at 创建时间
  19. * @property string $updated_at 修改时间
  20. */
  21. class RuleKeywordStat extends \common\models\base\BaseModel
  22. {
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public static function tableName()
  27. {
  28. return '{{%addon_wechat_rule_keyword_stat}}';
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function rules()
  34. {
  35. return [
  36. [['merchant_id', 'store_id', 'rule_id', 'keyword_id', 'keyword_type', 'hit', 'status', 'created_at', 'updated_at'], 'integer'],
  37. [['rule_name'], 'string', 'max' => 50],
  38. [['keyword_content'], 'string', 'max' => 255],
  39. ];
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function attributeLabels()
  45. {
  46. return [
  47. 'id' => 'ID',
  48. 'rule_id' => '规则ID',
  49. 'keyword_id' => '关键字id',
  50. 'rule_name' => '规则名称',
  51. 'keyword_type' => '关键字类型',
  52. 'keyword_content' => '关键字内容',
  53. 'hit' => '触发次数',
  54. 'status' => '状态',
  55. 'created_at' => '创建时间',
  56. 'updated_at' => '更新时间',
  57. ];
  58. }
  59. /**
  60. * 关联规则
  61. *
  62. * @return \yii\db\ActiveQuery
  63. */
  64. public function getRule()
  65. {
  66. return $this->hasOne(Rule::class,['id' => 'rule_id']);
  67. }
  68. /**
  69. * 关联关键字
  70. *
  71. * @return \yii\db\ActiveQuery
  72. */
  73. public function getRuleKeyword()
  74. {
  75. return $this->hasOne(RuleKeyword::class,['id' => 'keyword_id']);
  76. }
  77. /**
  78. * @param bool $insert
  79. * @return bool
  80. */
  81. public function beforeSave($insert)
  82. {
  83. if($this->isNewRecord) {
  84. $this->created_at = strtotime(date('Y-m-d'));
  85. }
  86. return parent::beforeSave($insert);
  87. }
  88. /**
  89. * @return array
  90. */
  91. public function behaviors()
  92. {
  93. return [
  94. [
  95. 'class' => TimestampBehavior::class,
  96. 'attributes' => [
  97. ActiveRecord::EVENT_BEFORE_INSERT => ['updated_at'],
  98. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
  99. ],
  100. ],
  101. [
  102. 'class' => BlameableBehavior::class,
  103. 'attributes' => [
  104. ActiveRecord::EVENT_BEFORE_INSERT => ['merchant_id'],
  105. ],
  106. 'value' => Yii::$app->services->merchant->getNotNullId(),
  107. ],
  108. [
  109. 'class' => BlameableBehavior::class,
  110. 'attributes' => [
  111. ActiveRecord::EVENT_BEFORE_INSERT => ['store_id'],
  112. ],
  113. 'value' => Yii::$app->services->store->getNotNullId(),
  114. ]
  115. ];
  116. }
  117. }
粤ICP备19079148号