Пример #1
0
 /**
  * 将消息和用户关联
  * @param  MessageModel $p_msgModel   消息模型
  * @param  array  $p_queryWhere   用户的筛选方案
  * @return int                   关联个数
  */
 public static function createNewModels($p_msgModel, $p_queryWhere = array())
 {
     $userIDs = DBModel::instance('user')->where($p_queryWhere)->selectValues('id');
     $tmpData = array();
     $tmpData['msgID'] = $p_msgModel->getId();
     $tmpData['readStatus'] = READ_STATUS::UNREAD;
     $tmpData['createTime'] = date('Y-m-d H:i:s');
     $tmpData['modifyTime'] = date('Y-m-d H:i:s');
     $dbFac = static::newDBModel();
     foreach ($userIDs as $userID) {
         $tmpData['userID'] = $userID;
         $dbFac->insert($tmpData);
     }
     //推送
     if (count($userIDs) > 0) {
         $p_where = array();
         $p_where['joinList'] = array();
         $p_where['joinList'][] = array('relationMessageUser t2', array('t2.userID = t1.userID', 't2.msgID' => $p_msgID, 't2.readStatus' => READ_STATUS::UNREAD));
         DeviceController::pushSingleMessage($p_where, $p_msgModel->getTitle(), $p_msgModel->getDescription(), $customtype = null, $customvalue = null, $tag_name = null);
     }
     return count($userIDs);
 }