| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace addons\Wechat\common\models;
- use Yii;
- use yii\db\ActiveRecord;
- use yii\behaviors\BlameableBehavior;
- use yii\behaviors\TimestampBehavior;
- /**
- * This is the model class for table "{{%addon_wechat_rule_stat}}".
- *
- * @property string $id
- * @property string $rule_id 规则id
- * @property string $rule_name 规则名称
- * @property string $hit
- * @property int $status 状态(-1:已删除,0:禁用,1:正常)
- * @property int $created_at 创建时间
- * @property string $updated_at 修改时间
- */
- class RuleStat extends \common\models\base\BaseModel
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addon_wechat_rule_stat}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['merchant_id', 'store_id', 'rule_id', 'hit', 'status', 'created_at', 'updated_at'], 'integer'],
- [['rule_name'], 'string', 'max' => 50],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'rule_id' => 'Rule ID',
- 'rule_name' => '规则名称',
- 'hit' => '触发次数',
- 'status' => '状态',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * 关联规则
- *
- * @return \yii\db\ActiveQuery
- */
- public function getRule()
- {
- return $this->hasOne(Rule::class,['id' => 'rule_id']);
- }
- /**
- * @param bool $insert
- * @return bool
- */
- public function beforeSave($insert)
- {
- if($this->isNewRecord) {
- $this->created_at = strtotime(date('Y-m-d'));
- }
- return parent::beforeSave($insert);
- }
- /**
- * @return array
- */
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['updated_at'],
- ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
- ],
- ],
- [
- 'class' => BlameableBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['merchant_id'],
- ],
- 'value' => Yii::$app->services->merchant->getNotNullId(),
- ],
- [
- 'class' => BlameableBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['store_id'],
- ],
- 'value' => Yii::$app->services->store->getNotNullId(),
- ]
- ];
- }
- }
|