'ID', 'mall_id' => '商城ID', 'type' => '项目类型[1=订单,2=售后订单,3=提现,4=通知]', 'unread_num' => '未读总数', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => '添加时间戳', 'updated_at' => '更新时间戳', ]; } /** * 获取未读消息数量 * * @param array $condition * @return int */ public static function getUnReadCount(array $condition) { return static::find()->where($condition)->select('unread_num')->scalar(); } /** * 根据类型获取未读数量总数 * @param $mall_id * @param $type * @return int|null */ public static function getUnreadNum($mall_id, $type) { $model = self::findOne(['mall_id' => $mall_id, 'type' => $type, 'status' => StatusEnum::ENABLED]); if (empty($model)) { return 0; } return $model->unread_num; } /** * 添加消息未读数量 * * @param integer $mall_id * @param integer $type * @return boolean|int */ public static function incUnreadNum(int $mall_id, int $type) { $model = static::find()->where(['mall_id' => $mall_id, 'type' => $type])->select('id')->one(); if (empty($model)) { $unread_num = 1; $model = new static(); $model->load(compact('mall_id', 'type', 'unread_num'), ''); return $model->save(); } return static::updateAllCounters(['unread_num' => 1], ['id' => $model->id]); } /** * 减少消息未读数量 * * @param integer $mall_id * @param integer $type * @return int */ public static function decUnreadNum(int $mall_id, int $type) { return static::updateAllCounters(['unread_num' => -1], ['mall_id' => $mall_id, 'type' => $type]); } }