RuleStat.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_stat}}".
  9. *
  10. * @property string $id
  11. * @property string $rule_id 规则id
  12. * @property string $rule_name 规则名称
  13. * @property string $hit
  14. * @property int $status 状态(-1:已删除,0:禁用,1:正常)
  15. * @property int $created_at 创建时间
  16. * @property string $updated_at 修改时间
  17. */
  18. class RuleStat extends \common\models\base\BaseModel
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%addon_wechat_rule_stat}}';
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['merchant_id', 'store_id', 'rule_id', 'hit', 'status', 'created_at', 'updated_at'], 'integer'],
  34. [['rule_name'], 'string', 'max' => 50],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'rule_id' => 'Rule ID',
  45. 'rule_name' => '规则名称',
  46. 'hit' => '触发次数',
  47. 'status' => '状态',
  48. 'created_at' => '创建时间',
  49. 'updated_at' => '更新时间',
  50. ];
  51. }
  52. /**
  53. * 关联规则
  54. *
  55. * @return \yii\db\ActiveQuery
  56. */
  57. public function getRule()
  58. {
  59. return $this->hasOne(Rule::class,['id' => 'rule_id']);
  60. }
  61. /**
  62. * @param bool $insert
  63. * @return bool
  64. */
  65. public function beforeSave($insert)
  66. {
  67. if($this->isNewRecord) {
  68. $this->created_at = strtotime(date('Y-m-d'));
  69. }
  70. return parent::beforeSave($insert);
  71. }
  72. /**
  73. * @return array
  74. */
  75. public function behaviors()
  76. {
  77. return [
  78. [
  79. 'class' => TimestampBehavior::class,
  80. 'attributes' => [
  81. ActiveRecord::EVENT_BEFORE_INSERT => ['updated_at'],
  82. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
  83. ],
  84. ],
  85. [
  86. 'class' => BlameableBehavior::class,
  87. 'attributes' => [
  88. ActiveRecord::EVENT_BEFORE_INSERT => ['merchant_id'],
  89. ],
  90. 'value' => Yii::$app->services->merchant->getNotNullId(),
  91. ],
  92. [
  93. 'class' => BlameableBehavior::class,
  94. 'attributes' => [
  95. ActiveRecord::EVENT_BEFORE_INSERT => ['store_id'],
  96. ],
  97. 'value' => Yii::$app->services->store->getNotNullId(),
  98. ]
  99. ];
  100. }
  101. }
粤ICP备19079148号