255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => '商城ID', 'notice_type' => '通知类型', 'title' => '消息标题', 'content' => '消息内容', 'is_read' => '是否已读,1-是,0-否', 'status' => '状态', 'created_at' => '添加时间戳', 'updated_at' => '更新时间戳', ]; } /** * 生成消息通知数据 * @param $params * @return bool */ public static function setData($params) { try { $model = new self(); $model->loadDefaultValues(); if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage()); return true; } catch (\Exception $e) { self::setStaticError($e->getMessage()); return false; } } /** * 消息阅读 * * @param array $condition * @return int */ public static function readNotice(int $id, int $mall_id) { $t = Yii::$app->db->beginTransaction(); try { BackendUnreadCount::decUnreadNum($mall_id, BackendUnreadCount::NOTICE); static::updateAll(['is_read' => 1], compact('mall_id', 'id')); $t->commit(); } catch (Exception $e) { Yii::error('消息阅读错误: ' . $e->getMessage()); $t->rollBack(); return false; } return true; } /** * 添加站点消息 * * @param integer $mall_id * @param string $title * @param string $content * @param int $notice_type * @return boolean */ public static function addMallNotice(int $mall_id, string $title, string $content, int $notice_type = self::ARREARS) { $t = Yii::$app->db->beginTransaction(); try { static::setData(compact('mall_id', 'title', 'content', 'notice_type')); BackendUnreadCount::incUnreadNum($mall_id, BackendUnreadCount::NOTICE); $t->commit(); } catch (Exception $e) { Yii::error('消息阅读错误: ' . $e->getMessage()); $t->rollBack(); return false; } return true; } }