256], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'cx_mch_id' => '平台商户ID', 'type' => '消息类型', 'to_user_id' => '接收用户:0=所有用户', 'title' => '标题', 'is_richtext' => '是否富文本:0=否,1=是', 'content' => '消息内容', 'status' => '状态:0=草稿,1=已发布', 'order_id' => '订单ID', 'created_at' => '添加时间', 'updated_at' => '更新时间', 'deleted_at' => '删除时间', 'published_at' => '发布时间', 'is_delete' => '是否删除:0=否,1=是', ]; } 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(); $this->htmlTagFilter(); return true; } else { return false; } } public function htmlTagFilter() { $this->title = Model::htmlTagFilter($this->title); $this->content = Model::htmlTagFilter($this->content); } public static function statusLabels() { return [ '0' => '草稿', '1' => '已发布', ]; } public static function getStatus($status) { $labels = self::statusLabels(); return isset($labels[$status]) ? $labels[$status] : "未知"; } /** * 发送系统消息通知 * @param integer $user_id 用户ID * @param string $title 标题 * @param string $content 消息内容 * @param integer $type 消息类型 * @param integer $is_richtext 是否富文本 * @param integer $order_id 订单ID * @param integer $cx_mch_id 平台商户ID */ public static function sendSysMsgToUser($user_id, $title, $content, $type, $is_richtext = 0, $order_id = 0, $cx_mch_id = 0) { $model = new SysMsg(); $model->cx_mch_id = $cx_mch_id; $model->type = $type; $model->to_user_id = $user_id; $model->title = $title; $model->content = $content; $model->status = SysMsg::STATUS_PUBLISHED; $model->published_at = time(); $model->is_richtext = $is_richtext; $model->order_id = $order_id; if(!$model->save()){ return (new Model())->getModelError($model); } return Model::asReturnSuccess(); } }