| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace app\api\model\system;
- use app\api\model\BaseModel;
- class Message extends BaseModel
- {
- // 表名
- protected $name = 'system_message';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- public function fetchUserSystemMessage($user_id, $page, $size)
- {
- return $this->where("identity_type", \E_IDENTITY_TYPE::User)
- ->where("to_user_id", $user_id)
- ->order("updatetime", "desc")
- ->page($page)
- ->paginate($size);
- }
- public function fetchMassagerSystemMessage($m_id, $page, $size)
- {
- return $this->where("identity_type", \E_IDENTITY_TYPE::Massager)
- ->where("to_massager_id", $m_id)
- ->order("updatetime", "desc")
- ->page($page)
- ->paginate($size);
- }
- public function fetchAgencySystemMessage($a_id, $page, $size)
- {
- return $this->where("identity_type", \E_IDENTITY_TYPE::Agency)
- ->where("to_agency_id", $a_id)
- ->order("updatetime", "desc")
- ->page($page)
- ->paginate($size);
- }
- /**
- * @param $m_id
- * @return int|string
- * @throws \think\Exception
- */
- public function getUnreadMessageCount($m_id)
- {
- return $this->where("identity_type", \E_IDENTITY_TYPE::Massager)
- ->where("to_massager_id", $m_id)
- ->where("is_read", 0)
- ->count();
- }
- /**
- * 给系统用户发送系统消息
- * @param $identity_type
- * @param array $to_target
- * @param $title
- * @param $content
- * @return Message
- */
- public static function sendSystemMessage($identity_type, array $to_target, $title, $content)
- {
- return self::create([
- "identity_type" => $identity_type,
- "to_user_id" => isset($to_target["to_user_id"]) ? $to_target["to_user_id"] : null,
- "to_massager_id" => isset($to_target["to_massager_id"]) ? $to_target["to_massager_id"] : null,
- "to_agency_id" => isset($to_target["to_agency_id"]) ? $to_target["to_agency_id"] : null,
- "title" => $title,
- "content" => $content,
- "is_read" => 0,
- "createtime" => time(),
- "updatetime" => time()
- ]);
- }
- /**
- * @param $msgs
- * @return bool|int|string
- */
- public static function sendSystemMessages($msgs)
- {
- return self::insertAll($msgs);
- }
- }
|