superbee315 преди 5 години
родител
ревизия
75e65ea44d
променени са 4 файла, в които са добавени 107 реда и са изтрити 17 реда
  1. 41 13
      application/newhome/controller/Message.php
  2. 15 0
      application/user/model/ReadMail.php
  3. 41 2
      application/user/view/mail/edit.html
  4. 10 2
      application/user/view/mail/index.html

+ 41 - 13
application/newhome/controller/Message.php

@@ -2,36 +2,64 @@
 namespace app\newhome\controller;
 
 use think\Controller;
-use app\user\model\User;
 use app\user\model\Mail;
-use app\user\model\Notice;
+use app\user\model\ReadMail;
 
 class Message extends Controller {
 	
-	private $userModel, $noticeModel, $mailModel;
+	private $readModel, $mailModel;
 	
 	public function _initialize(){
 		parent::_initialize();
 		
-		$this->userModel = new User();
+		$this->readModel = new ReadMail();
 		$this->mailModel = new Mail();
-		$this->noticeModel = new Notice();
 	}
 	
-	public function notice()
+	public function read()
 	{
+		$uid = $this->request->post('u', '1907239071686061468');
+		$mid = $this->request->post('i', 5);
 		
+		$res = $this->readModel->where(['uid'=>$uid, 'mid'=>$mid])->find();
+		if (empty($res)) {
+			$this->readModel->save(['uid'=>$uid, 'mid'=>$mid]);
+		}
+		
+		return json(['error'=>0]);
 	}
 	
 	public function mail(){
-		$uid = $this->request->post('i', '1907239071686061468');
+		$uid = $this->request->post('u', '1907239071686061468');
+		
+		// 找到用户的所有邮件
 		$res = $this->mailModel
-		->where(['is_del'=>0])
-		->where(['users'=>['like', "%{$uid}%"]])
-		->whereOr(['users'=>''])
-		->select();
-		echo '<pre>';
-		print_r(collection($res)->toArray());
+					->where(['is_del'=>0])
+					->where(function ($query) {
+						$uid = $this->request->post('u', '1907239071686061468');
+						$query->where(['users'=>['like', "%{$uid}%"]])->whereOr(['users'=>'']);
+					})
+					->where(function ($query) {
+						$time = getCurrentTime();
+						$query->where(['begin'=>['<', $time]])->whereOr('begin', null);
+					})
+					->where(function ($query) {
+						$time = getCurrentTime();
+						$query->where(['end'=>['>', $time]])->whereOr('end', null);
+					})
+					->order('create_time', 'desc')
+					->select();
+					
+		$read = $this->readModel->where(['uid'=>$uid])->column('mid');		
+		
+		foreach ($res as $key=>$val) {
+			if(in_array($val['id'], $read)) unset($res[$key]);
+			
+			unset($val['users']);
+			unset($val['is_del']);
+		}
+		
+		return json(array_values($res));
 	}
 	
 	

+ 15 - 0
application/user/model/ReadMail.php

@@ -0,0 +1,15 @@
+<?php
+namespace app\user\model;
+
+use think\Model;
+
+class ReadMail extends Model{
+	
+	protected $autoWriteTimestamp = 'int';			// 开启自动写入时间戳字段
+	protected $createTime = 'create_time';			// 创建时间
+	protected $updateTime = '';						// 每次更新时间
+	
+	public function initialize(){
+		parent::initialize();
+	}
+}

+ 41 - 2
application/user/view/mail/edit.html

@@ -5,7 +5,10 @@
 {js href="__ROOT__/__JS__/layui.js" /}
 {js href="__ROOT__/__JS__/bootstrap.min.js" /}
 {js href="__ROOT__/__JS__/bootstrap-tagsinput.min.js"}
+{js href="__ROOT__/__JS__/amazeui.datetimepicker.min.js"}
+{js href="__ROOT__/__JS__/amazeui.datetimepicker.zh-CN.js"}
 {css href="__ROOT__/__CSS__/layer.css" /}
+{css href="__ROOT__/__CSS__/amazeui.datetimepicker.css" /}
 {css href="__ROOT__/__CSS__/bootstrap.min.css" /}
 {css href="__ROOT__/__CSS__/bootstrap-tagsinput.css" /}
 
@@ -38,6 +41,18 @@
           </div>
           
           <div class="am-form-group">
+            <label for="users" class="am-u-sm-3 am-form-label">时间 / Time</label>
+            <div class="am-u-sm-9">
+            	<div class="am-u-sm-12 am-u-md-6">
+				    <input class="am-form-field" id="begin" name="begin" value="{$info.begin}" placeholder="开始日期"/>
+				</div>
+				<div class="am-u-sm-12 am-u-md-6">
+				    <input class="am-form-field" id="end" name="end" value="{$info.end}" placeholder="结束日期"/>
+				</div>
+            </div>
+          </div>
+          
+          <div class="am-form-group">
             <label for="diamond" class="am-u-sm-3 am-form-label">钻石 / Diamond</label>
             <div class="am-u-sm-9">
 				<input type="text" id="diamond" name="diamond" value="{$info.diamond}" placeholder="钻石 / Diamond"/>
@@ -52,9 +67,23 @@
           </div>
           
           <div class="am-form-group">
-            <label for="content" class="am-u-sm-3 am-form-label">内容 / Content</label>
+            <label for="zh" class="am-u-sm-3 am-form-label">中文 / Chinese</label>
+            <div class="am-u-sm-9">
+            	<textarea id="zh" name="zh" rows="5" placeholder="中文 / Chinese">{$info.zh}</textarea>
+            </div>
+          </div>
+          
+          <div class="am-form-group">
+            <label for="tw" class="am-u-sm-3 am-form-label">台湾 / Taiwan</label>
             <div class="am-u-sm-9">
-            	<textarea id="content" name="content" rows="5" placeholder="内容 / Content">{$info.content}</textarea>
+            	<textarea id="tw" name="tw" rows="5" placeholder="台湾 / Taiwan">{$info.tw}</textarea>
+            </div>
+          </div>
+          
+          <div class="am-form-group">
+            <label for="en" class="am-u-sm-3 am-form-label">英文 / English</label>
+            <div class="am-u-sm-9">
+            	<textarea id="en" name="en" rows="5" placeholder="英文 / English">{$info.en}</textarea>
             </div>
           </div>
           
@@ -81,6 +110,16 @@
     
     $(function(){
     	var users = $('#users').val();
+    	
+    	$('#begin').datetimepicker({
+    		  format: 'yyyy-mm-dd hh:ii:ss',
+    		  language:  'zh-CN'
+		});
+    	$('#end').datetimepicker({
+  		  	format: 'yyyy-mm-dd hh:ii:ss',
+    		language:  'zh-CN'
+		});
+    	
 
 		$('#users').tagsinput({
 			tagClass: function(item){

+ 10 - 2
application/user/view/mail/index.html

@@ -38,8 +38,12 @@
             <table class="am-table am-table-striped am-table-hover table-main">
               <thead>
 	              <tr>
-	                <th class="table-id">序号</th>
+	                <th class="table-id">ID</th>
 	                <th class="table-title">标题</th>
+	                <th class="">钻石</th>
+	                <th class="">金币</th>
+	                <th class="">开始日期</th>
+	                <th class="">结束日期</th>
 	                <th class="table-date am-hide-sm-only">创建日期</th>
 	                <th class="table-set">操作</th>
 	              </tr>
@@ -47,8 +51,12 @@
               <tbody>
               	{foreach name="info" key="k" item="v"}
 		              <tr>
-		                <td>{$k+1}</td>
+		                <td>{$v.id}</td>
 		                <td>{$v.title}</td>
+		                <td>{$v.diamond}</td>
+		                <td>{$v.coin}</td>
+		                <td>{$v.begin}</td>
+		                <td>{$v.end}</td>
 		                <td class="am-hide-sm-only">{$v.create_time}</td>
 		                <td>
 		                  <div class="am-btn-toolbar">