50], [['value'], 'string', 'max' => 256], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'cx_mch_id' => '平台商户ID', 'type' => '类型:0=分类,1=浏览量', 'faq_id' => '帮助ID', 'key' => 'KEY', 'value' => 'VALUE', 'created_at' => '添加时间', 'updated_at' => '更新时间', 'is_delete' => '是否删除:0=否,1=是', 'deleted_at' => '删除时间', ]; } public function beforeSave($insert) { if(parent::beforeSave($insert)){ if($this->isNewRecord){ $this->created_at = time(); } $this->updated_at = time(); if($this->is_delete == 1) $this->deleted_at = time(); return true; } else { return false; } } public static function getViewedNum($faq_id, $cx_mch_id = 0) { $model = FaqMeta::findOne([ 'cx_mch_id' => $cx_mch_id, 'type' => self::TYPE_VIEWED_NUM, 'faq_id' => $faq_id, 'is_delete' => 0, ]); if($model == null) return 0; return $model->value; } public static function setViewedNum($faq_id, $cx_mch_id = 0) { $model = FaqMeta::findOne([ 'cx_mch_id' => $cx_mch_id, 'type' => self::TYPE_VIEWED_NUM, 'faq_id' => $faq_id, 'is_delete' => 0, ]); if($model == null){ $model = new FaqMeta(); $model->cx_mch_id = $cx_mch_id; $model->type = self::TYPE_VIEWED_NUM; $model->faq_id = $faq_id; $model->value = 0; $model->is_delete = 0; } $val = (int)$model->value; $val += 1; $model->value = (string)$val; if(!$model->save()){ return (new Model())->getModelError($model); } return Model::asReturnSuccess(); } }