Jonlin 6 жил өмнө
parent
commit
7f1df6ff71

+ 10 - 3
application/user/controller/Index.php

@@ -4,6 +4,7 @@ namespace app\user\controller;
 
 use think\Lang;
 use think\Cache;
+use app\user\model\UserMessage;
 
 class Index extends UserControl
 {
@@ -16,9 +17,15 @@ class Index extends UserControl
 
     public function index()
     {
-//        $allpower = $this->qxhans();
-//        $this->assign('allpower',$allpower);
-        $this->assign('user_info', $this->getAdminInfo());
+        $user_info = $this->getAdminInfo();
+
+        // 获取用户未读消息数量
+        $db = new UserMessage();
+        $user_id = $user_info['user_id'];
+        $message = $db->getMessage($user_id);
+        $num = count($message);
+        $user_info['num'] = $num;
+        $this->assign('user_info', $user_info);
         return $this->fetch();
     }
 

+ 19 - 6
application/user/controller/Message.php

@@ -2,6 +2,7 @@
 
 namespace app\user\controller;
 use think\Lang;
+use app\user\model\UserMessage;
 
 class Message extends UserControl
 {
@@ -15,26 +16,38 @@ class Message extends UserControl
 
     public function index()
     {
-        $message = Model('Userproduct');
-        $condition['user_id'] = session('user_id');
+        $message = new UserMessage();
+        $user_id = session('user_id');
+
+        $condition = array();
+
+        $condition['user_id'] = array('=',$user_id);
 
         $time = input('get.timeRang');
         if (!empty($time)) {
             $gap = explode(' - ', $time);
             $begin = $gap[0];
             $end = date('Y-m-d', strtotime ("+1 day", strtotime($gap[1])));
-            $condition['userProduct_buyTime'] = array('between', array($begin, $end));
+            $condition['userMessage_create'] = array('between', array($begin, $end));
         }
         $type = input('get.type');
         if ($type) {
             if($type == -1){
-                $condition['userProduct_maturityTime'] = array('<',date('Y-m-d',time()));
+                $condition['userMessage_status'] = array('<',date('Y-m-d',time()));
             }
             if($type == 1){
-                $condition['userProduct_maturityTime'] = array('>=',date('Y-m-d',time()));
+                $condition['userMessage_status'] = array('>=',date('Y-m-d',time()));
+            }
+        }
+        $usermessage = $message->getUserMessage($condition);
+        for($i=0;$i<count($usermessage);$i++){
+            if($usermessage[$i]['userMessage_status'] == 1){
+                $usermessage[$i]['userMessage_status'] = '已读';
+            }
+            if($usermessage[$i]['userMessage_status'] == 0){
+                $usermessage[$i]['userMessage_status'] = '未读';
             }
         }
-        $usermessage = $message->getUserProduct($condition);
         $this->assign('show_page', $usermessage->render());
         $this->assign('usermessage', $usermessage);
 

+ 1 - 1
application/user/controller/Register.php

@@ -90,7 +90,7 @@ class Register extends Controller
             $condition['user_email'] = $user_email;
 
             $user_info = db('user')->where($condition)->find();
-            if (is_array($user_info) and !empty($user_info)) {
+                if (is_array($user_info) and !empty($user_info)) {
                 $this->success('账户已存在');
             } else {
                 $user_info = array(

+ 38 - 0
application/user/model/UserMessage.php

@@ -0,0 +1,38 @@
+<?php
+namespace app\user\model;
+
+use think\Model;
+
+/**
+ * 用户信息管理
+ */
+class UserMessage extends Model
+{
+    //获取用户消息
+    public function getUserMessage($condition)
+    {
+
+        $message_list = $this
+            ->where($condition)
+            ->order('userMessage_create desc')
+            ->paginate(10);
+
+        return $message_list;
+
+    }
+
+    //获取用户未读消息
+    public function getMessage($user_id)
+    {
+
+        $message = $this
+            ->where('user_id',$user_id)
+            ->where('userMessage_status',0)
+            ->select();
+
+        return $message;
+
+    }
+
+
+}

+ 21 - 2
application/user/view/index/index.html

@@ -50,6 +50,16 @@
     .treeview .admin-nav-item:hover{
             color: #0074FF !important;
     }
+    .num{
+        background-color:red;
+        color:white;
+        display:block;
+        width:30px;
+        float:right;
+        border-radius: 20px;
+        text-align:center;
+    }
+    .num:hover{color:white}
 </style>
 <div class="admincp-header" style="line-height: 4;">
     <div class="logo" onclick="goHome()" style="cursor:pointer;">
@@ -71,7 +81,7 @@
             {foreach name="menu_list" item="menu" key="fe_menu"}
             <li class="treeview"  style="cursor:pointer">
                 {if !empty($menu.children)}
-                <div class="title" id="navT">
+                <div class="title {$menu.name}" id="navT" style="display: flex;">
                     <img src="{$Think.USER_SITE_ROOT}/images/{$fe_menu}.png" style="margin-right: 5px">
                     <span class="title-txt"> {$menu.text}</span>
                     <span class="layui-nav-more"></span>
@@ -83,7 +93,7 @@
                 </ul>
                 {else}
                 <a data-id="{$fe_menu}" href="{$menu.url}" class="admin-nav-item" style="padding-left: 0px;">
-                    <div class="title" id="navT">
+                    <div class="title {$menu.name}" id="navT" style="display: flex;">
                         <img src="{$Think.USER_SITE_ROOT}/images/{$fe_menu}.png" style="margin-right: 5px">
                         <span class="title-txt"> {$menu.text}</span>
                         <span class="layui-nav-more"></span>
@@ -112,6 +122,15 @@
     </div>
     {block name="container"}{/block}
 </div>
+<input type="text" id="num" style="display: none;" value="{$user_info['num']}">
+<script>
+    var num = document.getElementById("num").value;
+    if(num>0){
+        console.log(num);
+        var appendHtml = '<a href="javascript:void(0);" onclick=" return false; " class="num">'+num+'</a>';
+        $(".my_massage").append(appendHtml);
+    }
+</script>
 <script type="text/javascript">
     var width =document.body.clientWidth;
     const myHost = "http://" + window.location.host;

+ 13 - 13
application/user/view/message/index.html

@@ -13,8 +13,8 @@
                     <label>{:lang('if_expire')}</label>
                     <select name="type" id="type" lay-verify="" class="layui-select layui-unselect layui-form-select">
                         <option value="">请选择</option>
-                        <option value="-1">{:lang('expire')}</option>
-                        <option value="1">{:lang('no_expire')}</option>
+                        <option value="0">未读</option>
+                        <option value="1">已读</option>
                     </select>
                 </div>
                 <div class="layui-inline">
@@ -24,28 +24,28 @@
         </div>
         <table class="layui-table lay-even">
             <colgroup>
-                <col width="150">
+                <col width="60">
                 <col width="200">
+                <col width="80">
+                <col width="60">
                 <col>
             </colgroup>
             <thead>
             <tr>
-                <th>订单编号</th>
-                <th>产品名称</th>
-                <th>购买时间</th>
-                <th>购买天数</th>
-                <th>到期时间</th>
+                <th>标题</th>
+                <th>内容</th>
+                <th>创建时间</th>
+                <th>读取状态</th>
             </tr>
             </thead>
             <tbody>
             {if count($usermessage)}
             {volist name="usermessage" id="message"}
             <tr>
-                <td>{$message.userProduct_identity}</td>
-                <td>{$message.product_name}</td>
-                <td>{$message.userProduct_buyTime}</td>
-                <td>{$message.userProduct_dayNumber}</td>
-                <td>{$message.userProduct_maturityTime}</td>
+                <td>{$message.userMessage_title}</td>
+                <td>{$message.userMessage_content}</td>
+                <td>{$message.userMessage_create}</td>
+                <td>{$message.userMessage_status}</td>
             </tr>
             {/volist}
             {else}