我也是大V 2019-07-26 11:47 采纳率: 100%
浏览 350
已采纳

PHP交友系统怎么实现只有异性之间可以私信?

类似oelove这样的婚恋交友系统,怎么实现只有异性之间可以私信?
因为是婚恋交友系统,同性之间的联系几乎没有任何好处。
全是广告、拉人,有没有方法实现只能“男、女”之间可以私信?

请麻烦给一个具体的解决办法,感谢回答问题的老师!

PC端代码:


 <!--{include file="<!--{$uctplpath}-->block_head.tpl"}-->
<style type="text/css">
.box-main{padding:10px;}
.box-dialog-left{float:left;width:120px;}
.box-dialog-left .user-img{padding:5px; border:1px solid #dddddd;width:100px;height:120px;display:block}
.box-dialog-left .user-info {padding:5px;text-align:center;line-height:22px;}
.box-dialog-left p{line-height:25px;}
.box-dialog-left p img{vertical-align:center;}
.box-dialog-right {float:left;margin-left:10px;}

.box-dialog-right .dialog-tips {margin-bottom:5px;}
.box-dialog-right .dialog-tips-l {width:100px;height:20px;line-height:20px;float:left;}
.box-dialog-right .dialog-tips-r {margin-left:10px;height:20px;line-height:20px;float:left;}
.box-dialog-right. p {padding-left:10px;line-height:20px;}

.box-dialog-kdmsg {border: 1px solid #F7F7F7;box-shadow: 0 0 0 #666666;padding: 0 25px; width:400px;margin-top:10px;}
.box-dialog-kdmsg .writecon {
    background: url("<!--{$ucpath}-->images/line_cont.jpg") repeat scroll 0 0 transparent;
    border: 0 none;
    height: 210px;
    line-height:30px;
    width: 100%;
    font-size:100%;
    color:#666666;
    overflow:auto;
}
.box-dialog-button{float:right; margin-top:20px;margin-right:20px;}
</style>
<div class="box-main">
  <div class="box-dialog-left fl">

    <div class="user-img">
      <img width="100" height="120" border="0" src="<!--{$touser.avatarurl}-->" />
    </div>
    <div class="user-info">
      <a href="<!--{$touser.homeurl}-->" target="_blank"><!--{$touser.levelimg}--> <b><!--{$touser.username}--></b></a><br />
      <!--{if $touser.gender=='1'}-->男<!--{else}-->女<!--{/if}--> 
      <!--{hook mod='var' item='marrystatus' type='text' value=$touser.marrystatus}--> 
      <!--{$touser.age}--> 岁<br />
      <!--{area type='text' value=$touser.provinceid}--> <!--{area type='text' value=$touser.cityid}--><br />
      <!--{hook mod='var' item='education' type='text' value=$touser.education}--> <!--{$touser.height}-->CM
    </div>
    <p></p>

  </div>

  <div class="box-dialog-right fl">

    <input type="hidden" name="touid" id="touid" value="<!--{$touid}-->" />
    <input type="hidden" name="posttype" id="posttype" value="0" />
    <div class="dialog-tips">
      <div class="dialog-tips-l"><img src="<!--{$ucpath}-->images/menu/edit.gif"><span id="btn_greet" style="color:#666666;cursor:pointer;">帮我找话题</span></div>
      <div class="dialog-tips-r"><span class="cc">(请文明聊天)</span></div>
      <div class="clear"></div>
    </div>
    <div class="box-dialog-kdmsg">
      <textarea class="writecon" name="content" id="content" onclick="del_content();" onblur="attr_content();">请在这里写信件内容...</textarea>
    </div>

    <div class="box-dialog-button">
      <!--{if true === $paystatus}-->
      <input type="button" value=" 私信 " class="button-red" name="btn_send" id="btn_send"  />
      <!--{else}-->
      <input type="button" value=" 发信 " class="button-green" name="btn_send" id="btn_send" />
      <!--{/if}-->
    </div>
    <div class="clear"></div>
    <p>
      <div class="nav-tips">
      免费会员无权限,<a href="<!--{$ucfile}-->?c=payment" target="_top">需充值金币,升级VIP会员。&gt;&gt;</a><br />
      <!--{if true === $paystatus}-->

      <!--{else}-->
      您可以免费给TA写信件。
      <!--{/if}-->
      </div>
    </p>

  </div>
  <div class="clear"></div>

</div>

<script type="text/javascript">
$(function(){
    //帮我找话题
    $("#btn_greet").click(function(){
        $.ajax({
            type: "POST",
            url: _ROOT_PATH + "usercp.php?c=message&a=greet&sex=<!--{$touser.gender}-->",
            cache: false,
            data: {r:get_rndnum(8)},
            dataType: "json",
            beforeSend: function(XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("request_type","ajax");
            },
            success: function(data) {
                var json = eval(data);
                var response = json.response;
                if (response.length > 0) {
                    $("#content").val(response);
                    $("#btn_greet").html("换一个话题");
                }
            },
            error: function() {}
        });
    });

    //执行发信
    $("#btn_send").click(function(){
        var fromtype = "";
        var uid = $("#touid").val();
        var content = $("#content").val();
        var payfee = <!--{$g.fee.sendmsgfee}-->;
        if (payfee == "" || payfee == 0) {
            payfee = 1;
        }
        if (uid < 1) {
            $.dialog.tips("会员ID丢失,请重试!", 3);
            return false;
        }
        if (uid == <!--{$u.userid}-->) {
            $.dialog.tips("对不起,你不能和自己写信!", 3);
            return false;
        }   
        if (content == '' || content == '请在这里写信件内容...') {
            $.dialog.tips("请填写信件内容!", 3);
            return false;
        }
        <!--{if (true === $paystatus)}-->
        if (<!--{$u.money}--> < payfee) {
            $.dialog.tips("对不起,您没有私信权限!", 3);
            return false;
        }
        <!--{/if}-->

        //执行
        $.ajax({
            type: "POST",
            url: _ROOT_PATH + "usercp.php?c=message",
            cache: false,
            data: {a: "savewrite", touid: uid, content:content, r:get_rndnum(8)},
            dataType: "json",
            beforeSend: function(XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("request_type","ajax");
            },
            success: function(data) {
                var json = eval(data);
                var response = json.response;
                var msg = json.msg;
                if (response == '1') {
                    $.dialog({
                        lock:false,
                        drag: false,
                        title: '成功提示',
                        content: "信件发送成功", 
                        icon: 'succeed',
                        button: [
                            {
                                name: '确定',
                                callback: function () {
                                    if (fromtype=='reload') {
                                        window.top.location.reload();
                                    }
                                    else {
                                        $("#content").val("");
                                        $.dialog.close();
                                    }
                                }
                            }
                        ]
                    });
                }
                else {
                    //发送失败
                    if (msg.length>0) {
                        $.dialog.tips(msg, 3);
                    }
                    else {
                        $.dialog.tips("对不起,信件发送失败", 3);
                    }
                }
            },
            error: function() {}
        });

    });

});

//内容
function del_content() {
    var content = $("#content").val();
    if (content == '请在这里写信件内容...') {
        $("#content").val("");
    }
}
function attr_content() {
    var content = $("#content").val();
    if (content == '') {
        $("#content").val("请在这里写信件内容...");
    }
}
</script>

</body>
</html>

手机移动端代码:

<!--{assign var="menu_id" value="message"}-->
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <title><!--{$page_title}--> </title>
  <meta name="description" content="<!--{$page_description}-->" />
  <meta name="keywords" content="<!--{$page_keyword}-->" />
  <meta name="author" content="<!--{$copyright_author}-->" />
  <meta name="generator" content="OElove" />

  <link rel="stylesheet" href="<!--{$urlpath}-->tpl/static/mui/css/mui.css">
  <link rel="stylesheet" href="<!--{$urlpath}-->tpl/static/mui/css/mui.picker.css">
  <link rel="stylesheet" href="<!--{$urlpath}-->tpl/static/mui/css/mui.dtpicker.css">
  <link rel="stylesheet" href="<!--{$urlpath}-->tpl/static/mui/css/mui.poppicker.css">

  <script src="<!--{$wapskin}-->js/jquery.min.js"></script>
  <script type="text/javascript">
    var WAP_APPFILE = "<!--{$wapfile}-->";
    var _ROOT_PATH = "<!--{$urlpath}-->";
    var WIN_WIDTH = $(window).width();
    var WIN_HEIGHT = $(window).height();
    if ($.browser.mozilla) {
      WIN_WIDTH = window.screen.width; //兼容Mozilla
      WIN_HEIGHT = window.screen.height;
    }
  </script>
  <script src="<!--{$wapskin}-->js/toast_OELOVE26FL319L.js"></script>
  <script src="<!--{$wapskin}-->js/public_OELOVE26FL319L.js"></script>
  <link rel="stylesheet" href="<!--{$wapskin}-->style/append_OELOVE26FL319L.css?spm=<!--{$time}-->" />
  <link rel="stylesheet" href="<!--{$wapskin}-->style/main_OELOVE26FL319L.css?spm=<!--{$time}-->" />
  <link rel="stylesheet" href="<!--{$wapskin}-->style/user_OELOVE26FL319L.css?spm=<!--{$time}-->" />
  <link rel="stylesheet" href="<!--{$wapskin}-->font/iconfont.css?spm=<!--{$time}-->" />
</head>
<body>
<div id="loading"></div>
<script type="text/javascript">
  $(function(){
    setTimeout(function(){
      $("#loading").hide();
      $("#loading").remove();
    }, 100);
  });
</script>
<header class="mui-bar mui-bar-nav no_shade">
  <!--{if $nofollow == 1}-->
  <a class="mui-icon mui-icon-left-nav mui-pull-left" href="<!--{$wapfile}-->?c=cp_message&nofollow=1"></a>
  <!--{else}-->
  <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  <!--{/if}-->
  <h1 class="mui-title"><!--{$chatuser.username}--></h1>
  <a id="menu" class="oe_navmore mui-action-menu mui-icon  mui-pull-right" href="#topLog"><i class="iconfont" style="font-size:24px;">&#xe654;</i></a>
</header>

<div id="topLog" class="mui-popover oe_downmenu" style="height:50px; width:80px;">
  <div class="mui-popover-arrow"></div>
  <div class="mui-scroll-wrapper">
    <div class="mui-scroll">
      <ul class="mui-table-view">
        <!--{assign var="backurl" value="<!--{$oefile}-->&c=msgchat&sid=<!--{$sid}-->&nofollow=1"}-->
        <li class="mui-table-view-cell"><a class="cursor but_goback_url" onclick="userDetail('<!--{$chatuser.userid}-->');">查看资料</a></li>
      </ul>
    </div>
  </div>
</div>

<input type="hidden" name="touid" id="touid" value="<!--{$touid}-->" />
<input type="hidden" id="page" name="page" value="1" />
<input type="hidden" id="reqs_url" name="reqs_url" value="<!--{$wapfile}-->?c=<!--{$c}-->&a=list&touid=<!--{$touid}-->&datatype=json" />

<div class="mui-content oe_chat">
  <div id="pullrefresh" class="mui-content mui-scroll-wrapper" style="top:44px;bottom:60px;background:#eee;">
    <div class="mui-scroll" style="background:#eee;">

      <!--{if $msg_nums == 0}-->
      <div class="chat_content">
        <ul>
          <li class="text">
            <span>聊天涉及钱财问题,请保持警惕,避免上当受骗。若发现可疑行为,请及时举报。</span>
          </li>
        </ul>
      </div>
      <!--{/if}-->

      <div class="chat_content">
        <ul id="pull_data">

        </ul>
        <div id="msg_face_bar" style="height:170px;display:none;"></div>
      </div>
    </div>
  </div>

  <div class="chat_input" style="height:60px;">
    <div class="input"><input type="text" name="msgchat_content" id="msgchat_content" /></div>
    <span class="iconfont icon-xiaolian cursor" f="but_show_face"></span>
    <!--{if $paystatus == false}-->
    <button class="cursor" id="but_send_msgchat" f="but_send_msgchat" data-sid="<!--{$chatuser.userid}-->" data-touid="<!--{$chatuser.userid}-->">发送</button>
    <!--{else}-->
    <button class="cursor" id="but_send_msgchat" f="but_notimes_tips" data-sid="<!--{$chatuser.userid}-->" data-touid="<!--{$chatuser.userid}-->">发送</button>
    <!--{/if}-->
  </div>

</div>


<div id="power_popover" class="mui-popover mui-popover-action mui-popover-bottom oe_btbox"  style="bottom:80px;">
  <div class="hd">温馨提示</div>
  <center>
  <div class="bd">
    您与<!--{if $chatuser.gender == '1'}-->他<!--{else}-->她<!--{/if}-->的聊天通道还没打开<br />
    请升级VIP会员获得通信权限<br><br />
    <span class="text"> </span>
    <span class="text"> </span>
  </div>
    </center>
      <div class="btn">
       <a class="a_2" href="#power_popover"">取消</a>   
       <a class="a_2" href="javascript:;" id="buy_freesid_vip" f="buy_freesid_vip" data-sid="<!--{$chatuser.userid}-->">升级会员</a>   
  </div>


  <a href="#power_popover" class="cancel"><i class="iconfont">&#xe6bc;</i></a>
</div>


<script src="<!--{$urlpath}-->tpl/static/mui/js/mui.js"></script>
<script src="<!--{$urlpath}-->tpl/static/mui/js/mui.picker.js"></script>
<script src="<!--{$urlpath}-->tpl/static/mui/js/mui.dtpicker.js"></script>
<script src="<!--{$urlpath}-->tpl/static/mui/js/mui.poppicker.js"></script>
<script src="<!--{$urlpath}-->tpl/static/mui/js/mui.view.js"></script>
<script type="text/javascript" charset="utf-8">
  $("#page").val(1);
  //$('.mui-scroll-wrapper').scroll({"indicators": false});
  mui.init({

    pullRefresh: {
      container: '#pullrefresh',
      down: {
        auto:false,
        style:'',
        contentdown:"下拉加载更多",
        contentover:"下拉加载更多",
        contentrefresh:"",
        callback: function(){
          //加载下一页...
          //pullDownRefresh();
          pullMoreChatMsg();
        }
      },

      /*
       up: {
       auto:true,
       contentrefresh: '正在加载...',
       callback: function(){
       pullUpRefresh();
       }
       }
       */
    }
  });

  $(function(){
    _maskShow();
    pullMoreChatMsg(function(){
      _maskClose();
    });
  });
</script>
<script src="<!--{$wapskin}-->js/cp/msgchat.js"></script>
</body>
</html>
  • 写回答

3条回答

  • Sometimes_Ymc 2019-07-26 14:54
    关注

    你是要代码还是不知道怎么去实现?
    解决的办法有很多种,
    1:私信按钮隐藏显示,session获取当前用户性别,循环判断好友列表,性别相同的隐藏私信按钮,或者反之;
    2:私信时判断性别,相同时提示用户不可私信即可;
    3:单独显示可私信列表好友,或添加筛选条件显示列表;
    4:私信全部可以发送,但是同性别用户收不到那条私信,只显示在自己的列表即可
    方法有很多种,但是感觉要的不是这个

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3